[PATCH] (resend with patch attached) PPC32 vfork support and misc small fixes

Franz Sirl Franz.Sirl-kernel@lauterbach.com
Mon Jan 13 04:56:00 GMT 2003


Hi,

this patch adds PPC32 vfork support to glibc, modeled along the other arches.

Besides that the patch optimizes the INTERNAL_SYSCALL macro by using the new 
ERR parameter, saving a few instructions on every use. The change to 
syscall.S takes the possible extra register need for 64-bit argument 
alignment into account.

BTW, since I'm the interim PPC32 maintainer, how do I subscribe to 
libc-hacker?

Franz.


	* sysdeps/unix/sysv/linux/kernel-features.h (__ASSUME_VFORK_SYSCALL):
	Define for powerpc.
	* sysdeps/unix/sysv/linux/powerpc/syscall.S: Take register alignment into
	account.
	* sysdeps/unix/sysv/linux/powerpc/powerpc32/sysdep.h
	(INTERNAL_SYSCALL): Make use of ERR parameter.
	(INTERNAL_SYSCALL_DECL, INTERNAL_SYSCALL_ERRNO,
	INTERNAL_SYSCALL_ERROR_P): Adjust accordingly.
	(INLINE_SYSCALL): Make use of INTERNAL_SYSCALL.
	* sysdeps/unix/sysv/linux/powerpc/powerpc32/vfork.S: New file.

linuxthreads/
	* sysdeps/unix/sysv/linux/powerpc/powerpc32/vfork.S: New file.

-------------- next part --------------
Index: sysdeps/unix/sysv/linux/kernel-features.h
===================================================================
RCS file: /cvs/glibc/libc/sysdeps/unix/sysv/linux/kernel-features.h,v
retrieving revision 1.40
diff -u -p -r1.40 kernel-features.h
--- sysdeps/unix/sysv/linux/kernel-features.h	10 Jan 2003 14:09:26 -0000	1.40
+++ sysdeps/unix/sysv/linux/kernel-features.h	12 Jan 2003 18:31:56 -0000
@@ -196,9 +196,11 @@
 # define __ASSUME_AT_XID		1
 #endif
 
-/* Starting with 2.4.5 kernels PPC passes the AUXV in the standard way.  */
+/* Starting with 2.4.5 kernels PPC passes the AUXV in the standard way
+   and the vfork syscall made it into the official kernel.  */
 #if __LINUX_KERNEL_VERSION >= (132096+5) && defined __powerpc__
 # define __ASSUME_STD_AUXV		1
+# define __ASSUME_VFORK_SYSCALL		1
 #endif
 
 /* Starting with 2.4.5 kernels the mmap2 syscall made it into the official
Index: sysdeps/unix/sysv/linux/powerpc/syscall.S
===================================================================
RCS file: /cvs/glibc/libc/sysdeps/unix/sysv/linux/powerpc/syscall.S,v
retrieving revision 1.6
diff -u -p -r1.6 syscall.S
--- sysdeps/unix/sysv/linux/powerpc/syscall.S	6 Jul 2001 04:56:19 -0000	1.6
+++ sysdeps/unix/sysv/linux/powerpc/syscall.S	12 Jan 2003 18:31:56 -0000
@@ -25,6 +25,7 @@ ENTRY (syscall)
 	mr   r5,r6
 	mr   r6,r7
 	mr   r7,r8
+	mr   r8,r9
 	sc
 	PSEUDO_RET
 PSEUDO_END (syscall)
Index: sysdeps/unix/sysv/linux/powerpc/powerpc32/sysdep.h
===================================================================
RCS file: /cvs/glibc/libc/sysdeps/unix/sysv/linux/powerpc/powerpc32/sysdep.h,v
retrieving revision 1.8
diff -u -p -r1.8 sysdep.h
--- sysdeps/unix/sysv/linux/powerpc/powerpc32/sysdep.h	9 Jan 2003 04:09:26 -0000	1.8
+++ sysdeps/unix/sysv/linux/powerpc/powerpc32/sysdep.h	12 Jan 2003 18:31:56 -0000
@@ -54,53 +54,29 @@
 
 # include <errno.h>
 
-/* On powerpc a system call basically clobbers the same registers like a
-   function call, with the exception of LR (which is needed for the
-   "sc; bnslr" sequence) and CR (where only CR0.SO is clobbered to signal
-   an error return status).  */
-
 # undef INLINE_SYSCALL
 # define INLINE_SYSCALL(name, nr, args...)				\
   ({									\
-    register long r0  __asm__ ("r0");					\
-    register long r3  __asm__ ("r3");					\
-    register long r4  __asm__ ("r4");					\
-    register long r5  __asm__ ("r5");					\
-    register long r6  __asm__ ("r6");					\
-    register long r7  __asm__ ("r7");					\
-    register long r8  __asm__ ("r8");					\
-    register long r9  __asm__ ("r9");					\
-    register long r10 __asm__ ("r10");					\
-    register long r11 __asm__ ("r11");					\
-    register long r12 __asm__ ("r12");					\
-    long ret, err;							\
-    LOADARGS_##nr(name, args);						\
-    __asm__ __volatile__						\
-      ("sc\n\t"								\
-       "mfcr	%0"							\
-       : "=&r" (r0),							\
-	 "=&r" (r3), "=&r" (r4), "=&r" (r5),  "=&r" (r6),  "=&r" (r7),	\
-	 "=&r" (r8), "=&r" (r9), "=&r" (r10), "=&r" (r11), "=&r" (r12)	\
-       : ASM_INPUT_##nr							\
-       : "cr0", "ctr", "memory");					\
-    err = r0;								\
-    ret = r3;								\
-    if (__builtin_expect (err & (1 << 28), 0))				\
+    INTERNAL_SYSCALL_DECL (sc_err);					\
+    long sc_ret = INTERNAL_SYSCALL (name, sc_err, nr, args);		\
+    if (INTERNAL_SYSCALL_ERROR_P (sc_ret, sc_err))			\
       {									\
-	__set_errno (ret);						\
-	ret = -1L;							\
+	__set_errno (INTERNAL_SYSCALL_ERRNO (sc_ret, sc_err));		\
+	sc_ret = -1L;							\
       }									\
-    ret;								\
+    sc_ret;								\
   })
 
 /* Define a macro which expands inline into the wrapper code for a system
    call. This use is for internal calls that do not need to handle errors
-   normally. It will never touch errno. This returns just what the kernel
-   gave back in the non-error (CR0.SO cleared) case, otherwise (CR0.SO set)
-   the negation of the return value in the kernel gets reverted.  */
+   normally. It will never touch errno.
+   On powerpc a system call basically clobbers the same registers like a
+   function call, with the exception of LR (which is needed for the
+   "sc; bnslr+" sequence) and CR (where only CR0.SO is clobbered to signal
+   an error return status).  */
 
 # undef INTERNAL_SYSCALL_DECL
-# define INTERNAL_SYSCALL_DECL(err) do { } while (0)
+# define INTERNAL_SYSCALL_DECL(err) long err
 
 # undef INTERNAL_SYSCALL
 # define INTERNAL_SYSCALL(name, err, nr, args...)			\
@@ -118,24 +94,23 @@
     register long r12 __asm__ ("r12");					\
     LOADARGS_##nr(name, args);						\
     __asm__ __volatile__						\
-      ("sc\n\t"								\
-       "bns+	0f\n\t"							\
-       "neg	%1,%1\n"						\
-       "0:"								\
+      ("sc   \n\t"							\
+       "mfcr %0"							\
        : "=&r" (r0),							\
 	 "=&r" (r3), "=&r" (r4), "=&r" (r5),  "=&r" (r6),  "=&r" (r7),	\
 	 "=&r" (r8), "=&r" (r9), "=&r" (r10), "=&r" (r11), "=&r" (r12)	\
        : ASM_INPUT_##nr							\
        : "cr0", "ctr", "memory");					\
+    err = r0;								\
     (int) r3;								\
   })
 
 # undef INTERNAL_SYSCALL_ERROR_P
 # define INTERNAL_SYSCALL_ERROR_P(val, err) \
-  ((unsigned long) (val) >= 0xfffff001u)
+  (__builtin_expect (err & (1 << 28), 0))
 
 # undef INTERNAL_SYSCALL_ERRNO
-# define INTERNAL_SYSCALL_ERRNO(val, err)     (-(val))
+# define INTERNAL_SYSCALL_ERRNO(val, err)     (val)
 
 # define LOADARGS_0(name, dummy) \
 	r0 = __NR_##name
@@ -181,4 +156,4 @@
 #endif /* __ASSEMBLER__ */
 
 
-#endif /* linux/powerpc/sysdep.h */
+#endif /* linux/powerpc/powerpc32/sysdep.h */
--- /dev/null	2002-11-11 17:51:46.000000000 -0700
+++ sysdeps/unix/sysv/linux/powerpc/powerpc32/vfork.S	2003-01-11 09:53:31.000000000 -0700
@@ -0,0 +1,56 @@
+/* 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.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
+
+	DO_CALL (SYS_ify (vfork))
+
+# ifdef __ASSUME_VFORK_SYSCALL
+	PSEUDO_RET
+# else
+	bnslr+
+	/* Check if vfork syscall is known at all.  */
+	cmpwi	r3,ENOSYS
+	bne	JUMPTARGET(__syscall_error)
+
+# endif
+#endif
+
+#ifndef __ASSUME_VFORK_SYSCALL
+	/* If we don't have vfork, fork is close enough.  */
+
+	DO_CALL (SYS_ify (fork))
+	PSEUDO_RET
+#endif
+
+PSEUDO_END (__vfork)
+libc_hidden_def (__vfork)
+
+weak_alias (__vfork, vfork)
--- /dev/null	2002-11-11 17:51:46.000000000 -0700
+++ linuxthreads/sysdeps/unix/sysv/linux/powerpc/powerpc32/vfork.S	2003-01-11 09:53:55.000000000 -0700
@@ -0,0 +1,59 @@
+/* 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>
+#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
+	bne-	HIDDEN_JUMPTARGET(__fork)
+
+	DO_CALL (SYS_ify (vfork));
+
+# ifdef __ASSUME_VFORK_SYSCALL
+	PSEUDO_RET
+# else
+	bnslr+
+	/* Check if vfork syscall is known at all.  */
+	cmpwi	r3,ENOSYS
+	bne	JUMPTARGET(__syscall_error)
+
+# endif
+#endif
+
+#ifndef __ASSUME_VFORK_SYSCALL
+	/* If we don't have vfork, fork is close enough.  */
+
+	DO_CALL (SYS_ify (fork));
+	PSEUDO_RET
+#endif
+
+PSEUDO_END (__vfork)
+libc_hidden_def (__vfork)
+
+weak_alias (__vfork, vfork)


More information about the Libc-alpha mailing list