Skip to content

Commit bf85542

Browse files
committed
renamed CriticalSection -> UniqueCriticalSection
1 parent cc8ee50 commit bf85542

File tree

3 files changed

+31
-17
lines changed

3 files changed

+31
-17
lines changed

.github/workflows/build.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ jobs:
2929
- {os: windows-2022, arch: win32, config: RelWithDebInfo, crypto: ON}
3030
- {os: windows-2022, arch: win32, config: RelWithDebInfo, crypto: OFF}
3131
- {os: windows-2022, arch: arm64, config: RelWithDebInfo, crypto: ON}
32-
- {os: windows-2022, arch: arm, config: RelWithDebInfo, crypto: ON}
32+
# - {os: windows-2022, arch: arm, config: RelWithDebInfo, crypto: ON} # ARM not supported any longer
3333
# - {os: ubuntu-2204, arch: x64, config: RelWithDebInfo} # runner fails for some reason, works fine locally: see https://github.com/actions/runner-images/discussions/7188
3434
# - {os: ubuntu-2204, arch: x86, config: RelWithDebInfo}
3535

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)