diff --git a/src/coreclr/inc/clrconfigvalues.h b/src/coreclr/inc/clrconfigvalues.h index d0a76bc85bcefe..e511fd19185d10 100644 --- a/src/coreclr/inc/clrconfigvalues.h +++ b/src/coreclr/inc/clrconfigvalues.h @@ -716,6 +716,7 @@ RETAIL_CONFIG_DWORD_INFO(EXTERNAL_GCGenAnalysisDump, W("GCGenAnalysisDump"), 0, // RETAIL_CONFIG_DWORD_INFO(EXTERNAL_DOTNET_DefaultDiagnosticPortSuspend, W("DefaultDiagnosticPortSuspend"), 0, "This sets the deafult diagnostic port to suspend causing the runtime to pause during startup before major subsystems are started. Resume using the Diagnostics IPC ResumeStartup command on the default diagnostic port."); RETAIL_CONFIG_STRING_INFO(EXTERNAL_DOTNET_DiagnosticPorts, W("DiagnosticPorts"), "A semicolon delimited list of additional Diagnostic Ports, where a Diagnostic Port is a NamedPipe path without '\\\\.\\pipe\\' on Windows or the full path of Unix Domain Socket on Linux/Unix followed by optional tags, e.g., ',connect,nosuspend;'"); +RETAIL_CONFIG_STRING_INFO(EXTERNAL_DOTNET_DiagnosticPortDefaultPrefix, W("DiagnosticPortDefaultPrefix"), "The default prefix for the diagnostic port name. The default is `dotnet-diagnostic`."); // // LTTng diff --git a/src/coreclr/nativeaot/Runtime/eventpipe/ds-rt-aot.h b/src/coreclr/nativeaot/Runtime/eventpipe/ds-rt-aot.h index 5a7ecaa7b2889d..5b19f29f5f6263 100644 --- a/src/coreclr/nativeaot/Runtime/eventpipe/ds-rt-aot.h +++ b/src/coreclr/nativeaot/Runtime/eventpipe/ds-rt-aot.h @@ -168,6 +168,20 @@ ds_rt_config_value_get_default_port_suspend (void) return 0; } +static +inline +ep_char8_t * +ds_rt_config_value_get_port_default_prefix (void) +{ + STATIC_CONTRACT_NOTHROW; + + char* value; + if (RhConfig::Environment::TryGetStringValue("DiagnosticPortDefaultPrefix", &value)) + return (ep_char8_t*)value; + + return nullptr; +} + /* * DiagnosticsDump. */ diff --git a/src/coreclr/vm/eventing/eventpipe/ds-rt-coreclr.h b/src/coreclr/vm/eventing/eventpipe/ds-rt-coreclr.h index fb6c0c3feeda09..1982fac3514168 100644 --- a/src/coreclr/vm/eventing/eventpipe/ds-rt-coreclr.h +++ b/src/coreclr/vm/eventing/eventpipe/ds-rt-coreclr.h @@ -178,6 +178,18 @@ ds_rt_config_value_get_default_port_suspend (void) return static_cast(CLRConfig::GetConfigValue (CLRConfig::EXTERNAL_DOTNET_DefaultDiagnosticPortSuspend)); } + +static +inline +ep_char8_t * +ds_rt_config_value_get_port_default_prefix (void) +{ + STATIC_CONTRACT_NOTHROW; + + CLRConfigStringHolder value(CLRConfig::GetConfigValue (CLRConfig::EXTERNAL_DOTNET_DiagnosticPortDefaultPrefix)); + return ep_rt_utf16_to_utf8_string (reinterpret_cast(value.GetValue ())); +} + /* * DiagnosticsDump. */ diff --git a/src/mono/mono/eventpipe/ds-rt-mono.h b/src/mono/mono/eventpipe/ds-rt-mono.h index 66e39b7078c4a4..642d961da142dc 100644 --- a/src/mono/mono/eventpipe/ds-rt-mono.h +++ b/src/mono/mono/eventpipe/ds-rt-mono.h @@ -149,6 +149,14 @@ ds_rt_config_value_get_default_port_suspend (void) return value_uint32_t; } +static +inline +ep_char8_t * +ds_rt_config_value_get_port_default_prefix (void) +{ + return g_getenv ("DOTNET_DiagnosticPortDefaultPrefix"); +} + /* * DiagnosticsDump. */ diff --git a/src/native/eventpipe/ds-ipc-pal-namedpipe.c b/src/native/eventpipe/ds-ipc-pal-namedpipe.c index b7cfd0528fa4e0..143580dea35e0e 100644 --- a/src/native/eventpipe/ds-ipc-pal-namedpipe.c +++ b/src/native/eventpipe/ds-ipc-pal-namedpipe.c @@ -117,7 +117,9 @@ DiagnosticsIpc * ds_ipc_alloc ( const ep_char8_t *ipc_name, DiagnosticsIpcConnectionMode mode, - ds_ipc_error_callback_func callback) + ds_ipc_error_callback_func callback, + const ep_char8_t *ipc_default_prefix) + { int32_t characters_written = -1; @@ -144,7 +146,8 @@ ds_ipc_alloc ( characters_written = sprintf_s ( (char *)&instance->pipe_name, (size_t)DS_IPC_WIN32_MAX_NAMED_PIPE_LEN, - (const char *)"\\\\.\\pipe\\dotnet-diagnostic-%d", + (const char *)"\\\\.\\pipe\\%s-%d", + ipc_default_prefix, GetCurrentProcessId ()); } diff --git a/src/native/eventpipe/ds-ipc-pal-socket.c b/src/native/eventpipe/ds-ipc-pal-socket.c index 7ad0b0f5d4859c..9cab2086cbb8f9 100644 --- a/src/native/eventpipe/ds-ipc-pal-socket.c +++ b/src/native/eventpipe/ds-ipc-pal-socket.c @@ -159,7 +159,8 @@ static bool ipc_transport_get_default_name ( ep_char8_t *name, - int32_t name_len); + int32_t name_len, + const ep_char8_t *ipc_default_prefix); static bool @@ -172,7 +173,8 @@ DiagnosticsIpc * ipc_alloc_uds_address ( DiagnosticsIpc *ipc, DiagnosticsIpcConnectionMode mode, - const ep_char8_t *ipc_name); + const ep_char8_t *ipc_name, + const ep_char8_t *ipc_default_prefix); static DiagnosticsIpc * @@ -694,14 +696,15 @@ inline bool ipc_transport_get_default_name ( ep_char8_t *name, - int32_t name_len) + int32_t name_len, + const ep_char8_t *ipc_default_prefix) { #ifdef DS_IPC_PAL_AF_UNIX #ifndef EP_NO_RT_DEPENDENCY return ds_rt_transport_get_default_name ( name, name_len, - "dotnet-diagnostic", + ipc_default_prefix, ep_rt_current_process_get_id (), NULL, "socket"); @@ -711,7 +714,7 @@ ipc_transport_get_default_name ( PAL_GetTransportName( name_len, name, - "dotnet-diagnostic", + ipc_default_prefix, pd.m_Pid, pd.m_ApplicationGroupId, "socket"); @@ -788,7 +791,8 @@ DiagnosticsIpc * ipc_alloc_uds_address ( DiagnosticsIpc *ipc, DiagnosticsIpcConnectionMode mode, - const ep_char8_t *ipc_name) + const ep_char8_t *ipc_name, + const ep_char8_t *ipc_default_prefix) { #ifdef DS_IPC_PAL_AF_UNIX EP_ASSERT (ipc != NULL); @@ -810,7 +814,8 @@ ipc_alloc_uds_address ( // generate the default socket name ipc_transport_get_default_name ( server_address->sun_path, - sizeof (server_address->sun_path)); + sizeof (server_address->sun_path), + ipc_default_prefix); } ipc->server_address = (ds_ipc_socket_address_t *)server_address; @@ -942,10 +947,11 @@ DiagnosticsIpc * ipc_alloc_address ( DiagnosticsIpc *ipc, DiagnosticsIpcConnectionMode mode, - const ep_char8_t *ipc_name) + const ep_char8_t *ipc_name, + const ep_char8_t *ipc_default_prefix) { #ifdef DS_IPC_PAL_AF_UNIX - return ipc_alloc_uds_address (ipc, mode, ipc_name); + return ipc_alloc_uds_address (ipc, mode, ipc_name, ipc_default_prefix); #elif defined(DS_IPC_PAL_AF_INET) || defined(DS_IPC_PAL_AF_INET6) return ipc_alloc_tcp_address (ipc, mode, ipc_name); #else @@ -1027,7 +1033,8 @@ DiagnosticsIpc * ds_ipc_alloc ( const ep_char8_t *ipc_name, DiagnosticsIpcConnectionMode mode, - ds_ipc_error_callback_func callback) + ds_ipc_error_callback_func callback, + const ep_char8_t *ipc_default_prefix) { DiagnosticsIpc *instance = NULL; @@ -1039,7 +1046,7 @@ ds_ipc_alloc ( instance->is_closed = false; instance->is_listening = false; - ep_raise_error_if_nok (ipc_alloc_address (instance, mode, ipc_name) != NULL); + ep_raise_error_if_nok (ipc_alloc_address (instance, mode, ipc_name, ipc_default_prefix) != NULL); if (mode == DS_IPC_CONNECTION_MODE_LISTEN) ep_raise_error_if_nok (ipc_init_listener (instance, callback) == true); diff --git a/src/native/eventpipe/ds-ipc-pal.h b/src/native/eventpipe/ds-ipc-pal.h index 8e246ed671955c..fd407d453fe119 100644 --- a/src/native/eventpipe/ds-ipc-pal.h +++ b/src/native/eventpipe/ds-ipc-pal.h @@ -30,7 +30,8 @@ DiagnosticsIpc * ds_ipc_alloc ( const ep_char8_t *ipc_name, DiagnosticsIpcConnectionMode mode, - ds_ipc_error_callback_func callback); + ds_ipc_error_callback_func callback, + const ep_char8_t *ipc_default_prefix); void ds_ipc_free (DiagnosticsIpc *ipc); diff --git a/src/native/eventpipe/ds-ipc.c b/src/native/eventpipe/ds-ipc.c index 7d3c56ee28d452..aa349f5136cb32 100644 --- a/src/native/eventpipe/ds-ipc.c +++ b/src/native/eventpipe/ds-ipc.c @@ -175,7 +175,10 @@ ipc_stream_factory_build_and_add_port ( if (builder->type == DS_PORT_TYPE_LISTEN) { #ifndef DS_IPC_DISABLE_LISTEN_PORTS - ipc = ds_ipc_alloc (builder->path, DS_IPC_CONNECTION_MODE_LISTEN, callback); + ep_char8_t* ipc_default_prefix = ds_rt_config_value_get_port_default_prefix(); + ipc_default_prefix = ipc_default_prefix != NULL ? ipc_default_prefix : (ep_char8_t*)"dotnet-diagnostic"; + + ipc = ds_ipc_alloc (builder->path, DS_IPC_CONNECTION_MODE_LISTEN, callback, ipc_default_prefix); ep_raise_error_if_nok (ipc != NULL); ep_raise_error_if_nok (ds_ipc_listen (ipc, callback)); ep_raise_error_if_nok (dn_vector_ptr_push_back (_ds_port_array, (DiagnosticsPort *)ds_listen_port_alloc (ipc, builder))); @@ -185,7 +188,10 @@ ipc_stream_factory_build_and_add_port ( #endif } else if (builder->type == DS_PORT_TYPE_CONNECT) { #ifndef DS_IPC_DISABLE_CONNECT_PORTS - ipc = ds_ipc_alloc (builder->path, DS_IPC_CONNECTION_MODE_CONNECT, callback); + ep_char8_t* ipc_default_prefix = ds_rt_config_value_get_port_default_prefix(); + ipc_default_prefix = ipc_default_prefix != NULL ? ipc_default_prefix : (ep_char8_t*)"dotnet-diagnostic"; + + ipc = ds_ipc_alloc (builder->path, DS_IPC_CONNECTION_MODE_CONNECT, callback, ipc_default_prefix); ep_raise_error_if_nok (ipc != NULL); ep_raise_error_if_nok (dn_vector_ptr_push_back (_ds_port_array, (DiagnosticsPort *)ds_connect_port_alloc (ipc, builder))); #else diff --git a/src/native/eventpipe/ds-rt.h b/src/native/eventpipe/ds-rt.h index a5f9fce15611c6..ddd01cb079448d 100644 --- a/src/native/eventpipe/ds-rt.h +++ b/src/native/eventpipe/ds-rt.h @@ -63,6 +63,10 @@ static uint32_t ds_rt_config_value_get_default_port_suspend (void); +static +ep_char8_t * +ds_rt_config_value_get_port_default_prefix (void); + /* * DiagnosticsDump. */