[win/unwinding] Remove Windows7 handling of unwinding records API.

Bug: https://github.com/dart-lang/sdk/issues/54509
Change-Id: Ic88c864a1d9c0ef571576b4d39119ba3d0384135
TEST=ci
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/353783
Reviewed-by: Ryan Macnak <rmacnak@google.com>
Commit-Queue: Alexander Aprelev <aam@google.com>
This commit is contained in:
Alexander Aprelev 2024-02-23 04:13:39 +00:00 committed by Commit Queue
parent a9b50e1df9
commit 34213ba605
6 changed files with 10 additions and 69 deletions

View file

@ -270,7 +270,6 @@ class LoadedElf {
}
bool LoadedElf::Load() {
UnwindingRecordsPlatform::Init();
VirtualMemory::Init();
if (error_ != nullptr) {
@ -300,7 +299,6 @@ LoadedElf::~LoadedElf() {
UnwindingRecordsPlatform::UnregisterDynamicTable(
dynamic_runtime_function_tables_[i]);
}
UnwindingRecordsPlatform::Cleanup();
#endif
// Unmap the image.

View file

@ -19,8 +19,6 @@ intptr_t UnwindingRecordsPlatform::SizeInBytes() {
#if !defined(DART_HOST_OS_WINDOWS) || \
(!defined(TARGET_ARCH_X64) && !defined(TARGET_ARCH_ARM64))
void UnwindingRecordsPlatform::Init() {}
void UnwindingRecordsPlatform::Cleanup() {}
void UnwindingRecordsPlatform::RegisterExecutableMemory(
void* start,
intptr_t size,

View file

@ -12,18 +12,12 @@ namespace dart {
class UnwindingRecordsPlatform : public AllStatic {
public:
static void Init();
static void Cleanup();
static intptr_t SizeInBytes();
static void RegisterExecutableMemory(void* start,
intptr_t size,
void** pp_dynamic_table);
static void UnregisterDynamicTable(void* p_dynamic_table);
static void* GetAddGrowableFunctionTableFunc();
static void* GetDeleteGrowableFunctionTableFunc();
};
#if (defined(DART_TARGET_OS_WINDOWS) || defined(DART_HOST_OS_WINDOWS)) && \

View file

@ -27,48 +27,10 @@ intptr_t UnwindingRecordsPlatform::SizeInBytes() {
#if defined(DART_HOST_OS_WINDOWS) && \
(defined(TARGET_ARCH_X64) || defined(TARGET_ARCH_ARM64))
static HMODULE ntdll_module;
static decltype(&::RtlAddGrowableFunctionTable)
add_growable_function_table_func_ = nullptr;
static decltype(&::RtlDeleteGrowableFunctionTable)
delete_growable_function_table_func_ = nullptr;
void* UnwindingRecordsPlatform::GetAddGrowableFunctionTableFunc() {
return add_growable_function_table_func_;
}
void* UnwindingRecordsPlatform::GetDeleteGrowableFunctionTableFunc() {
return delete_growable_function_table_func_;
}
void UnwindingRecordsPlatform::Init() {
ntdll_module =
LoadLibraryEx(L"ntdll.dll", nullptr, LOAD_LIBRARY_SEARCH_SYSTEM32);
ASSERT(ntdll_module != nullptr);
// This pair of functions is not available on Windows 7.
add_growable_function_table_func_ =
reinterpret_cast<decltype(&::RtlAddGrowableFunctionTable)>(
::GetProcAddress(ntdll_module, "RtlAddGrowableFunctionTable"));
delete_growable_function_table_func_ =
reinterpret_cast<decltype(&::RtlDeleteGrowableFunctionTable)>(
::GetProcAddress(ntdll_module, "RtlDeleteGrowableFunctionTable"));
// Either both available, or both not available.
ASSERT((add_growable_function_table_func_ == nullptr) ==
(delete_growable_function_table_func_ == nullptr));
}
void UnwindingRecordsPlatform::Cleanup() {
FreeLibrary(ntdll_module);
}
void UnwindingRecordsPlatform::RegisterExecutableMemory(
void* start,
intptr_t size,
void** pp_dynamic_table) {
auto func = add_growable_function_table_func_;
if (func == nullptr) {
return;
}
intptr_t unwinding_record_offset = size - kReservedUnwindingRecordsSizeBytes;
uint8_t* record_ptr = static_cast<uint8_t*>(start) + unwinding_record_offset;
CodeRangeUnwindingRecord* record =
@ -76,21 +38,20 @@ void UnwindingRecordsPlatform::RegisterExecutableMemory(
RELEASE_ASSERT(record->magic == kUnwindingRecordMagic);
uword start_num = reinterpret_cast<intptr_t>(start);
uword end_num = start_num + size;
DWORD status = func(pp_dynamic_table,
/*FunctionTable=*/record->runtime_function,
/*EntryCount=*/record->runtime_function_count,
/*MaximumEntryCount=*/record->runtime_function_count,
/*RangeBase=*/start_num,
/*RangeEnd=*/end_num);
DWORD status = RtlAddGrowableFunctionTable(
pp_dynamic_table,
/*FunctionTable=*/record->runtime_function,
/*EntryCount=*/record->runtime_function_count,
/*MaximumEntryCount=*/record->runtime_function_count,
/*RangeBase=*/start_num,
/*RangeEnd=*/end_num);
if (status != 0) {
FATAL("Failed to add growable function table: 0x%x\n", status);
}
}
void UnwindingRecordsPlatform::UnregisterDynamicTable(void* p_dynamic_table) {
auto func = delete_growable_function_table_func_;
if (func == nullptr) return;
func(p_dynamic_table);
RtlDeleteGrowableFunctionTable(p_dynamic_table);
}
#endif // defined(DART_HOST_OS_WINDOWS)

View file

@ -342,7 +342,6 @@ char* Dart::DartInit(const Dart_InitializeParams* params) {
ForwardingCorpse::Init();
Api::Init();
NativeSymbolResolver::Init();
UnwindingRecordsPlatform::Init();
Page::Init();
StoreBuffer::Init();
MarkingStack::Init();
@ -758,7 +757,6 @@ char* Dart::Cleanup() {
StoreBuffer::Cleanup();
Object::Cleanup();
Page::Cleanup();
UnwindingRecordsPlatform::Cleanup();
StubCode::Cleanup();
#if defined(SUPPORT_TIMELINE)
if (FLAG_trace_shutdown) {

View file

@ -109,11 +109,6 @@ const void* UnwindingRecords::GenerateRecordsInto(intptr_t offset,
// Special exception-unwinding records are put at the end of executable
// page on Windows for 64-bit applications.
void UnwindingRecords::RegisterExecutablePage(Page* page) {
// Won't set up unwinding records on Windows 7, so users won't be able
// to benefit from proper unhandled exceptions filtering.
auto function = static_cast<decltype(&::RtlAddGrowableFunctionTable)>(
UnwindingRecordsPlatform::GetAddGrowableFunctionTableFunc());
if (function == nullptr) return;
ASSERT(page->is_executable());
ASSERT(sizeof(CodeRangeUnwindingRecord) <=
UnwindingRecordsPlatform::SizeInBytes());
@ -125,7 +120,7 @@ void UnwindingRecords::RegisterExecutablePage(Page* page) {
unwinding_record_offset) CodeRangeUnwindingRecord();
InitUnwindingRecord(unwinding_record_offset, record, page->memory_->size());
RELEASE_ASSERT(record->magic == kUnwindingRecordMagic);
DWORD status = function(
DWORD status = RtlAddGrowableFunctionTable(
/*DynamicTable=*/&record->dynamic_table,
/*FunctionTable=*/record->runtime_function,
/*EntryCount=*/record->runtime_function_count,
@ -138,9 +133,6 @@ void UnwindingRecords::RegisterExecutablePage(Page* page) {
}
void UnwindingRecords::UnregisterExecutablePage(Page* page) {
auto function = static_cast<decltype(&::RtlDeleteGrowableFunctionTable)>(
UnwindingRecordsPlatform::GetDeleteGrowableFunctionTableFunc());
if (function == nullptr) return;
ASSERT(page->is_executable() && !page->is_image());
intptr_t unwinding_record_offset =
page->memory_->size() - UnwindingRecordsPlatform::SizeInBytes();
@ -149,7 +141,7 @@ void UnwindingRecords::UnregisterExecutablePage(Page* page) {
reinterpret_cast<uint8_t*>(page->memory_->start()) +
unwinding_record_offset);
RELEASE_ASSERT(record->magic == kUnwindingRecordMagic);
function(record->dynamic_table);
RtlDeleteGrowableFunctionTable(record->dynamic_table);
}
#endif // defined(DART_HOST_OS_WINDOWS)