]>
Commit | Line | Data |
---|---|---|
d9a64523 A |
1 | #include <darwintest.h> |
2 | #include <darwintest_utils.h> | |
3 | #include <mach/mach.h> | |
4 | #include <unistd.h> | |
5 | #include <sys/wait.h> | |
6 | #include <signal.h> | |
7 | ||
8 | #define ITER 100 | |
9 | ||
10 | T_DECL(ltable_exhaustion_test, | |
0a7de745 A |
11 | "check if allocating not used ltable entries can panic the system", |
12 | T_META_ASROOT(true)) | |
d9a64523 | 13 | { |
0a7de745 | 14 | int n_ltable_entries, n_ltable_entries_after; |
d9a64523 A |
15 | size_t len = sizeof(int); |
16 | int i; | |
17 | mach_port_name_t portset; | |
18 | ||
19 | /* | |
20 | * Get how many ltable entries are allocated right now. | |
21 | */ | |
22 | T_EXPECT_POSIX_SUCCESS(sysctlbyname("kern.n_ltable_entries", &n_ltable_entries, &len, NULL, 0), "kern.n_ltable_entries"); | |
23 | ||
24 | for (i = 0; i < ITER; i++) { | |
25 | mach_port_allocate(mach_task_self(), MACH_PORT_RIGHT_PORT_SET, &portset); | |
26 | } | |
27 | ||
28 | /* | |
29 | * Get how many ltable entries are allocated after the loop. Other processes in the system might have allocated entries, | |
30 | * so don't expect the same value. | |
31 | */ | |
32 | T_EXPECT_POSIX_SUCCESS(sysctlbyname("kern.n_ltable_entries", &n_ltable_entries_after, &len, NULL, 0), "kern.n_ltable_entries"); | |
33 | ||
0a7de745 | 34 | T_EXPECT_LE(n_ltable_entries_after, n_ltable_entries + ITER, "ltable before %d after %d iter %d", n_ltable_entries, n_ltable_entries_after, ITER); |
d9a64523 | 35 | } |