[PATCH] D14869: [sanitizer] Implement internal_fork and internal_forkpty for OS X

Phabricator via llvm-commits llvm-commits at lists.llvm.org
Fri Nov 20 06:31:22 PST 2015


This revision was automatically updated to reflect the committed changes.
Closed by commit rL253666: [sanitizer] Implement internal_fork and internal_forkpty for OS X (authored by kuba.brecka).

Changed prior to commit:
  http://reviews.llvm.org/D14869?vs=40766&id=40776#toc

Repository:
  rL LLVM

http://reviews.llvm.org/D14869

Files:
  compiler-rt/trunk/lib/sanitizer_common/sanitizer_mac.cc
  compiler-rt/trunk/lib/sanitizer_common/sanitizer_posix.h
  compiler-rt/trunk/lib/sanitizer_common/sanitizer_symbolizer_posix_libcdep.cc

Index: compiler-rt/trunk/lib/sanitizer_common/sanitizer_posix.h
===================================================================
--- compiler-rt/trunk/lib/sanitizer_common/sanitizer_posix.h
+++ compiler-rt/trunk/lib/sanitizer_common/sanitizer_posix.h
@@ -54,6 +54,7 @@
 uptr internal_waitpid(int pid, int *status, int options);
 
 int internal_fork();
+int internal_forkpty(int *amaster);
 
 // These functions call appropriate pthread_ functions directly, bypassing
 // the interceptor. They are weak and may not be present in some tools.
Index: compiler-rt/trunk/lib/sanitizer_common/sanitizer_mac.cc
===================================================================
--- compiler-rt/trunk/lib/sanitizer_common/sanitizer_mac.cc
+++ compiler-rt/trunk/lib/sanitizer_common/sanitizer_mac.cc
@@ -52,6 +52,7 @@
 #include <sys/sysctl.h>
 #include <sys/types.h>
 #include <unistd.h>
+#include <util.h>
 
 namespace __sanitizer {
 
@@ -147,9 +148,30 @@
   return sigprocmask(how, set, oldset);
 }
 
+// Doesn't call pthread_atfork() handlers.
+extern "C" pid_t __fork(void);
+
 int internal_fork() {
-  // TODO(glider): this may call user's pthread_atfork() handlers which is bad.
-  return fork();
+  return __fork();
+}
+
+int internal_forkpty(int *amaster) {
+  int master, slave;
+  if (openpty(&master, &slave, nullptr, nullptr, nullptr) == -1) return -1;
+  int pid = __fork();
+  if (pid == -1) {
+    close(master);
+    close(slave);
+    return -1;
+  }
+  if (pid == 0) {
+    close(master);
+    CHECK_EQ(login_tty(slave), 0);
+  } else {
+    *amaster = master;
+    close(slave);
+  }
+  return pid;
 }
 
 uptr internal_rename(const char *oldpath, const char *newpath) {
Index: compiler-rt/trunk/lib/sanitizer_common/sanitizer_symbolizer_posix_libcdep.cc
===================================================================
--- compiler-rt/trunk/lib/sanitizer_common/sanitizer_symbolizer_posix_libcdep.cc
+++ compiler-rt/trunk/lib/sanitizer_common/sanitizer_symbolizer_posix_libcdep.cc
@@ -75,7 +75,7 @@
 #if SANITIZER_MAC
     fd_t fd = kInvalidFd;
     // Use forkpty to disable buffering in the new terminal.
-    pid = forkpty(&fd, 0, 0, 0);
+    pid = internal_forkpty(&fd);
     if (pid == -1) {
       // forkpty() failed.
       Report("WARNING: failed to fork external symbolizer (errno: %d)\n",


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D14869.40776.patch
Type: text/x-patch
Size: 2316 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20151120/a2911ab4/attachment.bin>


More information about the llvm-commits mailing list