Author: jonpryor
Date: 2005-04-20 07:29:20 -0400 (Wed, 20 Apr 2005)
New Revision: 43324

Modified:
   trunk/mcs/class/Mono.Posix/Mono.Unix/ChangeLog
   trunk/mcs/class/Mono.Posix/Mono.Unix/Syscall.cs
Log:
        * Syscall.cs: Make all fork(2) and exec(2) functions `private`.  It
          currently isn't safe to call these under *any* circumstances.


Modified: trunk/mcs/class/Mono.Posix/Mono.Unix/ChangeLog
===================================================================
--- trunk/mcs/class/Mono.Posix/Mono.Unix/ChangeLog      2005-04-20 11:16:05 UTC 
(rev 43323)
+++ trunk/mcs/class/Mono.Posix/Mono.Unix/ChangeLog      2005-04-20 11:29:20 UTC 
(rev 43324)
@@ -1,3 +1,31 @@
+2005-04-20  Jonathan Pryor <[EMAIL PROTECTED]>
+
+       * Syscall.cs: Make all fork(2) and exec(2) functions `private`.  It
+         currently isn't safe to call these under *any* circumstances.  See 
also
+         68141, and this pertinent quote from Butenhof's 
+         "Programming with POSIX Threads", p197, s6.1:
+         
+             "When a threaded process calls fork to create a child process,
+             Pthreads specifies that only the thread calling fork exists in the
+             child. ... Pthreads does not 'terminate' the other threads in a 
forked
+             process...They simply cease to exist.  ... This is not a problem 
if
+             the child process is about to call exec to run a new program, but 
if
+             you use fork to clone a threaded program, beware that you may lose
+             access to memory, especially heap memory stored only as
+             thread-specific data values."
+         
+         Since P/Invoke currently requires using thread local storage, once you
+         fork(2) you won't be able to invoke exec(2) from managed code (since 
that
+         would require a P/Invoke transition to call exec(2), which would 
require
+         TLS, which doesn't exist in the new process).
+        
+         This can only be fixed by removing the TLS dependency on P/Invoke, 
which
+         isn't a priority (and may not be possible).
+        
+         The workaround is to create a C function which does your 
fork(2)/exec(2)
+         (and any other functions such as daemon(3)) on your behalf, and 
P/Invoke
+         to call this C function.
+
 2005-04-18  Jonathan Pryor <[EMAIL PROTECTED]>
 
        * Syscall.cs: Update comment specifying which functions belong in 
Syscall.

Modified: trunk/mcs/class/Mono.Posix/Mono.Unix/Syscall.cs
===================================================================
--- trunk/mcs/class/Mono.Posix/Mono.Unix/Syscall.cs     2005-04-20 11:16:05 UTC 
(rev 43323)
+++ trunk/mcs/class/Mono.Posix/Mono.Unix/Syscall.cs     2005-04-20 11:29:20 UTC 
(rev 43324)
@@ -2329,17 +2329,17 @@
 
                // TODO: does Mono marshal arrays properly?
                [DllImport (LIBC, SetLastError=true)]
-               public static extern int execve (string path, string[] argv, 
string[] envp);
+               private static extern int execve (string path, string[] argv, 
string[] envp);
 
                [DllImport (LIBC, SetLastError=true)]
-               public static extern int fexecve (int fd, string[] argv, 
string[] envp);
+               private static extern int fexecve (int fd, string[] argv, 
string[] envp);
 
                [DllImport (LIBC, SetLastError=true)]
-               public static extern int execv (string path, string[] argv);
+               private static extern int execv (string path, string[] argv);
 
                // TODO: execle, execl, execlp
                [DllImport (LIBC, SetLastError=true)]
-               public static extern int execvp (string path, string[] argv);
+               private static extern int execvp (string path, string[] argv);
 
                [DllImport (LIBC, SetLastError=true)]
                public static extern int nice (int inc);
@@ -2488,14 +2488,14 @@
                [DllImport (LIBC, SetLastError=true)]
                [Obsolete ("DO NOT directly call fork(2); it bypasses essential 
" + 
                                "shutdown code.\nUse System.Diagnostics.Process 
instead")]
-               public static extern int fork ();
+               private static extern int fork ();
 
                // vfork(2)
                //    pid_t vfork(void);
                [DllImport (LIBC, SetLastError=true)]
                [Obsolete ("DO NOT directly call vfork(2); it bypasses 
essential " + 
                                "shutdown code.\nUse System.Diagnostics.Process 
instead")]
-               public static extern int vfork ();
+               private static extern int vfork ();
 
                [DllImport (LIBC, SetLastError=true, EntryPoint="ttyname")]
                private static extern IntPtr sys_ttyname (int fd);

_______________________________________________
Mono-patches maillist  -  [email protected]
http://lists.ximian.com/mailman/listinfo/mono-patches

Reply via email to