xref: /xnu-11215.1.10/osfmk/kern/exclaves_resource.h (revision 8d741a5de7ff4191bf97d57b9f54c2f6d4a15585)
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 "kern/exclaves.tightbeam.h"
44 
45 __BEGIN_DECLS
46 
47 
48 /* -------------------------------------------------------------------------- */
49 #pragma mark Exclaves Resources
50 
51 #define EXCLAVES_DOMAIN_KERNEL "com.apple.kernel"
52 #define EXCLAVES_DOMAIN_DARWIN "com.apple.darwin"
53 
54 /*
55  * Data associated with a conclave.
56  */
57 
58 /*
59  * Conclave State Machine:
60  *
61  *                 Launch Syscall
62  *       +---------+         +--------------+
63  *       |Attached | ------->|  Launching   |
64  *       |         |         |              |
65  *       +---------+         +--------------+
66  *          ^ |                 |       |
67  *    Spawn | |proc_exit   Exit |       |   Start IPC
68  *          | |                 |       |  to Conclave Manager
69  *          | v                 v       v
70  *      +---------+   +-----------+   +----------+
71  * *--> |  None   |   |    Stop   |   | Launched |
72  *      |         |   | Requested |   |          |
73  *      +---------+   +-----------+   +----------+
74  *           ^                  |       |
75  *  proc_exit|          Launch  |       |  Exit
76  *           |        Completion|       |
77  *           |                  v       v
78  *         +---------+       +------------+
79  *         | Stopped |<------|  Stopping  |
80  *         |         |       |            |
81  *         +---------+       +------------+
82  *                    Stop IPC
83  *                   to Conclave Manager
84  */
85 typedef enum  {
86 	CONCLAVE_S_NONE = 0,
87 	CONCLAVE_S_ATTACHED,
88 	CONCLAVE_S_LAUNCHING,
89 	CONCLAVE_S_LAUNCHED,
90 	CONCLAVE_S_STOP_REQUESTED,
91 	CONCLAVE_S_STOPPING,
92 	CONCLAVE_S_STOPPED,
93 } conclave_state_t;
94 
95 /* The maximum number of services available in any conclave. */
96 #define CONCLAVE_SERVICE_MAX 128
97 
98 typedef struct {
99 	conclave_state_t       c_state;
100 	tb_client_connection_t c_control;
101 	task_t XNU_PTRAUTH_SIGNED_PTR("conclave.task") c_task;
102 	bitmap_t               c_service_bitmap[BITMAP_LEN(CONCLAVE_SERVICE_MAX)];
103 } conclave_resource_t;
104 
105 #define EXCLAVES_SHARED_BUFFER_MAX_RANGES 256
106 
107 typedef struct {
108 	char *address;
109 	size_t npages;
110 } named_buffer_range_t;
111 
112 typedef struct {
113 	size_t nb_size;
114 	exclaves_buffer_perm_t nb_perm;
115 	size_t nb_nranges;
116 	named_buffer_range_t nb_range[EXCLAVES_SHARED_BUFFER_MAX_RANGES];
117 } named_buffer_resource_t;
118 
119 typedef struct {
120 	size_t sm_size;
121 	exclaves_buffer_perm_t sm_perm;
122 	size_t sm_nranges;
123 	named_buffer_range_t sm_range[EXCLAVES_SHARED_BUFFER_MAX_RANGES];
124 	sharedmemorybase_mapping_s sm_mapping;
125 	sharedmemorybase_segxnuaccess_s sm_client;
126 } shared_memory_resource_t;
127 
128 typedef struct {
129 	/* how many times *this* sensor resource handle has been
130 	 * used to call sensor_start */
131 	uint64_t s_startcount;
132 } sensor_resource_t;
133 
134 typedef struct {
135 	struct klist notification_klist;
136 } exclaves_notification_t;
137 
138 /*
139  * Every resource has an associated name and some other common state.
140  * Additionally there may be type specific data associated with the resource.
141  */
142 #define EXCLAVES_RESOURCE_NAME_MAX 128
143 typedef struct exclaves_resource {
144 	char                r_name[EXCLAVES_RESOURCE_NAME_MAX];
145 	xnuproxy_resourcetype_s r_type;
146 	uint64_t            r_id;
147 	_Atomic uint32_t    r_usecnt;
148 	ipc_port_t          r_port;
149 	lck_mtx_t           r_mutex;
150 	bool                r_active;
151 	bool                r_connected;
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 name
483  * The name of conclave resource.
484  *
485  * @param task
486  * Task to attach the conclave to.
487  *
488  * @return
489  * KERN_SUCCESS on success, error code otherwise.
490  */
491 extern kern_return_t
492 exclaves_conclave_attach(const char *name, task_t task);
493 
494 /*!
495  * @function exclaves_conclave_detach
496  *
497  * @abstract
498  * Detach a conclave from a task. The conclave must already be attached to the
499  * task and stopped. Once detached, this conclave is available for other tasks.
500  *
501  * @param resource
502  * Conclave Manager resource.
503  *
504  * @param task
505  * Task to detach the conclave from.
506  *
507  * @return
508  * KERN_SUCCESS on success, error code otherwise.
509  */
510 extern kern_return_t
511 exclaves_conclave_detach(exclaves_resource_t *resource, task_t task);
512 
513 /*!
514  * @function exclaves_conclave_inherit
515  *
516  * @abstract
517  * Pass an attached conclave from one task to another.
518  *
519  * @param resource
520  * Conclave Manager resource.
521  *
522  * @param old_task
523  * Task with attached conclave.
524  *
525  * @param new_task
526  * Task which will inherit the conclave.
527  *
528  * @return
529  * KERN_SUCCESS on success, error code otherwise.
530  */
531 extern kern_return_t
532 exclaves_conclave_inherit(exclaves_resource_t *resource, task_t old_task,
533     task_t new_task);
534 
535 
536 /*!
537  * @function exclaves_conclave_is_attached
538  *
539  * @abstract
540  * Returns true if the conclave is in the ATTACHED state.
541  *
542  * @param resource
543  * Conclave Manager resource.
544  *
545  * @return
546  * True if conclave is attached, false otherwise
547  */
548 extern bool
549 exclaves_conclave_is_attached(const exclaves_resource_t *resource);
550 
551 /*!
552  * @function exclaves_conclave_launch
553  *
554  * @abstract
555  * Launch a conclave. The conclave must be attached to a task and not already
556  * launched.
557  *
558  * @param resource
559  * Conclave Manager resource.
560  *
561  * @return
562  * KERN_SUCCESS on success, error code otherwise.
563  */
564 extern kern_return_t
565 exclaves_conclave_launch(exclaves_resource_t *resource);
566 
567 /*!
568  * @function exclaves_conclave_lookup_resources
569  *
570  * @abstract
571  * Lookup conclave resource. The conclave must be attached to a task and
572  * launched.
573  *
574  * @param resource
575  * Conclave Manager resource.
576  *
577  * @param conclave_resource_user
578  * Array to fill user resources for Conclave
579  *
580  * @param resource_count
581  * Number of resources in array
582  *
583  * @return
584  * KERN_SUCCESS on success, error code otherwise.
585  */
586 extern kern_return_t
587 exclaves_conclave_lookup_resources(exclaves_resource_t *resource,
588     struct exclaves_resource_user *conclave_resource_user, int resource_count);
589 
590 /*!
591  * @function exclaves_conclave_stop
592  *
593  * @abstract
594  * Stop a conclave. The conclave must be launched and attached.
595  *
596  * @param resource
597  * Conclave Manager resource.
598  *
599  * @param gather_crash_bt
600  * Conclave Manager needs to gather backtraces
601  *
602  * @return
603  * KERN_SUCCESS on success, error code otherwise.
604  */
605 extern kern_return_t
606 exclaves_conclave_stop(exclaves_resource_t *resource, bool gather_crash_bt);
607 
608 /*!
609  * @function exclaves_conclave_stop_upcall
610  *
611  * @abstract
612  * Stop a conclave. The conclave must be launched and attached.
613  *
614  * @param resource
615  * Conclave Manager resource.
616  *
617  * @return
618  * KERN_SUCCESS on success, error code otherwise.
619  */
620 extern kern_return_t
621 exclaves_conclave_stop_upcall(exclaves_resource_t *resource);
622 
623 /*!
624  * @function exclaves_conclave_stop_upcall_complete
625  *
626  * @abstract
627  * Complete the Conclave stop once back in regular context.
628  *
629  * @param resource
630  * Conclave Manager resource.
631  *
632  * @param task
633  * Conclave Host task
634  *
635  * @return
636  * KERN_SUCCESS on success, error code otherwise.
637  */
638 extern kern_return_t
639 exclaves_conclave_stop_upcall_complete(exclaves_resource_t *resource, task_t task);
640 
641 /*!
642  * @function exclaves_conclave_get_domain
643  *
644  * @abstract
645  * Return the domain associated with the specified conclave resource. Or the
646  * kernel domain if the conclave resource is NULL.
647  *
648  * @param resource
649  * Conclave Manager resource.
650  *
651  * @return
652  * The domain of the conclave or the kernel domain.
653  */
654 extern const char *
655 exclaves_conclave_get_domain(exclaves_resource_t *resource);
656 
657 
658 /*!
659  * @function exclaves_conclave_has_service
660  *
661  * @abstract
662  * Return true if the service ID is associated with the specified conclave
663  * resource.
664  *
665  * @param resource
666  * Conclave Manager resource.
667  *
668  * @params id
669  * ID of a SERVICE resource.
670  *
671  * @return
672  * true if the ID is available to conclave, false otherwise
673  */
674 extern bool
675 exclaves_conclave_has_service(exclaves_resource_t *resource, uint64_t id);
676 
677 /* -------------------------------------------------------------------------- */
678 #pragma mark Sensors
679 
680 /*!
681  * @function exclaves_resource_sensor_open
682  *
683  * @abstract
684  * Open a sensor resource.
685  *
686  * @param domain
687  * The domain to search.
688  *
689  * @param name
690  * The name of the sensor resource.
691  *
692  * @param resource
693  * Out parameter which holds the resource on success.
694  *
695  * @return
696  * KERN_SUCCESS on success, error code otherwise.
697  *
698  * @discussion
699  * Returns with a +1 use-count on the resource which must be dropped with
700  * exclaves_resource_release().
701  */
702 extern kern_return_t
703 exclaves_resource_sensor_open(const char *domain, const char *name,
704     exclaves_resource_t **resource);
705 
706 /*!
707  * @function exclaves_resource_sensor_start
708  *
709  * @abstract
710  * Start accessing a sensor.
711  *
712  * @param resource
713  * Sensor resource.
714  *
715  * @param flags
716  * Flags to pass to implementation.
717  *
718  * @param status
719  * output parameter for status of sensor after this operation.
720  *
721  * @return
722  * KERN_SUCCESS on success, error code otherwise.
723  */
724 kern_return_t
725 exclaves_resource_sensor_start(exclaves_resource_t *resource, uint64_t flags,
726     exclaves_sensor_status_t *status);
727 
728 /*!
729  * @function exclaves_resource_sensor_stop
730  *
731  * @abstract
732  * Stop accessing a sensor.
733  *
734  * @param resource
735  * Sensor resource.
736  *
737  * @param flags
738  * Flags to pass to implementation.
739  *
740  * @param status
741  * output parameter for status of sensor after this operation.
742  *
743  * @return
744  * KERN_SUCCESS on success, error code otherwise.
745  */
746 kern_return_t
747 exclaves_resource_sensor_stop(exclaves_resource_t *resource, uint64_t flags,
748     exclaves_sensor_status_t *status);
749 
750 /*!
751  * @function exclaves_resource_sensor_status
752  *
753  * @abstract
754  * Query the status of access to a sensor.
755  *
756  * @param resource
757  * Sensor resource.
758  *
759  * @param flags
760  * Flags to pass to implementation.
761  *
762  * @param status
763  * output parameter for status of sensor after this operation.
764  *
765  * @return
766  * KERN_SUCCESS on success, error code otherwise.
767  */
768 kern_return_t
769 exclaves_resource_sensor_status(exclaves_resource_t *resource, uint64_t flags,
770     exclaves_sensor_status_t *status);
771 
772 /* -------------------------------------------------------------------------- */
773 #pragma mark Notifications
774 
775 /*!
776  * @function exclaves_notification_create
777  *
778  * @abstract
779  * Set up an exclave notification from the specified resource.
780  *
781  * @param domain
782  * The domain to search.
783  *
784  * @param name
785  * The name of the notification resource.
786  *
787  * @return
788  * A notification resource or NULL.
789  *
790  * @discussion
791  * Returns with a +1 use-count on the resource which must be dropped with
792  * exclaves_resource_release().
793  */
794 extern kern_return_t
795 exclaves_notification_create(const char *domain, const char *name,
796     exclaves_resource_t **resource);
797 
798 /*!
799  * @function exclaves_notification_signal
800  *
801  * @abstract
802  * To be called from upcall context when the specified notification resource is signaled.
803  *
804  * @param resource
805  * Notification resource.
806  *
807  * @param event_mask
808  * Bit mask of events for the notification.
809  *
810  * @return
811  * KERN_SUCCESS on success, error code otherwise.
812  */
813 extern kern_return_t
814 exclaves_notification_signal(exclaves_resource_t *resource, long event_mask);
815 
816 
817 /*!
818  * @function exclaves_notificatione_lookup_by_id
819  *
820  * @abstract
821  * Find an exclave notification  by ID.
822  *
823  * @param id
824  * The resource ID.
825  *
826  * @param domain
827  * The domain to search.
828  *
829  * @return
830  * Pointer to the resource
831  */
832 exclaves_resource_t *
833 exclaves_notification_lookup_by_id(const char *domain, uint64_t id);
834 
835 
836 /* -------------------------------------------------------------------------- */
837 #pragma mark Services
838 
839 /*
840  * Indicates an invalid service. */
841 #define  EXCLAVES_INVALID_ID UINT64_C(~0)
842 
843 /*!
844  * @function exclaves_service_lookup
845  *
846  * @abstract
847  * Look up a service resource
848  *
849  * @param domain
850  * The domain to search.
851  *
852  * @param name
853  * The name of the service resource.
854  *
855  * @return
856  * ID of service or EXCLAVES_INVALID_ID if the service cannot be found.
857  */
858 extern uint64_t
859 exclaves_service_lookup(const char *domain, const char *name);
860 
861 
862 /* -------------------------------------------------------------------------- */
863 #pragma mark Shared Memory
864 
865 /*!
866  * @function exclaves_resource_shared_memory_map
867  *
868  * @abstract
869  * Map a shared memory resource.
870  *
871  * @param domain
872  * The domain to search.
873  *
874  * @param name
875  * The name of the shared memory resource.
876  *
877  * @param size
878  * Size of shared memory region to map.
879  *
880  * @param perm
881  * The permissions of the shared memory.
882  *
883  * @param resource
884  * Out parameter which holds the resource on success.
885  *
886  * @return
887  * KERN_SUCCESS or an error code.
888  *
889  * @discussion
890  * Returns with a +1 use-count on the resource which must be dropped with
891  * exclaves_resource_release().
892  */
893 extern kern_return_t
894 exclaves_resource_shared_memory_map(const char *domain, const char *name,
895     size_t size, exclaves_buffer_perm_t perm, exclaves_resource_t **resource);
896 
897 /*!
898  * @function exclaves_resource_shared_memory_copyin
899  *
900  * @abstract
901  * Copy user data into a shared memory.
902  *
903  * @param resource
904  * Named buffer resource.
905  *
906  * @param ubuffer
907  * Source of data to copy.
908  *
909  * @param usize1
910  * Size of data to copy.
911  *
912  * @param uoffset1
913  * Offset into the shared memory.
914  *
915  * @param usize2
916  * Size of 2nd range of data to copy (can be 0).
917  *
918  * @param uoffset2
919  * Offset of 2nd range into the shared memory.
920  *
921  * @return
922  * KERN_SUCCESS or error code on failure.
923  */
924 extern kern_return_t
925 exclaves_resource_shared_memory_copyin(exclaves_resource_t *resource,
926     user_addr_t ubuffer, mach_vm_size_t usize1, mach_vm_size_t uoffset1,
927     mach_vm_size_t usize2, mach_vm_size_t uoffset2);
928 
929 /*!
930  * @function exclaves_resource_shared_memory_copyout
931  *
932  * @abstract
933  * Copy user data into a shared memory.
934  *
935  * @param resource
936  * Named buffer resource.
937  *
938  * @param ubuffer
939  * Destination to copy data to.
940  *
941  * @param usize1
942  * Size of data to copy.
943  *
944  * @param uoffset1
945  * Offset into the shared memory.
946  *
947  * @param usize2
948  * Size of 2nd range of data to copy (can be 0).
949  *
950  * @param uoffset2
951  * Offset of 2nd range into the shared memory.
952  *
953  * @return
954  * KERN_SUCCESS or error code on failure.
955  */
956 extern kern_return_t
957 exclaves_resource_shared_memory_copyout(exclaves_resource_t *resource,
958     user_addr_t ubuffer, mach_vm_size_t usize1, mach_vm_size_t uoffset1,
959     mach_vm_size_t usize2, mach_vm_size_t uoffset2);
960 
961 
962 /*!
963  * @function exclaves_resource_shared_memory_io
964  *
965  * @abstract
966  * Perform IO on a shared memory
967  *
968  * @param resource
969  * Named buffer resource.
970  *
971  * @param offset
972  * Offset into the shared memory
973  *
974  * @param len
975  * Size of the IO
976  *
977  * @param cb
978  * A block which is called (potentially) multiple times to perform the IO.
979  *
980  * @return
981  * 0 on success. If cb returns a non-zero value, exclaves_resource_shared_memory_io()
982  * immediately returns with that non-zero value.
983  */
984 extern int
985     exclaves_resource_shared_memory_io(exclaves_resource_t * resource, off_t offset,
986     size_t len, int (^cb)(char *buffer, size_t size));
987 
988 
989 /* -------------------------------------------------------------------------- */
990 #pragma mark Arbitrated Audio Memory
991 
992 /*!
993  * @function exclaves_resource_audio_memory_map
994  *
995  * @abstract
996  * Map an audio memory resource.
997  *
998  * @param domain
999  * The domain to search.
1000  *
1001  * @param name
1002  * The name of audio memory resource.
1003  *
1004  * @param size
1005  * Size of named buffer region to map.
1006  *
1007  * @param resource
1008  * Out parameter which holds the resource on success.
1009  *
1010  * @return
1011  * KERN_SUCCESS or error code on failure.
1012  *
1013  * @discussion
1014  * Returns with a +1 use-count on the resource which must be dropped with
1015  * exclaves_resource_release().
1016  */
1017 extern kern_return_t
1018 exclaves_resource_audio_memory_map(const char *domain, const char *name, size_t size,
1019     exclaves_resource_t **resource);
1020 
1021 /*!
1022  * @function exclaves_resource_audio_memory_copyout
1023  *
1024  * @abstract
1025  * Copy user data into a audio memory.
1026  *
1027  * @param resource
1028  * audio memory resource.
1029  *
1030  * @param ubuffer
1031  * Destination to copy data to.
1032  *
1033  * @param usize1
1034  * Size of data to copy.
1035  *
1036  * @param uoffset1
1037  * Offset into the audio memory.
1038  *
1039  * @param usize2
1040  * Size of 2nd range of data to copy (can be 0).
1041  *
1042  * @param uoffset2
1043  * Offset of 2nd range into the audio memory.
1044  *
1045  * @return
1046  * KERN_SUCCESS or error code on failure.
1047  */
1048 extern kern_return_t
1049 exclaves_resource_audio_memory_copyout(exclaves_resource_t *resource,
1050     user_addr_t ubuffer, mach_vm_size_t usize1, mach_vm_size_t uoffset1,
1051     mach_vm_size_t usize2, mach_vm_size_t uoffset2);
1052 
1053 extern exclaves_resource_t *
1054 exclaves_resource_lookup_by_name(const char *domain_name, const char *name,
1055     xnuproxy_resourcetype_s type);
1056 
1057 __END_DECLS
1058 
1059 #endif /* CONFIG_EXCLAVES */
1060