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

[PLAT-6113] Fix possible deadlock in bsg_ksmachfreeMemory #1013

Merged
merged 2 commits into from
Feb 25, 2021

Conversation

nickdowell
Copy link
Contributor

@nickdowell nickdowell commented Feb 25, 2021

Goal

Fixes a deadlock that can occur because the implementation of __builtin_available() uses malloc() and is therefore not async-signal-safe.

This was observed when investigating potential causes of deadlocks in the crash handling code.

Screenshot 2021-02-22 at 16 38 27

Design / Changeset

The availability of os_proc_available_memory() is now determined at initialization time rather than in the implementation of bsg_ksmachfreeMemory()

A function pointer is used to avoid the need for #pragma clang diagnostic statements in bsg_ksmachfreeMemory()

Testing

Manually verified by running example apps and adding log statements to confirm that os_proc_available_memory() is used on the relevant platforms.

Added an E2E scenario that could consistently produce a deadlock in bsg_ksmachfreeMemory() prior to the fix, and confirmed that it passes with the fix in place.

@nickdowell nickdowell changed the title Nickdowell/fix ksmach free memory deadlock [PLAT-6113] Fix possible deadlock in bsg_ksmachfreeMemory Feb 25, 2021
@github-actions
Copy link

Infer: No issues found 🎉

OCLint: No issues found 🎉

Bugsnag.framework binary size increased by 104 bytes from 1,061,720 to 1,061,824

Generated by 🚫 Danger

@nickdowell nickdowell force-pushed the nickdowell/fix-ksmach-free-memory-deadlock branch from e374fd8 to 7888a24 Compare February 25, 2021 10:11
@nickdowell nickdowell marked this pull request as ready for review February 25, 2021 10:51
Copy link
Contributor

@kattrali kattrali left a comment

Choose a reason for hiding this comment

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

nicely done 🎉

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.

2 participants