[PATCH] D48451: [sanitizers_common] when spawning a subprocess for symbolizers, use posix_spawn instead of fork()

Alex Gaynor via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Fri Jun 22 08:59:08 PDT 2018


alex updated this revision to Diff 152483.
alex added a comment.

- Simply use vfork everywhere, the macOS manpage does not describe it's semantics correctly.


Repository:
  rCRT Compiler Runtime

https://reviews.llvm.org/D48451

Files:
  lib/sanitizer_common/sanitizer_linux.cc
  lib/sanitizer_common/sanitizer_mac.cc
  lib/sanitizer_common/sanitizer_posix.h
  lib/sanitizer_common/sanitizer_posix_libcdep.cc


Index: lib/sanitizer_common/sanitizer_posix_libcdep.cc
===================================================================
--- lib/sanitizer_common/sanitizer_posix_libcdep.cc
+++ lib/sanitizer_common/sanitizer_posix_libcdep.cc
@@ -448,12 +448,12 @@
     }
   });
 
-  int pid = internal_fork();
+  int pid = internal_vfork();
 
   if (pid < 0) {
     int rverrno;
     if (internal_iserror(pid, &rverrno)) {
-      Report("WARNING: failed to fork (errno %d)\n", rverrno);
+      Report("WARNING: failed to vfork (errno %d)\n", rverrno);
     }
     return pid;
   }
Index: lib/sanitizer_common/sanitizer_posix.h
===================================================================
--- lib/sanitizer_common/sanitizer_posix.h
+++ lib/sanitizer_common/sanitizer_posix.h
@@ -58,6 +58,7 @@
 uptr internal_waitpid(int pid, int *status, int options);
 
 int internal_fork();
+int internal_vfork();
 int internal_forkpty(int *amaster);
 
 // These functions call appropriate pthread_ functions directly, bypassing
Index: lib/sanitizer_common/sanitizer_mac.cc
===================================================================
--- lib/sanitizer_common/sanitizer_mac.cc
+++ lib/sanitizer_common/sanitizer_mac.cc
@@ -207,6 +207,10 @@
   return fork();
 }
 
+int internal_vfork() {
+  return vfork();
+}
+
 int internal_forkpty(int *amaster) {
   int master, slave;
   if (openpty(&master, &slave, nullptr, nullptr, nullptr) == -1) return -1;
Index: lib/sanitizer_common/sanitizer_linux.cc
===================================================================
--- lib/sanitizer_common/sanitizer_linux.cc
+++ lib/sanitizer_common/sanitizer_linux.cc
@@ -793,6 +793,14 @@
 #endif
 }
 
+int internal_vfork() {
+#if SANITIZER_USES_CANONICAL_LINUX_SYSCALLS
+  return internal_syscall(SYSCALL(clone), CLONE_VM | CLONE_VFORK | SIGCHLD, 0);
+#else
+  return internal_syscall(SYSCALL(vfork));
+#endif
+}
+
 #if SANITIZER_LINUX
 #define SA_RESTORER 0x04000000
 // Doesn't set sa_restorer if the caller did not set it, so use with caution


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D48451.152483.patch
Type: text/x-patch
Size: 2013 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20180622/c964618d/attachment.bin>


More information about the llvm-commits mailing list