Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/dotnet/runtime.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid Wrighton <davidwr@microsoft.com>2021-02-24 23:43:51 +0300
committerGitHub <noreply@github.com>2021-02-24 23:43:51 +0300
commitdd6bc8ce6bfc6832c33800200d402f8913b8cfa2 (patch)
tree4f4fcd6108cf1f4e09a5adba21d5402bb03a1133 /src/native/eventpipe
parenteb03e0f7bc396736c7ac59cf8f135d7c632860dd (diff)
Enhance coreclr processing of event pipe configuration to be able to write the pid of the current process into the nettrace file (#48537)
- Also fix the behavior of get_next_config_value_as_utf8_string to work correctly on coreclr, it was type-punning between a buffer returned by ep_rt_byte_array_alloc and ep_rt_utf8_string_free, which isn't safe in the coreclr implementation
Diffstat (limited to 'src/native/eventpipe')
-rw-r--r--src/native/eventpipe/ep-rt.h12
-rw-r--r--src/native/eventpipe/ep.c27
2 files changed, 32 insertions, 7 deletions
diff --git a/src/native/eventpipe/ep-rt.h b/src/native/eventpipe/ep-rt.h
index 07c85a2e4eb..6b2d40e4dfe 100644
--- a/src/native/eventpipe/ep-rt.h
+++ b/src/native/eventpipe/ep-rt.h
@@ -672,6 +672,10 @@ ep_rt_utf8_string_dup (const ep_char8_t *str);
static
ep_char8_t *
+ep_rt_utf8_string_dup_range (const ep_char8_t *str, const ep_char8_t *strEnd);
+
+static
+ep_char8_t *
ep_rt_utf8_string_strtok (
ep_char8_t *str,
const ep_char8_t *delimiter,
@@ -683,6 +687,14 @@ ep_rt_utf8_string_strtok (
format, ...) ep_redefine
static
+inline bool
+ep_rt_utf8_string_replace (
+ ep_char8_t **str,
+ const ep_char8_t *strSearch,
+ const ep_char8_t *strReplacement
+);
+
+static
ep_char16_t *
ep_rt_utf8_to_utf16_string (
const ep_char8_t *str,
diff --git a/src/native/eventpipe/ep.c b/src/native/eventpipe/ep.c
index b3588ada5e2..5517c7d98fc 100644
--- a/src/native/eventpipe/ep.c
+++ b/src/native/eventpipe/ep.c
@@ -729,20 +729,17 @@ get_next_config_value_as_utf8_string (const ep_char8_t **data)
{
EP_ASSERT (data != NULL);
- uint8_t *buffer = NULL;
+ ep_char8_t *buffer = NULL;
const ep_char8_t *start = NULL;
const ep_char8_t *end = NULL;
*data = get_next_config_value (*data, &start, &end);
ptrdiff_t byte_len = end - start;
- if (byte_len != 0) {
- buffer = ep_rt_byte_array_alloc (byte_len + 1);
- memcpy (buffer, start, byte_len);
- buffer [byte_len] = '\0';
- }
+ if (byte_len != 0)
+ buffer = ep_rt_utf8_string_dup_range(start, end);
- return (ep_char8_t *)buffer;
+ return buffer;
}
static
@@ -792,6 +789,22 @@ enable_default_session_via_env_variables (void)
if (ep_rt_config_value_get_enable ()) {
ep_config = ep_rt_config_value_get_config ();
ep_config_output_path = ep_rt_config_value_get_output_path ();
+
+ ep_char8_t pidStr[24];
+ ep_rt_utf8_string_snprintf(pidStr, EP_ARRAY_SIZE (pidStr), "%u", (unsigned)ep_rt_current_process_get_id());
+
+ while (true)
+ {
+ if (ep_rt_utf8_string_replace(&ep_config_output_path, "{pid}", pidStr))
+ {
+ // In case there is a second use of {pid} in the output path
+ continue;
+ }
+
+ // No more instances of {pid} in the OutputPath
+ break;
+ }
+
ep_circular_mb = ep_rt_config_value_get_circular_mb ();
output_path = NULL;