Skip to content

signal handlers not async signal safe

Summary

Signal handlers are highly constrained in what functions they can call. In particular, they can't malloc or free because mutexes in glibc may already be held by the interrupted thread, resulting in a deadlock. See https://man7.org/linux/man-pages/man7/signal-safety.7.html.

Our signal handlers (in Signals.c) end up calling fprintf and vfprintf in at least rtsSysErrorMsgFn and the libdw backtrace code. I think in practice this is fine, so long as you don't try to format floats.

Chromium have a BSD-ish licensed safe_sprintf in C++ here: https://chromium.googlesource.com/chromium/src/base/+/master/strings/safe_sprintf.h

I understand mysql has one too, but I haven't looked for it.

EDIT: On further investigation, the dwarf backtrace (in Libdw.c) code calls malloc/free. I haven't investigated whether libdw call's malloc internally.

Environment

  • GHC version used: master

Optional:

  • Operating System: Linux
  • System Architecture:
Edited by Douglas Wilson
To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information