diff options
author | Mike McLaughlin <mikem@microsoft.com> | 2016-02-12 14:47:12 -0800 |
---|---|---|
committer | Mike McLaughlin <mikem@microsoft.com> | 2016-02-12 17:35:34 -0800 |
commit | ff4aa3f141c0191b2783ffd8b5046380143799c9 (patch) | |
tree | 969855f742441938ed60aa5589c5599f736789e3 | |
parent | 76afde059ec6acf46b2694638bc967705808422b (diff) | |
download | coreclr-ff4aa3f141c0191b2783ffd8b5046380143799c9.tar.gz coreclr-ff4aa3f141c0191b2783ffd8b5046380143799c9.tar.bz2 coreclr-ff4aa3f141c0191b2783ffd8b5046380143799c9.zip |
Fix tracing lib problems in multiple PALs. Issue #3164.
Moved the tracepointprovider loading in miscpalapi.cpp to separate library that
is only linked by libcoreclr.so.
-rw-r--r-- | src/dlls/mscoree/coreclr/CMakeLists.txt | 1 | ||||
-rw-r--r-- | src/pal/inc/pal.h | 20 | ||||
-rw-r--r-- | src/pal/src/CMakeLists.txt | 5 | ||||
-rw-r--r-- | src/pal/src/exception/signal.cpp | 16 | ||||
-rw-r--r-- | src/pal/src/include/pal/process.h | 4 | ||||
-rw-r--r-- | src/pal/src/init/pal.cpp | 6 | ||||
-rw-r--r-- | src/pal/src/misc/miscpalapi.cpp | 74 | ||||
-rw-r--r-- | src/pal/src/misc/tracepointprovider.cpp | 112 | ||||
-rw-r--r-- | src/pal/src/thread/process.cpp | 10 | ||||
-rw-r--r-- | src/pal/src/thread/thread.cpp | 2 |
10 files changed, 139 insertions, 111 deletions
diff --git a/src/dlls/mscoree/coreclr/CMakeLists.txt b/src/dlls/mscoree/coreclr/CMakeLists.txt index 0901404913..9795d41262 100644 --- a/src/dlls/mscoree/coreclr/CMakeLists.txt +++ b/src/dlls/mscoree/coreclr/CMakeLists.txt @@ -108,6 +108,7 @@ else() list(APPEND CORECLR_LIBRARIES ${START_WHOLE_ARCHIVE} # force all PAL objects to be included so all exports are available coreclrpal + tracepointprovider ${END_WHOLE_ARCHIVE} mscorrc_debug palrt diff --git a/src/pal/inc/pal.h b/src/pal/inc/pal.h index cc4a695d04..8ba8c9b2e3 100644 --- a/src/pal/inc/pal.h +++ b/src/pal/inc/pal.h @@ -493,26 +493,6 @@ typedef long time_t; typedef DWORD (PALAPI *PTHREAD_START_ROUTINE)(LPVOID lpThreadParameter); typedef PTHREAD_START_ROUTINE LPTHREAD_START_ROUTINE; - -/******************* Tracing Initialization *******************************/ - -#if defined(__LINUX__) - -// Constructor priority is set to 200, which allows for constructors to -// guarantee that they run before or after this constructor by setting -// their priority appropriately. - -// Priority values must be greater than 100. The lower the value, -// the higher the priority. -static -void -__attribute__((__unused__)) -__attribute__((constructor (200))) -PAL_InitializeTracing(void); - -#endif - - /******************* PAL-Specific Entrypoints *****************************/ PALIMPORT diff --git a/src/pal/src/CMakeLists.txt b/src/pal/src/CMakeLists.txt index 9828d30433..ff0d1c381d 100644 --- a/src/pal/src/CMakeLists.txt +++ b/src/pal/src/CMakeLists.txt @@ -202,6 +202,11 @@ add_library(coreclrpal ${PLATFORM_SOURCES} ) +add_library(tracepointprovider + STATIC + misc/tracepointprovider.cpp +) + if(CMAKE_SYSTEM_NAME STREQUAL Darwin) find_library(COREFOUNDATION CoreFoundation) find_library(CORESERVICES CoreServices) diff --git a/src/pal/src/exception/signal.cpp b/src/pal/src/exception/signal.cpp index 35a3de35d3..25136a703b 100644 --- a/src/pal/src/exception/signal.cpp +++ b/src/pal/src/exception/signal.cpp @@ -227,7 +227,7 @@ static void sigill_handler(int code, siginfo_t *siginfo, void *context) restore_signal(code, &g_previous_sigill); } - PROCShutdownProcess(); + PROCNotifyProcessShutdown(); } /*++ @@ -274,7 +274,7 @@ static void sigfpe_handler(int code, siginfo_t *siginfo, void *context) restore_signal(code, &g_previous_sigfpe); } - PROCShutdownProcess(); + PROCNotifyProcessShutdown(); } /*++ @@ -344,7 +344,7 @@ static void sigsegv_handler(int code, siginfo_t *siginfo, void *context) restore_signal(code, &g_previous_sigsegv); } - PROCShutdownProcess(); + PROCNotifyProcessShutdown(); } /*++ @@ -392,7 +392,7 @@ static void sigtrap_handler(int code, siginfo_t *siginfo, void *context) PROCAbort(); } - PROCShutdownProcess(); + PROCNotifyProcessShutdown(); } /*++ @@ -447,7 +447,7 @@ static void sigbus_handler(int code, siginfo_t *siginfo, void *context) restore_signal(code, &g_previous_sigbus); } - PROCShutdownProcess(); + PROCNotifyProcessShutdown(); } /*++ @@ -465,7 +465,7 @@ static void sigint_handler(int code, siginfo_t *siginfo, void *context) { TRACE("SIGINT signal; chaining to previous sigaction\n"); - PROCShutdownProcess(); + PROCNotifyProcessShutdown(); // Restore the original or default handler and resend signal restore_signal(code, &g_previous_sigint); @@ -487,7 +487,7 @@ static void sigquit_handler(int code, siginfo_t *siginfo, void *context) { TRACE("SIGQUIT signal; chaining to previous sigaction\n"); - PROCShutdownProcess(); + PROCNotifyProcessShutdown(); // Restore the original or default handler and resend signal restore_signal(code, &g_previous_sigquit); @@ -554,7 +554,7 @@ PAL_ERROR InjectActivationInternal(CorUnix::CPalThread* pThread) int status = pthread_kill(pThread->GetPThreadSelf(), INJECT_ACTIVATION_SIGNAL); if (status != 0) { - PROCShutdownProcess(); + PROCNotifyProcessShutdown(); // Failure to send the signal is fatal. There are only two cases when sending // the signal can fail. First, if the signal ID is invalid and second, diff --git a/src/pal/src/include/pal/process.h b/src/pal/src/include/pal/process.h index 724214ca5d..bd78f9bc12 100644 --- a/src/pal/src/include/pal/process.h +++ b/src/pal/src/include/pal/process.h @@ -132,14 +132,14 @@ void PROCAbort(); /*++ Function: - PROCShutdownProcess + PROCNotifyProcessShutdown Calls the abort handler to do any shutdown cleanup. Call be called from the unhandled native exception handler. (no return value) --*/ -void PROCShutdownProcess(); +void PROCNotifyProcessShutdown(); /*++ Function: diff --git a/src/pal/src/init/pal.cpp b/src/pal/src/init/pal.cpp index ab9614f5fb..b2efdf2779 100644 --- a/src/pal/src/init/pal.cpp +++ b/src/pal/src/init/pal.cpp @@ -242,7 +242,7 @@ Initialize( // Initialize the environment. if (FALSE == MiscInitialize()) { - goto done; + goto CLEANUP0; } // Initialize debug channel settings before anything else. @@ -250,7 +250,7 @@ Initialize( // MiscInitialize. if (FALSE == DBG_init_channels()) { - goto done; + goto CLEANUP0; } #if _DEBUG @@ -271,6 +271,7 @@ Initialize( // we use large numbers of threads or have many open files. } + /* initialize the shared memory infrastructure */ if (!SHMInitialize()) { @@ -572,6 +573,7 @@ CLEANUP1a: CLEANUP1: SHMCleanup(); CLEANUP0: + TLSCleanup(); ERROR("PAL_Initialize failed\n"); SetLastError(palError); done: diff --git a/src/pal/src/misc/miscpalapi.cpp b/src/pal/src/misc/miscpalapi.cpp index 10a71e3907..44ba18b907 100644 --- a/src/pal/src/misc/miscpalapi.cpp +++ b/src/pal/src/misc/miscpalapi.cpp @@ -50,80 +50,6 @@ SET_DEFAULT_DEBUG_CHANNEL(MISC); static const char RANDOM_DEVICE_NAME[] ="/dev/random"; static const char URANDOM_DEVICE_NAME[]="/dev/urandom"; - -/*++ - -Initialization logic for LTTng tracepoint providers. - ---*/ -#if defined(__LINUX__) - -static const char tpLibName[] = "libcoreclrtraceptprovider.so"; - - -/*++ - -NOTE: PAL_InitializeTracing MUST NOT depend on anything in the PAL itself -as it is called prior to PAL initialization. - ---*/ -static -void -PAL_InitializeTracing(void) -{ - // Get the path to the currently executing shared object (libcoreclr.so). - Dl_info info; - int succeeded = dladdr((void *)PAL_InitializeTracing, &info); - if(!succeeded) - { - return; - } - - // Copy the path and modify the shared object name to be the tracepoint provider. - char tpProvPath[MAX_LONGPATH]; - int pathLen = strlen(info.dli_fname); - int tpLibNameLen = strlen(tpLibName); - - // Find the length of the full path without the shared object name, including the trailing slash. - int lastTrailingSlashLen = -1; - for(int i=pathLen-1; i>=0; i--) - { - if(info.dli_fname[i] == '/') - { - lastTrailingSlashLen = i+1; - break; - } - } - - // Make sure we found the last trailing slash. - if(lastTrailingSlashLen == -1) - { - return; - } - - // Make sure that the final path is shorter than MAX_PATH. - // +1 ensures that the string can be NULL-terminated. - if((lastTrailingSlashLen + tpLibNameLen + 1) > MAX_LONGPATH) - { - return; - } - - // Copy the path without the shared object name. - memcpy(&tpProvPath, info.dli_fname, lastTrailingSlashLen); - - // Append the shared object name for the tracepoint provider. - memcpy(&tpProvPath[lastTrailingSlashLen], &tpLibName, tpLibNameLen); - - // NULL-terminate the string. - tpProvPath[lastTrailingSlashLen + tpLibNameLen] = '\0'; - - // Load the tracepoint provider. - // It's OK if this fails - that just means that tracing dependencies aren't available. - dlopen(tpProvPath, RTLD_NOW | RTLD_GLOBAL); -} - -#endif - /*++ Function : diff --git a/src/pal/src/misc/tracepointprovider.cpp b/src/pal/src/misc/tracepointprovider.cpp new file mode 100644 index 0000000000..68f898d94a --- /dev/null +++ b/src/pal/src/misc/tracepointprovider.cpp @@ -0,0 +1,112 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +/*++ + +Module Name: + + tracepointprovider.cpp + +Abstract: + + Trace point provider support + +Revision History: + +--*/ + +#include "pal/palinternal.h" +#include "pal/dbgmsg.h" +#include "pal/file.h" +#include "pal/process.h" +#include "pal/module.h" +#include "pal/malloc.hpp" + +#include <errno.h> +#include <unistd.h> +#include <pthread.h> +#include <dlfcn.h> + +SET_DEFAULT_DEBUG_CHANNEL(MISC); + +/*++ + +Initialization logic for LTTng tracepoint providers. + +--*/ +#if defined(__LINUX__) + +static const char tpLibName[] = "libcoreclrtraceptprovider.so"; + + +/*++ + +NOTE: PAL_InitializeTracing MUST NOT depend on anything in the PAL itself +as it is called prior to PAL initialization. + +Constructor priority is set to 200, which allows for constructors to +guarantee that they run before or after this constructor by setting +their priority appropriately. + +Priority values must be greater than 100. The lower the value, +the higher the priority. + +--*/ +__attribute__((__unused__)) +__attribute__((constructor (200))) +static void +PAL_InitializeTracing(void) +{ + // Get the path to the currently executing shared object (libcoreclr.so). + Dl_info info; + int succeeded = dladdr((void *)PAL_InitializeTracing, &info); + if(!succeeded) + { + return; + } + + // Copy the path and modify the shared object name to be the tracepoint provider. + char tpProvPath[MAX_LONGPATH]; + int pathLen = strlen(info.dli_fname); + int tpLibNameLen = strlen(tpLibName); + + // Find the length of the full path without the shared object name, including the trailing slash. + int lastTrailingSlashLen = -1; + for(int i=pathLen-1; i>=0; i--) + { + if(info.dli_fname[i] == '/') + { + lastTrailingSlashLen = i+1; + break; + } + } + + // Make sure we found the last trailing slash. + if(lastTrailingSlashLen == -1) + { + return; + } + + // Make sure that the final path is shorter than MAX_PATH. + // +1 ensures that the string can be NULL-terminated. + if((lastTrailingSlashLen + tpLibNameLen + 1) > MAX_LONGPATH) + { + return; + } + + // Copy the path without the shared object name. + memcpy(&tpProvPath, info.dli_fname, lastTrailingSlashLen); + + // Append the shared object name for the tracepoint provider. + memcpy(&tpProvPath[lastTrailingSlashLen], &tpLibName, tpLibNameLen); + + // NULL-terminate the string. + tpProvPath[lastTrailingSlashLen + tpLibNameLen] = '\0'; + + // Load the tracepoint provider. + // It's OK if this fails - that just means that tracing dependencies aren't available. + dlopen(tpProvPath, RTLD_NOW | RTLD_GLOBAL); +} + +#endif
\ No newline at end of file diff --git a/src/pal/src/thread/process.cpp b/src/pal/src/thread/process.cpp index eb2e8d5b29..c5f79f5532 100644 --- a/src/pal/src/thread/process.cpp +++ b/src/pal/src/thread/process.cpp @@ -2537,7 +2537,7 @@ DestroyProcessModules(IN ProcessModules *listHead) /*++ Function: - PROCShutdownProcess + PROCNotifyProcessShutdown Calls the abort handler to do any shutdown cleanup. Call be called from the unhandled native exception handler. @@ -2545,9 +2545,9 @@ Function: (no return value) --*/ __attribute__((destructor)) -void PROCShutdownProcess() +void PROCNotifyProcessShutdown() { - TRACE("PROCShutdownProcess %p\n", g_shutdownCallback.RawValue()); + TRACE("PROCNotifyProcessShutdown %p\n", g_shutdownCallback.RawValue()); PSHUTDOWN_CALLBACK callback = InterlockedExchangePointer(&g_shutdownCallback, NULL); if (callback != NULL) @@ -2569,7 +2569,7 @@ PAL_NORETURN void PROCAbort() { - PROCShutdownProcess(); + PROCNotifyProcessShutdown(); abort(); } @@ -3214,7 +3214,7 @@ CorUnix::TerminateCurrentProcessNoExit(BOOL bTerminateUnconditionally) locked = PALInitLock(); if(locked && PALIsInitialized()) { - PROCShutdownProcess(); + PROCNotifyProcessShutdown(); PALCommonCleanup(); } } diff --git a/src/pal/src/thread/thread.cpp b/src/pal/src/thread/thread.cpp index f3a93a9b79..57462166c8 100644 --- a/src/pal/src/thread/thread.cpp +++ b/src/pal/src/thread/thread.cpp @@ -206,6 +206,8 @@ Function: VOID TLSCleanup() { SPINLOCKDestroy(&free_threads_spinlock); + + pthread_key_delete(thObjKey); } /*++ |