diff options
author | Eugene Syromyatnikov <evgsyr@gmail.com> | 2023-04-30 15:53:58 +0200 |
---|---|---|
committer | Eugene Syromyatnikov <evgsyr@gmail.com> | 2023-04-30 16:41:13 +0200 |
commit | 69a2a407b998a629e13e309eab3fb4364c0284fd (patch) | |
tree | ece298545101134543b4c4e3bc7235d8b07ed413 | |
parent | 471f3593bf491e9296b9b889a15ba636460850c2 (diff) | |
download | strace-esyr/hppa-madvise.tar.gz |
mem: handle hppa MADV_* UAPI breakageesyr/hppa-madvise
Linux commit v6.2-rc1~39^2~7 has broken UAPI on PA-RISC by changing
the values of some MADV_* constants; that forces some special handling
for them, since we cannot have any assumptions about the version
of the kernel headers and/or kernel both strace and tracees are built
and/or being run on.
* src/mem.c: Include "xlat/madvise_hppa_generic_cmds.h".
[HPPA]: Include "xlat/madvise_hppa_old_cmds.h".
(SYS_FUNC(madvise)) <advice>: New local variable, set to tcp->u_arg[2].
[HPPA] (SYS_FUNC(madvise)): Check madvise_hppa_old_cmds for the advice
value and print it appropriately if it is there; then check
madvise_hppa_generic_cmds and print it appropriately if it is there;
then fallback to printing advice as madvise_cmds xval.
[!HPPA] (SYS_FUNC(madvise)): Print advice as madvise_cmds
and madvise_hppa_generic_cmds xval.
* src/xlat/madvise_cmds.in: Add sorted; remove "Generated ..." comment;
move hppa-specific values to madvise_hppa_old_cmds.in and their generic
counterparts to madvise_hppa_generic_cmds.in.
* src/xlat/madvise_hppa_generic_cmds.in: New file.
* src/xlat/madvise_hppa_old_cmds.in: Likewise.
* tests/.gitignore: Add madvise-Xabbrev, madvise-Xraw,
and madvise-Xverbose.
* tests/pure_executables.list: Likewise.
* tests/gen_tests.in (advise-Xabbrev, madvise-Xraw, madvise-Xverbos):
New tests.
* tests/madvise.c: Add checks for the advice argument decoding.
* tests/madvise-Xabbrev.c: New file.
* tests/madvise-Xraw.c: Likewise.
* tests/madvise-Xverbose.c: Likewise.
* NEWS: Mention it.
Reported-by: Matoro Mahri <matoro@users.noreply.github.com>
Closes: https://github.com/strace/strace/issues/241
-rw-r--r-- | NEWS | 3 | ||||
-rw-r--r-- | src/mem.c | 40 | ||||
-rw-r--r-- | src/xlat/madvise_cmds.in | 111 | ||||
-rw-r--r-- | src/xlat/madvise_hppa_generic_cmds.in | 16 | ||||
-rw-r--r-- | src/xlat/madvise_hppa_old_cmds.in | 12 | ||||
-rw-r--r-- | tests/.gitignore | 3 | ||||
-rw-r--r-- | tests/gen_tests.in | 5 | ||||
-rw-r--r-- | tests/madvise-Xabbrev.c | 2 | ||||
-rw-r--r-- | tests/madvise-Xraw.c | 2 | ||||
-rw-r--r-- | tests/madvise-Xverbose.c | 2 | ||||
-rw-r--r-- | tests/madvise.c | 109 | ||||
-rwxr-xr-x | tests/pure_executables.list | 3 |
12 files changed, 212 insertions, 96 deletions
@@ -18,6 +18,9 @@ Noteworthy changes in release ?.? (????-??-??) and V4L2_PIX_FMT_* constants. * Updated lists of ioctl commands from Linux 6.3. +* Bug fixes + * Fixed build on hppa with uapi headers from Linux >= 6.2. + Noteworthy changes in release 6.2 (2023-02-26) ============================================== @@ -290,6 +290,11 @@ SYS_FUNC(mremap) } #include "xlat/madvise_cmds.h" +#include "xlat/madvise_hppa_generic_cmds.h" + +#if defined HPPA +# include "xlat/madvise_hppa_old_cmds.h" +#endif SYS_FUNC(madvise) { @@ -302,7 +307,40 @@ SYS_FUNC(madvise) tprint_arg_next(); /* advice */ - printxval(madvise_cmds, tcp->u_arg[2], "MADV_???"); + const unsigned int advice = tcp->u_arg[2]; +#if defined HPPA + /* + * hppa decided to be very special: it used to have its own + * definitions for some MADV_* constants (just like Alpha, + * for example), but then (see Linux commit v6.2-rc1~39^2~7) + * decided to change their values, so their symbolic names + * are meaningless for the user now (which would also probably + * add spice to debugging old binaries with the newer kernels + * "in year 2025 (or later)"), and that forces us to state + * explicitly which variant of the constant value is used. + */ + const char *old_cmd = xlookup(madvise_hppa_old_cmds, advice); + + if (old_cmd) { + PRINT_VAL_X(advice); + if (xlat_verbose(xlat_verbosity) != XLAT_STYLE_RAW) + tprintf_comment("old %s", old_cmd); + } else { + const char *new_cmd = xlookup(madvise_hppa_generic_cmds, + advice); + + if (new_cmd) { + PRINT_VAL_X(advice); + if (xlat_verbose(xlat_verbosity) != XLAT_STYLE_RAW) + tprintf_comment("new/generic %s", new_cmd); + } else { + printxval(madvise_cmds, advice, "MADV_???"); + } + } +#else + printxvals(advice, "MADV_???", + madvise_cmds, madvise_hppa_generic_cmds, NULL); +#endif return RVAL_DECODED; } diff --git a/src/xlat/madvise_cmds.in b/src/xlat/madvise_cmds.in index 8a1f9d8e2..decae9bf5 100644 --- a/src/xlat/madvise_cmds.in +++ b/src/xlat/madvise_cmds.in @@ -1,91 +1,32 @@ -/* Generated by maint/gen_xlat_defs.sh -f 'd' -p 'MADV_' -c 'asm-generic/mman-common.h' -a 'asm/mman.h' */ - -MADV_NORMAL 0 - -MADV_RANDOM 1 - -MADV_SEQUENTIAL 2 - -MADV_WILLNEED 3 +#sorted +MADV_NORMAL 0 +MADV_RANDOM 1 +MADV_SEQUENTIAL 2 +MADV_WILLNEED 3 #if defined __alpha__ -MADV_DONTNEED 6 -#else -MADV_DONTNEED 4 -#endif - -MADV_FREE 8 - -MADV_REMOVE 9 - -MADV_DONTFORK 10 - -MADV_DOFORK 11 - -#if defined __hppa__ -MADV_MERGEABLE 65 -#else -MADV_MERGEABLE 12 -#endif - -#if defined __hppa__ -MADV_UNMERGEABLE 66 -#else -MADV_UNMERGEABLE 13 -#endif - -#if defined __hppa__ -MADV_HUGEPAGE 67 -#else -MADV_HUGEPAGE 14 -#endif - -#if defined __hppa__ -MADV_NOHUGEPAGE 68 -#else -MADV_NOHUGEPAGE 15 -#endif - -#if defined __hppa__ -MADV_DONTDUMP 69 -#else -MADV_DONTDUMP 16 -#endif - -#if defined __hppa__ -MADV_DODUMP 70 -#else -MADV_DODUMP 17 -#endif - -#if defined __hppa__ -MADV_WIPEONFORK 71 -#else -MADV_WIPEONFORK 18 -#endif - -#if defined __hppa__ -MADV_KEEPONFORK 72 -#else -MADV_KEEPONFORK 19 -#endif - -MADV_COLD 20 - -MADV_PAGEOUT 21 - +MADV_DONTNEED 6 +#else +MADV_DONTNEED 4 +#endif + +MADV_FREE 8 +MADV_REMOVE 9 +MADV_DONTFORK 10 +MADV_DOFORK 11 +/* MADV_MERGEABLE 12 - see madvise_hppa_generic_cmds */ +/* MADV_UNMERGEABLE 13 - see madvise_hppa_generic_cmds */ +/* MADV_HUGEPAGE 14 - see madvise_hppa_generic_cmds */ +/* MADV_NOHUGEPAGE 15 - see madvise_hppa_generic_cmds */ +/* MADV_DONTDUMP 16 - see madvise_hppa_generic_cmds */ +/* MADV_DODUMP 17 - see madvise_hppa_generic_cmds */ +/* MADV_WIPEONFORK 18 - see madvise_hppa_generic_cmds */ +/* MADV_KEEPONFORK 19 - see madvise_hppa_generic_cmds */ +MADV_COLD 20 +MADV_PAGEOUT 21 MADV_POPULATE_READ 22 - MADV_POPULATE_WRITE 23 - MADV_DONTNEED_LOCKED 24 - -#if defined __hppa__ -MADV_COLLAPSE 73 -#else -MADV_COLLAPSE 25 -#endif - -MADV_HWPOISON 100 - +/* MADV_COLLAPSE 25 - see madvise_hppa_generic_cmds */ +MADV_HWPOISON 100 MADV_SOFT_OFFLINE 101 diff --git a/src/xlat/madvise_hppa_generic_cmds.in b/src/xlat/madvise_hppa_generic_cmds.in new file mode 100644 index 000000000..9740cab9b --- /dev/null +++ b/src/xlat/madvise_hppa_generic_cmds.in @@ -0,0 +1,16 @@ +#unconditional +#nocheckval +/* + * These values are used on hppa since v6.2-rc1~39^2~7 + * and on other architectures since their introduction; + * see madvise_hppa_old_cmds for the old values. + */ +MADV_MERGEABLE 12 +MADV_UNMERGEABLE 13 +MADV_HUGEPAGE 14 +MADV_NOHUGEPAGE 15 +MADV_DONTDUMP 16 +MADV_DODUMP 17 +MADV_WIPEONFORK 18 +MADV_KEEPONFORK 19 +MADV_COLLAPSE 25 diff --git a/src/xlat/madvise_hppa_old_cmds.in b/src/xlat/madvise_hppa_old_cmds.in new file mode 100644 index 000000000..b939fbba6 --- /dev/null +++ b/src/xlat/madvise_hppa_old_cmds.in @@ -0,0 +1,12 @@ +#unconditional +#nocheckval +/* These values were used on hppa before v6.2-rc1~39^2~7. */ +MADV_MERGEABLE 65 +MADV_UNMERGEABLE 66 +MADV_HUGEPAGE 67 +MADV_NOHUGEPAGE 68 +MADV_DONTDUMP 69 +MADV_DODUMP 70 +MADV_WIPEONFORK 71 +MADV_KEEPONFORK 72 +MADV_COLLAPSE 73 diff --git a/tests/.gitignore b/tests/.gitignore index d0f99f01e..15073a0f9 100644 --- a/tests/.gitignore +++ b/tests/.gitignore @@ -486,6 +486,9 @@ lseek lstat lstat64 madvise +madvise-Xabbrev +madvise-Xraw +madvise-Xverbose maybe_switch_current_tcp maybe_switch_current_tcp--quiet-thread-execve mbind diff --git a/tests/gen_tests.in b/tests/gen_tests.in index 22807ae38..98bee712a 100644 --- a/tests/gen_tests.in +++ b/tests/gen_tests.in @@ -497,7 +497,10 @@ linkat--secontext_mismatch --secontext=mismatch -e trace=linkat lookup_dcookie -a27 lstat -a31 --no-abbrev --trace-path=stat.sample --trace-path=/dev/full lstat64 -a32 --no-abbrev --trace-path=stat.sample --trace-path=/dev/full -madvise -a33 +madvise -a31 +madvise-Xabbrev --trace=madvise -a31 -Xabbrev +madvise-Xraw --trace=madvise -a23 -Xraw +madvise-Xverbose --trace=madvise -a40 -Xverbose maybe_switch_current_tcp -a30 -f -e trace=execveat maybe_switch_current_tcp--quiet-thread-execve -a30 -s48 -f -e trace=execveat --quiet=personality,thread-execve mbind diff --git a/tests/madvise-Xabbrev.c b/tests/madvise-Xabbrev.c new file mode 100644 index 000000000..b5daa027d --- /dev/null +++ b/tests/madvise-Xabbrev.c @@ -0,0 +1,2 @@ +#define XLAT_ABBREV 1 +#include "madvise.c" diff --git a/tests/madvise-Xraw.c b/tests/madvise-Xraw.c new file mode 100644 index 000000000..8d990e398 --- /dev/null +++ b/tests/madvise-Xraw.c @@ -0,0 +1,2 @@ +#define XLAT_RAW 1 +#include "madvise.c" diff --git a/tests/madvise-Xverbose.c b/tests/madvise-Xverbose.c new file mode 100644 index 000000000..4c3ae997a --- /dev/null +++ b/tests/madvise-Xverbose.c @@ -0,0 +1,2 @@ +#define XLAT_VERBOSE 1 +#include "madvise.c" diff --git a/tests/madvise.c b/tests/madvise.c index 51118c6a0..9df952bbe 100644 --- a/tests/madvise.c +++ b/tests/madvise.c @@ -32,26 +32,117 @@ main(void) long rc; rc = madvise(addr, length, MADV_NORMAL); - printf("madvise(%p, %lu, MADV_NORMAL) = %s\n", - addr, length, sprintrc(rc)); + printf("madvise(%p, %lu, " XLAT_FMT ") = %s\n", + addr, length, XLAT_ARGS(MADV_NORMAL), sprintrc(rc)); static const kernel_ulong_t advice = (kernel_ulong_t) 0xfacefeed00000000ULL | MADV_RANDOM; rc = k_madvise((uintptr_t) addr, length, advice); - printf("madvise(%p, %lu, MADV_RANDOM) = %s\n", - addr, length, sprintrc(rc)); + printf("madvise(%p, %lu, " XLAT_FMT ") = %s\n", + addr, length, XLAT_ARGS(MADV_RANDOM), sprintrc(rc)); static const kernel_ulong_t bogus_length = (kernel_ulong_t) 0xfffffffffffffaceULL; rc = k_madvise(0, bogus_length, MADV_SEQUENTIAL); - printf("madvise(NULL, %llu, MADV_SEQUENTIAL) = %s\n", - (unsigned long long) bogus_length, sprintrc(rc)); + printf("madvise(NULL, %llu, " XLAT_FMT ") = %s\n", + (unsigned long long) bogus_length, + XLAT_ARGS(MADV_SEQUENTIAL), sprintrc(rc)); if (F8ILL_KULONG_SUPPORTED) { - rc = k_madvise(f8ill_ptr_to_kulong(addr), length, MADV_NORMAL); - printf("madvise(%#llx, %lu, MADV_NORMAL) = %s\n", + rc = k_madvise(f8ill_ptr_to_kulong(addr), length, + MADV_WILLNEED); + printf("madvise(%#llx, %lu, " XLAT_FMT ") = %s\n", (unsigned long long) f8ill_ptr_to_kulong(addr), - length, sprintrc(rc)); + length, XLAT_ARGS(MADV_WILLNEED), sprintrc(rc)); + } + + static const struct strval32 advices[] = { +#ifdef __alpha__ + { 4, "0x4" NRAW(" /* MADV_??? */") }, + { ARG_XLAT_KNOWN(0x6, "MADV_DONTNEED") }, +#else + { ARG_XLAT_KNOWN(0x4, "MADV_DONTNEED") }, + { 6, "0x6" NRAW(" /* MADV_??? */") }, +#endif + { 5, "0x5" NRAW(" /* MADV_??? */") }, + { 7, "0x7" NRAW(" /* MADV_??? */") }, + { ARG_XLAT_KNOWN(0x8, "MADV_FREE") }, + { ARG_XLAT_KNOWN(0x9, "MADV_REMOVE") }, + { ARG_XLAT_KNOWN(0xa, "MADV_DONTFORK") }, + { ARG_XLAT_KNOWN(0xb, "MADV_DOFORK") }, +#ifdef __hppa__ + { 12, "0xc" NRAW(" /* new/generic MADV_MERGEABLE */") }, + { 13, "0xd" NRAW(" /* new/generic MADV_UNMERGEABLE */") }, + { 14, "0xe" NRAW(" /* new/generic MADV_HUGEPAGE */") }, + { 15, "0xf" NRAW(" /* new/generic MADV_NOHUGEPAGE */") }, + { 16, "0x10" NRAW(" /* new/generic MADV_DONTDUMP */") }, + { 17, "0x11" NRAW(" /* new/generic MADV_DODUMP */") }, + { 18, "0x12" NRAW(" /* new/generic MADV_WIPEONFORK */") }, + { 19, "0x13" NRAW(" /* new/generic MADV_KEEPONFORK */") }, +#else + { ARG_XLAT_KNOWN(0xc, "MADV_MERGEABLE") }, + { ARG_XLAT_KNOWN(0xd, "MADV_UNMERGEABLE") }, + { ARG_XLAT_KNOWN(0xe, "MADV_HUGEPAGE") }, + { ARG_XLAT_KNOWN(0xf, "MADV_NOHUGEPAGE") }, + { ARG_XLAT_KNOWN(0x10, "MADV_DONTDUMP") }, + { ARG_XLAT_KNOWN(0x11, "MADV_DODUMP") }, + { ARG_XLAT_KNOWN(0x12, "MADV_WIPEONFORK") }, + { ARG_XLAT_KNOWN(0x13, "MADV_KEEPONFORK") }, +#endif + { ARG_XLAT_KNOWN(0x14, "MADV_COLD") }, + { ARG_XLAT_KNOWN(0x15, "MADV_PAGEOUT") }, + { ARG_XLAT_KNOWN(0x16, "MADV_POPULATE_READ") }, + { ARG_XLAT_KNOWN(0x17, "MADV_POPULATE_WRITE") }, + { ARG_XLAT_KNOWN(0x18, "MADV_DONTNEED_LOCKED") }, +#ifdef __hppa__ + { 25, "0x19" NRAW(" /* new/generic MADV_COLLAPSE */") }, +#else + { ARG_XLAT_KNOWN(0x19, "MADV_COLLAPSE") }, +#endif + { ARG_XLAT_UNKNOWN(0x1a, "MADV_???") }, + + { ARG_XLAT_UNKNOWN(0x40, "MADV_???") }, +#ifdef __hppa__ + { 65, "0x41" NRAW(" /* old MADV_MERGEABLE */") }, + { 66, "0x42" NRAW(" /* old MADV_UNMERGEABLE */") }, + { 67, "0x43" NRAW(" /* old MADV_HUGEPAGE */") }, + { 68, "0x44" NRAW(" /* old MADV_NOHUGEPAGE */") }, + { 69, "0x45" NRAW(" /* old MADV_DONTDUMP */") }, + { 70, "0x46" NRAW(" /* old MADV_DODUMP */") }, + { 71, "0x47" NRAW(" /* old MADV_WIPEONFORK */") }, + { 72, "0x48" NRAW(" /* old MADV_KEEPONFORK */") }, + { 73, "0x49" NRAW(" /* old MADV_COLLAPSE */") }, +#else + { ARG_XLAT_UNKNOWN(0x41, "MADV_???") }, + { ARG_XLAT_UNKNOWN(0x42, "MADV_???") }, + { ARG_XLAT_UNKNOWN(0x43, "MADV_???") }, + { ARG_XLAT_UNKNOWN(0x44, "MADV_???") }, + { ARG_XLAT_UNKNOWN(0x45, "MADV_???") }, + { ARG_XLAT_UNKNOWN(0x46, "MADV_???") }, + { ARG_XLAT_UNKNOWN(0x47, "MADV_???") }, + { ARG_XLAT_UNKNOWN(0x48, "MADV_???") }, + { ARG_XLAT_UNKNOWN(0x49, "MADV_???") }, +#endif + { ARG_XLAT_UNKNOWN(0x4a, "MADV_???") }, + + { ARG_XLAT_UNKNOWN(0x63, "MADV_???") }, + { ARG_XLAT_KNOWN(0x64, "MADV_HWPOISON") }, + { ARG_XLAT_KNOWN(0x65, "MADV_SOFT_OFFLINE") }, + { ARG_XLAT_UNKNOWN(0x66, "MADV_???") }, + + { ARG_XLAT_UNKNOWN(0x80, "MADV_???") }, + { ARG_XLAT_UNKNOWN(0x81, "MADV_???") }, + { ARG_XLAT_UNKNOWN(0x100, "MADV_???") }, + { ARG_XLAT_UNKNOWN(0x101, "MADV_???") }, + { ARG_XLAT_UNKNOWN(0x1000, "MADV_???") }, + { ARG_XLAT_UNKNOWN(0x1001, "MADV_???") }, + { ARG_XLAT_UNKNOWN(0xbadc0ded, "MADV_???") }, + }; + + for (unsigned int i = 0; i < ARRAY_SIZE(advices); i++) { + rc = madvise(NULL, length, advices[i].val); + printf("madvise(NULL, %lu, %s) = %s\n", + length, advices[i].str, sprintrc(rc)); } puts("+++ exited with 0 +++"); diff --git a/tests/pure_executables.list b/tests/pure_executables.list index 9948e9c2a..14f88ea0a 100755 --- a/tests/pure_executables.list +++ b/tests/pure_executables.list @@ -322,6 +322,9 @@ lseek lstat lstat64 madvise +madvise-Xabbrev +madvise-Xraw +madvise-Xverbose maybe_switch_current_tcp maybe_switch_current_tcp--quiet-thread-execve mbind |