| 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 <mach/exclaves.h> |
| 34 | |
| 35 | #include <libkern/section_keywords.h> |
| 36 | #include <mach/kern_return.h> |
| 37 | |
| 38 | #define EXCLAVES_BOOT_TASK_SEGMENT "__DATA_CONST" |
| 39 | #define EXCLAVES_BOOT_TASK_SECTION "__exclaves_bt" |
| 40 | |
| 41 | __BEGIN_DECLS |
| 42 | |
| 43 | __enum_decl(exclaves_boot_task_rank_t, uint32_t, { |
| 44 | EXCLAVES_BOOT_RANK_FIRST = 0, |
| 45 | EXCLAVES_BOOT_RANK_SECOND = 1, |
| 46 | EXCLAVES_BOOT_RANK_THIRD = 2, |
| 47 | EXCLAVES_BOOT_RANK_FOURTH = 3, |
| 48 | |
| 49 | EXCLAVES_BOOT_RANK_ANY = 0x7fffffff, |
| 50 | |
| 51 | EXCLAVES_BOOT_RANK_LAST = 0xffffffff, |
| 52 | }); |
| 53 | |
| 54 | typedef struct exclaves_boot_task_entry { |
| 55 | kern_return_t (*ebt_func)(void); |
| 56 | exclaves_boot_task_rank_t ebt_rank; |
| 57 | const char *ebt_name; |
| 58 | } exclaves_boot_task_entry_t; |
| 59 | |
| 60 | /* BEGIN IGNORE CODESTYLE */ |
| 61 | #define __EXCLAVES_BOOT_TASK(name, line, rank, func) \ |
| 62 | __PLACE_IN_SECTION(EXCLAVES_BOOT_TASK_SEGMENT "," \ |
| 63 | EXCLAVES_BOOT_TASK_SECTION) \ |
| 64 | static const exclaves_boot_task_entry_t \ |
| 65 | __exclaves_boot_task_entry_ ## name ## _ ## line = { \ |
| 66 | .ebt_func = func, \ |
| 67 | .ebt_rank = rank, \ |
| 68 | /* Used for panic string. */ \ |
| 69 | .ebt_name = #name, \ |
| 70 | } |
| 71 | /* END IGNORE CODESTYLE */ |
| 72 | |
| 73 | #define EXCLAVES_BOOT_TASK(func, rank) \ |
| 74 | __EXCLAVES_BOOT_TASK(func, __LINE__, rank, func) |
| 75 | |
| 76 | /* Boot the requested boot stage. */ |
| 77 | extern kern_return_t exclaves_boot(exclaves_boot_stage_t); |
| 78 | |
| 79 | /* |
| 80 | * Wait until the specified boot stage has been reached (or return |
| 81 | * KERN_NOT_SUPPORTED immediately if exclaves are not supported) |
| 82 | */ |
| 83 | extern kern_return_t exclaves_boot_wait(exclaves_boot_stage_t); |
| 84 | |
| 85 | __END_DECLS |
| 86 | |
| 87 | #endif /* CONFIG_EXCLAVES */ |
| 88 | |