[x64] Reuse module handle when pulling in growable function table imports.

This commit is contained in:
gibbed 2019-08-23 04:33:44 -05:00 committed by Rick Gibbed
parent 92a85d6692
commit 918a7d4365
1 changed files with 13 additions and 6 deletions

View File

@ -163,12 +163,19 @@ bool Win32X64CodeCache::Initialize() {
unwind_table_.resize(kMaximumFunctionCount);
// Check if this version of Windows supports growable function tables.
add_growable_table_ = (FnRtlAddGrowableFunctionTable)GetProcAddress(
GetModuleHandleW(L"ntdll.dll"), "RtlAddGrowableFunctionTable");
delete_growable_table_ = (FnRtlDeleteGrowableFunctionTable)GetProcAddress(
GetModuleHandleW(L"ntdll.dll"), "RtlDeleteGrowableFunctionTable");
grow_table_ = (FnRtlGrowFunctionTable)GetProcAddress(
GetModuleHandleW(L"ntdll.dll"), "RtlGrowFunctionTable");
auto ntdll_handle = GetModuleHandleW(L"ntdll.dll");
if (!ntdll_handle) {
add_growable_table_ = nullptr;
delete_growable_table_ = nullptr;
grow_table_ = nullptr;
} else {
add_growable_table_ = (FnRtlAddGrowableFunctionTable)GetProcAddress(
ntdll_handle, "RtlAddGrowableFunctionTable");
delete_growable_table_ = (FnRtlDeleteGrowableFunctionTable)GetProcAddress(
ntdll_handle, "RtlDeleteGrowableFunctionTable");
grow_table_ = (FnRtlGrowFunctionTable)GetProcAddress(
ntdll_handle, "RtlGrowFunctionTable");
}
supports_growable_table_ =
add_growable_table_ && delete_growable_table_ && grow_table_;