Skip to content

Commit 6b38e9b

Browse files
huoyaoyuanjkotas
andauthored
Remove process object from PAL (#128975)
The pseudo handle for current process is still used by various api. There's no need to keep the object and ProcLocalData behind. --------- Co-authored-by: Jan Kotas <jkotas@microsoft.com>
1 parent af215ca commit 6b38e9b

7 files changed

Lines changed: 41 additions & 331 deletions

File tree

src/coreclr/pal/src/handlemgr/handleapi.cpp

Lines changed: 6 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -107,31 +107,9 @@ CorUnix::InternalDuplicateHandle(
107107
PAL_ERROR palError = NO_ERROR;
108108
IPalObject *pobjSource = NULL;
109109

110-
DWORD source_process_id;
111-
DWORD target_process_id;
112-
DWORD cur_process_id;
113-
114-
cur_process_id = GetCurrentProcessId();
115-
source_process_id = PROCGetProcessIDFromHandle(hSourceProcess);
116-
target_process_id = PROCGetProcessIDFromHandle(hTargetProcess);
117-
118-
/* Check validity of process handles */
119-
if (0 == source_process_id || 0 == target_process_id)
120-
{
121-
ASSERT("Can't duplicate handle: invalid source or destination process");
122-
palError = ERROR_INVALID_PARAMETER;
123-
goto InternalDuplicateHandleExit;
124-
}
125-
126-
/* At least source or target process should be the current process. */
127-
if (source_process_id != cur_process_id
128-
&& target_process_id != cur_process_id)
129-
{
130-
ASSERT("Can't duplicate handle : neither source or destination"
131-
"processes are from current process");
132-
palError = ERROR_INVALID_PARAMETER;
133-
goto InternalDuplicateHandleExit;
134-
}
110+
/* We do not support other process in PAL */
111+
_ASSERTE(hSourceProcess == hPseudoCurrentProcess);
112+
_ASSERTE(hTargetProcess == hPseudoCurrentProcess);
135113

136114
if (FALSE != bInheritHandle)
137115
{
@@ -169,16 +147,6 @@ CorUnix::InternalDuplicateHandle(
169147
goto InternalDuplicateHandleExit;
170148
}
171149

172-
// Handles can't be remoted cross-process.
173-
// Just return the same handle.
174-
if (source_process_id != cur_process_id
175-
|| target_process_id != cur_process_id)
176-
{
177-
*phDuplicate = hSource;
178-
palError = NO_ERROR;
179-
goto InternalDuplicateHandleExit;
180-
}
181-
182150
//
183151
// Obtain the source IPalObject
184152
//
@@ -200,10 +168,10 @@ CorUnix::InternalDuplicateHandle(
200168
}
201169
else if (hPseudoCurrentProcess == hSource)
202170
{
171+
/* The only pseudo handle is invariant */
203172
TRACE("Duplicating process pseudo handle(%p)\n", hSource);
204-
205-
pobjSource = g_pobjProcess;
206-
pobjSource->AddReference();
173+
*phDuplicate = hPseudoCurrentProcess;
174+
goto InternalDuplicateHandleExit;
207175
}
208176
else if (hPseudoCurrentThread == hSource)
209177
{

src/coreclr/pal/src/include/pal/corunix.hpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,6 @@ namespace CorUnix
163163
otiFile,
164164
otiFileMapping,
165165
otiSocket,
166-
otiProcess,
167166
otiThread,
168167
otiIOCompletionPort,
169168
ObjectTypeIdCount // This entry must come last in the enumeration

src/coreclr/pal/src/include/pal/palinternal.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -332,6 +332,4 @@ const char StackOverflowMessage[] = "Stack overflow.\n";
332332

333333
#endif // __cplusplus
334334

335-
DWORD PALAPI GetCurrentSessionId();
336-
337335
#endif /* _PAL_INTERNAL_H_ */

src/coreclr/pal/src/include/pal/process.h

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,8 @@ extern "C"
3737
*/
3838
extern Volatile<LONG> terminator;
3939

40-
// The process and session ID of this process, so we can avoid excessive calls to getpid() and getsid().
40+
// The process ID of this process, so we can avoid excessive calls to getpid().
4141
extern DWORD gPID;
42-
extern DWORD gSID;
4342

4443
extern LPWSTR pAppDir;
4544

@@ -50,15 +49,6 @@ extern int gApplicationGroupIdLength;
5049
#endif // __APPLE__
5150
extern PathCharString *gSharedFilesPath;
5251

53-
/*++
54-
Function:
55-
PROCGetProcessIDFromHandle
56-
57-
Abstract
58-
Return the process ID from a process handle
59-
--*/
60-
DWORD PROCGetProcessIDFromHandle(HANDLE hProcess);
61-
6252
/*++
6353
Function:
6454
PROCCreateInitialProcess

src/coreclr/pal/src/include/pal/procobj.hpp

Lines changed: 0 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -23,43 +23,6 @@ Module Name:
2323

2424
namespace CorUnix
2525
{
26-
extern CObjectType otProcess;
27-
28-
//
29-
// Ideally dwProcessId would be part of the process object's immutable
30-
// data. Doing so, though, creates complications in CreateProcess. The
31-
// contents of the immutable data for a new object must be set before
32-
// that object is registered with the object manager (as the object
33-
// manager may make a copy of the immutable data). The PID for a new
34-
// process, though, is not known until after creation. Registering the
35-
// process object after process creation creates an undesirable error path
36-
// -- if we are not able to register the process object (say, because of
37-
// a low resource condition) we would be forced to return an error to
38-
// the caller of CreateProcess, even though the new process was actually
39-
// created...
40-
//
41-
// Note: we could work around this by effectively always going down
42-
// the create suspended path. That is, the new process would not exec until
43-
// the parent process released it. It's unclear how much benefit this would
44-
// provide us.
45-
//
46-
47-
class CProcProcessLocalData
48-
{
49-
public:
50-
CProcProcessLocalData()
51-
:
52-
dwProcessId(0)
53-
{
54-
};
55-
56-
~CProcProcessLocalData()
57-
{
58-
};
59-
60-
DWORD dwProcessId;
61-
};
62-
6326
PAL_ERROR
6427
InitializeProcessCommandLine(
6528
LPWSTR lpwstrCmdLine,
@@ -70,8 +33,6 @@ namespace CorUnix
7033
CreateInitialProcessAndThreadObjects(
7134
CPalThread *pThread
7235
);
73-
74-
extern IPalObject *g_pobjProcess;
7536
}
7637

7738
#endif // _PAL_PROCOBJ_HPP_

src/coreclr/pal/src/init/pal.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -331,9 +331,8 @@ Initialize(
331331

332332
if (init_count == 0)
333333
{
334-
// Set our pid and sid.
334+
// Set our pid.
335335
gPID = getpid();
336-
gSID = getsid(gPID);
337336

338337
// Initialize the thread local storage
339338
if (FALSE == TLSInitialize())

0 commit comments

Comments
 (0)