ReactOS 0.4.16-dev-197-g92996da
job.c
Go to the documentation of this file.
1/*
2 * COPYRIGHT: See COPYING in the top level directory
3 * PROJECT: ReactOS system libraries
4 * FILE: dll/win32/kernel32/client/job.c
5 * PURPOSE: Job functions
6 * PROGRAMMER: Thomas Weidenmueller <w3seek@reactos.com>
7 * UPDATE HISTORY:
8 * Created 9/23/2004
9 */
10
11/* INCLUDES *******************************************************************/
12
13#include <k32.h>
14#include <winspool.h>
15
16#define NDEBUG
17#include <debug.h>
18
19/* FUNCTIONS ******************************************************************/
20
21/*
22 * @implemented
23 */
28{
29 /* Call the W(ide) function */
30 ConvertWin32AnsiObjectApiToUnicodeApi(JobObject, lpName, lpJobAttributes);
31}
32
33/*
34 * @implemented
35 */
40{
41 /* Create the NT object */
42 CreateNtObjectFromWin32Api(JobObject, JobObject, JOB_OBJECT_ALL_ACCESS, lpJobAttributes, lpName);
43}
44
45/*
46 * @implemented
47 */
50OpenJobObjectW(IN DWORD dwDesiredAccess,
53{
54 /* Open the NT object */
55 OpenNtObjectFromWin32Api(JobObject, dwDesiredAccess, bInheritHandle, lpName);
56}
57
58
59/*
60 * @implemented
61 */
64OpenJobObjectA(IN DWORD dwDesiredAccess,
67{
68 /* Call the W(ide) function */
70}
71
72/*
73 * @implemented
74 */
75BOOL
78 IN HANDLE JobHandle,
80{
82
84 if (NT_SUCCESS(Status))
85 {
87 return TRUE;
88 }
89
91 return FALSE;
92}
93
94/*
95 * @implemented
96 */
97BOOL
101{
103
105 if (!NT_SUCCESS(Status))
106 {
108 return FALSE;
109 }
110
111 return TRUE;
112}
113
114/*
115 * @implemented
116 */
117BOOL
118WINAPI
120 IN JOBOBJECTINFOCLASS JobObjectInformationClass,
121 IN LPVOID lpJobObjectInformation,
122 IN DWORD cbJobObjectInformationLength,
123 OUT LPDWORD lpReturnLength)
124{
126 PVOID JobInfo;
128 ULONG ExpectedSize;
129
130 if (JobObjectInformationClass == JobObjectBasicLimitInformation)
131 {
132 ExpectedSize = sizeof(JOBOBJECT_BASIC_LIMIT_INFORMATION);
133 JobInfo = &LocalInfo;
134 }
135 else if (JobObjectInformationClass == JobObjectExtendedLimitInformation)
136 {
137 ExpectedSize = sizeof(JOBOBJECT_EXTENDED_LIMIT_INFORMATION);
138 JobInfo = &LocalInfo;
139 }
140 else
141 {
142 ExpectedSize = cbJobObjectInformationLength;
143 JobInfo = lpJobObjectInformation;
144 }
145
146 if (cbJobObjectInformationLength != ExpectedSize)
147 {
149 return FALSE;
150 }
151
153 JobObjectInformationClass,
154 JobInfo,
155 ExpectedSize,
156 lpReturnLength);
157 if (NT_SUCCESS(Status))
158 {
159 if (JobInfo != &LocalInfo) return TRUE;
160
161 switch (LocalInfo.BasicLimitInformation.PriorityClass)
162 {
166 break;
167
171 break;
172
176 break;
177
181 break;
182
186 break;
187
191 break;
192
193 default:
196 break;
197 }
198
199 RtlCopyMemory(lpJobObjectInformation, &LocalInfo, ExpectedSize);
200 return TRUE;
201 }
202
204 return FALSE;
205}
206
207/*
208 * @implemented
209 */
210BOOL
211WINAPI
213 IN JOBOBJECTINFOCLASS JobObjectInformationClass,
214 IN LPVOID lpJobObjectInformation,
215 IN DWORD cbJobObjectInformationLength)
216{
218 PVOID JobInfo;
220 ULONG ExpectedSize;
221 PVOID State = NULL;
223
224 if (JobObjectInformationClass == JobObjectBasicLimitInformation)
225 {
226 ExpectedSize = sizeof(JOBOBJECT_BASIC_LIMIT_INFORMATION);
227 JobInfo = &LocalInfo;
228 }
229 else if (JobObjectInformationClass == JobObjectExtendedLimitInformation)
230 {
231 ExpectedSize = sizeof(JOBOBJECT_EXTENDED_LIMIT_INFORMATION);
232 JobInfo = &LocalInfo;
233 }
234 else
235 {
236 ExpectedSize = cbJobObjectInformationLength;
237 JobInfo = lpJobObjectInformation;
238 }
239
240 if (cbJobObjectInformationLength != ExpectedSize)
241 {
243 return FALSE;
244 }
245
246 if (JobInfo == &LocalInfo)
247 {
248 RtlCopyMemory(&LocalInfo, lpJobObjectInformation, ExpectedSize);
249
250 if (LocalInfo.BasicLimitInformation.LimitFlags &
252 {
253 switch (LocalInfo.BasicLimitInformation.PriorityClass)
254 {
258 break;
259
263 break;
264
268 break;
269
273 break;
274
278 break;
279
283 break;
284
285 default:
288 break;
289 }
290 }
291
292 if (LocalInfo.BasicLimitInformation.LimitFlags &
294 {
296 }
297 }
298
300 JobObjectInformationClass,
301 JobInfo,
302 ExpectedSize);
303 if (NT_SUCCESS(Status))
304 {
306 return TRUE;
307 }
308
310 return FALSE;
311}
312
313/*
314 * @implemented
315 */
316BOOL
317WINAPI
319 IN UINT uExitCode)
320{
322
323 Status = NtTerminateJobObject(hJob, uExitCode);
324 if (!NT_SUCCESS(Status))
325 {
327 return FALSE;
328 }
329
330 return TRUE;
331}
332
333/*
334 * @implemented
335 */
336BOOL
337WINAPI
339 IN PJOB_SET_ARRAY UserJobSet,
340 IN ULONG Flags)
341{
343
344 Status = NtCreateJobSet(NumJob, UserJobSet, Flags);
345 if (!NT_SUCCESS(Status))
346 {
348 return FALSE;
349 }
350
351 return TRUE;
352}
353
354/* EOF */
LONG NTSTATUS
Definition: precomp.h:26
#define ConvertWin32AnsiObjectApiToUnicodeApi(obj, name,...)
Definition: base_x.h:54
#define ConvertOpenWin32AnsiObjectApiToUnicodeApi(obj, acc, inh, name)
Definition: base_x.h:86
#define CreateNtObjectFromWin32Api(obj, ntobj, access, sec, name,...)
Definition: base_x.h:135
#define OpenNtObjectFromWin32Api(ntobj, acc, inh, name)
Definition: base_x.h:143
#define NULL
Definition: types.h:112
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:33
BOOL WINAPI QueryInformationJobObject(IN HANDLE hJob, IN JOBOBJECTINFOCLASS JobObjectInformationClass, IN LPVOID lpJobObjectInformation, IN DWORD cbJobObjectInformationLength, OUT LPDWORD lpReturnLength)
Definition: job.c:119
HANDLE WINAPI OpenJobObjectW(IN DWORD dwDesiredAccess, IN BOOL bInheritHandle, IN LPCWSTR lpName)
Definition: job.c:50
BOOL WINAPI AssignProcessToJobObject(IN HANDLE hJob, IN HANDLE hProcess)
Definition: job.c:99
BOOL WINAPI CreateJobSet(IN ULONG NumJob, IN PJOB_SET_ARRAY UserJobSet, IN ULONG Flags)
Definition: job.c:338
BOOL WINAPI IsProcessInJob(IN HANDLE ProcessHandle, IN HANDLE JobHandle, OUT PBOOL Result)
Definition: job.c:77
HANDLE WINAPI OpenJobObjectA(IN DWORD dwDesiredAccess, IN BOOL bInheritHandle, IN LPCSTR lpName)
Definition: job.c:64
HANDLE WINAPI CreateJobObjectA(IN LPSECURITY_ATTRIBUTES lpJobAttributes, IN LPCSTR lpName)
Definition: job.c:26
BOOL WINAPI SetInformationJobObject(IN HANDLE hJob, IN JOBOBJECTINFOCLASS JobObjectInformationClass, IN LPVOID lpJobObjectInformation, IN DWORD cbJobObjectInformationLength)
Definition: job.c:212
BOOL WINAPI TerminateJobObject(IN HANDLE hJob, IN UINT uExitCode)
Definition: job.c:318
HANDLE WINAPI CreateJobObjectW(IN LPSECURITY_ATTRIBUTES lpJobAttributes, IN LPCWSTR lpName)
Definition: job.c:38
unsigned int BOOL
Definition: ntddk_ex.h:94
unsigned long DWORD
Definition: ntddk_ex.h:95
Status
Definition: gdiplustypes.h:25
#define PROCESS_PRIORITY_CLASS_IDLE
Definition: pstypes.h:108
#define JOB_OBJECT_ALL_ACCESS
Definition: pstypes.h:206
#define JOB_OBJECT_LIMIT_WORKINGSET
Definition: pstypes.h:213
#define PROCESS_PRIORITY_CLASS_NORMAL
Definition: pstypes.h:109
#define PROCESS_PRIORITY_CLASS_HIGH
Definition: pstypes.h:110
#define PROCESS_PRIORITY_CLASS_ABOVE_NORMAL
Definition: pstypes.h:113
enum _JOBOBJECTINFOCLASS JOBOBJECTINFOCLASS
#define JOB_OBJECT_LIMIT_PRIORITY_CLASS
Definition: pstypes.h:218
@ JobObjectBasicLimitInformation
Definition: pstypes.h:430
@ JobObjectExtendedLimitInformation
Definition: pstypes.h:437
struct _JOBOBJECT_EXTENDED_LIMIT_INFORMATION JOBOBJECT_EXTENDED_LIMIT_INFORMATION
#define PROCESS_PRIORITY_CLASS_BELOW_NORMAL
Definition: pstypes.h:112
#define PROCESS_PRIORITY_CLASS_REALTIME
Definition: pstypes.h:111
struct _JOBOBJECT_BASIC_LIMIT_INFORMATION JOBOBJECT_BASIC_LIMIT_INFORMATION
_In_ BOOL _In_ HANDLE hProcess
Definition: mapping.h:71
#define SE_INC_BASE_PRIORITY_PRIVILEGE
Definition: security.c:668
static BOOL bInheritHandle
Definition: pipe.c:82
unsigned int UINT
Definition: ndis.h:50
_In_ HANDLE ProcessHandle
Definition: mmfuncs.h:403
NTSYSAPI NTSTATUS NTAPI RtlAcquirePrivilege(_In_ PULONG Privilege, _In_ ULONG NumPriv, _In_ ULONG Flags, _Out_ PVOID *ReturnedState)
NTSYSAPI VOID NTAPI RtlReleasePrivilege(_In_ PVOID ReturnedState)
NTSTATUS NTAPI NtIsProcessInJob(IN HANDLE ProcessHandle, IN HANDLE JobHandle OPTIONAL)
Definition: job.c:361
NTSTATUS NTAPI NtQueryInformationJobObject(HANDLE JobHandle, JOBOBJECTINFOCLASS JobInformationClass, PVOID JobInformation, ULONG JobInformationLength, PULONG ReturnLength)
Definition: job.c:485
NTSTATUS NTAPI NtTerminateJobObject(HANDLE JobHandle, NTSTATUS ExitStatus)
Definition: job.c:850
NTSTATUS NTAPI NtSetInformationJobObject(HANDLE JobHandle, JOBOBJECTINFOCLASS JobInformationClass, PVOID JobInformation, ULONG JobInformationLength)
Definition: job.c:752
NTSTATUS NTAPI NtAssignProcessToJobObject(HANDLE JobHandle, HANDLE ProcessHandle)
Definition: job.c:157
NTSTATUS NTAPI NtCreateJobSet(IN ULONG NumJob, IN PJOB_SET_ARRAY UserJobSet, IN ULONG Flags)
Definition: job.c:243
#define STATUS_PROCESS_IN_JOB
Definition: ntstatus.h:108
DWORD BaseSetLastNTError(IN NTSTATUS Status)
Definition: reactos.cpp:167
JOBOBJECT_BASIC_LIMIT_INFORMATION BasicLimitInformation
Definition: pstypes.h:1603
uint32_t * LPDWORD
Definition: typedefs.h:59
#define RtlCopyMemory(Destination, Source, Length)
Definition: typedefs.h:263
#define IN
Definition: typedefs.h:39
uint32_t ULONG
Definition: typedefs.h:59
#define OUT
Definition: typedefs.h:40
#define STATUS_INFO_LENGTH_MISMATCH
Definition: udferr_usr.h:133
BOOL Privilege(LPTSTR pszPrivilege, BOOL bEnable)
Definition: user_lib.cpp:531
#define NORMAL_PRIORITY_CLASS
Definition: winbase.h:183
#define REALTIME_PRIORITY_CLASS
Definition: winbase.h:186
#define BELOW_NORMAL_PRIORITY_CLASS
Definition: winbase.h:192
_In_ LPCSTR lpName
Definition: winbase.h:2813
#define HIGH_PRIORITY_CLASS
Definition: winbase.h:185
#define IDLE_PRIORITY_CLASS
Definition: winbase.h:184
#define ABOVE_NORMAL_PRIORITY_CLASS
Definition: winbase.h:193
BOOL * PBOOL
Definition: windef.h:161
#define WINAPI
Definition: msvc.h:6
_At_(*)(_In_ PWSK_CLIENT Client, _In_opt_ PUNICODE_STRING NodeName, _In_opt_ PUNICODE_STRING ServiceName, _In_opt_ ULONG NameSpace, _In_opt_ GUID *Provider, _In_opt_ PADDRINFOEXW Hints, _Outptr_ PADDRINFOEXW *Result, _In_opt_ PEPROCESS OwningProcess, _In_opt_ PETHREAD OwningThread, _Inout_ PIRP Irp Result)(Mem)) NTSTATUS(WSKAPI *PFN_WSK_GET_ADDRESS_INFO
Definition: wsk.h:409
_Must_inspect_result_ _In_ ULONG Flags
Definition: wsk.h:170
const char * LPCSTR
Definition: xmlstorage.h:183
const WCHAR * LPCWSTR
Definition: xmlstorage.h:185