]>
git.saurik.com Git - apple/xnu.git/blob - tests/ltable_exhaustion_test.c
1 #include <darwintest.h>
2 #include <darwintest_utils.h>
10 T_DECL(ltable_exhaustion_test
,
11 "check if allocating not used ltable entries can panic the system",
14 int n_ltable_entries
, n_ltable_entries_after
;
15 size_t len
= sizeof(int);
17 mach_port_name_t portset
;
20 * Get how many ltable entries are allocated right now.
22 T_EXPECT_POSIX_SUCCESS(sysctlbyname("kern.n_ltable_entries", &n_ltable_entries
, &len
, NULL
, 0), "kern.n_ltable_entries");
24 for (i
= 0; i
< ITER
; i
++) {
25 mach_port_allocate(mach_task_self(), MACH_PORT_RIGHT_PORT_SET
, &portset
);
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.
32 T_EXPECT_POSIX_SUCCESS(sysctlbyname("kern.n_ltable_entries", &n_ltable_entries_after
, &len
, NULL
, 0), "kern.n_ltable_entries");
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
);