fix arm and x86 building

This commit is contained in:
KingKDot
2026-04-20 13:58:11 -05:00
parent a58e0fadf1
commit 1a43938982
3 changed files with 28 additions and 2 deletions
@@ -454,6 +454,12 @@ func (mm *MemoryModule) setupTLS(reason uint32) {
}
tebAddr := teb.CurrentTEB()
if tebAddr == 0 {
if tlsData != 0 {
_ = windows.VirtualFree(tlsData, 0, windows.MEM_RELEASE)
}
return
}
tlsArrayField := (*uintptr)(unsafe.Pointer(tebAddr + 0x58)) // ThreadLocalStoragePointer
oldArray := *tlsArrayField
@@ -538,6 +544,10 @@ func (mm *MemoryModule) SetupThreadTLS() func() {
ptrSize := unsafe.Sizeof(uintptr(0))
tebAddr := teb.CurrentTEB()
if tebAddr == 0 {
_ = windows.VirtualFree(tlsData, 0, windows.MEM_RELEASE)
return func() {}
}
tlsArrayField := (*uintptr)(unsafe.Pointer(tebAddr + 0x58))
oldArray := *tlsArrayField
@@ -572,8 +582,10 @@ func (mm *MemoryModule) SetupThreadTLS() func() {
_ = windows.VirtualFree(newArray, 0, windows.MEM_RELEASE)
}
tebNow := teb.CurrentTEB()
field := (*uintptr)(unsafe.Pointer(tebNow + 0x58))
*field = oldArray
if tebNow != 0 {
field := (*uintptr)(unsafe.Pointer(tebNow + 0x58))
*field = oldArray
}
}
}
@@ -0,0 +1,7 @@
//go:build windows && 386
package teb
func CurrentTEB() uintptr {
return 0
}
@@ -0,0 +1,7 @@
//go:build windows && arm64
package teb
func CurrentTEB() uintptr {
return 0
}