]> git.saurik.com Git - apple/xnu.git/blame - tools/tests/xnu_quick_test/helpers/launch.c
xnu-1699.32.7.tar.gz
[apple/xnu.git] / tools / tests / xnu_quick_test / helpers / launch.c
CommitLineData
2d21ac55
A
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
b0d623f7
A
74 /*
75 * We are ourselves launched with do_execve_test, which wants a chance to
76 * send a SIGKILL
77 */
78 sleep(4);
2d21ac55
A
79 return 0;
80
81test_failed_exit:
82 if (errmsg)
83 printf("%s", errmsg);
84 return -1;
85}
86