]> git.sesse.net Git - casparcg/blob - common/os/linux/signal_handlers.cpp
* Working server startup in Linux
[casparcg] / common / os / linux / signal_handlers.cpp
1 #include "../general_protection_fault.h"
2
3 #include "../../except.h"
4
5 #include <signal.h>
6
7 namespace caspar {
8
9 struct floating_point_exception : virtual caspar_exception {};
10 struct segmentation_fault_exception : virtual caspar_exception {};
11
12 void catch_fpe(int signum)
13 {
14         CASPAR_THROW_EXCEPTION(floating_point_exception());
15 }
16
17 void catch_segv(int signum)
18 {
19         CASPAR_THROW_EXCEPTION(segmentation_fault_exception());
20 }
21
22 void do_install_handlers()
23 {
24         signal(SIGFPE, catch_fpe);
25         signal(SIGSEGV, catch_segv);
26 }
27
28 void install_gpf_handler()
29 {
30         ensure_gpf_handler_installed_for_thread();
31 }
32
33 void ensure_gpf_handler_installed_for_thread(
34                 const char* thread_description)
35 {
36         static auto install = []() { do_install_handlers(); return 0; } ();
37 }
38
39 }