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