diff options
Diffstat (limited to 'runtime/test/loader_test.cpp')
| -rw-r--r-- | runtime/test/loader_test.cpp | 14 |
1 files changed, 14 insertions, 0 deletions
diff --git a/runtime/test/loader_test.cpp b/runtime/test/loader_test.cpp index 194174b00..3a4ced292 100644 --- a/runtime/test/loader_test.cpp +++ b/runtime/test/loader_test.cpp | |||
| @@ -941,6 +941,19 @@ std::vector<uint8_t> make_unwind_image(const std::vector<RUNTIME_FUNCTION>& entr | |||
| 941 | return img; | 941 | return img; |
| 942 | } | 942 | } |
| 943 | 943 | ||
| 944 | // PE/COFF: NumberOfRvaAndSizes counts the data directories; the slots past it are not directories whatever they hold. | ||
| 945 | // With 9 directories the TLS slot (index 9) is not one, so bytes left in it must not make the image fail to load. | ||
| 946 | void test_tls_directory_count() { | ||
| 947 | auto img = make_image(); | ||
| 948 | auto& tls = nt_of(img)->OptionalHeader.DataDirectory[IMAGE_DIRECTORY_ENTRY_TLS]; | ||
| 949 | tls.VirtualAddress = 0xFFFF0000; // would run past the image if it were read as a TLS directory | ||
| 950 | tls.Size = sizeof(IMAGE_TLS_DIRECTORY64); | ||
| 951 | nt_of(img)->OptionalHeader.NumberOfRvaAndSizes = IMAGE_DIRECTORY_ENTRY_TLS; | ||
| 952 | expect_loads("a TLS slot past NumberOfRvaAndSizes is not read as a TLS directory", img); | ||
| 953 | nt_of(img)->OptionalHeader.NumberOfRvaAndSizes = IMAGE_NUMBEROF_DIRECTORY_ENTRIES; | ||
| 954 | expect_rejects("the same TLS slot within NumberOfRvaAndSizes is checked and refused", img); | ||
| 955 | } | ||
| 956 | |||
| 944 | void test_unwind_registration() { | 957 | void test_unwind_registration() { |
| 945 | const std::vector<RUNTIME_FUNCTION> entries = {{0x1000, 0x1010, kUnwindRva}, {0x1010, 0x1020, kUnwindRva}}; | 958 | const std::vector<RUNTIME_FUNCTION> entries = {{0x1000, 0x1010, kUnwindRva}, {0x1010, 0x1020, kUnwindRva}}; |
| 946 | uintptr_t pc = 0; | 959 | uintptr_t pc = 0; |
| @@ -1109,6 +1122,7 @@ int main() { | |||
| 1109 | test_delay_descriptor_fields(); | 1122 | test_delay_descriptor_fields(); |
| 1110 | test_forwarded_exports(); | 1123 | test_forwarded_exports(); |
| 1111 | test_export_bounds(); | 1124 | test_export_bounds(); |
| 1125 | test_tls_directory_count(); | ||
| 1112 | test_unwind_registration(); | 1126 | test_unwind_registration(); |
| 1113 | } catch (const std::exception& e) { | 1127 | } catch (const std::exception& e) { |
| 1114 | // A write that fails (write_image throws) ends the run with the reason, instead of terminating the process. | 1128 | // A write that fails (write_image throws) ends the run with the reason, instead of terminating the process. |