Remove unsafe linkname usages

This commit is contained in:
世界 2022-08-03 16:37:25 +08:00
parent 842fd713ff
commit afbe231237
No known key found for this signature in database
GPG key ID: CD109927C34A63C4
2 changed files with 7 additions and 6 deletions

View file

@ -4,6 +4,8 @@ package buf
import (
"unsafe"
"github.com/sagernet/sing/common"
)
type dbgVar struct {
@ -17,8 +19,10 @@ var dbgvars any
// go.info.runtime.dbgvars: relocation target go.info.[]github.com/sagernet/sing/common/buf.dbgVar not defined
// var dbgvars []dbgVar
//nolint:gochecknoinits
func init() {
if !common.UnsafeBuffer {
return
}
debugVars := *(*[]dbgVar)(unsafe.Pointer(&dbgvars))
for _, v := range debugVars {
if v.name == "invalidptr" {

View file

@ -32,11 +32,8 @@ func Extend(cause error, message ...any) error {
return &extendedError{F.ToString(message...), cause}
}
//go:linkname errCanceled net.errCanceled
var errCanceled error
func IsClosedOrCanceled(err error) bool {
return IsMulti(err, io.EOF, net.ErrClosed, io.ErrClosedPipe, os.ErrClosed, syscall.EPIPE, syscall.ECONNRESET, context.Canceled, context.DeadlineExceeded, errCanceled)
return IsMulti(err, io.EOF, net.ErrClosed, io.ErrClosedPipe, os.ErrClosed, syscall.EPIPE, syscall.ECONNRESET, context.Canceled, context.DeadlineExceeded)
}
func IsClosed(err error) bool {
@ -44,5 +41,5 @@ func IsClosed(err error) bool {
}
func IsCanceled(err error) bool {
return IsMulti(err, context.Canceled, context.DeadlineExceeded, errCanceled)
return IsMulti(err, context.Canceled, context.DeadlineExceeded)
}