3 ms·
Switching to memory safe languages would not necessarily prevent this issue because this is an undefined behavior issue, not a memory safety issue. Pointers to
by ryao 2y ago
Switching to memory safe languages would not necessarily prevent this issue because this is an undefined behavior issue, not a memory safety issue.
Pointers to C++ functions that can throw exceptions should not be passed to C functions as callback pointers. Executing the exception in the callback context is undefined behavior, since C does not support stack unwinding.
Presumably, any language that has exception handling would have an issue on Windows when doing select() in one thread and QueueUserAPC() in another thread to interrupt it with a callback function that throws an exception. What happens then depends on how the stack unwinding works.
No programming language can avoid this because they need to use the underlying operating system's system calls in order to function. They also need to use the C functions in ntdll to do system calls since Microsoft does not support doing system calls outside of calling the corresponding functions in ntdll and friends.