diff options
| author | AwkGrep256 <AwkGrep256@users.noreply.github.com> | 2026-11-23 00:18:06 +0300 |
|---|---|---|
| committer | AwkGrep256 <AwkGrep256@users.noreply.github.com> | 2026-11-23 00:18:06 +0300 |
| commit | 7353b6fbdd615209aa9ba52f0e46eeb35dea90ad (patch) | |
| tree | dd5759ac54e1e9b8c01525c8291c2cf0ca856ca6 /runtime/test/loader_test.cpp | |
| parent | 58bc80c331097fe25df0cd43577ea17af2cd1e46 (diff) | |
| parent | 960466152f872c87e4593c919c77ca587551c865 (diff) | |
Merge branch 'radv-ps-oracle' into ps-helper-lanes
# Conflicts:
# docs/design.md
# docs/shader_validation.md
Diffstat (limited to 'runtime/test/loader_test.cpp')
| -rw-r--r-- | runtime/test/loader_test.cpp | 37 |
1 files changed, 37 insertions, 0 deletions
diff --git a/runtime/test/loader_test.cpp b/runtime/test/loader_test.cpp index 194174b00..73bc49206 100644 --- a/runtime/test/loader_test.cpp +++ b/runtime/test/loader_test.cpp | |||
| @@ -184,6 +184,28 @@ void expect_rejects(const char* what, const std::vector<uint8_t>& bytes) { | |||
| 184 | 184 | ||
| 185 | void test_valid_image() { expect_loads("a valid image maps with its section intact", make_image()); } | 185 | void test_valid_image() { expect_loads("a valid image maps with its section intact", make_image()); } |
| 186 | 186 | ||
| 187 | void test_entry_bounds() { | ||
| 188 | for (bool is_dll : {false, true}) { | ||
| 189 | for (uint32_t entry : {0u, 0x1000u, 0x1FFFu, 0x2000u, 0x2001u}) { | ||
| 190 | auto img = make_image(); | ||
| 191 | if (is_dll) nt_of(img)->FileHeader.Characteristics |= IMAGE_FILE_DLL; | ||
| 192 | nt_of(img)->OptionalHeader.AddressOfEntryPoint = entry; | ||
| 193 | const std::string what = std::string(is_dll ? "DLL" : "EXE") + " entry RVA " + std::to_string(entry); | ||
| 194 | if (entry < nt_of(img)->OptionalHeader.SizeOfImage) { | ||
| 195 | expect_loads(what.c_str(), img); | ||
| 196 | } else { | ||
| 197 | std::string error; | ||
| 198 | if (load(write_image(img), error) == 0) | ||
| 199 | failed(what.c_str(), "the image loaded"); | ||
| 200 | else if (error.find("the entry point is outside the image") == std::string::npos) | ||
| 201 | failed(what.c_str(), "unexpected error: " + error); | ||
| 202 | else | ||
| 203 | pass(what.c_str()); | ||
| 204 | } | ||
| 205 | } | ||
| 206 | } | ||
| 207 | } | ||
| 208 | |||
| 187 | void test_header_bounds() { | 209 | void test_header_bounds() { |
| 188 | { | 210 | { |
| 189 | auto img = make_image(); | 211 | auto img = make_image(); |
| @@ -941,6 +963,19 @@ std::vector<uint8_t> make_unwind_image(const std::vector<RUNTIME_FUNCTION>& entr | |||
| 941 | return img; | 963 | return img; |
| 942 | } | 964 | } |
| 943 | 965 | ||
| 966 | // PE/COFF: NumberOfRvaAndSizes counts the data directories; the slots past it are not directories whatever they hold. | ||
| 967 | // With 9 directories the TLS slot (index 9) is not one, so bytes left in it must not make the image fail to load. | ||
| 968 | void test_tls_directory_count() { | ||
| 969 | auto img = make_image(); | ||
| 970 | auto& tls = nt_of(img)->OptionalHeader.DataDirectory[IMAGE_DIRECTORY_ENTRY_TLS]; | ||
| 971 | tls.VirtualAddress = 0xFFFF0000; // would run past the image if it were read as a TLS directory | ||
| 972 | tls.Size = sizeof(IMAGE_TLS_DIRECTORY64); | ||
| 973 | nt_of(img)->OptionalHeader.NumberOfRvaAndSizes = IMAGE_DIRECTORY_ENTRY_TLS; | ||
| 974 | expect_loads("a TLS slot past NumberOfRvaAndSizes is not read as a TLS directory", img); | ||
| 975 | nt_of(img)->OptionalHeader.NumberOfRvaAndSizes = IMAGE_NUMBEROF_DIRECTORY_ENTRIES; | ||
| 976 | expect_rejects("the same TLS slot within NumberOfRvaAndSizes is checked and refused", img); | ||
| 977 | } | ||
| 978 | |||
| 944 | void test_unwind_registration() { | 979 | void test_unwind_registration() { |
| 945 | const std::vector<RUNTIME_FUNCTION> entries = {{0x1000, 0x1010, kUnwindRva}, {0x1010, 0x1020, kUnwindRva}}; | 980 | const std::vector<RUNTIME_FUNCTION> entries = {{0x1000, 0x1010, kUnwindRva}, {0x1010, 0x1020, kUnwindRva}}; |
| 946 | uintptr_t pc = 0; | 981 | uintptr_t pc = 0; |
| @@ -1093,6 +1128,7 @@ int main() { | |||
| 1093 | return 1; | 1128 | return 1; |
| 1094 | } | 1129 | } |
| 1095 | test_valid_image(); | 1130 | test_valid_image(); |
| 1131 | test_entry_bounds(); | ||
| 1096 | test_header_bounds(); | 1132 | test_header_bounds(); |
| 1097 | test_section_bounds(); | 1133 | test_section_bounds(); |
| 1098 | test_truncation(); | 1134 | test_truncation(); |
| @@ -1109,6 +1145,7 @@ int main() { | |||
| 1109 | test_delay_descriptor_fields(); | 1145 | test_delay_descriptor_fields(); |
| 1110 | test_forwarded_exports(); | 1146 | test_forwarded_exports(); |
| 1111 | test_export_bounds(); | 1147 | test_export_bounds(); |
| 1148 | test_tls_directory_count(); | ||
| 1112 | test_unwind_registration(); | 1149 | test_unwind_registration(); |
| 1113 | } catch (const std::exception& e) { | 1150 | } catch (const std::exception& e) { |
| 1114 | // A write that fails (write_image throws) ends the run with the reason, instead of terminating the process. | 1151 | // A write that fails (write_image throws) ends the run with the reason, instead of terminating the process. |