Skip to contentSkip to conversation

lib: Add tst_kernel_bits()

PATCH New Cyril Hrubis 2 participants 11 messages Jan 12, 2017 Library code

lore
Share & tools
lore
#0 lore raw

PATCH 1/4 lib: Add tst_kernel_bits()

This function returns 32 or 64 depending on if we are running on 32bit or 64bit kernel. This is detected from uname.machine string which seems to be good enough heuristic and even if that fails we can always add a special cases to the tst_kernel_bits() function.

---
 include/tst_kernel.h | 26 ++++++++++++++++++++++++++
 include/tst_test.h   |  1 +
 lib/tst_kernel.c     | 36 ++++++++++++++++++++++++++++++++++++
 3 files changed, 63 insertions(+)
 create mode 100644 include/tst_kernel.h
 create mode 100644 lib/tst_kernel.c
include/tst_kernel.h new file +26 -0
new file mode 100644
index 0000000..5d5c04c
@@ -0,0 +1,26 @@
+/*
+ * Copyright (c) 2017 Cyril Hrubis <[email protected]>
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef TST_KERNEL_H__
+#define TST_KERNEL_H__
+
+/*
+ * Returns 32 if we are running on 32bit kernel and 64 if on 64bit kernel.
+ */
+int tst_kernel_bits(void);
+
+#endif	/* TST_KERNEL_H__ */
include/tst_test.h +1 -0
index 1492ff5..7ff33b2 100644
@@ -33,6 +33,7 @@
 #include "tst_atomic.h"
 #include "tst_kvercmp.h"
 #include "tst_clone.h"
+#include "tst_kernel.h"
 
 /*
  * Reports testcase result.
lib/tst_kernel.c new file +36 -0
new file mode 100644
index 0000000..7a53002
@@ -0,0 +1,36 @@
+/*
+ * Copyright (c) 2017 Cyril Hrubis <[email protected]>
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include <sys/utsname.h>
+#include "test.h"
+#include "tst_kernel.h"
+
+int tst_kernel_bits(void)
+{
+	struct utsname buf;
+	int kernel_bits;
+
+	if (uname(&buf))
+		tst_brkm(TBROK | TERRNO, NULL, "uname()");
+
+	kernel_bits = strstr(buf.machine, "64") ? 64 : 32;
+
+	tst_resm(TINFO, "uname.machine=%s kernel is %ibit",
+	         buf.machine, kernel_bits);
+
+	return kernel_bits;
+}
Signature · 1 line
2.7.3
#1 lore raw

PATCH 2/4 vma03: Disable the test on 64bit kernel as well

The test works only on a 32bit kernel, otherwise we cannot cause the overflow.

---
 testcases/kernel/mem/vma/vma03.c | 9 ++++++---
 1 file changed, 6 insertions(+), 3 deletions(-)
testcases/kernel/mem/vma/vma03.c +6 -3
index 31c7716..edad9f4 100644
@@ -49,6 +49,7 @@
 #include <unistd.h>
 
 #include "test.h"
+#include "tst_kernel.h"
 
 char *TCID = "vma03";
 int TST_TOTAL = 1;
@@ -70,9 +71,11 @@ int main(int argc, char *argv[])
 	void *map, *remap;
 	off_t pgoff;
 
-#if __WORDSIZE != 32
-	tst_brkm(TCONF, NULL, "test is designed for 32-bit system only.");
-#endif
+	if (__WORDSIZE != 32 || tst_kernel_bits() != 32) {
+		tst_brkm(TCONF, NULL,
+			 "test is designed for 32-bit system only.");
+	}
+
 	tst_parse_opts(argc, argv, NULL, NULL);
 
 	pgsz = sysconf(_SC_PAGE_SIZE);
Signature · 1 line
2.7.3
#2 lore raw

PATCH 3/4 mmapstress03: Small cleanup

In reply to Cyril Hrubis

No fucntional changes done.

---
 testcases/kernel/mem/mmapstress/mmapstress03.c | 47 ++++++++------------------
 1 file changed, 14 insertions(+), 33 deletions(-)
testcases/kernel/mem/mmapstress/mmapstress03.c +14 -33
index 066587a..76a77a9 100644
@@ -42,11 +42,9 @@
 #include <errno.h>
 #include <unistd.h>
 #include <limits.h>
+#include <stdlib.h>
 
-/*****  LTP Port        *****/
 #include "test.h"
-#define FAILED 0
-#define PASSED 1
 
 char *TCID = "mmapstress03";
 FILE *temp;
@@ -54,36 +52,24 @@ int TST_TOTAL = 1;
 
 int anyfail();
 void ok_exit();
-/*****  **      **      *****/
 
 #define AS_SVSM_VSEG_MAX	48UL
 #define AS_SVSM_MMAP_MAX	16UL
 
 #define EXTRA_VSEGS	2L
 #define NUM_SEGS	(AS_SVSM_VSEG_MAX + EXTRA_VSEGS)
-#define ERROR(M) (void)fprintf(stderr, "%s: errno = %d: " M "\n", progname, \
+#define ERROR(M) (void)fprintf(stderr, "%s: errno = %d: " M "\n", TCID, \
 			errno)
 #define NEG1	(char *)-1
 #define POINTER_SIZE	(sizeof(void *) << 3)
 
-extern long sysconf(int name);
-extern void exit(int);
-extern time_t time(time_t *);
-extern char *ctime(const time_t *);
-static void do_test(caddr_t brk_max, long pagesize);
+static void do_test(void* brk_max, long pagesize);
 
-static char *progname;
-
- /*ARGSUSED*/ int main(int argc, char *argv[])
+int main(void)
 {
 	char *brk_max_addr, *hole_addr, *brk_start, *hole_start;
 	size_t pagesize = (size_t) sysconf(_SC_PAGE_SIZE);
-	time_t t;
-
-	progname = argv[0];
 
-	(void)time(&t);
-//      (void)printf("%s: Started %s", argv[0], ctime(&t));
 	if ((brk_start = sbrk(0)) == NEG1) {
 		ERROR("initial sbrk failed");
 		anyfail();
@@ -105,7 +91,7 @@ static char *progname;
 		ERROR("couldn't find top of brk");
 		anyfail();
 	}
-	do_test((caddr_t) brk_max_addr, pagesize);
+	do_test((void*) brk_max_addr, pagesize);
 
 	/* now make holes and repeat test */
 	while (hole_addr + pagesize < brk_max_addr) {
@@ -120,7 +106,7 @@ static char *progname;
 		ERROR("do_test should leave the top of brk where it began");
 		anyfail();
 	}
-	do_test((caddr_t) brk_max_addr, pagesize);
+	do_test((void*) brk_max_addr, pagesize);
 
 	/* Shrink brk */
 	if (sbrk(-NUM_SEGS * pagesize) == NEG1) {
@@ -152,11 +138,11 @@ static char *progname;
 		anyfail();
 	}
 	/* Ask for a ridiculously large mmap region@a high address */
-	if (mmap((caddr_t) (1UL << (POINTER_SIZE - 1)) - pagesize,
+	if (mmap((void*) (1UL << (POINTER_SIZE - 1)) - pagesize,
 		 (size_t) ((1UL << (POINTER_SIZE - 1)) - pagesize),
 		 PROT_READ | PROT_WRITE, MAP_ANONYMOUS | MAP_FIXED | MAP_SHARED,
 		 0, 0)
-	    != (caddr_t) - 1) {
+	    != (void*) - 1) {
 		ERROR("really large mmap didn't fail");
 		anyfail();
 	}
@@ -164,8 +150,7 @@ static char *progname;
 		ERROR("really large mmap didn't set errno = ENOMEM nor EINVAL");
 		anyfail();
 	}
-	(void)time(&t);
-//      (void)printf("%s: Finished %s", argv[0], ctime(&t));
+
 	ok_exit();
 	tst_exit();
 }
@@ -174,21 +159,20 @@ static char *progname;
  * do_test assumes that brk_max is a multiple of pagesize
  */
 
-static
-void do_test(caddr_t brk_max, long pagesize)
+static void do_test(void* brk_max, long pagesize)
 {
-	if (mmap((caddr_t) ((long)brk_max - 3 * pagesize), (2 * pagesize),
+	if (mmap((void*) ((long)brk_max - 3 * pagesize), (2 * pagesize),
 		 PROT_READ | PROT_WRITE,
 		 MAP_ANONYMOUS | MAP_FIXED | MAP_PRIVATE, 0, 0)
-	    == (caddr_t) - 1) {
+	    == (void*) - 1) {
 		ERROR("mmap failed");
 		anyfail();
 	}
 	/* extend mmap */
-	if (mmap((caddr_t) ((long)brk_max - 2 * pagesize), (2 * pagesize),
+	if (mmap((void*) ((long)brk_max - 2 * pagesize), (2 * pagesize),
 		 PROT_READ | PROT_WRITE,
 		 MAP_ANONYMOUS | MAP_FIXED | MAP_PRIVATE, 0, 0)
-	    == (caddr_t) - 1) {
+	    == (void*) - 1) {
 		ERROR("mmap failed");
 		anyfail();
 	}
@@ -214,7 +198,6 @@ void do_test(caddr_t brk_max, long pagesize)
 	}
 }
 
-/*****  LTP Port        *****/
 void ok_exit(void)
 {
 	tst_resm(TPASS, "Test passed");
@@ -225,5 +208,3 @@ int anyfail(void)
 {
 	tst_brkm(TFAIL, NULL, "Test failed");
 }
-
-/*****  **      **      *****/
Signature · 1 line
2.7.3
#3 lore raw

PATCH 4/4 mmapstress03: Fix 32bit test on 64bit kernel

In reply to Cyril Hrubis

The ridiculously large mapping size has to be adjusted based on the kernel addressing size not on a pointer size otherwise the testcase segfaults when 32bit binary is executed on 64bit kernel.

---
 testcases/kernel/mem/mmapstress/mmapstress03.c | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)
testcases/kernel/mem/mmapstress/mmapstress03.c +5 -3
index 76a77a9..fe25b7a 100644
@@ -45,6 +45,7 @@
 #include <stdlib.h>
 
 #include "test.h"
+#include "tst_kernel.h"
 
 char *TCID = "mmapstress03";
 FILE *temp;
@@ -61,7 +62,6 @@ void ok_exit();
 #define ERROR(M) (void)fprintf(stderr, "%s: errno = %d: " M "\n", TCID, \
 			errno)
 #define NEG1	(char *)-1
-#define POINTER_SIZE	(sizeof(void *) << 3)
 
 static void do_test(void* brk_max, long pagesize);
 
@@ -69,6 +69,7 @@ int main(void)
 {
 	char *brk_max_addr, *hole_addr, *brk_start, *hole_start;
 	size_t pagesize = (size_t) sysconf(_SC_PAGE_SIZE);
+	int kernel_bits = tst_kernel_bits();
 
 	if ((brk_start = sbrk(0)) == NEG1) {
 		ERROR("initial sbrk failed");
@@ -137,9 +138,10 @@ int main(void)
 		ERROR("failed to fiddle with brk at the end");
 		anyfail();
 	}
+
 	/* Ask for a ridiculously large mmap region@a high address */
-	if (mmap((void*) (1UL << (POINTER_SIZE - 1)) - pagesize,
-		 (size_t) ((1UL << (POINTER_SIZE - 1)) - pagesize),
+	if (mmap((void*) (1UL << (kernel_bits - 1)) - pagesize,
+		 (size_t) ((1ULL << (kernel_bits - 1)) - pagesize),
 		 PROT_READ | PROT_WRITE, MAP_ANONYMOUS | MAP_FIXED | MAP_SHARED,
 		 0, 0)
 	    != (void*) - 1) {
Signature · 1 line
2.7.3
#4 lore raw

PATCH 4/4 mmapstress03: Fix 32bit test on 64bit kernel

----- Original Message -----

Quoted 44 lines

From: "Cyril Hrubis" <[email protected]>
To: [email protected]
Sent: Thursday, 12 January, 2017 2:23:39 PM
Subject: [LTP] [PATCH 4/4] mmapstress03: Fix 32bit test on 64bit kernel

The ridiculously large mapping size has to be adjusted based on the kernel addressing size not on a pointer size otherwise the testcase segfaults when 32bit binary is executed on 64bit kernel.

---
 testcases/kernel/mem/mmapstress/mmapstress03.c | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)
testcases/kernel/mem/mmapstress/mmapstress03.c +2 -1
index 76a77a9..fe25b7a 100644
@@ -45,6 +45,7 @@
 #include <stdlib.h>
 
 #include "test.h"
+#include "tst_kernel.h"
 
 char *TCID = "mmapstress03";
 FILE *temp;
@@ -61,7 +62,6 @@ void ok_exit();
 #define ERROR(M) (void)fprintf(stderr, "%s: errno = %d: " M "\n", TCID, \
 			errno)
 #define NEG1	(char *)-1
-#define POINTER_SIZE	(sizeof(void *) << 3)
 
 static void do_test(void* brk_max, long pagesize);
 
@@ -69,6 +69,7 @@ int main(void)
 {
 	char *brk_max_addr, *hole_addr, *brk_start, *hole_start;
 	size_t pagesize = (size_t) sysconf(_SC_PAGE_SIZE);
+	int kernel_bits = tst_kernel_bits();
 
 	if ((brk_start = sbrk(0)) == NEG1) {
 		ERROR("initial sbrk failed");

testcases/kernel/mem/mmapstress/mmapstress03.c int main(void) · line 143

Quoted 8 lines
testcases/kernel/mem/mmapstress/mmapstress03.c +2 -2
@@ -137,9 +138,10 @@ int main(void)
 		ERROR("failed to fiddle with brk at the end");
 		anyfail();
 	}
+
 	/* Ask for a ridiculously large mmap region at a high address */
-	if (mmap((void*) (1UL << (POINTER_SIZE - 1)) - pagesize,
-		 (size_t) ((1UL << (POINTER_SIZE - 1)) - pagesize),
+	if (mmap((void*) (1UL << (kernel_bits - 1)) - pagesize,

Since this has same range as below, shouldn't it be also 1ULL? Entire series looks OK to me.

Regards,
Jan

Quoted 11 lines
testcases/kernel/mem/mmapstress/mmapstress03.c +1 -1
+		 (size_t) ((1ULL << (kernel_bits - 1)) - pagesize),
 		 PROT_READ | PROT_WRITE, MAP_ANONYMOUS | MAP_FIXED | MAP_SHARED,
 		 0, 0)
 	    != (void*) - 1) {
--

2.7.3

--
Mailing list info: https://lists.linux.it/listinfo/ltp

#5 lore raw

PATCH 4/4 mmapstress03: Fix 32bit test on 64bit kernel

Hi!

Quoted 7 lines

testcases/kernel/mem/mmapstress/mmapstress03.c int main(void) · line 143

Quoted 4 lines
testcases/kernel/mem/mmapstress/mmapstress03.c +1 -2
 	/* Ask for a ridiculously large mmap region at a high address */
-	if (mmap((void*) (1UL << (POINTER_SIZE - 1)) - pagesize,
-		 (size_t) ((1UL << (POINTER_SIZE - 1)) - pagesize),
+	if (mmap((void*) (1UL << (kernel_bits - 1)) - pagesize,

Since this has same range as below, shouldn't it be also 1ULL? Entire series looks OK to me.

Hmm, that produces warnings in case that sizeof(void) == 4 and with 64bit kernel since the value is truncated. I guess that the addres should be generated accordingly to the binary and not kernel after all because of address space limitations.

Something as (((uintptr_t)1) << ((sizeof(void*)<<3) - 1) - pagesize)

Signature · 2 lines
Cyril Hrubis
[email protected]
#6 lore raw

PATCH 4/4 mmapstress03: Fix 32bit test on 64bit kernel

----- Original Message -----

Quoted 15 lines

From: "Cyril Hrubis" <[email protected]>
To: "Jan Stancek" <[email protected]>
Cc: [email protected]
Sent: Thursday, 12 January, 2017 4:05:51 PM
Subject: Re: [LTP] [PATCH 4/4] mmapstress03: Fix 32bit test on 64bit kernel

Hi!

Quoted 7 lines

testcases/kernel/mem/mmapstress/mmapstress03.c int main(void) · line 143

Quoted 4 lines
testcases/kernel/mem/mmapstress/mmapstress03.c +1 -2
 	/* Ask for a ridiculously large mmap region at a high address */
-	if (mmap((void*) (1UL << (POINTER_SIZE - 1)) - pagesize,
-		 (size_t) ((1UL << (POINTER_SIZE - 1)) - pagesize),
+	if (mmap((void*) (1UL << (kernel_bits - 1)) - pagesize,

Since this has same range as below, shouldn't it be also 1ULL? Entire series looks OK to me.

Quoted 6 lines

Hmm, that produces warnings in case that sizeof(void) == 4 and with 64bit kernel since the value is truncated. I guess that the addres should be generated accordingly to the binary and not kernel after all because of address space limitations.

Something as (((uintptr_t)1) << ((sizeof(void*)<<3) - 1) - pagesize)

Wouldn't this crash same as original?

On 32 bit, it seems that as soon as mmap touches "stack" we crash. On 64-bit I'm guessing map area is so high, that we get rejected immediately with ENOMEM.

Example of lowering size to 1M and targeting stack (32bit on 64bit kernel):

# uname -r
4.8.0-1.el7.test.x86_64

Address Kbytes RSS Dirty Mode Mapping
0000000008048000 56 56 56 r-x-- mmapstress03

0000000008048000       0       0       0 r-x-- mmapstress03
0000000008056000       4       4       4 r---- mmapstress03
0000000008056000       0       0       0 r---- mmapstress03
0000000008057000       4       4       4 rw--- mmapstress03
0000000008057000       0       0       0 rw--- mmapstress03
0000000008058000      12       0       0 rw---   [ anon ]
0000000008058000       0       0       0 rw---   [ anon ]
00000000f7519000       4       4       4 rw---   [ anon ]
00000000f7519000       0       0       0 rw---   [ anon ]
00000000f751a000    1756     920       0 r-x-- libc-2.17.so
00000000f751a000       0       0       0 r-x-- libc-2.17.so
00000000f76d1000       4       0       0 ----- libc-2.17.so
00000000f76d1000       0       0       0 ----- libc-2.17.so
00000000f76d2000       8       8       8 r---- libc-2.17.so
00000000f76d2000       0       0       0 r---- libc-2.17.so
00000000f76d4000       4       4       4 rw--- libc-2.17.so
00000000f76d4000       0       0       0 rw--- libc-2.17.so
00000000f76d5000      12       8       8 rw---   [ anon ]
00000000f76d5000       0       0       0 rw---   [ anon ]
00000000f76e7000     124     120       0 r-x-- ld-2.17.so
00000000f76e7000       0       0       0 r-x-- ld-2.17.so
00000000f7706000       4       4       4 rw---   [ anon ]
00000000f7706000       0       0       0 rw---   [ anon ]
00000000f7707000       4       4       4 r---- ld-2.17.so
00000000f7707000       0       0       0 r---- ld-2.17.so
00000000f7708000       4       4       4 rw--- ld-2.17.so
00000000f7708000       0       0       0 rw--- ld-2.17.so
00000000ff873000     132       8       8 rw---   [ stack ]
00000000ff873000       0       0       0 rw---   [ stack ]

---------------- ------- ------- -------
total kB 2132 1148 108

...
mmap2(0xff800000, 1048576, PROT_READ|PROT_WRITE, MAP_SHARED|MAP_FIXED|MAP_ANONYMOUS, 0, 0) = 0xffffffffff800000 --- SIGSEGV {si_signo=SIGSEGV, si_code=SEGV_MAPERR, si_addr=0} ---
+++ killed by SIGSEGV +++
Segmentation fault

Quoted 5 lines

--
Cyril Hrubis
[email protected]

#7 lore raw

PATCH 4/4 mmapstress03: Fix 32bit test on 64bit kernel

Hi!

Quoted 3 lines
Quoted 1 line

Something as (((uintptr_t)1) << ((sizeof(void*)<<3) - 1) - pagesize)

Wouldn't this crash same as original?

That does not seem to be the case here I guess that the reason is that the size passed to the mmap2() in case of the 32bit binary on 64bit kernel is so close to 4GB after the patch that it's rejected right away as well. And possibly for 32bit binary on 32bit kernel 2GB size is enough to be rejected for the very same reason.

Signature · 2 lines
Cyril Hrubis
[email protected]
#8 lore raw

PATCH 4/4 mmapstress03: Fix 32bit test on 64bit kernel

In reply to Jan Stancek

----- Original Message -----

Quoted 31 lines

From: "Jan Stancek" <[email protected]>
To: "Cyril Hrubis" <[email protected]>
Cc: [email protected]
Sent: Thursday, 12 January, 2017 5:41:25 PM
Subject: Re: [LTP] [PATCH 4/4] mmapstress03: Fix 32bit test on 64bit kernel

----- Original Message -----

Quoted 20 lines

From: "Cyril Hrubis" <[email protected]>
To: "Jan Stancek" <[email protected]>
Cc: [email protected]
Sent: Thursday, 12 January, 2017 4:05:51 PM
Subject: Re: [LTP] [PATCH 4/4] mmapstress03: Fix 32bit test on 64bit kernel

Hi!

Quoted 7 lines

testcases/kernel/mem/mmapstress/mmapstress03.c int main(void) · line 143

Quoted 4 lines
testcases/kernel/mem/mmapstress/mmapstress03.c +1 -2
 	/* Ask for a ridiculously large mmap region at a high address */
-	if (mmap((void*) (1UL << (POINTER_SIZE - 1)) - pagesize,
-		 (size_t) ((1UL << (POINTER_SIZE - 1)) - pagesize),
+	if (mmap((void*) (1UL << (kernel_bits - 1)) - pagesize,

Since this has same range as below, shouldn't it be also 1ULL? Entire series looks OK to me.

Hmm, that produces warnings in case that sizeof(void) == 4 and with 64bit kernel since the value is truncated. I guess that the addres should be generated accordingly to the binary and not kernel after all because of address space limitations.

Quoted 7 lines
Quoted 1 line

Something as (((uintptr_t)1) << ((sizeof(void*)<<3) - 1) - pagesize)

Wouldn't this crash same as original?

On 32 bit, it seems that as soon as mmap touches "stack" we crash. On 64-bit I'm guessing map area is so high, that we get rejected immediately with ENOMEM.

Most likely here (for 64-bit case):

get_unmapped_area()
...
if (len > TASK_SIZE)
return -ENOMEM;

#define TASK_SIZE_MAX ((1UL << 47) - PAGE_SIZE)
and our len is almost half of address space.

Quoted 57 lines

Example of lowering size to 1M and targeting stack (32bit on 64bit kernel):

# uname -r
4.8.0-1.el7.test.x86_64

Address Kbytes RSS Dirty Mode Mapping
0000000008048000 56 56 56 r-x-- mmapstress03

0000000008048000       0       0       0 r-x-- mmapstress03
0000000008056000       4       4       4 r---- mmapstress03
0000000008056000       0       0       0 r---- mmapstress03
0000000008057000       4       4       4 rw--- mmapstress03
0000000008057000       0       0       0 rw--- mmapstress03
0000000008058000      12       0       0 rw---   [ anon ]
0000000008058000       0       0       0 rw---   [ anon ]
00000000f7519000       4       4       4 rw---   [ anon ]
00000000f7519000       0       0       0 rw---   [ anon ]
00000000f751a000    1756     920       0 r-x-- libc-2.17.so
00000000f751a000       0       0       0 r-x-- libc-2.17.so
00000000f76d1000       4       0       0 ----- libc-2.17.so
00000000f76d1000       0       0       0 ----- libc-2.17.so
00000000f76d2000       8       8       8 r---- libc-2.17.so
00000000f76d2000       0       0       0 r---- libc-2.17.so
00000000f76d4000       4       4       4 rw--- libc-2.17.so
00000000f76d4000       0       0       0 rw--- libc-2.17.so
00000000f76d5000      12       8       8 rw---   [ anon ]
00000000f76d5000       0       0       0 rw---   [ anon ]
00000000f76e7000     124     120       0 r-x-- ld-2.17.so
00000000f76e7000       0       0       0 r-x-- ld-2.17.so
00000000f7706000       4       4       4 rw---   [ anon ]
00000000f7706000       0       0       0 rw---   [ anon ]
00000000f7707000       4       4       4 r---- ld-2.17.so
00000000f7707000       0       0       0 r---- ld-2.17.so
00000000f7708000       4       4       4 rw--- ld-2.17.so
00000000f7708000       0       0       0 rw--- ld-2.17.so
00000000ff873000     132       8       8 rw---   [ stack ]
00000000ff873000       0       0       0 rw---   [ stack ]

---------------- ------- ------- -------
total kB 2132 1148 108

...
mmap2(0xff800000, 1048576, PROT_READ|PROT_WRITE, MAP_SHARED|MAP_FIXED|MAP_ANONYMOUS, 0, 0) = 0xffffffffff800000

killed by SIGSEGV +++ renamed from SIGSEGV {si_signo=SIGSEGV, si_code=SEGV_MAPERR, si_addr=0} --- +0 -0

Segmentation fault

Quoted 5 lines

--
Cyril Hrubis
[email protected]

--
Mailing list info: https://lists.linux.it/listinfo/ltp

#9 lore raw

PATCH 1/4 lib: Add tst_kernel_bits()

In reply to Cyril Hrubis

----- Original Message -----

Quoted 4 lines

This function returns 32 or 64 depending on if we are running on 32bit or 64bit kernel. This is detected from uname.machine string which seems to be good enough heuristic and even if that fails we can always add a special cases to the tst_kernel_bits() function.

ACK, though I keep thinking if there isn't something in /proc or /sys we could query and guess kernel bits from that.

Regards,
Jan

Quoted 103 lines
---
 include/tst_kernel.h | 26 ++++++++++++++++++++++++++
 include/tst_test.h   |  1 +
 lib/tst_kernel.c     | 36 ++++++++++++++++++++++++++++++++++++
 3 files changed, 63 insertions(+)
 create mode 100644 include/tst_kernel.h
 create mode 100644 lib/tst_kernel.c
include/tst_kernel.h new file +26 -0
new file mode 100644
index 0000000..5d5c04c
@@ -0,0 +1,26 @@
+/*
+ * Copyright (c) 2017 Cyril Hrubis <[email protected]>
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef TST_KERNEL_H__
+#define TST_KERNEL_H__
+
+/*
+ * Returns 32 if we are running on 32bit kernel and 64 if on 64bit kernel.
+ */
+int tst_kernel_bits(void);
+
+#endif	/* TST_KERNEL_H__ */
include/tst_test.h +1 -0
index 1492ff5..7ff33b2 100644
@@ -33,6 +33,7 @@
 #include "tst_atomic.h"
 #include "tst_kvercmp.h"
 #include "tst_clone.h"
+#include "tst_kernel.h"
 
 /*
  * Reports testcase result.
lib/tst_kernel.c new file +36 -1
new file mode 100644
index 0000000..7a53002
@@ -0,0 +1,36 @@
+/*
+ * Copyright (c) 2017 Cyril Hrubis <[email protected]>
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include <sys/utsname.h>
+#include "test.h"
+#include "tst_kernel.h"
+
+int tst_kernel_bits(void)
+{
+	struct utsname buf;
+	int kernel_bits;
+
+	if (uname(&buf))
+		tst_brkm(TBROK | TERRNO, NULL, "uname()");
+
+	kernel_bits = strstr(buf.machine, "64") ? 64 : 32;
+
+	tst_resm(TINFO, "uname.machine=%s kernel is %ibit",
+	         buf.machine, kernel_bits);
+
+	return kernel_bits;
+}
--

2.7.3

--
Mailing list info: https://lists.linux.it/listinfo/ltp

#10 lore raw

PATCH 1/4 lib: Add tst_kernel_bits()

Hi!

Quoted 7 lines
Quoted 4 lines

This function returns 32 or 64 depending on if we are running on 32bit or 64bit kernel. This is detected from uname.machine string which seems to be good enough heuristic and even if that fails we can always add a special cases to the tst_kernel_bits() function.

ACK, though I keep thinking if there isn't something in /proc or /sys we could query and guess kernel bits from that.

Unfortunately parsing the machine from uname was the only way I could came up with.

Signature · 2 lines
Cyril Hrubis
[email protected]