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"
28 #include "wine/server.h"
29 #include "wine/debug.h"
31 WINE_DEFAULT_DEBUG_CHANNEL(process
);
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
)
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
;
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
)
79 TRACE("(%ld, %d)\n", dwProcessID
, offset
);
81 if (dwProcessID
&& dwProcessID
!= GetCurrentProcessId())
83 ERR("%d: process %lx not accessible\n", offset
, dwProcessID
);
89 case GPD_APP_COMPAT_FLAGS
:
90 return GetAppCompatFlags16(0);
91 case GPD_LOAD_DONE_EVENT
:
95 case GPD_WINDOWS_VERSION
:
96 return GetExeVersion16();
98 return (DWORD
)NtCurrentTeb() - 0x10 /* FIXME */;
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
);
113 if ( (INT
)x
== CW_USEDEFAULT
) x
= CW_USEDEFAULT16
;
115 if ( (INT
)y
== CW_USEDEFAULT
) y
= CW_USEDEFAULT16
;
116 return MAKELONG( x
, y
);
117 case GPD_STARTF_POSITION
:
118 GetStartupInfoW(&siw
);
120 if ( (INT
)x
== CW_USEDEFAULT
) x
= CW_USEDEFAULT16
;
122 if ( (INT
)y
== CW_USEDEFAULT
) y
= CW_USEDEFAULT16
;
123 return MAKELONG( x
, y
);
124 case GPD_STARTF_FLAGS
:
125 GetStartupInfoW(&siw
);
130 return GetProcessFlags(0);
132 return process_dword
;
134 ERR("Unknown offset %d\n", offset
);
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
);
155 case GPD_APP_COMPAT_FLAGS
:
156 case GPD_LOAD_DONE_EVENT
:
157 case GPD_HINSTANCE16
:
158 case GPD_WINDOWS_VERSION
:
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
:
169 ERR("Not allowed to modify offset %d\n", offset
);
172 process_dword
= value
;
175 ERR("Unknown offset %d\n", offset
);
181 /***********************************************************************
182 * ExitProcess (KERNEL.466)
184 void WINAPI
ExitProcess16( WORD status
)
187 ReleaseThunkLock( &count
);
188 ExitProcess( status
);
192 /*********************************************************************
193 * OpenProcess (KERNEL32.@)
195 HANDLE WINAPI
OpenProcess( DWORD access
, BOOL inherit
, DWORD id
)
198 SERVER_START_REQ( open_process
)
201 req
->access
= access
;
202 req
->inherit
= inherit
;
203 if (!wine_server_call_err( req
)) ret
= reply
->handle
;
210 /*********************************************************************
211 * MapProcessHandle (KERNEL.483)
213 DWORD WINAPI
MapProcessHandle( HANDLE handle
)
216 SERVER_START_REQ( get_process_info
)
218 req
->handle
= handle
;
219 if (!wine_server_call_err( req
)) ret
= reply
->pid
;
226 /***********************************************************************
227 * SetPriorityClass (KERNEL32.@)
229 BOOL WINAPI
SetPriorityClass( HANDLE hprocess
, DWORD priorityclass
)
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
);
244 /***********************************************************************
245 * GetPriorityClass (KERNEL32.@)
247 DWORD WINAPI
GetPriorityClass(HANDLE hprocess
)
250 SERVER_START_REQ( get_process_info
)
252 req
->handle
= hprocess
;
253 if (!wine_server_call_err( req
)) ret
= reply
->priority
;
260 /***********************************************************************
261 * SetProcessAffinityMask (KERNEL32.@)
263 BOOL WINAPI
SetProcessAffinityMask( HANDLE hProcess
, DWORD affmask
)
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
);
278 /**********************************************************************
279 * GetProcessAffinityMask (KERNEL32.@)
281 BOOL WINAPI
GetProcessAffinityMask( HANDLE hProcess
,
282 LPDWORD lpProcessAffinityMask
,
283 LPDWORD lpSystemAffinityMask
)
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
;
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");
313 if ((nt
= RtlImageNtHeader( NtCurrentTeb()->Peb
->ImageBaseAddress
)))
314 return ((nt
->OptionalHeader
.MajorSubsystemVersion
<< 16) |
315 nt
->OptionalHeader
.MinorSubsystemVersion
);
320 /***********************************************************************
321 * SetProcessWorkingSetSize [KERNEL32.@]
322 * Sets the min/max working set sizes for a specified process.
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
331 BOOL WINAPI
SetProcessWorkingSetSize(HANDLE hProcess
, SIZE_T minset
,
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 */
342 /***********************************************************************
343 * GetProcessWorkingSetSize (KERNEL32.@)
345 BOOL WINAPI
GetProcessWorkingSetSize(HANDLE hProcess
, PSIZE_T minset
,
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;
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
;
368 /***********************************************************************
369 * GetProcessShutdownParameters (KERNEL32.@)
372 BOOL WINAPI
GetProcessShutdownParameters( LPDWORD lpdwLevel
, LPDWORD lpdwFlags
)
374 *lpdwLevel
= shutdown_priority
;
375 *lpdwFlags
= shutdown_flags
;
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
;
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. */
404 /***********************************************************************
405 * ReadProcessMemory (KERNEL32.@)
407 BOOL WINAPI
ReadProcessMemory( HANDLE process
, LPCVOID addr
, LPVOID buffer
, SIZE_T size
,
410 NTSTATUS status
= NtReadVirtualMemory( process
, addr
, buffer
, size
, bytes_read
);
411 if (status
) SetLastError( RtlNtStatusToDosError(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
) );
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
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;