[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 09:01:09 PDT 2018


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

- Query for sysconf open max before vforking


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,14 @@
     }
   });
 
-  int pid = internal_fork();
+  int max_fds = sysconf(_SC_OPEN_MAX);
+
+  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;
   }
@@ -476,7 +478,7 @@
       internal_close(stderr_fd);
     }
 
-    for (int fd = sysconf(_SC_OPEN_MAX); fd > 2; fd--) internal_close(fd);
+    for (int fd = max_fds; fd > 2; fd--) internal_close(fd);
 
     execv(program, const_cast<char **>(&argv[0]));
     internal__exit(1);
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.152485.patch
Type: text/x-patch
Size: 2334 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20180622/873d32b5/attachment.bin>


More information about the llvm-commits mailing list