diff --git a/common/buf/ptr.go b/common/buf/ptr.go index 901c9e3..60e8fcf 100644 --- a/common/buf/ptr.go +++ b/common/buf/ptr.go @@ -1,4 +1,4 @@ -//go:build !disable_unsafe +//go:build !disable_unsafe && go1.21 package buf @@ -23,7 +23,7 @@ func init() { if !common.UnsafeBuffer { return } - debugVars := *(*[]dbgVar)(unsafe.Pointer(&dbgvars)) + debugVars := *(*[]*dbgVar)(unsafe.Pointer(&dbgvars)) for _, v := range debugVars { if v.name == "invalidptr" { *v.value = 0 diff --git a/common/buf/ptr_go120.go b/common/buf/ptr_go120.go new file mode 100644 index 0000000..575c723 --- /dev/null +++ b/common/buf/ptr_go120.go @@ -0,0 +1,34 @@ +//go:build !disable_unsafe && !go1.21 + +package buf + +import ( + "unsafe" + + "github.com/sagernet/sing/common" +) + +type dbgVar struct { + name string + value *int32 +} + +//go:linkname dbgvars runtime.dbgvars +var dbgvars any + +// go.info.runtime.dbgvars: relocation target go.info.[]github.com/sagernet/sing/common/buf.dbgVar not defined +// var dbgvars []dbgVar + +func init() { + if !common.UnsafeBuffer { + return + } + debugVars := *(*[]dbgVar)(unsafe.Pointer(&dbgvars)) + for _, v := range debugVars { + if v.name == "invalidptr" { + *v.value = 0 + return + } + } + panic("can't disable invalidptr") +}