1 #pragma clang diagnostic ignored "-Wdeprecated-declarations" 2 3 #include <sys/codesign.h> 4 #include <signal.h> 5 6 #include <darwintest.h> 7 #include <darwintest_utils.h> 8 9 T_GLOBAL_META(T_META_RUN_CONCURRENTLY(true)); 10 11 T_DECL(static_binary, 12 "Verify that static binaries have CS_NO_UNTRUSTED_HELPERS set") { 13 int ret; 14 pid_t pid; 15 char *launch_argv[] = {"./static_binary", NULL}; 16 ret = dt_launch_tool(&pid, launch_argv, /*start_suspended*/ true, NULL, NULL); 17 T_QUIET; 18 T_ASSERT_POSIX_SUCCESS(ret, "dt_launch_tool on static binary"); 19 20 uint32_t status = 0; 21 ret = csops(pid, CS_OPS_STATUS, &status, sizeof(status)); 22 T_QUIET; 23 T_EXPECT_POSIX_SUCCESS(ret, "request CS_OPS_STATUS on static binary"); 24 25 if (!ret) { 26 T_EXPECT_BITS_SET(status, CS_NO_UNTRUSTED_HELPERS, "CS_NO_UNTRUSTED_HELPERS should be set on static binary"); 27 } 28 29 ret = kill(pid, SIGCONT); 30 T_QUIET; 31 T_ASSERT_POSIX_SUCCESS(ret, "SIGCONT on static binary"); 32 33 int exitstatus, signal; 34 dt_waitpid(pid, &exitstatus, &signal, 30); 35 T_QUIET; 36 T_ASSERT_EQ(signal, 0, "static binary exited"); 37 T_QUIET; 38 T_ASSERT_EQ(exitstatus, 42, "static binary exited with code 42"); 39 } 40