mirror of
https://github.com/SagerNet/sing.git
synced 2025-04-03 11:57:39 +03:00
Fix build on go1.21
This commit is contained in:
parent
dc27334e9a
commit
d852e9c03d
2 changed files with 36 additions and 2 deletions
|
@ -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
34
common/buf/ptr_go120.go
Normal 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")
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue