Patchwork PATCH: Qemu user-mode - fork - exec -

login
register
mail settings
Submitter Toni
Date Oct. 12, 2009, 5:52 p.m.
Message ID <526ddcfc0910121052m21615ebdj229a9dd7587f9aa5@mail.gmail.com>
Download mbox | patch
Permalink /patch/35809/
State New
Headers show

Comments

Toni - Oct. 12, 2009, 5:52 p.m.
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:
Paul Brook - Nov. 10, 2009, 3:58 p.m.
On Monday 12 October 2009, Toni wrote:
> 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

Patch

diff -r -u -p -B a/qemu-0.11.0/configure b/qemu-0.11.0/configure
--- a/qemu-0.11.0/configure    2009-09-23 12:01:31.000000000 -0700
+++ b/qemu-0.11.0/configure    2009-10-08 09:59:47.000000000 -0700
@@ -362,6 +362,9 @@  fi

 werror=""

+# tonygio04@aol.com
+enable_target_cpu_nptl="no"
+# tonygio04@aol.com
 for opt do
   optarg=`expr "x$opt" : 'x[^=]*=\(.*\)'`
   case "$opt" in
@@ -489,6 +492,10 @@  for opt do
   ;;
   --disable-nptl) nptl="no"
   ;;
+# tonygio04@aol.com
+  --enable-target-cpu-nptl) enable_target_cpu_nptl="yes"
+  ;;
+# tonygio04@aol.com
   --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"
+# tonygio04@aol.com
+echo "  --enable-target-cpu-nptl enable NPTL support for all target CPUs"
+# tonygio04@aol.com
 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
+
+# tonygio04@aol.com
+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 "*****"
+# tonygio04@aol.com
+
 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
--- a/qemu-0.11.0/linux-user/main.c    2009-09-23 12:01:32.000000000 -0700
+++ b/qemu-0.11.0/linux-user/main.c    2009-10-08 15:50:53.000000000 -0700
@@ -37,6 +37,9 @@ 
 #define DEBUG_LOGFILE "/tmp/qemu.log"

 char *exec_path;
+//tonygio04@aol.com
+char *file_path;
+//tonygio04@aol.com

 int singlestep;

@@ -2510,6 +2513,9 @@  int main(int argc, char **argv, char **e
         usage();
     filename = argv[optind];
     exec_path = argv[optind];
+//tonygio04@aol.com
+    file_path = argv[0];
+//tonygio04@aol.com

     /* 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
--- a/qemu-0.11.0/linux-user/qemu.h    2009-09-23 12:01:32.000000000 -0700
+++ b/qemu-0.11.0/linux-user/qemu.h    2009-10-08 16:37:31.000000000 -0700
@@ -129,6 +129,9 @@  typedef struct TaskState {
 } __attribute__((aligned(16))) TaskState;

 extern char *exec_path;
+// tonygio04@aol.com
+extern char *file_path;
+// tonygio04@aol.com
 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
+//tonygio04@aol.com
     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;
+//tonygio04@aol.com
     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
--- a/qemu-0.11.0/target-i386/cpu.h    2009-09-23 12:01:32.000000000 -0700
+++ b/qemu-0.11.0/target-i386/cpu.h    2009-10-08 10:41:49.000000000 -0700
@@ -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);
+
+//tonygio04@aol.com
+static inline void cpu_set_tls(CPUState *env, target_ulong newtls)
+{
+}
+//tonygio04@aol.com
 #endif /* CPU_I386_H */