Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
6bcee99
Exclude usage from ceeload
huoyaoyuan Mar 5, 2026
8abab31
Remove GetCommandLineW
huoyaoyuan Mar 6, 2026
caf4613
Update usage in SaveManagedCommandLine
huoyaoyuan Mar 8, 2026
f7339b1
Remove commandline initialization
huoyaoyuan Mar 10, 2026
7544b8f
Remove exePath from PAL_InitializeCoreCLR
huoyaoyuan Mar 10, 2026
455fd51
Fix Windows build
huoyaoyuan Mar 11, 2026
393300e
Return empty instead of NULL.
huoyaoyuan Mar 12, 2026
908812f
Merge branch 'main' into pal/commandline
huoyaoyuan Mar 13, 2026
3a8cdee
Store exe path
huoyaoyuan Mar 15, 2026
6e4496e
Merge branch 'main' into pal/commandline
huoyaoyuan Mar 15, 2026
2010eaf
Merge branch 'main' into pal/commandline
huoyaoyuan Mar 17, 2026
25b94f1
Merge branch 'main'
huoyaoyuan May 11, 2026
b3ad33f
Merge branch 'main' into pal/commandline
huoyaoyuan May 13, 2026
582181e
Exclude headers for DAC
huoyaoyuan May 14, 2026
3392b17
Merge branch 'main' into pal/commandline
huoyaoyuan May 27, 2026
afd4a29
Rename and add documentation
huoyaoyuan May 27, 2026
1c27fbb
Cleanup InitializeProcessCommandLine
huoyaoyuan May 28, 2026
0fd3bde
Consolidate GetManagedCommandLine
huoyaoyuan May 28, 2026
f4935fd
Update src/coreclr/vm/ceeload.cpp
huoyaoyuan May 28, 2026
27d670c
Use VolatileLoadWithoutBarrier
huoyaoyuan May 29, 2026
6c283cd
Apply suggestion from @jkotas
jkotas Jun 4, 2026
e0f62a3
Merge branch 'main' into pal/commandline
jkotas Jun 4, 2026
30e1b3b
Apply suggestion from @jkotas
jkotas Jun 4, 2026
baf1597
Apply suggestion from @jkotas
jkotas Jun 5, 2026
a72e00c
Apply suggestion from @jkotas
jkotas Jun 5, 2026
f4ea13e
Apply suggestion from @jkotas
jkotas Jun 5, 2026
e7dd8d1
Potential fix for pull request finding
jkotas Jun 5, 2026
a839b3c
Apply suggestion from @jkotas
jkotas Jun 5, 2026
4c6a46c
Remove stale comment
huoyaoyuan Jun 5, 2026
acf3ff9
Handle null terminator
huoyaoyuan Jun 5, 2026
e42b622
Fix missing bracket
huoyaoyuan Jun 6, 2026
96f0fe4
Merge branch 'main'
huoyaoyuan Jun 6, 2026
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
2 changes: 1 addition & 1 deletion src/coreclr/dlls/mscoree/exports.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,7 @@ int coreclr_initialize(
&hostContract);

#ifdef TARGET_UNIX
DWORD error = PAL_InitializeCoreCLR(exePath, g_coreclr_embedded);
DWORD error = PAL_InitializeCoreCLR(g_coreclr_embedded);
hr = HRESULT_FROM_WIN32(error);

// If PAL initialization failed, then we should return right away and avoid
Expand Down
11 changes: 1 addition & 10 deletions src/coreclr/pal/inc/pal.h
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ PALIMPORT
DWORD
PALAPI
PAL_InitializeCoreCLR(
const char *szExePath, BOOL runningInExe);
BOOL runningInExe);

/// <summary>
/// This function shuts down PAL WITHOUT exiting the current process.
Expand Down Expand Up @@ -3303,15 +3303,6 @@ PALAPI
SetLastError(
IN DWORD dwErrCode);

PALIMPORT
LPWSTR
PALAPI
GetCommandLineW();

#ifdef UNICODE
#define GetCommandLine GetCommandLineW
#endif

PALIMPORT
VOID
PALAPI
Expand Down
16 changes: 0 additions & 16 deletions src/coreclr/pal/src/include/pal/process.h
Original file line number Diff line number Diff line change
Expand Up @@ -69,22 +69,6 @@ Notes :
--*/
BOOL PROCCreateInitialProcess(LPWSTR lpwstrCmdLine, LPWSTR lpwstrFullPath);

/*++
Function:
PROCCleanupInitialProcess

Abstract
Cleanup all the structures for the initial process.

Parameter
VOID

Return
VOID

--*/
VOID PROCCleanupInitialProcess(VOID);

/*++
Function
PROCAbortInitialize()
Expand Down
6 changes: 0 additions & 6 deletions src/coreclr/pal/src/include/pal/procobj.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,6 @@ Module Name:

namespace CorUnix
{
PAL_ERROR
InitializeProcessCommandLine(
LPWSTR lpwstrCmdLine,
LPWSTR lpwstrFullPath
);

PAL_ERROR
CreateInitialProcessAndThreadObjects(
CPalThread *pThread
Expand Down
208 changes: 24 additions & 184 deletions src/coreclr/pal/src/init/pal.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -114,10 +114,8 @@ static minipal_mutex* init_critsec = NULL;

static DWORD g_initializeDLLFlags = PAL_INITIALIZE_DLL;

static int Initialize(int argc, const char *const argv[], DWORD flags);
static LPWSTR INIT_FormatCommandLine (int argc, const char * const *argv);
static int Initialize(DWORD flags);
static LPWSTR INIT_GetCurrentEXEPath();
static BOOL INIT_SharedFilesPath(void);

/*++
Function:
Expand All @@ -139,7 +137,7 @@ PAL_Initialize(
int argc,
char *const argv[])
{
return Initialize(argc, argv, PAL_INITIALIZE);
return Initialize(PAL_INITIALIZE);
}

/*++
Expand All @@ -163,7 +161,7 @@ PAL_InitializeWithFlags(
const char *const argv[],
DWORD flags)
{
return Initialize(argc, argv, flags);
return Initialize(flags);
}

/*++
Expand All @@ -182,7 +180,7 @@ int
PALAPI
PAL_InitializeDLL()
{
return Initialize(0, nullptr, g_initializeDLLFlags);
return Initialize(g_initializeDLLFlags);
}

/*++
Expand Down Expand Up @@ -285,22 +283,19 @@ InitializeDefaultStackSize()
--*/
int
Initialize(
int argc,
const char *const argv[],
DWORD flags)
{
PAL_ERROR palError = ERROR_GEN_FAILURE;
CPalThread *pThread = nullptr;
CListedObjectManager *plom = nullptr;
LPWSTR command_line = nullptr;
LPWSTR exe_path = nullptr;
int retval = -1;
bool fFirstTimeInit = false;

/* the first ENTRY within the first call to PAL_Initialize is a special
case, since debug channels are not initialized yet. So in that case the
ENTRY will be called after the DBG channels initialization */
ENTRY_EXTERNAL("PAL_Initialize(argc = %d argv = %p)\n", argc, argv);
ENTRY_EXTERNAL("PAL_Initialize\n");

/*Firstly initiate a lastError */
SetLastError(ERROR_GEN_FAILURE);
Expand Down Expand Up @@ -467,50 +462,25 @@ Initialize(

palError = ERROR_GEN_FAILURE;

if (argc > 0 && argv != nullptr)
/* find out the application's full path */
exe_path = INIT_GetCurrentEXEPath();
if (nullptr == exe_path)
{
/* build the command line */
command_line = INIT_FormatCommandLine(argc, argv);
if (nullptr == command_line)
{
ERROR("Error building command line\n");
palError = ERROR_PALINIT_COMMAND_LINE;
goto CLEANUP1d;
}

/* find out the application's full path */
exe_path = INIT_GetCurrentEXEPath();
if (nullptr == exe_path)
{
ERROR("Unable to find exe path\n");
palError = ERROR_PALINIT_CONVERT_EXE_PATH;
goto CLEANUP1e;
}

palError = InitializeProcessCommandLine(
command_line,
exe_path);

if (NO_ERROR != palError)
{
ERROR("Unable to initialize command line\n");
goto CLEANUP2;
}

// InitializeProcessCommandLine took ownership of this memory.
command_line = nullptr;

if (!LOADSetExeName(exe_path))
{
ERROR("Unable to set exe name\n");
palError = ERROR_PALINIT_SET_EXE_NAME;
goto CLEANUP2;
}
ERROR("Unable to find exe path\n");
palError = ERROR_PALINIT_CONVERT_EXE_PATH;
goto CLEANUP1e;
}

// LOADSetExeName took ownership of this memory.
exe_path = nullptr;
if (!LOADSetExeName(exe_path))
{
ERROR("Unable to set exe name\n");
palError = ERROR_PALINIT_SET_EXE_NAME;
goto CLEANUP2;
}

// LOADSetExeName took ownership of this memory.
exe_path = nullptr;

if (init_count == 0)
{
//
Expand Down Expand Up @@ -600,12 +570,10 @@ Initialize(
CLEANUP10:
MAPCleanup();
CLEANUP6:
PROCCleanupInitialProcess();
// Cleanup initial process data
CLEANUP2:
free(exe_path);
CLEANUP1e:
free(command_line);
CLEANUP1d:
// Cleanup synchronization manager
CLEANUP1c:
// Cleanup object manager
Expand Down Expand Up @@ -642,8 +610,7 @@ Initialize(
PAL_InitializeCoreCLR

Abstract:
A replacement for PAL_Initialize when loading CoreCLR. Instead of taking a command line (which CoreCLR
instances aren't given anyway) the path into which the CoreCLR is installed is supplied instead.
A replacement for PAL_Initialize when loading CoreCLR.

This routine also makes sure the psuedo dynamic libraries PALRT and mscorwks have their initialization
methods called.
Expand All @@ -655,12 +622,11 @@ Initialize(
--*/
PAL_ERROR
PALAPI
PAL_InitializeCoreCLR(const char *szExePath, BOOL runningInExe)
PAL_InitializeCoreCLR(BOOL runningInExe)
Comment thread
huoyaoyuan marked this conversation as resolved.
{
g_running_in_exe = runningInExe;

// Fake up a command line to call PAL initialization with.
int result = Initialize(1, &szExePath, PAL_INITIALIZE_CORECLR);
int result = Initialize(PAL_INITIALIZE_CORECLR);
if (result != 0)
{
return GetLastError();
Expand Down Expand Up @@ -851,132 +817,6 @@ void PALInitUnlock(void)

/* Internal functions *********************************************************/

/*++
Function:
INIT_FormatCommandLine [Internal]

Abstract:
This function converts an array of arguments (argv) into a Unicode
command-line for use by GetCommandLineW

Parameters :
int argc : number of arguments in argv
char **argv : argument list in an array of NULL-terminated strings

Return value :
pointer to Unicode command line. This is a buffer allocated with malloc;
caller is responsible for freeing it with free()

Note : not all peculiarities of Windows command-line processing are supported;

-what is supported :
-arguments with white-space must be double quoted (we'll just double-quote
all arguments to simplify things)
-some characters must be escaped with \ : particularly, the double-quote,
to avoid confusion with the double-quotes at the start and end of
arguments, and \ itself, to avoid confusion with escape sequences.
-what is not supported:
-under Windows, \\ is interpreted as an escaped \ ONLY if it's followed by
an escaped double-quote \". \\\" is passed to argv as \", but \\a is
passed to argv as \\a... there may be other similar cases
-there may be other characters which must be escaped
--*/
static LPWSTR INIT_FormatCommandLine (int argc, const char * const *argv)
{
LPWSTR retval;
LPSTR command_line=nullptr, command_ptr;
LPCSTR arg_ptr;
INT length, i,j;
BOOL bQuoted = FALSE;

/* list of characters that need no be escaped with \ when building the
command line. currently " and \ */
LPCSTR ESCAPE_CHARS="\"\\";

/* allocate temporary memory for the string. Play it safe :
double the length of each argument (in case they're composed
exclusively of escaped characters), and add 3 (for the double-quotes
and separating space). This is temporary anyway, we return a LPWSTR */
length=0;
for(i=0; i<argc; i++)
{
TRACE("argument %d is %s\n", i, argv[i]);
length+=3;
length+=strlen(argv[i])*2;
}
command_line = reinterpret_cast<LPSTR>(malloc(length != 0 ? length : 1));

if(!command_line)
{
ERROR("couldn't allocate memory for command line!\n");
return nullptr;
}

command_ptr=command_line;
for(i=0; i<argc; i++)
{
/* double-quote at beginning of argument containing at least one space */
for(j = 0; (argv[i][j] != 0) && (!isspace((unsigned char) argv[i][j])); j++);

if (argv[i][j] != 0)
{
*command_ptr++='"';
bQuoted = TRUE;
}
/* process the argument one character at a time */
for(arg_ptr=argv[i]; *arg_ptr; arg_ptr++)
{
/* if character needs to be escaped, prepend a \ to it. */
if( strchr(ESCAPE_CHARS,*arg_ptr))
{
*command_ptr++='\\';
}

/* now we can copy the actual character over. */
*command_ptr++=*arg_ptr;
}
/* double-quote at end of argument; space to separate arguments */
if (bQuoted == TRUE)
{
*command_ptr++='"';
bQuoted = FALSE;
}
*command_ptr++=' ';
}
/* replace the last space with a NULL terminator */
command_ptr--;
*command_ptr='\0';

/* convert to Unicode */
i = MultiByteToWideChar(CP_ACP, 0,command_line, -1, nullptr, 0);
if (i == 0)
{
ASSERT("MultiByteToWideChar failure\n");
free(command_line);
return nullptr;
}

retval = reinterpret_cast<LPWSTR>(malloc((sizeof(WCHAR)*i)));
if(retval == nullptr)
{
ERROR("can't allocate memory for Unicode command line!\n");
free(command_line);
return nullptr;
}

if(!MultiByteToWideChar(CP_ACP, 0,command_line, -1, retval, i))
{
ASSERT("MultiByteToWideChar failure\n");
free(retval);
retval = nullptr;
}
else
TRACE("Command line is %s\n", command_line);

free(command_line);
return retval;
}

/*++
Function:
INIT_GetCurrentEXEPath
Expand Down
Loading
Loading