summaryrefslogtreecommitdiffhomepage
path: root/tun/wintun/memmod/memmod_windows.go
diff options
context:
space:
mode:
authorJason A. Donenfeld <Jason@zx2c4.com>2021-08-05 14:56:48 +0200
committerJason A. Donenfeld <Jason@zx2c4.com>2021-08-05 14:56:48 +0200
commit3957e9b9dd191e0c4f7fc41d15a865357c097d9e (patch)
treea92fc7445933dab4bfadc8bdef66cba90a0001dc /tun/wintun/memmod/memmod_windows.go
parentbad6caeb82edd0e22bdbcfa1ca544a5805109e14 (diff)
memmod: register exception handler tables
Otherwise recent WDK binaries fail on ARM64, where an exception handler is used for trapping an illegal instruction when ARMv8.1 atomics are being tested for functionality. Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
Diffstat (limited to 'tun/wintun/memmod/memmod_windows.go')
-rw-r--r--tun/wintun/memmod/memmod_windows.go13
1 files changed, 13 insertions, 0 deletions
diff --git a/tun/wintun/memmod/memmod_windows.go b/tun/wintun/memmod/memmod_windows.go
index 59450e7..075c03a 100644
--- a/tun/wintun/memmod/memmod_windows.go
+++ b/tun/wintun/memmod/memmod_windows.go
@@ -159,6 +159,16 @@ func (module *Module) finalizeSection(sectionData *sectionFinalizeData) error {
return nil
}
+var rtlAddFunctionTable = windows.NewLazySystemDLL("ntdll.dll").NewProc("RtlAddFunctionTable")
+
+func (module *Module) registerExceptionHandlers() {
+ directory := module.headerDirectory(IMAGE_DIRECTORY_ENTRY_EXCEPTION)
+ if directory.Size == 0 || directory.VirtualAddress == 0 {
+ return
+ }
+ rtlAddFunctionTable.Call(module.codeBase+uintptr(directory.VirtualAddress), uintptr(directory.Size)/unsafe.Sizeof(IMAGE_RUNTIME_FUNCTION_ENTRY{}), module.codeBase)
+}
+
func (module *Module) finalizeSections() error {
sections := module.headers.Sections()
imageOffset := module.headers.OptionalHeader.imageOffset()
@@ -500,6 +510,9 @@ func LoadLibrary(data []byte) (module *Module, err error) {
return
}
+ // Register exception tables, if they exist.
+ module.registerExceptionHandlers()
+
// TLS callbacks are executed BEFORE the main loading.
module.executeTLS()