xref: /xnu-11215.81.4/osfmk/kern/exclaves_memory.h (revision d4514f0bc1d3f944c22d92e68b646ac3fb40d452) !
1 /*
2  * Copyright (c) 2024 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 <stdint.h>
34 #include <mach/kern_return.h>
35 
36 #include "kern/exclaves.tightbeam.h"
37 
38 /* The maximum number of pages in a memory request. */
39 #define EXCLAVES_MEMORY_MAX_REQUEST (64)
40 
41 typedef enum : uint32_t {
42 	EXCLAVES_MEMORY_PAGEKIND_ROOTDOMAIN = 1,
43 	EXCLAVES_MEMORY_PAGEKIND_CONCLAVE = 2,
44 } exclaves_memory_pagekind_t;
45 
46 __BEGIN_DECLS
47 
48 extern void
49 exclaves_memory_alloc(uint32_t npages, uint32_t * _Nonnull pages, const exclaves_memory_pagekind_t kind);
50 
51 extern void
52 exclaves_memory_free(uint32_t npages, const uint32_t * _Nonnull pages, const exclaves_memory_pagekind_t kind);
53 
54 extern kern_return_t
55 exclaves_memory_map(uint32_t npages, const uint32_t * _Nonnull pages, vm_prot_t prot,
56     char * _Nullable * _Nonnull address);
57 
58 extern kern_return_t
59 exclaves_memory_unmap(char * _Nonnull address, size_t size);
60 
61 /* BEGIN IGNORE CODESTYLE */
62 
63 /* Legacy upcall handlers */
64 
65 extern tb_error_t
66 exclaves_memory_upcall_legacy_alloc(uint32_t npages, xnuupcalls_pagekind_s kind,
67     tb_error_t (^_Nonnull completion)(xnuupcalls_pagelist_s));
68 
69 extern tb_error_t
70 exclaves_memory_upcall_legacy_free(const uint32_t pages[_Nonnull EXCLAVES_MEMORY_MAX_REQUEST],
71     uint32_t npages, const xnuupcalls_pagekind_s kind,
72     tb_error_t (^_Nonnull completion)(void));
73 
74 /* Upcall handlers */
75 
76 extern tb_error_t
77 exclaves_memory_upcall_alloc(uint32_t npages, xnuupcallsv2_pagekind_s kind,
78     tb_error_t (^_Nonnull completion)(xnuupcallsv2_pagelist_s));
79 
80 extern tb_error_t
81 exclaves_memory_upcall_free(const xnuupcallsv2_pagelist_s pages,
82     const xnuupcallsv2_pagekind_s kind, tb_error_t (^_Nonnull completion)(void));
83 
84 /* END IGNORE CODESTYLE */
85 
86 extern void
87 exclaves_memory_report_accounting(void);
88 
89 __END_DECLS
90 
91 #endif /* CONFIG_EXCLAVES */
92