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