Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Injectable monitors #496

Merged
merged 59 commits into from
Jun 16, 2024
Merged

Injectable monitors #496

merged 59 commits into from
Jun 16, 2024

Conversation

GLinnik21
Copy link
Collaborator

No description provided.

@GLinnik21 GLinnik21 linked an issue Jun 5, 2024 that may be closed by this pull request
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Moved the base monitor system to RecordingCore. Any other module can now inject monitors here with the desired functionality. Since we cannot use bit options in this case, I switched to using a C-string name to distinguish between monitors. Additionally, I introduced monitor properties because previously the base monitor system used monitor types (essentially names) to determine its behavior during exception handling. Now, any monitor can utilize these properties, for instance, by marking itself as a fatal monitor to indicate that if it is triggered, the process can no longer continue to operate.

Comment on lines 60 to 68
void kscm_activateMonitors(void);

void kscm_disableAllMonitors(void);

/** Get the currently active monitors.
*/
KSCrashMonitorType kscm_getActiveMonitors(void);
//KSCrashMonitorType kscm_getActiveMonitors(void);

void kscm_addMonitor(KSCrashMonitorAPI* api);
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We're transitioning to a new installation process. Upon reviewing the code, I noticed that KSCrash internally only activated monitors during installation and used kscm_setActiveMonitors with 0 in other places (effectively disabling them). With the new injection mechanism, I've changed to a two-stage process: first adding monitors, and then activating all of them. I also introduced a "killswitch," kscm_disableAllMonitors, to disable everything during exception handling. To streamline things, I replaced the KSCrashMonitorType defined in the public API with raw KSCrashMonitorAPI pointers and implemented this mapping in the Recording module. Because of this change, I commented out kscm_getActiveMonitors, as returning an array of raw pointers seemed like poor design and I wanted to avoid any mappings to keep things simple. This function is no longer needed internally, but we might come up with a better design and reintroduce it later.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe instead we should introduce a kscm_isMonitorActive(KSCrashMonitorAPI* api). But I agree, it's not a requirement now.

Copy link
Collaborator Author

@GLinnik21 GLinnik21 Jun 16, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually, you can get it just from the KSCrashMonitorAPI* you pass.

kscm_isMonitorEnabled(api);

#pragma mark - Globals -
// ============================================================================

static MonitorList g_monitors = {};
Copy link
Collaborator Author

@GLinnik21 GLinnik21 Jun 10, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am not sure if we need to synchronise here, as we could potentially get a deadlock.

Copy link
Collaborator Author

@GLinnik21 GLinnik21 Jun 10, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@naftaly, any ideas here? Should I use atomics instead?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, but in case of a crash in the synchronized code here, we can get a deadlock, as this code should also handle SINGAL or Mach crash of KSCrash. So I'm thinking of atomic operations here, but it gets complicated with structs

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One of the options is to skip the crash if something updates monitors. E.g. if it's a lock we can add "if locked – exit". This kinda makes sense as if something crashes while KSCrash is being setup it's reasonable to ignore such crash.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🤔

@GLinnik21 GLinnik21 marked this pull request as ready for review June 10, 2024 13:12
Sources/KSCrashBootTimeMonitor/KSCrashMonitor_BootTime.m Outdated Show resolved Hide resolved
Sources/KSCrashRecording/KSCrashC.c Outdated Show resolved Hide resolved
Sources/KSCrashRecordingCore/include/KSCrashMonitor.h Outdated Show resolved Hide resolved
Sources/KSCrashRecording/KSCrashReport.c Outdated Show resolved Hide resolved
}
else
{
KSLOG_ERROR("Unknown crash monitor type: %s", crash->monitorName);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(not for this PR, but) I'm wondering if this logic can be also put into monitors. As if I want to create my own type of crashes, I might need to change logic here.

Sources/KSCrashRecordingCore/KSCrashMonitor.c Outdated Show resolved Hide resolved
Sources/KSCrashRecordingCore/KSCrashMonitor.c Outdated Show resolved Hide resolved
Sources/KSCrashRecording/Monitors/KSCrashMonitor_Signal.c Outdated Show resolved Hide resolved
Repository owner deleted a comment from bamx23 Jun 15, 2024
Repository owner deleted a comment from bamx23 Jun 15, 2024
Copy link
Collaborator

@bamx23 bamx23 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for addressing all the comments. This new API looks really nice and flexible.

Would be great to update instructions in README to highlight this new modular monitoring approach (at least mentioning these two new sub-libs). But can be done later.

Sources/KSCrashRecording/KSCrashReport.c Outdated Show resolved Hide resolved
Sources/KSCrashRecordingCore/KSCrashMonitor.c Outdated Show resolved Hide resolved
Sources/KSCrashRecording/KSCrash.m Show resolved Hide resolved
Comment on lines 60 to 68
void kscm_activateMonitors(void);

void kscm_disableAllMonitors(void);

/** Get the currently active monitors.
*/
KSCrashMonitorType kscm_getActiveMonitors(void);
//KSCrashMonitorType kscm_getActiveMonitors(void);

void kscm_addMonitor(KSCrashMonitorAPI* api);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe instead we should introduce a kscm_isMonitorActive(KSCrashMonitorAPI* api). But I agree, it's not a requirement now.

Sources/KSCrashRecordingCore/include/KSCrashMonitor.h Outdated Show resolved Hide resolved
Sources/KSCrashRecording/KSCrashReport.c Outdated Show resolved Hide resolved
@GLinnik21 GLinnik21 merged commit 4b2360f into master Jun 16, 2024
19 checks passed
@GLinnik21 GLinnik21 deleted the injectable-monitors branch June 16, 2024 22:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Discussion on Implementing Opt-Out Mechanism for NSFileSystemSize
2 participants