/src/SockFuzzer/fuzz/api/syscall_wrappers.c
Line | Count | Source (jump to first uncovered line) |
1 | | /* |
2 | | * Copyright 2021 Google LLC |
3 | | * |
4 | | * @APPLE_OSREFERENCE_LICENSE_HEADER_START@ |
5 | | * |
6 | | * This file contains Original Code and/or Modifications of Original Code |
7 | | * as defined in and that are subject to the Apple Public Source License |
8 | | * Version 2.0 (the 'License'). You may not use this file except in |
9 | | * compliance with the License. The rights granted to you under the License |
10 | | * may not be used to create, or enable the creation or redistribution of, |
11 | | * unlawful or unlicensed copies of an Apple operating system, or to |
12 | | * circumvent, violate, or enable the circumvention or violation of, any |
13 | | * terms of an Apple operating system software license agreement. |
14 | | * |
15 | | * Please obtain a copy of the License at |
16 | | * http://www.opensource.apple.com/apsl/ and read it before using this file. |
17 | | * |
18 | | * The Original Code and all software distributed under the License are |
19 | | * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER |
20 | | * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, |
21 | | * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, |
22 | | * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. |
23 | | * Please see the License for the specific language governing rights and |
24 | | * limitations under the License. |
25 | | * |
26 | | * @APPLE_OSREFERENCE_LICENSE_HEADER_END@ |
27 | | */ |
28 | | |
29 | | #include "fuzz/api/syscall_wrappers.h" |
30 | | |
31 | | #pragma clang diagnostic push |
32 | | #pragma clang diagnostic ignored "-Wint-conversion" |
33 | | |
34 | | __attribute__((visibility("default"))) int accept_wrapper(int s, caddr_t name, |
35 | | socklen_t* anamelen, |
36 | 163k | int* retval) { |
37 | 163k | struct accept_args uap = { |
38 | 163k | .s = s, |
39 | 163k | .name = name, |
40 | 163k | .anamelen = anamelen, |
41 | 163k | }; |
42 | 163k | return accept(kernproc, &uap, retval); |
43 | 163k | } |
44 | | |
45 | | __attribute__((visibility("default"))) int accept_nocancel_wrapper( |
46 | 110k | int s, caddr_t name, socklen_t* anamelen, int* retval) { |
47 | 110k | struct accept_nocancel_args uap = { |
48 | 110k | .s = s, |
49 | 110k | .name = name, |
50 | 110k | .anamelen = anamelen, |
51 | 110k | }; |
52 | 110k | return accept_nocancel(kernproc, &uap, retval); |
53 | 110k | } |
54 | | |
55 | | __attribute__((visibility("default"))) int bind_wrapper(int s, caddr_t name, |
56 | | socklen_t namelen, |
57 | 91.0k | int* retval) { |
58 | 91.0k | struct bind_args uap = { |
59 | 91.0k | .s = s, |
60 | 91.0k | .name = name, |
61 | 91.0k | .namelen = namelen, |
62 | 91.0k | }; |
63 | 91.0k | return bind(kernproc, &uap, retval); |
64 | 91.0k | } |
65 | | |
66 | 161k | __attribute__((visibility("default"))) int close_wrapper(int fd, int* retval) { |
67 | 161k | struct close_args uap = { |
68 | 161k | .fd = fd, |
69 | 161k | }; |
70 | 161k | return sys_close(kernproc, &uap, retval); |
71 | 161k | } |
72 | | |
73 | | __attribute__((visibility("default"))) int connect_wrapper(int s, caddr_t name, |
74 | | socklen_t namelen, |
75 | 110k | int* retval) { |
76 | 110k | struct connect_args uap = { |
77 | 110k | .s = s, |
78 | 110k | .name = name, |
79 | 110k | .namelen = namelen, |
80 | 110k | }; |
81 | 110k | return connect(kernproc, &uap, retval); |
82 | 110k | } |
83 | | |
84 | | __attribute__((visibility("default"))) int connect_nocancel_wrapper( |
85 | 128k | int s, caddr_t name, socklen_t namelen, int* retval) { |
86 | 128k | struct connect_nocancel_args uap = { |
87 | 128k | .s = s, |
88 | 128k | .name = name, |
89 | 128k | .namelen = namelen, |
90 | 128k | }; |
91 | 128k | return connect_nocancel(kernproc, &uap, retval); |
92 | 128k | } |
93 | | |
94 | | __attribute__((visibility("default"))) int connectx_wrapper( |
95 | | int socket, const sa_endpoints_t* endpoints, sae_associd_t associd, |
96 | | unsigned int flags, const struct iovec* iov, unsigned int iovcnt, |
97 | 310k | size_t* len, sae_connid_t* connid, int* retval) { |
98 | 310k | struct connectx_args uap = { |
99 | 310k | .socket = socket, |
100 | 310k | .endpoints = endpoints, |
101 | 310k | .associd = associd, |
102 | 310k | .flags = flags, |
103 | 310k | .iov = iov, |
104 | 310k | .iovcnt = iovcnt, |
105 | 310k | .len = len, |
106 | 310k | .connid = connid, |
107 | 310k | }; |
108 | 310k | return connectx(kernproc, &uap, retval); |
109 | 310k | } |
110 | | |
111 | | __attribute__((visibility("default"))) int disconnectx_wrapper( |
112 | 73.7k | int s, sae_associd_t aid, sae_connid_t cid, int* retval) { |
113 | 73.7k | struct disconnectx_args uap = { |
114 | 73.7k | .s = s, |
115 | 73.7k | .aid = aid, |
116 | 73.7k | .cid = cid, |
117 | 73.7k | }; |
118 | 73.7k | return disconnectx(kernproc, &uap, retval); |
119 | 73.7k | } |
120 | | |
121 | | __attribute__((visibility("default"))) int getpeername_wrapper(int fdes, |
122 | | caddr_t asa, |
123 | | socklen_t* alen, |
124 | 108k | int* retval) { |
125 | 108k | struct getpeername_args uap = { |
126 | 108k | .fdes = fdes, |
127 | 108k | .asa = asa, |
128 | 108k | .alen = alen, |
129 | 108k | }; |
130 | 108k | return getpeername(kernproc, &uap, retval); |
131 | 108k | } |
132 | | |
133 | | __attribute__((visibility("default"))) int getsockname_wrapper(int fdes, |
134 | | caddr_t asa, |
135 | | socklen_t* alen, |
136 | 87.7k | int* retval) { |
137 | 87.7k | struct getsockname_args uap = { |
138 | 87.7k | .fdes = fdes, |
139 | 87.7k | .asa = asa, |
140 | 87.7k | .alen = alen, |
141 | 87.7k | }; |
142 | 87.7k | return getsockname(kernproc, &uap, retval); |
143 | 87.7k | } |
144 | | |
145 | | __attribute__((visibility("default"))) int getsockopt_wrapper( |
146 | 336k | int s, int level, int name, caddr_t val, socklen_t* avalsize, int* retval) { |
147 | 336k | struct getsockopt_args uap = { |
148 | 336k | .s = s, |
149 | 336k | .level = level, |
150 | 336k | .name = name, |
151 | 336k | .val = val, |
152 | 336k | .avalsize = avalsize, |
153 | 336k | }; |
154 | 336k | return getsockopt(kernproc, &uap, retval); |
155 | 336k | } |
156 | | |
157 | | __attribute__((visibility("default"))) int ioctl_wrapper(int fd, u_long com, |
158 | | caddr_t data, |
159 | 727k | int* retval) { |
160 | 727k | struct ioctl_args uap = { |
161 | 727k | .fd = fd, |
162 | 727k | .com = com, |
163 | 727k | .data = data, |
164 | 727k | }; |
165 | 727k | return ioctl(kernproc, &uap, retval); |
166 | 727k | } |
167 | | |
168 | | __attribute__((visibility("default"))) int listen_wrapper(int s, int backlog, |
169 | 114k | int* retval) { |
170 | 114k | struct listen_args uap = { |
171 | 114k | .s = s, |
172 | 114k | .backlog = backlog, |
173 | 114k | }; |
174 | 114k | return listen(kernproc, &uap, retval); |
175 | 114k | } |
176 | | |
177 | | __attribute__((visibility("default"))) int necp_client_action_wrapper( |
178 | | int necp_fd, uint32_t action, uuid_t client_id, size_t client_id_len, |
179 | 0 | uint8_t* buffer, size_t buffer_size, int* retval) { |
180 | 0 | struct necp_client_action_args uap = { |
181 | 0 | .necp_fd = necp_fd, |
182 | 0 | .action = action, |
183 | 0 | .client_id = client_id, |
184 | 0 | .client_id_len = client_id_len, |
185 | 0 | .buffer = buffer, |
186 | 0 | .buffer_size = buffer_size, |
187 | 0 | }; |
188 | 0 | return necp_client_action(kernproc, &uap, retval); |
189 | 0 | } |
190 | | |
191 | | __attribute__((visibility("default"))) int necp_match_policy_wrapper( |
192 | | uint8_t* parameters, size_t parameters_size, |
193 | 0 | struct necp_aggregate_result* returned_result, int* retval) { |
194 | 0 | struct necp_match_policy_args uap = { |
195 | 0 | .parameters = parameters, |
196 | 0 | .parameters_size = parameters_size, |
197 | 0 | .returned_result = returned_result, |
198 | 0 | }; |
199 | 0 | return necp_match_policy(kernproc, &uap, retval); |
200 | 0 | } |
201 | | |
202 | | __attribute__((visibility("default"))) int necp_open_wrapper(int flags, |
203 | 0 | int* retval) { |
204 | 0 | struct necp_open_args uap = { |
205 | 0 | .flags = flags, |
206 | 0 | }; |
207 | 0 | return necp_open(kernproc, &uap, retval); |
208 | 0 | } |
209 | | |
210 | | __attribute__((visibility("default"))) int necp_session_action_wrapper( |
211 | | int necp_fd, uint32_t action, uint8_t* in_buffer, size_t in_buffer_length, |
212 | 0 | uint8_t* out_buffer, size_t out_buffer_length, int* retval) { |
213 | 0 | struct necp_session_action_args uap = { |
214 | 0 | .necp_fd = necp_fd, |
215 | 0 | .action = action, |
216 | 0 | .in_buffer = in_buffer, |
217 | 0 | .in_buffer_length = in_buffer_length, |
218 | 0 | .out_buffer = out_buffer, |
219 | 0 | .out_buffer_length = out_buffer_length, |
220 | 0 | }; |
221 | 0 | return necp_session_action(kernproc, &uap, retval); |
222 | 0 | } |
223 | | |
224 | | __attribute__((visibility("default"))) int necp_session_open_wrapper( |
225 | 0 | int flags, int* retval) { |
226 | 0 | struct necp_session_open_args uap = { |
227 | 0 | .flags = flags, |
228 | 0 | }; |
229 | 0 | return necp_session_open(kernproc, &uap, retval); |
230 | 0 | } |
231 | | |
232 | | __attribute__((visibility("default"))) int peeloff_wrapper(int s, |
233 | | sae_associd_t aid, |
234 | 104k | int* retval) { |
235 | 104k | struct peeloff_args uap = { |
236 | 104k | .s = s, |
237 | 104k | .aid = aid, |
238 | 104k | }; |
239 | 104k | return peeloff(kernproc, &uap, retval); |
240 | 104k | } |
241 | | |
242 | 189k | __attribute__((visibility("default"))) int pipe_wrapper(int* retval) { |
243 | 189k | struct pipe_args uap = {}; |
244 | 189k | return pipe(kernproc, &uap, retval); |
245 | 189k | } |
246 | | |
247 | | __attribute__((visibility("default"))) int recvfrom_wrapper( |
248 | | int s, void* buf, size_t len, int flags, struct sockaddr* from, |
249 | 75.7k | int* fromlenaddr, int* retval) { |
250 | 75.7k | struct recvfrom_args uap = { |
251 | 75.7k | .s = s, |
252 | 75.7k | .buf = buf, |
253 | 75.7k | .len = len, |
254 | 75.7k | .flags = flags, |
255 | 75.7k | .from = from, |
256 | 75.7k | .fromlenaddr = fromlenaddr, |
257 | 75.7k | }; |
258 | 75.7k | return recvfrom(kernproc, &uap, retval); |
259 | 75.7k | } |
260 | | |
261 | | __attribute__((visibility("default"))) int recvfrom_nocancel_wrapper( |
262 | | int s, void* buf, size_t len, int flags, struct sockaddr* from, |
263 | 73.8k | int* fromlenaddr, int* retval) { |
264 | 73.8k | struct recvfrom_nocancel_args uap = { |
265 | 73.8k | .s = s, |
266 | 73.8k | .buf = buf, |
267 | 73.8k | .len = len, |
268 | 73.8k | .flags = flags, |
269 | 73.8k | .from = from, |
270 | 73.8k | .fromlenaddr = fromlenaddr, |
271 | 73.8k | }; |
272 | 73.8k | return recvfrom_nocancel(kernproc, &uap, retval); |
273 | 73.8k | } |
274 | | |
275 | | __attribute__((visibility("default"))) int recvmsg_wrapper(int s, |
276 | | struct msghdr* msg, |
277 | | int flags, |
278 | 100k | int* retval) { |
279 | 100k | struct recvmsg_args uap = { |
280 | 100k | .s = s, |
281 | 100k | .msg = msg, |
282 | 100k | .flags = flags, |
283 | 100k | }; |
284 | 100k | return recvmsg(kernproc, &uap, retval); |
285 | 100k | } |
286 | | |
287 | | __attribute__((visibility("default"))) int recvmsg_nocancel_wrapper( |
288 | 0 | int s, struct msghdr* msg, int flags, int* retval) { |
289 | 0 | struct recvmsg_nocancel_args uap = { |
290 | 0 | .s = s, |
291 | 0 | .msg = msg, |
292 | 0 | .flags = flags, |
293 | 0 | }; |
294 | 0 | return recvmsg_nocancel(kernproc, &uap, retval); |
295 | 0 | } |
296 | | |
297 | | __attribute__((visibility("default"))) int recvmsg_x_wrapper( |
298 | 0 | int s, struct msghdr_x* msgp, u_int cnt, int flags, user_ssize_t* retval) { |
299 | 0 | struct recvmsg_x_args uap = { |
300 | 0 | .s = s, |
301 | 0 | .msgp = msgp, |
302 | 0 | .cnt = cnt, |
303 | 0 | .flags = flags, |
304 | 0 | }; |
305 | 0 | return recvmsg_x(kernproc, &uap, retval); |
306 | 0 | } |
307 | | |
308 | | __attribute__((visibility("default"))) int sendmsg_wrapper(int s, caddr_t msg, |
309 | | int flags, |
310 | 0 | int* retval) { |
311 | 0 | struct sendmsg_args uap = { |
312 | 0 | .s = s, |
313 | 0 | .msg = msg, |
314 | 0 | .flags = flags, |
315 | 0 | }; |
316 | 0 | return sendmsg(kernproc, &uap, retval); |
317 | 0 | } |
318 | | |
319 | | __attribute__((visibility("default"))) int sendmsg_nocancel_wrapper( |
320 | 0 | int s, caddr_t msg, int flags, int* retval) { |
321 | 0 | struct sendmsg_nocancel_args uap = { |
322 | 0 | .s = s, |
323 | 0 | .msg = msg, |
324 | 0 | .flags = flags, |
325 | 0 | }; |
326 | 0 | return sendmsg_nocancel(kernproc, &uap, retval); |
327 | 0 | } |
328 | | |
329 | | __attribute__((visibility("default"))) int sendmsg_x_wrapper( |
330 | 0 | int s, struct msghdr_x* msgp, u_int cnt, int flags, user_ssize_t* retval) { |
331 | 0 | struct sendmsg_x_args uap = { |
332 | 0 | .s = s, |
333 | 0 | .msgp = msgp, |
334 | 0 | .cnt = cnt, |
335 | 0 | .flags = flags, |
336 | 0 | }; |
337 | 0 | return sendmsg_x(kernproc, &uap, retval); |
338 | 0 | } |
339 | | |
340 | | __attribute__((visibility("default"))) int sendto_wrapper(int s, caddr_t buf, |
341 | | size_t len, int flags, |
342 | | caddr_t to, |
343 | | socklen_t tolen, |
344 | 183k | int* retval) { |
345 | 183k | struct sendto_args uap = { |
346 | 183k | .s = s, |
347 | 183k | .buf = buf, |
348 | 183k | .len = len, |
349 | 183k | .flags = flags, |
350 | 183k | .to = to, |
351 | 183k | .tolen = tolen, |
352 | 183k | }; |
353 | 183k | return sendto(kernproc, &uap, retval); |
354 | 183k | } |
355 | | |
356 | | __attribute__((visibility("default"))) int sendto_nocancel_wrapper( |
357 | | int s, caddr_t buf, size_t len, int flags, caddr_t to, socklen_t tolen, |
358 | 0 | int* retval) { |
359 | 0 | struct sendto_nocancel_args uap = { |
360 | 0 | .s = s, |
361 | 0 | .buf = buf, |
362 | 0 | .len = len, |
363 | 0 | .flags = flags, |
364 | 0 | .to = to, |
365 | 0 | .tolen = tolen, |
366 | 0 | }; |
367 | 0 | return sendto_nocancel(kernproc, &uap, retval); |
368 | 0 | } |
369 | | |
370 | | __attribute__((visibility("default"))) int setsockopt_wrapper( |
371 | 176k | int s, int level, int name, caddr_t val, socklen_t valsize, int* retval) { |
372 | 176k | struct setsockopt_args uap = { |
373 | 176k | .s = s, |
374 | 176k | .level = level, |
375 | 176k | .name = name, |
376 | 176k | .val = val, |
377 | 176k | .valsize = valsize, |
378 | 176k | }; |
379 | 176k | return setsockopt(kernproc, &uap, retval); |
380 | 176k | } |
381 | | |
382 | | __attribute__((visibility("default"))) int shutdown_wrapper(int s, int how, |
383 | 122k | int* retval) { |
384 | 122k | struct shutdown_args uap = { |
385 | 122k | .s = s, |
386 | 122k | .how = how, |
387 | 122k | }; |
388 | 122k | return shutdown(kernproc, &uap, retval); |
389 | 122k | } |
390 | | |
391 | | __attribute__((visibility("default"))) int socket_wrapper(int domain, int type, |
392 | | int protocol, |
393 | 74.9k | int* retval) { |
394 | 74.9k | struct socket_args uap = { |
395 | 74.9k | .domain = domain, |
396 | 74.9k | .type = type, |
397 | 74.9k | .protocol = protocol, |
398 | 74.9k | }; |
399 | 74.9k | return socket(kernproc, &uap, retval); |
400 | 74.9k | } |
401 | | |
402 | | __attribute__((visibility("default"))) int socket_delegate_wrapper( |
403 | 0 | int domain, int type, int protocol, pid_t epid, int* retval) { |
404 | 0 | struct socket_delegate_args uap = { |
405 | 0 | .domain = domain, |
406 | 0 | .type = type, |
407 | 0 | .protocol = protocol, |
408 | 0 | .epid = epid, |
409 | 0 | }; |
410 | 0 | return socket_delegate(kernproc, &uap, retval); |
411 | 0 | } |
412 | | |
413 | | __attribute__((visibility("default"))) int socketpair_wrapper( |
414 | 1.96M | int domain, int type, int protocol, int* rsv, int* retval) { |
415 | 1.96M | struct socketpair_args uap = { |
416 | 1.96M | .domain = domain, |
417 | 1.96M | .type = type, |
418 | 1.96M | .protocol = protocol, |
419 | 1.96M | .rsv = rsv, |
420 | 1.96M | }; |
421 | 1.96M | return socketpair(kernproc, &uap, retval); |
422 | 1.96M | } |
423 | | |
424 | | #pragma clang diagnostic pop |