[PLAT-6113] Fix possible deadlock in bsg_ksmachfreeMemory #1013
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Goal
Fixes a deadlock that can occur because the implementation of
__builtin_available()
usesmalloc()
and is therefore not async-signal-safe.This was observed when investigating potential causes of deadlocks in the crash handling code.
Design / Changeset
The availability of
os_proc_available_memory()
is now determined at initialization time rather than in the implementation ofbsg_ksmachfreeMemory()
A function pointer is used to avoid the need for
#pragma clang diagnostic
statements inbsg_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.