diff --git a/projects/clr/rocclr/runtime/device/cpu/cpudevice.cpp b/projects/clr/rocclr/runtime/device/cpu/cpudevice.cpp index 2e4a575c13..3e5493b06e 100644 --- a/projects/clr/rocclr/runtime/device/cpu/cpudevice.cpp +++ b/projects/clr/rocclr/runtime/device/cpu/cpudevice.cpp @@ -51,7 +51,8 @@ Device::~Device() void Device::tearDown() { - aclCompilerFini(compiler_); + amd::Os::uninstallSigfpeHandler(); + aclCompilerFini(compiler_); } bool Device::init() @@ -60,6 +61,9 @@ Device::init() if (CPU_MAX_COMPUTE_UNITS == 0) return false; + if(!amd::Os::installSigfpeHandler()) + return false; + const char *library = getenv("COMPILER_LIBRARY"); aclCompilerOptions opts = { sizeof(aclCompilerOptions_0_8), diff --git a/projects/clr/rocclr/runtime/os/os.hpp b/projects/clr/rocclr/runtime/os/os.hpp index e361a96f4f..5299162e18 100644 --- a/projects/clr/rocclr/runtime/os/os.hpp +++ b/projects/clr/rocclr/runtime/os/os.hpp @@ -259,6 +259,12 @@ public: //! get Application file name static std::string getAppFileName(); + + //! Install SIGFPE handler for CPU device + static bool installSigfpeHandler(); + + //! Uninstall SIGFPE handler for CPU device + static void uninstallSigfpeHandler(); }; /*@}*/ diff --git a/projects/clr/rocclr/runtime/os/os_posix.cpp b/projects/clr/rocclr/runtime/os/os_posix.cpp index e7b6a9905f..26cde31c9c 100644 --- a/projects/clr/rocclr/runtime/os/os_posix.cpp +++ b/projects/clr/rocclr/runtime/os/os_posix.cpp @@ -124,6 +124,23 @@ static pthread_setaffinity_fn pthread_setaffinity_fptr; static void init() __attribute__((constructor(101))); static void init() { Os::init(); } +bool Os::installSigfpeHandler() { + // Install a SIGFPE signal handler @todo: Chain the handlers + struct sigaction sa; + sigfillset(&sa.sa_mask); + sa.sa_handler = SIG_DFL; + sa.sa_sigaction = divisionErrorHandler; + sa.sa_flags = SA_SIGINFO | SA_RESTART; + + if (sigaction(SIGFPE, &sa, &oldSigAction) != 0) { + return false; + } + return true; +} + +void Os::uninstallSigfpeHandler() { +} + bool Os::init() { @@ -138,17 +155,6 @@ Os::init() pageSize_ = (size_t) ::sysconf(_SC_PAGESIZE); processorCount_ = ::sysconf(_SC_NPROCESSORS_CONF); - // Install a SIGFPE signal handler @todo: Chain the handlers - struct sigaction sa; - sigfillset(&sa.sa_mask); - sa.sa_handler = SIG_DFL; - sa.sa_sigaction = divisionErrorHandler; - sa.sa_flags = SA_SIGINFO | SA_RESTART; - - if (sigaction(SIGFPE, &sa, &oldSigAction) != 0) { - return false; - } - pthread_setaffinity_fptr = (pthread_setaffinity_fn) dlsym(RTLD_NEXT, "pthread_setaffinity_np"); diff --git a/projects/clr/rocclr/runtime/os/os_win32.cpp b/projects/clr/rocclr/runtime/os/os_win32.cpp index bea0efac62..0d66e09374 100644 --- a/projects/clr/rocclr/runtime/os/os_win32.cpp +++ b/projects/clr/rocclr/runtime/os/os_win32.cpp @@ -66,10 +66,6 @@ Os::init() QueryPerformanceFrequency(&frequency); PerformanceFrequency = (double) frequency.QuadPart; -#ifdef _WIN64 - divExceptionHandler = AddVectoredExceptionHandler(1, divExceptionFilter); -#endif // _WIN64 - HMODULE handle = ::LoadLibrary("kernel32.dll"); if (handle != NULL) { pfnSetThreadGroupAffinity = (SetThreadGroupAffinity_fn) @@ -87,13 +83,6 @@ __declspec(allocate(".CRT$XTU")) void (*__exit)(void) = Os::tearDown; void Os::tearDown() { -#ifdef _WIN64 - if (divExceptionHandler != NULL) { - RemoveVectoredExceptionHandler(divExceptionHandler); - divExceptionHandler = NULL; - } -#endif // _WIN64 - Thread::tearDown(); } @@ -464,6 +453,22 @@ divExceptionFilter(struct _EXCEPTION_POINTERS* ep) return EXCEPTION_CONTINUE_SEARCH; } +bool Os::installSigfpeHandler() { +#ifdef _WIN64 + divExceptionHandler = AddVectoredExceptionHandler(1, divExceptionFilter); +#endif // _WIN64 + return true; +} + +void Os::uninstallSigfpeHandler() { +#ifdef _WIN64 + if (divExceptionHandler != NULL) { + RemoveVectoredExceptionHandler(divExceptionHandler); + divExceptionHandler = NULL; + } +#endif // _WIN64 +} + void* Thread::entry(Thread* thread) {