Skip to contentSkip to conversation

PATCH: Qemu user-mode - fork - exec -

Qemu-devel Toni 2 participants 2 messages Oct 12, 2009 – Nov 10, 2009

lore
Share & tools
lore

Toni

author
#0 lore raw

Hi guys,
I found a solution for the problems with the fork and the exec under qemu user-mode.
With the fork I enabled the NPTL and now it seems to work fine. For the exec the problem was that it was execute natively, and so the qemu process was killed by the exec, so I simply called the exec for a new instance of qemu, also this seems to work fine. Let me know what do you think:

qemu-0.11.0/configure 2009-10-08 09:59:47.000000000 -0700 renamed from qemu-0.11.0/configure 2009-09-23 12:01:31.000000000 -0700 +10 -0
diff -r -u -p -B a/qemu-0.11.0/configure b/qemu-0.11.0/configure
@@ -362,6 +362,9 @@ fi
 
 werror=""
 
+# [email protected]
+enable_target_cpu_nptl="no"
+# [email protected]
 for opt do
   optarg=`expr "x$opt" : 'x[^=]*=\(.*\)'`
   case "$opt" in
@@ -489,6 +492,10 @@ for opt do
   ;;
   --disable-nptl) nptl="no"
   ;;
+# [email protected]
+  --enable-target-cpu-nptl) enable_target_cpu_nptl="yes"
+  ;;
+# [email protected]
   --enable-mixemu) mixemu="yes"
   ;;
   --disable-pthread) pthread="no"
@@ -633,6 +640,9 @@ echo "  --disable-curl           disable
 echo "  --disable-bluez          disable bluez stack connectivity"
 echo "  --disable-kvm            disable KVM acceleration support"
 echo "  --disable-nptl           disable usermode NPTL support"
+# [email protected]
+echo "  --enable-target-cpu-nptl enable NPTL support for all target CPUs"
+# [email protected]
 echo "  --enable-system          enable all system emulation targets"
 echo "  --disable-system         disable all system emulation targets"
 echo "  --enable-linux-user      enable all linux usermode emulation

targets"
@@ -2065,6 +2075,22 @@ esac
if test "$target_user_only" = "yes" -a "$bflt" = "yes"; then
echo "TARGET_HAS_BFLT=y" >> $config_mak
fi
+
+# [email protected]
+if test "$enable_target_cpu_nptl" = "yes" -a $(echo $target | cut -d - -f
2) != "softmmu"; then
+ target_nptl="yes"
+fi
+
+echo "*****"
+echo "target: " $target
+echo "target_cpu: " $target_cpu
+echo "target_user_only: " $target_user_only
+echo "nptl: " $nptl
+echo "enable_target_cpu_nptl: " $enable_target_cpu_nptl
+echo "target_nptl: " $target_nptl
+echo "*****"
+# [email protected]
+

 if test "$target_user_only" = "yes" \
         -a "$nptl" = "yes" -a "$target_nptl" = "yes"; then

echo "USE_NPTL=y" >> $config_mak

diff -r -u -p -B a/qemu-0.11.0/linux-user/main.c
b/qemu-0.11.0/linux-user/main.c

qemu-0.11.0/linux-user/main.c 2009-10-08 15:50:53.000000000 -0700 renamed from qemu-0.11.0/linux-user/main.c 2009-09-23 12:01:32.000000000 -0700 +6 -0
@@ -37,6 +37,9 @@
 #define DEBUG_LOGFILE "/tmp/qemu.log"
 
 char *exec_path;
+//[email protected]
+char *file_path;
+//[email protected]
 
 int singlestep;
 
@@ -2510,6 +2513,9 @@ int main(int argc, char **argv, char **e
         usage();
     filename = argv[optind];
     exec_path = argv[optind];
+//[email protected]
+    file_path = argv[0];
+//[email protected]
 
     /* Zero out regs */
     memset(regs, 0, sizeof(struct target_pt_regs));

diff -r -u -p -B a/qemu-0.11.0/linux-user/qemu.h
b/qemu-0.11.0/linux-user/qemu.h

qemu-0.11.0/linux-user/qemu.h 2009-10-08 16:37:31.000000000 -0700 renamed from qemu-0.11.0/linux-user/qemu.h 2009-09-23 12:01:32.000000000 -0700 +3 -0
@@ -129,6 +129,9 @@ typedef struct TaskState {
 } __attribute__((aligned(16))) TaskState;
 
 extern char *exec_path;
+// [email protected]
+extern char *file_path;
+// [email protected]
 void init_task_state(TaskState *ts);
 void task_settid(TaskState *);
 void stop_all_tasks(void);

diff -r -u -p -B a/qemu-0.11.0/linux-user/syscall.c b/qemu-0.11.0/linux-user/syscall.c
--- a/qemu-0.11.0/linux-user/syscall.c 2009-09-23 12:01:32.000000000
-0700
+++ b/qemu-0.11.0/linux-user/syscall.c 2009-10-08 17:42:11.000000000
-0700
@@ -4291,6 +4291,7 @@ abi_long do_syscall(void *cpu_env, int n

         unlock_user(p, arg2, 0);
         break;
 #endif
+//[email protected]
     case TARGET_NR_execve:
         {
             char **argp, **envp;
@@ -4300,6 +4301,7 @@ abi_long do_syscall(void *cpu_env, int n
             abi_ulong guest_envp;
             abi_ulong addr;
             char **q;

+ int i=0;

             argc = 0;
             guest_argp = arg2;
@@ -4320,10 +4322,26 @@ abi_long do_syscall(void *cpu_env, int n
                 envc++;
             }

- argp = alloca((argc + 1) * sizeof(void *));
- envp = alloca((envc + 1) * sizeof(void *));

+        if(do_strace)
+        {
+        i=2;

+ //add one more element to argc that is the path of the
qemu-i386
+ argp = alloca((argc + 3) * sizeof(void *));
+ envp = alloca((envc + 1) * sizeof(void *));
+ //put path of qemu-i386 as first element of argp and "-strace"
as second
+ *argp=file_path;

+        *(argp+1)=(char *)"-strace";
+        }
+        else{
+        i=1;

+ //add one more element to argc that is the path of the
qemu-i386
+ argp = alloca((argc + 2) * sizeof(void *));
+ envp = alloca((envc + 1) * sizeof(void *));
+ //put path of qemu-i386 as first element of argp
+ *argp=file_path;
+ }

- for (gp = guest_argp, q = argp; gp;

+        for (gp = guest_argp, q = argp+i; gp;
                   gp += sizeof(abi_ulong), q++) {
                 if (get_user_ual(addr, gp))
                     goto execve_efault;

@@ -4347,7 +4365,14 @@ abi_long do_syscall(void *cpu_env, int n

             if (!(p = lock_user_string(arg1)))
                 goto execve_efault;
-            ret = get_errno(execve(p, argp, envp));
+
+        //put in position i the name of program to execute
+        *(argp+i)=p;
+        printf("\nA new instance of QEMU-i386 will execute\n");
+        printf("the program called by the instruction exec\n\n");
+        ret = get_errno(execve(file_path, argp, envp));
+        printf("\nThe execve was not executed well!!!!!\n\n");
+
             unlock_user(p, arg1, 0);

             goto execve_end;
@@ -4372,6 +4397,7 @@ abi_long do_syscall(void *cpu_env, int n
             }
         }
         break;
+//[email protected]
     case TARGET_NR_chdir:
         if (!(p = lock_user_string(arg1)))
             goto efault;

diff -r -u -p -B a/qemu-0.11.0/target-i386/cpu.h
b/qemu-0.11.0/target-i386/cpu.h

qemu-0.11.0/target-i386/cpu.h 2009-10-08 10:41:49.000000000 -0700 renamed from qemu-0.11.0/target-i386/cpu.h 2009-09-23 12:01:32.000000000 -0700 +6 -0
@@ -918,4 +918,10 @@ void apic_init_reset(CPUState *env);
 void apic_sipi(CPUState *env);
 void do_cpu_init(CPUState *env);
 void do_cpu_sipi(CPUState *env);
+
+//[email protected]
+static inline void cpu_set_tls(CPUState *env, target_ulong newtls)
+{
+}
+//[email protected]
 #endif /* CPU_I386_H */
#1 lore raw
Quoted 8 lines · Toni

Hi guys,
I found a solution for the problems with the fork and the exec under qemu user-mode.
With the fork I enabled the NPTL and now it seems to work fine. For the exec the problem was that it was execute natively, and so the qemu process was killed by the exec, so I simply called the exec for a new instance of qemu, also this seems to work fine. Let me know what do you think:

It will break horribly for shell scripts, multi-arch systems, etc. This is something the host kernel should really be taking care of.

Your patch also appears to have a load of unrelated cruft.

Paul