]> git.ipfire.org Git - thirdparty/valgrind.git/commitdiff
Bug 501846 - Add x86 Linux shm wrappers
authorPaul Floyd <pjfloyd@wanadoo.fr>
Fri, 21 Mar 2025 20:41:55 +0000 (21:41 +0100)
committerPaul Floyd <pjfloyd@wanadoo.fr>
Fri, 21 Mar 2025 20:41:55 +0000 (21:41 +0100)
.gitignore
NEWS
coregrind/m_syswrap/syswrap-x86-linux.c
memcheck/tests/x86-linux/Makefile.am
memcheck/tests/x86-linux/shm.c [new file with mode: 0644]
memcheck/tests/x86-linux/shm.stderr.exp [new file with mode: 0644]
memcheck/tests/x86-linux/shm.vgtest [new file with mode: 0644]

index c394d271752560c50d4327f6147a356a4f8c6858..45290719a6bce52c00a97657656bb8800b3dcf73 100644 (file)
 /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 7ea84cdc735eebb1a496ce82fc8d4ce871fb9f7a..7c0bba57744c7e3859271047c9c50804526534ec 100644 (file)
--- 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
index 13c9a3386510d6e78cafb3af74e27eb9c1c9900b..c4b00bd3f45bc21b2d530a6f6cab59852277756c 100644 (file)
@@ -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
 
index 7e91aaf8b4382215cf8194b5d493229cb8b925cd..e8de590b3e58df6fe5321f7f290d97fc3a986f45 100644 (file)
@@ -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 (file)
index 0000000..fcc9a78
--- /dev/null
@@ -0,0 +1,37 @@
+#define _GNU_SOURCE
+#include <stdio.h>
+#include <stdlib.h>
+#include <assert.h>
+#include <sys/ipc.h>
+#include <sys/shm.h>
+#include <sys/stat.h>
+#include <sys/mman.h>
+#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 (file)
index 0000000..58e8a24
--- /dev/null
@@ -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 (file)
index 0000000..19ba6e1
--- /dev/null
@@ -0,0 +1,2 @@
+prog: shm
+vgopts: -q