2 #include <mach/mach_vm.h>
3 #include <mach/mach_port.h>
4 #include <mach/mach_error.h>
5 #include <sys/sysctl.h>
13 #include <darwintest.h>
14 #include <darwintest_utils.h>
16 T_GLOBAL_META(T_META_RUN_CONCURRENTLY(true), T_META_NAMESPACE("xnu.ipc"));
18 T_DECL(test_task_filter_msg_flag
, "Set the filter msg flag on the task and check if the forked child inherits it",
19 T_META_ASROOT(true), T_META_CHECK_LEAKS(false))
27 sysctl_size
= sizeof(dev
);
28 ret
= sysctlbyname("kern.development", &dev
, &sysctl_size
, NULL
, 0);
29 T_QUIET
; T_ASSERT_POSIX_SUCCESS(ret
, "sysctl kern.development failed");
31 T_SKIP("Skipping test on release kernel");
36 int cur_filter_flag
= 0;
37 int new_filter_flag
= 1;
38 ret
= sysctlbyname("kern.task_set_filter_msg_flag", &cur_filter_flag
, &sysctl_size
, &new_filter_flag
, sizeof(new_filter_flag
));
39 T_ASSERT_POSIX_SUCCESS(ret
, "sysctlbyname");
40 T_ASSERT_EQ(cur_filter_flag
, 0, "Task should not have filtering on");
43 ret
= sysctlbyname("kern.task_set_filter_msg_flag", &cur_filter_flag
, &sysctl_size
, NULL
, 0);
44 T_ASSERT_POSIX_SUCCESS(ret
, "sysctlbyname");
45 T_ASSERT_EQ(cur_filter_flag
, 1, "Task should have filtering on");
50 ret
= sysctlbyname("kern.task_set_filter_msg_flag", &cur_filter_flag
, &sysctl_size
, NULL
, 0);
52 if (cur_filter_flag
== 1) {
60 ret
= waitpid(pid
, &status
, 0);
61 T_ASSERT_POSIX_SUCCESS(ret
, "waitpid");
63 if (WIFEXITED(status
)) {
64 const int exit_code
= WEXITSTATUS(status
);
65 T_ASSERT_EQ(exit_code
, 0, "Child inherited the filter msg flag");
68 /* Turn off task msg filtering */
71 ret
= sysctlbyname("kern.task_set_filter_msg_flag", &cur_filter_flag
, &sysctl_size
, &new_filter_flag
, sizeof(new_filter_flag
));
72 T_ASSERT_POSIX_SUCCESS(ret
, "sysctlbyname");
73 T_ASSERT_EQ(cur_filter_flag
, 1, "Task should have filtering on");