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

SigBusGuard: SIBGUS handler class #278

Merged
merged 2 commits into from Dec 16, 2022
Merged

SigBusGuard: SIBGUS handler class #278

merged 2 commits into from Dec 16, 2022

Conversation

tswilliams
Copy link
Collaborator

@tswilliams tswilliams commented Dec 15, 2022

The SIGBUS signal can be received when errors occur during reads/writes from mmap'ed device files. This branch adds the SigBusGuard class, which implements a signal handler that will throw a SigBusError exception whenever SIGBUS is received. The ipbusmmap-2.0 client was also updated to protect against SIGBUS with this class.

Intended usage: An instance of SigBusGuard class should be created before any set of reads/writes from the mmap'ed device file, and the reads/writes themselves should be implemented in a std::function/lambda that's passed to the protect method, along with a message which will be used for the exception that's thrown. I.e:

uhal::SigBusGuard guard;
guard.protect([&]{
  // Put mmap'ed device file reads/writes here
}, "An error occurred when reading from address 0x... in file ...");

Note: The SIGBUS signal handler is only defined for the lifetime of the SigBusGuard instance, and to ensure the the signals are handled by the appropriate thread a static mutex is is locked in the SigBusGuard contructor and unlocked in the destructor. As a result only one SigBusGuard instance can be alive at any given time, and so a deadlock will occur if e.g. the user were to attempt to create multiple instances in a single function, e.g:

uhal::SigBusGuard guard1;
uhal::SigBusGuard guard2;
// Execution would get stuck on the line above; code below this line would never be reached

@tswilliams tswilliams merged commit 4522ea2 into master Dec 16, 2022
@tswilliams tswilliams deleted the feature/sigbus-guard branch December 16, 2022 10:57
@tswilliams tswilliams added this to the v2.8.5 release milestone Jan 3, 2023
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.

None yet

1 participant