From 7c5d6326f85dc87d7a54bb8a581cef5e4f2242e1 Mon Sep 17 00:00:00 2001 From: Aiken Harris Date: Mon, 8 Sep 2025 22:35:59 +0200 Subject: [PATCH] Migrate EX subsystem to C++ --- xtoskrnl/ex/exports.cc | 112 ++++++++++++++++++++++++++ xtoskrnl/ex/{rundown.c => rundown.cc} | 21 +++-- xtoskrnl/includes/ex.hh | 16 ++++ xtoskrnl/includes/ex/rundown.hh | 30 +++++++ xtoskrnl/includes/xtos.hh | 1 + 5 files changed, 172 insertions(+), 8 deletions(-) create mode 100644 xtoskrnl/ex/exports.cc rename xtoskrnl/ex/{rundown.c => rundown.cc} (88%) create mode 100644 xtoskrnl/includes/ex.hh create mode 100644 xtoskrnl/includes/ex/rundown.hh diff --git a/xtoskrnl/ex/exports.cc b/xtoskrnl/ex/exports.cc new file mode 100644 index 0000000..92dce80 --- /dev/null +++ b/xtoskrnl/ex/exports.cc @@ -0,0 +1,112 @@ +/** + * PROJECT: ExectOS + * COPYRIGHT: See COPYING.md in the top level directory + * FILE: xtoskrnl/ex/exports.cc + * DESCRIPTION: C-compatible API wrappers for exported kernel functions + * DEVELOPERS: Aiken Harris + */ + +#include + + +/** + * Acquires the rundown protection for given descriptor. + * + * @param Descriptor + * Supplies a pointer to the rundown block descriptor. + * + * @return This routine returns TRUE if protection acquired successfully, or FALSE otherwise. + * + * @since NT 5.1 + */ +XTFASTCALL +BOOLEAN +ExAcquireRundownProtection(IN PEX_RUNDOWN_REFERENCE Descriptor) +{ + return EX::Rundown::AcquireProtection(Descriptor); +} + +/** + * Marks the rundown descriptor as completed. + * + * @param Descriptor + * Supplies a pointer to the descriptor to be completed. + * + * @return This routine does not return any value. + * + * @since NT 5.1 + */ +XTFASTCALL +VOID +ExCompleteRundownProtection(IN PEX_RUNDOWN_REFERENCE Descriptor) +{ + EX::Rundown::CompleteProtection(Descriptor); +} + +/** + * Initializes the rundown protection descriptor. + * + * @param Descriptor + * Supplies a pointer to the descriptor to be initialized. + * + * @return This routine does not return any value. + * + * @since NT 5.1 + */ +XTFASTCALL +VOID +ExInitializeRundownProtection(IN PEX_RUNDOWN_REFERENCE Descriptor) +{ + EX::Rundown::InitializeProtection(Descriptor); +} + +/** + * Reinitializes the rundown protection structure after it has been completed. + * + * @param Descriptor + * Supplies a pointer to the descriptor to be reinitialized. + * + * @return This routine does not return any value. + * + * @since NT 5.1 + */ +XTFASTCALL +VOID +ExReInitializeRundownProtection(IN PEX_RUNDOWN_REFERENCE Descriptor) +{ + EX::Rundown::ReInitializeProtection(Descriptor); +} + +/** + * Releases the rundown protection for given descriptor. + * + * @param Descriptor + * Supplies a pointer to the descriptor to be initialized. + * + * @return This routine does not return any value. + * + * @since NT 5.1 + */ +XTFASTCALL +VOID +ExReleaseRundownProtection(IN PEX_RUNDOWN_REFERENCE Descriptor) +{ + EX::Rundown::ReleaseProtection(Descriptor); +} + +/** + * Waits until rundown protection calls are completed. + * + * @param Descriptor + * Supplies a pointer to the rundown block descriptor. + * + * @return This routine does not return any value. + * + * @since NT 5.1 + */ +XTFASTCALL +VOID +ExWaitForRundownProtectionRelease(IN PEX_RUNDOWN_REFERENCE Descriptor) +{ + EX::Rundown::WaitForProtectionRelease(Descriptor); +} diff --git a/xtoskrnl/ex/rundown.c b/xtoskrnl/ex/rundown.cc similarity index 88% rename from xtoskrnl/ex/rundown.c rename to xtoskrnl/ex/rundown.cc index f5f5392..2af354b 100644 --- a/xtoskrnl/ex/rundown.c +++ b/xtoskrnl/ex/rundown.cc @@ -1,14 +1,17 @@ /** * PROJECT: ExectOS * COPYRIGHT: See COPYING.md in the top level directory - * FILE: xtoskrnl/ex/rundown.c + * FILE: xtoskrnl/ex/rundown.cc * DESCRIPTION: Rundown protection mechanism * DEVELOPERS: Rafal Kupiec */ -#include +#include +namespace EX +{ + /** * Acquires the rundown protection for given descriptor. * @@ -21,7 +24,7 @@ */ XTFASTCALL BOOLEAN -ExAcquireRundownProtection(IN PEX_RUNDOWN_REFERENCE Descriptor) +Rundown::AcquireProtection(IN PEX_RUNDOWN_REFERENCE Descriptor) { ULONG_PTR CurrentValue, NewValue; @@ -69,7 +72,7 @@ ExAcquireRundownProtection(IN PEX_RUNDOWN_REFERENCE Descriptor) */ XTFASTCALL VOID -ExCompleteRundownProtection(IN PEX_RUNDOWN_REFERENCE Descriptor) +Rundown::CompleteProtection(IN PEX_RUNDOWN_REFERENCE Descriptor) { RtlAtomicExchangePointer(&Descriptor->Ptr, (PVOID)EX_RUNDOWN_ACTIVE); } @@ -86,7 +89,7 @@ ExCompleteRundownProtection(IN PEX_RUNDOWN_REFERENCE Descriptor) */ XTFASTCALL VOID -ExInitializeRundownProtection(IN PEX_RUNDOWN_REFERENCE Descriptor) +Rundown::InitializeProtection(IN PEX_RUNDOWN_REFERENCE Descriptor) { /* Reset descriptor counter */ Descriptor->Count = 0; @@ -104,7 +107,7 @@ ExInitializeRundownProtection(IN PEX_RUNDOWN_REFERENCE Descriptor) */ XTFASTCALL VOID -ExReInitializeRundownProtection(IN PEX_RUNDOWN_REFERENCE Descriptor) +Rundown::ReInitializeProtection(IN PEX_RUNDOWN_REFERENCE Descriptor) { RtlAtomicExchangePointer(&Descriptor->Ptr, NULL); } @@ -121,7 +124,7 @@ ExReInitializeRundownProtection(IN PEX_RUNDOWN_REFERENCE Descriptor) */ XTFASTCALL VOID -ExReleaseRundownProtection(IN PEX_RUNDOWN_REFERENCE Descriptor) +Rundown::ReleaseProtection(IN PEX_RUNDOWN_REFERENCE Descriptor) { ULONG_PTR CurrentValue, NewValue; PEX_RUNDOWN_WAIT_BLOCK WaitBlock; @@ -172,7 +175,9 @@ ExReleaseRundownProtection(IN PEX_RUNDOWN_REFERENCE Descriptor) */ XTFASTCALL VOID -ExWaitForRundownProtectionRelease(IN PEX_RUNDOWN_REFERENCE Descriptor) +Rundown::WaitForProtectionRelease(IN PEX_RUNDOWN_REFERENCE Descriptor) { UNIMPLEMENTED; } + +} /* namespace */ diff --git a/xtoskrnl/includes/ex.hh b/xtoskrnl/includes/ex.hh new file mode 100644 index 0000000..0762412 --- /dev/null +++ b/xtoskrnl/includes/ex.hh @@ -0,0 +1,16 @@ +/** + * PROJECT: ExectOS + * COPYRIGHT: See COPYING.md in the top level directory + * FILE: xtoskrnl/includes/ex.hh + * DESCRIPTION: + * DEVELOPERS: Aiken Harris + */ + +#ifndef __XTOSKRNL_EX_HH +#define __XTOSKRNL_EX_HH + +#include + +#include + +#endif /* __XTOSKRNL_EX_HH */ diff --git a/xtoskrnl/includes/ex/rundown.hh b/xtoskrnl/includes/ex/rundown.hh new file mode 100644 index 0000000..b7d617f --- /dev/null +++ b/xtoskrnl/includes/ex/rundown.hh @@ -0,0 +1,30 @@ +/** + * PROJECT: ExectOS + * COPYRIGHT: See COPYING.md in the top level directory + * FILE: xtoskrnl/includes/ex/rundown.hh + * DESCRIPTION: Rundown protection mechanism + * DEVELOPERS: Aiken Harris + */ + +#ifndef __XTOSKRNL_EX_RUNDOWN_HH +#define __XTOSKRNL_EX_RUNDOWN_HH + +#include + + +/* Architecture-specific Library */ +namespace EX +{ + class Rundown + { + public: + STATIC XTFASTCALL BOOLEAN AcquireProtection(IN PEX_RUNDOWN_REFERENCE Descriptor); + STATIC XTFASTCALL VOID CompleteProtection(IN PEX_RUNDOWN_REFERENCE Descriptor); + STATIC XTFASTCALL VOID InitializeProtection(IN PEX_RUNDOWN_REFERENCE Descriptor); + STATIC XTFASTCALL VOID ReInitializeProtection(IN PEX_RUNDOWN_REFERENCE Descriptor); + STATIC XTFASTCALL VOID ReleaseProtection(IN PEX_RUNDOWN_REFERENCE Descriptor); + STATIC XTFASTCALL VOID WaitForProtectionRelease(IN PEX_RUNDOWN_REFERENCE Descriptor); + }; +} + +#endif /* __XTOSKRNL_EX_RUNDOWN_HH */ diff --git a/xtoskrnl/includes/xtos.hh b/xtoskrnl/includes/xtos.hh index 71edec8..4f59bb9 100644 --- a/xtoskrnl/includes/xtos.hh +++ b/xtoskrnl/includes/xtos.hh @@ -27,3 +27,4 @@ extern "C" { #include +#include