Begin reworking TLS impl & add TLS loader support

This commit is contained in:
2025-10-27 01:03:30 -06:00
parent f2743d05e7
commit 50a457c5e3
12 changed files with 691 additions and 29 deletions

View File

@@ -1,4 +1,3 @@
#include "async_io.h"
#include "common.h"
#include "context.h"
#include "files.h"
@@ -6,6 +5,7 @@
#include "processes.h"
#include "strutil.h"
#include "version_info.h"
#include "tls.h"
#include <asm/ldt.h>
#include <charconv>
@@ -57,7 +57,8 @@ TIB *wibo::allocateTib() {
if (!newTib) {
return nullptr;
}
newTib->tib = newTib;
tls::initializeTib(newTib);
newTib->self = newTib;
newTib->peb = processPeb;
return newTib;
}
@@ -451,7 +452,8 @@ int main(int argc, char **argv) {
// Create TIB
memset(&tib, 0, sizeof(tib));
tib.tib = &tib;
wibo::tls::initializeTib(&tib);
tib.self = &tib;
tib.peb = static_cast<PEB *>(calloc(1, sizeof(PEB)));
tib.peb->ProcessParameters =
static_cast<RTL_USER_PROCESS_PARAMETERS *>(calloc(1, sizeof(RTL_USER_PROCESS_PARAMETERS)));
@@ -596,6 +598,10 @@ int main(int argc, char **argv) {
fprintf(stderr, "Failed to resolve imports for main module (DLL initialization failure?)\n");
abort();
}
if (!wibo::initializeModuleTls(*wibo::mainModule)) {
fprintf(stderr, "Failed to initialize TLS for main module\n");
return 1;
}
// Reset last error
wibo::lastError = 0;