xref: /xnu-10063.141.1/osfmk/kern/exclaves_debug.h (revision d8b80295118ef25ac3a784134bcf95cd8e88109f)
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 #pragma once
30 
31 #if CONFIG_EXCLAVES
32 
33 #include <sys/cdefs.h>
34 #include <stdbool.h>
35 
36 #if DEVELOPMENT || DEBUG
37 extern unsigned int exclaves_debug;
38 #else
39 #define exclaves_debug 0
40 #endif /* DEVELOPMENT || DEBUG */
41 
42 /* Flag values in exclaves_debug boot-arg/sysctl */
43 __options_closed_decl(exclaves_debug_flags, unsigned int, {
44 	exclaves_debug_show_errors = 0x1,
45 	exclaves_debug_show_progress = 0x2,
46 	exclaves_debug_show_scheduler_request_response = 0x4,
47 	exclaves_debug_show_storage_upcalls = 0x8,
48 	exclaves_debug_show_iokit_upcalls = 0x10,
49 	exclaves_debug_show_notification_upcalls = 0x20,
50 	exclaves_debug_show_test_output = 0x40,
51 	exclaves_debug_show_lifecycle_upcalls = 0x80,
52 });
53 
54 #define EXCLAVES_ENABLE_SHOW_ERRORS                     (DEVELOPMENT || DEBUG)
55 #define EXCLAVES_ENABLE_SHOW_PROGRESS                   (DEVELOPMENT || DEBUG)
56 #define EXCLAVES_ENABLE_SHOW_SCHEDULER_REQUEST_RESPONSE (DEVELOPMENT || DEBUG)
57 #define EXCLAVES_ENABLE_SHOW_STORAGE_UPCALLS            (DEVELOPMENT || DEBUG)
58 #define EXCLAVES_ENABLE_SHOW_IOKIT_UPCALLS              (DEVELOPMENT || DEBUG)
59 #define EXCLAVES_ENABLE_SHOW_NOTIFICATION_UPCALLS       (DEVELOPMENT || DEBUG)
60 #define EXCLAVES_ENABLE_SHOW_TEST_OUTPUT                (DEVELOPMENT || DEBUG)
61 #define EXCLAVES_ENABLE_SHOW_LIFECYCLE_UPCALLS          (DEVELOPMENT || DEBUG)
62 
63 #if EXCLAVES_ENABLE_SHOW_ERRORS || EXCLAVES_ENABLE_SHOW_TEST_OUTPUT
64 #define exclaves_debug_show_errors_flag (exclaves_debug_show_errors|exclaves_debug_show_test_output)
65 #else
66 #define exclaves_debug_show_errors_flag 0
67 #endif
68 #if EXCLAVES_ENABLE_SHOW_PROGRESS
69 #define exclaves_debug_show_progress_flag exclaves_debug_show_progress
70 #else
71 #define exclaves_debug_show_progress_flag 0
72 #endif
73 #if EXCLAVES_ENABLE_SHOW_SCHEDULER_REQUEST_RESPONSE
74 #define exclaves_debug_show_scheduler_request_response_flag \
75     exclaves_debug_show_scheduler_request_response
76 #else
77 #define exclaves_debug_show_scheduler_request_response_flag 0
78 #endif
79 #if EXCLAVES_ENABLE_SHOW_STORAGE_UPCALLS
80 #define exclaves_debug_show_storage_upcalls_flag \
81     exclaves_debug_show_storage_upcalls
82 #else
83 #define exclaves_debug_show_storage_upcalls_flag 0
84 #endif
85 #if EXCLAVES_ENABLE_SHOW_IOKIT_UPCALLS
86 #define exclaves_debug_show_iokit_upcalls_flag exclaves_debug_show_iokit_upcalls
87 #else
88 #define exclaves_debug_show_iokit_upcalls_flag 0
89 #endif
90 #if EXCLAVES_ENABLE_SHOW_NOTIFICATION_UPCALLS
91 #define exclaves_debug_show_notification_upcalls_flag exclaves_debug_show_notification_upcalls
92 #else
93 #define exclaves_debug_show_notification_upcalls_flag 0
94 #endif
95 #if EXCLAVES_ENABLE_SHOW_TEST_OUTPUT
96 #define exclaves_debug_show_test_output_flag exclaves_debug_show_test_output
97 #else
98 #define exclaves_debug_show_test_output_flag 0
99 #endif
100 #if EXCLAVES_ENABLE_SHOW_LIFECYCLE_UPCALLS
101 #define exclaves_debug_show_lifecycle_upcalls_flag exclaves_debug_show_lifecycle_upcalls
102 #else
103 #define exclaves_debug_show_lifecycle_upcalls_flag 0
104 #endif
105 
106 #define exclaves_debug_enabled(flag) \
107     ((bool)(exclaves_debug & exclaves_debug_##flag##_flag))
108 #define exclaves_debug_printf(flag, format, ...) ({ \
109 	if (exclaves_debug_enabled(flag)) { \
110 	        printf(format, ##__VA_ARGS__); \
111 	}})
112 
113 #endif /* CONFIG_EXCLAVES */
114