1/* 2 * Part of the execve tests. This program should not be compiled fat. xnu_quick_test 3 * will call the various single-architecture builds of this program as helpers to test 4 * the exec() transitions it cannot test itself. 5 * 6 * When running on a 64-bit machine (x86_64 or PPC64), the 32-bit version of 7 * xnu_quick_test will fork and exec a 64-bit helper process that performs 8 * the following tests. 9 * 1. 64 bit process forking() 64-bit child, child execing() 64-bit file(4GB pagezero) 10 * 2. 64 bit process forking() 64-bit child, child execing() 64-bit file (4KB pagezero) 11 * 3. 64 bit process forking() 64-bit child, child execing() 32-bit file 12 * 13 * The 64-bit version of xnu_quick_test will fork and exec a 32-bit process 14 * that performs the following tests. 15 * 4. 32 bit process forking() 32-bit child, child execing() 32-bit file 16 * 5. 32 bit process forking() 32-bit child, child execing() 64 bit file (4GB pagezero) 17 * 6. 32 bit process forking() 32-bit child, child execing() 64 bit file (4KB pagezero) 18 */ 19 20#include <stdio.h> 21#include <sys/types.h> 22#include <sys/syscall.h> 23 24extern int do_execve_test(char * path, char * argv[], void * envp, int killwait); 25extern int get_bits(void); 26 27 28int main(int argc, const char * argv[]) 29{ 30 int my_err, my_status; 31 pid_t my_pid, my_wait_pid; 32 char * errmsg = NULL; 33 char * argvs[2] = {"", NULL}; 34 int bits = get_bits(); /* Gets actual processor bit-ness. */ 35 36#if defined(__i386__) 37 /* 38 * This is the helper binary for the x86_64 version of xnu_quick_test. xnu_quick_test 39 * forks and execs this code to test exec()ing from a 32-bit binary. 40 */ 41 errmsg = "execve failed: from i386 forking and exec()ing i386 process.\n"; 42 argvs[0] = "sleep-i386"; 43 if (do_execve_test("helpers/sleep-i386", argvs, NULL, 0)) goto test_failed_exit; 44 45 errmsg = "execve failed: from i386 forking and exec()ing x86_64 process w/ 4G pagezero.\n"; 46 argvs[0] = "sleep-x86_64-4G"; 47 if (do_execve_test("helpers/sleep-x86_64-4G", argvs, NULL, 0)) goto test_failed_exit; 48 49 errmsg = "execve failed: from i386 forking and exec()ing x86_64 process w/ 4K pagezero.\n"; 50 argvs[0] = "sleep-x86_64-4K"; 51 if (do_execve_test("helpers/sleep-x86_64-4K", argvs, NULL, 0)) goto test_failed_exit; 52#endif 53 54 55#if defined(__x86_64__) 56 /* 57 * This is the helper binary for the i386 version of xnu_quick_test. xnu_quick_test 58 * forks and execs this code to test exec()ing from a 64-bit binary. 59 */ 60 errmsg = "execve failed: from x86_64 forking and exec()ing 64-bit x86_64 process w/ 4G pagezero.\n"; 61 argvs[0] = "sleep-x86_64-4G"; 62 if (do_execve_test("helpers/sleep-x86_64-4G", argvs, NULL, 1)) goto test_failed_exit; 63 64 errmsg = "execve failed: from x86_64 forking and exec()ing 64-bit x86_64 process w/ 4K Pagezero.\n"; 65 argvs[0] = "sleep-x86_64-4K"; 66 if (do_execve_test("helpers/sleep-x86_64-4K", argvs, NULL, 1)) goto test_failed_exit; 67 68 errmsg = "execve failed: from x64_64 forking and exec()ing 32-bit i386 process.\n"; 69 argvs[0] = "sleep-i386"; 70 if (do_execve_test("helpers/sleep-i386", argvs, NULL, 1)) goto test_failed_exit; 71#endif 72 73 74#if defined(__ppc__) 75 /* 76 * This is the helper binary for the PPC64 version of xnu_quick_test. xnu_quick_test 77 * forks and execs this code to test exec()ing from a 32-bit binary. 78 */ 79 errmsg = "execve failed: from ppc forking and exec()ing ppc process.\n"; 80 argvs[0] = "sleep-ppc32"; 81 if (do_execve_test("helpers/sleep-ppc32", argvs, NULL, 0)) goto test_failed_exit; 82 83 errmsg = "execve failed: from ppc forking and exec()ing ppc64 process w/ 4G pagezero.\n"; 84 argvs[0] = "sleep-ppc64-4G"; 85 if (do_execve_test("helpers/sleep-ppc64-4G", argvs, NULL, 0)) goto test_failed_exit; 86 87 errmsg = "execve failed: from ppc forking and exec()ing ppc64 process w/ 4K pagezero.\n"; 88 argvs[0] = "sleep-ppc64-4K"; 89 if (do_execve_test("helpers/sleep-ppc64-4K", argvs, NULL, 0)) goto test_failed_exit; 90#endif 91 92 93#if defined(__ppc64__) 94 /* 95 * This is the helper binary for the ppc version of xnu_quick_test. xnu_quick_test 96 * forks and execs this code to test exec()ing from a 64-bit binary. 97 */ 98 errmsg = "execve failed: from ppc64 forking and exec()ing 64-bit ppc process w/ 4G pagezero.\n"; 99 argvs[0] = "sleep-ppc64-4G"; 100 if (do_execve_test("helpers/sleep-ppc64-4G", argvs, NULL, 1)) goto test_failed_exit; 101 102 errmsg = "execve failed: from ppc64 forking and exec()ing 64-bit ppc process w/ 4K pagezero.\n"; 103 argvs[0] = "sleep-ppc64-4K"; 104 if (do_execve_test("helpers/sleep-ppc64-4K", argvs, NULL, 1)) goto test_failed_exit; 105 106 errmsg = "execve failed: from ppc64 forking and exec()ing 32 bit ppc process.\n"; 107 argvs[0] = "sleep-ppc32"; 108 if (do_execve_test("helpers/sleep-ppc32", argvs, NULL, 1)) goto test_failed_exit; 109#endif 110 111 return 0; 112 113test_failed_exit: 114 if (errmsg) 115 printf("%s", errmsg); 116 return -1; 117} 118 119