source: trunk/src/kernel32/process.cpp@ 1885

Last change on this file since 1885 was 1885, checked in by sandervl, 26 years ago

Added process api + virtualprotect fix

File size: 12.8 KB
Line 
1/* $Id: process.cpp,v 1.1 1999-11-30 14:16:16 sandervl Exp $ */
2
3/*
4 * Win32 process functions for OS/2
5 *
6 * Copyright 1999 Sander van Leeuwen (OS/2 Port)
7 *
8 * TODO: Not done yet! (setting up process structures)
9 *
10 * Based on Wine code (scheduler\process.c)
11 *
12 * Copyright 1996, 1998 Alexandre Julliard
13 *
14 * Project Odin Software License can be found in LICENSE.TXT
15 *
16 */
17#include <odin.h>
18#include <odinwrap.h>
19#include <os2sel.h>
20
21#include <os2win.h>
22#include <winnt.h>
23#include <winnls.h>
24#include <stdlib.h>
25#include <string.h>
26
27#include <misc.h>
28#include <wprocess.h>
29#include <win\task.h>
30
31#define SHUTDOWN_NORETRY 1
32
33static unsigned int shutdown_noretry = 0;
34static unsigned int shutdown_priority = 0x280L;
35static DWORD ProcessAffinityMask = 1;
36static PDB *PROCESS_First = &ProcessPDB;
37
38//******************************************************************************
39//******************************************************************************
40HANDLE WIN32API OpenProcess(DWORD arg1, BOOL arg2, DWORD arg3)
41{
42 dprintf(("KERNEL32: OS2OpenProcess\n"));
43 return O32_OpenProcess(arg1, arg2, arg3);
44}
45//******************************************************************************
46//******************************************************************************
47BOOL WIN32API GetExitCodeProcess(HANDLE arg1, LPDWORD arg2)
48{
49 dprintf(("KERNEL32: GetExitCodeProcess\n"));
50 return O32_GetExitCodeProcess(arg1, arg2);
51}
52//******************************************************************************
53//******************************************************************************
54HANDLE WIN32API GetCurrentProcess(void)
55{
56 dprintf2(("KERNEL32: GetCurrentProcess\n"));
57 return O32_GetCurrentProcess();
58}
59//******************************************************************************
60//******************************************************************************
61DWORD WIN32API GetCurrentProcessId(void)
62{
63 dprintf2(("KERNEL32: GetCurrentProcessId\n"));
64 return O32_GetCurrentProcessId();
65}
66//******************************************************************************
67//******************************************************************************
68BOOL WIN32API TerminateProcess( HANDLE arg1, DWORD arg2)
69{
70 dprintf(("KERNEL32: TerminateProcess\n"));
71 return O32_TerminateProcess(arg1, arg2);
72}
73//******************************************************************************
74//Should retrieve this from the exe...
75//******************************************************************************
76DWORD WIN32API GetProcessVersion(DWORD Processid)
77{
78 dprintf(("KERNEL32: OS2GetProcessVersion not correctly implemented!!\n"));
79 return(WIN32OS2_VERSION);
80}
81/***********************************************************************
82 * SetProcessAffinityMask (KERNEL32.662)
83 */
84BOOL WINAPI SetProcessAffinityMask( HANDLE hProcess, DWORD affmask )
85{
86 ProcessAffinityMask = affmask;
87 return TRUE;
88}
89//******************************************************************************
90//******************************************************************************
91BOOL WIN32API GetProcessAffinityMask(HANDLE hProcess,
92 LPDWORD lpProcessAffinityMask,
93 LPDWORD lpSystemAffinityMask)
94{
95 /* It is definitely important for a process to know on what processor
96 it is running :-) */
97 if(lpProcessAffinityMask)
98 *lpProcessAffinityMask=ProcessAffinityMask;
99 if(lpSystemAffinityMask)
100 *lpSystemAffinityMask=1;
101 return TRUE;
102}
103/***********************************************************************
104 * GetProcessHeaps [KERNEL32.376]
105 */
106DWORD WINAPI GetProcessHeaps(DWORD nrofheaps,HANDLE *heaps)
107{
108 dprintf(("GetProcessHeaps: (%ld,%p), incomplete implementation.\n",nrofheaps,heaps));
109
110 if (nrofheaps) {
111 heaps[0] = GetProcessHeap();
112 /* ... probably SystemHeap too ? */
113 return 1;
114 }
115 /* number of available heaps */
116 return 1;
117}
118/***********************************************************************
119 * RegisterServiceProcess (KERNEL, KERNEL32)
120 *
121 * A service process calls this function to ensure that it continues to run
122 * even after a user logged off.
123 */
124DWORD WINAPI RegisterServiceProcess(DWORD dwProcessId, DWORD dwType)
125{
126 dprintf(("RegisterServiceProcess %x %x", dwProcessId, dwType));
127 /* I don't think that Wine needs to do anything in that function */
128 return 1; /* success */
129}
130/***********************************************************************
131 * Name : BOOL SetProcessShutdownParameters
132 * Purpose : The SetProcessShutdownParameters function sets shutdown parameters
133 * for the currently calling process. This function sets a shutdown
134 * order for a process relative to the other processes in the system.
135 * Parameters: DWORD dwLevel shutdown priority
136 * DWORD dwFlags shutdown flags
137 * Variables :
138 * Result : TRUE / FALSE
139 * Remark :
140 *
141 * SetProcessShutdownParameters (KERNEL32)
142 *
143 * CHANGED - James Sutherland (JamesSutherland@gmx.de)
144 * Now tracks changes made (but does not act on these changes)
145 * NOTE: the definition for SHUTDOWN_NORETRY was done on guesswork.
146 * It really shouldn't be here, but I'll move it when it's been checked!
147 */
148BOOL WINAPI SetProcessShutdownParameters(DWORD level,DWORD flags)
149{
150 if (flags & SHUTDOWN_NORETRY)
151 shutdown_noretry = 1;
152 else
153 shutdown_noretry = 0;
154 if (level > 0x100L && level < 0x3FFL)
155 shutdown_priority = level;
156 else
157 {
158 dprintf(("SetProcessShutdownParameters: invalid priority level 0x%08lx\n", level));
159 return FALSE;
160 }
161 return TRUE;
162}
163/***********************************************************************
164 * GetProcessShutdownParameters (KERNEL32)
165 * Name : BOOL GetProcessShutdownParameters
166 * Purpose : The GetProcessShutdownParameters function retrieves shutdown
167 * parameters for the currently calling process.
168 * Parameters: LPDWORD lpdwLevel
169 * LPDWORD lpdwFlags
170 * Variables :
171 * Result : TRUE / FALSE
172 * Remark :
173 *
174 */
175BOOL WINAPI GetProcessShutdownParameters( LPDWORD lpdwLevel,
176 LPDWORD lpdwFlags )
177{
178 dprintf(("GetProcessShutdownParameters"));
179 (*lpdwLevel) = shutdown_priority;
180 (*lpdwFlags) = (shutdown_noretry * SHUTDOWN_NORETRY);
181 return TRUE;
182}
183/***********************************************************************
184 * SetProcessPriorityBoost (KERNEL32)
185 */
186BOOL WINAPI SetProcessPriorityBoost(HANDLE hprocess,BOOL disableboost)
187{
188 dprintf(("SetProcessPriorityBoost: (%d,%d): stub\n",hprocess,disableboost));
189 /* Say we can do it. I doubt the program will notice that we don't. */
190 return TRUE;
191}
192/***********************************************************************
193 * SetProcessWorkingSetSize [KERNEL32.662]
194 * Sets the min/max working set sizes for a specified process.
195 *
196 * PARAMS
197 * hProcess [I] Handle to the process of interest
198 * minset [I] Specifies minimum working set size
199 * maxset [I] Specifies maximum working set size
200 *
201 * RETURNS STD
202 */
203BOOL WINAPI SetProcessWorkingSetSize(HANDLE hProcess,DWORD minset,
204 DWORD maxset)
205{
206 dprintf(("SetProcessWorkingSetSize (0x%08x,%ld,%ld): stub - harmless\n",hProcess,minset,maxset));
207 if(( minset == -1) && (maxset == -1)) {
208 /* Trim the working set to zero */
209 /* Swap the process out of physical RAM */
210 }
211 return TRUE;
212}
213
214/***********************************************************************
215 * GetProcessWorkingSetSize (KERNEL32)
216 * Name : BOOL SetProcessWorkingSetSize
217 * Purpose : The SetProcessWorkingSetSize function sets the minimum and
218 * maximum working set sizes for a specified process.
219 * The working set of a process is the set of memory pages currently
220 * visible to the process in physical RAM memory. These pages are
221 * resident and available for an application to use without triggering
222 * a page fault. The size of the working set of a process is specified
223 * in bytes. The minimum and maximum working set sizes affect the
224 * virtual memory paging behavior of a process.
225 * Parameters: HANDLE hProcess open handle to the process of interest
226 * DWORD dwMinimumWorkingSetSize specifies minimum working set size
227 * DWORD dwMaximumWorkingSetSize specifies maximum working set size
228 * Variables :
229 * Result : TRUE / FALSE
230 */
231BOOL WINAPI GetProcessWorkingSetSize(HANDLE hProcess,LPDWORD minset,
232 LPDWORD maxset)
233{
234 dprintf(("GetProcessWorkingSetSize 0x%08x,%p,%p): stub\n",hProcess,minset,maxset));
235 /* 32 MB working set size */
236 if (minset) *minset = 32*1024*1024;
237 if (maxset) *maxset = 32*1024*1024;
238 return TRUE;
239}
240/***********************************************************************
241 * PROCESS_IdToPDB
242 *
243 * Convert a process id to a PDB, making sure it is valid.
244 */
245PDB *PROCESS_IdToPDB( DWORD id )
246{
247 PDB *pdb;
248
249 if (!id) return PROCESS_Current();
250 pdb = PROCESS_First;
251 while (pdb)
252 {
253 if ((DWORD)pdb->server_pid == id) return pdb;
254 pdb = pdb->next;
255 }
256 SetLastError( ERROR_INVALID_PARAMETER );
257 return NULL;
258}
259/***********************************************************************
260 * GetProcessDword (KERNEL32.18) (KERNEL.485)
261 * 'Of course you cannot directly access Windows internal structures'
262 */
263DWORD WINAPI GetProcessDword( DWORD dwProcessID, INT offset )
264{
265 PDB *process = PROCESS_IdToPDB( dwProcessID );
266 TDB *pTask;
267 DWORD x, y;
268
269 dprintf(("GetProcessDword: (%ld, %d)\n", dwProcessID, offset ));
270 if ( !process ) return 0;
271
272 switch ( offset )
273 {
274 case GPD_APP_COMPAT_FLAGS:
275 pTask = (TDB *)GlobalLock( process->task );
276 return pTask? pTask->compat_flags : 0;
277
278 case GPD_LOAD_DONE_EVENT:
279 return process->load_done_evt;
280
281 case GPD_HINSTANCE16:
282 pTask = (TDB *)GlobalLock( process->task );
283 return pTask? pTask->hInstance : 0;
284
285 case GPD_WINDOWS_VERSION:
286 pTask = (TDB *)GlobalLock( process->task );
287 return pTask? pTask->version : 0;
288
289 case GPD_THDB:
290 if ( process != PROCESS_Current() ) return 0;
291 return (DWORD)GetThreadTHDB();
292
293 case GPD_PDB:
294 return (DWORD)process;
295
296 case GPD_STARTF_SHELLDATA: /* return stdoutput handle from startupinfo ??? */
297 return process->env_db->startup_info->hStdOutput;
298
299 case GPD_STARTF_HOTKEY: /* return stdinput handle from startupinfo ??? */
300 return process->env_db->startup_info->hStdInput;
301
302 case GPD_STARTF_SHOWWINDOW:
303 return process->env_db->startup_info->wShowWindow;
304
305 case GPD_STARTF_SIZE:
306 x = process->env_db->startup_info->dwXSize;
307 if ( x == CW_USEDEFAULT ) x = CW_USEDEFAULT16;
308 y = process->env_db->startup_info->dwYSize;
309 if ( y == CW_USEDEFAULT ) y = CW_USEDEFAULT16;
310 return MAKELONG( x, y );
311
312 case GPD_STARTF_POSITION:
313 x = process->env_db->startup_info->dwX;
314 if ( x == CW_USEDEFAULT ) x = CW_USEDEFAULT16;
315 y = process->env_db->startup_info->dwY;
316 if ( y == CW_USEDEFAULT ) y = CW_USEDEFAULT16;
317 return MAKELONG( x, y );
318
319 case GPD_STARTF_FLAGS:
320 return process->env_db->startup_info->dwFlags;
321
322 case GPD_PARENT:
323 if(process->parent)
324 return (DWORD)process->parent->server_pid;
325 return 0;
326
327 case GPD_FLAGS:
328 return process->flags;
329
330 case GPD_USERDATA:
331 return process->process_dword;
332
333 default:
334 dprintf(("GetProcessDword: Unknown offset %d\n", offset ));
335 return 0;
336 }
337}
338
339/***********************************************************************
340 * SetProcessDword (KERNEL.484)
341 * 'Of course you cannot directly access Windows internal structures'
342 */
343void WINAPI SetProcessDword( DWORD dwProcessID, INT offset, DWORD value )
344{
345 PDB *process = PROCESS_IdToPDB( dwProcessID );
346
347 dprintf(("SetProcessDword: (%ld, %d)\n", dwProcessID, offset));
348 if ( !process ) return;
349
350 switch ( offset )
351 {
352 case GPD_APP_COMPAT_FLAGS:
353 case GPD_LOAD_DONE_EVENT:
354 case GPD_HINSTANCE16:
355 case GPD_WINDOWS_VERSION:
356 case GPD_THDB:
357 case GPD_PDB:
358 case GPD_STARTF_SHELLDATA:
359 case GPD_STARTF_HOTKEY:
360 case GPD_STARTF_SHOWWINDOW:
361 case GPD_STARTF_SIZE:
362 case GPD_STARTF_POSITION:
363 case GPD_STARTF_FLAGS:
364 case GPD_PARENT:
365 case GPD_FLAGS:
366 dprintf(("SetProcessDword: Not allowed to modify offset %d\n", offset ));
367 break;
368
369 case GPD_USERDATA:
370 process->process_dword = value;
371 break;
372
373 default:
374 dprintf(("SetProcessDword: Unknown offset %d\n", offset));
375 break;
376 }
377}
378//******************************************************************************
379//******************************************************************************
Note: See TracBrowser for help on using the repository browser.