From 0d0a50aa2511f7fd0b32af41e6b18e34e37e6345 Mon Sep 17 00:00:00 2001 From: "Dmitry V. Levin" Date: Sun, 15 Nov 2015 02:35:57 +0000 Subject: [PATCH] Implement mlock2 syscall decoding * mem.c: Include "xlat/mlock_flags.h". (SYS_FUNC(mlock2)): New function. * xlat/mlock_flags.in: New file. * xlat/mlockall_flags.in: Add MCL_ONFAULT, add default values. * linux/dummy.h (mlock2): Remove. * tests/mlock2.c: New file. * tests/mlock2.test: New test. * tests/Makefile.am (check_PROGRAMS): Add mlock2. (TESTS): Add mlock2.test. * tests/.gitignore Add mlock2. --- linux/dummy.h | 1 - mem.c | 11 +++++++++++ tests/.gitignore | 1 + tests/Makefile.am | 2 ++ tests/mlock2.c | 25 +++++++++++++++++++++++++ tests/mlock2.test | 13 +++++++++++++ xlat/mlock_flags.in | 1 + xlat/mlockall_flags.in | 5 +++-- 8 files changed, 56 insertions(+), 3 deletions(-) create mode 100644 tests/mlock2.c create mode 100755 tests/mlock2.test create mode 100644 xlat/mlock_flags.in diff --git a/linux/dummy.h b/linux/dummy.h index e856bc99..ca76d0af 100644 --- a/linux/dummy.h +++ b/linux/dummy.h @@ -37,7 +37,6 @@ #define sys_kcmp printargs #define sys_kexec_file_load printargs #define sys_lookup_dcookie printargs -#define sys_mlock2 printargs #define sys_name_to_handle_at printargs #define sys_open_by_handle_at printargs #define sys_sysfs printargs diff --git a/mem.c b/mem.c index 8867f1ee..c7c41cff 100644 --- a/mem.c +++ b/mem.c @@ -247,6 +247,17 @@ SYS_FUNC(msync) return RVAL_DECODED; } +#include "xlat/mlock_flags.h" + +SYS_FUNC(mlock2) +{ + printaddr(tcp->u_arg[0]); + tprintf(", %lu, ", tcp->u_arg[1]); + printflags(mlock_flags, tcp->u_arg[2], "MLOCK_???"); + + return RVAL_DECODED; +} + SYS_FUNC(mincore) { if (entering(tcp)) { diff --git a/tests/.gitignore b/tests/.gitignore index 79585e1a..8e2919a9 100644 --- a/tests/.gitignore +++ b/tests/.gitignore @@ -20,6 +20,7 @@ ipc_sem ipc_shm membarrier memfd_create +mlock2 mmap mmap64 mmsg diff --git a/tests/Makefile.am b/tests/Makefile.am index 5aae4bd0..fe5f0bf5 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -33,6 +33,7 @@ check_PROGRAMS = \ ipc_shm \ membarrier \ memfd_create \ + mlock2 \ mmap \ mmap64 \ mmsg \ @@ -148,6 +149,7 @@ TESTS = \ sysinfo.test \ membarrier.test \ memfd_create.test \ + mlock2.test \ mmap.test \ mmap64.test \ mmsg.test \ diff --git a/tests/mlock2.c b/tests/mlock2.c new file mode 100644 index 00000000..fe662d20 --- /dev/null +++ b/tests/mlock2.c @@ -0,0 +1,25 @@ +#ifdef HAVE_CONFIG_H +# include "config.h" +#endif + +#include +#include +#include +#include + +int +main(void) +{ +#ifdef __NR_mlock2 + if (syscall(__NR_mlock2, 0xdeadbeef, 0xdefaced, 0xffff) != -1) + return 77; + printf("mlock2(0xdeadbeef, 233811181, MLOCK_ONFAULT|0xfffe) = -1 %s\n", + errno == ENOSYS ? + "ENOSYS (Function not implemented)" : + "EINVAL (Invalid argument)"); + puts("+++ exited with 0 +++"); + return 0; +#else + return 77; +#endif +} diff --git a/tests/mlock2.test b/tests/mlock2.test new file mode 100755 index 00000000..fdbcfdef --- /dev/null +++ b/tests/mlock2.test @@ -0,0 +1,13 @@ +#!/bin/sh + +# Check mlock2 syscall decoding. + +. "${srcdir=.}/init.sh" + +run_prog > /dev/null +OUT="$LOG.out" +run_strace -e mlock2 $args > "$OUT" +match_diff "$OUT" "$LOG" +rm -f "$OUT" + +exit 0 diff --git a/xlat/mlock_flags.in b/xlat/mlock_flags.in new file mode 100644 index 00000000..b285e673 --- /dev/null +++ b/xlat/mlock_flags.in @@ -0,0 +1 @@ +MLOCK_ONFAULT 1 diff --git a/xlat/mlockall_flags.in b/xlat/mlockall_flags.in index ba28847b..a39d7ba0 100644 --- a/xlat/mlockall_flags.in +++ b/xlat/mlockall_flags.in @@ -1,2 +1,3 @@ -MCL_CURRENT -MCL_FUTURE +MCL_CURRENT 1 +MCL_FUTURE 2 +MCL_ONFAULT 4 -- 2.40.0