feat: implement llgo.stackSave

This commit is contained in:
Haolan
2025-09-15 13:38:33 +08:00
parent dba7bd498f
commit 2ec5653f5e
8 changed files with 119 additions and 2 deletions

View File

@@ -0,0 +1,26 @@
//go:build amd64
package main
import (
"unsafe"
_ "unsafe"
)
//go:linkname getsp llgo.stackSave
func getsp() unsafe.Pointer
//go:linkname asmFull llgo.asm
func asmFull(instruction string, regs map[string]any) uintptr { return 0 }
func main() {
var spPtr uintptr
asmFull("movq sp, {{addr}}", map[string]any{
"addr": unsafe.Pointer(&spPtr),
})
if spPtr != uintptr(getsp()) {
panic("invalid stack pointer")
}
}

View File

@@ -0,0 +1,22 @@
//go:build arm64
package main
import (
"unsafe"
_ "unsafe"
)
//go:linkname getsp llgo.stackSave
func getsp() unsafe.Pointer
//go:linkname asmFull llgo.asm
func asmFull(instruction string, regs map[string]any) uintptr { return 0 }
func main() {
sp := asmFull("mov {}, sp", nil)
if sp != uintptr(getsp()) {
panic("invalid stack pointer")
}
}