1*a1e26a70SApple OSS Distributions #include <darwintest.h>
2*a1e26a70SApple OSS Distributions #include <mach/mach.h>
3*a1e26a70SApple OSS Distributions #include <stdlib.h>
4*a1e26a70SApple OSS Distributions #include <stdio.h>
5*a1e26a70SApple OSS Distributions #include <sys/sysctl.h>
6*a1e26a70SApple OSS Distributions #include <unistd.h>
7*a1e26a70SApple OSS Distributions #include <darwintest_multiprocess.h>
8*a1e26a70SApple OSS Distributions #include <spawn.h>
9*a1e26a70SApple OSS Distributions #include <spawn_private.h>
10*a1e26a70SApple OSS Distributions #include <libproc_internal.h>
11*a1e26a70SApple OSS Distributions #include <signal.h>
12*a1e26a70SApple OSS Distributions #include <string.h>
13*a1e26a70SApple OSS Distributions
14*a1e26a70SApple OSS Distributions #include <err.h>
15*a1e26a70SApple OSS Distributions #include <stdio.h>
16*a1e26a70SApple OSS Distributions #include <sysexits.h>
17*a1e26a70SApple OSS Distributions #include <stdbool.h>
18*a1e26a70SApple OSS Distributions
19*a1e26a70SApple OSS Distributions #include "kqwl_rnServer.h" // generated by MIG from rnserver.defs
20*a1e26a70SApple OSS Distributions
21*a1e26a70SApple OSS Distributions #include <servers/bootstrap.h>
22*a1e26a70SApple OSS Distributions #include <libproc_internal.h> // proc*cpumon*()
23*a1e26a70SApple OSS Distributions
24*a1e26a70SApple OSS Distributions T_GLOBAL_META(
25*a1e26a70SApple OSS Distributions T_META_NAMESPACE("xnu.kevent"),
26*a1e26a70SApple OSS Distributions T_META_RUN_CONCURRENTLY(TRUE),
27*a1e26a70SApple OSS Distributions T_META_RADAR_COMPONENT_NAME("xnu"),
28*a1e26a70SApple OSS Distributions T_META_RADAR_COMPONENT_VERSION("kevent"));
29*a1e26a70SApple OSS Distributions
30*a1e26a70SApple OSS Distributions #define TEST_PROGRAM_NAME "./kqworkloop_limits_client"
31*a1e26a70SApple OSS Distributions #define MAX_ARGV 5
32*a1e26a70SApple OSS Distributions
33*a1e26a70SApple OSS Distributions extern char **environ;
34*a1e26a70SApple OSS Distributions
35*a1e26a70SApple OSS Distributions static int
spawn_child_process_with_limits(int soft_limit,int hard_limit,int test_num)36*a1e26a70SApple OSS Distributions spawn_child_process_with_limits(int soft_limit, int hard_limit, int test_num)
37*a1e26a70SApple OSS Distributions {
38*a1e26a70SApple OSS Distributions char *child_args[MAX_ARGV];
39*a1e26a70SApple OSS Distributions int child_pid;
40*a1e26a70SApple OSS Distributions posix_spawnattr_t attrs;
41*a1e26a70SApple OSS Distributions int err;
42*a1e26a70SApple OSS Distributions
43*a1e26a70SApple OSS Distributions /* Initialize posix_spawn attributes */
44*a1e26a70SApple OSS Distributions posix_spawnattr_init(&attrs);
45*a1e26a70SApple OSS Distributions
46*a1e26a70SApple OSS Distributions err = posix_spawnattr_set_kqworklooplimit_ext(&attrs, soft_limit, hard_limit);
47*a1e26a70SApple OSS Distributions T_ASSERT_POSIX_SUCCESS(err, "posix_spawnattr_set_kqworklooplimit_ext");
48*a1e26a70SApple OSS Distributions
49*a1e26a70SApple OSS Distributions char soft_limit_str[32];
50*a1e26a70SApple OSS Distributions sprintf(soft_limit_str, "%d", soft_limit);
51*a1e26a70SApple OSS Distributions
52*a1e26a70SApple OSS Distributions char hard_limit_str[32];
53*a1e26a70SApple OSS Distributions sprintf(hard_limit_str, "%d", hard_limit);
54*a1e26a70SApple OSS Distributions
55*a1e26a70SApple OSS Distributions char test_num_str[32];
56*a1e26a70SApple OSS Distributions sprintf(test_num_str, "%d", test_num);
57*a1e26a70SApple OSS Distributions
58*a1e26a70SApple OSS Distributions child_args[0] = TEST_PROGRAM_NAME;
59*a1e26a70SApple OSS Distributions child_args[1] = soft_limit_str; // soft limit
60*a1e26a70SApple OSS Distributions child_args[2] = hard_limit_str; // hard limit
61*a1e26a70SApple OSS Distributions child_args[3] = test_num_str; // test num
62*a1e26a70SApple OSS Distributions child_args[4] = NULL;
63*a1e26a70SApple OSS Distributions
64*a1e26a70SApple OSS Distributions err = posix_spawn(&child_pid, child_args[0], NULL, &attrs, child_args, environ);
65*a1e26a70SApple OSS Distributions T_ASSERT_POSIX_SUCCESS(err, "posix_spawn kqworkloop_limits_client");
66*a1e26a70SApple OSS Distributions return child_pid;
67*a1e26a70SApple OSS Distributions }
68*a1e26a70SApple OSS Distributions
69*a1e26a70SApple OSS Distributions T_DECL(test_kqworkloop_soft_limit, "Allocate kqworkloops up to soft limit",
70*a1e26a70SApple OSS Distributions T_META_IGNORECRASHES(".*kqworkloop_limits_client.*"), T_META_CHECK_LEAKS(false), T_META_TAG_VM_PREFERRED)
71*a1e26a70SApple OSS Distributions {
72*a1e26a70SApple OSS Distributions #if TARGET_OS_BRIDGE
73*a1e26a70SApple OSS Distributions T_SKIP("Not running on target platforms");
74*a1e26a70SApple OSS Distributions #endif /* TARGET_OS_BRIDGE */
75*a1e26a70SApple OSS Distributions
76*a1e26a70SApple OSS Distributions int child_pid = spawn_child_process_with_limits(200, 0, 1);
77*a1e26a70SApple OSS Distributions
78*a1e26a70SApple OSS Distributions int child_status;
79*a1e26a70SApple OSS Distributions /* Wait for child and check for exception */
80*a1e26a70SApple OSS Distributions if (-1 == waitpid(child_pid, &child_status, 0)) {
81*a1e26a70SApple OSS Distributions T_FAIL("waitpid: child mia");
82*a1e26a70SApple OSS Distributions }
83*a1e26a70SApple OSS Distributions
84*a1e26a70SApple OSS Distributions if (WIFSIGNALED(child_status)) {
85*a1e26a70SApple OSS Distributions T_FAIL("Child exited with signal = %d", WTERMSIG(child_status));
86*a1e26a70SApple OSS Distributions }
87*a1e26a70SApple OSS Distributions
88*a1e26a70SApple OSS Distributions T_ASSERT_EQ(WIFEXITED(child_status), 1, "Child exited normally with exit value %d", WEXITSTATUS(child_status));
89*a1e26a70SApple OSS Distributions }
90*a1e26a70SApple OSS Distributions
91*a1e26a70SApple OSS Distributions T_DECL(test_kqworkloop_hard_limit, "Allocate kqworkloops up to hard limit",
92*a1e26a70SApple OSS Distributions T_META_IGNORECRASHES(".*kqworkloop_limits_client.*"), T_META_CHECK_LEAKS(false), T_META_TAG_VM_PREFERRED)
93*a1e26a70SApple OSS Distributions {
94*a1e26a70SApple OSS Distributions #if TARGET_OS_BRIDGE
95*a1e26a70SApple OSS Distributions T_SKIP("Not running on target platforms");
96*a1e26a70SApple OSS Distributions #endif /* TARGET_OS_BRIDGE */
97*a1e26a70SApple OSS Distributions
98*a1e26a70SApple OSS Distributions int child_pid = spawn_child_process_with_limits(0, 500, 1);
99*a1e26a70SApple OSS Distributions
100*a1e26a70SApple OSS Distributions int child_status;
101*a1e26a70SApple OSS Distributions /* Wait for child and check for exception */
102*a1e26a70SApple OSS Distributions if (-1 == waitpid(child_pid, &child_status, 0)) {
103*a1e26a70SApple OSS Distributions T_FAIL("waitpid: child mia");
104*a1e26a70SApple OSS Distributions }
105*a1e26a70SApple OSS Distributions
106*a1e26a70SApple OSS Distributions T_ASSERT_EQ(WIFEXITED(child_status), 0, "Child did not exit normally");
107*a1e26a70SApple OSS Distributions
108*a1e26a70SApple OSS Distributions if (WIFSIGNALED(child_status)) {
109*a1e26a70SApple OSS Distributions T_ASSERT_EQ(child_status, 9, "Child exited with status = %x", child_status);
110*a1e26a70SApple OSS Distributions }
111*a1e26a70SApple OSS Distributions }
112*a1e26a70SApple OSS Distributions
113*a1e26a70SApple OSS Distributions T_DECL(test_kqworkloop_soft_and_hard_limit, "Allocate kqworkloops with soft and hard limit",
114*a1e26a70SApple OSS Distributions T_META_IGNORECRASHES(".*kqworkloop_limits_client.*"),
115*a1e26a70SApple OSS Distributions T_META_CHECK_LEAKS(false),
116*a1e26a70SApple OSS Distributions T_META_TAG_VM_PREFERRED,
117*a1e26a70SApple OSS Distributions T_META_ENABLED(false /* rdar://133461542 */)
118*a1e26a70SApple OSS Distributions )
119*a1e26a70SApple OSS Distributions {
120*a1e26a70SApple OSS Distributions #if TARGET_OS_BRIDGE
121*a1e26a70SApple OSS Distributions T_SKIP("Not running on target platforms");
122*a1e26a70SApple OSS Distributions #endif /* TARGET_OS_BRIDGE */
123*a1e26a70SApple OSS Distributions
124*a1e26a70SApple OSS Distributions int child_pid = spawn_child_process_with_limits(250, 500, 1);
125*a1e26a70SApple OSS Distributions
126*a1e26a70SApple OSS Distributions int child_status;
127*a1e26a70SApple OSS Distributions /* Wait for child and check for exception */
128*a1e26a70SApple OSS Distributions if (-1 == waitpid(child_pid, &child_status, 0)) {
129*a1e26a70SApple OSS Distributions T_FAIL("waitpid: child mia");
130*a1e26a70SApple OSS Distributions }
131*a1e26a70SApple OSS Distributions
132*a1e26a70SApple OSS Distributions T_ASSERT_EQ(WIFEXITED(child_status), 0, "Child did not exit normally");
133*a1e26a70SApple OSS Distributions
134*a1e26a70SApple OSS Distributions if (WIFSIGNALED(child_status)) {
135*a1e26a70SApple OSS Distributions T_ASSERT_EQ(child_status, 9, "Child exited with status = %x", child_status);
136*a1e26a70SApple OSS Distributions }
137*a1e26a70SApple OSS Distributions }
138*a1e26a70SApple OSS Distributions
139*a1e26a70SApple OSS Distributions // Tests which define a resource notify server and verify that the soft/hard
140*a1e26a70SApple OSS Distributions // limit violations are correctly delivered to the server
141*a1e26a70SApple OSS Distributions
142*a1e26a70SApple OSS Distributions typedef struct {
143*a1e26a70SApple OSS Distributions mach_msg_header_t header;
144*a1e26a70SApple OSS Distributions mach_msg_body_t body;
145*a1e26a70SApple OSS Distributions mach_msg_port_descriptor_t port_descriptor;
146*a1e26a70SApple OSS Distributions mach_msg_trailer_t trailer; // subtract this when sending
147*a1e26a70SApple OSS Distributions } ipc_complex_message;
148*a1e26a70SApple OSS Distributions
149*a1e26a70SApple OSS Distributions struct args {
150*a1e26a70SApple OSS Distributions const char *progname;
151*a1e26a70SApple OSS Distributions int verbose;
152*a1e26a70SApple OSS Distributions int voucher;
153*a1e26a70SApple OSS Distributions int num_msgs;
154*a1e26a70SApple OSS Distributions const char *server_port_name;
155*a1e26a70SApple OSS Distributions mach_port_t server_port;
156*a1e26a70SApple OSS Distributions mach_port_t reply_port;
157*a1e26a70SApple OSS Distributions int request_msg_size;
158*a1e26a70SApple OSS Distributions void *request_msg;
159*a1e26a70SApple OSS Distributions int reply_msg_size;
160*a1e26a70SApple OSS Distributions void *reply_msg;
161*a1e26a70SApple OSS Distributions uint32_t persona_id;
162*a1e26a70SApple OSS Distributions long client_pid;
163*a1e26a70SApple OSS Distributions };
164*a1e26a70SApple OSS Distributions
165*a1e26a70SApple OSS Distributions void parse_args(struct args *args);
166*a1e26a70SApple OSS Distributions void server_setup(struct args* args);
167*a1e26a70SApple OSS Distributions void* exception_server_thread(void *arg);
168*a1e26a70SApple OSS Distributions mach_port_t create_exception_port(void);
169*a1e26a70SApple OSS Distributions static mach_port_t create_resource_notify_port(void);
170*a1e26a70SApple OSS Distributions static ipc_complex_message icm_request = {};
171*a1e26a70SApple OSS Distributions static ipc_complex_message icm_reply = {};
172*a1e26a70SApple OSS Distributions static mach_port_t resource_notify_port = MACH_PORT_NULL;
173*a1e26a70SApple OSS Distributions
174*a1e26a70SApple OSS Distributions #define TEST_TIMEOUT 10
175*a1e26a70SApple OSS Distributions
176*a1e26a70SApple OSS Distributions void
setup_server_args(struct args * args)177*a1e26a70SApple OSS Distributions setup_server_args(struct args *args)
178*a1e26a70SApple OSS Distributions {
179*a1e26a70SApple OSS Distributions args->server_port_name = "TEST_KQWORKLOOP_LIMITS";
180*a1e26a70SApple OSS Distributions args->server_port = MACH_PORT_NULL;
181*a1e26a70SApple OSS Distributions args->reply_msg_size = sizeof(ipc_complex_message) - sizeof(mach_msg_trailer_t);
182*a1e26a70SApple OSS Distributions args->request_msg_size = sizeof(ipc_complex_message) - sizeof(mach_msg_trailer_t);
183*a1e26a70SApple OSS Distributions args->reply_msg_size = sizeof(ipc_complex_message) - sizeof(mach_msg_trailer_t);
184*a1e26a70SApple OSS Distributions args->request_msg = &icm_request;
185*a1e26a70SApple OSS Distributions args->reply_msg = &icm_reply;
186*a1e26a70SApple OSS Distributions }
187*a1e26a70SApple OSS Distributions
188*a1e26a70SApple OSS Distributions /* Create a mach IPC listener which will respond to the client's message */
189*a1e26a70SApple OSS Distributions void
server_setup(struct args * args)190*a1e26a70SApple OSS Distributions server_setup(struct args *args)
191*a1e26a70SApple OSS Distributions {
192*a1e26a70SApple OSS Distributions kern_return_t ret;
193*a1e26a70SApple OSS Distributions mach_port_t bsport;
194*a1e26a70SApple OSS Distributions
195*a1e26a70SApple OSS Distributions ret = mach_port_allocate(mach_task_self(), MACH_PORT_RIGHT_RECEIVE,
196*a1e26a70SApple OSS Distributions &args->server_port);
197*a1e26a70SApple OSS Distributions T_ASSERT_MACH_SUCCESS(ret, "server: mach_port_allocate()");
198*a1e26a70SApple OSS Distributions
199*a1e26a70SApple OSS Distributions ret = mach_port_insert_right(mach_task_self(), args->server_port, args->server_port,
200*a1e26a70SApple OSS Distributions MACH_MSG_TYPE_MAKE_SEND);
201*a1e26a70SApple OSS Distributions T_ASSERT_MACH_SUCCESS(ret, "server: mach_port_insert_right()");
202*a1e26a70SApple OSS Distributions
203*a1e26a70SApple OSS Distributions ret = task_get_bootstrap_port(mach_task_self(), &bsport);
204*a1e26a70SApple OSS Distributions T_ASSERT_MACH_SUCCESS(ret, "server: task_get_bootstrap_port()");
205*a1e26a70SApple OSS Distributions
206*a1e26a70SApple OSS Distributions ret = bootstrap_register(bsport, (const char *)args->server_port_name, args->server_port);
207*a1e26a70SApple OSS Distributions T_ASSERT_MACH_SUCCESS(ret, "server: bootstrap_register()");
208*a1e26a70SApple OSS Distributions
209*a1e26a70SApple OSS Distributions T_LOG("server: waiting for IPC messages from client on port '%s'.\n",
210*a1e26a70SApple OSS Distributions args->server_port_name);
211*a1e26a70SApple OSS Distributions
212*a1e26a70SApple OSS Distributions /* Make the server port as the resource notify port */
213*a1e26a70SApple OSS Distributions resource_notify_port = args->server_port;
214*a1e26a70SApple OSS Distributions }
215*a1e26a70SApple OSS Distributions
216*a1e26a70SApple OSS Distributions T_DECL(test_kqworkloop_hard_limit_with_resource_notify_port,
217*a1e26a70SApple OSS Distributions "Allocate kqworkloops up to hard limit and trigger notification",
218*a1e26a70SApple OSS Distributions T_META_IGNORECRASHES(".*kqworkloop_limits_client.*"), T_META_CHECK_LEAKS(false), T_META_TAG_VM_PREFERRED)
219*a1e26a70SApple OSS Distributions {
220*a1e26a70SApple OSS Distributions #if TARGET_OS_BRIDGE
221*a1e26a70SApple OSS Distributions T_SKIP("Not running on target platforms");
222*a1e26a70SApple OSS Distributions #endif /* TARGET_OS_BRIDGE */
223*a1e26a70SApple OSS Distributions struct args* server_args = (struct args*)malloc(sizeof(struct args));
224*a1e26a70SApple OSS Distributions
225*a1e26a70SApple OSS Distributions /* Create the bootstrap port */
226*a1e26a70SApple OSS Distributions setup_server_args(server_args);
227*a1e26a70SApple OSS Distributions server_setup(server_args);
228*a1e26a70SApple OSS Distributions
229*a1e26a70SApple OSS Distributions server_args->client_pid = spawn_child_process_with_limits(0, 500, 2);
230*a1e26a70SApple OSS Distributions
231*a1e26a70SApple OSS Distributions T_LOG("server: Let's see if we can catch some kqworkloop leak");
232*a1e26a70SApple OSS Distributions
233*a1e26a70SApple OSS Distributions kern_return_t kr = mach_msg_server_once(resource_notify_server, 4096, resource_notify_port, 0);
234*a1e26a70SApple OSS Distributions T_ASSERT_MACH_SUCCESS(kr, "mach_msg_server_once resource_notify_port");
235*a1e26a70SApple OSS Distributions }
236*a1e26a70SApple OSS Distributions
237*a1e26a70SApple OSS Distributions // MIG's resource_notify_server() expects receive_cpu_usage_triggers as well
238*a1e26a70SApple OSS Distributions // This must match the definition in xnu's resource_notify.defs
239*a1e26a70SApple OSS Distributions kern_return_t
receive_cpu_usage_violation(__unused mach_port_t receiver,__unused proc_name_t procname,__unused pid_t pid,__unused posix_path_t killed_proc_path,__unused mach_timespec_t timestamp,__unused int64_t observed_cpu_nsecs,__unused int64_t observation_nsecs,__unused int64_t cpu_nsecs_allowed,__unused int64_t limit_window_nsecs,__unused resource_notify_flags_t flags)240*a1e26a70SApple OSS Distributions receive_cpu_usage_violation(__unused mach_port_t receiver,
241*a1e26a70SApple OSS Distributions __unused proc_name_t procname,
242*a1e26a70SApple OSS Distributions __unused pid_t pid,
243*a1e26a70SApple OSS Distributions __unused posix_path_t killed_proc_path,
244*a1e26a70SApple OSS Distributions __unused mach_timespec_t timestamp,
245*a1e26a70SApple OSS Distributions __unused int64_t observed_cpu_nsecs,
246*a1e26a70SApple OSS Distributions __unused int64_t observation_nsecs,
247*a1e26a70SApple OSS Distributions __unused int64_t cpu_nsecs_allowed,
248*a1e26a70SApple OSS Distributions __unused int64_t limit_window_nsecs,
249*a1e26a70SApple OSS Distributions __unused resource_notify_flags_t flags)
250*a1e26a70SApple OSS Distributions {
251*a1e26a70SApple OSS Distributions return KERN_FAILURE;
252*a1e26a70SApple OSS Distributions }
253*a1e26a70SApple OSS Distributions
254*a1e26a70SApple OSS Distributions kern_return_t
receive_cpu_wakes_violation(__unused mach_port_t receiver,__unused proc_name_t procname,__unused pid_t pid,__unused posix_path_t killed_proc_path,__unused mach_timespec_t timestamp,__unused int64_t observed_cpu_wakes,__unused int64_t observation_nsecs,__unused int64_t cpu_wakes_allowed,__unused int64_t limit_window_nsecs,__unused resource_notify_flags_t flags)255*a1e26a70SApple OSS Distributions receive_cpu_wakes_violation(__unused mach_port_t receiver,
256*a1e26a70SApple OSS Distributions __unused proc_name_t procname,
257*a1e26a70SApple OSS Distributions __unused pid_t pid,
258*a1e26a70SApple OSS Distributions __unused posix_path_t killed_proc_path,
259*a1e26a70SApple OSS Distributions __unused mach_timespec_t timestamp,
260*a1e26a70SApple OSS Distributions __unused int64_t observed_cpu_wakes,
261*a1e26a70SApple OSS Distributions __unused int64_t observation_nsecs,
262*a1e26a70SApple OSS Distributions __unused int64_t cpu_wakes_allowed,
263*a1e26a70SApple OSS Distributions __unused int64_t limit_window_nsecs,
264*a1e26a70SApple OSS Distributions __unused resource_notify_flags_t flags)
265*a1e26a70SApple OSS Distributions {
266*a1e26a70SApple OSS Distributions return KERN_FAILURE;
267*a1e26a70SApple OSS Distributions }
268*a1e26a70SApple OSS Distributions
269*a1e26a70SApple OSS Distributions kern_return_t
receive_disk_writes_violation(__unused mach_port_t receiver,__unused proc_name_t procname,__unused pid_t pid,__unused posix_path_t killed_proc_path,__unused mach_timespec_t timestamp,__unused int64_t observed_bytes_dirtied,__unused int64_t observation_nsecs,__unused int64_t bytes_dirtied_allowed,__unused int64_t limit_window_nsecs,__unused resource_notify_flags_t flags)270*a1e26a70SApple OSS Distributions receive_disk_writes_violation(__unused mach_port_t receiver,
271*a1e26a70SApple OSS Distributions __unused proc_name_t procname,
272*a1e26a70SApple OSS Distributions __unused pid_t pid,
273*a1e26a70SApple OSS Distributions __unused posix_path_t killed_proc_path,
274*a1e26a70SApple OSS Distributions __unused mach_timespec_t timestamp,
275*a1e26a70SApple OSS Distributions __unused int64_t observed_bytes_dirtied,
276*a1e26a70SApple OSS Distributions __unused int64_t observation_nsecs,
277*a1e26a70SApple OSS Distributions __unused int64_t bytes_dirtied_allowed,
278*a1e26a70SApple OSS Distributions __unused int64_t limit_window_nsecs,
279*a1e26a70SApple OSS Distributions __unused resource_notify_flags_t flags)
280*a1e26a70SApple OSS Distributions {
281*a1e26a70SApple OSS Distributions return KERN_FAILURE;
282*a1e26a70SApple OSS Distributions }
283*a1e26a70SApple OSS Distributions
284*a1e26a70SApple OSS Distributions kern_return_t
receive_port_space_violation(__unused mach_port_t receiver,__unused proc_name_t procname,__unused pid_t pid,__unused mach_timespec_t timestamp,__unused int64_t observed_ports,__unused int64_t ports_allowed,__unused mach_port_t fatal_port,__unused resource_notify_flags_t flags)285*a1e26a70SApple OSS Distributions receive_port_space_violation(__unused mach_port_t receiver,
286*a1e26a70SApple OSS Distributions __unused proc_name_t procname,
287*a1e26a70SApple OSS Distributions __unused pid_t pid,
288*a1e26a70SApple OSS Distributions __unused mach_timespec_t timestamp,
289*a1e26a70SApple OSS Distributions __unused int64_t observed_ports,
290*a1e26a70SApple OSS Distributions __unused int64_t ports_allowed,
291*a1e26a70SApple OSS Distributions __unused mach_port_t fatal_port,
292*a1e26a70SApple OSS Distributions __unused resource_notify_flags_t flags)
293*a1e26a70SApple OSS Distributions {
294*a1e26a70SApple OSS Distributions return KERN_FAILURE;
295*a1e26a70SApple OSS Distributions }
296*a1e26a70SApple OSS Distributions
297*a1e26a70SApple OSS Distributions kern_return_t
receive_file_descriptors_violation(__unused mach_port_t receiver,__unused proc_name_t procname,__unused pid_t pid,__unused mach_timespec_t timestamp,__unused int64_t observed_filedesc,__unused int64_t filedesc_allowed,__unused mach_port_t fatal_port,__unused resource_notify_flags_t flags)298*a1e26a70SApple OSS Distributions receive_file_descriptors_violation(__unused mach_port_t receiver,
299*a1e26a70SApple OSS Distributions __unused proc_name_t procname,
300*a1e26a70SApple OSS Distributions __unused pid_t pid,
301*a1e26a70SApple OSS Distributions __unused mach_timespec_t timestamp,
302*a1e26a70SApple OSS Distributions __unused int64_t observed_filedesc,
303*a1e26a70SApple OSS Distributions __unused int64_t filedesc_allowed,
304*a1e26a70SApple OSS Distributions __unused mach_port_t fatal_port,
305*a1e26a70SApple OSS Distributions __unused resource_notify_flags_t flags)
306*a1e26a70SApple OSS Distributions {
307*a1e26a70SApple OSS Distributions return KERN_FAILURE;
308*a1e26a70SApple OSS Distributions }
309*a1e26a70SApple OSS Distributions
310*a1e26a70SApple OSS Distributions kern_return_t
receive_kqworkloops_violation(__unused mach_port_t receiver,__unused proc_name_t procname,__unused pid_t pid,__unused mach_timespec_t timestamp,__unused int64_t observed_kqworkloops,__unused int64_t kqworkloops_allowed,__unused mach_port_t fatal_port,__unused resource_notify_flags_t flags)311*a1e26a70SApple OSS Distributions receive_kqworkloops_violation( __unused mach_port_t receiver,
312*a1e26a70SApple OSS Distributions __unused proc_name_t procname,
313*a1e26a70SApple OSS Distributions __unused pid_t pid,
314*a1e26a70SApple OSS Distributions __unused mach_timespec_t timestamp,
315*a1e26a70SApple OSS Distributions __unused int64_t observed_kqworkloops,
316*a1e26a70SApple OSS Distributions __unused int64_t kqworkloops_allowed,
317*a1e26a70SApple OSS Distributions __unused mach_port_t fatal_port,
318*a1e26a70SApple OSS Distributions __unused resource_notify_flags_t flags)
319*a1e26a70SApple OSS Distributions {
320*a1e26a70SApple OSS Distributions T_LOG("Received a notification on the resource notify port");
321*a1e26a70SApple OSS Distributions T_LOG("kqworkloops_allowed = %lld, kqworkloops observed = %lld", kqworkloops_allowed, observed_kqworkloops);
322*a1e26a70SApple OSS Distributions if (fatal_port) {
323*a1e26a70SApple OSS Distributions mach_port_deallocate(mach_task_self(), fatal_port);
324*a1e26a70SApple OSS Distributions }
325*a1e26a70SApple OSS Distributions return KERN_SUCCESS;
326*a1e26a70SApple OSS Distributions }
327