From: Paul Floyd Date: Fri, 21 Mar 2025 20:41:55 +0000 (+0100) Subject: Bug 501846 - Add x86 Linux shm wrappers X-Git-Tag: VALGRIND_3_25_0~95 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=afea9317a1c958cdac72c9f55a27c9ecd1253eb8;p=thirdparty%2Fvalgrind.git Bug 501846 - Add x86 Linux shm wrappers --- diff --git a/.gitignore b/.gitignore index c394d2717..45290719a 100644 --- a/.gitignore +++ b/.gitignore @@ -1384,6 +1384,7 @@ /memcheck/tests/x86-linux/scalar_fork /memcheck/tests/x86-linux/scalar_supp /memcheck/tests/x86-linux/scalar_vfork +/memcheck/tests/x86-linux/shm # /memcheck/tests/x86-solaris/ /memcheck/tests/x86-solaris/*.stderr.diff diff --git a/NEWS b/NEWS index 7ea84cdc7..7c0bba577 100644 --- a/NEWS +++ b/NEWS @@ -63,6 +63,7 @@ are not entered into bugzilla tend to get forgotten about or ignored. 501348 glibc built with -march=x86-64-v3 does not work due to ld.so memcmp 501479 Illumos DRD pthread_mutex_init wrapper errors 501365 syscall userfaultfd not wrapped +501846 Add x86 Linux shm wrappers To see details of a given bug, visit diff --git a/coregrind/m_syswrap/syswrap-x86-linux.c b/coregrind/m_syswrap/syswrap-x86-linux.c index 13c9a3386..c4b00bd3f 100644 --- a/coregrind/m_syswrap/syswrap-x86-linux.c +++ b/coregrind/m_syswrap/syswrap-x86-linux.c @@ -1622,6 +1622,11 @@ static SyscallTableEntry syscall_table[] = { GENX_(__NR_rseq, sys_ni_syscall), // 386 + LINX_(__NR_shmget, sys_shmget), // 395 + LINX_(__NR_shmctl, sys_shmctl), // 396 + LINX_(__NR_shmat, sys_shmat), // 397 + LINX_(__NR_shmdt, sys_shmdt), // 398 + LINXY(__NR_clock_gettime64, sys_clock_gettime64), // 403 LINX_(__NR_clock_settime64, sys_clock_settime64), // 404 diff --git a/memcheck/tests/x86-linux/Makefile.am b/memcheck/tests/x86-linux/Makefile.am index 7e91aaf8b..e8de590b3 100644 --- a/memcheck/tests/x86-linux/Makefile.am +++ b/memcheck/tests/x86-linux/Makefile.am @@ -17,12 +17,14 @@ EXTRA_DIST = \ scalar_supp.stderr.exp \ scalar_supp.vgtest scalar_supp.supp \ scalar_vfork.stderr.exp scalar_vfork.vgtest \ - scalar_openat2.vgtest scalar_openat2.stderr.exp + scalar_openat2.vgtest scalar_openat2.stderr.exp \ + shm.vgtest shm.stderr.exp check_PROGRAMS = \ bug133694 \ int3-x86 \ - scalar scalar_exit_group scalar_fork scalar_supp scalar_vfork + scalar scalar_exit_group scalar_fork scalar_supp scalar_vfork \ + shm if HAVE_OPENAT2 check_PROGRAMS += scalar_openat2 @@ -38,3 +40,4 @@ if HAVE_OPENAT2 scalar_openat2_CFLAGS = $(AM_CFLAGS) @FLAG_W_NO_UNINITIALIZED@ endif scalar_supp_CFLAGS = $(AM_CFLAGS) @FLAG_W_NO_UNINITIALIZED@ +shm_CFLAGS = ${AM_CFLAGS} @FLAG_W_NO_UNINITIALIZED@ diff --git a/memcheck/tests/x86-linux/shm.c b/memcheck/tests/x86-linux/shm.c new file mode 100644 index 000000000..fcc9a7856 --- /dev/null +++ b/memcheck/tests/x86-linux/shm.c @@ -0,0 +1,37 @@ +#define _GNU_SOURCE +#include +#include +#include +#include +#include +#include +#include +#include "../../memcheck.h" +#include "scalar.h" + +int main(void) +{ + // uninitialised, but we know px[0] is 0x0 + long* px = malloc(sizeof(long)); + long x0 = px[0]; + long res; + + GO(__NR_shmget, "3s 0m"); + SY(__NR_shmget, x0+IPC_PRIVATE, x0+1024, x0 | IPC_CREAT | IPC_EXCL | S_IRUSR | S_IWUSR); SUCC; + + long id = res; + + GO(__NR_shmat, "3s 0m"); + SY(__NR_shmat, x0+id, x0, x0); SUCC; + + void* mem = (void*)res; + struct shmid_ds buf; + VALGRIND_MAKE_MEM_NOACCESS(&buf, sizeof(buf)); + GO(__NR_shmctl, "3s 0m"); + SY(__NR_shmctl, x0+id, x0 | IPC_INFO, x0+&buf); SUCC; + + GO(__NR_shmdt, "1s 0m"); + SY(__NR_shmdt, x0+mem); SUCC; + + SY(__NR_shmctl, id, IPC_RMID, NULL); +} diff --git a/memcheck/tests/x86-linux/shm.stderr.exp b/memcheck/tests/x86-linux/shm.stderr.exp new file mode 100644 index 000000000..58e8a2417 --- /dev/null +++ b/memcheck/tests/x86-linux/shm.stderr.exp @@ -0,0 +1,58 @@ +----------------------------------------------------- +395: __NR_shmget 3s 0m +----------------------------------------------------- +Syscall param shmget(key) contains uninitialised byte(s) + ... + by 0x........: main (shm.c:20) + +Syscall param shmget(size) contains uninitialised byte(s) + ... + by 0x........: main (shm.c:20) + +Syscall param shmget(shmflg) contains uninitialised byte(s) + ... + by 0x........: main (shm.c:20) + +----------------------------------------------------- +397: __NR_shmat 3s 0m +----------------------------------------------------- +Syscall param shmat(shmid) contains uninitialised byte(s) + ... + by 0x........: main (shm.c:25) + +Syscall param shmat(shmaddr) contains uninitialised byte(s) + ... + by 0x........: main (shm.c:25) + +Syscall param shmat(shmflg) contains uninitialised byte(s) + ... + by 0x........: main (shm.c:25) + +----------------------------------------------------- +396: __NR_shmctl 3s 0m +----------------------------------------------------- +Syscall param shmctl(shmid) contains uninitialised byte(s) + ... + by 0x........: main (shm.c:31) + +Syscall param shmctl(cmd) contains uninitialised byte(s) + ... + by 0x........: main (shm.c:31) + +Syscall param shmctl(buf) contains uninitialised byte(s) + ... + by 0x........: main (shm.c:31) + +Syscall param shmctl(IPC_INFO, buf) points to unaddressable byte(s) + ... + by 0x........: main (shm.c:31) + Address 0x........ is on thread 1's stack + in frame #1, created by main (shm.c:13) + +----------------------------------------------------- +398: __NR_shmdt 1s 0m +----------------------------------------------------- +Syscall param shmdt(shmaddr) contains uninitialised byte(s) + ... + by 0x........: main (shm.c:34) + diff --git a/memcheck/tests/x86-linux/shm.vgtest b/memcheck/tests/x86-linux/shm.vgtest new file mode 100644 index 000000000..19ba6e1a0 --- /dev/null +++ b/memcheck/tests/x86-linux/shm.vgtest @@ -0,0 +1,2 @@ +prog: shm +vgopts: -q