2 * Copyright (c) 2006-2007,2009-2010,2012-2014 Apple Inc. All Rights Reserved.
4 * @APPLE_LICENSE_HEADER_START@
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. Please obtain a copy of the License at
10 * http://www.opensource.apple.com/apsl/ and read it before using this
13 * The Original Code and all software distributed under the License are
14 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
15 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
16 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
18 * Please see the License for the specific language governing rights and
19 * limitations under the License.
21 * @APPLE_LICENSE_HEADER_END@
25 * debugging.h - non-trivial debug support
27 #ifndef _SECURITY_UTILITIES_DEBUGGING_H_
28 #define _SECURITY_UTILITIES_DEBUGGING_H_
31 #include <libkern/libkern.h>
32 #define secalert(format, ...) printf((format), ## __VA_ARGS__)
33 #define secemergency(format, ...) printf((format), ## __VA_ARGS__)
34 #define seccritical(format, ...) printf((format), ## __VA_ARGS__)
35 #define secerror(format, ...) printf((format), ## __VA_ARGS__)
36 #define secwarning(format, ...) printf((format), ## __VA_ARGS__)
37 #define secnotice(scope, format, ...) printf((format), ## __VA_ARGS__)
38 #define secnoticeq(scope, format, ...) printf((format), ## __VA_ARGS__)
39 #define secinfo(scope, format, ...) printf((format), ## __VA_ARGS__)
41 #define secdebug(scope, format, ...) printf((format), ## __VA_ARGS__)
43 #define secdebug(scope, format, ...) /* nothing */
47 #include <TargetConditionals.h>
48 #include <CoreFoundation/CFString.h>
53 extern void __security_trace_enter_api(const char *api
, CFStringRef format
, ...) CF_FORMAT_FUNCTION(2, 3);
54 extern void __security_trace_return_api(const char *api
, CFStringRef format
, ...) CF_FORMAT_FUNCTION(2, 3);
56 extern void __security_debug(CFStringRef scope
,
57 const char *function
, const char *file
, int line
,
58 CFStringRef format
, ...) CF_FORMAT_FUNCTION(5,6);
60 extern void __security_log(int level
, CFStringRef scope
,
61 const char *function
, const char *file
, int line
,
62 CFStringRef format
, ...) CF_FORMAT_FUNCTION(6,7);
64 #define sec_trace_enter_api(format...) __security_trace_enter_api(__FUNCTION__, format)
65 #define sec_trace_return_api(rtype, body, format...) { rtype _r = body(); __security_trace_return_api(__FUNCTION__, format, _r); return _r; }
66 #define sec_trace_return_bool_api(body, format...) { bool _r = body(); typeof(format) _fmt = format; __security_trace_return_api(__FUNCTION__, _fmt ? _fmt : CFSTR("return=%d"), (int)_r); return _r; }
68 #define secemergency(format, ...) __security_log(ASL_LEVEL_EMERG, NULL, \
69 __FUNCTION__, __FILE__, __LINE__, \
70 CFSTR(format), ## __VA_ARGS__)
72 #define secalert(format, ...) __security_log(ASL_LEVEL_ALERT, NULL, \
73 __FUNCTION__, __FILE__, __LINE__, \
74 CFSTR(format), ## __VA_ARGS__)
76 #define seccritical(format, ...) __security_log(ASL_LEVEL_CRIT, NULL, \
77 __FUNCTION__, __FILE__, __LINE__, \
78 CFSTR(format), ## __VA_ARGS__)
80 #define secerror(format, ...) __security_log(ASL_LEVEL_ERR, NULL, \
81 __FUNCTION__, __FILE__, __LINE__, \
82 CFSTR(format), ## __VA_ARGS__)
84 #define secerrorq(format, ...) __security_log(ASL_LEVEL_ERR, NULL, \
86 CFSTR(format), ## __VA_ARGS__)
88 #define secwarning(format, ...) __security_log(ASL_LEVEL_WARNING, NULL, \
89 __FUNCTION__, __FILE__, __LINE__, \
90 CFSTR(format), ## __VA_ARGS__)
92 #define secnotice(scope, format, ...) __security_log(ASL_LEVEL_NOTICE, CFSTR(scope), \
93 __FUNCTION__, __FILE__, __LINE__, \
94 CFSTR(format), ## __VA_ARGS__)
96 #define secnoticeq(scope, format, ...) __security_log(ASL_LEVEL_NOTICE, CFSTR(scope), \
98 CFSTR(format), ## __VA_ARGS__)
100 #define secinfo(scope, format, ...) __security_log(ASL_LEVEL_INFO, CFSTR(scope), \
101 __FUNCTION__, __FILE__, __LINE__, \
102 CFSTR(format), ## __VA_ARGS__)
106 # define secdebug(scope,format, ...) __security_debug(CFSTR(scope), \
107 __FUNCTION__, __FILE__, __LINE__, \
108 CFSTR(format), ## __VA_ARGS__)
110 # define secdebug(scope,...) /* nothing */
113 typedef void (^security_log_handler
)(int level
, CFStringRef scope
, const char *function
,
114 const char *file
, int line
, CFStringRef message
);
116 void add_security_log_handler(security_log_handler handler
);
117 void remove_security_log_handler(security_log_handler handler
);
119 /* To simulate a process crash in some conditions */
120 void __security_simulatecrash(CFStringRef reason
, uint32_t code
);
122 /* predefined simulate crash exception codes */
123 #define __sec_exception_code(x) (0x53c00000+x)
124 #define __sec_exception_code_CorruptDb(db,rc) __sec_exception_code(1|((db)<<8)|((rc)<<16))
125 #define __sec_exception_code_CorruptItem __sec_exception_code(2)
126 #define __sec_exception_code_OTRError __sec_exception_code(3)
127 #define __sec_exception_code_DbItemDescribe __sec_exception_code(4)
128 #define __sec_exception_code_TwiceCorruptDb(db) __sec_exception_code(5|((db)<<8))
130 /* Logging control functions */
133 kScopeIDEnvironment
= 0,
134 kScopeIDDefaults
= 1,
140 void ApplyScopeListForID(CFStringRef scopeList
, SecDebugScopeID whichID
);
141 void ApplyScopeDictionaryForID(CFDictionaryRef scopeList
, SecDebugScopeID whichID
);
142 CFPropertyListRef
CopyCurrentScopePlist(void);
148 #endif /* _SECURITY_UTILITIES_DEBUGGING_H_ */