]> git.ipfire.org Git - thirdparty/valgrind.git/commitdiff
Bug 390269 - unhandled amd64-darwin syscall: unix:464 (openat_nocancel)
authorPaul Floyd <pjfloyd@wanadoo.fr>
Mon, 20 Nov 2023 11:59:12 +0000 (12:59 +0100)
committerPaul Floyd <pjfloyd@wanadoo.fr>
Mon, 20 Nov 2023 11:59:12 +0000 (12:59 +0100)
Copied from https://github.com/LouisBrunner/valgrind-macos.git

Regtest to come shortly

NEWS
coregrind/m_syswrap/priv_syswrap-darwin.h
coregrind/m_syswrap/syswrap-darwin.c
include/vki/vki-scnums-darwin.h

diff --git a/NEWS b/NEWS
index 1bfdd52615becd5814844bb9cd0392b3df1df9b6..223d7233cbdf47c53fb6d7525f5f82b70ea9139e 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -24,6 +24,7 @@ than mailing the developers (or mailing lists) directly -- bugs that
 are not entered into bugzilla tend to get forgotten about or ignored.
 
 
+390269  unhandled amd64-darwin syscall: unix:464 (openat_nocancel)
 401284  False positive "Source and destination overlap in strncat"
 428364  Signals inside io_uring_enter not handled
 437790  valgrind reports "Conditional jump or move depends on uninitialised
index f31cde0c4149b5d22109b9ecb6b022134183f47d..cb31fb51b11417e0fef770ac99bc5f0fcaf0b168 100644 (file)
@@ -572,8 +572,10 @@ DECL_TEMPLATE(darwin, getattrlistbulk);          // 461
 // NYI clonefileat     // 462
 #endif /* DARWIN_VERS >= DARWIN_10_12 */
 #if DARWIN_VERS >= DARWIN_10_10
-// NYI openat          // 463
-// NYI openat_nocancel // 464
+DECL_TEMPLATE(darwin, openat);                   // 463
+#if DARWIN_VERS >= DARWIN_10_13
+DECL_TEMPLATE(darwin, openat_nocancel);          // 464
+#endif
 // NYI renameat        // 465
 DECL_TEMPLATE(darwin, faccessat);                // 466
 // NYI fchmodat        // 467
index cc7ee3e70ebf7eda75ab7a95fa654c80cce26983..d8e88ccb81d411db41b9c1e50bcf36c683434981 100644 (file)
@@ -9836,6 +9836,48 @@ PRE(guarded_writev_np)
         ARG1, ARG2, ARG3, (ULong)ARG4);
 }
 
+PRE(openat)
+{
+   if (ARG3 & VKI_O_CREAT) {
+      // 4-arg version
+      PRINT("sys_openat ( %ld, %#" FMT_REGWORD "x(%s), %ld, %ld )",
+            SARG1, ARG2, (HChar*)(Addr)ARG2, SARG3, SARG4);
+      PRE_REG_READ4(long, "openat",
+                    int, dfd, const char *, filename, int, flags, int, mode);
+   } else {
+     // 3-arg version
+     PRINT("sys_openat ( %ld, %#" FMT_REGWORD "x(%s), %ld )",
+           SARG1, ARG2, (HChar*)(Addr)ARG2, SARG3);
+     PRE_REG_READ3(long, "openat",
+                   int, dfd, const char *, filename, int, flags);
+   }
+   PRE_MEM_RASCIIZ( "openat(filename)", ARG2 );
+
+   /* For absolute filenames, dfd is ignored.  If dfd is AT_FDCWD,
+      filename is relative to cwd.  When comparing dfd against AT_FDCWD,
+      be sure only to compare the bottom 32 bits. */
+   if (ML_(safe_to_deref)( (void*)(Addr)ARG2, 1 )
+       && *(Char *)(Addr)ARG2 != '/'
+       && ((Int)ARG1) != ((Int)VKI_AT_FDCWD)
+       && !ML_(fd_allowed)(ARG1, "openat", tid, False))
+      SET_STATUS_Failure( VKI_EBADF );
+
+   /* Otherwise handle normally */
+   *flags |= SfMayBlock;
+}
+
+POST(openat)
+{
+   vg_assert(SUCCESS);
+   if (!ML_(fd_allowed)(RES, "openat", 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*)(Addr)ARG2);
+   }
+}
+
 #endif /* DARWIN_VERS >= DARWIN_10_10 */
 
 
@@ -10071,6 +10113,54 @@ POST(mach_generate_activity_id)
 
 #endif /* DARWIN_VERS >= DARWIN_10_12 */
 
+/* ---------------------------------------------------------------------
+ Added for macOS 10.13 (High Sierra)
+ ------------------------------------------------------------------ */
+
+#if DARWIN_VERS >= DARWIN_10_13
+
+PRE(openat_nocancel)
+{
+   if (ARG3 & VKI_O_CREAT) {
+      // 4-arg version
+      PRINT("openat_nocancel ( %ld, %#" FMT_REGWORD "x(%s), %ld, %ld )",
+            SARG1, ARG2, (HChar*)(Addr)ARG2, SARG3, SARG4);
+      PRE_REG_READ4(long, "openat_nocancel",
+                    int, dfd, const char *, filename, int, flags, int, mode);
+   } else {
+     // 3-arg version
+     PRINT("openat_nocancel ( %ld, %#" FMT_REGWORD "x(%s), %ld )",
+           SARG1, ARG2, (HChar*)(Addr)ARG2, SARG3);
+     PRE_REG_READ3(long, "openat_nocancel",
+                   int, dfd, const char *, filename, int, flags);
+   }
+   PRE_MEM_RASCIIZ( "openat_nocancel(filename)", ARG2 );
+
+   /* For absolute filenames, dfd is ignored.  If dfd is AT_FDCWD,
+      filename is relative to cwd.  When comparing dfd against AT_FDCWD,
+      be sure only to compare the bottom 32 bits. */
+   if (ML_(safe_to_deref)( (void*)(Addr)ARG2, 1 )
+       && *(Char *)(Addr)ARG2 != '/'
+       && ((Int)ARG1) != ((Int)VKI_AT_FDCWD)
+       && !ML_(fd_allowed)(ARG1, "openat", tid, False))
+      SET_STATUS_Failure( VKI_EBADF );
+
+   /* Otherwise handle normally */
+   *flags |= SfMayBlock;
+}
+POST(openat_nocancel)
+{
+   vg_assert(SUCCESS);
+   if (!ML_(fd_allowed)(RES, "openat_nocancel", 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*)(Addr)ARG2);
+   }
+}
+
+#endif /* DARWIN_VERS >= DARWIN_10_13 */
 
 /* ---------------------------------------------------------------------
    syscall tables
index 7fa442a39cd5f300620b17a2c464ba8d685c24f3..7af0465c54319d8e04ad1ade55975bcb24b03569 100644 (file)
 #endif /* DARWIN_VERS >= DARWIN_10_12 */
 
 #if DARWIN_VERS >= DARWIN_10_10
+#define __NR_openat                 VG_DARWIN_SYSCALL_CONSTRUCT_UNIX(463)
+#if DARWIN_VERS >= DARWIN_10_13
+#define __NR_openat_nocancel        VG_DARWIN_SYSCALL_CONSTRUCT_UNIX(464)
+#endif
 #define __NR_faccessat              VG_DARWIN_SYSCALL_CONSTRUCT_UNIX(466)
 #define __NR_fstatat64              VG_DARWIN_SYSCALL_CONSTRUCT_UNIX(470)
 #define __NR_readlinkat             VG_DARWIN_SYSCALL_CONSTRUCT_UNIX(473)