xref: /xnu-10002.81.5/tests/debug_control_port_for_pid.c (revision 5e3eaea39dcf651e66cb99ba7d70e32cc4a99587)
1*5e3eaea3SApple OSS Distributions #include <stdio.h>
2*5e3eaea3SApple OSS Distributions #include <errno.h>
3*5e3eaea3SApple OSS Distributions #include <string.h>
4*5e3eaea3SApple OSS Distributions #include <unistd.h>
5*5e3eaea3SApple OSS Distributions #include <mach/mach.h>
6*5e3eaea3SApple OSS Distributions #include <mach/mach_types.h>
7*5e3eaea3SApple OSS Distributions #include <darwintest.h>
8*5e3eaea3SApple OSS Distributions #include <darwintest_utils.h>
9*5e3eaea3SApple OSS Distributions 
10*5e3eaea3SApple OSS Distributions T_GLOBAL_META(T_META_RUN_CONCURRENTLY(true));
11*5e3eaea3SApple OSS Distributions 
12*5e3eaea3SApple OSS Distributions T_DECL(debug_control_port_for_pid_success,
13*5e3eaea3SApple OSS Distributions     "Verify that with debug_port entitlement you can call debug_control_port_for_pid",
14*5e3eaea3SApple OSS Distributions     T_META_ASROOT(true), T_META_CHECK_LEAKS(false))
15*5e3eaea3SApple OSS Distributions {
16*5e3eaea3SApple OSS Distributions 	if (geteuid() != 0) {
17*5e3eaea3SApple OSS Distributions 		T_SKIP("test requires root privileges to run.");
18*5e3eaea3SApple OSS Distributions 	}
19*5e3eaea3SApple OSS Distributions 
20*5e3eaea3SApple OSS Distributions 	mach_port_t port = MACH_PORT_NULL;
21*5e3eaea3SApple OSS Distributions 	T_ASSERT_MACH_SUCCESS(debug_control_port_for_pid(mach_task_self(), 1, &port), "debug_control_port_for_pid");
22*5e3eaea3SApple OSS Distributions 	T_EXPECT_NE(port, MACH_PORT_NULL, "debug_port");
23*5e3eaea3SApple OSS Distributions 	mach_port_deallocate(mach_task_self(), port);
24*5e3eaea3SApple OSS Distributions }
25