This is the mail archive of the libc-hacker@sources.redhat.com mailing list for the glibc project.
Note that libc-hacker is a closed list. You may look at the archives of this list, but subscription and posting are not open.
Index Nav: | [Date Index] [Subject Index] [Author Index] [Thread Index] | |
---|---|---|
Message Nav: | [Date Prev] [Date Next] | [Thread Prev] [Thread Next] |
Other format: | [Raw text] |
Hi! The following new test (tst-popen) got broken when vfork has been made hidden in libc. linuxthreads really needs to use full-blown fork if pthread_create has been ever called. The following patch fixes this. I've left cris, sh, arm, m68k and powerpc64 unchanged, they need similar changes, otherwise tst-popen will fail. s390, s390x and powerpc32 are using sysdeps/generic/vfork.c, ie. they use fork no matter if vfork or fork is used. Martin said he'll change s390*, Franz, could you look at why ppc32 doesn't use vfork? If vfork is added for these arches, it will need special assembly in linuxthreads. Tested on i386/i686/IA-64/x86-64/alpha/alphaev6/ppc32. 2003-01-09 Jakub Jelinek <jakub@redhat.com> * posix/test-vfork.c (noop): Add __attribute_noinline__. * sysdeps/generic/sysdep.h (JUMPTARGET): Define if not defined. * sysdeps/i386/sysdep.h (JUMPTARGET): Undefine JUMPTARGET before defining it. * sysdeps/powerpc/powerpc32/sysdep.h (JUMPTARGET): Likewise. * sysdeps/powerpc/powerpc64/sysdep.h (JUMPTARGET): Likewise. * sysdeps/s390/s390-32/sysdep.h (JUMPTARGET): Likewise. * sysdeps/s390/s390-64/sysdep.h (JUMPTARGET): Likewise. * sysdeps/x86_64/sysdep.h (JUMPTARGET): Likewise. linuxthreads/ * sysdeps/unix/sysv/linux/i386/vfork.S: New file. * sysdeps/unix/sysv/linux/ia64/vfork.S: New file. * sysdeps/unix/sysv/linux/ia64/sysdep-cancel.h [__ASSEMBLER__] (SINGLE_THREAD_P): Remove trailing ;;. * sysdeps/unix/sysv/linux/sparc/sparc32/vfork.S: New file. * sysdeps/unix/sysv/linux/sparc/sparc64/vfork.S: New file. * sysdeps/unix/sysv/linux/x86_64/vfork.S: New file. * sysdeps/unix/sysv/linux/alpha/vfork.S: New file. * tst-popen.c: New test. * Makefile (tests): Add tst-popen. --- libc/linuxthreads/sysdeps/unix/sysv/linux/i386/vfork.S.jj 2003-01-08 22:18:12.000000000 +0100 +++ libc/linuxthreads/sysdeps/unix/sysv/linux/i386/vfork.S 2003-01-09 03:20:12.000000000 +0100 @@ -0,0 +1,81 @@ +/* Copyright (C) 1999, 2002, 2003 Free Software Foundation, Inc. + This file is part of the GNU C Library. + Contributed by Andreas Schwab <schwab@gnu.org>. + + The GNU C Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + The GNU C Library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with the GNU C Library; if not, write to the Free + Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA + 02111-1307 USA. */ + +#include <sysdep-cancel.h> +#define _ERRNO_H 1 +#include <bits/errno.h> +#include <kernel-features.h> + +/* Clone the calling process, but without copying the whole address space. + The calling process is suspended until the new process exits or is + replaced by a call to `execve'. Return -1 for errors, 0 to the new process, + and the process ID of the new process to the old process. */ + +ENTRY (__vfork) + +#ifdef __NR_vfork + + SINGLE_THREAD_P + jne HIDDEN_JUMPTARGET (__fork) + + /* Pop the return PC value into ECX. */ + popl %ecx + + /* Stuff the syscall number in EAX and enter into the kernel. */ + movl $SYS_ify (vfork), %eax + int $0x80 + + /* Jump to the return PC. Don't jump directly since this + disturbs the branch target cache. Instead push the return + address back on the stack. */ + pushl %ecx + + cmpl $-4095, %eax + /* Branch forward if it failed. */ +# ifdef __ASSUME_VFORK_SYSCALL + jae SYSCALL_ERROR_LABEL +.Lpseudo_end: +# else + jae .Lerror +# endif + + ret + +# ifndef __ASSUME_VFORK_SYSCALL +.Lerror: + /* Check if vfork syscall is known at all. */ + cmpl $-ENOSYS, %eax + jne SYSCALL_ERROR_LABEL +# endif +#endif + +#ifndef __ASSUME_VFORK_SYSCALL + /* If we don't have vfork, fork is close enough. */ + + movl $SYS_ify (fork), %eax + int $0x80 + cmpl $-4095, %eax + jae SYSCALL_ERROR_LABEL +.Lpseudo_end: + ret +#endif +PSEUDO_END (__vfork) +libc_hidden_def (__vfork) + +weak_alias (__vfork, vfork) --- libc/linuxthreads/sysdeps/unix/sysv/linux/ia64/vfork.S.jj 2003-01-08 22:37:54.000000000 +0100 +++ libc/linuxthreads/sysdeps/unix/sysv/linux/ia64/vfork.S 2003-01-08 23:54:14.000000000 +0100 @@ -0,0 +1,49 @@ +/* Copyright (C) 2000, 2002, 2003 Free Software Foundation, Inc. + This file is part of the GNU C Library. + + The GNU C Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + The GNU C Library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with the GNU C Library; if not, write to the Free + Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA + 02111-1307 USA. */ + + +#include <sysdep-cancel.h> +#define _SIGNAL_H +#include <bits/signum.h> + +#define JUMPTARGET(name) name + +/* The following are defined in linux/sched.h, which unfortunately */ +/* is not safe for inclusion in an assembly file. */ +#define CLONE_VM 0x00000100 /* set if VM shared between processes */ +#define CLONE_VFORK 0x00004000 /* set if the parent wants the child to wake it up on mm_release */ + +/* pid_t vfork(void); */ +/* Implemented as __clone_syscall(CLONE_VFORK | CLONE_VM | SIGCHLD, 0) */ + +ENTRY(__vfork) + SINGLE_THREAD_P +(p6) br.cond.spnt.few HIDDEN_JUMPTARGET (__fork);; + alloc r2=ar.pfs,0,0,2,0 + mov out0=CLONE_VM+CLONE_VFORK+SIGCHLD + mov out1=0 /* Standard sp value. */ + ;; + DO_CALL (SYS_ify (clone)) + cmp.eq p6,p0=-1,r10 + ;; +(p6) br.cond.spnt.few __syscall_error + ret +PSEUDO_END(__vfork) +libc_hidden_def (__vfork) + +weak_alias (__vfork, vfork) --- libc/linuxthreads/sysdeps/unix/sysv/linux/ia64/sysdep-cancel.h.jj 2003-01-01 03:40:04.000000000 +0100 +++ libc/linuxthreads/sysdeps/unix/sysv/linux/ia64/sysdep-cancel.h 2003-01-08 22:45:07.000000000 +0100 @@ -1,4 +1,4 @@ -/* Copyright (C) 2002 Free Software Foundation, Inc. +/* Copyright (C) 2002, 2003 Free Software Foundation, Inc. This file is part of the GNU C Library. Contributed by Jakub Jelinek <jakub@redhat.com>, 2002. @@ -105,7 +105,7 @@ __syscall_error_##args: \ p_header.data.multiple_threads) == 0, 1) # else # define SINGLE_THREAD_P \ - adds r14 = MULTIPLE_THREADS_OFFSET, r13 ;; ld4 r14 = [r14] ;; cmp4.ne p6, p7 = 0, r14 ;; + adds r14 = MULTIPLE_THREADS_OFFSET, r13 ;; ld4 r14 = [r14] ;; cmp4.ne p6, p7 = 0, r14 # endif #elif !defined __ASSEMBLER__ --- libc/linuxthreads/sysdeps/unix/sysv/linux/sparc/sparc32/vfork.S.jj 2003-01-08 22:52:03.000000000 +0100 +++ libc/linuxthreads/sysdeps/unix/sysv/linux/sparc/sparc32/vfork.S 2003-01-09 03:21:43.000000000 +0100 @@ -0,0 +1,37 @@ +/* Copyright (C) 2003 Free Software Foundation, Inc. + This file is part of the GNU C Library. + Contributed by Jakub Jelinek <jakub@redhat.com>, 2003. + + The GNU C Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + The GNU C Library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with the GNU C Library; if not, write to the Free + Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA + 02111-1307 USA. */ + +#include <sysdep-cancel.h> + + .text +ENTRY(__vfork) + ld [%g6 + MULTIPLE_THREADS_OFFSET], %o0 + cmp %o0, 0 + bne HIDDEN_JUMPTARGET(__fork) + mov __NR_vfork, %g1 + ta 0x10; + bcs __syscall_error_handler + nop + sub %o1, 1, %o1 + retl + and %o0, %o1, %o0 + SYSCALL_ERROR_HANDLER +PSEUDO_END (__vfork) +libc_hidden_def (__vfork) +weak_alias (__vfork, vfork) --- libc/linuxthreads/sysdeps/unix/sysv/linux/sparc/sparc64/vfork.S.jj 2003-01-08 22:52:03.000000000 +0100 +++ libc/linuxthreads/sysdeps/unix/sysv/linux/sparc/sparc64/vfork.S 2003-01-09 03:22:31.000000000 +0100 @@ -0,0 +1,36 @@ +/* Copyright (C) 2003 Free Software Foundation, Inc. + This file is part of the GNU C Library. + Contributed by Jakub Jelinek <jakub@redhat.com>, 2003. + + The GNU C Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + The GNU C Library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with the GNU C Library; if not, write to the Free + Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA + 02111-1307 USA. */ + +#include <sysdep-cancel.h> + + .text +ENTRY(__vfork) + ld [%g6 + MULTIPLE_THREADS_OFFSET], %o0 + bne HIDDEN_JUMPTARGET (__fork) + mov __NR_vfork, %g1 + ta 0x6d + bcs,pn %xcc, __syscall_error_handler + nop + sub %o1, 1, %o1 + retl + and %o0, %o1, %o0 + SYSCALL_ERROR_HANDLER +PSEUDO_END (__vfork) +libc_hidden_def (__vfork) +weak_alias (__vfork, vfork) --- libc/linuxthreads/sysdeps/unix/sysv/linux/x86_64/vfork.S.jj 2003-01-08 22:45:50.000000000 +0100 +++ libc/linuxthreads/sysdeps/unix/sysv/linux/x86_64/vfork.S 2003-01-08 22:48:42.000000000 +0100 @@ -0,0 +1,54 @@ +/* Copyright (C) 2001, 2002, 2003 Free Software Foundation, Inc. + This file is part of the GNU C Library. + + The GNU C Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + The GNU C Library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with the GNU C Library; if not, write to the Free + Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA + 02111-1307 USA. */ + +#include <sysdep-cancel.h> +#define _ERRNO_H 1 +#include <bits/errno.h> + +/* Clone the calling process, but without copying the whole address space. + The calling process is suspended until the new process exits or is + replaced by a call to `execve'. Return -1 for errors, 0 to the new process, + and the process ID of the new process to the old process. */ + +ENTRY (__vfork) + + SINGLE_THREAD_P + jne HIDDEN_JUMPTARGET (__fork) + + /* Pop the return PC value into RDI. We need a register that + is preserved by the syscall and that we're allowed to destroy. */ + popq %rdi + + /* Stuff the syscall number in RAX and enter into the kernel. */ + movl $SYS_ify (vfork), %eax + syscall + + /* Push back the return PC. */ + pushq %rdi + + cmpl $-4095, %eax + jae SYSCALL_ERROR_LABEL /* Branch forward if it failed. */ + + /* Normal return. */ +.Lpseudo_end: + ret + +PSEUDO_END (__vfork) +libc_hidden_def (__vfork) + +weak_alias (__vfork, vfork) --- libc/linuxthreads/sysdeps/unix/sysv/linux/alpha/vfork.S.jj 2003-01-08 23:20:31.000000000 +0100 +++ libc/linuxthreads/sysdeps/unix/sysv/linux/alpha/vfork.S 2003-01-09 15:11:13.000000000 +0100 @@ -0,0 +1,38 @@ +/* Copyright (C) 2003 Free Software Foundation, Inc. + This file is part of the GNU C Library. + + The GNU C Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + The GNU C Library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with the GNU C Library; if not, write to the Free + Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA + 02111-1307 USA. */ + + +#include <sysdep-cancel.h> + + .globl __vfork + .align 4 + .ent __vfork,0 +__LABEL(__vfork) + ldgp gp, 0(pv) + .prologue 1 + PSEUDO_PROF + SINGLE_THREAD_P(t0) + bne t0, HIDDEN_JUMPTARGET (__fork) !samegp + lda v0, SYS_ify(vfork) + call_pal PAL_callsys + bne a3, __syscall_error !samegp + ret +PSEUDO_END(__vfork) +libc_hidden_def (__vfork) + +weak_alias (__vfork, vfork) --- libc/linuxthreads/tst-popen.c.jj 2003-01-08 23:26:05.000000000 +0100 +++ libc/linuxthreads/tst-popen.c 2003-01-09 03:24:48.000000000 +0100 @@ -0,0 +1,37 @@ +#include <errno.h> +#include <error.h> +#include <pthread.h> +#include <stdio.h> +#include <stdlib.h> +#include <string.h> +#include <unistd.h> + +static void * +dummy (void *x) +{ + return NULL; +} + +static char buf[sizeof "something\n"]; + +static int +do_test (void) +{ + FILE *f; + pthread_t p; + + pthread_create (&p, NULL, dummy, NULL); + f = popen ("echo something", "r"); + if (f == NULL) + error (EXIT_FAILURE, errno, "popen failed"); + if (fgets (buf, sizeof (buf), f) == NULL) + error (EXIT_FAILURE, 0, "fgets failed"); + if (strcmp (buf, "something\n")) + error (EXIT_FAILURE, 0, "read wrong data"); + if (pclose (f)) + error (EXIT_FAILURE, errno, "pclose returned non-zero"); + exit (0); +} + +#define TEST_FUNCTION do_test () +#include "../test-skeleton.c" --- libc/linuxthreads/Makefile.jj 2003-01-05 21:11:04.000000000 +0100 +++ libc/linuxthreads/Makefile 2003-01-08 23:33:54.000000000 +0100 @@ -88,7 +88,7 @@ tests = ex1 ex2 ex3 ex4 ex5 ex6 ex7 ex8 tststack $(tests-nodelete-$(have-z-nodelete)) ecmutex ex14 ex15 ex16 \ ex17 ex18 tst-cancel tst-context bug-sleep \ tst-cancel1 tst-cancel2 tst-cancel3 tst-cancel4 tst-cancel5 \ - tst-cancel6 + tst-cancel6 tst-popen test-srcs = tst-signal # These tests are linked with libc before libpthread tests-reverse += tst-cancel5 --- libc/posix/test-vfork.c.jj 2001-01-02 14:18:02.000000000 +0100 +++ libc/posix/test-vfork.c 2003-01-09 15:06:49.000000000 +0100 @@ -5,7 +5,7 @@ #include <errno.h> #include <sys/wait.h> -void noop (void); +void __attribute_noinline__ noop (void); #define NR 2 /* Exit code of the child. */ --- libc/sysdeps/generic/sysdep.h.jj 2002-08-02 11:47:42.000000000 +0200 +++ libc/sysdeps/generic/sysdep.h 2003-01-09 03:11:37.000000000 +0100 @@ -1,5 +1,5 @@ /* Generic asm macros used on many machines. - Copyright (C) 1991,92,93,96,98,2002 Free Software Foundation, Inc. + Copyright (C) 1991,92,93,96,98,2002,2003 Free Software Foundation, Inc. This file is part of the GNU C Library. The GNU C Library is free software; you can redistribute it and/or @@ -42,4 +42,8 @@ #ifndef END #define END(sym) #endif + +#ifndef JUMPTARGET +#define JUMPTARGET(sym) sym +#endif #endif /* __ASSEMBLER__ */ --- libc/sysdeps/i386/sysdep.h.jj 2002-08-27 23:19:51.000000000 +0200 +++ libc/sysdeps/i386/sysdep.h 2003-01-09 03:13:13.000000000 +0100 @@ -1,5 +1,5 @@ /* Assembler macros for i386. - Copyright (C) 1991,92,93,95,96,98,2002 Free Software Foundation, Inc. + Copyright (C) 1991,92,93,95,96,98,2002,2003 Free Software Foundation, Inc. This file is part of the GNU C Library. The GNU C Library is free software; you can redistribute it and/or @@ -108,6 +108,7 @@ lose: SYSCALL_PIC_SETUP \ #define PSEUDO_END(name) \ END (name) +#undef JUMPTARGET #ifdef PIC #define JUMPTARGET(name) name##@PLT #define SYSCALL_PIC_SETUP \ --- libc/sysdeps/powerpc/powerpc32/sysdep.h.jj 2003-01-07 16:58:14.000000000 +0100 +++ libc/sysdeps/powerpc/powerpc32/sysdep.h 2003-01-09 03:13:40.000000000 +0100 @@ -1,5 +1,5 @@ /* Assembly macros for 32-bit PowerPC. - Copyright (C) 1999, 2001, 2002 Free Software Foundation, Inc. + Copyright (C) 1999, 2001, 2002, 2003 Free Software Foundation, Inc. This file is part of the GNU C Library. The GNU C Library is free software; you can redistribute it and/or @@ -104,6 +104,7 @@ li 0,syscall; \ sc +#undef JUMPTARGET #ifdef PIC #define JUMPTARGET(name) name##@plt #else --- libc/sysdeps/powerpc/powerpc64/sysdep.h.jj 2002-09-21 01:45:50.000000000 +0200 +++ libc/sysdeps/powerpc/powerpc64/sysdep.h 2003-01-09 03:14:04.000000000 +0100 @@ -1,5 +1,5 @@ /* Assembly macros for 64-bit PowerPC. - Copyright (C) 2002 Free Software Foundation, Inc. + Copyright (C) 2002, 2003 Free Software Foundation, Inc. This file is part of the GNU C Library. The GNU C Library is free software; you can redistribute it and/or @@ -207,6 +207,7 @@ LT_LABELSUFFIX(name,_name_end): ; \ sc /* ppc64 is always PIC */ +#undef JUMPTARGET #define JUMPTARGET(name) DOT_LABEL(name) #define PSEUDO(name, syscall_name, args) \ --- libc/sysdeps/s390/s390-32/sysdep.h.jj 2001-08-23 18:50:18.000000000 +0200 +++ libc/sysdeps/s390/s390-32/sysdep.h 2003-01-09 03:14:50.000000000 +0100 @@ -1,5 +1,5 @@ /* Assembler macros for s390. - Copyright (C) 2000, 2001 Free Software Foundation, Inc. + Copyright (C) 2000, 2001, 2003 Free Software Foundation, Inc. Contributed by Martin Schwidefsky (schwidefsky@de.ibm.com). This file is part of the GNU C Library. @@ -94,6 +94,7 @@ lose: SYSCALL_PIC_SETUP \ #define PSEUDO_END(name) \ END (name) +#undef JUMPTARGET #ifdef PIC #define JUMPTARGET(name) \ basr %r1,0 \ --- libc/sysdeps/s390/s390-64/sysdep.h.jj 2001-08-23 18:50:19.000000000 +0200 +++ libc/sysdeps/s390/s390-64/sysdep.h 2003-01-09 03:15:10.000000000 +0100 @@ -1,5 +1,5 @@ /* Assembler macros for 64 bit S/390. - Copyright (C) 2001 Free Software Foundation, Inc. + Copyright (C) 2001, 2003 Free Software Foundation, Inc. Contributed by Martin Schwidefsky (schwidefsky@de.ibm.com). This file is part of the GNU C Library. @@ -92,6 +92,7 @@ lose: SYSCALL_PIC_SETUP \ #define PSEUDO_END(name) \ END (name) +#undef JUMPTARGET #ifdef PIC #define JUMPTARGET(name) \ brasl name##@PLT --- libc/sysdeps/x86_64/sysdep.h.jj 2002-09-30 11:23:56.000000000 +0200 +++ libc/sysdeps/x86_64/sysdep.h 2003-01-09 03:15:54.000000000 +0100 @@ -1,5 +1,5 @@ /* Assembler macros for x86-64. - Copyright (C) 2001, 2002 Free Software Foundation, Inc. + Copyright (C) 2001, 2002, 2003 Free Software Foundation, Inc. This file is part of the GNU C Library. The GNU C Library is free software; you can redistribute it and/or @@ -86,6 +86,7 @@ lose: \ #define PSEUDO_END(name) \ END (name) +#undef JUMPTARGET #ifdef PIC #define JUMPTARGET(name) name##@PLT #else Jakub
Index Nav: | [Date Index] [Subject Index] [Author Index] [Thread Index] | |
---|---|---|
Message Nav: | [Date Prev] [Date Next] | [Thread Prev] [Thread Next] |