Files
hfiref0x 2ecd87a0b5 2.1.0
Internal rearrangement: apply multiple bugfixes and cleanups across the UI and kernel helper code:
- aboutDlg: guard message loop on valid hwndDlg and minor date bump.
- extrasDrivers: fix double-free ordering when freeing dumpInfo->Buffer and dumpInfo.
- findDlg: reduce buffer sizes, add FINDDLG_RESIZE struct, centralize resize state, use ARRAYSIZE for safety, streamline message handling and search workflow, improve thread cancellation/waiting (use INFINITE) and add cleanup guard in worker thread.
- kldbg: handle allocation failure by cleaning up list elements, simplify unused variable usage, adjust memory/free ordering and minor scanning optimization.
- list: move suppression of tree redraw to surrounding caller so batch operations suspend/resume redraw correctly.
- main: fix comment typo and bump headers.
- plugmngr: skip empty plugin names and build combined message with RtlStringCchPrintfSecure to avoid manual strcat usage.
- props/propDlg & propProcess: update versions/dates, fix dialog property cleanup (use RemoveProp and avoid duplicate removals), update page handling.
- sup/sync: check NtCreateEvent return (ntStatus), avoid leaking on failure and return FALSE when event creation fails.
- sup/w32k: reorder variable declaration for clarity.
- ui.h and various files: bump versions/dates/copyright years and PROGRAM_BUILD_NUMBER.
2026-03-01 10:37:41 +07:00

200 lines
3.6 KiB
C

/*******************************************************************************
*
* (C) COPYRIGHT AUTHORS, 2022 - 2026
*
* TITLE: SYNC.C
*
* VERSION: 2.10
*
* DATE: 19 Feb 2026
*
* Synchronization primitives.
*
*
* THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF
* ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED
* TO THE IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A
* PARTICULAR PURPOSE.
*
*******************************************************************************/
#include "global.h"
/*
*
* Fast events, taken from ph2
*
*/
/*
* supInitFastEvent
*
* Purpose:
*
* Initialize fast event.
*
*/
VOID supInitFastEvent(
_In_ PFAST_EVENT Event
)
{
Event->Value = FAST_EVENT_REFCOUNT_INC;
Event->EventHandle = NULL;
}
/*
* supReferenceFastEvent
*
* Purpose:
*
* Make a reference for fast event.
*
*/
VOID supReferenceFastEvent(
_In_ PFAST_EVENT Event
)
{
_InterlockedExchangeAddPointer((PLONG_PTR)&Event->Value, FAST_EVENT_REFCOUNT_INC);
}
/*
* supDereferenceFastEvent
*
* Purpose:
*
* Remove reference from fast event.
*
*/
VOID supDereferenceFastEvent(
_In_ PFAST_EVENT Event,
_In_opt_ HANDLE EventHandle
)
{
ULONG_PTR value;
value = _InterlockedExchangeAddPointer((PLONG_PTR)&Event->Value, -FAST_EVENT_REFCOUNT_INC);
if (((value >> FAST_EVENT_REFCOUNT_SHIFT) & FAST_EVENT_REFCOUNT_MASK) - 1 == 0)
{
if (EventHandle)
{
NtClose(EventHandle);
Event->EventHandle = NULL;
}
}
}
/*
* supSetFastEvent
*
* Purpose:
*
* Set event to signaled state.
*
*/
VOID supSetFastEvent(
_In_ PFAST_EVENT Event
)
{
HANDLE eventHandle;
if (!_InterlockedBitTestAndSetPointer((PLONG_PTR)&Event->Value, FAST_EVENT_SET_SHIFT)) {
eventHandle = Event->EventHandle;
if (eventHandle)
{
NtSetEvent(eventHandle, NULL);
}
}
}
/*
* supTestFastEvent
*
* Purpose:
*
* Returns fast event state.
*
*/
BOOLEAN supTestFastEvent(
_In_ PFAST_EVENT Event
)
{
return (BOOLEAN)Event->Set; //-V724
}
/*
* supResetFastEvent
*
* Purpose:
*
* Perform fast event manual reset.
*
*/
VOID supResetFastEvent(
_In_ PFAST_EVENT Event
)
{
if (Event == NULL)
return;
if (supTestFastEvent(Event))
Event->Value = FAST_EVENT_REFCOUNT_INC;
}
/*
* supWaitForFastEvent
*
* Purpose:
*
* Do the wait for event, if event object not allocated - allocate it.
*
*/
BOOLEAN supWaitForFastEvent(
_In_ PFAST_EVENT Event,
_In_opt_ PLARGE_INTEGER Timeout
)
{
BOOLEAN result;
ULONG_PTR value;
HANDLE eventHandle;
NTSTATUS ntStatus;
value = Event->Value;
if (value & FAST_EVENT_SET)
return TRUE;
if (Timeout && Timeout->QuadPart == 0)
return FALSE;
supReferenceFastEvent(Event);
eventHandle = Event->EventHandle;
if (eventHandle == NULL) {
ntStatus = NtCreateEvent(&eventHandle, EVENT_ALL_ACCESS, NULL, NotificationEvent, FALSE);
if (!NT_SUCCESS(ntStatus) || (eventHandle == NULL)) {
supDereferenceFastEvent(Event, NULL);
return FALSE;
}
if (NULL != _InterlockedCompareExchangePointer(
&Event->EventHandle,
eventHandle,
NULL))
{
NtClose(eventHandle);
eventHandle = Event->EventHandle;
}
}
if (!(Event->Value & FAST_EVENT_SET)) {
result = (NtWaitForSingleObject(eventHandle, FALSE, Timeout) == STATUS_WAIT_0);
}
else {
result = TRUE;
}
supDereferenceFastEvent(Event, eventHandle);
return result;
}