Browse Source

[LibOS/glibc] Make fork-instead-of-clone patch optional

Previously, in-LibOS Glibc was patched to prefer fork()
over clone(!CLONE_VM) to spawn a new process. Now that
clone(!CLONE_VM) works correctly, this patch is not needed.
Thus, this Glibc patch is made optional.
Isaku Yamahata 5 years ago
parent
commit
c806e5b437
3 changed files with 25 additions and 27 deletions
  1. 5 0
      LibOS/Makefile
  2. 0 27
      LibOS/glibc-2.19.patch
  3. 20 0
      LibOS/glibc-arch-fork.patch

+ 5 - 0
LibOS/Makefile

@@ -86,6 +86,11 @@ GLIBC_PATCHES = \
 	glibc-fix-warning.patch \
 	glibc-no-pie.patch
 
+# USE_clone_FOR_fork = true
+ifneq ($(USE_clone_FOR_fork),)
+GLIBC_PATCHES += glibc-arch-fork.patch
+endif
+
 $(GLIBC_SRC)/configure: $(GLIBC_PATCHES) Makefile
 	[ -f $(GLIBC_SRC).tar.gz ] || \
 	for MIRROR in $(GLIBC_MIRRORS); do \

+ 0 - 27
LibOS/glibc-2.19.patch

@@ -713,33 +713,6 @@ index 89fda5e..f6963f6 100644
  	movl	%fs:CANCELHANDLING, %eax
  	jmp	3b
  END(__pthread_disable_asynccancel)
-diff --git a/nptl/sysdeps/unix/sysv/linux/x86_64/fork.c b/nptl/sysdeps/unix/sysv/linux/x86_64/fork.c
-index a036b92..40a1eaf 100644
---- a/nptl/sysdeps/unix/sysv/linux/x86_64/fork.c
-+++ b/nptl/sysdeps/unix/sysv/linux/x86_64/fork.c
-@@ -21,10 +21,20 @@
- #include <sysdep.h>
- #include <tls.h>
- 
--
--#define ARCH_FORK() \
-+/* In Graphene, we prefer to call fork system call directly than clone */
-+#if USE_clone_FOR_fork
-+# define ARCH_FORK() \
-   INLINE_SYSCALL (clone, 4,						      \
- 		  CLONE_CHILD_SETTID | CLONE_CHILD_CLEARTID | SIGCHLD, 0,     \
- 		  NULL, &THREAD_SELF->tid)
-+#else
-+# define ARCH_FORK() \
-+ ({ unsigned long ret = INLINE_SYSCALL (fork, 0);	\
-+    if (!ret) {						\
-+	pid_t pid = INLINE_SYSCALL (getpid, 0);		\
-+	THREAD_SETMEM (THREAD_SELF, pid, pid);		\
-+	THREAD_SETMEM (THREAD_SELF, tid, pid);		\
-+    } ret; })
-+#endif
- 
- #include "../fork.c"
 diff --git a/nptl/sysdeps/unix/sysv/linux/x86_64/lowlevellock.S b/nptl/sysdeps/unix/sysv/linux/x86_64/lowlevellock.S
 index f2dca07..0ce7c67 100644
 --- a/nptl/sysdeps/unix/sysv/linux/x86_64/lowlevellock.S

+ 20 - 0
LibOS/glibc-arch-fork.patch

@@ -0,0 +1,20 @@
+diff --git a/nptl/sysdeps/unix/sysv/linux/x86_64/fork.c b/nptl/sysdeps/unix/sysv/linux/x86_64/fork.c
+index a036b92..40a1eaf 100644
+--- a/nptl/sysdeps/unix/sysv/linux/x86_64/fork.c
++++ b/nptl/sysdeps/unix/sysv/linux/x86_64/fork.c
+@@ -21,9 +21,12 @@
+ #include <sysdep.h>
+ #include <tls.h>
+ 
+ #define ARCH_FORK() \
+-  INLINE_SYSCALL (clone, 4,						      \
+-		  CLONE_CHILD_SETTID | CLONE_CHILD_CLEARTID | SIGCHLD, 0,     \
+-		  NULL, &THREAD_SELF->tid)
++ ({ unsigned long ret = INLINE_SYSCALL (fork, 0);	\
++    if (!ret) {						\
++	pid_t pid = INLINE_SYSCALL (getpid, 0);		\
++	THREAD_SETMEM (THREAD_SELF, pid, pid);		\
++	THREAD_SETMEM (THREAD_SELF, tid, pid);		\
++    } ret; })
+ 
+ #include "../fork.c"