Skip to content

Commit 130d47b

Browse files
committed
Add PhDelayExecutionEx, Move PhDelayExecution
1 parent b149de7 commit 130d47b

File tree

4 files changed

+60
-29
lines changed

4 files changed

+60
-29
lines changed

phlib/basesup.c

Lines changed: 0 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -430,28 +430,6 @@ VOID PhLocalTimeToSystemTime(
430430
SystemTime->QuadPart = LocalTime->QuadPart + timeZoneBias.QuadPart;
431431
}
432432

433-
NTSTATUS PhDelayExecution(
434-
_In_ LONGLONG Interval
435-
)
436-
{
437-
if (Interval == INFINITE) // HACK (dmex)
438-
{
439-
LARGE_INTEGER interval;
440-
441-
interval.QuadPart = LLONG_MIN;
442-
443-
return NtDelayExecution(FALSE, &interval);
444-
}
445-
else
446-
{
447-
LARGE_INTEGER interval;
448-
449-
interval.QuadPart = -(LONGLONG)UInt32x32To64(Interval, PH_TIMEOUT_MS);
450-
451-
return NtDelayExecution(FALSE, &interval);
452-
}
453-
}
454-
455433
/**
456434
* Allocates a block of memory.
457435
*

phlib/include/phbasesup.h

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -89,13 +89,6 @@ PhLocalTimeToSystemTime(
8989
_Out_ PLARGE_INTEGER SystemTime
9090
);
9191

92-
PHLIBAPI
93-
NTSTATUS
94-
NTAPI
95-
PhDelayExecution(
96-
_In_ LONGLONG Interval
97-
);
98-
9992
// Heap
10093

10194
_May_raise_

phlib/include/phutil.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1509,6 +1509,13 @@ PhFreeLibraryAsImageResource(
15091509
_In_ PVOID BaseAddress
15101510
);
15111511

1512+
PHLIBAPI
1513+
NTSTATUS
1514+
NTAPI
1515+
PhDelayExecution(
1516+
_In_ LONGLONG Interval
1517+
);
1518+
15121519
#ifdef __cplusplus
15131520
}
15141521
#endif

phlib/util.c

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7934,3 +7934,56 @@ NTSTATUS PhFreeLibraryAsImageResource(
79347934
{
79357935
return NtUnmapViewOfSection(NtCurrentProcess(), BaseAddress);
79367936
}
7937+
7938+
NTSTATUS PhDelayExecutionEx(
7939+
_In_ BOOLEAN Alertable,
7940+
_In_opt_ PLARGE_INTEGER DelayInterval
7941+
)
7942+
{
7943+
static PH_INITONCE initOnce = PH_INITONCE_INIT;
7944+
static NTSTATUS (NTAPI* RtlDelayExecution_I)(
7945+
_In_ BOOLEAN Alertable,
7946+
_In_opt_ PLARGE_INTEGER DelayInterval
7947+
) = NULL;
7948+
7949+
if (PhBeginInitOnce(&initOnce))
7950+
{
7951+
PVOID ntdll;
7952+
7953+
if (ntdll = PhGetLoaderEntryDllBase(L"ntdll.dll"))
7954+
{
7955+
RtlDelayExecution_I = PhGetDllBaseProcedureAddress(ntdll, "RtlDelayExecution", 0);
7956+
}
7957+
7958+
PhEndInitOnce(&initOnce);
7959+
}
7960+
7961+
if (RtlDelayExecution_I)
7962+
{
7963+
return RtlDelayExecution_I(Alertable, DelayInterval);
7964+
}
7965+
7966+
return NtDelayExecution(Alertable, DelayInterval);
7967+
}
7968+
7969+
NTSTATUS PhDelayExecution(
7970+
_In_ LONGLONG Interval
7971+
)
7972+
{
7973+
if (Interval == INFINITE) // HACK (dmex)
7974+
{
7975+
LARGE_INTEGER interval;
7976+
7977+
interval.QuadPart = LLONG_MIN;
7978+
7979+
return PhDelayExecutionEx(FALSE, &interval);
7980+
}
7981+
else
7982+
{
7983+
LARGE_INTEGER interval;
7984+
7985+
interval.QuadPart = -(LONGLONG)UInt32x32To64(Interval, PH_TIMEOUT_MS);
7986+
7987+
return PhDelayExecutionEx(FALSE, &interval);
7988+
}
7989+
}

0 commit comments

Comments
 (0)