mirror of
https://github.com/HyperDbg/HyperDbg.git
synced 2026-07-09 17:19:26 +00:00
New platform lib calls
This commit is contained in:
parent
c2c0030f1b
commit
5a02c43cc1
2 changed files with 138 additions and 0 deletions
|
|
@ -16,6 +16,8 @@
|
|||
# include <unistd.h>
|
||||
# include <sched.h>
|
||||
# include <sys/syscall.h>
|
||||
# include <errno.h>
|
||||
# include <stdint.h>
|
||||
#endif // defined(__linux__)
|
||||
|
||||
/**
|
||||
|
|
@ -240,3 +242,115 @@ PlatformGetCurrentProcessName(VOID)
|
|||
# error "Unsupported platform"
|
||||
#endif
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Platform independent wrapper for CreateEvent
|
||||
*
|
||||
* @param ManualReset TRUE for a manual-reset event, FALSE for auto-reset
|
||||
* @param InitialState TRUE if the event starts signaled
|
||||
* @return HANDLE to the event, or NULL on failure
|
||||
*/
|
||||
HANDLE
|
||||
PlatformCreateEvent(BOOLEAN ManualReset, BOOLEAN InitialState)
|
||||
{
|
||||
#if defined(_WIN32)
|
||||
return CreateEvent(NULL, ManualReset, InitialState, NULL);
|
||||
#elif defined(__linux__)
|
||||
//
|
||||
// TODO: back this with a pthread mutex+cond (or eventfd) when the Linux
|
||||
// kernel-debugger transport is implemented. For now return a dummy
|
||||
// non-NULL handle so existing NULL-checks treat creation as success.
|
||||
//
|
||||
(void)ManualReset;
|
||||
(void)InitialState;
|
||||
return (HANDLE)(uintptr_t)1;
|
||||
#else
|
||||
# error "Unsupported platform"
|
||||
#endif
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Platform independent wrapper for SetEvent
|
||||
*/
|
||||
BOOLEAN
|
||||
PlatformSetEvent(HANDLE EventHandle)
|
||||
{
|
||||
#if defined(_WIN32)
|
||||
return (BOOLEAN)SetEvent(EventHandle);
|
||||
#elif defined(__linux__)
|
||||
(void)EventHandle; // TODO: signal the underlying cond/eventfd
|
||||
return TRUE;
|
||||
#else
|
||||
# error "Unsupported platform"
|
||||
#endif
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Platform independent wrapper for ResetEvent
|
||||
*/
|
||||
BOOLEAN
|
||||
PlatformResetEvent(HANDLE EventHandle)
|
||||
{
|
||||
#if defined(_WIN32)
|
||||
return (BOOLEAN)ResetEvent(EventHandle);
|
||||
#elif defined(__linux__)
|
||||
(void)EventHandle; // TODO: clear the underlying cond/eventfd
|
||||
return TRUE;
|
||||
#else
|
||||
# error "Unsupported platform"
|
||||
#endif
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Platform independent wrapper for WaitForSingleObject
|
||||
*
|
||||
* @return 0 (WAIT_OBJECT_0) on success
|
||||
*/
|
||||
DWORD
|
||||
PlatformWaitForSingleObject(HANDLE Handle, DWORD TimeoutMilliseconds)
|
||||
{
|
||||
#if defined(_WIN32)
|
||||
return WaitForSingleObject(Handle, TimeoutMilliseconds);
|
||||
#elif defined(__linux__)
|
||||
//
|
||||
// TODO: wait on the underlying cond/eventfd. For now return immediately as
|
||||
// success — no real transport exists yet to wait on.
|
||||
//
|
||||
(void)Handle;
|
||||
(void)TimeoutMilliseconds;
|
||||
return 0;
|
||||
#else
|
||||
# error "Unsupported platform"
|
||||
#endif
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Platform independent wrapper for CloseHandle
|
||||
*/
|
||||
BOOLEAN
|
||||
PlatformCloseHandle(HANDLE Handle)
|
||||
{
|
||||
#if defined(_WIN32)
|
||||
return (BOOLEAN)CloseHandle(Handle);
|
||||
#elif defined(__linux__)
|
||||
(void)Handle; // TODO: free the underlying cond/eventfd or close the fd
|
||||
return TRUE;
|
||||
#else
|
||||
# error "Unsupported platform"
|
||||
#endif
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Platform independent wrapper for GetLastError
|
||||
*/
|
||||
DWORD
|
||||
PlatformGetLastError(VOID)
|
||||
{
|
||||
#if defined(_WIN32)
|
||||
return GetLastError();
|
||||
#elif defined(__linux__)
|
||||
return (DWORD)errno;
|
||||
#else
|
||||
# error "Unsupported platform"
|
||||
#endif
|
||||
}
|
||||
|
|
|
|||
|
|
@ -51,6 +51,30 @@ PlatformQueryPerformanceFrequency(LARGE_INTEGER * Frequency);
|
|||
BOOLEAN
|
||||
PlatformQueryPerformanceCounter(LARGE_INTEGER * Count);
|
||||
|
||||
//
|
||||
// EVENT / SYNCHRONIZATION OBJECTS
|
||||
//
|
||||
HANDLE
|
||||
PlatformCreateEvent(BOOLEAN ManualReset, BOOLEAN InitialState);
|
||||
|
||||
BOOLEAN
|
||||
PlatformSetEvent(HANDLE EventHandle);
|
||||
|
||||
BOOLEAN
|
||||
PlatformResetEvent(HANDLE EventHandle);
|
||||
|
||||
DWORD
|
||||
PlatformWaitForSingleObject(HANDLE Handle, DWORD TimeoutMilliseconds);
|
||||
|
||||
BOOLEAN
|
||||
PlatformCloseHandle(HANDLE Handle);
|
||||
|
||||
//
|
||||
// LAST OS ERROR
|
||||
//
|
||||
DWORD
|
||||
PlatformGetLastError(VOID);
|
||||
|
||||
//
|
||||
// PROCESS / THREAD IDENTITY
|
||||
//
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue