From 6e7601e3ded21aef72072d1e1b37854aa2c2da70 Mon Sep 17 00:00:00 2001 From: Huo Yaoyuan Date: Thu, 4 Jun 2026 07:05:47 +0800 Subject: [PATCH 1/9] Only support current process in PROCEndProcess --- src/coreclr/pal/src/thread/process.cpp | 85 ++++++++------------------ 1 file changed, 27 insertions(+), 58 deletions(-) diff --git a/src/coreclr/pal/src/thread/process.cpp b/src/coreclr/pal/src/thread/process.cpp index 25902fcea08b8c..497c79a45dd693 100644 --- a/src/coreclr/pal/src/thread/process.cpp +++ b/src/coreclr/pal/src/thread/process.cpp @@ -455,78 +455,47 @@ RaiseFailFastException( little extra work before exiting. Most importantly, it won't shut down any DLLs that are loaded. + Only terminating current process is supported. + --*/ static BOOL PROCEndProcess(HANDLE hProcess, UINT uExitCode, BOOL bTerminateUnconditionally) { - DWORD dwProcessId; BOOL ret = FALSE; - dwProcessId = PROCGetProcessIDFromHandle(hProcess); - if (dwProcessId == 0) + _ASSERTE (hProcess != hPseudoCurrentProcess); + + // WARN/ERROR before starting the termination process and/or leaving the PAL. + if (bTerminateUnconditionally) { - SetLastError(ERROR_INVALID_HANDLE); + WARN("exit code 0x%x ignored for terminate.\n", uExitCode); } - else if(dwProcessId != GetCurrentProcessId()) + else if ((uExitCode & 0xff) != uExitCode) { - if (uExitCode != 0) - WARN("exit code 0x%x ignored for external process.\n", uExitCode); - - if (kill(dwProcessId, SIGKILL) == 0) - { - ret = TRUE; - } - else - { - switch (errno) { - case ESRCH: - SetLastError(ERROR_INVALID_HANDLE); - break; - case EPERM: - SetLastError(ERROR_ACCESS_DENIED); - break; - default: - // Unexpected failure. - ASSERT(FALSE); - SetLastError(ERROR_INTERNAL_ERROR); - break; - } - } + // TODO: Convert uExitCodes into sysexits(3)? + ERROR("exit() only supports the lower 8-bits of an exit code. " + "status will only see error 0x%x instead of 0x%x.\n", uExitCode & 0xff, uExitCode); } - else - { - // WARN/ERROR before starting the termination process and/or leaving the PAL. - if (bTerminateUnconditionally) - { - WARN("exit code 0x%x ignored for terminate.\n", uExitCode); - } - else if ((uExitCode & 0xff) != uExitCode) - { - // TODO: Convert uExitCodes into sysexits(3)? - ERROR("exit() only supports the lower 8-bits of an exit code. " - "status will only see error 0x%x instead of 0x%x.\n", uExitCode & 0xff, uExitCode); - } - - TerminateCurrentProcessNoExit(bTerminateUnconditionally); - LOGEXIT("PROCEndProcess will not return\n"); + TerminateCurrentProcessNoExit(bTerminateUnconditionally); - if (bTerminateUnconditionally) - { - // abort() has the semantics that - // (1) it doesn't run atexit handlers - // (2) can invoke CrashReporter or produce a coredump, which is appropriate for TerminateProcess calls - // TerminationRequestHandlingRoutine in synchmanager.cpp sets the exit code to this special value. The - // Watson analyzer needs to know that the process was terminated with a SIGTERM. - PROCAbort(uExitCode == (128 + SIGTERM) ? SIGTERM : SIGABRT); - } - else - { - exit(uExitCode); - } + LOGEXIT("PROCEndProcess will not return\n"); - ASSERT(FALSE); // we shouldn't get here + if (bTerminateUnconditionally) + { + // abort() has the semantics that + // (1) it doesn't run atexit handlers + // (2) can invoke CrashReporter or produce a coredump, which is appropriate for TerminateProcess calls + // TerminationRequestHandlingRoutine in synchmanager.cpp sets the exit code to this special value. The + // Watson analyzer needs to know that the process was terminated with a SIGTERM. + PROCAbort(uExitCode == (128 + SIGTERM) ? SIGTERM : SIGABRT); + } + else + { + exit(uExitCode); } + ASSERT(FALSE); // we shouldn't get here + return ret; } From e2f89ffa9165f993fe5e18f5de2402fa33756911 Mon Sep 17 00:00:00 2001 From: Huo Yaoyuan Date: Thu, 4 Jun 2026 07:23:09 +0800 Subject: [PATCH 2/9] Remove GetCurrentSessionId --- src/coreclr/pal/src/include/pal/palinternal.h | 2 -- src/coreclr/pal/src/include/pal/process.h | 3 +-- src/coreclr/pal/src/init/pal.cpp | 3 +-- src/coreclr/pal/src/thread/process.cpp | 23 +------------------ 4 files changed, 3 insertions(+), 28 deletions(-) diff --git a/src/coreclr/pal/src/include/pal/palinternal.h b/src/coreclr/pal/src/include/pal/palinternal.h index 8c610758a998d5..871fb86ed65ddf 100644 --- a/src/coreclr/pal/src/include/pal/palinternal.h +++ b/src/coreclr/pal/src/include/pal/palinternal.h @@ -332,6 +332,4 @@ const char StackOverflowMessage[] = "Stack overflow.\n"; #endif // __cplusplus -DWORD PALAPI GetCurrentSessionId(); - #endif /* _PAL_INTERNAL_H_ */ diff --git a/src/coreclr/pal/src/include/pal/process.h b/src/coreclr/pal/src/include/pal/process.h index e3f26bde875a03..d123415616b8c9 100644 --- a/src/coreclr/pal/src/include/pal/process.h +++ b/src/coreclr/pal/src/include/pal/process.h @@ -37,9 +37,8 @@ extern "C" */ extern Volatile terminator; -// The process and session ID of this process, so we can avoid excessive calls to getpid() and getsid(). +// The process ID of this process, so we can avoid excessive calls to getpid(). extern DWORD gPID; -extern DWORD gSID; extern LPWSTR pAppDir; diff --git a/src/coreclr/pal/src/init/pal.cpp b/src/coreclr/pal/src/init/pal.cpp index d261ce80c898a7..6c5c9989a2bb3f 100644 --- a/src/coreclr/pal/src/init/pal.cpp +++ b/src/coreclr/pal/src/init/pal.cpp @@ -331,9 +331,8 @@ Initialize( if (init_count == 0) { - // Set our pid and sid. + // Set our pid. gPID = getpid(); - gSID = getsid(gPID); // Initialize the thread local storage if (FALSE == TLSInitialize()) diff --git a/src/coreclr/pal/src/thread/process.cpp b/src/coreclr/pal/src/thread/process.cpp index 497c79a45dd693..1bc443382373f3 100644 --- a/src/coreclr/pal/src/thread/process.cpp +++ b/src/coreclr/pal/src/thread/process.cpp @@ -152,9 +152,8 @@ Volatile terminator = 0; // Id of thread generating a core dump Volatile g_crashingThreadId = 0; -// Process and session ID of this process. +// Process ID of this process. DWORD gPID = (DWORD) -1; -DWORD gSID = (DWORD) -1; // Application group ID for this process #ifdef __APPLE__ @@ -274,26 +273,6 @@ GetCurrentProcessId( } -/*++ -Function: - GetCurrentSessionId - -See MSDN doc. ---*/ -DWORD -PALAPI -GetCurrentSessionId( - VOID) -{ - PERF_ENTRY(GetCurrentSessionId); - ENTRY("GetCurrentSessionId()\n" ); - - LOGEXIT("GetCurrentSessionId returns DWORD %#x\n", gSID); - PERF_EXIT(GetCurrentSessionId); - return gSID; -} - - /*++ Function: GetCurrentProcess From f81a6a0789e00542eee57e591e88dbbb37df6087 Mon Sep 17 00:00:00 2001 From: Huo Yaoyuan Date: Thu, 4 Jun 2026 15:00:31 +0800 Subject: [PATCH 3/9] Remove non-local process support from handleapi --- src/coreclr/pal/src/handlemgr/handleapi.cpp | 35 +---------- src/coreclr/pal/src/include/pal/process.h | 9 --- src/coreclr/pal/src/include/pal/procobj.hpp | 4 -- src/coreclr/pal/src/thread/process.cpp | 64 --------------------- 4 files changed, 3 insertions(+), 109 deletions(-) diff --git a/src/coreclr/pal/src/handlemgr/handleapi.cpp b/src/coreclr/pal/src/handlemgr/handleapi.cpp index 5f08f2fae51423..5550ae584e9208 100644 --- a/src/coreclr/pal/src/handlemgr/handleapi.cpp +++ b/src/coreclr/pal/src/handlemgr/handleapi.cpp @@ -107,31 +107,12 @@ CorUnix::InternalDuplicateHandle( PAL_ERROR palError = NO_ERROR; IPalObject *pobjSource = NULL; - DWORD source_process_id; - DWORD target_process_id; DWORD cur_process_id; cur_process_id = GetCurrentProcessId(); - source_process_id = PROCGetProcessIDFromHandle(hSourceProcess); - target_process_id = PROCGetProcessIDFromHandle(hTargetProcess); - - /* Check validity of process handles */ - if (0 == source_process_id || 0 == target_process_id) - { - ASSERT("Can't duplicate handle: invalid source or destination process"); - palError = ERROR_INVALID_PARAMETER; - goto InternalDuplicateHandleExit; - } - - /* At least source or target process should be the current process. */ - if (source_process_id != cur_process_id - && target_process_id != cur_process_id) - { - ASSERT("Can't duplicate handle : neither source or destination" - "processes are from current process"); - palError = ERROR_INVALID_PARAMETER; - goto InternalDuplicateHandleExit; - } + /* We do not support other process in PAL */ + _ASSERTE(hSourceProcess == hPseudoCurrentProcess); + _ASSERTE(hTargetProcess == hPseudoCurrentProcess); if (FALSE != bInheritHandle) { @@ -169,16 +150,6 @@ CorUnix::InternalDuplicateHandle( goto InternalDuplicateHandleExit; } - // Handles can't be remoted cross-process. - // Just return the same handle. - if (source_process_id != cur_process_id - || target_process_id != cur_process_id) - { - *phDuplicate = hSource; - palError = NO_ERROR; - goto InternalDuplicateHandleExit; - } - // // Obtain the source IPalObject // diff --git a/src/coreclr/pal/src/include/pal/process.h b/src/coreclr/pal/src/include/pal/process.h index d123415616b8c9..b15d2ab837a696 100644 --- a/src/coreclr/pal/src/include/pal/process.h +++ b/src/coreclr/pal/src/include/pal/process.h @@ -49,15 +49,6 @@ extern int gApplicationGroupIdLength; #endif // __APPLE__ extern PathCharString *gSharedFilesPath; -/*++ -Function: - PROCGetProcessIDFromHandle - -Abstract - Return the process ID from a process handle ---*/ -DWORD PROCGetProcessIDFromHandle(HANDLE hProcess); - /*++ Function: PROCCreateInitialProcess diff --git a/src/coreclr/pal/src/include/pal/procobj.hpp b/src/coreclr/pal/src/include/pal/procobj.hpp index c1e10df2b44166..3391828d8d2091 100644 --- a/src/coreclr/pal/src/include/pal/procobj.hpp +++ b/src/coreclr/pal/src/include/pal/procobj.hpp @@ -48,16 +48,12 @@ namespace CorUnix { public: CProcProcessLocalData() - : - dwProcessId(0) { }; ~CProcProcessLocalData() { }; - - DWORD dwProcessId; }; PAL_ERROR diff --git a/src/coreclr/pal/src/thread/process.cpp b/src/coreclr/pal/src/thread/process.cpp index 1bc443382373f3..8c938a3c75513a 100644 --- a/src/coreclr/pal/src/thread/process.cpp +++ b/src/coreclr/pal/src/thread/process.cpp @@ -1998,69 +1998,6 @@ PROCAbort(int signal, siginfo_t* siginfo, void* context) } \ while(0) -/*++ -Function: - PROCGetProcessIDFromHandle - -Abstract - Return the process ID from a process handle - -Parameter - hProcess: process handle - -Return - Return the process ID, or 0 if it's not a valid handle ---*/ -DWORD -PROCGetProcessIDFromHandle( - HANDLE hProcess) -{ - PAL_ERROR palError; - IPalObject *pobjProcess = NULL; - CPalThread *pThread = InternalGetCurrentThread(); - - DWORD dwProcessId = 0; - - if (hPseudoCurrentProcess == hProcess) - { - dwProcessId = gPID; - goto PROCGetProcessIDFromHandleExit; - } - - - palError = g_pObjectManager->ReferenceObjectByHandle( - pThread, - hProcess, - &aotProcess, - &pobjProcess - ); - - if (NO_ERROR == palError) - { - IDataLock *pDataLock; - CProcProcessLocalData *pLocalData; - - palError = pobjProcess->GetProcessLocalData( - pThread, - ReadLock, - &pDataLock, - reinterpret_cast(&pLocalData) - ); - - if (NO_ERROR == palError) - { - dwProcessId = pLocalData->dwProcessId; - pDataLock->ReleaseLock(pThread, FALSE); - } - - pobjProcess->ReleaseReference(pThread); - } - -PROCGetProcessIDFromHandleExit: - - return dwProcessId; -} - /*++ Function InitializeProcessCommandLine @@ -2209,7 +2146,6 @@ CorUnix::CreateInitialProcessAndThreadObjects( goto CreateInitialProcessAndThreadObjectsExit; } - pLocalData->dwProcessId = gPID; pDataLock->ReleaseLock(pThread, TRUE); palError = g_pObjectManager->RegisterObject( From c8d3e8104da78ae447acc074ecd5f5b616ba75c0 Mon Sep 17 00:00:00 2001 From: Huo Yaoyuan Date: Thu, 4 Jun 2026 15:11:31 +0800 Subject: [PATCH 4/9] Remove CProcProcessLocalData --- src/coreclr/pal/src/include/pal/procobj.hpp | 31 --------------------- src/coreclr/pal/src/thread/process.cpp | 19 +------------ 2 files changed, 1 insertion(+), 49 deletions(-) diff --git a/src/coreclr/pal/src/include/pal/procobj.hpp b/src/coreclr/pal/src/include/pal/procobj.hpp index 3391828d8d2091..9344d8b3320cc4 100644 --- a/src/coreclr/pal/src/include/pal/procobj.hpp +++ b/src/coreclr/pal/src/include/pal/procobj.hpp @@ -25,37 +25,6 @@ namespace CorUnix { extern CObjectType otProcess; - // - // Ideally dwProcessId would be part of the process object's immutable - // data. Doing so, though, creates complications in CreateProcess. The - // contents of the immutable data for a new object must be set before - // that object is registered with the object manager (as the object - // manager may make a copy of the immutable data). The PID for a new - // process, though, is not known until after creation. Registering the - // process object after process creation creates an undesirable error path - // -- if we are not able to register the process object (say, because of - // a low resource condition) we would be forced to return an error to - // the caller of CreateProcess, even though the new process was actually - // created... - // - // Note: we could work around this by effectively always going down - // the create suspended path. That is, the new process would not exec until - // the parent process released it. It's unclear how much benefit this would - // provide us. - // - - class CProcProcessLocalData - { - public: - CProcProcessLocalData() - { - }; - - ~CProcProcessLocalData() - { - }; - }; - PAL_ERROR InitializeProcessCommandLine( LPWSTR lpwstrCmdLine, diff --git a/src/coreclr/pal/src/thread/process.cpp b/src/coreclr/pal/src/thread/process.cpp index 8c938a3c75513a..f980860d108ce8 100644 --- a/src/coreclr/pal/src/thread/process.cpp +++ b/src/coreclr/pal/src/thread/process.cpp @@ -126,7 +126,7 @@ CObjectType CorUnix::otProcess( 0, // No immutable data NULL, // No immutable data copy routine NULL, // No immutable data cleanup routine - sizeof(CProcProcessLocalData), + 0, // No process local data NULL, // No process local data cleanup routine CObjectType::WaitableObject, CObjectType::SingleTransitionObject, @@ -2095,8 +2095,6 @@ CorUnix::CreateInitialProcessAndThreadObjects( PAL_ERROR palError = NO_ERROR; HANDLE hThread; IPalObject *pobjProcess = NULL; - IDataLock *pDataLock; - CProcProcessLocalData *pLocalData; CObjectAttributes oa; HANDLE hProcess; @@ -2133,21 +2131,6 @@ CorUnix::CreateInitialProcessAndThreadObjects( goto CreateInitialProcessAndThreadObjectsExit; } - palError = pobjProcess->GetProcessLocalData( - pThread, - WriteLock, - &pDataLock, - reinterpret_cast(&pLocalData) - ); - - if (NO_ERROR != palError) - { - ASSERT("Unable to access local data"); - goto CreateInitialProcessAndThreadObjectsExit; - } - - pDataLock->ReleaseLock(pThread, TRUE); - palError = g_pObjectManager->RegisterObject( pThread, pobjProcess, From 8e7d560faf3e52ef7da4d9d939c307a19866e97a Mon Sep 17 00:00:00 2001 From: Huo Yaoyuan Date: Thu, 4 Jun 2026 15:21:25 +0800 Subject: [PATCH 5/9] Remove process object --- src/coreclr/pal/src/handlemgr/handleapi.cpp | 5 +- src/coreclr/pal/src/include/pal/corunix.hpp | 1 - src/coreclr/pal/src/thread/process.cpp | 72 --------------------- 3 files changed, 2 insertions(+), 76 deletions(-) diff --git a/src/coreclr/pal/src/handlemgr/handleapi.cpp b/src/coreclr/pal/src/handlemgr/handleapi.cpp index 5550ae584e9208..b105aa6a3d74ee 100644 --- a/src/coreclr/pal/src/handlemgr/handleapi.cpp +++ b/src/coreclr/pal/src/handlemgr/handleapi.cpp @@ -171,10 +171,9 @@ CorUnix::InternalDuplicateHandle( } else if (hPseudoCurrentProcess == hSource) { + /* NOP - the only pseudo handle is invariant */ TRACE("Duplicating process pseudo handle(%p)\n", hSource); - - pobjSource = g_pobjProcess; - pobjSource->AddReference(); + goto InternalDuplicateHandleExit; } else if (hPseudoCurrentThread == hSource) { diff --git a/src/coreclr/pal/src/include/pal/corunix.hpp b/src/coreclr/pal/src/include/pal/corunix.hpp index f5d9ae6560a858..82ab89a1626e59 100644 --- a/src/coreclr/pal/src/include/pal/corunix.hpp +++ b/src/coreclr/pal/src/include/pal/corunix.hpp @@ -163,7 +163,6 @@ namespace CorUnix otiFile, otiFileMapping, otiSocket, - otiProcess, otiThread, otiIOCompletionPort, ObjectTypeIdCount // This entry must come last in the enumeration diff --git a/src/coreclr/pal/src/thread/process.cpp b/src/coreclr/pal/src/thread/process.cpp index f980860d108ce8..920eb5b0addc8a 100644 --- a/src/coreclr/pal/src/thread/process.cpp +++ b/src/coreclr/pal/src/thread/process.cpp @@ -120,26 +120,6 @@ extern bool g_running_in_exe; using namespace CorUnix; -CObjectType CorUnix::otProcess( - otiProcess, - NULL, // No cleanup routine - 0, // No immutable data - NULL, // No immutable data copy routine - NULL, // No immutable data cleanup routine - 0, // No process local data - NULL, // No process local data cleanup routine - CObjectType::WaitableObject, - CObjectType::SingleTransitionObject, - CObjectType::ThreadReleaseHasNoSideEffects - ); - -CAllowedObjectTypes aotProcess(otiProcess); - -// -// The representative IPalObject for this process -// -IPalObject* CorUnix::g_pobjProcess; - // // The command line and app name for the process // @@ -2094,9 +2074,7 @@ CorUnix::CreateInitialProcessAndThreadObjects( { PAL_ERROR palError = NO_ERROR; HANDLE hThread; - IPalObject *pobjProcess = NULL; CObjectAttributes oa; - HANDLE hProcess; // // Create initial thread object @@ -2114,58 +2092,8 @@ CorUnix::CreateInitialProcessAndThreadObjects( (void) g_pObjectManager->RevokeHandle(pThread, hThread); - // - // Create and initialize process object - // - - palError = g_pObjectManager->AllocateObject( - pThread, - &otProcess, - &oa, - &pobjProcess - ); - - if (NO_ERROR != palError) - { - ERROR("Unable to allocate process object"); - goto CreateInitialProcessAndThreadObjectsExit; - } - - palError = g_pObjectManager->RegisterObject( - pThread, - pobjProcess, - &aotProcess, - &hProcess, - &g_pobjProcess - ); - - // - // pobjProcess is invalidated by the call to RegisterObject, so - // NULL it out here to prevent it from being released later - // - - pobjProcess = NULL; - - if (NO_ERROR != palError) - { - ASSERT("Failure registering process object"); - goto CreateInitialProcessAndThreadObjectsExit; - } - - // - // There's no need to keep this handle around, so revoke - // it now - // - - g_pObjectManager->RevokeHandle(pThread, hProcess); - CreateInitialProcessAndThreadObjectsExit: - if (NULL != pobjProcess) - { - pobjProcess->ReleaseReference(pThread); - } - return palError; } From 838e2d5fa7f6bc137f2035a65b4078b05ab042ed Mon Sep 17 00:00:00 2001 From: Huo Yaoyuan Date: Thu, 4 Jun 2026 15:27:09 +0800 Subject: [PATCH 6/9] Remove handle parameter from PROCEndProcess --- src/coreclr/pal/src/thread/process.cpp | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/coreclr/pal/src/thread/process.cpp b/src/coreclr/pal/src/thread/process.cpp index 920eb5b0addc8a..94ff751db5dac8 100644 --- a/src/coreclr/pal/src/thread/process.cpp +++ b/src/coreclr/pal/src/thread/process.cpp @@ -231,7 +231,7 @@ CreateSemaphoreName( const UnambiguousProcessDescriptor& unambiguousProcessDescriptor, LPCSTR applicationGroupId); -static BOOL PROCEndProcess(HANDLE hProcess, UINT uExitCode, BOOL bTerminateUnconditionally); +static BOOL PROCEndProcess(UINT uExitCode, BOOL bTerminateUnconditionally); /*++ Function: @@ -311,7 +311,7 @@ ExitProcess( else { WARN("thread re-called ExitProcess\n"); - PROCEndProcess(GetCurrentProcess(), uExitCode, FALSE); + PROCEndProcess(uExitCode, FALSE); } } else if (0 != old_terminator) @@ -335,7 +335,7 @@ ExitProcess( */ if (PALInitLock() && PALIsInitialized()) { - PROCEndProcess(GetCurrentProcess(), uExitCode, FALSE); + PROCEndProcess(uExitCode, FALSE); /* Should not get here, because we terminate the current process */ ASSERT("PROCEndProcess has returned\n"); @@ -370,10 +370,12 @@ TerminateProcess( { BOOL ret; + _ASSERTE(hProcess == hPseudoCurrentProcess); + PERF_ENTRY(TerminateProcess); ENTRY("TerminateProcess(hProcess=%p, uExitCode=%u)\n",hProcess, uExitCode ); - ret = PROCEndProcess(hProcess, uExitCode, TRUE); + ret = PROCEndProcess(uExitCode, TRUE); LOGEXIT("TerminateProcess returns BOOL %d\n", ret); PERF_EXIT(TerminateProcess); @@ -417,12 +419,10 @@ RaiseFailFastException( Only terminating current process is supported. --*/ -static BOOL PROCEndProcess(HANDLE hProcess, UINT uExitCode, BOOL bTerminateUnconditionally) +static BOOL PROCEndProcess(UINT uExitCode, BOOL bTerminateUnconditionally) { BOOL ret = FALSE; - _ASSERTE (hProcess != hPseudoCurrentProcess); - // WARN/ERROR before starting the termination process and/or leaving the PAL. if (bTerminateUnconditionally) { From 1158965629f82098ab1749eebc1ac4d15646c8ff Mon Sep 17 00:00:00 2001 From: Huo Yaoyuan Date: Thu, 4 Jun 2026 15:35:25 +0800 Subject: [PATCH 7/9] Remove remaining extern declarations --- src/coreclr/pal/src/include/pal/procobj.hpp | 4 ---- 1 file changed, 4 deletions(-) diff --git a/src/coreclr/pal/src/include/pal/procobj.hpp b/src/coreclr/pal/src/include/pal/procobj.hpp index 9344d8b3320cc4..a53551f03d0234 100644 --- a/src/coreclr/pal/src/include/pal/procobj.hpp +++ b/src/coreclr/pal/src/include/pal/procobj.hpp @@ -23,8 +23,6 @@ Module Name: namespace CorUnix { - extern CObjectType otProcess; - PAL_ERROR InitializeProcessCommandLine( LPWSTR lpwstrCmdLine, @@ -35,8 +33,6 @@ namespace CorUnix CreateInitialProcessAndThreadObjects( CPalThread *pThread ); - - extern IPalObject *g_pobjProcess; } #endif // _PAL_PROCOBJ_HPP_ From 2c0b2943f3d09b91f1080f61f9c4a6786742dc7a Mon Sep 17 00:00:00 2001 From: Huo Yaoyuan Date: Fri, 5 Jun 2026 14:54:48 +0800 Subject: [PATCH 8/9] Assign output in DuplicateHandle --- src/coreclr/pal/src/handlemgr/handleapi.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/coreclr/pal/src/handlemgr/handleapi.cpp b/src/coreclr/pal/src/handlemgr/handleapi.cpp index b105aa6a3d74ee..96befac182d84c 100644 --- a/src/coreclr/pal/src/handlemgr/handleapi.cpp +++ b/src/coreclr/pal/src/handlemgr/handleapi.cpp @@ -171,8 +171,9 @@ CorUnix::InternalDuplicateHandle( } else if (hPseudoCurrentProcess == hSource) { - /* NOP - the only pseudo handle is invariant */ + /* The only pseudo handle is invariant */ TRACE("Duplicating process pseudo handle(%p)\n", hSource); + *phDuplicate = hPseudoCurrentProcess; goto InternalDuplicateHandleExit; } else if (hPseudoCurrentThread == hSource) From c3958fa7b0128f60ba7aaa35b2d23865afab73e8 Mon Sep 17 00:00:00 2001 From: Huo Yaoyuan Date: Fri, 5 Jun 2026 14:56:02 +0800 Subject: [PATCH 9/9] Remove unused cur_process_id --- src/coreclr/pal/src/handlemgr/handleapi.cpp | 3 --- 1 file changed, 3 deletions(-) diff --git a/src/coreclr/pal/src/handlemgr/handleapi.cpp b/src/coreclr/pal/src/handlemgr/handleapi.cpp index 96befac182d84c..adda2aa2110c1e 100644 --- a/src/coreclr/pal/src/handlemgr/handleapi.cpp +++ b/src/coreclr/pal/src/handlemgr/handleapi.cpp @@ -107,9 +107,6 @@ CorUnix::InternalDuplicateHandle( PAL_ERROR palError = NO_ERROR; IPalObject *pobjSource = NULL; - DWORD cur_process_id; - - cur_process_id = GetCurrentProcessId(); /* We do not support other process in PAL */ _ASSERTE(hSourceProcess == hPseudoCurrentProcess); _ASSERTE(hTargetProcess == hPseudoCurrentProcess);