Return STATUS_INVALID_INFO_CLASS for non-implemented classes.
[wine] / dlls / ntdll / process.c
1 /*
2  * NT basis DLL
3  *
4  * This file contains the Nt* API functions of NTDLL.DLL.
5  * In the original ntdll.dll they all seem to just call int 0x2e (down to the NTOSKRNL)
6  *
7  * Copyright 1996-1998 Marcus Meissner
8  *
9  * This library is free software; you can redistribute it and/or
10  * modify it under the terms of the GNU Lesser General Public
11  * License as published by the Free Software Foundation; either
12  * version 2.1 of the License, or (at your option) any later version.
13  *
14  * This library is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
17  * Lesser General Public License for more details.
18  *
19  * You should have received a copy of the GNU Lesser General Public
20  * License along with this library; if not, write to the Free Software
21  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
22  */
23
24 #include <stdarg.h>
25 #include <stdio.h>
26 #include <stdlib.h>
27 #include <string.h>
28 #include <time.h>
29 #include "wine/debug.h"
30
31 #include "windef.h"
32 #include "winbase.h"
33 #include "winreg.h"
34 #include "winternl.h"
35 #include "ntdll_misc.h"
36 #include "wine/server.h"
37
38 WINE_DEFAULT_DEBUG_CHANNEL(ntdll);
39
40 /*
41  *      Process object
42  */
43
44 /******************************************************************************
45  *  NtTerminateProcess                  [NTDLL.@]
46  *
47  *  Native applications must kill themselves when done
48  */
49 NTSTATUS WINAPI NtTerminateProcess( HANDLE handle, LONG exit_code )
50 {
51     NTSTATUS ret;
52     BOOL self;
53     SERVER_START_REQ( terminate_process )
54     {
55         req->handle    = handle;
56         req->exit_code = exit_code;
57         ret = wine_server_call( req );
58         self = !ret && reply->self;
59     }
60     SERVER_END_REQ;
61     if (self) exit( exit_code );
62     return ret;
63 }
64
65 /******************************************************************************
66 *  NtQueryInformationProcess            [NTDLL.@]
67 *  ZwQueryInformationProcess            [NTDLL.@]
68 *
69 */
70 NTSTATUS WINAPI NtQueryInformationProcess(
71         IN HANDLE ProcessHandle,
72         IN PROCESSINFOCLASS ProcessInformationClass,
73         OUT PVOID ProcessInformation,
74         IN ULONG ProcessInformationLength,
75         OUT PULONG ReturnLength)
76 {
77     NTSTATUS ret = STATUS_SUCCESS;
78     ULONG len = 0;
79
80     TRACE("(%p,0x%08x,%p,0x%08lx,%p)\n",
81           ProcessHandle,ProcessInformationClass,
82           ProcessInformation,ProcessInformationLength,
83           ReturnLength);
84
85     switch (ProcessInformationClass) 
86     {
87     case ProcessBasicInformation:
88         if (ProcessInformationLength == sizeof(PROCESS_BASIC_INFORMATION))
89         {
90             if (!ProcessInformation) ret = STATUS_ACCESS_VIOLATION;
91             else
92             {
93                 SERVER_START_REQ(get_process_info)
94                 {
95                     req->handle = ProcessHandle;
96                     if ((ret = wine_server_call( req )) == STATUS_SUCCESS)
97                     {
98                         PROCESS_BASIC_INFORMATION* pbi = (PROCESS_BASIC_INFORMATION*)ProcessInformation;
99                         pbi->ExitStatus = reply->exit_code;
100                         pbi->PebBaseAddress = (DWORD)reply->peb;
101                         pbi->AffinityMask = reply->process_affinity;
102                         pbi->BasePriority = reply->priority;
103                         pbi->UniqueProcessId = reply->pid;
104                         pbi->InheritedFromUniqueProcessId = reply->ppid;
105                         len = sizeof(PROCESS_BASIC_INFORMATION);
106                     }
107                 }
108                 SERVER_END_REQ;
109             }
110         }
111         else ret = STATUS_INFO_LENGTH_MISMATCH;
112         break;
113     case ProcessIoCounters:
114         if (ProcessInformationLength == sizeof(IO_COUNTERS))
115         {
116             memset(ProcessInformation, 0, ProcessInformationLength);
117             len = sizeof(IO_COUNTERS);
118         }
119         else ret = STATUS_INFO_LENGTH_MISMATCH;
120         break;
121     case ProcessDebugPort:
122         /* "These are not the debuggers you are looking for." *
123          * set it to 0 aka "no debugger" to satisfy copy protections */
124         if (ProcessInformationLength == 4)
125         {
126             memset(ProcessInformation, 0, ProcessInformationLength);
127             len = 4;
128         }
129         else ret = STATUS_INFO_LENGTH_MISMATCH;
130         break;
131     case ProcessWow64Information:
132         if (ProcessInformationLength == 4)
133         {
134             memset(ProcessInformation, 0, ProcessInformationLength);
135             len = 4;
136         }
137         else ret = STATUS_INFO_LENGTH_MISMATCH;
138         break;
139     default:
140         FIXME("(%p,0x%08x,%p,0x%08lx,%p),stub!\n",
141               ProcessHandle,ProcessInformationClass,
142               ProcessInformation,ProcessInformationLength,
143               ReturnLength);
144         ret = STATUS_INVALID_INFO_CLASS;
145         break;
146     }
147
148     if (ReturnLength) *ReturnLength = len;
149     
150     return ret;
151 }
152
153 /******************************************************************************
154  * NtSetInformationProcess [NTDLL.@]
155  * ZwSetInformationProcess [NTDLL.@]
156  */
157 NTSTATUS WINAPI NtSetInformationProcess(
158         IN HANDLE ProcessHandle,
159         IN PROCESSINFOCLASS ProcessInformationClass,
160         IN PVOID ProcessInformation,
161         IN ULONG ProcessInformationLength)
162 {
163     FIXME("(%p,0x%08x,%p,0x%08lx) stub\n",
164           ProcessHandle,ProcessInformationClass,ProcessInformation,ProcessInformationLength);
165     return 0;
166 }
167
168 /******************************************************************************
169  * NtFlushInstructionCache [NTDLL.@]
170  * ZwFlushInstructionCache [NTDLL.@]
171  */
172 NTSTATUS WINAPI NtFlushInstructionCache(
173         IN HANDLE ProcessHandle,
174         IN LPCVOID BaseAddress,
175         IN ULONG Size)
176 {
177 #ifdef __i386__
178     TRACE("%p %p %ld - no-op on x86\n", ProcessHandle, BaseAddress, Size );
179 #else
180     FIXME("%p %p %ld\n", ProcessHandle, BaseAddress, Size );
181 #endif
182     return STATUS_SUCCESS;
183 }