1*2c2f96dcSApple OSS Distributions /* 2*2c2f96dcSApple OSS Distributions * Copyright (c) 2023 Apple Inc. All rights reserved. 3*2c2f96dcSApple OSS Distributions * 4*2c2f96dcSApple OSS Distributions * @APPLE_OSREFERENCE_LICENSE_HEADER_START@ 5*2c2f96dcSApple OSS Distributions * 6*2c2f96dcSApple OSS Distributions * This file contains Original Code and/or Modifications of Original Code 7*2c2f96dcSApple OSS Distributions * as defined in and that are subject to the Apple Public Source License 8*2c2f96dcSApple OSS Distributions * Version 2.0 (the 'License'). You may not use this file except in 9*2c2f96dcSApple OSS Distributions * compliance with the License. The rights granted to you under the License 10*2c2f96dcSApple OSS Distributions * may not be used to create, or enable the creation or redistribution of, 11*2c2f96dcSApple OSS Distributions * unlawful or unlicensed copies of an Apple operating system, or to 12*2c2f96dcSApple OSS Distributions * circumvent, violate, or enable the circumvention or violation of, any 13*2c2f96dcSApple OSS Distributions * terms of an Apple operating system software license agreement. 14*2c2f96dcSApple OSS Distributions * 15*2c2f96dcSApple OSS Distributions * Please obtain a copy of the License at 16*2c2f96dcSApple OSS Distributions * http://www.opensource.apple.com/apsl/ and read it before using this file. 17*2c2f96dcSApple OSS Distributions * 18*2c2f96dcSApple OSS Distributions * The Original Code and all software distributed under the License are 19*2c2f96dcSApple OSS Distributions * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER 20*2c2f96dcSApple OSS Distributions * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, 21*2c2f96dcSApple OSS Distributions * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, 22*2c2f96dcSApple OSS Distributions * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. 23*2c2f96dcSApple OSS Distributions * Please see the License for the specific language governing rights and 24*2c2f96dcSApple OSS Distributions * limitations under the License. 25*2c2f96dcSApple OSS Distributions * 26*2c2f96dcSApple OSS Distributions * @APPLE_OSREFERENCE_LICENSE_HEADER_END@ 27*2c2f96dcSApple OSS Distributions */ 28*2c2f96dcSApple OSS Distributions 29*2c2f96dcSApple OSS Distributions #pragma once 30*2c2f96dcSApple OSS Distributions 31*2c2f96dcSApple OSS Distributions #if CONFIG_EXCLAVES 32*2c2f96dcSApple OSS Distributions 33*2c2f96dcSApple OSS Distributions #include <sys/cdefs.h> 34*2c2f96dcSApple OSS Distributions #include <stdbool.h> 35*2c2f96dcSApple OSS Distributions 36*2c2f96dcSApple OSS Distributions #if DEVELOPMENT || DEBUG 37*2c2f96dcSApple OSS Distributions extern unsigned int exclaves_debug; 38*2c2f96dcSApple OSS Distributions #else 39*2c2f96dcSApple OSS Distributions #define exclaves_debug 0 40*2c2f96dcSApple OSS Distributions #endif /* DEVELOPMENT || DEBUG */ 41*2c2f96dcSApple OSS Distributions 42*2c2f96dcSApple OSS Distributions /* Flag values in exclaves_debug boot-arg/sysctl */ 43*2c2f96dcSApple OSS Distributions __options_closed_decl(exclaves_debug_flags, unsigned int, { 44*2c2f96dcSApple OSS Distributions exclaves_debug_show_errors = 0x1, 45*2c2f96dcSApple OSS Distributions exclaves_debug_show_progress = 0x2, 46*2c2f96dcSApple OSS Distributions exclaves_debug_show_scheduler_request_response = 0x4, 47*2c2f96dcSApple OSS Distributions exclaves_debug_show_storage_upcalls = 0x8, 48*2c2f96dcSApple OSS Distributions exclaves_debug_show_iokit_upcalls = 0x10, 49*2c2f96dcSApple OSS Distributions exclaves_debug_show_notification_upcalls = 0x20, 50*2c2f96dcSApple OSS Distributions exclaves_debug_show_test_output = 0x40, 51*2c2f96dcSApple OSS Distributions exclaves_debug_show_lifecycle_upcalls = 0x80, 52*2c2f96dcSApple OSS Distributions }); 53*2c2f96dcSApple OSS Distributions 54*2c2f96dcSApple OSS Distributions #define EXCLAVES_ENABLE_SHOW_ERRORS (DEVELOPMENT || DEBUG) 55*2c2f96dcSApple OSS Distributions #define EXCLAVES_ENABLE_SHOW_PROGRESS (DEVELOPMENT || DEBUG) 56*2c2f96dcSApple OSS Distributions #define EXCLAVES_ENABLE_SHOW_SCHEDULER_REQUEST_RESPONSE (DEVELOPMENT || DEBUG) 57*2c2f96dcSApple OSS Distributions #define EXCLAVES_ENABLE_SHOW_STORAGE_UPCALLS (DEVELOPMENT || DEBUG) 58*2c2f96dcSApple OSS Distributions #define EXCLAVES_ENABLE_SHOW_IOKIT_UPCALLS (DEVELOPMENT || DEBUG) 59*2c2f96dcSApple OSS Distributions #define EXCLAVES_ENABLE_SHOW_NOTIFICATION_UPCALLS (DEVELOPMENT || DEBUG) 60*2c2f96dcSApple OSS Distributions #define EXCLAVES_ENABLE_SHOW_TEST_OUTPUT (DEVELOPMENT || DEBUG) 61*2c2f96dcSApple OSS Distributions #define EXCLAVES_ENABLE_SHOW_LIFECYCLE_UPCALLS (DEVELOPMENT || DEBUG) 62*2c2f96dcSApple OSS Distributions 63*2c2f96dcSApple OSS Distributions #if EXCLAVES_ENABLE_SHOW_ERRORS || EXCLAVES_ENABLE_SHOW_TEST_OUTPUT 64*2c2f96dcSApple OSS Distributions #define exclaves_debug_show_errors_flag (exclaves_debug_show_errors|exclaves_debug_show_test_output) 65*2c2f96dcSApple OSS Distributions #else 66*2c2f96dcSApple OSS Distributions #define exclaves_debug_show_errors_flag 0 67*2c2f96dcSApple OSS Distributions #endif 68*2c2f96dcSApple OSS Distributions #if EXCLAVES_ENABLE_SHOW_PROGRESS 69*2c2f96dcSApple OSS Distributions #define exclaves_debug_show_progress_flag exclaves_debug_show_progress 70*2c2f96dcSApple OSS Distributions #else 71*2c2f96dcSApple OSS Distributions #define exclaves_debug_show_progress_flag 0 72*2c2f96dcSApple OSS Distributions #endif 73*2c2f96dcSApple OSS Distributions #if EXCLAVES_ENABLE_SHOW_SCHEDULER_REQUEST_RESPONSE 74*2c2f96dcSApple OSS Distributions #define exclaves_debug_show_scheduler_request_response_flag \ 75*2c2f96dcSApple OSS Distributions exclaves_debug_show_scheduler_request_response 76*2c2f96dcSApple OSS Distributions #else 77*2c2f96dcSApple OSS Distributions #define exclaves_debug_show_scheduler_request_response_flag 0 78*2c2f96dcSApple OSS Distributions #endif 79*2c2f96dcSApple OSS Distributions #if EXCLAVES_ENABLE_SHOW_STORAGE_UPCALLS 80*2c2f96dcSApple OSS Distributions #define exclaves_debug_show_storage_upcalls_flag \ 81*2c2f96dcSApple OSS Distributions exclaves_debug_show_storage_upcalls 82*2c2f96dcSApple OSS Distributions #else 83*2c2f96dcSApple OSS Distributions #define exclaves_debug_show_storage_upcalls_flag 0 84*2c2f96dcSApple OSS Distributions #endif 85*2c2f96dcSApple OSS Distributions #if EXCLAVES_ENABLE_SHOW_IOKIT_UPCALLS 86*2c2f96dcSApple OSS Distributions #define exclaves_debug_show_iokit_upcalls_flag exclaves_debug_show_iokit_upcalls 87*2c2f96dcSApple OSS Distributions #else 88*2c2f96dcSApple OSS Distributions #define exclaves_debug_show_iokit_upcalls_flag 0 89*2c2f96dcSApple OSS Distributions #endif 90*2c2f96dcSApple OSS Distributions #if EXCLAVES_ENABLE_SHOW_NOTIFICATION_UPCALLS 91*2c2f96dcSApple OSS Distributions #define exclaves_debug_show_notification_upcalls_flag exclaves_debug_show_notification_upcalls 92*2c2f96dcSApple OSS Distributions #else 93*2c2f96dcSApple OSS Distributions #define exclaves_debug_show_notification_upcalls_flag 0 94*2c2f96dcSApple OSS Distributions #endif 95*2c2f96dcSApple OSS Distributions #if EXCLAVES_ENABLE_SHOW_TEST_OUTPUT 96*2c2f96dcSApple OSS Distributions #define exclaves_debug_show_test_output_flag exclaves_debug_show_test_output 97*2c2f96dcSApple OSS Distributions #else 98*2c2f96dcSApple OSS Distributions #define exclaves_debug_show_test_output_flag 0 99*2c2f96dcSApple OSS Distributions #endif 100*2c2f96dcSApple OSS Distributions #if EXCLAVES_ENABLE_SHOW_LIFECYCLE_UPCALLS 101*2c2f96dcSApple OSS Distributions #define exclaves_debug_show_lifecycle_upcalls_flag exclaves_debug_show_lifecycle_upcalls 102*2c2f96dcSApple OSS Distributions #else 103*2c2f96dcSApple OSS Distributions #define exclaves_debug_show_lifecycle_upcalls_flag 0 104*2c2f96dcSApple OSS Distributions #endif 105*2c2f96dcSApple OSS Distributions 106*2c2f96dcSApple OSS Distributions #define exclaves_debug_enabled(flag) \ 107*2c2f96dcSApple OSS Distributions ((bool)(exclaves_debug & exclaves_debug_##flag##_flag)) 108*2c2f96dcSApple OSS Distributions #define exclaves_debug_printf(flag, format, ...) ({ \ 109*2c2f96dcSApple OSS Distributions if (exclaves_debug_enabled(flag)) { \ 110*2c2f96dcSApple OSS Distributions printf(format, ##__VA_ARGS__); \ 111*2c2f96dcSApple OSS Distributions }}) 112*2c2f96dcSApple OSS Distributions 113*2c2f96dcSApple OSS Distributions #endif /* CONFIG_EXCLAVES */ 114