Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[release/6.0] Don't cache commandline in coreclr diagnostics server #63356

Merged
merged 5 commits into from
May 3, 2022
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
63 changes: 16 additions & 47 deletions src/coreclr/vm/eventing/eventpipe/ep-rt-coreclr.h
Original file line number Diff line number Diff line change
Expand Up @@ -1107,50 +1107,6 @@ _rt_coreclr_hash_map_iterator_value (CONST_ITERATOR_TYPE *iterator)
#define EP_RT_DEFINE_HASH_MAP_ITERATOR(hash_map_name, hash_map_type, iterator_type, key_type, value_type) \
EP_RT_DEFINE_HASH_MAP_ITERATOR_PREFIX(ep, hash_map_name, hash_map_type, iterator_type, key_type, value_type)

static
inline
char *
diagnostics_command_line_get (void)
{
STATIC_CONTRACT_NOTHROW;
return ep_rt_utf16_to_utf8_string (reinterpret_cast<const ep_char16_t *>(GetCommandLineForDiagnostics ()), -1);
}

static
inline
ep_char8_t **
diagnostics_command_line_get_ref (void)
{
STATIC_CONTRACT_NOTHROW;

extern ep_char8_t *_ep_rt_coreclr_diagnostics_cmd_line;
return &_ep_rt_coreclr_diagnostics_cmd_line;
}

static
inline
void
diagnostics_command_line_lazy_init (void)
{
STATIC_CONTRACT_NOTHROW;

//TODO: Real lazy init implementation.
if (!*diagnostics_command_line_get_ref ())
*diagnostics_command_line_get_ref () = diagnostics_command_line_get ();
}

static
inline
void
diagnostics_command_line_lazy_clean (void)
{
STATIC_CONTRACT_NOTHROW;

//TODO: Real lazy clean up implementation.
ep_rt_utf8_string_free (*diagnostics_command_line_get_ref ());
*diagnostics_command_line_get_ref () = NULL;
}

static
inline
ep_rt_lock_handle_t *
Expand Down Expand Up @@ -1316,7 +1272,6 @@ void
ep_rt_shutdown (void)
{
STATIC_CONTRACT_NOTHROW;
diagnostics_command_line_lazy_clean ();
}

static
Expand Down Expand Up @@ -2711,8 +2666,22 @@ ep_rt_diagnostics_command_line_get (void)
{
STATIC_CONTRACT_NOTHROW;

diagnostics_command_line_lazy_init ();
return *diagnostics_command_line_get_ref ();
// In coreclr, this value can change over time, specifically before vs after suspension in diagnostics server.
// The host initalizes the runtime in two phases, init and exec assembly. On non-Windows platforms the commandline returned by the runtime
// is different during each phase. We suspend during init where the runtime has populated the commandline with a
// mock value (the full path of the executing assembly) and the actual value isn't populated till the exec assembly phase.
// On Windows this does not apply as the value is retrieved directly from the OS any time it is requested.
// As a result, we cannot actually cache this value. We need to return the _current_ value.
// This function needs to handle freeing the string in order to make it consistent with Mono's version.
// To that end, we'll "cache" it here so we free the previous string when we get it again.
extern ep_char8_t *_ep_rt_coreclr_diagnostics_cmd_line;

if (_ep_rt_coreclr_diagnostics_cmd_line)
ep_rt_utf8_string_free(_ep_rt_coreclr_diagnostics_cmd_line);
josalem marked this conversation as resolved.
Show resolved Hide resolved

_ep_rt_coreclr_diagnostics_cmd_line = ep_rt_utf16_to_utf8_string (reinterpret_cast<const ep_char16_t *>(GetCommandLineForDiagnostics ()), -1);

return _ep_rt_coreclr_diagnostics_cmd_line;
}

/*
Expand Down