[PATCH 21/46] vfork: Use clone if arch does not have the vfork syscall

Markos Chandras markos.chandras at gmail.com
Tue Nov 13 11:31:30 UTC 2012


From: Markos Chandras <markos.chandras at imgtec.com>

Signed-off-by: Markos Chandras <markos.chandras at imgtec.com>
---
 libc/sysdeps/linux/common/vfork.c |   20 +++++++++++++++++++-
 1 files changed, 19 insertions(+), 1 deletions(-)

diff --git a/libc/sysdeps/linux/common/vfork.c b/libc/sysdeps/linux/common/vfork.c
index e7c9208..16f5f79 100644
--- a/libc/sysdeps/linux/common/vfork.c
+++ b/libc/sysdeps/linux/common/vfork.c
@@ -4,13 +4,31 @@
  * Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball.
  */
 
+#include <signal.h>
 #include <unistd.h>
 #include <sys/types.h>
 #include <sys/syscall.h>
 
 extern __typeof(vfork) __vfork attribute_hidden;
 
-#ifdef __NR_vfork
+#if defined(__NR_clone) && ! defined(__NR_vfork)
+pid_t __vfork(void)
+{
+	pid_t pid;
+	pid = INLINE_SYSCALL(clone, 4, CLONE_VFORK | CLONE_VM |
+		SIGCHLD, NULL, NULL, NULL);
+
+	if (pid<0) {
+		__set_errno(-pid);
+		return -1
+	}
+
+	return pid;
+}
+weak_alias(__vfork,vfork)
+libc_hidden_weak(vfork)
+
+#elif defined(__NR_vfork)
 
 # define __NR___vfork __NR_vfork
 _syscall0(pid_t, __vfork)
-- 
1.7.1




More information about the uClibc mailing list