ReactOS 0.4.17-dev-769-g1500a35
job.c File Reference
#include <win32k.h>
Include dependency graph for job.c:

Go to the source code of this file.

Macros

#define JOB_PROCESS_GROWTH   8
 
#define JOB_HANDLE_GROWTH   16
 

Functions

 DBG_DEFAULT_CHANNEL (UserProcess)
 
 _Requires_lock_held_ (UserLock)
 
 _Requires_exclusive_lock_held_ (UserLock)
 
static NTSTATUS IntJobSetRestrictions (_In_ PEJOB pEJob, _In_ ULONG UIRestrictions)
 
static NTSTATUS IntJobAddProcess (_In_ PEJOB pEJob, _In_ PPROCESSINFO ppi)
 
static NTSTATUS IntJobTerminate (_In_ PEJOB pEJob)
 
NTSTATUS NTAPI Win32kJobCallout (_In_ PWIN32_JOBCALLOUT_PARAMETERS Parameters)
 
BOOL APIENTRY NtUserUserHandleGrantAccess (_In_ HANDLE hUserHandle, _In_ HANDLE hJob, _In_ BOOL bGrant)
 

Variables

static PJOBINFO gJobInfoList = NULL
 

Macro Definition Documentation

◆ JOB_HANDLE_GROWTH

#define JOB_HANDLE_GROWTH   16

Definition at line 24 of file job.c.

◆ JOB_PROCESS_GROWTH

#define JOB_PROCESS_GROWTH   8

Definition at line 23 of file job.c.

Function Documentation

◆ _Requires_exclusive_lock_held_()

_Requires_exclusive_lock_held_ ( UserLock  )

Definition at line 50 of file job.c.

54{
55 PJOBINFO pJobInfo;
57
59
61 if (pJobInfo == NULL)
62 {
63 ERR("Failed to allocate a JOBINFO for job %p\n", pEJob);
64 return NULL;
65 }
66
67 Status = RtlCreateAtomTable(37, &pJobInfo->pAtomTable);
68 if (!NT_SUCCESS(Status))
69 {
70 ERR("Failed to create the atom table of job %p: 0x%lx\n", pEJob, Status);
72 return NULL;
73 }
74
75 pJobInfo->pEJob = pEJob;
76
77 pJobInfo->Next = gJobInfoList;
78 gJobInfoList = pJobInfo;
79
80 TRACE("Created JOBINFO %p for job %p\n", pJobInfo, pEJob);
81 return pJobInfo;
82}
LONG NTSTATUS
Definition: precomp.h:26
#define ERR(fmt,...)
Definition: precomp.h:57
#define NULL
Definition: types.h:112
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:33
#define PagedPool
Definition: env_spec_w32.h:308
Status
Definition: gdiplustypes.h:24
#define ASSERT(a)
Definition: mode.c:44
#define ExFreePoolWithTag(_P, _T)
Definition: module.h:1109
static PVOID ExAllocatePoolZero(ULONG PoolType, SIZE_T NumberOfBytes, ULONG Tag)
Definition: precomp.h:45
NTSYSAPI NTSTATUS NTAPI RtlCreateAtomTable(_In_ ULONG TableSize, _Inout_ PRTL_ATOM_TABLE *AtomTable)
BOOL FASTCALL UserIsEnteredExclusive(VOID)
Definition: ntuser.c:231
#define TRACE(s)
Definition: solgame.cpp:4
Definition: job.h:12
PEJOB pEJob
Definition: job.h:14
PRTL_ATOM_TABLE pAtomTable
Definition: job.h:15
struct _JOBINFO * Next
Definition: job.h:13
static PJOBINFO gJobInfoList
Definition: job.c:28
#define USERTAG_W32JOB
Definition: tags.h:241

◆ _Requires_lock_held_()

_Requires_lock_held_ ( UserLock  )

Definition at line 32 of file job.c.

36{
37 PJOBINFO pJobInfo;
38
40
41 for (pJobInfo = gJobInfoList; pJobInfo != NULL; pJobInfo = pJobInfo->Next)
42 {
43 if (pJobInfo->pEJob == pEJob)
44 return pJobInfo;
45 }
46
47 return NULL;
48}
BOOL FASTCALL UserIsEntered(VOID)
Definition: ntuser.c:225

◆ DBG_DEFAULT_CHANNEL()

DBG_DEFAULT_CHANNEL ( UserProcess  )

◆ IntJobAddProcess()

static NTSTATUS IntJobAddProcess ( _In_ PEJOB  pEJob,
_In_ PPROCESSINFO  ppi 
)
static

Definition at line 328 of file job.c.

331{
333 PJOBINFO pJobInfo;
334
336
337 pJobInfo = IntFindJobInfo(pEJob);
338 if (pJobInfo == NULL)
339 {
340 /* The kernel only calls us for jobs that have restrictions,
341 so we should have been told about this job already */
342 ERR("No JOBINFO for job %p\n", pEJob);
344 }
345 else
346 {
347 Status = IntAddProcessToJobInfo(pJobInfo, ppi);
348 }
349
350 UserLeave();
351 return Status;
352}
VOID FASTCALL UserLeave(VOID)
Definition: ntuser.c:255
VOID FASTCALL UserEnterExclusive(VOID)
Definition: ntuser.c:247
#define STATUS_UNSUCCESSFUL
Definition: udferr_usr.h:132

Referenced by Win32kJobCallout().

◆ IntJobSetRestrictions()

static NTSTATUS IntJobSetRestrictions ( _In_ PEJOB  pEJob,
_In_ ULONG  UIRestrictions 
)
static

Definition at line 266 of file job.c.

269{
271 PJOBINFO pJobInfo;
272 BOOL Created = FALSE;
273
275
276 pJobInfo = IntFindJobInfo(pEJob);
277
278 /* No restrictions left, so no state to keep */
279 if (UIRestrictions == 0)
280 {
281 if (pJobInfo != NULL)
282 IntDestroyJobInfo(pJobInfo);
283
284 goto Quit;
285 }
286
287 if (pJobInfo == NULL)
288 {
289 PPROCESSINFO ppi;
290
291 pJobInfo = IntCreateJobInfo(pEJob);
292 if (pJobInfo == NULL)
293 {
295 goto Quit;
296 }
297
298 Created = TRUE;
299
300 /* The job may already hold processes that connected to USER before
301 the restrictions were applied */
302 for (ppi = gppiList; ppi != NULL; ppi = ppi->ppiNext)
303 {
304 if (ppi->peProcess != NULL &&
305 PsGetProcessJob(ppi->peProcess) == pEJob)
306 {
307 Status = IntAddProcessToJobInfo(pJobInfo, ppi);
308 if (!NT_SUCCESS(Status))
309 goto Quit;
310 }
311 }
312 }
313
314 pJobInfo->UIRestrictions = UIRestrictions;
315
316Quit:
317 /* Undo a job we did not manage to finish building */
318 if (!NT_SUCCESS(Status) && Created)
319 IntDestroyJobInfo(pJobInfo);
320
321 UserLeave();
322 return Status;
323}
#define STATUS_NO_MEMORY
Definition: d3dkmdt.h:51
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
unsigned int BOOL
Definition: ntddk_ex.h:94
PEJOB NTAPI PsGetProcessJob(PEPROCESS Process)
Definition: process.c:1123
#define STATUS_SUCCESS
Definition: shellext.h:65
ULONG UIRestrictions
Definition: job.h:16
PPROCESSINFO ppiNext
Definition: win32.h:263
PPROCESSINFO gppiList
Definition: main.c:31

Referenced by Win32kJobCallout().

◆ IntJobTerminate()

static NTSTATUS IntJobTerminate ( _In_ PEJOB  pEJob)
static

Definition at line 357 of file job.c.

358{
359 PJOBINFO pJobInfo;
360
362
363 pJobInfo = IntFindJobInfo(pEJob);
364 if (pJobInfo != NULL)
365 IntDestroyJobInfo(pJobInfo);
366
367 UserLeave();
368 return STATUS_SUCCESS;
369}

Referenced by Win32kJobCallout().

◆ NtUserUserHandleGrantAccess()

BOOL APIENTRY NtUserUserHandleGrantAccess ( _In_ HANDLE  hUserHandle,
_In_ HANDLE  hJob,
_In_ BOOL  bGrant 
)

Definition at line 587 of file job.c.

591{
592 PEJOB pEJob;
593 PJOBINFO pJobInfo;
595 BOOL Ret = FALSE;
596
597 if (hUserHandle == NULL)
598 {
600 return FALSE;
601 }
602
605 PsJobType,
606 UserMode,
607 (PVOID*)&pEJob,
608 NULL);
609 if (!NT_SUCCESS(Status))
610 {
612 return FALSE;
613 }
614
616
617 pJobInfo = IntFindJobInfo(pEJob);
618 if (pJobInfo == NULL)
619 {
620 /* A job with no UI restrictions at all keeps no granted list */
622 }
623 else
624 {
625 Ret = IntGrantHandleToJob(pJobInfo, hUserHandle, bGrant);
626 }
627
628 UserLeave();
629
630 ObDereferenceObject(pEJob);
631 return Ret;
632}
#define ERROR_INVALID_PARAMETER
Definition: compat.h:101
#define JOB_OBJECT_SET_ATTRIBUTES
Definition: pstypes.h:197
#define UserMode
Definition: asm.h:39
NTSTATUS NTAPI ObReferenceObjectByHandle(IN HANDLE Handle, IN ACCESS_MASK DesiredAccess, IN POBJECT_TYPE ObjectType, IN KPROCESSOR_MODE AccessMode, OUT PVOID *Object, OUT POBJECT_HANDLE_INFORMATION HandleInformation OPTIONAL)
Definition: obref.c:493
POBJECT_TYPE PsJobType
Definition: job.c:23
VOID FASTCALL SetLastNtError(_In_ NTSTATUS Status)
Definition: error.c:30
ENGAPI VOID APIENTRY EngSetLastError(_In_ ULONG iError)
Definition: error.c:21
#define ObDereferenceObject
Definition: obfuncs.h:203

◆ Win32kJobCallout()

NTSTATUS NTAPI Win32kJobCallout ( _In_ PWIN32_JOBCALLOUT_PARAMETERS  Parameters)

Definition at line 476 of file job.c.

477{
478 switch (Parameters->CalloutType)
479 {
482 PtrToUlong(Parameters->Data));
483
485 return IntJobAddProcess((PEJOB)Parameters->Job,
486 (PPROCESSINFO)Parameters->Data);
487
489 return IntJobTerminate((PEJOB)Parameters->Job);
490
491 default:
492 ERR("Unknown job callout %d\n", Parameters->CalloutType);
494 }
495}
_In_ HANDLE _In_ CONST PDXGKMDT_OPM_GET_INFO_PARAMETERS Parameters
Definition: dispmprt.h:321
#define PtrToUlong(u)
Definition: config.h:107
@ PsW32JobCalloutTerminate
Definition: pstypes.h:555
@ PsW32JobCalloutAddProcess
Definition: pstypes.h:554
@ PsW32JobCalloutSetInformation
Definition: pstypes.h:553
#define STATUS_INVALID_PARAMETER
Definition: udferr_usr.h:135
static NTSTATUS IntJobSetRestrictions(_In_ PEJOB pEJob, _In_ ULONG UIRestrictions)
Definition: job.c:266
static NTSTATUS IntJobTerminate(_In_ PEJOB pEJob)
Definition: job.c:357
static NTSTATUS IntJobAddProcess(_In_ PEJOB pEJob, _In_ PPROCESSINFO ppi)
Definition: job.c:328

Referenced by DriverEntry().

Variable Documentation

◆ gJobInfoList

PJOBINFO gJobInfoList = NULL
static

Definition at line 28 of file job.c.

Referenced by _Requires_exclusive_lock_held_(), and _Requires_lock_held_().