forked from kstenerud/KSCrash
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Basic implementation of injection and new property system * Basic implementation of the new system for CPP monitor * Implement for Deadlock monitor * Implement for Mach monitor * Implement for Memory monitor * Implement for NSException * Add missing property to Mach monitor * Implement for Signal monitor * Implement for System monitor * Implement for User monitor * Implement for Zombie * Add name to AppState * Create helper for MonitorAPI with inline functions * Use new helper * Update C facade with the new injection mechanism * Create DiscSpace monitor * Add boot time monitor * return `kscm_setEventCallback` back * Fix monitors logic * Add privacy manifest for Disc Space * Add privacy manifest for Boot Time * Update Podspec with the new modules * Fix declaration of functions in KSCrashMonitor * Fix typos * Fix podspec linting issues * Fix forward declaration issue * Fix imports for new monitors * Add new schemes * Fix build for WatchOS * Remove constant pointer in `name` in Monitor API * Move MachineContext test to its own Case * Add KSCrashMonitor tests * Add some tests and sort * Make AppState Monitor compilable * Fix compilation * Temporary fixed Memory Monitor Tests * Try to introduce deduplication * Add KSCrashMonitor_BootTime_Tests * Add KSCrashMonitor_DiscSpace_Tests * Return documentation to KSCrashMonitorType * Remove privacy-related APIs from KSCrash API * Add some documentation * Follow the current style in files headers * Uddate KSCrashReport logic * rename name to monitorId * Address small changes to KSCrashMonitor * Raname monitorId in CrashContext * Rename monitorFlags in Crash Context * Address Monitor Context filling * Deduplicate APIs with monitorId * Rename to monitorFlags * Support monitor removing * Move `safeStrcmp` to `KSString` * Shorten monitor names for optimisation * Add `static` to `ksmc_fillMonitorContext` * Return NULL if monitor is not supported on platform * setMonitors prior to install in Tests * Return optional fields in `systemInfo` * Address issues from PR
- Loading branch information
Showing
41 changed files
with
2,083 additions
and
607 deletions.
There are no files selected for viewing
67 changes: 67 additions & 0 deletions
67
.swiftpm/xcode/xcshareddata/xcschemes/BootTimeMonitor.xcscheme
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<Scheme | ||
LastUpgradeVersion = "1530" | ||
version = "1.7"> | ||
<BuildAction | ||
parallelizeBuildables = "YES" | ||
buildImplicitDependencies = "YES" | ||
buildArchitectures = "Automatic"> | ||
<BuildActionEntries> | ||
<BuildActionEntry | ||
buildForTesting = "YES" | ||
buildForRunning = "YES" | ||
buildForProfiling = "YES" | ||
buildForArchiving = "YES" | ||
buildForAnalyzing = "YES"> | ||
<BuildableReference | ||
BuildableIdentifier = "primary" | ||
BlueprintIdentifier = "BootTimeMonitor" | ||
BuildableName = "BootTimeMonitor" | ||
BlueprintName = "BootTimeMonitor" | ||
ReferencedContainer = "container:"> | ||
</BuildableReference> | ||
</BuildActionEntry> | ||
</BuildActionEntries> | ||
</BuildAction> | ||
<TestAction | ||
buildConfiguration = "Debug" | ||
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB" | ||
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB" | ||
shouldUseLaunchSchemeArgsEnv = "YES" | ||
shouldAutocreateTestPlan = "YES"> | ||
</TestAction> | ||
<LaunchAction | ||
buildConfiguration = "Debug" | ||
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB" | ||
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB" | ||
launchStyle = "0" | ||
useCustomWorkingDirectory = "NO" | ||
ignoresPersistentStateOnLaunch = "NO" | ||
debugDocumentVersioning = "YES" | ||
debugServiceExtension = "internal" | ||
allowLocationSimulation = "YES"> | ||
</LaunchAction> | ||
<ProfileAction | ||
buildConfiguration = "Release" | ||
shouldUseLaunchSchemeArgsEnv = "YES" | ||
savedToolIdentifier = "" | ||
useCustomWorkingDirectory = "NO" | ||
debugDocumentVersioning = "YES"> | ||
<MacroExpansion> | ||
<BuildableReference | ||
BuildableIdentifier = "primary" | ||
BlueprintIdentifier = "BootTimeMonitor" | ||
BuildableName = "BootTimeMonitor" | ||
BlueprintName = "BootTimeMonitor" | ||
ReferencedContainer = "container:"> | ||
</BuildableReference> | ||
</MacroExpansion> | ||
</ProfileAction> | ||
<AnalyzeAction | ||
buildConfiguration = "Debug"> | ||
</AnalyzeAction> | ||
<ArchiveAction | ||
buildConfiguration = "Release" | ||
revealArchiveInOrganizer = "YES"> | ||
</ArchiveAction> | ||
</Scheme> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
104 changes: 104 additions & 0 deletions
104
Sources/KSCrashBootTimeMonitor/KSCrashMonitor_BootTime.m
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,104 @@ | ||
// | ||
// KSCrashMonitor_BootTime.c | ||
// | ||
// Created by Gleb Linnik on 04.06.2024. | ||
// | ||
// Copyright (c) 2012 Karl Stenerud. All rights reserved. | ||
// | ||
// Permission is hereby granted, free of charge, to any person obtaining a copy | ||
// of this software and associated documentation files (the "Software"), to deal | ||
// in the Software without restriction, including without limitation the rights | ||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
// copies of the Software, and to permit persons to whom the Software is | ||
// furnished to do so, subject to the following conditions: | ||
// | ||
// The above copyright notice and this permission notice shall remain in place | ||
// in this source code. | ||
// | ||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | ||
// THE SOFTWARE. | ||
// | ||
|
||
#import "KSCrashMonitor_BootTime.h" | ||
|
||
#import "KSCrashMonitorContext.h" | ||
#import "KSSysCtl.h" | ||
#import "KSDate.h" | ||
|
||
#import <sys/types.h> | ||
#import <Foundation/Foundation.h> | ||
|
||
static volatile bool g_isEnabled = false; | ||
|
||
__attribute__((unused)) // For tests. Declared as extern in TestCase | ||
void kscm_bootTime_resetState(void) | ||
{ | ||
g_isEnabled = false; | ||
} | ||
|
||
/** Get a sysctl value as an NSDate. | ||
* | ||
* @param name The sysctl name. | ||
* | ||
* @return The result of the sysctl call. | ||
*/ | ||
static const char* dateSysctl(const char* name) | ||
{ | ||
struct timeval value = kssysctl_timevalForName(name); | ||
char* buffer = malloc(21); | ||
ksdate_utcStringFromTimestamp(value.tv_sec, buffer); | ||
return buffer; | ||
} | ||
|
||
#pragma mark - API - | ||
|
||
static const char* monitorId(void) | ||
{ | ||
return "BootTime"; | ||
} | ||
|
||
static void setEnabled(bool isEnabled) | ||
{ | ||
if(isEnabled != g_isEnabled) | ||
{ | ||
g_isEnabled = isEnabled; | ||
} | ||
} | ||
|
||
static bool isEnabled(void) | ||
{ | ||
return g_isEnabled; | ||
} | ||
|
||
static void addContextualInfoToEvent(KSCrash_MonitorContext* eventContext) | ||
{ | ||
if(g_isEnabled) | ||
{ | ||
eventContext->System.bootTime = dateSysctl("kern.boottime"); | ||
} | ||
} | ||
|
||
KSCrashMonitorAPI* kscm_boottime_getAPI(void) | ||
{ | ||
static KSCrashMonitorAPI api = | ||
{ | ||
.monitorId = monitorId, | ||
.setEnabled = setEnabled, | ||
.isEnabled = isEnabled, | ||
.addContextualInfoToEvent = addContextualInfoToEvent | ||
}; | ||
return &api; | ||
} | ||
|
||
#pragma mark - Injection - | ||
|
||
__attribute__((constructor)) | ||
static void kscm_boottime_register(void) | ||
{ | ||
kscm_addMonitor(kscm_boottime_getAPI()); | ||
} |
36 changes: 36 additions & 0 deletions
36
Sources/KSCrashBootTimeMonitor/Resources/PrivacyInfo.xcprivacy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> | ||
<plist version="1.0"> | ||
<dict> | ||
<key>NSPrivacyTracking</key> | ||
<false/> | ||
<key>NSPrivacyTrackingDomains</key> | ||
<array/> | ||
<key>NSPrivacyCollectedDataTypes</key> | ||
<array> | ||
<dict> | ||
<key>NSPrivacyCollectedDataType</key> | ||
<string>NSPrivacyCollectedDataTypeOtherDiagnosticData</string> | ||
<key>NSPrivacyCollectedDataTypeLinked</key> | ||
<false/> | ||
<key>NSPrivacyCollectedDataTypeTracking</key> | ||
<false/> | ||
<key>NSPrivacyCollectedDataTypePurposes</key> | ||
<array> | ||
<string>NSPrivacyCollectedDataTypePurposeAppFunctionality</string> | ||
</array> | ||
</dict> | ||
</array> | ||
<key>NSPrivacyAccessedAPITypes</key> | ||
<array> | ||
<dict> | ||
<key>NSPrivacyAccessedAPIType</key> | ||
<string>NSPrivacyAccessedAPICategorySystemBootTime</string> | ||
<key>NSPrivacyAccessedAPITypeReasons</key> | ||
<array> | ||
<string>3D61.1</string> | ||
</array> | ||
</dict> | ||
</array> | ||
</dict> | ||
</plist> |
45 changes: 45 additions & 0 deletions
45
Sources/KSCrashBootTimeMonitor/include/KSCrashMonitor_BootTime.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
// | ||
// KSCrashMonitor_BootTime.h | ||
// | ||
// Created by Gleb Linnik on 04.06.2024. | ||
// | ||
// Copyright (c) 2012 Karl Stenerud. All rights reserved. | ||
// | ||
// Permission is hereby granted, free of charge, to any person obtaining a copy | ||
// of this software and associated documentation files (the "Software"), to deal | ||
// in the Software without restriction, including without limitation the rights | ||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
// copies of the Software, and to permit persons to whom the Software is | ||
// furnished to do so, subject to the following conditions: | ||
// | ||
// The above copyright notice and this permission notice shall remain in place | ||
// in this source code. | ||
// | ||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | ||
// THE SOFTWARE. | ||
// | ||
|
||
|
||
#ifndef KSCrashMonitor_BootTime_h | ||
#define KSCrashMonitor_BootTime_h | ||
|
||
#include "KSCrashMonitor.h" | ||
|
||
#ifdef __cplusplus | ||
extern "C" { | ||
#endif | ||
|
||
/** Access the Monitor API. | ||
*/ | ||
KSCrashMonitorAPI* kscm_boottime_getAPI(void); | ||
|
||
#ifdef __cplusplus | ||
} | ||
#endif | ||
|
||
#endif /* KSCrashMonitor_BootTime_h */ |
Oops, something went wrong.