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