From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1MxP4x-0005mz-8l for qemu-devel@nongnu.org; Mon, 12 Oct 2009 13:53:03 -0400 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1MxP4r-0005hj-Lb for qemu-devel@nongnu.org; Mon, 12 Oct 2009 13:53:02 -0400 Received: from [199.232.76.173] (port=49421 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1MxP4r-0005hX-6c for qemu-devel@nongnu.org; Mon, 12 Oct 2009 13:52:57 -0400 Received: from mail-px0-f179.google.com ([209.85.216.179]:57523) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1MxP4q-0005bo-6K for qemu-devel@nongnu.org; Mon, 12 Oct 2009 13:52:56 -0400 Received: by pxi9 with SMTP id 9so8759957pxi.4 for ; Mon, 12 Oct 2009 10:52:51 -0700 (PDT) MIME-Version: 1.0 Date: Mon, 12 Oct 2009 10:52:51 -0700 Message-ID: <526ddcfc0910121052m21615ebdj229a9dd7587f9aa5@mail.gmail.com> From: Toni Content-Type: multipart/alternative; boundary=0016e64b044836abe90475c099da Subject: [Qemu-devel] PATCH: Qemu user-mode - fork - exec - List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org --0016e64b044836abe90475c099da Content-Type: text/plain; charset=ISO-8859-1 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: 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 */ --0016e64b044836abe90475c099da Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable 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 exe= c for a new instance of qemu, also this seems to work fine. Let me know wha= t do you think:


diff -r -u -p -B a/qemu-0.11.0/configure b/qemu-0.11.0/configure--- a/qemu-0.11.0/configure=A0=A0=A0 2009-09-23 12:01:31.000000000 -0700+++ b/qemu-0.11.0/configure=A0=A0=A0 2009-10-08 09:59:47.000000000 -0700<= br>@@ -362,6 +362,9 @@ fi
=A0
=A0werror=3D""
=A0
+# tonygio04@aol.com
+enable_target_cpu_nptl=3D"no"+# tonygio04@aol.com
=A0for op= t do
=A0=A0 optarg=3D`expr "x$opt" : 'x[^=3D]*=3D\(.*\)= 9;`
=A0=A0 case "$opt" in
@@ -489,6 +492,10 @@ for opt do
=A0= =A0 ;;
=A0=A0 --disable-nptl) nptl=3D"no"
=A0=A0 ;;
+# <= a href=3D"mailto:tonygio04@aol.com">tonygio04@aol.com
+=A0 --enable-= target-cpu-nptl) enable_target_cpu_nptl=3D"yes"
+=A0 ;;
+# tonygio04@aol.com=A0=A0 --enable-mixemu) mixemu=3D"yes"
=A0=A0 ;;
=A0=A0 --= disable-pthread) pthread=3D"no"
@@ -633,6 +640,9 @@ echo "= ;=A0 --disable-curl=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 disable
=A0echo "=A0 --disable-bluez=A0=A0=A0=A0=A0=A0=A0=A0=A0 disable bluez = stack connectivity"
=A0echo "=A0 --disable-kvm=A0=A0=A0=A0=A0= =A0=A0=A0=A0=A0=A0 disable KVM acceleration support"
=A0echo "= =A0 --disable-nptl=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 disable usermode NPTL supp= ort"
+# tonygio04@aol.com
+echo &quo= t;=A0 --enable-target-cpu-nptl enable NPTL support for all target CPUs"= ;
+# tonygio04@aol.com
=A0ec= ho "=A0 --enable-system=A0=A0=A0=A0=A0=A0=A0=A0=A0 enable all system e= mulation targets"
=A0echo "=A0 --disable-system=A0=A0=A0=A0=A0=A0=A0=A0 disable all syst= em emulation targets"
=A0echo "=A0 --enable-linux-user=A0=A0= =A0=A0=A0 enable all linux usermode emulation targets"
@@ -2065,6 += 2075,22 @@ esac
=A0if test "$target_user_only" =3D "yes&q= uot; -a "$bflt" =3D "yes"; then
=A0=A0 echo "TARGET_HAS_BFLT=3Dy" >> $config_mak
=A0fi+
+# tonygio04@aol.com
+if= test "$enable_target_cpu_nptl" =3D "yes" -a $(echo $ta= rget | cut -d - -f 2) !=3D "softmmu"; then
+=A0=A0 target_nptl=3D"yes"
+fi
+
+echo "*****"= ;
+echo "target: " $target
+echo "target_cpu: " $= target_cpu
+echo "target_user_only: " $target_user_only
+ec= ho "nptl: " $nptl
+echo "enable_target_cpu_nptl: " $enable_target_cpu_nptl
+echo= "target_nptl: " $target_nptl
+echo "*****"
+# tonygio04@aol.com
+
=A0if test= "$target_user_only" =3D "yes" \
=A0=A0=A0=A0=A0=A0=A0=A0 -a "$nptl" =3D "yes" -a "= $target_nptl" =3D "yes"; then
=A0=A0 echo "USE_NPTL= =3Dy" >> $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=A0=A0=A0 2009-09-23 12:01:32.000000000 = -0700
+++ b/qemu-0.11.0/linux-user/main.c=A0=A0=A0 2009-10-08 15:50:53.0= 00000000 -0700
@@ -37,6 +37,9 @@
=A0#define DEBUG_LOGFILE "/tmp/= qemu.log"
=A0
=A0char *exec_path;
+//tonyg= io04@aol.com
+char *file_path;
+//tonygio04@aol.com
=A0
=A0int singlestep;
=A0
@@ -2510= ,6 +2513,9 @@ int main(int argc, char **argv, char **e
=A0=A0=A0=A0=A0=A0=A0=A0 usage();
=A0=A0=A0=A0 filename =3D argv[optind]= ;
=A0=A0=A0=A0 exec_path =3D argv[optind];
+//tonygio04@aol.com
+=A0=A0=A0 file_path =3D argv[0];+//tonygio04@aol.com
=A0
=A0=A0=A0=A0 /* Zero out regs */
=A0=A0=A0=A0 memset(regs, 0, siz= eof(struct target_pt_regs));
diff -r -u -p -B a/qemu-0.11.0/linux-user/q= emu.h b/qemu-0.11.0/linux-user/qemu.h
--- a/qemu-0.11.0/linux-user/qemu.= h=A0=A0=A0 2009-09-23 12:01:32.000000000 -0700
+++ b/qemu-0.11.0/linux-user/qemu.h=A0=A0=A0 2009-10-08 16:37:31.000000000 = -0700
@@ -129,6 +129,9 @@ typedef struct TaskState {
=A0} __attribute= __((aligned(16))) TaskState;
=A0
=A0extern char *exec_path;
+// tonygio04@aol.com
+extern char *file_path;
+// tonygi= o04@aol.com
=A0void init_task_state(TaskState *ts);
=A0void task_= settid(TaskState *);
=A0void 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=A0=A0=A0 2009-09-23 12:01:32.0000000= 00 -0700
+++ b/qemu-0.11.0/linux-user/syscall.c=A0=A0=A0 2009-10-08 17:4= 2:11.000000000 -0700
@@ -4291,6 +4291,7 @@ abi_long do_syscall(void *cpu= _env, int n
=A0=A0=A0=A0=A0=A0=A0=A0 unlock_user(p, arg2, 0);
=A0=A0=A0=A0=A0=A0=A0= =A0 break;
=A0#endif
+//tonygio0= 4@aol.com
=A0=A0=A0=A0 case TARGET_NR_execve:
=A0=A0=A0=A0=A0=A0= =A0=A0 {
=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 char **argp, **envp;
@@= -4300,6 +4301,7 @@ abi_long do_syscall(void *cpu_env, int n
=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 abi_ulong guest_envp;
=A0=A0=A0=A0= =A0=A0=A0=A0=A0=A0=A0=A0 abi_ulong addr;
=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0= =A0=A0 char **q;
+=A0=A0=A0 =A0=A0=A0 int i=3D0;
=A0
=A0=A0=A0=A0= =A0=A0=A0=A0=A0=A0=A0=A0 argc =3D 0;
=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0= =A0 guest_argp =3D arg2;
@@ -4320,10 +4322,26 @@ abi_long do_syscall(voi= d *cpu_env, int n
=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 envc++;
=A0=A0=A0=A0=A0= =A0=A0=A0=A0=A0=A0=A0 }
=A0
-=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 argp = =3D alloca((argc + 1) * sizeof(void *));
-=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0= =A0 envp =3D alloca((envc + 1) * sizeof(void *));
+=A0=A0=A0 =A0=A0=A0 i= f(do_strace)
+=A0=A0=A0 =A0=A0=A0 {
+=A0=A0=A0 =A0=A0=A0 i=3D2;
+=A0=A0=A0 =A0=A0=A0 =A0=A0=A0 //add one more element to argc that is the p= ath of the qemu-i386
+=A0=A0=A0 =A0=A0=A0 =A0=A0=A0 argp =3D alloca((ar= gc + 3) * sizeof(void *));
+=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 =A0=A0=A0= envp =3D alloca((envc + 1) * sizeof(void *));
+=A0=A0=A0 =A0=A0=A0 =A0= =A0=A0 //put path of qemu-i386 as first element of argp and "-strace&q= uot; as second
+=A0=A0=A0 =A0=A0=A0 =A0=A0=A0 *argp=3Dfile_path;
+=A0=A0=A0 =A0=A0=A0 *= (argp+1)=3D(char *)"-strace";
+=A0=A0=A0 =A0=A0=A0 }
+=A0= =A0=A0 =A0=A0=A0 else{
+=A0=A0=A0 =A0=A0=A0 i=3D1;
+=A0=A0=A0 =A0=A0= =A0 =A0=A0=A0 //add one more element to argc that is the path of the qemu-i= 386
+=A0=A0=A0 =A0=A0=A0 =A0=A0=A0 argp =3D alloca((argc + 2) * sizeof(= void *));=A0=A0=A0
+=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 =A0=A0=A0 envp =3D alloca((envc + 1) * s= izeof(void *));
+=A0=A0=A0 =A0=A0=A0 =A0=A0=A0 //put path of qemu-i386 a= s first element of argp
+=A0=A0=A0 =A0=A0=A0 =A0=A0=A0 *argp=3Dfile_path= ;
+=A0=A0=A0 =A0=A0=A0 }
=A0
-=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 fo= r (gp =3D guest_argp, q =3D argp; gp;
+=A0=A0=A0 =A0=A0=A0 for (gp =3D guest_argp, q =3D argp+i; gp;
=A0=A0=A0= =A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 gp +=3D sizeof(abi_ulong), q+= +) {
=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 if (get_user_ual(a= ddr, gp))
=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 g= oto execve_efault;
@@ -4347,7 +4365,14 @@ abi_long do_syscall(void *cpu_= env, int n
=A0
=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 if (!(p =3D lock_user_string(ar= g1)))
=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 goto execve_efaul= t;
-=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 ret =3D get_errno(execve(p, argp, = envp));
+=A0=A0=A0 =A0=A0=A0
+=A0=A0=A0 =A0=A0=A0 //put in position = i the name of program to execute
+=A0=A0=A0 =A0=A0=A0 *(argp+i)=3Dp;
+=A0=A0=A0 =A0=A0=A0 printf("\n= A new instance of QEMU-i386 will execute\n");
+=A0=A0=A0 =A0=A0=A0 = printf("the program called by the instruction exec\n\n");
+=A0= =A0=A0 =A0=A0=A0 ret =3D get_errno(execve(file_path, argp, envp));
+=A0=A0=A0 =A0=A0=A0 printf("\nThe execve was not executed well!!!!!\n= \n");
+
=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 unlock_user(p, arg1= , 0);
=A0
=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 goto execve_end;
@@= -4372,6 +4397,7 @@ abi_long do_syscall(void *cpu_env, int n
=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 }
=A0=A0=A0=A0=A0=A0=A0=A0 }
=A0= =A0=A0=A0=A0=A0=A0=A0 break;
+//ton= ygio04@aol.com
=A0=A0=A0=A0 case TARGET_NR_chdir:
=A0=A0=A0=A0=A0= =A0=A0=A0 if (!(p =3D lock_user_string(arg1)))
=A0=A0=A0=A0=A0=A0=A0=A0= =A0=A0=A0=A0 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=A0=A0=A0 2009-09-23 12:01:32.0= 00000000 -0700
+++ b/qemu-0.11.0/target-i386/cpu.h=A0=A0=A0 2009-10-08 1= 0:41:49.000000000 -0700
@@ -918,4 +918,10 @@ void apic_init_reset(CPUState *env);
=A0void apic_s= ipi(CPUState *env);
=A0void do_cpu_init(CPUState *env);
=A0void do_cp= u_sipi(CPUState *env);
+
+//tony= gio04@aol.com
+static inline void cpu_set_tls(CPUState *env, target_ulong newtls)
+{+}
+//tonygio04@aol.com
= =A0#endif /* CPU_I386_H */
--0016e64b044836abe90475c099da--