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