diff --git a/eng/pipelines/runtime.yml b/eng/pipelines/runtime.yml index c39d656d3189b..65769749869b4 100644 --- a/eng/pipelines/runtime.yml +++ b/eng/pipelines/runtime.yml @@ -248,7 +248,7 @@ extends: extraStepsTemplate: /eng/pipelines/coreclr/nativeaot-post-build-steps.yml extraStepsParameters: creator: dotnet-bot - testBuildArgs: 'nativeaot tree ";nativeaot;Loader;Interop;tracing/eventpipe/config;tracing/eventpipe/diagnosticport;tracing/eventpipe/reverse;tracing/eventpipe/simpleruntimeeventvalidation;" test tracing/eventcounter/runtimecounters.csproj /p:BuildNativeAotFrameworkObjects=true' + testBuildArgs: 'nativeaot tree ";nativeaot;Loader;Interop;tracing/eventpipe/config;tracing/eventpipe/diagnosticport;tracing/eventpipe/reverse;tracing/eventpipe/processenvironment;tracing/eventpipe/simpleruntimeeventvalidation;" test tracing/eventcounter/runtimecounters.csproj /p:BuildNativeAotFrameworkObjects=true' liveLibrariesBuildConfig: Release testRunNamePrefixSuffix: NativeAOT_$(_BuildConfig) extraVariablesTemplates: diff --git a/src/coreclr/nativeaot/Runtime/eventpipe/ds-rt-aot.cpp b/src/coreclr/nativeaot/Runtime/eventpipe/ds-rt-aot.cpp index 25272643d18a3..f6346b3c04666 100644 --- a/src/coreclr/nativeaot/Runtime/eventpipe/ds-rt-aot.cpp +++ b/src/coreclr/nativeaot/Runtime/eventpipe/ds-rt-aot.cpp @@ -1,6 +1,12 @@ // Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. +#ifdef TARGET_WINDOWS +#include +#else +#include +#endif + #include #ifdef __APPLE__ @@ -227,4 +233,19 @@ ds_rt_aot_transport_get_default_name ( return true; #endif } + +uint32_t +ds_rt_aot_set_environment_variable (const ep_char16_t *name, const ep_char16_t *value) +{ +#ifdef TARGET_UNIX + ep_char8_t *nameNarrow = ep_rt_utf16le_to_utf8_string (name, ep_rt_utf16_string_len (name)); + ep_char8_t *valueNarrow = ep_rt_utf16le_to_utf8_string (value, ep_rt_utf16_string_len (value)); + int32_t ret_value = setenv(nameNarrow, valueNarrow, 1); + free(nameNarrow); + free(valueNarrow); + return ret_value; +#else + return SetEnvironmentVariableW(reinterpret_cast(name), reinterpret_cast(value)) ? S_OK : HRESULT_FROM_WIN32(GetLastError()); +#endif +} #endif /* ENABLE_PERFTRACING */ diff --git a/src/coreclr/nativeaot/Runtime/eventpipe/ds-rt-aot.h b/src/coreclr/nativeaot/Runtime/eventpipe/ds-rt-aot.h index 3afd85aac0d93..811a39b574f96 100644 --- a/src/coreclr/nativeaot/Runtime/eventpipe/ds-rt-aot.h +++ b/src/coreclr/nativeaot/Runtime/eventpipe/ds-rt-aot.h @@ -266,9 +266,8 @@ static uint32_t ds_rt_set_environment_variable (const ep_char16_t *name, const ep_char16_t *value) { - // return SetEnvironmentVariableW(reinterpret_cast(name), reinterpret_cast(value)) ? S_OK : HRESULT_FROM_WIN32(GetLastError()); - // PalDebugBreak(); - return 0xffff; + extern uint32_t ds_rt_aot_set_environment_variable (const ep_char16_t *name, const ep_char16_t *value); + return ds_rt_aot_set_environment_variable(name, value); } static diff --git a/src/coreclr/nativeaot/Runtime/eventpipe/ep-rt-aot.cpp b/src/coreclr/nativeaot/Runtime/eventpipe/ep-rt-aot.cpp index f7793b4065f53..90d2c27523c28 100644 --- a/src/coreclr/nativeaot/Runtime/eventpipe/ep-rt-aot.cpp +++ b/src/coreclr/nativeaot/Runtime/eventpipe/ep-rt-aot.cpp @@ -669,6 +669,44 @@ bool ep_rt_aot_spin_lock_release (ep_rt_spin_lock_handle_t *spin_lock) return false; } +#ifndef HOST_WIN32 +#if defined(__APPLE__) +#if defined (HOST_OSX) +extern "C" {char ***_NSGetEnviron(void);} +#define environ (*_NSGetEnviron()) +#else +static char *_ep_rt_aot_environ[1] = { NULL }; +#define environ _ep_rt_aot_environ +#endif /* defined (HOST_OSX) */ +#else +extern "C" { +extern char **environ; +} +#endif /* defined (__APPLE__) */ +#endif /* !defined (HOST_WIN32) */ + +void ep_rt_aot_os_environment_get_utf16 (dn_vector_ptr_t *env_array) +{ + STATIC_CONTRACT_NOTHROW; + EP_ASSERT (env_array != NULL); + +#ifdef HOST_WIN32 + ep_char16_t * envs = reinterpret_cast(GetEnvironmentStringsW ()); + if (envs) { + const ep_char16_t * next = envs; + while (*next) { + dn_vector_ptr_push_back (env_array, ep_rt_utf16_string_dup (reinterpret_cast(next))); + next += ep_rt_utf16_string_len (reinterpret_cast(next)) + 1; + } + FreeEnvironmentStringsW (reinterpret_cast(envs)); + } +#else + ep_char8_t **next = NULL; + for (next = environ; *next != NULL; ++next) + dn_vector_ptr_push_back (env_array, ep_rt_utf8_to_utf16le_string (*next, -1)); +#endif +} + #ifdef EP_CHECKED_BUILD void ep_rt_aot_lock_requires_lock_held (const ep_rt_lock_handle_t *lock) diff --git a/src/coreclr/nativeaot/Runtime/eventpipe/ep-rt-aot.h b/src/coreclr/nativeaot/Runtime/eventpipe/ep-rt-aot.h index 899c949821683..25c9666b78c01 100644 --- a/src/coreclr/nativeaot/Runtime/eventpipe/ep-rt-aot.h +++ b/src/coreclr/nativeaot/Runtime/eventpipe/ep-rt-aot.h @@ -1114,10 +1114,8 @@ static void ep_rt_os_environment_get_utf16 (dn_vector_ptr_t *env_array) { - STATIC_CONTRACT_NOTHROW; - EP_ASSERT (env_array != NULL); - - // PalDebugBreak(); + extern void ep_rt_aot_os_environment_get_utf16 (dn_vector_ptr_t *env_array); + ep_rt_aot_os_environment_get_utf16(env_array); } /* diff --git a/src/tests/tracing/eventpipe/processenvironment/processenvironment.csproj b/src/tests/tracing/eventpipe/processenvironment/processenvironment.csproj index 4cf5a34c0c141..ddab20e07466b 100644 --- a/src/tests/tracing/eventpipe/processenvironment/processenvironment.csproj +++ b/src/tests/tracing/eventpipe/processenvironment/processenvironment.csproj @@ -8,6 +8,7 @@ true true true + true