@@ -8290,6 +8290,38 @@ static int host_to_target_cpu_mask(const unsigned long *host_mask,
8290
8290
}
8291
8291
#endif
8292
8292
8293
+ // executes the specified program in a QEMU VM
8294
+ static int qemu_execve (const char * filename , char * * argv , char * * envp )
8295
+ {
8296
+ int target_argc = 0 ;
8297
+ char * * exec_argv ;
8298
+ int i ;
8299
+ const char * fname = path (filename );
8300
+
8301
+ // count number of arguments the target program is passing
8302
+ while (argv [target_argc ] != NULL )
8303
+ target_argc ++ ;
8304
+
8305
+ exec_argv = g_malloc ((qemu_argc + target_argc + 1 ) * sizeof (* exec_argv ));
8306
+
8307
+ // add qemu args
8308
+ for (i = 0 ; i < qemu_argc ; i ++ )
8309
+ exec_argv [i ] = qemu_argv [i ];
8310
+
8311
+ // add target program args
8312
+ exec_argv [qemu_argc + 0 ] = (char * )fname ;
8313
+ for (i = 1 ; i < target_argc ; i ++ )
8314
+ exec_argv [qemu_argc + i ] = argv [i ];
8315
+
8316
+ // end with a null pointer
8317
+ exec_argv [qemu_argc + target_argc ] = NULL ;
8318
+
8319
+ int ret = safe_execve (exec_argv [0 ], exec_argv , envp );
8320
+
8321
+ g_free (exec_argv );
8322
+ return ret ;
8323
+ }
8324
+
8293
8325
/* do_syscall() should always have a single exit point at the end so
8294
8326
that actions, such as logging of syscall results, can be performed.
8295
8327
All errnos that do_syscall() returns must be -TARGET_<errcode>. */
@@ -8624,7 +8656,7 @@ abi_long do_syscall(void *cpu_env, int num, abi_long arg1,
8624
8656
* before the execve completes and makes it the other
8625
8657
* program's problem.
8626
8658
*/
8627
- ret = get_errno (safe_execve ( path ( p ) , argp , envp ));
8659
+ ret = get_errno (qemu_execve ( p , argp , envp ));
8628
8660
unlock_user (p , arg1 , 0 );
8629
8661
8630
8662
goto execve_end ;
0 commit comments