xref: /xnu-12377.41.6/osfmk/kern/exclaves_memory.h (revision bbb1b6f9e71b8cdde6e5cd6f4841f207dee3d828)
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 typedef enum __enum_closed __enum_options : uint32_t {
47 	EXCLAVES_MEMORY_PAGE_FLAGS_NONE = 0,
48 #if HAS_MTE
49 	EXCLAVES_MEMORY_PAGE_FLAGS_MTE_TAGGED = (1 << 0),
50 #endif /* HAS_MTE */
51 } exclaves_memory_page_flags_t;
52 
53 __BEGIN_DECLS
54 
55 extern void
56 exclaves_memory_alloc(uint32_t npages, uint32_t * _Nonnull pages, const exclaves_memory_pagekind_t kind, const exclaves_memory_page_flags_t flags);
57 
58 extern void
59 exclaves_memory_free(uint32_t npages, const uint32_t * _Nonnull pages, const exclaves_memory_pagekind_t kind, const exclaves_memory_page_flags_t flags);
60 
61 extern kern_return_t
62 exclaves_memory_map(uint32_t npages, const uint32_t * _Nonnull pages, vm_prot_t prot,
63     char * _Nullable * _Nonnull address);
64 
65 extern kern_return_t
66 exclaves_memory_unmap(char * _Nonnull address, size_t size);
67 
68 /* BEGIN IGNORE CODESTYLE */
69 
70 /* Legacy upcall handlers */
71 
72 extern tb_error_t
73 exclaves_memory_upcall_legacy_alloc(uint32_t npages, xnuupcalls_pagekind_s kind,
74     tb_error_t (^_Nonnull completion)(xnuupcalls_pagelist_s));
75 
76 extern tb_error_t
77 exclaves_memory_upcall_legacy_alloc_ext(uint32_t npages, xnuupcalls_pageallocflags_s flags,
78     tb_error_t (^_Nonnull completion)(xnuupcalls_pagelist_s));
79 
80 extern tb_error_t
81 exclaves_memory_upcall_legacy_free(const uint32_t pages[_Nonnull EXCLAVES_MEMORY_MAX_REQUEST],
82     uint32_t npages, const xnuupcalls_pagekind_s kind,
83     tb_error_t (^_Nonnull completion)(void));
84 
85 extern tb_error_t
86 exclaves_memory_upcall_legacy_free_ext(const uint32_t pages[_Nonnull EXCLAVES_MEMORY_MAX_REQUEST],
87     uint32_t npages, xnuupcalls_pagefreeflags_s flags,
88     tb_error_t (^_Nonnull completion)(void));
89 
90 /* Upcall handlers */
91 
92 extern tb_error_t
93 exclaves_memory_upcall_alloc(uint32_t npages, xnuupcallsv2_pagekind_s kind,
94     tb_error_t (^_Nonnull completion)(xnuupcallsv2_pagelist_s));
95 
96 extern tb_error_t
97 exclaves_memory_upcall_alloc_ext(uint32_t npages, xnuupcallsv2_pageallocflagsv2_s flags,
98     tb_error_t (^_Nonnull completion)(xnuupcallsv2_pagelist_s));
99 
100 extern tb_error_t
101 exclaves_memory_upcall_free(const xnuupcallsv2_pagelist_s pages,
102     const xnuupcallsv2_pagekind_s kind, tb_error_t (^_Nonnull completion)(void));
103 
104 extern tb_error_t
105 exclaves_memory_upcall_free_ext(const xnuupcallsv2_pagelist_s pages,
106     const xnuupcallsv2_pagefreeflagsv2_s kind, tb_error_t (^_Nonnull completion)(void));
107 
108 /* END IGNORE CODESTYLE */
109 
110 extern void
111 exclaves_memory_report_accounting(void);
112 
113 __END_DECLS
114 
115 #endif /* CONFIG_EXCLAVES */
116