Skip to content
Closed
Show file tree
Hide file tree
Changes from 3 commits
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
17 changes: 11 additions & 6 deletions src/coreclr/nativeaot/Runtime/unix/PalUnix.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
#include <cstdarg>
#include <signal.h>
#include <minipal/thread.h>
#include <minipal/env.h>

#ifdef TARGET_LINUX
#include <sys/syscall.h>
Expand Down Expand Up @@ -981,21 +982,25 @@ UInt32_BOOL PalResetEvent(HANDLE event)

uint32_t PalGetEnvironmentVariable(const char * name, char * buffer, uint32_t size)
{
const char* value = getenv(name);
if (value == NULL)
size_t valueLen = 0;
if (!minipal_env_get_s(&valueLen, buffer, size, name, false))
{
return 0;
}

size_t valueLen = strlen(value);
// minipal_env_get_s returns the length of the value including the null terminator.
if (valueLen > 0)
{
valueLen--;
}

if (valueLen < size)
{
strcpy(buffer, value);
return valueLen;
return (uint32_t)valueLen;
}

// return required size including the null character or 0 if the size doesn't fit into uint32_t
return (valueLen < UINT32_MAX) ? (valueLen + 1) : 0;
return valueLen < UINT32_MAX ? (uint32_t)(valueLen + 1) : 0;
}

uint16_t PalCaptureStackBackTrace(uint32_t arg1, uint32_t arg2, void* arg3, uint32_t* arg4)
Expand Down
1 change: 0 additions & 1 deletion src/coreclr/pal/src/config.h.in
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,6 @@
#define PAL_THREAD_PRIORITY_MIN 0
#define PAL_THREAD_PRIORITY_MAX 0

#cmakedefine01 HAVE__NSGETENVIRON
#cmakedefine01 DEADLOCK_WHEN_THREAD_IS_SUSPENDED_WHILE_BLOCKED_ON_MUTEX
#cmakedefine PAL_PTRACE(cmd, pid, addr, data) @PAL_PTRACE@
#cmakedefine01 SYNCHMGR_SUSPENSION_SAFE_CONDITION_SIGNALING
Expand Down
1 change: 0 additions & 1 deletion src/coreclr/pal/src/configure.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -890,7 +890,6 @@ if(NOT CLR_CMAKE_HOST_ARCH_ARM AND NOT CLR_CMAKE_HOST_ARCH_ARM64)
endif()

if(CLR_CMAKE_TARGET_APPLE)
set(HAVE__NSGETENVIRON 1)
set(DEADLOCK_WHEN_THREAD_IS_SUSPENDED_WHILE_BLOCKED_ON_MUTEX 1)
set(PAL_PTRACE "ptrace((cmd), (pid), (caddr_t)(addr), (data))")
set(HAVE_SCHED_OTHER_ASSIGNABLE 1)
Expand Down
7 changes: 2 additions & 5 deletions src/coreclr/pal/src/debug/debug.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -160,11 +160,8 @@ OutputDebugStringA(
lpOutputString ? lpOutputString : "NULL");

// As we don't support debug events, we are going to output the debug string
// to stderr instead of generating OUT_DEBUG_STRING_EVENT. It's safe to tell
// EnvironGetenv not to make a copy of the value here since we only want to
// check whether it exists, not actually use it.
if ((lpOutputString != NULL) &&
(NULL != EnvironGetenv(PAL_OUTPUTDEBUGSTRING, /* copyValue */ FALSE)))
// to stderr instead of generating OUT_DEBUG_STRING_EVENT.
if ((lpOutputString != NULL) && (EnvironCheckenv(PAL_OUTPUTDEBUGSTRING)))
{
fprintf(stderr, "%s", lpOutputString);
}
Expand Down
2 changes: 1 addition & 1 deletion src/coreclr/pal/src/exception/machmessage.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ using namespace CorUnix;

#ifdef _DEBUG

#define NONPAL_TRACE_ENABLED EnvironGetenv("NONPAL_TRACING", /* copyValue */ false)
#define NONPAL_TRACE_ENABLED EnvironCheckenv("NONPAL_TRACING")

#define NONPAL_ASSERT(_msg, ...) NONPAL_RETAIL_ASSERT(_msg, __VA_ARGS__)

Expand Down
31 changes: 20 additions & 11 deletions src/coreclr/pal/src/include/pal/environ.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,32 +26,41 @@ extern "C"
#endif // __cplusplus

/*++
Variables :

palEnvironment: a global variable equivalent to environ on systems on
which that exists, and a pointer to an array of environment
strings on systems without environ.
gcsEnvironment: critical section to synchronize access to palEnvironment
Function:
EnvironInitialize

Initialization function for the PAL environment code.
--*/
extern char **palEnvironment;
extern minipal_mutex gcsEnvironment;
BOOL EnvironInitialize();

/*++
Function:
EnvironGetUnsafe

Get the current environment. This is similar accessing
global environ variable and is not thread safe. This function
should only be called from code that guarantees environment won't
change while using returned pointer.
--*/
char **EnvironGetUnsafe();

/*++
Function:
EnvironInitialize
EnvironCheckenv

Initialization function for the PAL environment code.
Check if environment variable with the given name exists in environment.
--*/
BOOL EnvironInitialize();
BOOL EnvironCheckenv(const char *name);

/*++
Function:
EnvironGetenv

Get the value of environment variable with the given name.
Caller should free the returned string if it is not NULL.
--*/
char *EnvironGetenv(const char *name, BOOL copyValue = TRUE);
char *EnvironGetenv(const char *name);

/*++
Function:
Expand Down
17 changes: 2 additions & 15 deletions src/coreclr/pal/src/misc/dbgmsg.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -705,24 +705,11 @@ bool DBG_ShouldCheckStackAlignment()

if (caMode == CheckAlignment_Uninitialized)
{
char* checkAlignmentSettings;
bool shouldFreeCheckAlignmentSettings = false;
if (palEnvironment == nullptr)
{
// This function might be called before the PAL environment is initialized.
// In this case, use the system getenv instead.
checkAlignmentSettings = ::getenv(PAL_CHECK_ALIGNMENT_MODE);
}
else
{
checkAlignmentSettings = EnvironGetenv(PAL_CHECK_ALIGNMENT_MODE);
shouldFreeCheckAlignmentSettings = true;
}

char* checkAlignmentSettings = EnvironGetenv(PAL_CHECK_ALIGNMENT_MODE);
caMode = checkAlignmentSettings ?
(CheckAlignmentMode)atoi(checkAlignmentSettings) : CheckAlignment_Default;

if (checkAlignmentSettings && shouldFreeCheckAlignmentSettings)
if (checkAlignmentSettings)
{
free(checkAlignmentSettings);
}
Expand Down
Loading
Loading