mirror of
https://github.com/taviso/loadlibrary
synced 2026-06-08 17:42:38 +00:00
make tls slots accessible via teb
This commit is contained in:
+11
-8
@@ -622,16 +622,19 @@ error:
|
||||
return false;
|
||||
}
|
||||
|
||||
uintptr_t LocalStorage[1024] = {0};
|
||||
|
||||
bool setup_nt_threadinfo(PEXCEPTION_HANDLER ExceptionHandler)
|
||||
{
|
||||
static EXCEPTION_FRAME ExceptionFrame;
|
||||
static NT_TIB ThreadInfo = {
|
||||
.Self = &ThreadInfo,
|
||||
static TEB ThreadEnvironment = {
|
||||
.Tib.Self = &ThreadEnvironment.Tib,
|
||||
.ThreadLocalStoragePointer = LocalStorage, // https://github.com/taviso/loadlibrary/issues/65
|
||||
};
|
||||
struct user_desc pebdescriptor = {
|
||||
.entry_number = -1,
|
||||
.base_addr = (uintptr_t) &ThreadInfo,
|
||||
.limit = sizeof ThreadInfo,
|
||||
.base_addr = (uintptr_t) &ThreadEnvironment,
|
||||
.limit = sizeof ThreadEnvironment,
|
||||
.seg_32bit = 1,
|
||||
.contents = 0,
|
||||
.read_exec_only = 0,
|
||||
@@ -641,12 +644,12 @@ bool setup_nt_threadinfo(PEXCEPTION_HANDLER ExceptionHandler)
|
||||
};
|
||||
|
||||
if (ExceptionHandler) {
|
||||
if (ThreadInfo.ExceptionList) {
|
||||
if (ThreadEnvironment.Tib.ExceptionList) {
|
||||
DebugLog("Resetting ThreadInfo.ExceptionList");
|
||||
}
|
||||
ExceptionFrame.handler = ExceptionHandler;
|
||||
ExceptionFrame.prev = NULL;
|
||||
ThreadInfo.ExceptionList = &ExceptionFrame;
|
||||
ExceptionFrame.handler = ExceptionHandler;
|
||||
ExceptionFrame.prev = NULL;
|
||||
ThreadEnvironment.Tib.ExceptionList = &ExceptionFrame;
|
||||
}
|
||||
|
||||
if (syscall(__NR_set_thread_area, &pebdescriptor) != 0) {
|
||||
|
||||
@@ -981,6 +981,22 @@ typedef struct _NT_TIB {
|
||||
PVOID Self;
|
||||
} NT_TIB, *PNT_TIB;
|
||||
|
||||
typedef struct _CLIENT_ID {
|
||||
HANDLE UniqueProcess;
|
||||
HANDLE UniqueThread;
|
||||
} CLIENT_ID;
|
||||
|
||||
typedef struct _TEB {
|
||||
NT_TIB Tib;
|
||||
PVOID EnvironmentPointer;
|
||||
CLIENT_ID Cid;
|
||||
PVOID ActiveRpcInfo;
|
||||
PVOID ThreadLocalStoragePointer;
|
||||
// The fields below this are deliberately omitted so that access causes a
|
||||
// crash (because of the segment limit). This lets me know I have to fix
|
||||
// it, otherwise the error is very difficult to track down.
|
||||
} TEB, *PTEB;
|
||||
|
||||
struct user_desc {
|
||||
unsigned int entry_number;
|
||||
unsigned long base_addr;
|
||||
|
||||
@@ -17,7 +17,7 @@
|
||||
#endif
|
||||
|
||||
static int TlsIndex;
|
||||
uintptr_t LocalStorage[1024];
|
||||
extern uintptr_t LocalStorage[1024];
|
||||
|
||||
STATIC DWORD WINAPI TlsAlloc(void)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user