4 * Copyright 1996, 1998 Alexandre Julliard
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22 #include "wine/port.h"
24 #include "wine/winbase16.h"
25 #include "wine/winuser16.h"
27 #include "wine/server.h"
28 #include "wine/debug.h"
30 WINE_DEFAULT_DEBUG_CHANNEL(process);
33 #define PDB32_DEBUGGED 0x0001 /* Process is being debugged */
34 #define PDB32_WIN16_PROC 0x0008 /* Win16 process */
35 #define PDB32_DOS_PROC 0x0010 /* Dos process */
36 #define PDB32_CONSOLE_PROC 0x0020 /* Console process */
37 #define PDB32_FILE_APIS_OEM 0x0040 /* File APIs are OEM */
38 #define PDB32_WIN32S_PROC 0x8000 /* Win32s process */
41 static DWORD shutdown_flags = 0;
42 static DWORD shutdown_priority = 0x280;
43 static DWORD process_dword;
44 static BOOL oem_file_apis;
47 /***********************************************************************
48 * GetProcessFlags (KERNEL32.@)
50 DWORD WINAPI GetProcessFlags( DWORD processid )
55 if (processid && processid != GetCurrentProcessId()) return 0;
57 if ((nt = RtlImageNtHeader( NtCurrentTeb()->Peb->ImageBaseAddress )))
59 if (nt->OptionalHeader.Subsystem == IMAGE_SUBSYSTEM_WINDOWS_CUI)
60 flags |= PDB32_CONSOLE_PROC;
62 if (!AreFileApisANSI()) flags |= PDB32_FILE_APIS_OEM;
63 if (IsDebuggerPresent()) flags |= PDB32_DEBUGGED;
68 /***********************************************************************
69 * GetProcessDword (KERNEL.485)
70 * GetProcessDword (KERNEL32.18)
71 * 'Of course you cannot directly access Windows internal structures'
73 DWORD WINAPI GetProcessDword( DWORD dwProcessID, INT offset )
78 TRACE("(%ld, %d)\n", dwProcessID, offset );
80 if (dwProcessID && dwProcessID != GetCurrentProcessId())
82 ERR("%d: process %lx not accessible\n", offset, dwProcessID);
88 case GPD_APP_COMPAT_FLAGS:
89 return GetAppCompatFlags16(0);
90 case GPD_LOAD_DONE_EVENT:
94 case GPD_WINDOWS_VERSION:
95 return GetExeVersion16();
97 return (DWORD)NtCurrentTeb() - 0x10 /* FIXME */;
99 return (DWORD)NtCurrentTeb()->Peb;
100 case GPD_STARTF_SHELLDATA: /* return stdoutput handle from startupinfo ??? */
101 GetStartupInfoW(&siw);
102 return (DWORD)siw.hStdOutput;
103 case GPD_STARTF_HOTKEY: /* return stdinput handle from startupinfo ??? */
104 GetStartupInfoW(&siw);
105 return (DWORD)siw.hStdInput;
106 case GPD_STARTF_SHOWWINDOW:
107 GetStartupInfoW(&siw);
108 return siw.wShowWindow;
109 case GPD_STARTF_SIZE:
110 GetStartupInfoW(&siw);
112 if ( (INT)x == CW_USEDEFAULT ) x = CW_USEDEFAULT16;
114 if ( (INT)y == CW_USEDEFAULT ) y = CW_USEDEFAULT16;
115 return MAKELONG( x, y );
116 case GPD_STARTF_POSITION:
117 GetStartupInfoW(&siw);
119 if ( (INT)x == CW_USEDEFAULT ) x = CW_USEDEFAULT16;
121 if ( (INT)y == CW_USEDEFAULT ) y = CW_USEDEFAULT16;
122 return MAKELONG( x, y );
123 case GPD_STARTF_FLAGS:
124 GetStartupInfoW(&siw);
129 return GetProcessFlags(0);
131 return process_dword;
133 ERR("Unknown offset %d\n", offset );
138 /***********************************************************************
139 * SetProcessDword (KERNEL.484)
140 * 'Of course you cannot directly access Windows internal structures'
142 void WINAPI SetProcessDword( DWORD dwProcessID, INT offset, DWORD value )
144 TRACE("(%ld, %d)\n", dwProcessID, offset );
146 if (dwProcessID && dwProcessID != GetCurrentProcessId())
148 ERR("%d: process %lx not accessible\n", offset, dwProcessID);
154 case GPD_APP_COMPAT_FLAGS:
155 case GPD_LOAD_DONE_EVENT:
156 case GPD_HINSTANCE16:
157 case GPD_WINDOWS_VERSION:
160 case GPD_STARTF_SHELLDATA:
161 case GPD_STARTF_HOTKEY:
162 case GPD_STARTF_SHOWWINDOW:
163 case GPD_STARTF_SIZE:
164 case GPD_STARTF_POSITION:
165 case GPD_STARTF_FLAGS:
168 ERR("Not allowed to modify offset %d\n", offset );
171 process_dword = value;
174 ERR("Unknown offset %d\n", offset );
180 /***********************************************************************
181 * ExitProcess (KERNEL.466)
183 void WINAPI ExitProcess16( WORD status )
186 ReleaseThunkLock( &count );
187 ExitProcess( status );
191 /*********************************************************************
192 * OpenProcess (KERNEL32.@)
194 HANDLE WINAPI OpenProcess( DWORD access, BOOL inherit, DWORD id )
197 SERVER_START_REQ( open_process )
200 req->access = access;
201 req->inherit = inherit;
202 if (!wine_server_call_err( req )) ret = reply->handle;
209 /*********************************************************************
210 * MapProcessHandle (KERNEL.483)
212 DWORD WINAPI MapProcessHandle( HANDLE handle )
215 SERVER_START_REQ( get_process_info )
217 req->handle = handle;
218 if (!wine_server_call_err( req )) ret = reply->pid;
225 /***********************************************************************
226 * SetPriorityClass (KERNEL32.@)
228 BOOL WINAPI SetPriorityClass( HANDLE hprocess, DWORD priorityclass )
231 SERVER_START_REQ( set_process_info )
233 req->handle = hprocess;
234 req->priority = priorityclass;
235 req->mask = SET_PROCESS_INFO_PRIORITY;
236 ret = !wine_server_call_err( req );
243 /***********************************************************************
244 * GetPriorityClass (KERNEL32.@)
246 DWORD WINAPI GetPriorityClass(HANDLE hprocess)
249 SERVER_START_REQ( get_process_info )
251 req->handle = hprocess;
252 if (!wine_server_call_err( req )) ret = reply->priority;
259 /***********************************************************************
260 * SetProcessAffinityMask (KERNEL32.@)
262 BOOL WINAPI SetProcessAffinityMask( HANDLE hProcess, DWORD affmask )
265 SERVER_START_REQ( set_process_info )
267 req->handle = hProcess;
268 req->affinity = affmask;
269 req->mask = SET_PROCESS_INFO_AFFINITY;
270 ret = !wine_server_call_err( req );
277 /**********************************************************************
278 * GetProcessAffinityMask (KERNEL32.@)
280 BOOL WINAPI GetProcessAffinityMask( HANDLE hProcess,
281 LPDWORD lpProcessAffinityMask,
282 LPDWORD lpSystemAffinityMask )
285 SERVER_START_REQ( get_process_info )
287 req->handle = hProcess;
288 if (!wine_server_call_err( req ))
290 if (lpProcessAffinityMask) *lpProcessAffinityMask = reply->process_affinity;
291 if (lpSystemAffinityMask) *lpSystemAffinityMask = reply->system_affinity;
300 /***********************************************************************
301 * GetProcessVersion (KERNEL32.@)
303 DWORD WINAPI GetProcessVersion( DWORD processid )
305 IMAGE_NT_HEADERS *nt;
307 if (processid && processid != GetCurrentProcessId())
309 FIXME("should use ReadProcessMemory\n");
312 if ((nt = RtlImageNtHeader( NtCurrentTeb()->Peb->ImageBaseAddress )))
313 return ((nt->OptionalHeader.MajorSubsystemVersion << 16) |
314 nt->OptionalHeader.MinorSubsystemVersion);
319 /***********************************************************************
320 * SetProcessWorkingSetSize [KERNEL32.@]
321 * Sets the min/max working set sizes for a specified process.
324 * hProcess [I] Handle to the process of interest
325 * minset [I] Specifies minimum working set size
326 * maxset [I] Specifies maximum working set size
330 BOOL WINAPI SetProcessWorkingSetSize(HANDLE hProcess, SIZE_T minset,
333 FIXME("(%p,%ld,%ld): stub - harmless\n",hProcess,minset,maxset);
334 if(( minset == (SIZE_T)-1) && (maxset == (SIZE_T)-1)) {
335 /* Trim the working set to zero */
336 /* Swap the process out of physical RAM */
341 /***********************************************************************
342 * GetProcessWorkingSetSize (KERNEL32.@)
344 BOOL WINAPI GetProcessWorkingSetSize(HANDLE hProcess, PSIZE_T minset,
347 FIXME("(%p,%p,%p): stub\n",hProcess,minset,maxset);
348 /* 32 MB working set size */
349 if (minset) *minset = 32*1024*1024;
350 if (maxset) *maxset = 32*1024*1024;
355 /***********************************************************************
356 * SetProcessShutdownParameters (KERNEL32.@)
358 BOOL WINAPI SetProcessShutdownParameters(DWORD level, DWORD flags)
360 FIXME("(%08lx, %08lx): partial stub.\n", level, flags);
361 shutdown_flags = flags;
362 shutdown_priority = level;
367 /***********************************************************************
368 * GetProcessShutdownParameters (KERNEL32.@)
371 BOOL WINAPI GetProcessShutdownParameters( LPDWORD lpdwLevel, LPDWORD lpdwFlags )
373 *lpdwLevel = shutdown_priority;
374 *lpdwFlags = shutdown_flags;
379 /***********************************************************************
380 * GetProcessPriorityBoost (KERNEL32.@)
382 BOOL WINAPI GetProcessPriorityBoost(HANDLE hprocess,PBOOL pDisablePriorityBoost)
384 FIXME("(%p,%p): semi-stub\n", hprocess, pDisablePriorityBoost);
386 /* Report that no boost is present.. */
387 *pDisablePriorityBoost = FALSE;
392 /***********************************************************************
393 * SetProcessPriorityBoost (KERNEL32.@)
395 BOOL WINAPI SetProcessPriorityBoost(HANDLE hprocess,BOOL disableboost)
397 FIXME("(%p,%d): stub\n",hprocess,disableboost);
398 /* Say we can do it. I doubt the program will notice that we don't. */
403 /***********************************************************************
404 * ReadProcessMemory (KERNEL32.@)
406 BOOL WINAPI ReadProcessMemory( HANDLE process, LPCVOID addr, LPVOID buffer, SIZE_T size,
409 NTSTATUS status = NtReadVirtualMemory( process, addr, buffer, size, bytes_read );
410 if (status) SetLastError( RtlNtStatusToDosError(status) );
415 /***********************************************************************
416 * WriteProcessMemory (KERNEL32.@)
418 BOOL WINAPI WriteProcessMemory( HANDLE process, LPVOID addr, LPCVOID buffer, SIZE_T size,
419 SIZE_T *bytes_written )
421 NTSTATUS status = NtWriteVirtualMemory( process, addr, buffer, size, bytes_written );
422 if (status) SetLastError( RtlNtStatusToDosError(status) );
427 /***********************************************************************
428 * RegisterServiceProcess (KERNEL.491)
429 * RegisterServiceProcess (KERNEL32.@)
431 * A service process calls this function to ensure that it continues to run
432 * even after a user logged off.
434 DWORD WINAPI RegisterServiceProcess(DWORD dwProcessId, DWORD dwType)
436 /* I don't think that Wine needs to do anything in that function */
437 return 1; /* success */
441 /**************************************************************************
442 * SetFileApisToOEM (KERNEL32.@)
444 VOID WINAPI SetFileApisToOEM(void)
446 oem_file_apis = TRUE;
450 /**************************************************************************
451 * SetFileApisToANSI (KERNEL32.@)
453 VOID WINAPI SetFileApisToANSI(void)
455 oem_file_apis = FALSE;
459 /******************************************************************************
460 * AreFileApisANSI [KERNEL32.@] Determines if file functions are using ANSI
463 * TRUE: Set of file functions is using ANSI code page
464 * FALSE: Set of file functions is using OEM code page
466 BOOL WINAPI AreFileApisANSI(void)
468 return !oem_file_apis;
472 /***********************************************************************
473 * GetCurrentProcess (KERNEL32.@)
475 #undef GetCurrentProcess
476 HANDLE WINAPI GetCurrentProcess(void)
478 return (HANDLE)0xffffffff;