[NTOS:PS] NtOpenJobObject:

- SAL2 annotate NtOpenJobObject and related user-mode functions
- Re-format NtOpenJobObject
- Don't use hungarian notation for handles in NtCreateJobObject and NtOpenJobObject
This commit is contained in:
Gleb Surikov 2024-06-17 17:30:13 +03:00
parent a16fbf0f1c
commit 6fa4ac7d09
2 changed files with 44 additions and 33 deletions

View file

@ -23,8 +23,8 @@
*/
HANDLE
WINAPI
CreateJobObjectA(IN LPSECURITY_ATTRIBUTES lpJobAttributes,
IN LPCSTR lpName)
CreateJobObjectA(_In_ LPSECURITY_ATTRIBUTES lpJobAttributes,
_In_ LPCSTR lpName)
{
/* Call the W(ide) function */
ConvertWin32AnsiObjectApiToUnicodeApi(JobObject, lpName, lpJobAttributes);
@ -35,8 +35,8 @@ CreateJobObjectA(IN LPSECURITY_ATTRIBUTES lpJobAttributes,
*/
HANDLE
WINAPI
CreateJobObjectW(IN LPSECURITY_ATTRIBUTES lpJobAttributes,
IN LPCWSTR lpName)
CreateJobObjectW(_In_ LPSECURITY_ATTRIBUTES lpJobAttributes,
_In_ LPCWSTR lpName)
{
/* Create the NT object */
CreateNtObjectFromWin32Api(JobObject, JobObject, JOB_OBJECT_ALL_ACCESS, lpJobAttributes, lpName);
@ -47,9 +47,9 @@ CreateJobObjectW(IN LPSECURITY_ATTRIBUTES lpJobAttributes,
*/
HANDLE
WINAPI
OpenJobObjectW(IN DWORD dwDesiredAccess,
IN BOOL bInheritHandle,
IN LPCWSTR lpName)
OpenJobObjectW(_In_ DWORD dwDesiredAccess,
_In_ BOOL bInheritHandle,
_In_ LPCWSTR lpName)
{
/* Open the NT object */
OpenNtObjectFromWin32Api(JobObject, dwDesiredAccess, bInheritHandle, lpName);
@ -61,9 +61,9 @@ OpenJobObjectW(IN DWORD dwDesiredAccess,
*/
HANDLE
WINAPI
OpenJobObjectA(IN DWORD dwDesiredAccess,
IN BOOL bInheritHandle,
IN LPCSTR lpName)
OpenJobObjectA(_In_ DWORD dwDesiredAccess,
_In_ BOOL bInheritHandle,
_In_ LPCSTR lpName)
{
/* Call the W(ide) function */
ConvertOpenWin32AnsiObjectApiToUnicodeApi(JobObject, dwDesiredAccess, bInheritHandle, lpName);

View file

@ -256,7 +256,6 @@ NtCreateJobSet(IN ULONG NumJob,
*
* @param[out] JobHandle
* A pointer to a handle that will receive the handle of the created job object.
* The caller must have write access to this memory.
*
* @param[in] DesiredAccess
* Specifies the desired access rights for the job object.
@ -264,7 +263,7 @@ NtCreateJobSet(IN ULONG NumJob,
* @param[in, optional] ObjectAttributes
* An optional pointer to an object attributes block
*
* @returns
* @returns
* STATUS_SUCCESS if the job object is successfully created.
* An appropriate NTSTATUS error code otherwise.
*/
@ -276,7 +275,7 @@ NtCreateJobObject(
_In_opt_ POBJECT_ATTRIBUTES ObjectAttributes
)
{
HANDLE hJob;
HANDLE Handle;
PEJOB Job;
KPROCESSOR_MODE PreviousMode;
PEPROCESS CurrentProcess;
@ -348,7 +347,7 @@ NtCreateJobObject(
DesiredAccess,
0,
NULL,
&hJob);
&Handle);
if (NT_SUCCESS(Status))
{
/* Pass the handle back to the caller */
@ -357,7 +356,7 @@ NtCreateJobObject(
/* NOTE: if the caller passed invalid buffers to receive the handle it's his
own fault! the object will still be created and live... It's possible
to find the handle using ObFindHandleForObject()! */
*JobHandle = hJob;
*JobHandle = Handle;
}
_SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER)
{
@ -437,26 +436,39 @@ NtIsProcessInJob (
return Status;
}
/*
* @implemented
/*!
* Opens a handle to an existing job object.
*
* @param JobHandle
* A pointer to a handle that will receive the handle of the created job object.
*
* @param DesiredAccess
* Specifies the desired access rights for the job object.
*
* @param ObjectAttributes
* Pointer to the OBJECT_ATTRIBUTES structure specifying the object name and attributes.
*
* @returns
* STATUS_SUCCESS if the job object is successfully created.
* An appropriate NTSTATUS error code otherwise.
*/
NTSTATUS
NTAPI
NtOpenJobObject (
PHANDLE JobHandle,
ACCESS_MASK DesiredAccess,
POBJECT_ATTRIBUTES ObjectAttributes)
NtOpenJobObject(
_Out_ PHANDLE JobHandle,
_In_ ACCESS_MASK DesiredAccess,
_In_ POBJECT_ATTRIBUTES ObjectAttributes
)
{
KPROCESSOR_MODE PreviousMode;
HANDLE hJob;
HANDLE Handle;
NTSTATUS Status;
PAGED_CODE();
PreviousMode = ExGetPreviousMode();
/* check for valid buffers */
/* Check for valid buffers */
if (PreviousMode != KernelMode)
{
_SEH2_TRY
@ -476,12 +488,12 @@ NtOpenJobObject (
NULL,
DesiredAccess,
NULL,
&hJob);
if(NT_SUCCESS(Status))
&Handle);
if (NT_SUCCESS(Status))
{
_SEH2_TRY
{
*JobHandle = hJob;
*JobHandle = Handle;
}
_SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER)
{
@ -493,7 +505,6 @@ NtOpenJobObject (
return Status;
}
/*
* @implemented
*/