Fix build on go1.21

This commit is contained in:
世界 2023-06-22 14:55:16 +08:00
parent dc27334e9a
commit d852e9c03d
No known key found for this signature in database
GPG key ID: CD109927C34A63C4
2 changed files with 36 additions and 2 deletions

View file

@ -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

34
common/buf/ptr_go120.go Normal file
View file

@ -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")
}