i386 vfork bug -- was Re: [uClibc]popen failing on i386 -- vfork issue?

Erik Andersen andersen at lineo.com
Fri Mar 2 18:55:55 UTC 2001


On Fri Mar 02, 2001 at 10:58:25AM -0600, Manuel Novoa III wrote:
> 
> On Thu, 01 Mar 2001, Manuel Novoa III wrote:
> > call generates a SIGPIPE.  What am I missing?  Why should this work with vfork
> > at all?
> 
> Ok... I know what was missing above.  I missed the part about the parent
> continuing execution when the child does an execve.  
> 
> However, vfork on i386 is definitely broken.  A test program to illustrate this
> is attached.  The child executes but the parent segfaults.
> 
> As a temporary work-around, I'm making vfork on i386 a weak alias for fork.


It is interesting to note that GNU libc uses asm to implement vfork, so I doubt
we can get away with simply using C.  Anyways, for your reading enjoyment (I'm
in the middle of something so I don't have time to fix it) I am including the
results of what glibc uses after running it through the pre-processor to
resolve all its 15 levels or so of sysdeps.h preprocessor junk ( I found their
source was mostly illegible due to the zillions of macros).

[andersen at slag glibc-2.1.3]$ gcc sysdeps/unix/sysv/linux/i386/vfork.S -c  -Iinclude -I.   -Ilibio  -Isysdeps/i386/elf -Isysdeps/unix/sysv/linux/i386/i686 -Isysdeps/unix/sysv/linux/i386 -Isysdeps/unix/sysv/linux -Isysdeps/gnu -Isysdeps/unix/common -Isysdeps/unix/mman -Isysdeps/unix/inet -Isysdeps/unix/sysv/i386 -Isysdeps/unix/sysv -Isysdeps/unix/i386 -Isysdeps/unix -Isysdeps/posix -Isysdeps/i386/i686 -Isysdeps/i386/i486 -Isysdeps/libm-i387/i686 -Isysdeps/i386/fpu -Isysdeps/libm-i387 -Isysdeps/i386 -Isysdeps/wordsize-32 -Isysdeps/ieee754 -Isysdeps/libm-ieee754 -Isysdeps/generic/elf -Isysdeps/generic    -include include/libc-symbols.h     -DASSEMBLER  -DGAS_SYNTAX  -E > vfork.post_cpp.c

Anyways, here is the (slightly edited) output of what glibc 
uses to implement vfork on i386:

# 22 "sysdeps/unix/sysv/linux/i386/vfork.S" 2

.stabs  "" ,100,0,0,1b;
.stabs  "__vfork" ,100,0,0,1b;  	
.globl    __vfork   ;	
.type    __vfork    , @function ; 	
.align 1<< 4  ;	
.stabs "int:t(0,1)=r(0,1);-2147483648;2147483647;",128,0,0,0;	
.stabs "__vfork:F(0,1)",36,0,0,   __vfork   ;  	  


__vfork: 	  
	 
	popl	%ecx

	 
	movl	$190   , %eax
	int	$0x80
	cmpl	$-4095, %eax
	jae	.Lerror		 

	 
	jmp	*%ecx

.Lerror:
	 
	pushl	%ecx

	 
	cmpl	$- 38 , %eax
	jne	__syscall_error  


	movl	$2   , %eax
	int	$0x80
	cmpl	$-4095, %eax
	jae	__syscall_error  
.Lpseudo_end:
	ret

 	.size    __vfork   ,.-   __vfork   ; 	1: .stabs "",36,0,0,1b-   __vfork   ;   

.weak    vfork   ;	   vfork    =   __vfork    


 -Erik

--
Erik B. Andersen   email:  andersen at lineo.com
--This message was written using 73% post-consumer electrons--


 -Erik

--
Erik B. Andersen   email:  andersen at lineo.com
--This message was written using 73% post-consumer electrons--





More information about the uClibc mailing list