mirror of
https://github.com/donnaskiez/ac.git
synced 2024-11-21 22:24:08 +01:00
change lock prim
This commit is contained in:
parent
012e9e5116
commit
6b32374c98
6 changed files with 145 additions and 128 deletions
|
@ -15,7 +15,7 @@ typedef struct _THREAD_LIST
|
|||
{
|
||||
SINGLE_LIST_ENTRY start;
|
||||
volatile BOOLEAN active;
|
||||
KSPIN_LOCK lock;
|
||||
KGUARDED_MUTEX lock;
|
||||
|
||||
}THREAD_LIST, * PTHREAD_LIST;
|
||||
|
||||
|
@ -26,7 +26,7 @@ typedef struct _PROCESS_LIST
|
|||
{
|
||||
SINGLE_LIST_ENTRY start;
|
||||
volatile BOOLEAN active;
|
||||
KSPIN_LOCK lock;
|
||||
KGUARDED_MUTEX lock;
|
||||
|
||||
}PROCESS_LIST, *PPROCESS_LIST;
|
||||
|
||||
|
@ -85,16 +85,16 @@ CleanupThreadListOnDriverUnload()
|
|||
* Important to remember the callback function will run at irql = DISPATCH_LEVEL since
|
||||
* we hold the spinlock during enumeration.
|
||||
*/
|
||||
_Acquires_lock_(_Lock_kind_spin_lock_)
|
||||
_Releases_lock_(_Lock_kind_spin_lock_)
|
||||
_IRQL_requires_max_(APC_LEVEL)
|
||||
_Acquires_lock_(_Lock_kind_mutex_)
|
||||
_Releases_lock_(_Lock_kind_mutex_)
|
||||
VOID
|
||||
EnumerateThreadListWithCallbackRoutine(
|
||||
_In_ PVOID CallbackRoutine,
|
||||
_In_opt_ PVOID Context
|
||||
)
|
||||
{
|
||||
KIRQL irql = KeGetCurrentIrql();
|
||||
KeAcquireSpinLock(&thread_list->lock, &irql);
|
||||
KeAcquireGuardedMutex(&thread_list->lock);
|
||||
|
||||
if (!CallbackRoutine)
|
||||
goto unlock;
|
||||
|
@ -109,19 +109,19 @@ EnumerateThreadListWithCallbackRoutine(
|
|||
}
|
||||
|
||||
unlock:
|
||||
KeReleaseSpinLock(&thread_list->lock, irql);
|
||||
KeReleaseGuardedMutex(&thread_list->lock);
|
||||
}
|
||||
|
||||
_Acquires_lock_(_Lock_kind_spin_lock_)
|
||||
_Releases_lock_(_Lock_kind_spin_lock_)
|
||||
_IRQL_requires_max_(APC_LEVEL)
|
||||
_Acquires_lock_(_Lock_kind_mutex_)
|
||||
_Releases_lock_(_Lock_kind_mutex_)
|
||||
VOID
|
||||
EnumerateProcessListWithCallbackRoutine(
|
||||
_In_ PVOID CallbackRoutine,
|
||||
_In_opt_ PVOID Context
|
||||
)
|
||||
{
|
||||
KIRQL irql = KeGetCurrentIrql();
|
||||
KeAcquireSpinLock(&process_list->lock, &irql);
|
||||
KeAcquireGuardedMutex(&process_list->lock);
|
||||
|
||||
if (!CallbackRoutine)
|
||||
goto unlock;
|
||||
|
@ -136,7 +136,7 @@ EnumerateProcessListWithCallbackRoutine(
|
|||
}
|
||||
|
||||
unlock:
|
||||
KeReleaseSpinLock(&process_list->lock, irql);
|
||||
KeReleaseGuardedMutex(&process_list->lock);
|
||||
}
|
||||
|
||||
NTSTATUS
|
||||
|
@ -173,17 +173,17 @@ InitialiseThreadList()
|
|||
return STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
_Acquires_lock_(_Lock_kind_spin_lock_)
|
||||
_Releases_lock_(_Lock_kind_spin_lock_)
|
||||
_IRQL_requires_max_(APC_LEVEL)
|
||||
_Acquires_lock_(_Lock_kind_mutex_)
|
||||
_Releases_lock_(_Lock_kind_mutex_)
|
||||
VOID
|
||||
FindProcessListEntryByProcess(
|
||||
_In_ PKPROCESS Process,
|
||||
_Inout_ PPROCESS_LIST_ENTRY* Entry
|
||||
)
|
||||
{
|
||||
KIRQL irql = KeGetCurrentIrql();
|
||||
*Entry = NULL;
|
||||
KeAcquireSpinLock(&process_list->lock, &irql);
|
||||
KeAcquireGuardedMutex(&process_list->lock);
|
||||
|
||||
PPROCESS_LIST_ENTRY entry = (PPROCESS_LIST_ENTRY)process_list->start.Next;
|
||||
|
||||
|
@ -198,20 +198,20 @@ FindProcessListEntryByProcess(
|
|||
entry = entry->list.Next;
|
||||
}
|
||||
unlock:
|
||||
KeReleaseSpinLock(&process_list->lock, irql);
|
||||
KeReleaseGuardedMutex(&process_list->lock);
|
||||
}
|
||||
|
||||
_Acquires_lock_(_Lock_kind_spin_lock_)
|
||||
_Releases_lock_(_Lock_kind_spin_lock_)
|
||||
_IRQL_requires_max_(APC_LEVEL)
|
||||
_Acquires_lock_(_Lock_kind_mutex_)
|
||||
_Releases_lock_(_Lock_kind_mutex_)
|
||||
VOID
|
||||
FindThreadListEntryByThreadAddress(
|
||||
_In_ PKTHREAD Thread,
|
||||
_Inout_ PTHREAD_LIST_ENTRY* Entry
|
||||
)
|
||||
{
|
||||
KIRQL irql = KeGetCurrentIrql();
|
||||
*Entry = NULL;
|
||||
KeAcquireSpinLock(&thread_list->lock, &irql);
|
||||
KeAcquireGuardedMutex(&thread_list->lock);
|
||||
|
||||
PTHREAD_LIST_ENTRY entry = (PTHREAD_LIST_ENTRY)thread_list->start.Next;
|
||||
|
||||
|
@ -226,13 +226,13 @@ FindThreadListEntryByThreadAddress(
|
|||
entry = entry->list.Next;
|
||||
}
|
||||
unlock:
|
||||
KeReleaseSpinLock(&thread_list->lock, irql);
|
||||
KeReleaseGuardedMutex(&thread_list->lock);
|
||||
}
|
||||
|
||||
VOID
|
||||
ProcessCreateNotifyRoutine(
|
||||
_In_ HANDLE ParentId,
|
||||
_In_ HANDLE ProcessID,
|
||||
_In_ HANDLE ProcessId,
|
||||
_In_ BOOLEAN Create
|
||||
)
|
||||
{
|
||||
|
@ -244,7 +244,7 @@ ProcessCreateNotifyRoutine(
|
|||
return;
|
||||
|
||||
PsLookupProcessByProcessId(ParentId, &parent);
|
||||
PsLookupProcessByProcessId(ProcessID, &process);
|
||||
PsLookupProcessByProcessId(ProcessId, &process);
|
||||
|
||||
if (!parent || !process)
|
||||
return;
|
||||
|
@ -259,7 +259,7 @@ ProcessCreateNotifyRoutine(
|
|||
entry->parent = parent;
|
||||
entry->process = process;
|
||||
|
||||
ListInit(&process_list->start, &process_list->lock);
|
||||
ListInsert(&process_list->start, entry, &process_list->lock);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
|
|
@ -118,39 +118,43 @@ ThreadCreateNotifyRoutine(
|
|||
VOID
|
||||
ProcessCreateNotifyRoutine(
|
||||
_In_ HANDLE ParentId,
|
||||
_In_ HANDLE ProcessID,
|
||||
_In_ HANDLE ProcessId,
|
||||
_In_ BOOLEAN Create
|
||||
);
|
||||
|
||||
VOID
|
||||
CleanupThreadListOnDriverUnload();
|
||||
|
||||
_Acquires_lock_(_Lock_kind_spin_lock_)
|
||||
_Releases_lock_(_Lock_kind_spin_lock_)
|
||||
_IRQL_requires_max_(APC_LEVEL)
|
||||
_Acquires_lock_(_Lock_kind_mutex_)
|
||||
_Releases_lock_(_Lock_kind_mutex_)
|
||||
VOID
|
||||
FindThreadListEntryByThreadAddress(
|
||||
_In_ PKTHREAD Thread,
|
||||
_Inout_ PTHREAD_LIST_ENTRY* Entry
|
||||
);
|
||||
|
||||
_Acquires_lock_(_Lock_kind_spin_lock_)
|
||||
_Releases_lock_(_Lock_kind_spin_lock_)
|
||||
_IRQL_requires_max_(APC_LEVEL)
|
||||
_Acquires_lock_(_Lock_kind_mutex_)
|
||||
_Releases_lock_(_Lock_kind_mutex_)
|
||||
VOID
|
||||
FindProcessListEntryByProcess(
|
||||
_In_ PKPROCESS Process,
|
||||
_Inout_ PPROCESS_LIST_ENTRY* Entry
|
||||
);
|
||||
|
||||
_Acquires_lock_(_Lock_kind_spin_lock_)
|
||||
_Releases_lock_(_Lock_kind_spin_lock_)
|
||||
_IRQL_requires_max_(APC_LEVEL)
|
||||
_Acquires_lock_(_Lock_kind_mutex_)
|
||||
_Releases_lock_(_Lock_kind_mutex_)
|
||||
VOID
|
||||
EnumerateThreadListWithCallbackRoutine(
|
||||
_In_ PVOID CallbackRoutine,
|
||||
_In_opt_ PVOID Context
|
||||
);
|
||||
|
||||
_Acquires_lock_(_Lock_kind_spin_lock_)
|
||||
_Releases_lock_(_Lock_kind_spin_lock_)
|
||||
_IRQL_requires_max_(APC_LEVEL)
|
||||
_Acquires_lock_(_Lock_kind_mutex_)
|
||||
_Releases_lock_(_Lock_kind_mutex_)
|
||||
VOID
|
||||
EnumerateProcessListWithCallbackRoutine(
|
||||
_In_ PVOID CallbackRoutine,
|
||||
|
|
|
@ -123,7 +123,6 @@ typedef struct _DRIVER_CONFIG
|
|||
PVOID apc_contexts[MAXIMUM_APC_CONTEXTS];
|
||||
volatile BOOLEAN unload_in_progress;
|
||||
KGUARDED_MUTEX lock;
|
||||
KSPIN_LOCK spin_lock;
|
||||
|
||||
}DRIVER_CONFIG, * PDRIVER_CONFIG;
|
||||
|
||||
|
@ -288,8 +287,9 @@ unlock:
|
|||
return result;
|
||||
}
|
||||
|
||||
_Acquires_lock_(_Lock_kind_spin_lock_)
|
||||
_Releases_lock_(_Lock_kind_spin_lock_)
|
||||
_IRQL_requires_max_(APC_LEVEL)
|
||||
_Acquires_lock_(_Lock_kind_mutex_)
|
||||
_Releases_lock_(_Lock_kind_mutex_)
|
||||
VOID
|
||||
IncrementApcCount(
|
||||
_In_ LONG ContextId
|
||||
|
@ -302,13 +302,14 @@ IncrementApcCount(
|
|||
if (!header)
|
||||
return;
|
||||
|
||||
KeAcquireSpinLock(&driver_config.spin_lock, &irql);
|
||||
KeAcquireGuardedMutex(&driver_config.lock);
|
||||
header->count += 1;
|
||||
KeReleaseSpinLock(&driver_config.spin_lock, irql);
|
||||
KeReleaseGuardedMutex(&driver_config.lock);
|
||||
}
|
||||
|
||||
_Acquires_lock_(_Lock_kind_spin_lock_)
|
||||
_Releases_lock_(_Lock_kind_spin_lock_)
|
||||
_IRQL_requires_max_(APC_LEVEL)
|
||||
_Acquires_lock_(_Lock_kind_mutex_)
|
||||
_Releases_lock_(_Lock_kind_mutex_)
|
||||
VOID
|
||||
FreeApcAndDecrementApcCount(
|
||||
_Inout_ PRKAPC Apc,
|
||||
|
@ -316,7 +317,6 @@ FreeApcAndDecrementApcCount(
|
|||
)
|
||||
{
|
||||
PAPC_CONTEXT_HEADER context = NULL;
|
||||
KIRQL irql = KeGetCurrentIrql();
|
||||
|
||||
ExFreePoolWithTag(Apc, POOL_TAG_APC);
|
||||
GetApcContext(&context, ContextId);
|
||||
|
@ -324,10 +324,10 @@ FreeApcAndDecrementApcCount(
|
|||
if (!context)
|
||||
goto end;
|
||||
|
||||
KeAcquireSpinLock(&driver_config.spin_lock, &irql);
|
||||
KeAcquireGuardedMutex(&driver_config.lock);
|
||||
context->count -= 1;
|
||||
end:
|
||||
KeReleaseSpinLock(&driver_config.spin_lock, irql);
|
||||
KeReleaseGuardedMutex(&driver_config.lock);
|
||||
}
|
||||
|
||||
/*
|
||||
|
@ -353,8 +353,9 @@ end:
|
|||
* the count is 0 and allocation_in_progress is 0. We can then call this function alongside
|
||||
* other query callbacks via IOCTL to constantly monitor the status of open APC contexts.
|
||||
*/
|
||||
_Acquires_lock_(_Lock_kind_spin_lock_)
|
||||
_Releases_lock_(_Lock_kind_spin_lock_)
|
||||
_IRQL_requires_max_(APC_LEVEL)
|
||||
_Acquires_lock_(_Lock_kind_mutex_)
|
||||
_Releases_lock_(_Lock_kind_mutex_)
|
||||
NTSTATUS
|
||||
QueryActiveApcContextsForCompletion()
|
||||
{
|
||||
|
@ -365,11 +366,11 @@ QueryActiveApcContextsForCompletion()
|
|||
GetApcContextByIndex(&entry, index);
|
||||
|
||||
/* acquire mutex after we get the context to prevent thread deadlock */
|
||||
KeAcquireSpinLock(&driver_config.spin_lock, &irql);
|
||||
KeAcquireGuardedMutex(&driver_config.lock);
|
||||
|
||||
if (entry == NULL)
|
||||
{
|
||||
KeReleaseSpinLock(&driver_config.spin_lock, irql);
|
||||
KeReleaseGuardedMutex(&driver_config.lock);
|
||||
continue;
|
||||
}
|
||||
|
||||
|
@ -378,7 +379,7 @@ QueryActiveApcContextsForCompletion()
|
|||
|
||||
if (entry->count > 0 || entry->allocation_in_progress == TRUE)
|
||||
{
|
||||
KeReleaseSpinLock(&driver_config.spin_lock, irql);
|
||||
KeReleaseGuardedMutex(&driver_config.lock);
|
||||
continue;
|
||||
}
|
||||
|
||||
|
@ -390,22 +391,22 @@ QueryActiveApcContextsForCompletion()
|
|||
break;
|
||||
}
|
||||
|
||||
KeReleaseSpinLock(&driver_config.spin_lock, irql);
|
||||
KeReleaseGuardedMutex(&driver_config.lock);
|
||||
|
||||
}
|
||||
return STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
_Acquires_lock_(_Lock_kind_spin_lock_)
|
||||
_Releases_lock_(_Lock_kind_spin_lock_)
|
||||
_IRQL_requires_max_(APC_LEVEL)
|
||||
_Acquires_lock_(_Lock_kind_mutex_)
|
||||
_Releases_lock_(_Lock_kind_mutex_)
|
||||
NTSTATUS
|
||||
InsertApcContext(
|
||||
_In_ PVOID Context
|
||||
)
|
||||
{
|
||||
NTSTATUS status = STATUS_SUCCESS;
|
||||
KIRQL irql = KeGetCurrentIrql();
|
||||
KeAcquireSpinLock(&driver_config.spin_lock, &irql);
|
||||
KeAcquireGuardedMutex(&driver_config.lock);
|
||||
|
||||
PAPC_CONTEXT_HEADER header = Context;
|
||||
|
||||
|
@ -430,20 +431,20 @@ InsertApcContext(
|
|||
}
|
||||
}
|
||||
end:
|
||||
KeReleaseSpinLock(&driver_config.spin_lock, irql);
|
||||
KeReleaseGuardedMutex(&driver_config.lock);
|
||||
return status;
|
||||
}
|
||||
|
||||
_Acquires_lock_(_Lock_kind_spin_lock_)
|
||||
_Releases_lock_(_Lock_kind_spin_lock_)
|
||||
_IRQL_requires_max_(APC_LEVEL)
|
||||
_Acquires_lock_(_Lock_kind_mutex_)
|
||||
_Releases_lock_(_Lock_kind_mutex_)
|
||||
VOID
|
||||
GetApcContext(
|
||||
_Inout_ PVOID* Context,
|
||||
_In_ LONG ContextIdentifier
|
||||
)
|
||||
{
|
||||
KIRQL irql = KeGetCurrentIrql();
|
||||
KeAcquireSpinLock(&driver_config.spin_lock, &irql);
|
||||
KeAcquireGuardedMutex(&driver_config.lock);
|
||||
|
||||
for (INT index = 0; index < MAXIMUM_APC_CONTEXTS; index++)
|
||||
{
|
||||
|
@ -460,11 +461,12 @@ GetApcContext(
|
|||
}
|
||||
|
||||
unlock:
|
||||
KeReleaseSpinLock(&driver_config.spin_lock, irql);
|
||||
KeReleaseGuardedMutex(&driver_config.lock);
|
||||
}
|
||||
|
||||
_Acquires_lock_(_Lock_kind_spin_lock_)
|
||||
_Releases_lock_(_Lock_kind_spin_lock_)
|
||||
_IRQL_requires_max_(APC_LEVEL)
|
||||
_Acquires_lock_(_Lock_kind_mutex_)
|
||||
_Releases_lock_(_Lock_kind_mutex_)
|
||||
VOID
|
||||
GetApcContextByIndex(
|
||||
_Inout_ PVOID* Context,
|
||||
|
@ -477,9 +479,9 @@ GetApcContextByIndex(
|
|||
return;
|
||||
|
||||
*Context = NULL;
|
||||
KeAcquireSpinLock(&driver_config.spin_lock, &irql);
|
||||
KeAcquireGuardedMutex(&driver_config.lock);
|
||||
*Context = driver_config.apc_contexts[Index];
|
||||
KeReleaseSpinLock(&driver_config.spin_lock, irql);
|
||||
KeReleaseGuardedMutex(&driver_config.lock);
|
||||
}
|
||||
|
||||
/*
|
||||
|
@ -845,16 +847,16 @@ DrvUnloadUnregisterObCallbacks()
|
|||
* It's important to remember that the driver can unload when pending APC's have not been freed due to the
|
||||
* limitations windows places on APCs, however I am in the process of finding a solution for this.
|
||||
*/
|
||||
_Acquires_lock_(driver_config.spin_lock)
|
||||
_Releases_lock_(driver_config.spin_lock)
|
||||
_IRQL_requires_max_(APC_LEVEL)
|
||||
_Acquires_lock_(_Lock_kind_mutex_)
|
||||
_Releases_lock_(_Lock_kind_mutex_)
|
||||
STATIC
|
||||
BOOLEAN
|
||||
DrvUnloadFreeAllApcContextStructures()
|
||||
{
|
||||
BOOLEAN flag = TRUE;
|
||||
KIRQL irql = KeGetCurrentIrql();
|
||||
|
||||
KeAcquireSpinLock(&driver_config.spin_lock, &irql);
|
||||
KeAcquireGuardedMutex(&driver_config.lock);
|
||||
|
||||
for (INT index = 0; index < MAXIMUM_APC_CONTEXTS; index++)
|
||||
{
|
||||
|
@ -875,7 +877,7 @@ DrvUnloadFreeAllApcContextStructures()
|
|||
}
|
||||
|
||||
unlock:
|
||||
KeReleaseSpinLock(&driver_config.spin_lock, irql);
|
||||
KeReleaseGuardedMutex(&driver_config.lock);
|
||||
return flag;
|
||||
}
|
||||
|
||||
|
@ -990,9 +992,20 @@ DrvLoadEnableNotifyRoutines()
|
|||
|
||||
status = PsSetCreateThreadNotifyRoutine(ThreadCreateNotifyRoutine);
|
||||
|
||||
if (!NT_SUCCESS(status))
|
||||
{
|
||||
DEBUG_ERROR("PsSetCreateThreadNotifyRoutine failed with status %x", status);
|
||||
DrvUnloadFreeThreadList();
|
||||
DrvUnloadFreeProcessList();
|
||||
return status;
|
||||
}
|
||||
|
||||
status = PsSetCreateProcessNotifyRoutine(ProcessCreateNotifyRoutine, FALSE);
|
||||
|
||||
if (!NT_SUCCESS(status))
|
||||
{
|
||||
DEBUG_ERROR("PsSetCreateProcessNotifyRoutine failed with status %x", status);
|
||||
PsRemoveCreateThreadNotifyRoutine(ThreadCreateNotifyRoutine);
|
||||
DrvUnloadFreeThreadList();
|
||||
DrvUnloadFreeProcessList();
|
||||
return status;
|
||||
|
@ -1048,7 +1061,6 @@ DrvLoadInitialiseDriverConfig(
|
|||
RTL_QUERY_REGISTRY_TABLE query_table[3] = { 0 };
|
||||
|
||||
KeInitializeGuardedMutex(&driver_config.lock);
|
||||
KeInitializeSpinLock(&driver_config.spin_lock);
|
||||
driver_config.unload_in_progress = FALSE;
|
||||
|
||||
RtlInitUnicodeString(&driver_config.device_name, L"\\Device\\DonnaAC");
|
||||
|
|
|
@ -79,46 +79,52 @@ VOID GetDriverConfigSystemInformation(
|
|||
_Out_ PSYSTEM_INFORMATION* SystemInformation
|
||||
);
|
||||
|
||||
_Acquires_lock_(_Lock_kind_spin_lock_)
|
||||
_Releases_lock_(_Lock_kind_spin_lock_)
|
||||
_IRQL_requires_max_(APC_LEVEL)
|
||||
_Acquires_lock_(_Lock_kind_mutex_)
|
||||
_Releases_lock_(_Lock_kind_mutex_)
|
||||
VOID
|
||||
GetApcContext(
|
||||
_Inout_ PVOID* Context,
|
||||
_In_ LONG ContextIdentifier
|
||||
);
|
||||
|
||||
_Acquires_lock_(_Lock_kind_spin_lock_)
|
||||
_Releases_lock_(_Lock_kind_spin_lock_)
|
||||
_IRQL_requires_max_(APC_LEVEL)
|
||||
_Acquires_lock_(_Lock_kind_mutex_)
|
||||
_Releases_lock_(_Lock_kind_mutex_)
|
||||
NTSTATUS
|
||||
InsertApcContext(
|
||||
_In_ PVOID Context
|
||||
);
|
||||
|
||||
_Acquires_lock_(_Lock_kind_spin_lock_)
|
||||
_Releases_lock_(_Lock_kind_spin_lock_)
|
||||
_IRQL_requires_max_(APC_LEVEL)
|
||||
_Acquires_lock_(_Lock_kind_mutex_)
|
||||
_Releases_lock_(_Lock_kind_mutex_)
|
||||
VOID
|
||||
GetApcContextByIndex(
|
||||
_Inout_ PVOID* Context,
|
||||
_In_ INT Index
|
||||
);
|
||||
|
||||
_Acquires_lock_(_Lock_kind_spin_lock_)
|
||||
_Releases_lock_(_Lock_kind_spin_lock_)
|
||||
_IRQL_requires_max_(APC_LEVEL)
|
||||
_Acquires_lock_(_Lock_kind_mutex_)
|
||||
_Releases_lock_(_Lock_kind_mutex_)
|
||||
VOID
|
||||
IncrementApcCount(
|
||||
_In_ LONG ContextId
|
||||
);
|
||||
|
||||
_Acquires_lock_(_Lock_kind_spin_lock_)
|
||||
_Releases_lock_(_Lock_kind_spin_lock_)
|
||||
_IRQL_requires_max_(APC_LEVEL)
|
||||
_Acquires_lock_(_Lock_kind_mutex_)
|
||||
_Releases_lock_(_Lock_kind_mutex_)
|
||||
VOID
|
||||
FreeApcAndDecrementApcCount(
|
||||
_Inout_ PRKAPC Apc,
|
||||
_In_ LONG ContextId
|
||||
);
|
||||
|
||||
_Acquires_lock_(_Lock_kind_spin_lock_)
|
||||
_Releases_lock_(_Lock_kind_spin_lock_)
|
||||
_IRQL_requires_max_(APC_LEVEL)
|
||||
_Acquires_lock_(_Lock_kind_mutex_)
|
||||
_Releases_lock_(_Lock_kind_mutex_)
|
||||
NTSTATUS
|
||||
QueryActiveApcContextsForCompletion();
|
||||
|
||||
|
|
|
@ -35,7 +35,7 @@ InitialiseGlobalReportQueue(
|
|||
report_queue_config.head.end = NULL;
|
||||
report_queue_config.head.entries = 0;
|
||||
|
||||
KeInitializeSpinLock(&report_queue_config.head.lock);
|
||||
KeInitializeGuardedMutex(&report_queue_config.head.lock);
|
||||
KeInitializeGuardedMutex(&report_queue_config.lock);
|
||||
|
||||
*Status = TRUE;
|
||||
|
@ -57,16 +57,15 @@ InitialiseGlobalReportQueue(
|
|||
// return head;
|
||||
//}
|
||||
|
||||
_Acquires_lock_(_Lock_kind_spin_lock_)
|
||||
_Releases_lock_(_Lock_kind_spin_lock_)
|
||||
_Acquires_lock_(_Lock_kind_mutex_)
|
||||
_Releases_lock_(_Lock_kind_mutex_)
|
||||
VOID
|
||||
QueuePush(
|
||||
_Inout_ PQUEUE_HEAD Head,
|
||||
_In_ PVOID Data
|
||||
)
|
||||
{
|
||||
KIRQL irql = KeGetCurrentIrql();
|
||||
KeAcquireSpinLock(&Head->lock, &irql);
|
||||
KeAcquireGuardedMutex(&Head->lock);
|
||||
|
||||
PQUEUE_NODE temp = ExAllocatePool2(POOL_FLAG_NON_PAGED, sizeof(QUEUE_NODE), QUEUE_POOL_TAG);
|
||||
|
||||
|
@ -86,18 +85,17 @@ QueuePush(
|
|||
Head->start = temp;
|
||||
|
||||
end:
|
||||
KeReleaseSpinLock(&Head->lock, irql);
|
||||
KeReleaseGuardedMutex(&Head->lock);
|
||||
}
|
||||
|
||||
_Acquires_lock_(_Lock_kind_spin_lock_)
|
||||
_Releases_lock_(_Lock_kind_spin_lock_)
|
||||
_Acquires_lock_(_Lock_kind_mutex_)
|
||||
_Releases_lock_(_Lock_kind_mutex_)
|
||||
PVOID
|
||||
QueuePop(
|
||||
_Inout_ PQUEUE_HEAD Head
|
||||
)
|
||||
{
|
||||
KIRQL irql = KeGetCurrentIrql();
|
||||
KeAcquireSpinLock(&Head->lock, &irql);
|
||||
KeAcquireGuardedMutex(&Head->lock);
|
||||
|
||||
PVOID data = NULL;
|
||||
PQUEUE_NODE temp = Head->start;
|
||||
|
@ -116,7 +114,7 @@ QueuePop(
|
|||
ExFreePoolWithTag(temp, QUEUE_POOL_TAG);
|
||||
|
||||
end:
|
||||
KeReleaseSpinLock(&Head->lock, irql);
|
||||
KeReleaseGuardedMutex(&Head->lock);
|
||||
return data;
|
||||
}
|
||||
|
||||
|
@ -299,44 +297,42 @@ end:
|
|||
VOID
|
||||
ListInit(
|
||||
_Inout_ PSINGLE_LIST_ENTRY Head,
|
||||
_Inout_ PKSPIN_LOCK Lock
|
||||
_Inout_ PKGUARDED_MUTEX Lock
|
||||
)
|
||||
{
|
||||
KeInitializeSpinLock(Lock);
|
||||
KeInitializeGuardedMutex(Lock);
|
||||
Head->Next = NULL;
|
||||
}
|
||||
|
||||
_Acquires_lock_(_Lock_kind_spin_lock_)
|
||||
_Releases_lock_(_Lock_kind_spin_lock_)
|
||||
_Acquires_lock_(_Lock_kind_mutex_)
|
||||
_Releases_lock_(_Lock_kind_mutex_)
|
||||
VOID
|
||||
ListInsert(
|
||||
_Inout_ PSINGLE_LIST_ENTRY Head,
|
||||
_Inout_ PSINGLE_LIST_ENTRY NewEntry,
|
||||
_In_ PKSPIN_LOCK Lock
|
||||
_In_ PKGUARDED_MUTEX Lock
|
||||
)
|
||||
{
|
||||
KIRQL irql = KeGetCurrentIrql();
|
||||
KeAcquireSpinLock(Lock, &irql);
|
||||
KeAcquireGuardedMutex(Lock);
|
||||
|
||||
PSINGLE_LIST_ENTRY old_entry = Head->Next;
|
||||
|
||||
Head->Next = NewEntry;
|
||||
NewEntry->Next = old_entry;
|
||||
|
||||
KeReleaseSpinLock(Lock, irql);
|
||||
KeReleaseGuardedMutex(Lock);
|
||||
}
|
||||
|
||||
_Acquires_lock_(_Lock_kind_spin_lock_)
|
||||
_Releases_lock_(_Lock_kind_spin_lock_)
|
||||
_Acquires_lock_(_Lock_kind_mutex_)
|
||||
_Releases_lock_(_Lock_kind_mutex_)
|
||||
BOOLEAN
|
||||
ListFreeFirstEntry(
|
||||
_Inout_ PSINGLE_LIST_ENTRY Head,
|
||||
_In_ PKSPIN_LOCK Lock
|
||||
_In_ PKGUARDED_MUTEX Lock
|
||||
)
|
||||
{
|
||||
BOOLEAN result = FALSE;
|
||||
KIRQL irql = KeGetCurrentIrql();
|
||||
KeAcquireSpinLock(Lock, &irql);
|
||||
KeAcquireGuardedMutex(Lock);
|
||||
|
||||
if (Head->Next)
|
||||
{
|
||||
|
@ -346,21 +342,20 @@ ListFreeFirstEntry(
|
|||
result = TRUE;
|
||||
}
|
||||
|
||||
KeReleaseSpinLock(Lock, irql);
|
||||
KeReleaseGuardedMutex(Lock);
|
||||
return result;
|
||||
}
|
||||
|
||||
_Acquires_lock_(_Lock_kind_spin_lock_)
|
||||
_Releases_lock_(_Lock_kind_spin_lock_)
|
||||
_Acquires_lock_(_Lock_kind_mutex_)
|
||||
_Releases_lock_(_Lock_kind_mutex_)
|
||||
VOID
|
||||
ListRemoveEntry(
|
||||
_Inout_ PSINGLE_LIST_ENTRY Head,
|
||||
_Inout_ PSINGLE_LIST_ENTRY Entry,
|
||||
_In_ PKSPIN_LOCK Lock
|
||||
_In_ PKGUARDED_MUTEX Lock
|
||||
)
|
||||
{
|
||||
KIRQL irql = KeGetCurrentIrql();
|
||||
KeAcquireSpinLock(Lock, &irql);
|
||||
KeAcquireGuardedMutex(Lock);
|
||||
|
||||
PSINGLE_LIST_ENTRY entry = Head->Next;
|
||||
|
||||
|
@ -387,5 +382,5 @@ ListRemoveEntry(
|
|||
}
|
||||
|
||||
unlock:
|
||||
KeReleaseSpinLock(Lock, irql);
|
||||
KeReleaseGuardedMutex(Lock);
|
||||
}
|
||||
|
|
|
@ -17,7 +17,7 @@ typedef struct QUEUE_HEAD
|
|||
{
|
||||
struct _QUEUE_NODE* start;
|
||||
struct _QUEUE_NODE* end;
|
||||
KSPIN_LOCK lock;
|
||||
KGUARDED_MUTEX lock;
|
||||
INT entries;
|
||||
|
||||
}QUEUE_HEAD, * PQUEUE_HEAD;
|
||||
|
@ -36,16 +36,16 @@ typedef struct _REPORT_HEADER
|
|||
|
||||
#define LIST_POOL_TAG 'list'
|
||||
|
||||
_Acquires_lock_(_Lock_kind_spin_lock_)
|
||||
_Releases_lock_(_Lock_kind_spin_lock_)
|
||||
_Acquires_lock_(_Lock_kind_mutex_)
|
||||
_Releases_lock_(_Lock_kind_mutex_)
|
||||
VOID
|
||||
QueuePush(
|
||||
_Inout_ PQUEUE_HEAD Head,
|
||||
_In_ PVOID Data
|
||||
);
|
||||
|
||||
_Acquires_lock_(_Lock_kind_spin_lock_)
|
||||
_Releases_lock_(_Lock_kind_spin_lock_)
|
||||
_Acquires_lock_(_Lock_kind_mutex_)
|
||||
_Releases_lock_(_Lock_kind_mutex_)
|
||||
PVOID
|
||||
QueuePop(
|
||||
_Inout_ PQUEUE_HEAD Head
|
||||
|
@ -81,33 +81,33 @@ FreeGlobalReportQueueObjects();
|
|||
VOID
|
||||
ListInit(
|
||||
_Inout_ PSINGLE_LIST_ENTRY Head,
|
||||
_Inout_ PKSPIN_LOCK Lock
|
||||
_Inout_ PKGUARDED_MUTEX Lock
|
||||
);
|
||||
|
||||
_Acquires_lock_(_Lock_kind_spin_lock_)
|
||||
_Releases_lock_(_Lock_kind_spin_lock_)
|
||||
_Acquires_lock_(_Lock_kind_mutex_)
|
||||
_Releases_lock_(_Lock_kind_mutex_)
|
||||
VOID
|
||||
ListInsert(
|
||||
_Inout_ PSINGLE_LIST_ENTRY Head,
|
||||
_Inout_ PSINGLE_LIST_ENTRY NewEntry,
|
||||
_In_ PKSPIN_LOCK Lock
|
||||
_In_ PKGUARDED_MUTEX Lock
|
||||
);
|
||||
|
||||
_Acquires_lock_(_Lock_kind_spin_lock_)
|
||||
_Releases_lock_(_Lock_kind_spin_lock_)
|
||||
_Acquires_lock_(_Lock_kind_mutex_)
|
||||
_Releases_lock_(_Lock_kind_mutex_)
|
||||
BOOLEAN
|
||||
ListFreeFirstEntry(
|
||||
_Inout_ PSINGLE_LIST_ENTRY Head,
|
||||
_In_ PKSPIN_LOCK Lock
|
||||
_In_ PKGUARDED_MUTEX Lock
|
||||
);
|
||||
|
||||
_Acquires_lock_(_Lock_kind_spin_lock_)
|
||||
_Releases_lock_(_Lock_kind_spin_lock_)
|
||||
_Acquires_lock_(_Lock_kind_mutex_)
|
||||
_Releases_lock_(_Lock_kind_mutex_)
|
||||
VOID
|
||||
ListRemoveEntry(
|
||||
_Inout_ PSINGLE_LIST_ENTRY Head,
|
||||
_Inout_ PSINGLE_LIST_ENTRY Entry,
|
||||
_In_ PKSPIN_LOCK Lock
|
||||
_In_ PKGUARDED_MUTEX Lock
|
||||
);
|
||||
|
||||
#endif
|
Loading…
Reference in a new issue