upleb.uk

Public git repos — served from a NIP-34 GRASP relay at git.upleb.uk

summaryrefslogtreecommitdiff
path: root/runtime/test/loader_test.cpp
diff options
context:
space:
mode:
authorItsNotRexed <300290919+ItsNotRexed@users.noreply.github.com>2026-11-21 18:37:42 -0500
committerItsNotRexed <300290919+ItsNotRexed@users.noreply.github.com>2026-11-21 18:37:42 -0500
commit99e4044d6b79984d6a0df1e478c6262306cce476 (patch)
tree3165dc8186030ef6b886dbbc1fe2848f38d1544e /runtime/test/loader_test.cpp
parentd937b7f092dbc188b59754e5c73c1a9dac553cf9 (diff)
parent993a2cbf72a9509ca730e509ea38e455d35f5a74 (diff)
Merge pull request #93 from Kam471
Diffstat (limited to 'runtime/test/loader_test.cpp')
-rw-r--r--runtime/test/loader_test.cpp18
1 files changed, 14 insertions, 4 deletions
diff --git a/runtime/test/loader_test.cpp b/runtime/test/loader_test.cpp
index b756cc1b6..6165352f6 100644
--- a/runtime/test/loader_test.cpp
+++ b/runtime/test/loader_test.cpp
@@ -4,6 +4,7 @@
4// What it pins down: a valid image maps exactly as its headers say, and a truncated or corrupt one is rejected with 4// What it pins down: a valid image maps exactly as its headers say, and a truncated or corrupt one is rejected with
5// a message instead of being followed out of bounds. The truncation case covers every length of a valid image. 5// a message instead of being followed out of bounds. The truncation case covers every length of a valid image.
6#include <windows.h> 6#include <windows.h>
7#include <intrin.h>
7 8
8#include <algorithm> 9#include <algorithm>
9#include <cstdio> 10#include <cstdio>
@@ -499,12 +500,21 @@ void test_initialise() {
499 failed("initialise calls DllMain for a DLL", "the entry point never wrote its sentinel"); 500 failed("initialise calls DllMain for a DLL", "the entry point never wrote its sentinel");
500 else 501 else
501 pass("initialise calls DllMain for a DLL"); 502 pass("initialise calls DllMain for a DLL");
502 uint32_t slot = *reinterpret_cast<const uint32_t*>(m.base + 0x10A0); 503 // __declspec(thread) reads TEB->ThreadLocalStoragePointer[_tls_index] at gs:[58h], which is a different index
503 void* block = slot == TLS_OUT_OF_INDEXES ? nullptr : TlsGetValue(slot); 504 // space from the TlsAlloc slots. The loader writes the OS-assigned module index (reserved through
505 // gta6rt_tls_host.dll) into AddressOfIndex and puts the template copy in that TEB slot, so this reads exactly
506 // what mapped __declspec(thread) code would.
507 const uint32_t index = *reinterpret_cast<const uint32_t*>(m.base + 0x10A0);
508 auto** module_slots = reinterpret_cast<void**>(__readgsqword(0x58));
509 void* block = index == TLS_OUT_OF_INDEXES || index >= 64 || !module_slots ? nullptr : module_slots[index];
510 if (index != m.tls_index)
511 failed("the module TLS index is written to AddressOfIndex", "the image and the Module disagree");
512 else
513 pass("the module TLS index is written to AddressOfIndex");
504 if (!block || std::memcmp(block, "TLS!", 4) != 0) 514 if (!block || std::memcmp(block, "TLS!", 4) != 0)
505 failed("the TLS template is copied into the allocated slot", "the slot doesn't hold the template"); 515 failed("the TLS template is copied into the module TLS slot", "the TEB slot doesn't hold the template");
506 else 516 else
507 pass("the TLS template is copied into the allocated slot"); 517 pass("the TLS template is copied into the module TLS slot");
508 } catch (const std::exception& e) { 518 } catch (const std::exception& e) {
509 failed("initialise runs a TLS callback and DllMain", e.what()); 519 failed("initialise runs a TLS callback and DllMain", e.what());
510 } 520 }