]>
Commit | Line | Data |
---|---|---|
1 | #include <sys/wait.h> | |
2 | #include <spawn.h> | |
3 | #include <spawn_private.h> | |
4 | ||
5 | #include <mach/mach_init.h> | |
6 | #include <mach/mach_vm.h> | |
7 | ||
8 | #include <darwintest.h> | |
9 | #include <darwintest_utils.h> | |
10 | ||
11 | T_GLOBAL_META(T_META_RUN_CONCURRENTLY(true)); | |
12 | ||
13 | extern char * testpath; | |
14 | ||
15 | T_DECL(set_max_addr, | |
16 | "Description", | |
17 | T_META_NAMESPACE("xnu.vm"), | |
18 | T_META_CHECK_LEAKS(false)) | |
19 | { | |
20 | #if (!defined(TARGET_OS_MAC) && defined(__arm64__) && defined(__LP64__)) | |
21 | int result = 0; | |
22 | int code = 0; | |
23 | int child_pid = 0; | |
24 | int status = 0; | |
25 | char * command_path = "./vm_set_max_addr_helper"; | |
26 | char * command_args[] = { command_path, NULL }; | |
27 | posix_spawnattr_t attrp; | |
28 | ||
29 | result = posix_spawnattr_init(&attrp); | |
30 | T_ASSERT_POSIX_SUCCESS(result, "posix_spawnattr_init"); | |
31 | ||
32 | result = posix_spawn(&child_pid, command_path, NULL, &attrp, command_args, NULL); | |
33 | T_ASSERT_POSIX_SUCCESS(result, "posix_spawn"); | |
34 | ||
35 | result = waitpid(child_pid, &status, 0); | |
36 | T_ASSERT_POSIX_SUCCESS(result, "waitpid"); | |
37 | ||
38 | code = WEXITSTATUS(status); | |
39 | T_ASSERT_NE_INT(code, 0, "Child should have failed"); | |
40 | ||
41 | result = posix_spawnattr_set_max_addr_np(&attrp, ~0ULL); | |
42 | T_ASSERT_POSIX_SUCCESS(result, "posix_spawnattr_set_max_addr_np"); | |
43 | ||
44 | result = posix_spawn(&child_pid, command_path, NULL, &attrp, command_args, NULL); | |
45 | T_ASSERT_POSIX_SUCCESS(result, "posix_spawn"); | |
46 | ||
47 | result = waitpid(child_pid, &status, 0); | |
48 | T_ASSERT_POSIX_SUCCESS(result, "waitpid"); | |
49 | ||
50 | code = WEXITSTATUS(status); | |
51 | T_ASSERT_EQ_INT(code, 0, "Child should have succeeded"); | |
52 | ||
53 | posix_spawnattr_destroy(&attrp); | |
54 | T_ASSERT_POSIX_SUCCESS(result, "posix_spawnattr_destroy"); | |
55 | #else /* !defined(__arm64__) || !defined(__LP64__) */ | |
56 | T_SKIP("Not supported on this architecture"); | |
57 | #endif /* (defined(__arm64__) && defined(__LP64__)) */ | |
58 | } |