]> git.ipfire.org Git - thirdparty/valgrind.git/commitdiff
Add FreeBSD shm_open2 syscall wrapper
authorPaul Floyd <pjfloyd@wanadoo.fr>
Mon, 9 May 2022 09:05:49 +0000 (11:05 +0200)
committerPaul Floyd <pjfloyd@wanadoo.fr>
Mon, 9 May 2022 09:05:49 +0000 (11:05 +0200)
coregrind/m_syswrap/priv_syswrap-freebsd.h
coregrind/m_syswrap/syswrap-freebsd.c
memcheck/tests/freebsd/scalar_13_plus.c
memcheck/tests/freebsd/scalar_13_plus.stderr.exp

index 36a48ac1ffe1d1e77beaffea5b1fc1a1e1c87a67..5d6bec529cf8520d6543faeb789c0b3b93b3d55b 100644 (file)
@@ -533,7 +533,7 @@ DECL_TEMPLATE(freebsd, sys___sysctlbyname) // 570
 #if (FREEBSD_VERS >= FREEBSD_13_0)
 // looks like close_range got backported
 // to 12.2 leaving these 4 marked as UNIMPL in 12.2
-// unimpl __NR_shm_open2           571
+DECL_TEMPLATE(freebsd, sys_shm_open2) // 571
 // unimpl __NR_shm_rename          572
 // unimpl __NR_sigfastblock        573
 DECL_TEMPLATE(freebsd, sys___realpathat) // 574
index 64260f8a9aff9e3034641ee08702a30dcd76be0b..eed1b5a6da377c4cc4bde5946b8469f0ecafc46b 100644 (file)
@@ -6221,7 +6221,43 @@ POST(sys___sysctlbyname)
 
 #if (FREEBSD_VERS >= FREEBSD_13_0)
 
-// SYS___realpathat 474
+// SYS_shm_open2   571
+// from syscalls.master
+// int shm_open2(_In_z_ const char *path,
+//               int flags,
+//               mode_t mode,
+//               int shmflags,
+//               _In_z_ const char *name);
+PRE(sys_shm_open2)
+{
+   PRE_REG_READ5(int, "shm_open2",
+                 const char *, path, int, flags, vki_mode_t, mode, int, shmflags, const char*, name);
+   if (ARG1 == VKI_SHM_ANON) {
+      PRINT("sys_shm_open2(%#" FMT_REGWORD "x(SHM_ANON), %" FMT_REGWORD "u, %hu, %d, %#" FMT_REGWORD "x(%s))",
+            ARG1, ARG2, (vki_mode_t)ARG3, (Int)ARG4, ARG5, (HChar*)ARG5);
+   } else {
+      PRINT("sys_shm_open2(%#" FMT_REGWORD "x(%s), %" FMT_REGWORD "u, %hu, %d, %#" FMT_REGWORD "x(%s))",
+            ARG1, (HChar *)ARG1, ARG2, (vki_mode_t)ARG3, (Int)ARG4, ARG5, (HChar*)ARG5);
+      PRE_MEM_RASCIIZ( "shm_open2(path)", ARG1 );
+   }
+
+    PRE_MEM_RASCIIZ( "shm_open2(name)", ARG5 );
+   *flags |= SfMayBlock;
+}
+
+POST(sys_shm_open2)
+{
+   vg_assert(SUCCESS);
+   if (!ML_(fd_allowed)(RES, "shm_open2", tid, True)) {
+      VG_(close)(RES);
+      SET_STATUS_Failure( VKI_EMFILE );
+   } else {
+      if (VG_(clo_track_fds))
+         ML_(record_fd_open_with_given_name)(tid, RES, (HChar*)ARG1);
+   }
+}
+
+// SYS___realpathat 574
 // from syscalls.master
 //         int __realpathat(int fd,
 //         _In_z_ const char *path,
@@ -6969,7 +7005,7 @@ const SyscallTableEntry ML_(syscall_table)[] = {
    BSDXY(__NR___sysctlbyname,   sys___sysctlbyname),    // 570
 
 #if (FREEBSD_VERS >= FREEBSD_13_0)
-   // unimpl __NR_shm_open2           571
+   BSDXY(__NR_shm_open2,        sys_shm_open2),         // 571
    // unimpl __NR_shm_rename          572
    // unimpl __NR_sigfastblock        573
    BSDXY( __NR___realpathat,    sys___realpathat),      // 574
index 5cb8102465d3d90a3cf455b0703f97a59f3c0342..a0f5dfe363fd8a038ad9a388ee57a3926eef2c68 100644 (file)
@@ -5,6 +5,10 @@ int main(void)
    long *px = malloc(2*sizeof(long));
    x0 = px[0];
 
+   /* SYS_shm_open2                      571 */
+   GO(SYS_shm_open2, " 5s 2m");
+   SY(SYS_shm_open2, x0, x0+1, x0+2, x0+3, x0); FAIL;
+
    /* SYS___realpathat                   574 */
    GO(SYS___realpathat, " 5s 2m");
    SY(SYS___realpathat, x0+0xffff, x0, x0, x0+100, x0+2); FAIL;
index 91721fc7af36b2086ffa68d4b7f73af6b943c7e2..02447b53aec17583ad18ff430dee62571cea9e81 100644 (file)
@@ -1,3 +1,29 @@
+---------------------------------------------------------
+571:           SYS_shm_open2  5s 2m
+---------------------------------------------------------
+Syscall param shm_open2(path) contains uninitialised byte(s)
+   ...
+
+Syscall param shm_open2(flags) contains uninitialised byte(s)
+   ...
+
+Syscall param shm_open2(mode) contains uninitialised byte(s)
+   ...
+
+Syscall param shm_open2(shmflags) contains uninitialised byte(s)
+   ...
+
+Syscall param shm_open2(name) contains uninitialised byte(s)
+   ...
+
+Syscall param shm_open2(path) points to unaddressable byte(s)
+   ...
+ Address 0x........ is not stack'd, malloc'd or (recently) free'd
+
+Syscall param shm_open2(name) points to unaddressable byte(s)
+   ...
+ Address 0x........ is not stack'd, malloc'd or (recently) free'd
+
 ---------------------------------------------------------
 574:        SYS___realpathat  5s 2m
 ---------------------------------------------------------