1 | /* |
2 | * Copyright (c) 2023 Apple Inc. All rights reserved. |
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 | #if CONFIG_EXCLAVES |
30 | |
31 | #pragma once |
32 | |
33 | #include <kern/bits.h> |
34 | #include <kern/locks.h> |
35 | #include <kern/queue.h> |
36 | #include <mach/exclaves.h> |
37 | #include <mach/kern_return.h> |
38 | #include <sys/event.h> |
39 | |
40 | #include <stdint.h> |
41 | #include <os/base.h> |
42 | |
43 | #include <libxnuproxy/messages.h> |
44 | |
45 | #include "kern/exclaves.tightbeam.h" |
46 | |
47 | __BEGIN_DECLS |
48 | |
49 | |
50 | /* -------------------------------------------------------------------------- */ |
51 | #pragma mark Exclaves Resources |
52 | |
53 | #define EXCLAVES_DOMAIN_KERNEL "com.apple.kernel" |
54 | #define EXCLAVES_DOMAIN_DARWIN "com.apple.darwin" |
55 | |
56 | /* |
57 | * Data associated with a conclave. |
58 | */ |
59 | |
60 | /* |
61 | * Conclave State Machine: |
62 | * |
63 | * Launch Syscall |
64 | * +---------+ +--------------+ |
65 | * |Attached | ------->| Launching | |
66 | * | | | | |
67 | * +---------+ +--------------+ |
68 | * ^ | | | |
69 | * Spawn | |proc_exit Exit | | Start IPC |
70 | * | | | | to Conclave Manager |
71 | * | v v v |
72 | * +---------+ +-----------+ +----------+ |
73 | * *--> | None | | Stop | | Launched | |
74 | * | | | Requested | | | |
75 | * +---------+ +-----------+ +----------+ |
76 | * ^ | | |
77 | * proc_exit| Launch | | Exit |
78 | * | Completion| | |
79 | * | v v |
80 | * +---------+ +------------+ |
81 | * | Stopped |<------| Stopping | |
82 | * | | | | |
83 | * +---------+ +------------+ |
84 | * Stop IPC |
85 | * to Conclave Manager |
86 | */ |
87 | typedef enum { |
88 | CONCLAVE_S_NONE = 0, |
89 | CONCLAVE_S_ATTACHED, |
90 | CONCLAVE_S_LAUNCHING, |
91 | CONCLAVE_S_LAUNCHED, |
92 | CONCLAVE_S_STOP_REQUESTED, |
93 | CONCLAVE_S_STOPPING, |
94 | CONCLAVE_S_STOPPED, |
95 | } conclave_state_t; |
96 | |
97 | /* The maximum number of services available in any conclave. */ |
98 | #define CONCLAVE_SERVICE_MAX 128 |
99 | |
100 | typedef struct { |
101 | conclave_state_t c_state; |
102 | tb_client_connection_t c_control; |
103 | task_t XNU_PTRAUTH_SIGNED_PTR("conclave.task" ) c_task; |
104 | bitmap_t c_service_bitmap[BITMAP_LEN(CONCLAVE_SERVICE_MAX)]; |
105 | } conclave_resource_t; |
106 | |
107 | #define EXCLAVES_SHARED_BUFFER_MAX_RANGES 256 |
108 | |
109 | typedef struct { |
110 | char *address; |
111 | size_t npages; |
112 | } named_buffer_range_t; |
113 | |
114 | typedef struct { |
115 | size_t nb_size; |
116 | exclaves_buffer_perm_t nb_perm; |
117 | size_t nb_nranges; |
118 | named_buffer_range_t nb_range[EXCLAVES_SHARED_BUFFER_MAX_RANGES]; |
119 | } named_buffer_resource_t; |
120 | |
121 | typedef struct { |
122 | size_t sm_size; |
123 | exclaves_buffer_perm_t sm_perm; |
124 | size_t sm_nranges; |
125 | named_buffer_range_t sm_range[EXCLAVES_SHARED_BUFFER_MAX_RANGES]; |
126 | sharedmemorybase_mapping_s sm_mapping; |
127 | sharedmemorybase_segxnuaccess_s sm_client; |
128 | } shared_memory_resource_t; |
129 | |
130 | typedef struct { |
131 | /* how many times *this* sensor resource handle has been |
132 | * used to call sensor_start */ |
133 | uint64_t s_startcount; |
134 | } sensor_resource_t; |
135 | |
136 | typedef struct { |
137 | struct klist notification_klist; |
138 | } exclaves_notification_t; |
139 | |
140 | /* |
141 | * Every resource has an associated name and some other common state. |
142 | * Additionally there may be type specific data associated with the resource. |
143 | */ |
144 | typedef struct exclaves_resource { |
145 | char r_name[XNUPROXY_RESOURCE_NAME_MAX]; |
146 | xnuproxy_resource_t r_type; |
147 | uint64_t r_id; |
148 | _Atomic uint32_t r_usecnt; |
149 | ipc_port_t r_port; |
150 | lck_mtx_t r_mutex; |
151 | bool r_active; |
152 | |
153 | union { |
154 | conclave_resource_t r_conclave; |
155 | named_buffer_resource_t r_named_buffer; |
156 | sensor_resource_t r_sensor; |
157 | exclaves_notification_t r_notification; |
158 | shared_memory_resource_t r_shared_memory; |
159 | }; |
160 | } exclaves_resource_t; |
161 | |
162 | /*! |
163 | * @function exclaves_resource_init |
164 | * |
165 | * @abstract |
166 | * Called during exclaves_boot to dump the resource information from xnu proxy |
167 | * and build the xnu-side tables. |
168 | * |
169 | * @return |
170 | * KERN_SUCCESS on success otherwise an error code. |
171 | */ |
172 | extern kern_return_t |
173 | exclaves_resource_init(void); |
174 | |
175 | /*! |
176 | * @function exclaves_resource_name |
177 | * |
178 | * @abstract |
179 | * Return the name associated with a resource. |
180 | * |
181 | * @param resource |
182 | * Conclave manager resource. |
183 | * |
184 | * @return |
185 | * The name of the resource or NULL. |
186 | */ |
187 | extern const char * |
188 | exclaves_resource_name(const exclaves_resource_t *resource); |
189 | |
190 | /*! |
191 | * @function exclaves_resource_retain |
192 | * |
193 | * @abstract |
194 | * Grab a reference to the specified resource |
195 | * |
196 | * @param resource |
197 | * The resource to retain. |
198 | * |
199 | * @return |
200 | * The value of the use count before the retain |
201 | */ |
202 | extern uint32_t |
203 | exclaves_resource_retain(exclaves_resource_t *resource); |
204 | |
205 | /*! |
206 | * @function exclaves_resource_release |
207 | * |
208 | * @abstract |
209 | * Drop a reference to the specified resource |
210 | * |
211 | * @param resource |
212 | * The resource to release. |
213 | * |
214 | * @discussion |
215 | * This may result in a resource type specific release function being called |
216 | * which can grab locks, free memory etc. |
217 | * After this function has been called, the resource should not be accessed as |
218 | * it may be in an uninitialized state. |
219 | */ |
220 | extern void |
221 | exclaves_resource_release(exclaves_resource_t *resource); |
222 | |
223 | /*! |
224 | * @function exclaves_resource_from_port_name |
225 | * |
226 | * @abstract |
227 | * Find the resource associated with a port name in the specified space. |
228 | * |
229 | * @param space |
230 | * IPC space to search |
231 | * |
232 | * @param name |
233 | * Port name of the resource. |
234 | * |
235 | * @param resource |
236 | * Out parameter holding a pointer to the resource. |
237 | * |
238 | * @return |
239 | * KERN_SUCCESS or error code on failure. |
240 | * |
241 | * @discussion |
242 | * Returns with a +1 use-count on the resource which must be dropped with |
243 | * exclaves_resource_release(). |
244 | */ |
245 | extern kern_return_t |
246 | exclaves_resource_from_port_name(ipc_space_t space, mach_port_name_t name, |
247 | exclaves_resource_t **resource); |
248 | |
249 | |
250 | /*! |
251 | * @function exclaves_resource_create_port_name |
252 | * |
253 | * @abstract |
254 | * Create a port name for the given resource in the specified space. |
255 | * |
256 | * @param name |
257 | * Our parameter for holding a pointer to the port name. |
258 | * |
259 | * @param space |
260 | * IPC space in which to create the name |
261 | * |
262 | * @param resource |
263 | * Resource for which to create a port name for. |
264 | * |
265 | * @return |
266 | * KERN_SUCCESS or error code on failure. |
267 | * |
268 | * @discussion |
269 | * Returns with a +1 use-count on the resource which is associated with the life |
270 | * of the newly created send right. |
271 | */ |
272 | extern kern_return_t |
273 | exclaves_resource_create_port_name(exclaves_resource_t *resource, ipc_space_t space, |
274 | mach_port_name_t *name); |
275 | |
276 | |
277 | |
278 | |
279 | /* -------------------------------------------------------------------------- */ |
280 | #pragma mark Named Buffers |
281 | |
282 | /*! |
283 | * @function exclaves_named_buffer_map |
284 | * |
285 | * @abstract |
286 | * Map a named buffer resource. |
287 | * |
288 | * @param domain |
289 | * The domain to search. |
290 | * |
291 | * @param name |
292 | * The name of the named buffer resource. |
293 | * |
294 | * @param size |
295 | * Size of named buffer region to map. |
296 | * |
297 | * @param perm |
298 | * The permissions of the named buffer. |
299 | * |
300 | * @param resource |
301 | * Out parameter which holds the resource on success. |
302 | * |
303 | * @return |
304 | * KERN_SUCCESS or an error code. |
305 | * |
306 | * @discussion |
307 | * Returns with a +1 use-count on the resource which must be dropped with |
308 | * exclaves_resource_release(). |
309 | */ |
310 | extern kern_return_t |
311 | exclaves_named_buffer_map(const char *domain, const char *name, size_t size, |
312 | exclaves_buffer_perm_t perm, exclaves_resource_t **resource); |
313 | |
314 | /*! |
315 | * @function exclaves_named_buffer_copyin |
316 | * |
317 | * @abstract |
318 | * Copy user data into a named buffer. |
319 | * |
320 | * @param resource |
321 | * Named buffer resource. |
322 | * |
323 | * @param ubuffer |
324 | * Source of data to copy. |
325 | * |
326 | * @param usize1 |
327 | * Size of data to copy. |
328 | * |
329 | * @param uoffset1 |
330 | * Offset into the named buffer. |
331 | * |
332 | * @param usize2 |
333 | * Size of 2nd range of data to copy (can be 0). |
334 | * |
335 | * @param uoffset2 |
336 | * Offset of 2nd range into the named buffer. |
337 | * |
338 | * @return |
339 | * KERN_SUCCESS or error code on failure. |
340 | */ |
341 | extern kern_return_t |
342 | exclaves_named_buffer_copyin(exclaves_resource_t *resource, |
343 | user_addr_t ubuffer, mach_vm_size_t usize1, mach_vm_size_t uoffset1, |
344 | mach_vm_size_t usize2, mach_vm_size_t uoffset2); |
345 | |
346 | /*! |
347 | * @function exclaves_named_buffer_copyout |
348 | * |
349 | * @abstract |
350 | * Copy user data into a named buffer. |
351 | * |
352 | * @param resource |
353 | * Named buffer resource. |
354 | * |
355 | * @param ubuffer |
356 | * Destination to copy data to. |
357 | * |
358 | * @param usize1 |
359 | * Size of data to copy. |
360 | * |
361 | * @param uoffset1 |
362 | * Offset into the named buffer. |
363 | * |
364 | * @param usize2 |
365 | * Size of 2nd range of data to copy (can be 0). |
366 | * |
367 | * @param uoffset2 |
368 | * Offset of 2nd range into the named buffer. |
369 | * |
370 | * @return |
371 | * KERN_SUCCESS or error code on failure. |
372 | */ |
373 | extern kern_return_t |
374 | exclaves_named_buffer_copyout(exclaves_resource_t *resource, |
375 | user_addr_t ubuffer, mach_vm_size_t usize1, mach_vm_size_t uoffset1, |
376 | mach_vm_size_t usize2, mach_vm_size_t uoffset2); |
377 | |
378 | |
379 | /*! |
380 | * @function exclaves_named_buffer_io |
381 | * |
382 | * @abstract |
383 | * Perform IO on a named buffer |
384 | * |
385 | * @param resource |
386 | * Named buffer resource. |
387 | * |
388 | * @param offset |
389 | * Offset into the named buffer |
390 | * |
391 | * @param len |
392 | * Size of the IO |
393 | * |
394 | * @param cb |
395 | * A block which is called (potentially) multiple times to perform the IO. |
396 | * |
397 | * @return |
398 | * 0 on success. If cb returns a non-zero value, exclaves_named_buffer_io() |
399 | * immediately returns with that non-zero value. |
400 | */ |
401 | extern int |
402 | exclaves_named_buffer_io(exclaves_resource_t * resource, off_t offset, |
403 | size_t len, int (^cb)(char *buffer, size_t size)); |
404 | |
405 | /* -------------------------------------------------------------------------- */ |
406 | #pragma mark Audio buffers |
407 | |
408 | /*! |
409 | * @function exclaves_audio_buffer_map |
410 | * |
411 | * @abstract |
412 | * Map an audio buffer resource. |
413 | * |
414 | * @param domain |
415 | * The domain to search. |
416 | * |
417 | * @param name |
418 | * The name of audio buffer resource. |
419 | * |
420 | * @param size |
421 | * Size of named buffer region to map. |
422 | * |
423 | * @param resource |
424 | * Out parameter which holds the resource on success. |
425 | * |
426 | * @return |
427 | * KERN_SUCCESS or error code on failure. |
428 | * |
429 | * @discussion |
430 | * Returns with a +1 use-count on the resource which must be dropped with |
431 | * exclaves_resource_release(). |
432 | */ |
433 | extern kern_return_t |
434 | exclaves_audio_buffer_map(const char *domain, const char *name, size_t size, |
435 | exclaves_resource_t **resource); |
436 | |
437 | /*! |
438 | * @function exclaves_audio_buffer_copyout |
439 | * |
440 | * @abstract |
441 | * Copy user data into a audio buffer. |
442 | * |
443 | * @param resource |
444 | * audio buffer resource. |
445 | * |
446 | * @param ubuffer |
447 | * Destination to copy data to. |
448 | * |
449 | * @param usize1 |
450 | * Size of data to copy. |
451 | * |
452 | * @param uoffset1 |
453 | * Offset into the audio buffer. |
454 | * |
455 | * @param usize2 |
456 | * Size of 2nd range of data to copy (can be 0). |
457 | * |
458 | * @param uoffset2 |
459 | * Offset of 2nd range into the audio buffer. |
460 | * |
461 | * @return |
462 | * KERN_SUCCESS or error code on failure. |
463 | */ |
464 | extern kern_return_t |
465 | exclaves_audio_buffer_copyout(exclaves_resource_t *resource, |
466 | user_addr_t ubuffer, mach_vm_size_t usize1, mach_vm_size_t uoffset1, |
467 | mach_vm_size_t usize2, mach_vm_size_t uoffset2); |
468 | |
469 | |
470 | |
471 | |
472 | /* -------------------------------------------------------------------------- */ |
473 | #pragma mark Conclaves |
474 | |
475 | /*! |
476 | * @function exclaves_conclave_attach |
477 | * |
478 | * @abstract |
479 | * Attach a conclave to a task. The conclave must not already be attached to any |
480 | * task. Once attached, this conclave is exclusively associated with the task. |
481 | * |
482 | * @param domain |
483 | * The domain to search. |
484 | * |
485 | * @param name |
486 | * The name of conclave resource. |
487 | * |
488 | * @param task |
489 | * Task to attach the conclave to. |
490 | * |
491 | * @return |
492 | * KERN_SUCCESS on success, error code otherwise. |
493 | */ |
494 | extern kern_return_t |
495 | exclaves_conclave_attach(const char *domain, const char *name, task_t task); |
496 | |
497 | /*! |
498 | * @function exclaves_conclave_detach |
499 | * |
500 | * @abstract |
501 | * Detach a conclave from a task. The conclave must already be attached to the |
502 | * task and stopped. Once detached, this conclave is available for other tasks. |
503 | * |
504 | * @param resource |
505 | * Conclave Manager resource. |
506 | * |
507 | * @param task |
508 | * Task to detach the conclave from. |
509 | * |
510 | * @return |
511 | * KERN_SUCCESS on success, error code otherwise. |
512 | */ |
513 | extern kern_return_t |
514 | exclaves_conclave_detach(exclaves_resource_t *resource, task_t task); |
515 | |
516 | /*! |
517 | * @function exclaves_conclave_inherit |
518 | * |
519 | * @abstract |
520 | * Pass an attached conclave from one task to another. |
521 | * |
522 | * @param resource |
523 | * Conclave Manager resource. |
524 | * |
525 | * @param old_task |
526 | * Task with attached conclave. |
527 | * |
528 | * @param new_task |
529 | * Task which will inherit the conclave. |
530 | * |
531 | * @return |
532 | * KERN_SUCCESS on success, error code otherwise. |
533 | */ |
534 | extern kern_return_t |
535 | exclaves_conclave_inherit(exclaves_resource_t *resource, task_t old_task, |
536 | task_t new_task); |
537 | |
538 | |
539 | /*! |
540 | * @function exclaves_conclave_is_attached |
541 | * |
542 | * @abstract |
543 | * Returns true if the conclave is in the ATTACHED state. |
544 | * |
545 | * @param resource |
546 | * Conclave Manager resource. |
547 | * |
548 | * @return |
549 | * True if conclave is attached, false otherwise |
550 | */ |
551 | extern bool |
552 | exclaves_conclave_is_attached(const exclaves_resource_t *resource); |
553 | |
554 | /*! |
555 | * @function exclaves_conclave_launch |
556 | * |
557 | * @abstract |
558 | * Launch a conclave. The conclave must be attached to a task and not already |
559 | * launched. |
560 | * |
561 | * @param resource |
562 | * Conclave Manager resource. |
563 | * |
564 | * @return |
565 | * KERN_SUCCESS on success, error code otherwise. |
566 | */ |
567 | extern kern_return_t |
568 | exclaves_conclave_launch(exclaves_resource_t *resource); |
569 | |
570 | /*! |
571 | * @function exclaves_conclave_lookup_resources |
572 | * |
573 | * @abstract |
574 | * Lookup conclave resource. The conclave must be attached to a task and |
575 | * launched. |
576 | * |
577 | * @param resource |
578 | * Conclave Manager resource. |
579 | * |
580 | * @param conclave_resource_user |
581 | * Array to fill user resources for Conclave |
582 | * |
583 | * @param resource_count |
584 | * Number of resources in array |
585 | * |
586 | * @return |
587 | * KERN_SUCCESS on success, error code otherwise. |
588 | */ |
589 | extern kern_return_t |
590 | exclaves_conclave_lookup_resources(exclaves_resource_t *resource, |
591 | struct exclaves_resource_user *conclave_resource_user, int resource_count); |
592 | |
593 | /*! |
594 | * @function exclaves_conclave_stop |
595 | * |
596 | * @abstract |
597 | * Stop a conclave. The conclave must be launched and attached. |
598 | * |
599 | * @param resource |
600 | * Conclave Manager resource. |
601 | * |
602 | * @param gather_crash_bt |
603 | * Conclave Manager needs to gather backtraces |
604 | * |
605 | * @return |
606 | * KERN_SUCCESS on success, error code otherwise. |
607 | */ |
608 | extern kern_return_t |
609 | exclaves_conclave_stop(exclaves_resource_t *resource, bool gather_crash_bt); |
610 | |
611 | /*! |
612 | * @function exclaves_conclave_stop_upcall |
613 | * |
614 | * @abstract |
615 | * Stop a conclave. The conclave must be launched and attached. |
616 | * |
617 | * @param resource |
618 | * Conclave Manager resource. |
619 | * |
620 | * @return |
621 | * KERN_SUCCESS on success, error code otherwise. |
622 | */ |
623 | extern kern_return_t |
624 | exclaves_conclave_stop_upcall(exclaves_resource_t *resource); |
625 | |
626 | /*! |
627 | * @function exclaves_conclave_stop_upcall_complete |
628 | * |
629 | * @abstract |
630 | * Complete the Conclave stop once back in regular context. |
631 | * |
632 | * @param resource |
633 | * Conclave Manager resource. |
634 | * |
635 | * @param task |
636 | * Conclave Host task |
637 | * |
638 | * @return |
639 | * KERN_SUCCESS on success, error code otherwise. |
640 | */ |
641 | extern kern_return_t |
642 | exclaves_conclave_stop_upcall_complete(exclaves_resource_t *resource, task_t task); |
643 | |
644 | /*! |
645 | * @function exclaves_conclave_get_domain |
646 | * |
647 | * @abstract |
648 | * Return the domain associated with the specified conclave resource. Or the |
649 | * kernel domain if the conclave resource is NULL. |
650 | * |
651 | * @param resource |
652 | * Conclave Manager resource. |
653 | * |
654 | * @return |
655 | * The domain of the conclave or the kernel domain. |
656 | */ |
657 | extern const char * |
658 | exclaves_conclave_get_domain(exclaves_resource_t *resource); |
659 | |
660 | |
661 | /*! |
662 | * @function exclaves_conclave_has_service |
663 | * |
664 | * @abstract |
665 | * Return true if the service ID is associated with the specified conclave |
666 | * resource. |
667 | * |
668 | * @param resource |
669 | * Conclave Manager resource. |
670 | * |
671 | * @params id |
672 | * ID of a SERVICE resource. |
673 | * |
674 | * @return |
675 | * true if the ID is available to conclave, false otherwise |
676 | */ |
677 | extern bool |
678 | exclaves_conclave_has_service(exclaves_resource_t *resource, uint64_t id); |
679 | |
680 | /* -------------------------------------------------------------------------- */ |
681 | #pragma mark Sensors |
682 | |
683 | /*! |
684 | * @function exclaves_resource_sensor_open |
685 | * |
686 | * @abstract |
687 | * Open a sensor resource. |
688 | * |
689 | * @param domain |
690 | * The domain to search. |
691 | * |
692 | * @param name |
693 | * The name of the sensor resource. |
694 | * |
695 | * @param resource |
696 | * Out parameter which holds the resource on success. |
697 | * |
698 | * @return |
699 | * KERN_SUCCESS on success, error code otherwise. |
700 | * |
701 | * @discussion |
702 | * Returns with a +1 use-count on the resource which must be dropped with |
703 | * exclaves_resource_release(). |
704 | */ |
705 | extern kern_return_t |
706 | exclaves_resource_sensor_open(const char *domain, const char *name, |
707 | exclaves_resource_t **resource); |
708 | |
709 | /*! |
710 | * @function exclaves_resource_sensor_start |
711 | * |
712 | * @abstract |
713 | * Start accessing a sensor. |
714 | * |
715 | * @param resource |
716 | * Sensor resource. |
717 | * |
718 | * @param flags |
719 | * Flags to pass to implementation. |
720 | * |
721 | * @param status |
722 | * output parameter for status of sensor after this operation. |
723 | * |
724 | * @return |
725 | * KERN_SUCCESS on success, error code otherwise. |
726 | */ |
727 | kern_return_t |
728 | exclaves_resource_sensor_start(exclaves_resource_t *resource, uint64_t flags, |
729 | exclaves_sensor_status_t *status); |
730 | |
731 | /*! |
732 | * @function exclaves_resource_sensor_stop |
733 | * |
734 | * @abstract |
735 | * Stop accessing a sensor. |
736 | * |
737 | * @param resource |
738 | * Sensor resource. |
739 | * |
740 | * @param flags |
741 | * Flags to pass to implementation. |
742 | * |
743 | * @param status |
744 | * output parameter for status of sensor after this operation. |
745 | * |
746 | * @return |
747 | * KERN_SUCCESS on success, error code otherwise. |
748 | */ |
749 | kern_return_t |
750 | exclaves_resource_sensor_stop(exclaves_resource_t *resource, uint64_t flags, |
751 | exclaves_sensor_status_t *status); |
752 | |
753 | /*! |
754 | * @function exclaves_resource_sensor_status |
755 | * |
756 | * @abstract |
757 | * Query the status of access to a sensor. |
758 | * |
759 | * @param resource |
760 | * Sensor resource. |
761 | * |
762 | * @param flags |
763 | * Flags to pass to implementation. |
764 | * |
765 | * @param status |
766 | * output parameter for status of sensor after this operation. |
767 | * |
768 | * @return |
769 | * KERN_SUCCESS on success, error code otherwise. |
770 | */ |
771 | kern_return_t |
772 | exclaves_resource_sensor_status(exclaves_resource_t *resource, uint64_t flags, |
773 | exclaves_sensor_status_t *status); |
774 | |
775 | /* -------------------------------------------------------------------------- */ |
776 | #pragma mark Notifications |
777 | |
778 | /*! |
779 | * @function exclaves_notification_create |
780 | * |
781 | * @abstract |
782 | * Set up an exclave notification from the specified resource. |
783 | * |
784 | * @param domain |
785 | * The domain to search. |
786 | * |
787 | * @param name |
788 | * The name of the notification resource. |
789 | * |
790 | * @return |
791 | * A notification resource or NULL. |
792 | * |
793 | * @discussion |
794 | * Returns with a +1 use-count on the resource which must be dropped with |
795 | * exclaves_resource_release(). |
796 | */ |
797 | extern kern_return_t |
798 | exclaves_notification_create(const char *domain, const char *name, |
799 | exclaves_resource_t **resource); |
800 | |
801 | /*! |
802 | * @function exclaves_notification_signal |
803 | * |
804 | * @abstract |
805 | * To be called from upcall context when the specified notification resource is signaled. |
806 | * |
807 | * @param resource |
808 | * Notification resource. |
809 | * |
810 | * @param event_mask |
811 | * Bit mask of events for the notification. |
812 | * |
813 | * @return |
814 | * KERN_SUCCESS on success, error code otherwise. |
815 | */ |
816 | extern kern_return_t |
817 | exclaves_notification_signal(exclaves_resource_t *resource, long event_mask); |
818 | |
819 | |
820 | /*! |
821 | * @function exclaves_notificatione_lookup_by_id |
822 | * |
823 | * @abstract |
824 | * Find an exclave notification by ID. |
825 | * |
826 | * @param id |
827 | * The resource ID. |
828 | * |
829 | * @param domain |
830 | * The domain to search. |
831 | * |
832 | * @return |
833 | * Pointer to the resource |
834 | */ |
835 | exclaves_resource_t * |
836 | exclaves_notification_lookup_by_id(const char *domain, uint64_t id); |
837 | |
838 | |
839 | /* -------------------------------------------------------------------------- */ |
840 | #pragma mark Services |
841 | |
842 | /*! |
843 | * @function exclaves_service_lookup |
844 | * |
845 | * @abstract |
846 | * Look up a service resource |
847 | * |
848 | * @param domain |
849 | * The domain to search. |
850 | * |
851 | * @param name |
852 | * The name of the service resource. |
853 | * |
854 | * @return |
855 | * ID of service or -1 if the service cannot be found. |
856 | */ |
857 | extern uint64_t |
858 | exclaves_service_lookup(const char *domain, const char *name); |
859 | |
860 | |
861 | /* -------------------------------------------------------------------------- */ |
862 | #pragma mark Shared Memory |
863 | |
864 | /*! |
865 | * @function exclaves_resource_shared_memory_map |
866 | * |
867 | * @abstract |
868 | * Map a shared memory resource. |
869 | * |
870 | * @param domain |
871 | * The domain to search. |
872 | * |
873 | * @param name |
874 | * The name of the shared memory resource. |
875 | * |
876 | * @param size |
877 | * Size of shared memory region to map. |
878 | * |
879 | * @param perm |
880 | * The permissions of the shared memory. |
881 | * |
882 | * @param resource |
883 | * Out parameter which holds the resource on success. |
884 | * |
885 | * @return |
886 | * KERN_SUCCESS or an error code. |
887 | * |
888 | * @discussion |
889 | * Returns with a +1 use-count on the resource which must be dropped with |
890 | * exclaves_resource_release(). |
891 | */ |
892 | extern kern_return_t |
893 | exclaves_resource_shared_memory_map(const char *domain, const char *name, |
894 | size_t size, exclaves_buffer_perm_t perm, exclaves_resource_t **resource); |
895 | |
896 | /*! |
897 | * @function exclaves_resource_shared_memory_copyin |
898 | * |
899 | * @abstract |
900 | * Copy user data into a shared memory. |
901 | * |
902 | * @param resource |
903 | * Named buffer resource. |
904 | * |
905 | * @param ubuffer |
906 | * Source of data to copy. |
907 | * |
908 | * @param usize1 |
909 | * Size of data to copy. |
910 | * |
911 | * @param uoffset1 |
912 | * Offset into the shared memory. |
913 | * |
914 | * @param usize2 |
915 | * Size of 2nd range of data to copy (can be 0). |
916 | * |
917 | * @param uoffset2 |
918 | * Offset of 2nd range into the shared memory. |
919 | * |
920 | * @return |
921 | * KERN_SUCCESS or error code on failure. |
922 | */ |
923 | extern kern_return_t |
924 | exclaves_resource_shared_memory_copyin(exclaves_resource_t *resource, |
925 | user_addr_t ubuffer, mach_vm_size_t usize1, mach_vm_size_t uoffset1, |
926 | mach_vm_size_t usize2, mach_vm_size_t uoffset2); |
927 | |
928 | /*! |
929 | * @function exclaves_resource_shared_memory_copyout |
930 | * |
931 | * @abstract |
932 | * Copy user data into a shared memory. |
933 | * |
934 | * @param resource |
935 | * Named buffer resource. |
936 | * |
937 | * @param ubuffer |
938 | * Destination to copy data to. |
939 | * |
940 | * @param usize1 |
941 | * Size of data to copy. |
942 | * |
943 | * @param uoffset1 |
944 | * Offset into the shared memory. |
945 | * |
946 | * @param usize2 |
947 | * Size of 2nd range of data to copy (can be 0). |
948 | * |
949 | * @param uoffset2 |
950 | * Offset of 2nd range into the shared memory. |
951 | * |
952 | * @return |
953 | * KERN_SUCCESS or error code on failure. |
954 | */ |
955 | extern kern_return_t |
956 | exclaves_resource_shared_memory_copyout(exclaves_resource_t *resource, |
957 | user_addr_t ubuffer, mach_vm_size_t usize1, mach_vm_size_t uoffset1, |
958 | mach_vm_size_t usize2, mach_vm_size_t uoffset2); |
959 | |
960 | |
961 | /*! |
962 | * @function exclaves_resource_shared_memory_io |
963 | * |
964 | * @abstract |
965 | * Perform IO on a shared memory |
966 | * |
967 | * @param resource |
968 | * Named buffer resource. |
969 | * |
970 | * @param offset |
971 | * Offset into the shared memory |
972 | * |
973 | * @param len |
974 | * Size of the IO |
975 | * |
976 | * @param cb |
977 | * A block which is called (potentially) multiple times to perform the IO. |
978 | * |
979 | * @return |
980 | * 0 on success. If cb returns a non-zero value, exclaves_resource_shared_memory_io() |
981 | * immediately returns with that non-zero value. |
982 | */ |
983 | extern int |
984 | exclaves_resource_shared_memory_io(exclaves_resource_t * resource, off_t offset, |
985 | size_t len, int (^cb)(char *buffer, size_t size)); |
986 | |
987 | |
988 | /* -------------------------------------------------------------------------- */ |
989 | #pragma mark Arbitrated Audio Memory |
990 | |
991 | /*! |
992 | * @function exclaves_resource_audio_memory_map |
993 | * |
994 | * @abstract |
995 | * Map an audio memory resource. |
996 | * |
997 | * @param domain |
998 | * The domain to search. |
999 | * |
1000 | * @param name |
1001 | * The name of audio memory resource. |
1002 | * |
1003 | * @param size |
1004 | * Size of named buffer region to map. |
1005 | * |
1006 | * @param resource |
1007 | * Out parameter which holds the resource on success. |
1008 | * |
1009 | * @return |
1010 | * KERN_SUCCESS or error code on failure. |
1011 | * |
1012 | * @discussion |
1013 | * Returns with a +1 use-count on the resource which must be dropped with |
1014 | * exclaves_resource_release(). |
1015 | */ |
1016 | extern kern_return_t |
1017 | exclaves_resource_audio_memory_map(const char *domain, const char *name, size_t size, |
1018 | exclaves_resource_t **resource); |
1019 | |
1020 | /*! |
1021 | * @function exclaves_resource_audio_memory_copyout |
1022 | * |
1023 | * @abstract |
1024 | * Copy user data into a audio memory. |
1025 | * |
1026 | * @param resource |
1027 | * audio memory resource. |
1028 | * |
1029 | * @param ubuffer |
1030 | * Destination to copy data to. |
1031 | * |
1032 | * @param usize1 |
1033 | * Size of data to copy. |
1034 | * |
1035 | * @param uoffset1 |
1036 | * Offset into the audio memory. |
1037 | * |
1038 | * @param usize2 |
1039 | * Size of 2nd range of data to copy (can be 0). |
1040 | * |
1041 | * @param uoffset2 |
1042 | * Offset of 2nd range into the audio memory. |
1043 | * |
1044 | * @return |
1045 | * KERN_SUCCESS or error code on failure. |
1046 | */ |
1047 | extern kern_return_t |
1048 | exclaves_resource_audio_memory_copyout(exclaves_resource_t *resource, |
1049 | user_addr_t ubuffer, mach_vm_size_t usize1, mach_vm_size_t uoffset1, |
1050 | mach_vm_size_t usize2, mach_vm_size_t uoffset2); |
1051 | |
1052 | extern exclaves_resource_t * |
1053 | exclaves_resource_lookup_by_name(const char *domain_name, const char *name, |
1054 | xnuproxy_resource_t type); |
1055 | |
1056 | kern_return_t |
1057 | exclaves_xnu_proxy_check_mem_usage(void); |
1058 | |
1059 | __END_DECLS |
1060 | |
1061 | #endif /* CONFIG_EXCLAVES */ |
1062 | |