upleb.uk

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

summaryrefslogtreecommitdiff
path: root/runtime/src
diff options
context:
space:
mode:
authorItsNotRexed <300290919+ItsNotRexed@users.noreply.github.com>2026-11-21 15:47:56 -0500
committerItsNotRexed <300290919+ItsNotRexed@users.noreply.github.com>2026-11-21 15:47:56 -0500
commit7ec7511da0e2c1b8a47d2b920106d4dc67cbb3a7 (patch)
tree797236f73f0bf04053ce39e71110a0f8c75de07c /runtime/src
parent556fc4a1db007067d17eb90d3e014231243f0a00 (diff)
parentda499ab9113015ba91c2218895abc51f0aa4baf3 (diff)
Merge pull request #140 from IAmNotSiob
Diffstat (limited to 'runtime/src')
-rw-r--r--runtime/src/pe_loader.cpp8
-rw-r--r--runtime/src/pe_loader.h7
2 files changed, 11 insertions, 4 deletions
diff --git a/runtime/src/pe_loader.cpp b/runtime/src/pe_loader.cpp
index caf5f0ad5..a0198c033 100644
--- a/runtime/src/pe_loader.cpp
+++ b/runtime/src/pe_loader.cpp
@@ -67,14 +67,16 @@ Module& Loader::load(const std::filesystem::path& image) {
67 std::string key = lower(image.filename().string()); 67 std::string key = lower(image.filename().string());
68 if (auto it = by_name_.find(key); it != by_name_.end()) return *it->second; 68 if (auto it = by_name_.find(key); it != by_name_.end()) return *it->second;
69 Module& m = map_image(image); 69 Module& m = map_image(image);
70 bind_imports(m); 70 bind_imports(m); // loads every bundled module m imports first, so they land in init_order_ before m
71 protect_sections(m); 71 protect_sections(m);
72 init_order_.push_back(&m);
72 return m; 73 return m;
73} 74}
74 75
75void Loader::initialise() { 76void Loader::initialise() {
76 // order_ is dependency order: a module is pushed after the modules it imports. 77 // Not order_: map_image pushes a module there before bind_imports maps its dependencies, so order_ lists an
77 for (auto* m : order_) initialise(*m); 78 // importer ahead of the DLLs it imports. init_order_ is filled once a module's imports are all loaded.
79 for (auto* m : init_order_) initialise(*m);
78} 80}
79 81
80void Loader::initialise(Module& m) { 82void Loader::initialise(Module& m) {
diff --git a/runtime/src/pe_loader.h b/runtime/src/pe_loader.h
index 8d9e0a224..9df630ae0 100644
--- a/runtime/src/pe_loader.h
+++ b/runtime/src/pe_loader.h
@@ -49,6 +49,10 @@ public:
49 49
50 const std::vector<Module*>& modules() const { return order_; } 50 const std::vector<Module*>& modules() const { return order_; }
51 51
52 // The order initialise() runs modules in: each module after every module it imports (a cycle is broken at the
53 // module that closed it). modules() is mapping order, which puts an importer before its imports.
54 const std::vector<Module*>& initialisation_order() const { return init_order_; }
55
52 // Runs each loaded module's TLS callbacks and then its DllMain(DLL_PROCESS_ATTACH), dependencies first. 56 // Runs each loaded module's TLS callbacks and then its DllMain(DLL_PROCESS_ATTACH), dependencies first.
53 // Only DLLs get DllMain called: an EXE's entry point is the caller's to run. Throws on a corrupt TLS 57 // Only DLLs get DllMain called: an EXE's entry point is the caller's to run. Throws on a corrupt TLS
54 // directory, a TLS callback outside its image, or a DllMain that returns FALSE. 58 // directory, a TLS callback outside its image, or a DllMain that returns FALSE.
@@ -65,7 +69,8 @@ private:
65 69
66 std::filesystem::path game_dir_; 70 std::filesystem::path game_dir_;
67 std::map<std::string, Module*> by_name_; // lower-case file name 71 std::map<std::string, Module*> by_name_; // lower-case file name
68 std::vector<Module*> order_; 72 std::vector<Module*> order_; // mapping order; owns the modules
73 std::vector<Module*> init_order_; // dependencies first, see initialisation_order()
69}; 74};
70 75
71std::string lower(std::string s); 76std::string lower(std::string s);