1 /*
2 * Copyright (c) 2022 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 #include <mach/exclaves.h>
30
31 kern_return_t
exclaves_endpoint_call(mach_port_t port,exclaves_id_t endpoint_id,mach_vm_address_t msg_buffer,mach_vm_size_t size,exclaves_tag_t * tag,exclaves_error_t * error)32 exclaves_endpoint_call(mach_port_t port, exclaves_id_t endpoint_id,
33 mach_vm_address_t msg_buffer, mach_vm_size_t size, exclaves_tag_t *tag,
34 exclaves_error_t *error)
35 {
36 #if defined(__LP64__)
37 kern_return_t kr = KERN_SUCCESS;
38 const uint32_t opf = EXCLAVES_CTL_OP_AND_FLAGS(ENDPOINT_CALL, 0);
39 kr = _exclaves_ctl_trap(port, opf, endpoint_id, msg_buffer, size);
40 *tag = 0;
41 *error = 0;
42 return kr;
43 #else
44 #pragma unused(port, endpoint_id, msg_buffer, size, tag, error)
45 return KERN_NOT_SUPPORTED;
46 #endif /* defined(__LP64__) */
47 }
48
49 kern_return_t
exclaves_named_buffer_create(mach_port_t port,exclaves_id_t buffer_id,mach_vm_size_t size,mach_port_t * out_named_buffer_port)50 exclaves_named_buffer_create(mach_port_t port, exclaves_id_t buffer_id,
51 mach_vm_size_t size, mach_port_t* out_named_buffer_port)
52 {
53 const uint32_t opf = EXCLAVES_CTL_OP_AND_FLAGS(NAMED_BUFFER_CREATE, 0);
54 return _exclaves_ctl_trap(port, opf, buffer_id,
55 (uintptr_t)out_named_buffer_port, size);
56 }
57
58 kern_return_t
exclaves_named_buffer_copyin(mach_port_t named_buffer_port,mach_vm_address_t src_buffer,mach_vm_size_t size,mach_vm_size_t offset)59 exclaves_named_buffer_copyin(mach_port_t named_buffer_port,
60 mach_vm_address_t src_buffer, mach_vm_size_t size, mach_vm_size_t offset)
61 {
62 const uint32_t opf = EXCLAVES_CTL_OP_AND_FLAGS(NAMED_BUFFER_COPYIN, 0);
63 return _exclaves_ctl_trap(named_buffer_port, opf, (exclaves_id_t)offset,
64 src_buffer, size);
65 }
66
67 kern_return_t
exclaves_named_buffer_copyout(mach_port_t named_buffer_port,mach_vm_address_t dst_buffer,mach_vm_size_t size,mach_vm_size_t offset)68 exclaves_named_buffer_copyout(mach_port_t named_buffer_port,
69 mach_vm_address_t dst_buffer, mach_vm_size_t size, mach_vm_size_t offset)
70 {
71 const uint32_t opf = EXCLAVES_CTL_OP_AND_FLAGS(NAMED_BUFFER_COPYOUT, 0);
72 return _exclaves_ctl_trap(named_buffer_port, opf, (exclaves_id_t)offset,
73 dst_buffer, size);
74 }
75
76 kern_return_t
exclaves_boot(mach_port_t port,uint64_t flags)77 exclaves_boot(mach_port_t port, uint64_t flags)
78 {
79 const uint32_t opf = EXCLAVES_CTL_OP_AND_FLAGS(BOOT, 0);
80 return _exclaves_ctl_trap(port, opf, flags, 0, 0);
81 }
82