ReactOS  0.4.13-dev-540-g8f04a09
job.c File Reference
#include <k32.h>
#include <winspool.h>
#include <debug.h>
Include dependency graph for job.c:

Go to the source code of this file.

Macros

#define NDEBUG
 

Functions

HANDLE WINAPI CreateJobObjectA (IN LPSECURITY_ATTRIBUTES lpJobAttributes, IN LPCSTR lpName)
 
HANDLE WINAPI CreateJobObjectW (IN LPSECURITY_ATTRIBUTES lpJobAttributes, IN LPCWSTR lpName)
 
HANDLE WINAPI OpenJobObjectW (IN DWORD dwDesiredAccess, IN BOOL bInheritHandle, IN LPCWSTR lpName)
 
HANDLE WINAPI OpenJobObjectA (IN DWORD dwDesiredAccess, IN BOOL bInheritHandle, IN LPCSTR lpName)
 
BOOL WINAPI IsProcessInJob (IN HANDLE ProcessHandle, IN HANDLE JobHandle, OUT PBOOL Result)
 
BOOL WINAPI AssignProcessToJobObject (IN HANDLE hJob, IN HANDLE hProcess)
 
BOOL WINAPI QueryInformationJobObject (IN HANDLE hJob, IN JOBOBJECTINFOCLASS JobObjectInformationClass, IN LPVOID lpJobObjectInformation, IN DWORD cbJobObjectInformationLength, OUT LPDWORD lpReturnLength)
 
BOOL WINAPI SetInformationJobObject (IN HANDLE hJob, IN JOBOBJECTINFOCLASS JobObjectInformationClass, IN LPVOID lpJobObjectInformation, IN DWORD cbJobObjectInformationLength)
 
BOOL WINAPI TerminateJobObject (IN HANDLE hJob, IN UINT uExitCode)
 
BOOL WINAPI CreateJobSet (IN ULONG NumJob, IN PJOB_SET_ARRAY UserJobSet, IN ULONG Flags)
 

Macro Definition Documentation

◆ NDEBUG

#define NDEBUG

Definition at line 16 of file job.c.

Function Documentation

◆ AssignProcessToJobObject()

BOOL WINAPI AssignProcessToJobObject ( IN HANDLE  hJob,
IN HANDLE  hProcess 
)

Definition at line 99 of file job.c.

101 {
103 
105  if (!NT_SUCCESS(Status))
106  {
108  return FALSE;
109  }
110 
111  return TRUE;
112 }
#define TRUE
Definition: types.h:120
LONG NTSTATUS
Definition: precomp.h:26
_In_ BOOL _In_ HANDLE hProcess
Definition: mapping.h:70
DWORD BaseSetLastNTError(IN NTSTATUS Status)
Definition: reactos.cpp:166
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
NTSTATUS NTAPI NtAssignProcessToJobObject(HANDLE JobHandle, HANDLE ProcessHandle)
Definition: job.c:157
Status
Definition: gdiplustypes.h:24

◆ CreateJobObjectA()

HANDLE WINAPI CreateJobObjectA ( IN LPSECURITY_ATTRIBUTES  lpJobAttributes,
IN LPCSTR  lpName 
)

Definition at line 26 of file job.c.

28 {
29  /* Call the W(ide) function */
30  ConvertWin32AnsiObjectApiToUnicodeApi(JobObject, lpName, lpJobAttributes);
31 }
_In_ LPCSTR lpName
Definition: winbase.h:2729
#define ConvertWin32AnsiObjectApiToUnicodeApi(obj, name,...)
Definition: base_x.h:54

◆ CreateJobObjectW()

HANDLE WINAPI CreateJobObjectW ( IN LPSECURITY_ATTRIBUTES  lpJobAttributes,
IN LPCWSTR  lpName 
)

Definition at line 38 of file job.c.

40 {
41  /* Create the NT object */
42  CreateNtObjectFromWin32Api(JobObject, JobObject, JOB_OBJECT, lpJobAttributes, lpName);
43 }
_In_ LPCSTR lpName
Definition: winbase.h:2729
#define CreateNtObjectFromWin32Api(obj, ntobj, capsobj, sec, name,...)
Definition: base_x.h:140

◆ CreateJobSet()

BOOL WINAPI CreateJobSet ( IN ULONG  NumJob,
IN PJOB_SET_ARRAY  UserJobSet,
IN ULONG  Flags 
)

Definition at line 338 of file job.c.

341 {
343 
344  Status = NtCreateJobSet(NumJob, UserJobSet, Flags);
345  if (!NT_SUCCESS(Status))
346  {
348  return FALSE;
349  }
350 
351  return TRUE;
352 }
#define TRUE
Definition: types.h:120
LONG NTSTATUS
Definition: precomp.h:26
NTSTATUS NTAPI NtCreateJobSet(IN ULONG NumJob, IN PJOB_SET_ARRAY UserJobSet, IN ULONG Flags)
Definition: job.c:243
_Must_inspect_result_ _In_ ULONG Flags
Definition: wsk.h:170
DWORD BaseSetLastNTError(IN NTSTATUS Status)
Definition: reactos.cpp:166
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
Status
Definition: gdiplustypes.h:24

◆ IsProcessInJob()

BOOL WINAPI IsProcessInJob ( IN HANDLE  ProcessHandle,
IN HANDLE  JobHandle,
OUT PBOOL  Result 
)

Definition at line 77 of file job.c.

80 {
82 
84  if (NT_SUCCESS(Status))
85  {
87  return TRUE;
88  }
89 
91  return FALSE;
92 }
#define TRUE
Definition: types.h:120
LONG NTSTATUS
Definition: precomp.h:26
_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:426
DWORD BaseSetLastNTError(IN NTSTATUS Status)
Definition: reactos.cpp:166
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
Status
Definition: gdiplustypes.h:24
#define STATUS_PROCESS_IN_JOB
Definition: ntstatus.h:108
NTSTATUS NTAPI NtIsProcessInJob(IN HANDLE ProcessHandle, IN HANDLE JobHandle OPTIONAL)
Definition: job.c:361
_In_ HANDLE ProcessHandle
Definition: mmfuncs.h:403

◆ OpenJobObjectA()

HANDLE WINAPI OpenJobObjectA ( IN DWORD  dwDesiredAccess,
IN BOOL  bInheritHandle,
IN LPCSTR  lpName 
)

Definition at line 64 of file job.c.

67 {
68  /* Call the W(ide) function */
70 }
_In_ LPCSTR lpName
Definition: winbase.h:2729
static BOOL bInheritHandle
Definition: pipe.c:82
#define ConvertOpenWin32AnsiObjectApiToUnicodeApi(obj, acc, inh, name)
Definition: base_x.h:86

◆ OpenJobObjectW()

HANDLE WINAPI OpenJobObjectW ( IN DWORD  dwDesiredAccess,
IN BOOL  bInheritHandle,
IN LPCWSTR  lpName 
)

Definition at line 50 of file job.c.

53 {
54  /* Open the NT object */
55  OpenNtObjectFromWin32Api(JobObject, dwDesiredAccess, bInheritHandle, lpName);
56 }
_In_ LPCSTR lpName
Definition: winbase.h:2729
#define OpenNtObjectFromWin32Api(ntobj, acc, inh, name)
Definition: base_x.h:148
static BOOL bInheritHandle
Definition: pipe.c:82

◆ QueryInformationJobObject()

BOOL WINAPI QueryInformationJobObject ( IN HANDLE  hJob,
IN JOBOBJECTINFOCLASS  JobObjectInformationClass,
IN LPVOID  lpJobObjectInformation,
IN DWORD  cbJobObjectInformationLength,
OUT LPDWORD  lpReturnLength 
)

Definition at line 119 of file job.c.

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 }
struct _JOBOBJECT_EXTENDED_LIMIT_INFORMATION JOBOBJECT_EXTENDED_LIMIT_INFORMATION
#define REALTIME_PRIORITY_CLASS
Definition: winbase.h:184
#define TRUE
Definition: types.h:120
NTSYSAPI VOID NTAPI RtlCopyMemory(VOID UNALIGNED *Destination, CONST VOID UNALIGNED *Source, ULONG Length)
#define STATUS_INFO_LENGTH_MISMATCH
Definition: udferr_usr.h:133
LONG NTSTATUS
Definition: precomp.h:26
#define NORMAL_PRIORITY_CLASS
Definition: winbase.h:181
#define ABOVE_NORMAL_PRIORITY_CLASS
Definition: winbase.h:191
JOBOBJECT_BASIC_LIMIT_INFORMATION BasicLimitInformation
Definition: pstypes.h:1533
#define HIGH_PRIORITY_CLASS
Definition: winbase.h:183
DWORD BaseSetLastNTError(IN NTSTATUS Status)
Definition: reactos.cpp:166
#define PROCESS_PRIORITY_CLASS_NORMAL
Definition: pstypes.h:108
#define PROCESS_PRIORITY_CLASS_ABOVE_NORMAL
Definition: pstypes.h:112
#define IDLE_PRIORITY_CLASS
Definition: winbase.h:182
#define PROCESS_PRIORITY_CLASS_REALTIME
Definition: pstypes.h:110
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
#define PROCESS_PRIORITY_CLASS_HIGH
Definition: pstypes.h:109
Status
Definition: gdiplustypes.h:24
struct _JOBOBJECT_BASIC_LIMIT_INFORMATION JOBOBJECT_BASIC_LIMIT_INFORMATION
#define BELOW_NORMAL_PRIORITY_CLASS
Definition: winbase.h:190
unsigned int ULONG
Definition: retypes.h:1
#define PROCESS_PRIORITY_CLASS_BELOW_NORMAL
Definition: pstypes.h:111
#define PROCESS_PRIORITY_CLASS_IDLE
Definition: pstypes.h:107
NTSTATUS NTAPI NtQueryInformationJobObject(HANDLE JobHandle, JOBOBJECTINFOCLASS JobInformationClass, PVOID JobInformation, ULONG JobInformationLength, PULONG ReturnLength)
Definition: job.c:485

Referenced by test_QueryInformationJobObject().

◆ SetInformationJobObject()

BOOL WINAPI SetInformationJobObject ( IN HANDLE  hJob,
IN JOBOBJECTINFOCLASS  JobObjectInformationClass,
IN LPVOID  lpJobObjectInformation,
IN DWORD  cbJobObjectInformationLength 
)

Definition at line 212 of file job.c.

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  {
255  case IDLE_PRIORITY_CLASS:
258  break;
259 
263  break;
264 
268  break;
269 
273  break;
274 
275  case HIGH_PRIORITY_CLASS:
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 }
struct _JOBOBJECT_EXTENDED_LIMIT_INFORMATION JOBOBJECT_EXTENDED_LIMIT_INFORMATION
#define REALTIME_PRIORITY_CLASS
Definition: winbase.h:184
#define TRUE
Definition: types.h:120
NTSYSAPI VOID NTAPI RtlCopyMemory(VOID UNALIGNED *Destination, CONST VOID UNALIGNED *Source, ULONG Length)
#define STATUS_INFO_LENGTH_MISMATCH
Definition: udferr_usr.h:133
LONG NTSTATUS
Definition: precomp.h:26
NTSTATUS NTAPI NtSetInformationJobObject(HANDLE JobHandle, JOBOBJECTINFOCLASS JobInformationClass, PVOID JobInformation, ULONG JobInformationLength)
Definition: job.c:752
#define NORMAL_PRIORITY_CLASS
Definition: winbase.h:181
#define ABOVE_NORMAL_PRIORITY_CLASS
Definition: winbase.h:191
JOBOBJECT_BASIC_LIMIT_INFORMATION BasicLimitInformation
Definition: pstypes.h:1533
#define JOB_OBJECT_LIMIT_WORKINGSET
Definition: pstypes.h:204
#define HIGH_PRIORITY_CLASS
Definition: winbase.h:183
smooth NULL
Definition: ftsmooth.c:416
NTSYSAPI VOID NTAPI RtlReleasePrivilege(_In_ PVOID ReturnedState)
DWORD BaseSetLastNTError(IN NTSTATUS Status)
Definition: reactos.cpp:166
#define PROCESS_PRIORITY_CLASS_NORMAL
Definition: pstypes.h:108
#define PROCESS_PRIORITY_CLASS_ABOVE_NORMAL
Definition: pstypes.h:112
#define IDLE_PRIORITY_CLASS
Definition: winbase.h:182
#define PROCESS_PRIORITY_CLASS_REALTIME
Definition: pstypes.h:110
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
BOOL Privilege(LPTSTR pszPrivilege, BOOL bEnable)
Definition: user_lib.cpp:531
#define PROCESS_PRIORITY_CLASS_HIGH
Definition: pstypes.h:109
#define SE_INC_BASE_PRIORITY_PRIVILEGE
Definition: security.c:668
Status
Definition: gdiplustypes.h:24
struct _JOBOBJECT_BASIC_LIMIT_INFORMATION JOBOBJECT_BASIC_LIMIT_INFORMATION
NTSYSAPI NTSTATUS NTAPI RtlAcquirePrivilege(_In_ PULONG Privilege, _In_ ULONG NumPriv, _In_ ULONG Flags, _Out_ PVOID *ReturnedState)
#define BELOW_NORMAL_PRIORITY_CLASS
Definition: winbase.h:190
unsigned int ULONG
Definition: retypes.h:1
#define PROCESS_PRIORITY_CLASS_BELOW_NORMAL
Definition: pstypes.h:111
#define PROCESS_PRIORITY_CLASS_IDLE
Definition: pstypes.h:107
#define JOB_OBJECT_LIMIT_PRIORITY_CLASS
Definition: pstypes.h:209

◆ TerminateJobObject()

BOOL WINAPI TerminateJobObject ( IN HANDLE  hJob,
IN UINT  uExitCode 
)

Definition at line 318 of file job.c.

320 {
322 
323  Status = NtTerminateJobObject(hJob, uExitCode);
324  if (!NT_SUCCESS(Status))
325  {
327  return FALSE;
328  }
329 
330  return TRUE;
331 }
#define TRUE
Definition: types.h:120
LONG NTSTATUS
Definition: precomp.h:26
DWORD BaseSetLastNTError(IN NTSTATUS Status)
Definition: reactos.cpp:166
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
Status
Definition: gdiplustypes.h:24
NTSTATUS NTAPI NtTerminateJobObject(HANDLE JobHandle, NTSTATUS ExitStatus)
Definition: job.c:850