Skip site navigation (1)Skip section navigation (2)
Date:      Mon, 12 Mar 2001 18:46:16 -0500
From:      James FitzGibbon <james@ehlo.com>
To:        KUROSAWA Takahiro <fwkg7679@mb.infoweb.ne.jp>, Daniel Eischen <eischen@vigrid.com>
Cc:        current@freebsd.org
Subject:   Fixed - pthread altsigstack problem
Message-ID:  <20010312184616.A25098@ehlo.com>

next in thread | raw e-mail | index | archive | help
Both of the patches below fix the problem mentioned in PR bin/25110.  The
first one fixes it inside of kern_fork.c and would appear to apply the
corrective behaviour regardless of whether the process uses libc_r or not. 
The second patch fixes the problem inside of uthread_fork.c.  Whether the
first approach imposes an extra cost on non-threaded applications I'm not
kernel-experienced enough to say, but hopefully between two of you gents you
can decide which is the better fix to apply.

As I mentioned in my original post, this is a bug that we are experiencing
in 4.3-BETA, so if this could make it into 4.3-RELEASE it would be of great
help.  One note regarding the second (libc_r) patch: the reference to
__sys_sigaltstack needs to be changed to _thread_sys_sigaltstack in order to
prevent undefined symbols on 4.x systems.

Patch #1 (kernel fix):

--- kern_fork.c.orig    Sat Mar 10 12:17:40 2001                                
+++ kern_fork.c Sat Mar 10 12:20:39 2001                                        
@@ -434,7 +434,7 @@                                                             
         * Preserve some more flags in subprocess.  P_PROFIL has already        
         * been preserved.                                                      
         */                                                                     
-       p2->p_flag |= p1->p_flag & P_SUGID;                                     
+       p2->p_flag |= p1->p_flag & (P_SUGID | P_ALTSTACK);                      
        if (p1->p_session->s_ttyvp != NULL && p1->p_flag & P_CONTROLT)          
                p2->p_flag |= P_CONTROLT;                                       
        if (flags & RFPPWAIT)

Patch #2 (libc_r fix):

--- uthread_fork.c      2001/01/24 13:03:33     1.21                                                          
+++ uthread_fork.c      2001/03/09 17:53:37                                                                   
@@ -32,6 +32,7 @@                                                                                             
  * $FreeBSD: src/lib/libc_r/uthread/uthread_fork.c,v 1.21 2001/01/24 13:03:33 deischen Exp $                                                                                       
  */                                                                                                          
 #include <errno.h>                                                                                           
+#include <signal.h>                                                                                          
 #include <string.h>                                                                                          
 #include <stdlib.h>                                                                                          
 #include <unistd.h>                                                                                          
@@ -110,7 +111,16 @@                                                                                          
                else if (_pq_init(&_readyq) != 0) {                                                           
                        /* Abort this application: */                                                         
                        PANIC("Cannot initialize priority ready queue.");                                     
-               } else {                                                                                      
+               } else if ((_thread_sigstack.ss_sp == NULL) &&                                                
+                   ((_thread_sigstack.ss_sp = malloc(SIGSTKSZ)) == NULL))                                    
+                       PANIC("Unable to allocate alternate signal stack");                                   
+               else {                                                                                        
+                       /* Install the alternate signal stack: */                                             
+                       _thread_sigstack.ss_size = SIGSTKSZ;                                                  
+                       _thread_sigstack.ss_flags = 0;                                                        
+                       if (__sys_sigaltstack(&_thread_sigstack, NULL) != 0)                                  
+                               PANIC("Unable to install alternate signal stack");                            
+                                                                                                             
                        /*                                                                                    
                         * Enter a loop to remove all threads other than                                      
                         * the running thread from the thread list:                          

Thanks for the help guys.

-- 
j.

To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-current" in the body of the message




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20010312184616.A25098>