#ifndef _SECURITY_UTILITIES_DEBUGGING_H_
#define _SECURITY_UTILITIES_DEBUGGING_H_
#include <TargetConditionals.h>
#ifdef KERNEL
#include <libkern/libkern.h>
#define secalert(format, ...) printf((format), ## __VA_ARGS__)
#define secemergency(format, ...) printf((format), ## __VA_ARGS__)
#define seccritical(format, ...) printf((format), ## __VA_ARGS__)
#define secerror(format, ...) printf((format), ## __VA_ARGS__)
#define secwarning(format, ...) printf((format), ## __VA_ARGS__)
#define secnotice(scope, format, ...) printf((format), ## __VA_ARGS__)
#define secnoticeq(scope, format, ...) printf((format), ## __VA_ARGS__)
#define secinfo(scope, format, ...) printf((format), ## __VA_ARGS__)
#undef secdebug
#if !defined(NDEBUG)
#define secdebug(scope, format, ...) printf((format), ## __VA_ARGS__)
#else #define secdebug(scope, format, ...)
#endif #else // !KERNEL
#include <CoreFoundation/CFString.h>
#include <asl.h>
__BEGIN_DECLS
#define SECLOG_LEVEL_EMERG 0
#define SECLOG_LEVEL_ALERT 1
#define SECLOG_LEVEL_CRIT 2
#define SECLOG_LEVEL_ERR 3
#define SECLOG_LEVEL_WARNING 4
#define SECLOG_LEVEL_NOTICE 5
#define SECLOG_LEVEL_INFO 6
#define SECLOG_LEVEL_DEBUG 7
#include <os/log_private.h>
extern os_log_t secLogObjForScope(const char *scope);
extern os_log_t secLogObjForCFScope(CFStringRef scope);
extern bool secLogEnabled(void);
extern void secLogDisable(void);
extern void secLogEnable(void);
#if TARGET_OS_OSX
void weak_os_log_impl(void *dso, os_log_t log, os_log_type_t type, const char *format, uint8_t *buf, unsigned int size);
os_log_t weak_os_log_create(const char *subsystem, const char *category);
bool weak_os_log_type_enabled(os_log_t oslog, os_log_type_t type);
#endif // TARGET_OS_OSX
CFStringRef SecLogAPICreate(bool apiIn, const char *api, CFStringRef format, ...)
CF_FORMAT_FUNCTION(3, 4);
extern const char *api_trace;
#define sec_trace_enter_api(format...) { \
CFStringRef info = SecLogAPICreate(true, __FUNCTION__, format, NULL); \
secinfo(api_trace, "%@", info); CFReleaseNull(info); \
}
#define sec_trace_return_api(rtype, body, format...) { \
rtype _r = body(); \
CFStringRef info = SecLogAPICreate(true, __FUNCTION__, format, _r); \
secinfo(api_trace, "%@", info); \
CFReleaseNull(info); return _r; \
}
#define sec_trace_return_bool_api(body, format...) { \
bool _r = body(); \
CFStringRef info = SecLogAPICreate(true, __FUNCTION__, format ? format : CFSTR("return=%d"), _r); \
secinfo(api_trace, "%@", info); \
CFReleaseNull(info); return _r; \
}
#define secemergency(format, ...) os_log_error(secLogObjForScope("SecEmergency"), format, ## __VA_ARGS__)
#define secalert(format, ...) os_log_error(secLogObjForScope("SecAlert"), format, ## __VA_ARGS__)
#define seccritical(format, ...) os_log(secLogObjForScope("SecCritical"), format, ## __VA_ARGS__)
#define secerror(format, ...) os_log(secLogObjForScope("SecError"), format, ## __VA_ARGS__)
#define secerrorq(format, ...) os_log(secLogObjForScope("SecError"), format, ## __VA_ARGS__)
#define secwarning(format, ...) os_log(secLogObjForScope("SecWarning"), format, ## __VA_ARGS__)
#define secnotice(scope, format, ...) os_log(secLogObjForScope(scope), format, ## __VA_ARGS__)
#define secnoticeq(scope, format, ...) os_log(secLogObjForScope(scope), format, ## __VA_ARGS__)
#define secinfo(scope, format, ...) os_log_debug(secLogObjForScope(scope), format, ## __VA_ARGS__)
#define secinfoenabled(scope) os_log_debug_enabled(secLogObjForScope(scope))
#undef secdebug
#if !defined(NDEBUG)
#define secdebug(scope, format, ...) os_log_debug(secLogObjForScope(scope), format, ## __VA_ARGS__)
#else
# define secdebug(scope,...)
#endif
typedef void (^security_log_handler)(int level, CFStringRef scope, const char *function,
const char *file, int line, CFStringRef message);
void __security_simulatecrash(CFStringRef reason, uint32_t code);
void __security_stackshotreport(CFStringRef reason, uint32_t code);
#define __sec_exception_code(x) (0x53c00000+x)
#define __sec_exception_code_CorruptItem __sec_exception_code(2)
#define __sec_exception_code_OTRError __sec_exception_code(3)
#define __sec_exception_code_DbItemDescribe __sec_exception_code(4)
#define __sec_exception_code_TwiceCorruptDb(db) __sec_exception_code(5|((db)<<8))
#define __sec_exception_code_AuthLoop __sec_exception_code(6)
#define __sec_exception_code_MissingEntitlements __sec_exception_code(7)
#define __sec_exception_code_LostInMist __sec_exception_code(8)
#define __sec_exception_code_CKD_nil_pending_keys __sec_exception_code(9)
#define __sec_exception_code_SQLiteBusy __sec_exception_code(10)
#define __sec_exception_code_CorruptDb(rc) __sec_exception_code(11|((rc)<<8))
#define __sec_exception_code_Watchdog __sec_exception_code(12)
int __security_simulatecrash_enable(bool enable);
typedef enum {
kScopeIDEnvironment = 0,
kScopeIDDefaults = 1,
kScopeIDConfig = 2,
kScopeIDXPC = 3,
kScopeIDCircle = 4,
kScopeIDMax = 4,
} SecDebugScopeID;
void ApplyScopeListForID(CFStringRef scopeList, SecDebugScopeID whichID);
void ApplyScopeDictionaryForID(CFDictionaryRef scopeList, SecDebugScopeID whichID);
CFPropertyListRef CopyCurrentScopePlist(void);
__END_DECLS
#endif // !KERNEL
#endif