2026-05-10 00:58:47 +02:00
|
|
|
/**
|
|
|
|
|
* @file PlatformIo.c
|
|
|
|
|
* @author Sina Karvandi (sina@hyperdbg.org)
|
|
|
|
|
* @brief Implementation of cross platform APIs for I/O Request Packet (IRP) management
|
|
|
|
|
* @details
|
|
|
|
|
* @version 0.19
|
|
|
|
|
* @date 2026-05-09
|
|
|
|
|
*
|
|
|
|
|
* @copyright This project is released under the GNU Public License v3.
|
|
|
|
|
*
|
|
|
|
|
*/
|
|
|
|
|
#include "pch.h"
|
|
|
|
|
|
|
|
|
|
#if defined(__linux__)
|
|
|
|
|
# include "../header/PlatformIo.h"
|
|
|
|
|
#endif // defined(__linux__)
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @brief Get the current I/O stack location from an IRP
|
|
|
|
|
*
|
|
|
|
|
* @param Irp Pointer to the IRP (I/O Request Packet)
|
|
|
|
|
* @return PIO_STACK_LOCATION Pointer to the current stack location
|
|
|
|
|
*/
|
|
|
|
|
PIO_STACK_LOCATION
|
|
|
|
|
PlatformIoGetCurrentIrpStackLocation(PIRP Irp)
|
|
|
|
|
{
|
|
|
|
|
#if defined(_WIN32) || defined(_WIN64)
|
|
|
|
|
|
|
|
|
|
return IoGetCurrentIrpStackLocation(Irp);
|
|
|
|
|
|
|
|
|
|
#elif defined(__linux__)
|
|
|
|
|
|
2026-08-11 12:00:27 +02:00
|
|
|
//
|
|
|
|
|
// STUB: no NT IRP on Linux. TODO(Linux): map the IRP onto the char-device
|
|
|
|
|
// read/ioctl request that carries the notify buffer.
|
|
|
|
|
//
|
|
|
|
|
UNREFERENCED_PARAMETER(Irp);
|
|
|
|
|
|
|
|
|
|
return NULL;
|
2026-05-10 00:58:47 +02:00
|
|
|
|
|
|
|
|
#else
|
|
|
|
|
|
|
|
|
|
# error "Unsupported platform"
|
|
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @brief Complete an IRP and release it back to the I/O manager
|
|
|
|
|
*
|
|
|
|
|
* @param Irp Pointer to the IRP to complete
|
|
|
|
|
* @param PriorityBoost Priority boost value (e.g., IO_NO_INCREMENT)
|
|
|
|
|
* @return VOID
|
|
|
|
|
*/
|
|
|
|
|
VOID
|
|
|
|
|
PlatformIoCompleteRequest(PIRP Irp, CCHAR PriorityBoost)
|
|
|
|
|
{
|
|
|
|
|
#if defined(_WIN32) || defined(_WIN64)
|
|
|
|
|
|
|
|
|
|
IoCompleteRequest(Irp, PriorityBoost);
|
|
|
|
|
|
|
|
|
|
#elif defined(__linux__)
|
|
|
|
|
|
2026-08-11 12:00:27 +02:00
|
|
|
//
|
|
|
|
|
// STUB. TODO(Linux): complete the pending read/ioctl (copy out + wake waiter).
|
|
|
|
|
//
|
|
|
|
|
UNREFERENCED_PARAMETER(Irp);
|
|
|
|
|
UNREFERENCED_PARAMETER(PriorityBoost);
|
2026-05-10 00:58:47 +02:00
|
|
|
|
|
|
|
|
#else
|
|
|
|
|
|
|
|
|
|
# error "Unsupported platform"
|
|
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @brief Mark the current IRP stack location as pending
|
|
|
|
|
*
|
|
|
|
|
* @param Irp Pointer to the IRP to mark as pending
|
|
|
|
|
* @return VOID
|
|
|
|
|
*/
|
|
|
|
|
VOID
|
|
|
|
|
PlatformIoMarkIrpPending(PIRP Irp)
|
|
|
|
|
{
|
|
|
|
|
#if defined(_WIN32) || defined(_WIN64)
|
|
|
|
|
|
|
|
|
|
IoMarkIrpPending(Irp);
|
|
|
|
|
|
|
|
|
|
#elif defined(__linux__)
|
|
|
|
|
|
2026-08-11 12:00:27 +02:00
|
|
|
//
|
|
|
|
|
// STUB. TODO(Linux): mark the request pending (a blocking read parks itself).
|
|
|
|
|
//
|
|
|
|
|
UNREFERENCED_PARAMETER(Irp);
|
2026-05-10 00:58:47 +02:00
|
|
|
|
|
|
|
|
#else
|
|
|
|
|
|
|
|
|
|
# error "Unsupported platform"
|
|
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
}
|