Skip to content

Commit 7e66294

Browse files
committed
renamed CriticalSection -> UniqueCriticalSection
1 parent 06db740 commit 7e66294

File tree

2 files changed

+30
-16
lines changed

2 files changed

+30
-16
lines changed

Modules/Common/Include/Handle.hpp

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,9 @@
55
#include "Common.hpp"
66

77
///
8-
/// Scope-managed handles
8+
/// @brief Scope-managed handles
99
///
1010
/// @ref https://andreasfertig.blog/2022/08/cpp-insights-lambdas-in-unevaluated-contexts/
11-
/// @link https://developercommunity.visualstudio.com/t/c20-internal-compiler-error-for-lambda-in-decltype/1631476
1211
///
1312
template<typename T, auto Deleter>
1413
using GenericHandle = std::unique_ptr<
@@ -26,8 +25,30 @@ using GenericHandle = std::unique_ptr<
2625
#ifdef __linux__
2726
using UniqueHandle = GenericHandle<FILE, ::fclose>;
2827
#else
29-
using UniqueHandle = GenericHandle<void, ::CloseHandle>;
28+
29+
///
30+
/// @brief A unique (as-in `unique_ptr`) Windows handle. It will close itself on scope-exit.
31+
///
32+
using UniqueHandle = GenericHandle<void, ::CloseHandle>;
33+
34+
///
35+
/// @brief A unique (as-in `unique_ptr`) Windows module handle.
36+
///
3037
using UniqueLibraryHandle = GenericHandle<HINSTANCE__, ::FreeLibrary>;
38+
39+
///
40+
/// @brief A unique Windows Critical Section.
41+
///
42+
using UniqueCriticalSection = GenericHandle<
43+
RTL_CRITICAL_SECTION,
44+
[](RTL_CRITICAL_SECTION* p)
45+
{
46+
if ( p )
47+
{
48+
::LeaveCriticalSection(p);
49+
p = nullptr;
50+
}
51+
}>;
3152
#endif // __linux__
3253

3354
using SharedHandle = std::shared_ptr<UniqueHandle>;

Modules/Process/Source/Win32/Process.cpp

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -27,13 +27,6 @@ usize
2727
GetPebLength();
2828
EXTERN_C_END
2929

30-
using CriticalSection = GenericHandle<
31-
RTL_CRITICAL_SECTION,
32-
[](auto p)
33-
{
34-
::LeaveCriticalSection(p);
35-
}>;
36-
3730

3831
namespace pwn::Process
3932
{
@@ -590,12 +583,12 @@ Process::EnumerateLocalModules()
590583
{
591584
std::vector<LDR_DATA_TABLE_ENTRY> res;
592585
auto peb = Peb();
593-
CriticalSection csLoaderLock {[&]()
594-
{
595-
auto lock = peb->LoaderLock;
596-
::EnterCriticalSection(lock);
597-
return lock;
598-
}()};
586+
UniqueCriticalSection csLoaderLock {[&]()
587+
{
588+
auto lock = peb->LoaderLock;
589+
::EnterCriticalSection(lock);
590+
return lock;
591+
}()};
599592

600593
if ( !peb->Ldr->Initialized )
601594
return Ok(res);

0 commit comments

Comments
 (0)