#ifndef _SECURITY_UTILITIES_DEBUGGING_H_
#define _SECURITY_UTILITIES_DEBUGGING_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 secinfo(scope, format, ...) printf((format), ## __VA_ARGS__)
#if !defined(NDEBUG)
#define secdebug(scope, format, ...) printf((format), ## __VA_ARGS__)
#else #define secdebug(scope, format, ...)
#endif #else // !KERNEL
#include <TargetConditionals.h>
#include <CoreFoundation/CFString.h>
#include <asl.h>
__BEGIN_DECLS
extern void __security_trace_enter_api(const char *api, CFStringRef format, ...) CF_FORMAT_FUNCTION(2, 3);
extern void __security_trace_return_api(const char *api, CFStringRef format, ...) CF_FORMAT_FUNCTION(2, 3);
extern void __security_debug(CFStringRef scope,
const char *function, const char *file, int line,
CFStringRef format, ...) CF_FORMAT_FUNCTION(5,6);
extern void __security_log(const char *level, CFStringRef scope,
const char *function, const char *file, int line,
CFStringRef format, ...) CF_FORMAT_FUNCTION(6,7);
#define sec_trace_enter_api(format...) __security_trace_enter_api(__FUNCTION__, format)
#define sec_trace_return_api(rtype, body, format...) { rtype _r = body(); __security_trace_return_api(__FUNCTION__, format, _r); return _r; }
#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; }
#define secemergency(format, ...) __security_log(ASL_STRING_EMERG, NULL, \
__FUNCTION__, __FILE__, __LINE__, \
CFSTR(format), ## __VA_ARGS__)
#define secalert(format, ...) __security_log(ASL_STRING_ALERT, NULL, \
__FUNCTION__, __FILE__, __LINE__, \
CFSTR(format), ## __VA_ARGS__)
#define seccritical(format, ...) __security_log(ASL_STRING_CRIT, NULL, \
__FUNCTION__, __FILE__, __LINE__, \
CFSTR(format), ## __VA_ARGS__)
#define secerror(format, ...) __security_log(ASL_STRING_ERR, NULL, \
__FUNCTION__, __FILE__, __LINE__, \
CFSTR(format), ## __VA_ARGS__)
#define secwarning(format, ...) __security_log(ASL_STRING_WARNING, NULL, \
__FUNCTION__, __FILE__, __LINE__, \
CFSTR(format), ## __VA_ARGS__)
#define secnotice(scope, format, ...) __security_log(ASL_STRING_NOTICE, CFSTR(scope), \
__FUNCTION__, __FILE__, __LINE__, \
CFSTR(format), ## __VA_ARGS__)
#define secinfo(scope, format, ...) __security_log(ASL_STRING_INFO, CFSTR(scope), \
__FUNCTION__, __FILE__, __LINE__, \
CFSTR(format), ## __VA_ARGS__)
#if !defined(NDEBUG)
# define secdebug(scope,format, ...) __security_debug(CFSTR(scope), \
__FUNCTION__, __FILE__, __LINE__, \
CFSTR(format), ## __VA_ARGS__)
#else
# define secdebug(scope,...)
#endif
typedef void (^security_log_handler)(const char *level, CFStringRef scope, const char *function,
const char *file, int line, CFStringRef message);
void add_security_log_hanlder(security_log_handler handler);
void __security_simulatecrash(CFStringRef reason, uint32_t code);
#define __sec_exception_code(x) (0x53c00000+x)
#define __sec_exception_code_CorruptDb(db,rc) __sec_exception_code(1|((db)<<8)|((rc)<<16))
#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))
__END_DECLS
#endif // !KERNEL
#endif