analyzer icon indicating copy to clipboard operation
analyzer copied to clipboard

Support for `atexit`, `on_exit` and `pthread_cleanup_*` handlers

Open michael-schwarz opened this issue 3 years ago • 2 comments

Those are features we currently do not support yet, but it might be interesting to do so.

michael-schwarz avatar Jul 28 '22 09:07 michael-schwarz

While looking at Concrat again, I found out that pthread_cleanup_push is a macro which doesn't actually store the cleanup routine is some magic place, but implements it using some flavor of setjmp. It's just that the longjmp isn't explicit, rather but that's what pthread does magically with __pthread_register_cancel.

Perhaps it's possible to handle __pthread_register_cancel specially as triggering a longjmp and unwinding the stack. Actually the longjmp can happen anywhere in a nested function call, but maybe that doesn't really matter? What's important is that there is something which unwinds the stack back.

sim642 avatar Jan 02 '25 14:01 sim642

I learned today that GCC/Clang also have a __cleanup__ attribute which gives C++ RAII-like features in C. And it's starting to be used in the Linux kernel: https://lwn.net/Articles/934679/. It's more fine-grained than the functions listed in the issue (and requires block scope support!), but might become relevant if we try to analyze the modern kernel. Not handling them could easily make us very unsound: we just ignore the attribute and perhaps never consider some mutexes unlocked.

sim642 avatar Oct 19 '25 17:10 sim642