1 #include <unistd.h>
2 #include <stdint.h>
3 #include <sys/time.h>
4 #include <mach/mach_time.h>
5 #include <sys/codesign.h>
6 #include <mach/mach.h>
7 #include <darwintest.h>
8 #include <stdlib.h>
9 #include "cs_helpers.h"
10
11
12 int
remove_platform_binary(void)13 remove_platform_binary(void)
14 {
15 int ret;
16 uint32_t my_csflags;
17
18 T_QUIET; T_ASSERT_POSIX_ZERO(csops(getpid(), CS_OPS_STATUS, &my_csflags, sizeof(my_csflags)), NULL);
19
20 if (!(my_csflags & CS_PLATFORM_BINARY)) {
21 return 0;
22 }
23
24 ret = csops(getpid(), CS_OPS_CLEARPLATFORM, NULL, 0);
25 if (ret) {
26 switch (errno) {
27 case ENOTSUP:
28 T_LOG("clearing platform binary not supported, skipping test");
29 return -1;
30 default:
31 T_LOG("csops failed with flag CS_OPS_CLEARPLATFORM");
32 return -1;
33 }
34 }
35
36 my_csflags = 0;
37 T_QUIET; T_ASSERT_POSIX_ZERO(csops(getpid(), CS_OPS_STATUS, &my_csflags, sizeof(my_csflags)), NULL);
38
39 if (my_csflags & CS_PLATFORM_BINARY) {
40 T_LOG("platform binary flag still set");
41 return -1;
42 }
43
44 return 0;
45 }
46