2007-07-10 18:55:54 +02:00
|
|
|
Index: qemu.bkp/linux-user/main.c
|
2007-11-13 21:32:02 +01:00
|
|
|
================================================================================
|
2008-01-18 00:38:52 +01:00
|
|
|
--- qemu-0.9.1/linux-user/syscall.c
|
|
|
|
+++ qemu-0.9.1/linux-user/syscall.c
|
2007-11-13 21:32:02 +01:00
|
|
|
@@ -159,6 +159,7 @@
|
|
|
|
#define __NR_sys_tkill __NR_tkill
|
|
|
|
#define __NR_sys_unlinkat __NR_unlinkat
|
|
|
|
#define __NR_sys_utimensat __NR_utimensat
|
2007-07-10 18:55:54 +02:00
|
|
|
+#define __NR_sys_clone __NR_clone
|
|
|
|
|
|
|
|
#if defined(__alpha__) || defined (__ia64__) || defined(__x86_64__)
|
|
|
|
#define __NR__llseek __NR_lseek
|
2007-11-13 21:32:02 +01:00
|
|
|
@@ -227,6 +228,9 @@
|
|
|
|
#if defined(TARGET_NR_tkill) && defined(__NR_tkill)
|
|
|
|
_syscall2(int,sys_tkill,int,tid,int,sig)
|
|
|
|
#endif
|
|
|
|
+#ifdef __NR_sys_clone
|
2007-07-10 18:55:54 +02:00
|
|
|
+_syscall5(int,sys_clone, int, flags, void *, child_stack, int *, parent_tidptr, void *, newtls, int *, child_tidptr)
|
2007-11-13 21:32:02 +01:00
|
|
|
+#endif
|
2007-07-10 18:55:54 +02:00
|
|
|
#ifdef __NR_exit_group
|
|
|
|
_syscall1(int,exit_group,int,error_code)
|
|
|
|
#endif
|
2008-01-18 00:38:52 +01:00
|
|
|
@@ -2705,15 +2783,20 @@
|
2007-07-10 18:55:54 +02:00
|
|
|
|
2007-11-13 21:32:02 +01:00
|
|
|
/* do_fork() Must return host values and target errnos (unlike most
|
|
|
|
do_*() functions). */
|
|
|
|
-int do_fork(CPUState *env, unsigned int flags, abi_ulong newsp)
|
|
|
|
+int do_fork(CPUState *env, unsigned int flags, abi_ulong newsp, abi_ulong parent_tidptr, abi_ulong newtls, abi_ulong child_tidptr)
|
2007-07-10 18:55:54 +02:00
|
|
|
{
|
|
|
|
int ret;
|
2007-11-13 21:32:02 +01:00
|
|
|
+ unsigned long parent_tid = gettid();
|
2007-07-10 18:55:54 +02:00
|
|
|
TaskState *ts;
|
|
|
|
uint8_t *new_stack;
|
|
|
|
CPUState *new_env;
|
|
|
|
+#if defined(TARGET_I386)
|
|
|
|
+ uint64_t *new_gdt_table;
|
|
|
|
+#endif
|
2007-11-13 21:32:02 +01:00
|
|
|
|
2007-07-10 18:55:54 +02:00
|
|
|
if (flags & CLONE_VM) {
|
|
|
|
ts = malloc(sizeof(TaskState) + NEW_STACK_SIZE);
|
2007-11-13 21:32:02 +01:00
|
|
|
+ if (!ts) return -ENOMEM;
|
2007-07-10 18:55:54 +02:00
|
|
|
memset(ts, 0, sizeof(TaskState));
|
|
|
|
new_stack = ts->stack;
|
|
|
|
ts->used = 1;
|
2008-01-18 00:38:52 +01:00
|
|
|
@@ -2725,6 +2808,27 @@
|
2007-07-10 18:55:54 +02:00
|
|
|
#if defined(TARGET_I386)
|
|
|
|
if (!newsp)
|
|
|
|
newsp = env->regs[R_ESP];
|
|
|
|
+ new_gdt_table = malloc(9 * 8);
|
|
|
|
+ if (!new_gdt_table) {
|
|
|
|
+ free(new_env);
|
|
|
|
+ return -ENOMEM;
|
|
|
|
+ }
|
|
|
|
+ /* Copy main GDT table from parent, but clear TLS entries */
|
|
|
|
+ memcpy(new_gdt_table, g2h(env->gdt.base), 6 * 8);
|
|
|
|
+ memset(&new_gdt_table[6], 0, 3 * 8);
|
|
|
|
+ new_env->gdt.base = h2g(new_gdt_table);
|
|
|
|
+ if (flags & CLONE_SETTLS) {
|
|
|
|
+ ret = do_set_thread_area(new_env, newtls);
|
|
|
|
+ if (ret) {
|
|
|
|
+ free(new_gdt_table);
|
|
|
|
+ free(new_env);
|
|
|
|
+ return ret;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ cpu_x86_load_seg(new_env, R_FS, new_env->segs[R_FS].selector);
|
|
|
|
+ cpu_x86_load_seg(new_env, R_GS, new_env->segs[R_GS].selector);
|
|
|
|
+
|
|
|
|
new_env->regs[R_ESP] = newsp;
|
|
|
|
new_env->regs[R_EAX] = 0;
|
|
|
|
#elif defined(TARGET_ARM)
|
2008-01-18 00:38:52 +01:00
|
|
|
@@ -2782,15 +2886,27 @@
|
2007-07-10 18:55:54 +02:00
|
|
|
#endif
|
|
|
|
new_env->opaque = ts;
|
|
|
|
#ifdef __ia64__
|
|
|
|
- ret = __clone2(clone_func, new_stack + NEW_STACK_SIZE, flags, new_env);
|
|
|
|
+ ret = __clone2(clone_func, new_stack + NEW_STACK_SIZE, flags & ~(CLONE_SETTLS|CLONE_PARENT_SETTID|CLONE_CHILD_CLEARTID), new_env);
|
|
|
|
#else
|
|
|
|
- ret = clone(clone_func, new_stack + NEW_STACK_SIZE, flags, new_env);
|
|
|
|
+ ret = clone(clone_func, new_stack + NEW_STACK_SIZE, flags & ~(CLONE_SETTLS|CLONE_PARENT_SETTID|CLONE_CHILD_CLEARTID), new_env);
|
|
|
|
#endif
|
|
|
|
} else {
|
|
|
|
/* if no CLONE_VM, we consider it is a fork */
|
|
|
|
- if ((flags & ~CSIGNAL) != 0)
|
|
|
|
- return -EINVAL;
|
|
|
|
- ret = fork();
|
|
|
|
+ ret = sys_clone(flags & ~(CLONE_SETTLS|CLONE_PARENT_SETTID|CLONE_CHILD_CLEARTID), 0, g2h(parent_tidptr), NULL, g2h(child_tidptr));
|
|
|
|
+ }
|
|
|
|
+ /* Store child thread ID at location parent_tidptr in parent and child memory.
|
|
|
|
+ Currently this is only done in client memory */
|
|
|
|
+ if(flags & CLONE_PARENT_SETTID) {
|
2008-01-18 00:38:52 +01:00
|
|
|
+ put_user_u32(parent_tidptr, parent_tid);
|
2007-07-10 18:55:54 +02:00
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /* Store child thread ID at location child_tidptr in child memory. */
|
|
|
|
+ if(flags & CLONE_CHILD_SETTID) {
|
|
|
|
+ if(ret==0) { /* only in client memory for fork() */
|
2008-01-18 00:38:52 +01:00
|
|
|
+ put_user_u32(child_tidptr, gettid());
|
2007-07-10 18:55:54 +02:00
|
|
|
+ } else if(flags & CLONE_VM) { /* real threads need it too */
|
2008-01-18 00:38:52 +01:00
|
|
|
+ put_user_u32(child_tidptr, ret);
|
2007-07-10 18:55:54 +02:00
|
|
|
+ }
|
|
|
|
}
|
|
|
|
return ret;
|
|
|
|
}
|
2008-01-18 00:38:52 +01:00
|
|
|
@@ -3073,7 +3189,7 @@
|
2007-07-10 18:55:54 +02:00
|
|
|
_mcleanup();
|
|
|
|
#endif
|
|
|
|
gdb_exit(cpu_env, arg1);
|
|
|
|
- /* XXX: should free thread stack and CPU env */
|
|
|
|
+ /* XXX: should free thread stack, GDT and CPU env */
|
|
|
|
_exit(arg1);
|
|
|
|
ret = 0; /* avoid warning */
|
|
|
|
break;
|
2008-01-18 00:38:52 +01:00
|
|
|
@@ -3115,7 +3231,7 @@
|
2007-07-10 18:55:54 +02:00
|
|
|
ret = do_brk(arg1);
|
|
|
|
break;
|
|
|
|
case TARGET_NR_fork:
|
|
|
|
- ret = get_errno(do_fork(cpu_env, SIGCHLD, 0));
|
|
|
|
+ ret = get_errno(do_fork(cpu_env, SIGCHLD, 0, 0,0,0));
|
|
|
|
break;
|
|
|
|
#ifdef TARGET_NR_waitpid
|
|
|
|
case TARGET_NR_waitpid:
|
2008-01-18 00:38:52 +01:00
|
|
|
@@ -4477,7 +4593,7 @@
|
2007-07-10 18:55:54 +02:00
|
|
|
ret = get_errno(fsync(arg1));
|
|
|
|
break;
|
|
|
|
case TARGET_NR_clone:
|
|
|
|
- ret = get_errno(do_fork(cpu_env, arg1, arg2));
|
|
|
|
+ ret = get_errno(do_fork(cpu_env, arg1, arg2,arg3,arg4,arg5));
|
|
|
|
break;
|
|
|
|
#ifdef __NR_exit_group
|
|
|
|
/* new thread calls */
|
2008-01-18 00:38:52 +01:00
|
|
|
@@ -4897,7 +5013,7 @@
|
2007-07-10 18:55:54 +02:00
|
|
|
#endif
|
|
|
|
#ifdef TARGET_NR_vfork
|
|
|
|
case TARGET_NR_vfork:
|
|
|
|
- ret = get_errno(do_fork(cpu_env, CLONE_VFORK | CLONE_VM | SIGCHLD, 0));
|
|
|
|
+ ret = get_errno(do_fork(cpu_env, CLONE_VFORK | CLONE_VM | SIGCHLD, 0, 0,0,0));
|
|
|
|
break;
|
|
|
|
#endif
|
|
|
|
#ifdef TARGET_NR_ugetrlimit
|