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

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

LARGE_INTEGER change

File size: 15.7 KB
Line 
1/* $Id: process.cpp,v 1.4 1999-12-01 19:46:49 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#include <winimagebase.h>
31#include "oslibdos.h"
32
33#define SHUTDOWN_NORETRY 1
34
35static unsigned int shutdown_noretry = 0;
36static unsigned int shutdown_priority = 0x280L;
37static DWORD ProcessAffinityMask = 1;
38static PDB *PROCESS_First = &ProcessPDB;
39
40/***********************************************************************
41 * PROCESS_IdToPDB
42 *
43 * Convert a process id to a PDB, making sure it is valid.
44 */
45PDB *PROCESS_IdToPDB( DWORD id )
46{
47 PDB *pdb;
48
49 if (!id) return PROCESS_Current();
50 pdb = PROCESS_First;
51 while (pdb)
52 {
53 if ((DWORD)pdb->server_pid == id) return pdb;
54 pdb = pdb->next;
55 }
56 SetLastError( ERROR_INVALID_PARAMETER );
57 return NULL;
58}
59//******************************************************************************
60//******************************************************************************
61HANDLE WIN32API OpenProcess(DWORD arg1, BOOL arg2, DWORD arg3)
62{
63 dprintf(("KERNEL32: OS2OpenProcess\n"));
64 return O32_OpenProcess(arg1, arg2, arg3);
65}
66//******************************************************************************
67//******************************************************************************
68BOOL WIN32API GetExitCodeProcess(HANDLE arg1, LPDWORD arg2)
69{
70 dprintf(("KERNEL32: GetExitCodeProcess\n"));
71 return O32_GetExitCodeProcess(arg1, arg2);
72}
73//******************************************************************************
74//******************************************************************************
75HANDLE WIN32API GetCurrentProcess(void)
76{
77 dprintf2(("KERNEL32: GetCurrentProcess\n"));
78 return O32_GetCurrentProcess();
79}
80//******************************************************************************
81//******************************************************************************
82DWORD WIN32API GetCurrentProcessId(void)
83{
84 dprintf2(("KERNEL32: GetCurrentProcessId\n"));
85 return O32_GetCurrentProcessId();
86}
87//******************************************************************************
88//******************************************************************************
89BOOL WIN32API TerminateProcess( HANDLE arg1, DWORD arg2)
90{
91 dprintf(("KERNEL32: TerminateProcess\n"));
92 return O32_TerminateProcess(arg1, arg2);
93}
94//******************************************************************************
95//******************************************************************************
96DWORD WIN32API GetProcessVersion(DWORD Processid)
97{
98 Win32ImageBase *image;
99 PDB *process = PROCESS_IdToPDB( Processid );
100 DWORD version;
101
102 if(process == NULL) {
103 dprintf(("GetProcessVersion: can't find process (%d)", Processid));
104 return 0;
105 }
106 image = Win32ImageBase::findModule(process->hInstance);
107 if(image) {
108 version = image->getVersion();
109 dprintf(("GetProcessVersion of %x = %x", Processid, version));
110 return version;
111 }
112 dprintf(("GetProcessVersion: can't find module %x (%d)", process->hInstance, Processid));
113 return 0;
114}
115/***********************************************************************
116 * SetProcessAffinityMask (KERNEL32.662)
117 */
118BOOL WINAPI SetProcessAffinityMask( HANDLE hProcess, DWORD affmask )
119{
120 ProcessAffinityMask = affmask;
121 return TRUE;
122}
123//******************************************************************************
124//******************************************************************************
125BOOL WIN32API GetProcessAffinityMask(HANDLE hProcess,
126 LPDWORD lpProcessAffinityMask,
127 LPDWORD lpSystemAffinityMask)
128{
129 /* It is definitely important for a process to know on what processor
130 it is running :-) */
131 if(lpProcessAffinityMask)
132 *lpProcessAffinityMask=ProcessAffinityMask;
133 if(lpSystemAffinityMask)
134 *lpSystemAffinityMask=1;
135 return TRUE;
136}
137/***********************************************************************
138 * GetProcessHeaps [KERNEL32.376]
139 */
140DWORD WINAPI GetProcessHeaps(DWORD nrofheaps,HANDLE *heaps)
141{
142 dprintf(("GetProcessHeaps: (%ld,%p), incomplete implementation.\n",nrofheaps,heaps));
143
144 if (nrofheaps) {
145 heaps[0] = GetProcessHeap();
146 /* ... probably SystemHeap too ? */
147 return 1;
148 }
149 /* number of available heaps */
150 return 1;
151}
152/***********************************************************************
153 * RegisterServiceProcess (KERNEL, KERNEL32)
154 *
155 * A service process calls this function to ensure that it continues to run
156 * even after a user logged off.
157 */
158DWORD WINAPI RegisterServiceProcess(DWORD dwProcessId, DWORD dwType)
159{
160 dprintf(("RegisterServiceProcess %x %x", dwProcessId, dwType));
161 /* I don't think that Wine needs to do anything in that function */
162 return 1; /* success */
163}
164/***********************************************************************
165 * Name : BOOL SetProcessShutdownParameters
166 * Purpose : The SetProcessShutdownParameters function sets shutdown parameters
167 * for the currently calling process. This function sets a shutdown
168 * order for a process relative to the other processes in the system.
169 * Parameters: DWORD dwLevel shutdown priority
170 * DWORD dwFlags shutdown flags
171 * Variables :
172 * Result : TRUE / FALSE
173 * Remark :
174 *
175 * SetProcessShutdownParameters (KERNEL32)
176 *
177 * CHANGED - James Sutherland (JamesSutherland@gmx.de)
178 * Now tracks changes made (but does not act on these changes)
179 * NOTE: the definition for SHUTDOWN_NORETRY was done on guesswork.
180 * It really shouldn't be here, but I'll move it when it's been checked!
181 */
182BOOL WINAPI SetProcessShutdownParameters(DWORD level,DWORD flags)
183{
184 if (flags & SHUTDOWN_NORETRY)
185 shutdown_noretry = 1;
186 else
187 shutdown_noretry = 0;
188 if (level > 0x100L && level < 0x3FFL)
189 shutdown_priority = level;
190 else
191 {
192 dprintf(("SetProcessShutdownParameters: invalid priority level 0x%08lx\n", level));
193 return FALSE;
194 }
195 return TRUE;
196}
197/***********************************************************************
198 * GetProcessShutdownParameters (KERNEL32)
199 * Name : BOOL GetProcessShutdownParameters
200 * Purpose : The GetProcessShutdownParameters function retrieves shutdown
201 * parameters for the currently calling process.
202 * Parameters: LPDWORD lpdwLevel
203 * LPDWORD lpdwFlags
204 * Variables :
205 * Result : TRUE / FALSE
206 * Remark :
207 *
208 */
209BOOL WINAPI GetProcessShutdownParameters( LPDWORD lpdwLevel,
210 LPDWORD lpdwFlags )
211{
212 dprintf(("GetProcessShutdownParameters"));
213 (*lpdwLevel) = shutdown_priority;
214 (*lpdwFlags) = (shutdown_noretry * SHUTDOWN_NORETRY);
215 return TRUE;
216}
217/***********************************************************************
218 * SetProcessPriorityBoost (KERNEL32)
219 */
220BOOL WINAPI SetProcessPriorityBoost(HANDLE hprocess,BOOL disableboost)
221{
222 dprintf(("SetProcessPriorityBoost: (%d,%d): stub\n",hprocess,disableboost));
223 /* Say we can do it. I doubt the program will notice that we don't. */
224 return TRUE;
225}
226/***********************************************************************
227 * SetProcessWorkingSetSize [KERNEL32.662]
228 * Sets the min/max working set sizes for a specified process.
229 *
230 * PARAMS
231 * hProcess [I] Handle to the process of interest
232 * minset [I] Specifies minimum working set size
233 * maxset [I] Specifies maximum working set size
234 *
235 * RETURNS STD
236 */
237BOOL WINAPI SetProcessWorkingSetSize(HANDLE hProcess,DWORD minset,
238 DWORD maxset)
239{
240 dprintf(("SetProcessWorkingSetSize (0x%08x,%ld,%ld): stub - harmless\n",hProcess,minset,maxset));
241 if(( minset == -1) && (maxset == -1)) {
242 /* Trim the working set to zero */
243 /* Swap the process out of physical RAM */
244 }
245 return TRUE;
246}
247
248/***********************************************************************
249 * GetProcessWorkingSetSize (KERNEL32)
250 * Name : BOOL SetProcessWorkingSetSize
251 * Purpose : The SetProcessWorkingSetSize function sets the minimum and
252 * maximum working set sizes for a specified process.
253 * The working set of a process is the set of memory pages currently
254 * visible to the process in physical RAM memory. These pages are
255 * resident and available for an application to use without triggering
256 * a page fault. The size of the working set of a process is specified
257 * in bytes. The minimum and maximum working set sizes affect the
258 * virtual memory paging behavior of a process.
259 * Parameters: HANDLE hProcess open handle to the process of interest
260 * DWORD dwMinimumWorkingSetSize specifies minimum working set size
261 * DWORD dwMaximumWorkingSetSize specifies maximum working set size
262 * Variables :
263 * Result : TRUE / FALSE
264 */
265BOOL WINAPI GetProcessWorkingSetSize(HANDLE hProcess,LPDWORD minset,
266 LPDWORD maxset)
267{
268 dprintf(("GetProcessWorkingSetSize 0x%08x,%p,%p): stub\n",hProcess,minset,maxset));
269 /* 32 MB working set size */
270 if (minset) *minset = 32*1024*1024;
271 if (maxset) *maxset = 32*1024*1024;
272 return TRUE;
273}
274/***********************************************************************
275 * GetProcessDword (KERNEL32.18) (KERNEL.485)
276 * 'Of course you cannot directly access Windows internal structures'
277 */
278DWORD WINAPI GetProcessDword( DWORD dwProcessID, INT offset )
279{
280 PDB *process = PROCESS_IdToPDB( dwProcessID );
281 TDB *pTask;
282 DWORD x, y;
283
284 dprintf(("GetProcessDword: (%ld, %d)\n", dwProcessID, offset ));
285 if ( !process ) return 0;
286
287 switch ( offset )
288 {
289 case GPD_APP_COMPAT_FLAGS:
290 pTask = (TDB *)GlobalLock( process->task );
291 return pTask? pTask->compat_flags : 0;
292
293 case GPD_LOAD_DONE_EVENT:
294 return process->load_done_evt;
295
296 case GPD_HINSTANCE16:
297 pTask = (TDB *)GlobalLock( process->task );
298 return pTask? pTask->hInstance : 0;
299
300 case GPD_WINDOWS_VERSION:
301 pTask = (TDB *)GlobalLock( process->task );
302 return pTask? pTask->version : 0;
303
304 case GPD_THDB:
305 if ( process != PROCESS_Current() ) return 0;
306 return (DWORD)GetThreadTHDB();
307
308 case GPD_PDB:
309 return (DWORD)process;
310
311 case GPD_STARTF_SHELLDATA: /* return stdoutput handle from startupinfo ??? */
312 return process->env_db->startup_info->hStdOutput;
313
314 case GPD_STARTF_HOTKEY: /* return stdinput handle from startupinfo ??? */
315 return process->env_db->startup_info->hStdInput;
316
317 case GPD_STARTF_SHOWWINDOW:
318 return process->env_db->startup_info->wShowWindow;
319
320 case GPD_STARTF_SIZE:
321 x = process->env_db->startup_info->dwXSize;
322 if ( x == CW_USEDEFAULT ) x = CW_USEDEFAULT16;
323 y = process->env_db->startup_info->dwYSize;
324 if ( y == CW_USEDEFAULT ) y = CW_USEDEFAULT16;
325 return MAKELONG( x, y );
326
327 case GPD_STARTF_POSITION:
328 x = process->env_db->startup_info->dwX;
329 if ( x == CW_USEDEFAULT ) x = CW_USEDEFAULT16;
330 y = process->env_db->startup_info->dwY;
331 if ( y == CW_USEDEFAULT ) y = CW_USEDEFAULT16;
332 return MAKELONG( x, y );
333
334 case GPD_STARTF_FLAGS:
335 return process->env_db->startup_info->dwFlags;
336
337 case GPD_PARENT:
338 if(process->parent)
339 return (DWORD)process->parent->server_pid;
340 return 0;
341
342 case GPD_FLAGS:
343 return process->flags;
344
345 case GPD_USERDATA:
346 return process->process_dword;
347
348 default:
349 dprintf(("GetProcessDword: Unknown offset %d\n", offset ));
350 return 0;
351 }
352}
353
354/***********************************************************************
355 * SetProcessDword (KERNEL.484)
356 * 'Of course you cannot directly access Windows internal structures'
357 */
358void WINAPI SetProcessDword( DWORD dwProcessID, INT offset, DWORD value )
359{
360 PDB *process = PROCESS_IdToPDB( dwProcessID );
361
362 dprintf(("SetProcessDword: (%ld, %d)\n", dwProcessID, offset));
363 if ( !process ) return;
364
365 switch ( offset )
366 {
367 case GPD_APP_COMPAT_FLAGS:
368 case GPD_LOAD_DONE_EVENT:
369 case GPD_HINSTANCE16:
370 case GPD_WINDOWS_VERSION:
371 case GPD_THDB:
372 case GPD_PDB:
373 case GPD_STARTF_SHELLDATA:
374 case GPD_STARTF_HOTKEY:
375 case GPD_STARTF_SHOWWINDOW:
376 case GPD_STARTF_SIZE:
377 case GPD_STARTF_POSITION:
378 case GPD_STARTF_FLAGS:
379 case GPD_PARENT:
380 case GPD_FLAGS:
381 dprintf(("SetProcessDword: Not allowed to modify offset %d\n", offset ));
382 break;
383
384 case GPD_USERDATA:
385 process->process_dword = value;
386 break;
387
388 default:
389 dprintf(("SetProcessDword: Unknown offset %d\n", offset));
390 break;
391 }
392}
393/*****************************************************************************
394 * Name : BOOL GetProcessTimes
395 * Purpose : The GetProcessTimes function obtains timing information about a specified process.
396 * Parameters: HANDLE hProcess specifies the process of interest
397 * LPFILETIME lpCreationTime when the process was created
398 * LPFILETIME lpExitTime when the process exited
399 * LPFILETIME lpKernelTime time the process has spent in kernel mode
400 * LPFILETIME lpUserTime time the process has spent in user mode
401 * Variables :
402 * Result : TRUE / FALSE
403 * Remark :
404 * Status : UNTESTED STUB
405 *
406 * Author : Patrick Haller [Mon, 1998/06/15 08:00]
407 *****************************************************************************/
408
409ULONG (WINAPI *NtdllRtlExtendedIntegerMultiply)(LARGE_INTEGER factor1,
410 INT factor2) = 0;
411
412BOOL WIN32API GetProcessTimes(HANDLE hProcess,
413 LPFILETIME lpCreationTime,
414 LPFILETIME lpExitTime,
415 LPFILETIME lpKernelTime,
416 LPFILETIME lpUserTime)
417{
418 LARGE_INTEGER *kerneltime, *usertime;
419
420 dprintf(("Kernel32: GetProcessTimes(%08xh,%08xh,%08xh,%08xh,%08xh) partly implemented",
421 hProcess,
422 lpCreationTime,
423 lpExitTime,
424 lpKernelTime,
425 lpUserTime));
426
427 if(!NtdllRtlExtendedIntegerMultiply) {
428 HINSTANCE hInstance = LoadLibraryA("NTDLL.DLL");
429 if(hInstance)
430 *(VOID **)&NtdllRtlExtendedIntegerMultiply=(void*)GetProcAddress(hInstance, (LPCSTR)"RtlExtendedIntegerMultiply");
431 }
432 if(!lpCreationTime || !lpExitTime || !lpKernelTime || !lpUserTime) {
433 SetLastError(ERROR_INVALID_PARAMETER);
434 return FALSE;
435 }
436 if(hProcess != GetCurrentProcess()) {
437 dprintf(("GetProcessTimes unknown process"));
438 return FALSE;
439 }
440
441 SystemTimeToFileTime(&ProcessPDB.creationTime, lpCreationTime);
442 memset(lpExitTime, 0, sizeof(FILETIME));
443 memset(lpKernelTime, 0, sizeof(FILETIME));
444 memset(lpUserTime, 0, sizeof(FILETIME));
445
446 kerneltime = (LARGE_INTEGER *)lpKernelTime;
447 usertime = (LARGE_INTEGER *)lpUserTime;
448 OSLibDosQueryProcTimes(GetCurrentProcessId(), &lpKernelTime->dwLowDateTime, &lpUserTime->dwLowDateTime);
449 //TODO: Isn't correct -> (if result's high dword != 0)
450 kerneltime->LowPart = NtdllRtlExtendedIntegerMultiply(*kerneltime, 10);
451 usertime->LowPart = NtdllRtlExtendedIntegerMultiply(*usertime, 10);
452 return TRUE;
453}
454//******************************************************************************
455//******************************************************************************
Note: See TracBrowser for help on using the repository browser.