diff -urN RC14-rc3-git4-unmap/arch/um/include/sysdep-i386/stub.h RC14-rc3-git4-uml-clone/arch/um/include/sysdep-i386/stub.h --- RC14-rc3-git4-unmap/arch/um/include/sysdep-i386/stub.h 2005-08-28 23:09:40.000000000 -0400 +++ RC14-rc3-git4-uml-clone/arch/um/include/sysdep-i386/stub.h 2005-10-04 15:14:34.000000000 -0400 @@ -12,54 +12,7 @@ extern void stub_segv_handler(int sig); extern void stub_clone_handler(void); -#define STUB_SYSCALL_RET EAX #define STUB_MMAP_NR __NR_mmap2 #define MMAP_OFFSET(o) ((o) >> PAGE_SHIFT) -static inline long stub_syscall2(long syscall, long arg1, long arg2) -{ - long ret; - - __asm__("movl %0, %%ecx; " : : "g" (arg2) : "%ecx"); - __asm__("movl %0, %%ebx; " : : "g" (arg1) : "%ebx"); - __asm__("movl %0, %%eax; " : : "g" (syscall) : "%eax"); - __asm__("int $0x80;" : : : "%eax"); - __asm__ __volatile__("movl %%eax, %0; " : "=g" (ret) :); - return(ret); -} - -static inline long stub_syscall3(long syscall, long arg1, long arg2, long arg3) -{ - __asm__("movl %0, %%edx; " : : "g" (arg3) : "%edx"); - return(stub_syscall2(syscall, arg1, arg2)); -} - -static inline long stub_syscall4(long syscall, long arg1, long arg2, long arg3, - long arg4) -{ - __asm__("movl %0, %%esi; " : : "g" (arg4) : "%esi"); - return(stub_syscall3(syscall, arg1, arg2, arg3)); -} - -static inline long stub_syscall6(long syscall, long arg1, long arg2, long arg3, - long arg4, long arg5, long arg6) -{ - long ret; - __asm__("movl %0, %%eax; " : : "g" (syscall) : "%eax"); - __asm__("movl %0, %%ebx; " : : "g" (arg1) : "%ebx"); - __asm__("movl %0, %%ecx; " : : "g" (arg2) : "%ecx"); - __asm__("movl %0, %%edx; " : : "g" (arg3) : "%edx"); - __asm__("movl %0, %%esi; " : : "g" (arg4) : "%esi"); - __asm__("movl %0, %%edi; " : : "g" (arg5) : "%edi"); - __asm__ __volatile__("pushl %%ebp ; movl %1, %%ebp; " - "int $0x80; popl %%ebp ; " - "movl %%eax, %0; " : "=g" (ret) : "g" (arg6) : "%eax"); - return(ret); -} - -static inline void trap_myself(void) -{ - __asm("int3"); -} - #endif diff -urN RC14-rc3-git4-unmap/arch/um/include/sysdep-x86_64/stub.h RC14-rc3-git4-uml-clone/arch/um/include/sysdep-x86_64/stub.h --- RC14-rc3-git4-unmap/arch/um/include/sysdep-x86_64/stub.h 2005-08-28 23:09:40.000000000 -0400 +++ RC14-rc3-git4-uml-clone/arch/um/include/sysdep-x86_64/stub.h 2005-10-04 15:14:34.000000000 -0400 @@ -13,46 +13,7 @@ extern void stub_segv_handler(int sig); extern void stub_clone_handler(void); -#define STUB_SYSCALL_RET PT_INDEX(RAX) #define STUB_MMAP_NR __NR_mmap #define MMAP_OFFSET(o) (o) -static inline long stub_syscall2(long syscall, long arg1, long arg2) -{ - long ret; - - __asm__("movq %0, %%rsi; " : : "g" (arg2) : "%rsi"); - __asm__("movq %0, %%rdi; " : : "g" (arg1) : "%rdi"); - __asm__("movq %0, %%rax; " : : "g" (syscall) : "%rax"); - __asm__("syscall;" : : : "%rax", "%r11", "%rcx"); - __asm__ __volatile__("movq %%rax, %0; " : "=g" (ret) :); - return(ret); -} - -static inline long stub_syscall3(long syscall, long arg1, long arg2, long arg3) -{ - __asm__("movq %0, %%rdx; " : : "g" (arg3) : "%rdx"); - return(stub_syscall2(syscall, arg1, arg2)); -} - -static inline long stub_syscall4(long syscall, long arg1, long arg2, long arg3, - long arg4) -{ - __asm__("movq %0, %%r10; " : : "g" (arg4) : "%r10"); - return(stub_syscall3(syscall, arg1, arg2, arg3)); -} - -static inline long stub_syscall6(long syscall, long arg1, long arg2, long arg3, - long arg4, long arg5, long arg6) -{ - __asm__("movq %0, %%r9; " : : "g" (arg6) : "%r9"); - __asm__("movq %0, %%r8; " : : "g" (arg5) : "%r8"); - return(stub_syscall4(syscall, arg1, arg2, arg3, arg4)); -} - -static inline void trap_myself(void) -{ - __asm("int3"); -} - #endif diff -urN RC14-rc3-git4-unmap/arch/um/kernel/skas/Makefile RC14-rc3-git4-uml-clone/arch/um/kernel/skas/Makefile --- RC14-rc3-git4-unmap/arch/um/kernel/skas/Makefile 2005-10-04 05:40:04.000000000 -0400 +++ RC14-rc3-git4-uml-clone/arch/um/kernel/skas/Makefile 2005-10-04 15:14:34.000000000 -0400 @@ -3,12 +3,9 @@ # Licensed under the GPL # -obj-y := clone.o exec_kern.o mem.o mem_user.o mmu.o process.o process_kern.o \ +obj-y := exec_kern.o mem.o mem_user.o mmu.o process.o process_kern.o \ syscall.o tlb.o trap_user.o uaccess.o -USER_OBJS := process.o clone.o +USER_OBJS := process.o include arch/um/scripts/Makefile.rules - -# clone.o is in the stub, so it can't be built with profiling -$(obj)/clone.o : c_flags = -Wp,-MD,$(depfile) $(call unprofile,$(USER_CFLAGS)) diff -urN RC14-rc3-git4-unmap/arch/um/kernel/skas/include/stub-data.h RC14-rc3-git4-uml-clone/arch/um/kernel/skas/include/stub-data.h --- RC14-rc3-git4-unmap/arch/um/kernel/skas/include/stub-data.h 2005-08-28 23:09:40.000000000 -0400 +++ RC14-rc3-git4-uml-clone/arch/um/kernel/skas/include/stub-data.h 2005-10-04 15:14:34.000000000 -0400 @@ -6,7 +6,11 @@ #ifndef __STUB_DATA_H #define __STUB_DATA_H +#ifdef __KERNEL__ +#include +#else #include +#endif struct stub_data { long offset; diff -urN RC14-rc3-git4-unmap/arch/um/sys-i386/Makefile RC14-rc3-git4-uml-clone/arch/um/sys-i386/Makefile --- RC14-rc3-git4-unmap/arch/um/sys-i386/Makefile 2005-10-04 15:14:33.000000000 -0400 +++ RC14-rc3-git4-uml-clone/arch/um/sys-i386/Makefile 2005-10-04 15:14:34.000000000 -0400 @@ -6,6 +6,7 @@ subarch-obj-$(CONFIG_HIGHMEM) += mm/highmem.o subarch-obj-$(CONFIG_MODULES) += kernel/module.o +obj-$(CONFIG_MODE_SKAS) += clone.o USER_OBJS := bugs.o ptrace_user.o sigcontext.o fault.o @@ -13,5 +14,5 @@ extra-$(CONFIG_MODE_TT) += unmap.o -$(obj)/stub_segv.o $(obj)/unmap.o: \ +$(obj)/stub_segv.o $(obj)/clone.o $(obj)/unmap.o: \ _c_flags = $(call unprofile,$(CFLAGS)) diff -urN RC14-rc3-git4-unmap/arch/um/sys-i386/clone.c RC14-rc3-git4-uml-clone/arch/um/sys-i386/clone.c --- RC14-rc3-git4-unmap/arch/um/sys-i386/clone.c 1969-12-31 19:00:00.000000000 -0500 +++ RC14-rc3-git4-uml-clone/arch/um/sys-i386/clone.c 2005-10-04 15:14:34.000000000 -0400 @@ -0,0 +1,47 @@ +#include +#include +#include +#include +#include "stub-data.h" + +static int errno; + +static inline _syscall2(int,clone,unsigned long,flags,unsigned long,newsp) +static inline _syscall4(long,ptrace,long,request, + pid_t,pid,void *,addr,void *,data); +static inline _syscall3(int,setitimer,int,which, const struct itimerval *,value, + struct itimerval *,ovalue); +static inline _syscall6(void *,mmap2,void *,addr,size_t,len,int,prot,int,flags,int,fd,off_t,offset) + +static inline void trap_myself(void) +{ + __asm("int3"); +} + +void __attribute__ ((__section__ (".__syscall_stub"))) +stub_clone_handler(void) +{ + long err; + struct stub_data *from = (struct stub_data *) CONFIG_STUB_DATA; + + err = clone(CLONE_PARENT | CLONE_FILES | SIGCHLD, + CONFIG_STUB_DATA + PAGE_SIZE / 2 - sizeof(void *)); + if (err) + goto out; + + err = ptrace(PTRACE_TRACEME, 0, NULL, NULL); + if (err) + goto out; + + err = setitimer(ITIMER_VIRTUAL, &from->timer, NULL); + if (err) + goto out; + + err = (long)mmap2((void *)CONFIG_STUB_DATA, PAGE_SIZE, + PROT_READ | PROT_WRITE, MAP_FIXED | MAP_SHARED, + from->fd, from->offset); +out: + /* save current result. Parent: pid; child: retcode of mmap */ + from->err = err == -1 ? errno : err; + trap_myself(); +} diff -urN RC14-rc3-git4-unmap/arch/um/sys-x86_64/Makefile RC14-rc3-git4-uml-clone/arch/um/sys-x86_64/Makefile --- RC14-rc3-git4-unmap/arch/um/sys-x86_64/Makefile 2005-10-04 15:14:33.000000000 -0400 +++ RC14-rc3-git4-uml-clone/arch/um/sys-x86_64/Makefile 2005-10-04 15:14:34.000000000 -0400 @@ -8,6 +8,7 @@ signal.o stub.o stub_segv.o syscalls.o syscall_table.o sysrq.o ksyms.o obj-$(CONFIG_MODULES) += um_module.o +obj-$(CONFIG_MODE_SKAS) += clone.o subarch-obj-y = lib/bitops.o lib/csum-partial.o lib/memcpy.o lib/thunk.o subarch-obj-$(CONFIG_MODULES) += kernel/module.o @@ -18,5 +19,5 @@ extra-$(CONFIG_MODE_TT) += unmap.o -$(obj)/stub_segv.o $(obj)/unmap.o: \ +$(obj)/stub_segv.o $(obj)/clone.o $(obj)/unmap.o: \ _c_flags = $(call unprofile,$(CFLAGS)) diff -urN RC14-rc3-git4-unmap/arch/um/sys-x86_64/clone.c RC14-rc3-git4-uml-clone/arch/um/sys-x86_64/clone.c --- RC14-rc3-git4-unmap/arch/um/sys-x86_64/clone.c 1969-12-31 19:00:00.000000000 -0500 +++ RC14-rc3-git4-uml-clone/arch/um/sys-x86_64/clone.c 2005-10-04 15:14:34.000000000 -0400 @@ -0,0 +1,47 @@ +#include +#include +#include +#include +#include "stub-data.h" + +static int errno; + +static inline _syscall2(int,clone,unsigned long,flags,unsigned long,newsp) +static inline _syscall4(long,ptrace,long,request, + pid_t,pid,void *,addr,void *,data); +static inline _syscall3(int,setitimer,int,which, const struct itimerval *,value, + struct itimerval *,ovalue); +static inline _syscall6(void *,mmap,void *,addr,size_t,len,int,prot,int,flags,int,fd,off_t,offset) + +static inline void trap_myself(void) +{ + __asm("int3"); +} + +void __attribute__ ((__section__ (".__syscall_stub"))) +stub_clone_handler(void) +{ + long err; + struct stub_data *from = (struct stub_data *) CONFIG_STUB_DATA; + + err = clone(CLONE_PARENT | CLONE_FILES | SIGCHLD, + CONFIG_STUB_DATA + PAGE_SIZE / 2 - sizeof(void *)); + if (err) + goto out; + + err = ptrace(PTRACE_TRACEME, 0, NULL, NULL); + if (err) + goto out; + + err = setitimer(ITIMER_VIRTUAL, &from->timer, NULL); + if (err) + goto out; + + err = (long)mmap((void *)CONFIG_STUB_DATA, PAGE_SIZE, + PROT_READ | PROT_WRITE, MAP_FIXED | MAP_SHARED, + from->fd, from->offset); +out: + /* save current result. Parent: pid; child: retcode of mmap */ + from->err = err == -1 ? errno : err; + trap_myself(); +}