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

Calling malloc from signal handler #181

Open
nathanwbrei opened this issue Dec 19, 2022 · 1 comment
Open

Calling malloc from signal handler #181

nathanwbrei opened this issue Dec 19, 2022 · 1 comment

Comments

@nathanwbrei
Copy link
Collaborator

Signal handler is calling malloc. Signal handlers should avoid all non-async-signal-safe (approx the same thing as non-reentrant) syscalls as per https://man7.org/linux/man-pages/man7/signal-safety.7.html. That includes malloc and all IO.

If the segfault corrupts malloc itself, such as here (eic/EICrecon#402), we lose the backtrace.

The solution is to pre-allocate a buffer for the backtrace instead.

@nathanwbrei
Copy link
Collaborator Author

As of #385, we pre-allocate buffers for the backtrace. We also move symbol lookup and demangling to the supervisor thread. The system seems robust in practice, and TSAN is down to exactly one complaint, about backtrace() itself calling malloc. It turns out this is an easy fix: As per the backtrace(3) man page, the malloc() call happens during dynamic library loading. We only need to ensure that the library is loaded before any signal handlers are invoked.

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

No branches or pull requests

1 participant