5 // Copyright (c) 2014 Apple Inc. All Rights Reserved.
11 #import <SoftLinking/SoftLinking.h>
12 #import <Foundation/Foundation.h>
14 SOFT_LINK_FRAMEWORK_SAFE(PrivateFrameworks, CrashReporterSupport);
16 SOFT_LINK_FUNCTION(CrashReporterSupport, SimulateCrash, soft_SimulateCrash, \
17 BOOL, (pid_t pid, mach_exception_data_type_t exceptionCode, NSString *description),
18 (pid, exceptionCode, description));
19 SOFT_LINK_FUNCTION(CrashReporterSupport, WriteStackshotReport, soft_WriteStackshotReport, \
20 BOOL, (NSString *reason, mach_exception_data_type_t exceptionCode),
21 (reason, exceptionCode));
23 static int __simulate_crash_counter = -1;
25 void __security_simulatecrash(CFStringRef reason, uint32_t code)
27 secerror("Simulating crash, reason: %@, code=%08x", reason, code);
28 if (__security_simulatecrash_enabled() && isCrashReporterSupportAvailable()) {
29 soft_SimulateCrash(getpid(), code, (__bridge NSString *)reason);
31 __simulate_crash_counter++;
35 void __security_stackshotreport(CFStringRef reason, uint32_t code)
37 secerror("stackshot report, reason: %@, code=%08x", reason, code);
38 if (!__security_simulatecrash_enabled() && isCrashReporterSupportAvailable()) {
41 if (isCrashReporterSupportAvailable()) {
42 soft_WriteStackshotReport((__bridge NSString *)reason, code);
47 int __security_simulatecrash_enable(bool enable)
49 int count = __simulate_crash_counter;
50 __simulate_crash_counter = enable ? -1 : 0;
54 bool __security_simulatecrash_enabled(void)
56 return __simulate_crash_counter == -1;