Skip to content

Commit

Permalink
xrCore: implement linux process naming and signal handling
Browse files Browse the repository at this point in the history
  • Loading branch information
eagleivg committed Oct 11, 2018
1 parent e51ed07 commit 13d0b2c
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
9 changes: 7 additions & 2 deletions src/xrCore/_math.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
#include <pthread.h>
#include <sys/time.h>
#include <sys/resource.h>
#include <sys/prctl.h>
#include <chrono>
#endif
#include <thread>
Expand Down Expand Up @@ -333,19 +334,23 @@ struct THREAD_NAME

void thread_name(const char* name)
{
Msg("start new thread [%s]", name);
#if defined(WINDOWS)
THREAD_NAME tn;
tn.dwType = 0x1000;
tn.szName = name;
tn.dwThreadID = DWORD(-1);
tn.dwFlags = 0;
#if defined(WINDOWS)

__try
{
RaiseException(0x406D1388, 0, sizeof(tn) / sizeof(DWORD), (ULONG_PTR*)&tn);
}
__except (EXCEPTION_CONTINUE_EXECUTION)
{
}
#else
prctl(PR_SET_NAME, name, 0, 0, 0);
#endif
}
#pragma pack(pop)
Expand Down Expand Up @@ -385,7 +390,7 @@ void thread_spawn(thread_t* entry, const char* name, unsigned stack, void* argli
#if defined(WINDOWS)
_beginthread(thread_entry, stack, startup);
#elif defined(LINUX)
pthread_t handle;
pthread_t handle = 0;
pthread_attr_t attr;
pthread_attr_init(&attr);
pthread_attr_setstacksize(&attr, stack);
Expand Down
8 changes: 8 additions & 0 deletions src/xrCore/xrDebug.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -817,6 +817,7 @@ static void unexpected_handler() { handler_base("unexpected program termination"
static void abort_handler(int signal) { handler_base("application is aborting"); }
static void floating_point_handler(int signal) { handler_base("floating point error"); }
static void illegal_instruction_handler(int signal) { handler_base("illegal instruction"); }
static void segmentation_fault_handler(int signal) { handler_base("segmentation fault"); }
static void termination_handler(int signal) { handler_base("termination with exit code 3"); }

void xrDebug::OnThreadSpawn()
Expand All @@ -841,6 +842,13 @@ void xrDebug::OnThreadSpawn()
#if 0 // should be if we use exceptions
std::set_unexpected(_terminate);
#endif
#else //WINDOWS
signal(SIGABRT, abort_handler);
signal(SIGFPE, floating_point_handler);
signal(SIGILL, illegal_instruction_handler);
signal(SIGINT, 0);
signal(SIGTERM, termination_handler);
signal(SIGSEGV, segmentation_fault_handler);
#endif
}

Expand Down

0 comments on commit 13d0b2c

Please sign in to comment.