Fixed include statements to match server_protocol.h (spotted by Eric
[wine/hacks.git] / dlls / kernel / process.c
blob2dcd5c2fdafd0aee0c80d3264d46d9063b9b6894
1 /*
2 * Win32 processes
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
21 #include "config.h"
22 #include "wine/port.h"
24 #include "wine/winbase16.h"
25 #include "wine/winuser16.h"
26 #include "ntstatus.h"
27 #include "thread.h"
28 #include "wine/server.h"
29 #include "wine/debug.h"
31 WINE_DEFAULT_DEBUG_CHANNEL(process);
33 /* Process flags */
34 #define PDB32_DEBUGGED 0x0001 /* Process is being debugged */
35 #define PDB32_WIN16_PROC 0x0008 /* Win16 process */
36 #define PDB32_DOS_PROC 0x0010 /* Dos process */
37 #define PDB32_CONSOLE_PROC 0x0020 /* Console process */
38 #define PDB32_FILE_APIS_OEM 0x0040 /* File APIs are OEM */
39 #define PDB32_WIN32S_PROC 0x8000 /* Win32s process */
42 static DWORD shutdown_flags = 0;
43 static DWORD shutdown_priority = 0x280;
44 static DWORD process_dword;
45 static BOOL oem_file_apis;
48 /***********************************************************************
49 * GetProcessFlags (KERNEL32.@)
51 DWORD WINAPI GetProcessFlags( DWORD processid )
53 IMAGE_NT_HEADERS *nt;
54 DWORD flags = 0;
56 if (processid && processid != GetCurrentProcessId()) return 0;
58 if ((nt = RtlImageNtHeader( NtCurrentTeb()->Peb->ImageBaseAddress )))
60 if (nt->OptionalHeader.Subsystem == IMAGE_SUBSYSTEM_WINDOWS_CUI)
61 flags |= PDB32_CONSOLE_PROC;
63 if (!AreFileApisANSI()) flags |= PDB32_FILE_APIS_OEM;
64 if (IsDebuggerPresent()) flags |= PDB32_DEBUGGED;
65 return flags;
69 /***********************************************************************
70 * GetProcessDword (KERNEL.485)
71 * GetProcessDword (KERNEL32.18)
72 * 'Of course you cannot directly access Windows internal structures'
74 DWORD WINAPI GetProcessDword( DWORD dwProcessID, INT offset )
76 DWORD x, y;
77 STARTUPINFOW siw;
79 TRACE("(%ld, %d)\n", dwProcessID, offset );
81 if (dwProcessID && dwProcessID != GetCurrentProcessId())
83 ERR("%d: process %lx not accessible\n", offset, dwProcessID);
84 return 0;
87 switch ( offset )
89 case GPD_APP_COMPAT_FLAGS:
90 return GetAppCompatFlags16(0);
91 case GPD_LOAD_DONE_EVENT:
92 return 0;
93 case GPD_HINSTANCE16:
94 return GetTaskDS16();
95 case GPD_WINDOWS_VERSION:
96 return GetExeVersion16();
97 case GPD_THDB:
98 return (DWORD)NtCurrentTeb() - 0x10 /* FIXME */;
99 case GPD_PDB:
100 return (DWORD)NtCurrentTeb()->Peb;
101 case GPD_STARTF_SHELLDATA: /* return stdoutput handle from startupinfo ??? */
102 GetStartupInfoW(&siw);
103 return (DWORD)siw.hStdOutput;
104 case GPD_STARTF_HOTKEY: /* return stdinput handle from startupinfo ??? */
105 GetStartupInfoW(&siw);
106 return (DWORD)siw.hStdInput;
107 case GPD_STARTF_SHOWWINDOW:
108 GetStartupInfoW(&siw);
109 return siw.wShowWindow;
110 case GPD_STARTF_SIZE:
111 GetStartupInfoW(&siw);
112 x = siw.dwXSize;
113 if ( (INT)x == CW_USEDEFAULT ) x = CW_USEDEFAULT16;
114 y = siw.dwYSize;
115 if ( (INT)y == CW_USEDEFAULT ) y = CW_USEDEFAULT16;
116 return MAKELONG( x, y );
117 case GPD_STARTF_POSITION:
118 GetStartupInfoW(&siw);
119 x = siw.dwX;
120 if ( (INT)x == CW_USEDEFAULT ) x = CW_USEDEFAULT16;
121 y = siw.dwY;
122 if ( (INT)y == CW_USEDEFAULT ) y = CW_USEDEFAULT16;
123 return MAKELONG( x, y );
124 case GPD_STARTF_FLAGS:
125 GetStartupInfoW(&siw);
126 return siw.dwFlags;
127 case GPD_PARENT:
128 return 0;
129 case GPD_FLAGS:
130 return GetProcessFlags(0);
131 case GPD_USERDATA:
132 return process_dword;
133 default:
134 ERR("Unknown offset %d\n", offset );
135 return 0;
139 /***********************************************************************
140 * SetProcessDword (KERNEL.484)
141 * 'Of course you cannot directly access Windows internal structures'
143 void WINAPI SetProcessDword( DWORD dwProcessID, INT offset, DWORD value )
145 TRACE("(%ld, %d)\n", dwProcessID, offset );
147 if (dwProcessID && dwProcessID != GetCurrentProcessId())
149 ERR("%d: process %lx not accessible\n", offset, dwProcessID);
150 return;
153 switch ( offset )
155 case GPD_APP_COMPAT_FLAGS:
156 case GPD_LOAD_DONE_EVENT:
157 case GPD_HINSTANCE16:
158 case GPD_WINDOWS_VERSION:
159 case GPD_THDB:
160 case GPD_PDB:
161 case GPD_STARTF_SHELLDATA:
162 case GPD_STARTF_HOTKEY:
163 case GPD_STARTF_SHOWWINDOW:
164 case GPD_STARTF_SIZE:
165 case GPD_STARTF_POSITION:
166 case GPD_STARTF_FLAGS:
167 case GPD_PARENT:
168 case GPD_FLAGS:
169 ERR("Not allowed to modify offset %d\n", offset );
170 break;
171 case GPD_USERDATA:
172 process_dword = value;
173 break;
174 default:
175 ERR("Unknown offset %d\n", offset );
176 break;
181 /***********************************************************************
182 * ExitProcess (KERNEL.466)
184 void WINAPI ExitProcess16( WORD status )
186 DWORD count;
187 ReleaseThunkLock( &count );
188 ExitProcess( status );
192 /*********************************************************************
193 * OpenProcess (KERNEL32.@)
195 HANDLE WINAPI OpenProcess( DWORD access, BOOL inherit, DWORD id )
197 HANDLE ret = 0;
198 SERVER_START_REQ( open_process )
200 req->pid = id;
201 req->access = access;
202 req->inherit = inherit;
203 if (!wine_server_call_err( req )) ret = reply->handle;
205 SERVER_END_REQ;
206 return ret;
210 /*********************************************************************
211 * MapProcessHandle (KERNEL.483)
213 DWORD WINAPI MapProcessHandle( HANDLE handle )
215 DWORD ret = 0;
216 SERVER_START_REQ( get_process_info )
218 req->handle = handle;
219 if (!wine_server_call_err( req )) ret = reply->pid;
221 SERVER_END_REQ;
222 return ret;
226 /***********************************************************************
227 * SetPriorityClass (KERNEL32.@)
229 BOOL WINAPI SetPriorityClass( HANDLE hprocess, DWORD priorityclass )
231 BOOL ret;
232 SERVER_START_REQ( set_process_info )
234 req->handle = hprocess;
235 req->priority = priorityclass;
236 req->mask = SET_PROCESS_INFO_PRIORITY;
237 ret = !wine_server_call_err( req );
239 SERVER_END_REQ;
240 return ret;
244 /***********************************************************************
245 * GetPriorityClass (KERNEL32.@)
247 DWORD WINAPI GetPriorityClass(HANDLE hprocess)
249 DWORD ret = 0;
250 SERVER_START_REQ( get_process_info )
252 req->handle = hprocess;
253 if (!wine_server_call_err( req )) ret = reply->priority;
255 SERVER_END_REQ;
256 return ret;
260 /***********************************************************************
261 * SetProcessAffinityMask (KERNEL32.@)
263 BOOL WINAPI SetProcessAffinityMask( HANDLE hProcess, DWORD affmask )
265 BOOL ret;
266 SERVER_START_REQ( set_process_info )
268 req->handle = hProcess;
269 req->affinity = affmask;
270 req->mask = SET_PROCESS_INFO_AFFINITY;
271 ret = !wine_server_call_err( req );
273 SERVER_END_REQ;
274 return ret;
278 /**********************************************************************
279 * GetProcessAffinityMask (KERNEL32.@)
281 BOOL WINAPI GetProcessAffinityMask( HANDLE hProcess,
282 LPDWORD lpProcessAffinityMask,
283 LPDWORD lpSystemAffinityMask )
285 BOOL ret = FALSE;
286 SERVER_START_REQ( get_process_info )
288 req->handle = hProcess;
289 if (!wine_server_call_err( req ))
291 if (lpProcessAffinityMask) *lpProcessAffinityMask = reply->process_affinity;
292 if (lpSystemAffinityMask) *lpSystemAffinityMask = reply->system_affinity;
293 ret = TRUE;
296 SERVER_END_REQ;
297 return ret;
301 /***********************************************************************
302 * GetProcessVersion (KERNEL32.@)
304 DWORD WINAPI GetProcessVersion( DWORD processid )
306 IMAGE_NT_HEADERS *nt;
308 if (processid && processid != GetCurrentProcessId())
310 FIXME("should use ReadProcessMemory\n");
311 return 0;
313 if ((nt = RtlImageNtHeader( NtCurrentTeb()->Peb->ImageBaseAddress )))
314 return ((nt->OptionalHeader.MajorSubsystemVersion << 16) |
315 nt->OptionalHeader.MinorSubsystemVersion);
316 return 0;
320 /***********************************************************************
321 * SetProcessWorkingSetSize [KERNEL32.@]
322 * Sets the min/max working set sizes for a specified process.
324 * PARAMS
325 * hProcess [I] Handle to the process of interest
326 * minset [I] Specifies minimum working set size
327 * maxset [I] Specifies maximum working set size
329 * RETURNS STD
331 BOOL WINAPI SetProcessWorkingSetSize(HANDLE hProcess, SIZE_T minset,
332 SIZE_T maxset)
334 FIXME("(%p,%ld,%ld): stub - harmless\n",hProcess,minset,maxset);
335 if(( minset == (SIZE_T)-1) && (maxset == (SIZE_T)-1)) {
336 /* Trim the working set to zero */
337 /* Swap the process out of physical RAM */
339 return TRUE;
342 /***********************************************************************
343 * GetProcessWorkingSetSize (KERNEL32.@)
345 BOOL WINAPI GetProcessWorkingSetSize(HANDLE hProcess, PSIZE_T minset,
346 PSIZE_T maxset)
348 FIXME("(%p,%p,%p): stub\n",hProcess,minset,maxset);
349 /* 32 MB working set size */
350 if (minset) *minset = 32*1024*1024;
351 if (maxset) *maxset = 32*1024*1024;
352 return TRUE;
356 /***********************************************************************
357 * SetProcessShutdownParameters (KERNEL32.@)
359 BOOL WINAPI SetProcessShutdownParameters(DWORD level, DWORD flags)
361 FIXME("(%08lx, %08lx): partial stub.\n", level, flags);
362 shutdown_flags = flags;
363 shutdown_priority = level;
364 return TRUE;
368 /***********************************************************************
369 * GetProcessShutdownParameters (KERNEL32.@)
372 BOOL WINAPI GetProcessShutdownParameters( LPDWORD lpdwLevel, LPDWORD lpdwFlags )
374 *lpdwLevel = shutdown_priority;
375 *lpdwFlags = shutdown_flags;
376 return TRUE;
380 /***********************************************************************
381 * GetProcessPriorityBoost (KERNEL32.@)
383 BOOL WINAPI GetProcessPriorityBoost(HANDLE hprocess,PBOOL pDisablePriorityBoost)
385 FIXME("(%p,%p): semi-stub\n", hprocess, pDisablePriorityBoost);
387 /* Report that no boost is present.. */
388 *pDisablePriorityBoost = FALSE;
390 return TRUE;
393 /***********************************************************************
394 * SetProcessPriorityBoost (KERNEL32.@)
396 BOOL WINAPI SetProcessPriorityBoost(HANDLE hprocess,BOOL disableboost)
398 FIXME("(%p,%d): stub\n",hprocess,disableboost);
399 /* Say we can do it. I doubt the program will notice that we don't. */
400 return TRUE;
404 /***********************************************************************
405 * ReadProcessMemory (KERNEL32.@)
407 BOOL WINAPI ReadProcessMemory( HANDLE process, LPCVOID addr, LPVOID buffer, SIZE_T size,
408 SIZE_T *bytes_read )
410 NTSTATUS status = NtReadVirtualMemory( process, addr, buffer, size, bytes_read );
411 if (status) SetLastError( RtlNtStatusToDosError(status) );
412 return !status;
416 /***********************************************************************
417 * WriteProcessMemory (KERNEL32.@)
419 BOOL WINAPI WriteProcessMemory( HANDLE process, LPVOID addr, LPCVOID buffer, SIZE_T size,
420 SIZE_T *bytes_written )
422 NTSTATUS status = NtWriteVirtualMemory( process, addr, buffer, size, bytes_written );
423 if (status) SetLastError( RtlNtStatusToDosError(status) );
424 return !status;
428 /***********************************************************************
429 * RegisterServiceProcess (KERNEL.491)
430 * RegisterServiceProcess (KERNEL32.@)
432 * A service process calls this function to ensure that it continues to run
433 * even after a user logged off.
435 DWORD WINAPI RegisterServiceProcess(DWORD dwProcessId, DWORD dwType)
437 /* I don't think that Wine needs to do anything in that function */
438 return 1; /* success */
442 /**************************************************************************
443 * SetFileApisToOEM (KERNEL32.@)
445 VOID WINAPI SetFileApisToOEM(void)
447 oem_file_apis = TRUE;
451 /**************************************************************************
452 * SetFileApisToANSI (KERNEL32.@)
454 VOID WINAPI SetFileApisToANSI(void)
456 oem_file_apis = FALSE;
460 /******************************************************************************
461 * AreFileApisANSI [KERNEL32.@] Determines if file functions are using ANSI
463 * RETURNS
464 * TRUE: Set of file functions is using ANSI code page
465 * FALSE: Set of file functions is using OEM code page
467 BOOL WINAPI AreFileApisANSI(void)
469 return !oem_file_apis;
473 /***********************************************************************
474 * GetCurrentProcess (KERNEL32.@)
476 #undef GetCurrentProcess
477 HANDLE WINAPI GetCurrentProcess(void)
479 return (HANDLE)0xffffffff;