Minor cleanup

This commit is contained in:
2025-10-06 13:12:00 -06:00
parent f52ca2803f
commit f5aa320800
3 changed files with 8 additions and 11 deletions

View File

@@ -6,6 +6,7 @@
#include "handles.h" #include "handles.h"
#include "strutil.h" #include "strutil.h"
#include <algorithm>
#include <iterator> #include <iterator>
#include <mutex> #include <mutex>
#include <string> #include <string>
@@ -115,12 +116,8 @@ Pin<RegistryKeyObject> handleDataFromHKeyLocked(HKEY hKey) {
bool isPredefinedKeyHandle(HKEY hKey) { bool isPredefinedKeyHandle(HKEY hKey) {
uintptr_t raw = reinterpret_cast<uintptr_t>(hKey); uintptr_t raw = reinterpret_cast<uintptr_t>(hKey);
for (const auto &kPredefinedKeyInfo : kPredefinedKeyInfos) { return std::any_of(std::begin(kPredefinedKeyInfos), std::end(kPredefinedKeyInfos),
if (kPredefinedKeyInfo.value == raw) { [raw](const PredefinedKeyInfo &info) { return info.value == raw; });
return true;
}
}
return false;
} }
} // namespace } // namespace

View File

@@ -37,22 +37,22 @@ BOOL WIN_FUNC DuplicateHandle(HANDLE hSourceProcessHandle, HANDLE hSourceHandle,
return FALSE; return FALSE;
} }
auto &handles = wibo::handles();
if (isPseudoCurrentProcessHandle(hSourceHandle)) { if (isPseudoCurrentProcessHandle(hSourceHandle)) {
auto po = make_pin<ProcessObject>(getpid(), -1); auto po = make_pin<ProcessObject>(getpid(), -1);
auto handle = wibo::handles().alloc(std::move(po), 0, 0); auto handle = handles.alloc(std::move(po), 0, 0);
DEBUG_LOG("DuplicateHandle: created process handle for current process -> %p\n", handle); DEBUG_LOG("DuplicateHandle: created process handle for current process -> %p\n", handle);
*lpTargetHandle = handle; *lpTargetHandle = handle;
return TRUE; return TRUE;
} else if (isPseudoCurrentThreadHandle(hSourceHandle)) { } else if (isPseudoCurrentThreadHandle(hSourceHandle)) {
auto th = make_pin<ThreadObject>(pthread_self()); auto th = make_pin<ThreadObject>(pthread_self());
auto handle = wibo::handles().alloc(std::move(th), 0, 0); auto handle = handles.alloc(std::move(th), 0, 0);
DEBUG_LOG("DuplicateHandle: created thread handle for current thread -> %p\n", handle); DEBUG_LOG("DuplicateHandle: created thread handle for current thread -> %p\n", handle);
*lpTargetHandle = handle; *lpTargetHandle = handle;
return TRUE; return TRUE;
} }
if (!wibo::handles().duplicateTo(hSourceHandle, wibo::handles(), *lpTargetHandle, dwDesiredAccess, bInheritHandle, if (!handles.duplicateTo(hSourceHandle, handles, *lpTargetHandle, dwDesiredAccess, bInheritHandle, dwOptions)) {
dwOptions)) {
wibo::lastError = ERROR_INVALID_HANDLE; wibo::lastError = ERROR_INVALID_HANDLE;
return FALSE; return FALSE;
} }

View File

@@ -187,7 +187,7 @@ bool Handles::duplicateTo(HANDLE src, Handles &dst, HANDLE &out, uint32_t desire
uint32_t effAccess = (options & DUPLICATE_SAME_ACCESS) ? meta.grantedAccess : (desiredAccess & meta.grantedAccess); uint32_t effAccess = (options & DUPLICATE_SAME_ACCESS) ? meta.grantedAccess : (desiredAccess & meta.grantedAccess);
const uint32_t flags = (inherit ? HANDLE_FLAG_INHERIT : 0); const uint32_t flags = (inherit ? HANDLE_FLAG_INHERIT : 0);
// Reuse the same handle if duplicating within the same table and no changes // Reuse the same handle if duplicating with DUPLICATE_CLOSE_SOURCE within the same table and no changes
if (&dst == this && closeSource && effAccess == meta.grantedAccess && flags == meta.flags) { if (&dst == this && closeSource && effAccess == meta.grantedAccess && flags == meta.flags) {
out = src; out = src;
return true; return true;