diff options
Diffstat (limited to 'linux-user/main.c')
-rw-r--r-- | linux-user/main.c | 42 |
1 files changed, 35 insertions, 7 deletions
diff --git a/linux-user/main.c b/linux-user/main.c index 4832d3f860..7eabd0c22f 100644 --- a/linux-user/main.c +++ b/linux-user/main.c @@ -25,6 +25,7 @@ #include <errno.h> #include <unistd.h> #include <sys/mman.h> +#include <sys/syscall.h> #include "qemu.h" #include "qemu-common.h" @@ -2319,6 +2320,27 @@ static void usage(void) THREAD CPUState *thread_env; +void task_settid(TaskState *ts) +{ + if (ts->ts_tid == 0) { +#ifdef USE_NPTL + ts->ts_tid = (pid_t)syscall(SYS_gettid); +#else + /* when no threads are used, tid becomes pid */ + ts->ts_tid = getpid(); +#endif + } +} + +void stop_all_tasks(void) +{ + /* + * We trust that when using NPTL, start_exclusive() + * handles thread stopping correctly. + */ + start_exclusive(); +} + /* Assumes contents are already zeroed. */ void init_task_state(TaskState *ts) { @@ -2338,6 +2360,7 @@ int main(int argc, char **argv, char **envp) const char *cpu_model; struct target_pt_regs regs1, *regs = ®s1; struct image_info info1, *info = &info1; + struct linux_binprm bprm; TaskState ts1, *ts = &ts1; CPUState *env; int optind; @@ -2467,6 +2490,8 @@ int main(int argc, char **argv, char **envp) /* Zero out image_info */ memset(info, 0, sizeof(struct image_info)); + memset(&bprm, 0, sizeof (bprm)); + /* Scan interp_prefix dir for replacement files. */ init_paths(interp_prefix); @@ -2543,7 +2568,16 @@ int main(int argc, char **argv, char **envp) } target_argv[target_argc] = NULL; - if (loader_exec(filename, target_argv, target_environ, regs, info) != 0) { + memset(ts, 0, sizeof(TaskState)); + init_task_state(ts); + /* build Task State */ + ts->info = info; + ts->bprm = &bprm; + env->opaque = ts; + task_settid(ts); + + if (loader_exec(filename, target_argv, target_environ, regs, + info, &bprm) != 0) { printf("Error loading %s\n", filename); _exit(1); } @@ -2579,12 +2613,6 @@ int main(int argc, char **argv, char **envp) syscall_init(); signal_init(); - /* build Task State */ - memset(ts, 0, sizeof(TaskState)); - init_task_state(ts); - ts->info = info; - env->opaque = ts; - #if defined(TARGET_I386) cpu_x86_set_cpl(env, 3); |