diff options
author | José Rivero <jorive@microsoft.com> | 2019-03-18 10:23:30 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-03-18 10:23:30 -0700 |
commit | 4497df34cbe3d8bf7a21828714a3cf764da16e98 (patch) | |
tree | 894fc03e621e498cf6b5b33a34fdbb3c63c7d10a /src/pal | |
parent | b88f2f635b02c130ae00b4d8aee3e766a60698d5 (diff) | |
download | coreclr-4497df34cbe3d8bf7a21828714a3cf764da16e98.tar.gz coreclr-4497df34cbe3d8bf7a21828714a3cf764da16e98.tar.bz2 coreclr-4497df34cbe3d8bf7a21828714a3cf764da16e98.zip |
[EventPipe] Adding an IPC server to handle out of process communication. (#23106)
This is the first commit to enable a "diagnostic port" using IPC (Named Pipe on Windows and Unix Domain Socket on other platforms). This change currently enable EventPipe to be enabled/disabled without the use of a file drop.
- Split the DiagnosticsIpc into (DiagnosticsIpc/IpcStream)
- DiagnosticsIpc (IPC listener) is meant to be used by the Diagnostic server.
- IpcStream (IPC channel) is meant to be use to communicate with the connected client.
- Change the FastSerializer dependency from `CFileStream` to `StreamWriter`
This abstraction is meant decouple the writing of objects in order to extend its usability.
The main objective is to reuse FastSerializer to stream data through the open IPC channel.
- Moved the EventPipeSessionProvider* classes to their own file.
- Added a more streamlined parsing achievable by defining a simpler binary protocol (by noahfalk).
1. Only one allocation is needed for the EventPipeProviderConfiguration array, no allocations or copies are needed for strings because we can refer to them directly out of the incoming command buffer
2. No change to the EventPipe API for enable is required. EventPipeProviderConfiguration retains its current behavior of not deleting the string pointers it holds.
3. No leaks happen because the command buffer owns the string memory and ensures that it stays alive for the duration of the Enable() call.
Diffstat (limited to 'src/pal')
-rw-r--r-- | src/pal/inc/pal.h | 11 | ||||
-rw-r--r-- | src/pal/src/thread/process.cpp | 54 |
2 files changed, 51 insertions, 14 deletions
diff --git a/src/pal/inc/pal.h b/src/pal/inc/pal.h index 26c9e3f6d8..1be000ce8a 100644 --- a/src/pal/inc/pal.h +++ b/src/pal/inc/pal.h @@ -480,6 +480,17 @@ static const int MAX_DEBUGGER_TRANSPORT_PIPE_NAME_LENGTH = MAX_PATH; PALIMPORT VOID PALAPI +PAL_GetTransportName( + const int MAX_TRANSPORT_NAME_LENGTH, + OUT char *name, + IN const char *prefix, + IN DWORD id, + IN const char *applicationGroupId, + IN const char *suffix); + +PALIMPORT +VOID +PALAPI PAL_GetTransportPipeName( OUT char *name, IN DWORD id, diff --git a/src/pal/src/thread/process.cpp b/src/pal/src/thread/process.cpp index 5615036806..f7618cbdb9 100644 --- a/src/pal/src/thread/process.cpp +++ b/src/pal/src/thread/process.cpp @@ -1549,7 +1549,8 @@ static uint64_t HashSemaphoreName(uint64_t a, uint64_t b) #define HashSemaphoreName(a,b) a,b #endif -static const char* PipeNameFormat = "clr-debug-pipe-%d-%llu-%s"; +static const char *const TwoWayNamedPipePrefix = "clr-debug-pipe"; +static const char* IpcNameFormat = "%s-%d-%llu-%s"; class PAL_RuntimeStartupHelper { @@ -2288,14 +2289,16 @@ GetProcessIdDisambiguationKey(DWORD processId, UINT64 *disambiguationKey) /*++ Function: - PAL_GetTransportPipeName + PAL_GetTransportName - Builds the transport pipe names from the process id. + Builds the transport IPC names from the process id. --*/ VOID PALAPI -PAL_GetTransportPipeName( +PAL_GetTransportName( + const int MAX_TRANSPORT_NAME_LENGTH, OUT char *name, + IN const char *prefix, IN DWORD id, IN const char *applicationGroupId, IN const char *suffix) @@ -2305,7 +2308,7 @@ PAL_GetTransportPipeName( UINT64 disambiguationKey = 0; PathCharString formatBufferString; BOOL ret = GetProcessIdDisambiguationKey(id, &disambiguationKey); - char *formatBuffer = formatBufferString.OpenStringBuffer(MAX_DEBUGGER_TRANSPORT_PIPE_NAME_LENGTH-1); + char *formatBuffer = formatBufferString.OpenStringBuffer(MAX_TRANSPORT_NAME_LENGTH-1); if (formatBuffer == nullptr) { ERROR("Out Of Memory"); @@ -2337,9 +2340,9 @@ PAL_GetTransportPipeName( } // Verify the size of the path won't exceed maximum allowed size - if (formatBufferString.GetCount() >= MAX_DEBUGGER_TRANSPORT_PIPE_NAME_LENGTH) + if (formatBufferString.GetCount() >= MAX_TRANSPORT_NAME_LENGTH) { - ERROR("GetApplicationContainerFolder returned a path that was larger than MAX_DEBUGGER_TRANSPORT_PIPE_NAME_LENGTH"); + ERROR("GetApplicationContainerFolder returned a path that was larger than MAX_TRANSPORT_NAME_LENGTH"); return; } } @@ -2347,27 +2350,50 @@ PAL_GetTransportPipeName( #endif // __APPLE__ { // Get a temp file location - dwRetVal = ::GetTempPathA(MAX_DEBUGGER_TRANSPORT_PIPE_NAME_LENGTH, formatBuffer); + dwRetVal = ::GetTempPathA(MAX_TRANSPORT_NAME_LENGTH, formatBuffer); if (dwRetVal == 0) { ERROR("GetTempPath failed (0x%08x)", ::GetLastError()); return; } - if (dwRetVal > MAX_DEBUGGER_TRANSPORT_PIPE_NAME_LENGTH) + if (dwRetVal > MAX_TRANSPORT_NAME_LENGTH) { - ERROR("GetTempPath returned a path that was larger than MAX_DEBUGGER_TRANSPORT_PIPE_NAME_LENGTH"); + ERROR("GetTempPath returned a path that was larger than MAX_TRANSPORT_NAME_LENGTH"); return; } } - if (strncat_s(formatBuffer, MAX_DEBUGGER_TRANSPORT_PIPE_NAME_LENGTH, PipeNameFormat, strlen(PipeNameFormat)) == STRUNCATE) + if (strncat_s(formatBuffer, MAX_TRANSPORT_NAME_LENGTH, IpcNameFormat, strlen(IpcNameFormat)) == STRUNCATE) { - ERROR("TransportPipeName was larger than MAX_DEBUGGER_TRANSPORT_PIPE_NAME_LENGTH"); + ERROR("TransportPipeName was larger than MAX_TRANSPORT_NAME_LENGTH"); return; } - int chars = snprintf(name, MAX_DEBUGGER_TRANSPORT_PIPE_NAME_LENGTH, formatBuffer, id, disambiguationKey, suffix); - _ASSERTE(chars > 0 && chars < MAX_DEBUGGER_TRANSPORT_PIPE_NAME_LENGTH); + int chars = snprintf(name, MAX_TRANSPORT_NAME_LENGTH, formatBuffer, prefix, id, disambiguationKey, suffix); + _ASSERTE(chars > 0 && chars < MAX_TRANSPORT_NAME_LENGTH); +} + +/*++ + Function: + PAL_GetTransportPipeName + + Builds the transport pipe names from the process id. +--*/ +VOID +PALAPI +PAL_GetTransportPipeName( + OUT char *name, + IN DWORD id, + IN const char *applicationGroupId, + IN const char *suffix) +{ + PAL_GetTransportName( + MAX_DEBUGGER_TRANSPORT_PIPE_NAME_LENGTH, + name, + TwoWayNamedPipePrefix, + id, + applicationGroupId, + suffix); } /*++ |