Skip to content

Commit

Permalink
winapi: Implement Suspend/Resume Thread
Browse files Browse the repository at this point in the history
  • Loading branch information
Ryzee119 committed Dec 27, 2024
1 parent 0c806df commit 6278edc
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 0 deletions.
2 changes: 2 additions & 0 deletions lib/winapi/processthreadsapi.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ DWORD GetThreadId (HANDLE Thread);
BOOL SwitchToThread (VOID);

BOOL SetThreadPriority (HANDLE hThread, int nPriority);
DWORD SuspendThread (HANDLE hThread);
DWORD ResumeThread (HANDLE hThread);

DWORD TlsAlloc (void);
BOOL TlsFree (DWORD dwTlsIndex);
Expand Down
28 changes: 28 additions & 0 deletions lib/winapi/thread.c
Original file line number Diff line number Diff line change
Expand Up @@ -172,3 +172,31 @@ BOOL SetThreadPriority (HANDLE hThread, int nPriority)
ObfDereferenceObject(thread);
return TRUE;
}

DWORD SuspendThread (HANDLE hThread)
{
ULONG PreviousSuspendCount;
NTSTATUS status;

status = NtSuspendThread(hThread, &PreviousSuspendCount);
if (!NT_SUCCESS(status)) {
SetLastError(RtlNtStatusToDosError(status));
return -1;
}

return PreviousSuspendCount;
}

DWORD ResumeThread (HANDLE hThread)
{
ULONG PreviousResumeCount;
NTSTATUS status;

status = NtResumeThread(hThread, &PreviousResumeCount);
if (!NT_SUCCESS(status)) {
SetLastError(RtlNtStatusToDosError(status));
return -1;
}

return PreviousResumeCount;
}

0 comments on commit 6278edc

Please sign in to comment.