mirror of
https://github.com/golang/sys.git
synced 2026-02-08 03:36:03 +03:00
x/sys/unix: use uintptr for tracee addresses on FreeBSD
Change PtraceLwpInfoStruct, PtraceIoDesc and PtraceIO to not use *byte to represent addresses that belong to the traced process. Fixes golang/go#54113 Change-Id: I6efad26046b784d79b83fed4498cac93957274ca Reviewed-on: https://go-review.googlesource.com/c/sys/+/419915 TryBot-Result: Gopher Robot <gobot@golang.org> Run-TryBot: Michael Pratt <mpratt@google.com> Reviewed-by: Russ Cox <rsc@golang.org> Run-TryBot: Russ Cox <rsc@golang.org> Auto-Submit: Russ Cox <rsc@golang.org>
This commit is contained in:
@@ -70,6 +70,32 @@ func main() {
|
||||
b = convertEprocRegex.ReplaceAll(b, []byte("$1$2[$3]byte"))
|
||||
}
|
||||
|
||||
if goos == "freebsd" {
|
||||
// Inside PtraceLwpInfoStruct replace __Siginfo with __PtraceSiginfo,
|
||||
// Create __PtraceSiginfo as a copy of __Siginfo where every *byte instance is replaced by uintptr
|
||||
ptraceLwpInfoStruct := regexp.MustCompile(`(?s:type PtraceLwpInfoStruct struct \{.*?\})`)
|
||||
b = ptraceLwpInfoStruct.ReplaceAllFunc(b, func(in []byte) []byte {
|
||||
return bytes.ReplaceAll(in, []byte("__Siginfo"), []byte("__PtraceSiginfo"))
|
||||
})
|
||||
|
||||
siginfoStruct := regexp.MustCompile(`(?s:type __Siginfo struct \{.*?\})`)
|
||||
b = siginfoStruct.ReplaceAllFunc(b, func(in []byte) []byte {
|
||||
out := append([]byte{}, in...)
|
||||
out = append(out, '\n', '\n')
|
||||
out = append(out,
|
||||
bytes.ReplaceAll(
|
||||
bytes.ReplaceAll(in, []byte("__Siginfo"), []byte("__PtraceSiginfo")),
|
||||
[]byte("*byte"), []byte("uintptr"))...)
|
||||
return out
|
||||
})
|
||||
|
||||
// Inside PtraceIoDesc replace all *byte with uintptr
|
||||
ptraceIoDescStruct := regexp.MustCompile(`(?s:type PtraceIoDesc struct \{.*?\})`)
|
||||
b = ptraceIoDescStruct.ReplaceAllFunc(b, func(in []byte) []byte {
|
||||
return bytes.ReplaceAll(in, []byte("*byte"), []byte("uintptr"))
|
||||
})
|
||||
}
|
||||
|
||||
// Intentionally export __val fields in Fsid and Sigset_t
|
||||
valRegex := regexp.MustCompile(`type (Fsid|Sigset_t) struct {(\s+)X__(bits|val)(\s+\S+\s+)}`)
|
||||
b = valRegex.ReplaceAll(b, []byte("type $1 struct {${2}Val$4}"))
|
||||
|
||||
@@ -61,7 +61,7 @@ func PtraceGetFsBase(pid int, fsbase *int64) (err error) {
|
||||
}
|
||||
|
||||
func PtraceIO(req int, pid int, addr uintptr, out []byte, countin int) (count int, err error) {
|
||||
ioDesc := PtraceIoDesc{Op: int32(req), Offs: (*byte)(unsafe.Pointer(addr)), Addr: (*byte)(unsafe.Pointer(&out[0])), Len: uint32(countin)}
|
||||
ioDesc := PtraceIoDesc{Op: int32(req), Offs: uintptr(unsafe.Pointer(addr)), Addr: uintptr(unsafe.Pointer(&out[0])), Len: uint32(countin)}
|
||||
err = ptrace(PT_IO, pid, uintptr(unsafe.Pointer(&ioDesc)), 0)
|
||||
return int(ioDesc.Len), err
|
||||
}
|
||||
|
||||
@@ -61,7 +61,7 @@ func PtraceGetFsBase(pid int, fsbase *int64) (err error) {
|
||||
}
|
||||
|
||||
func PtraceIO(req int, pid int, addr uintptr, out []byte, countin int) (count int, err error) {
|
||||
ioDesc := PtraceIoDesc{Op: int32(req), Offs: (*byte)(unsafe.Pointer(addr)), Addr: (*byte)(unsafe.Pointer(&out[0])), Len: uint64(countin)}
|
||||
ioDesc := PtraceIoDesc{Op: int32(req), Offs: uintptr(unsafe.Pointer(addr)), Addr: uintptr(unsafe.Pointer(&out[0])), Len: uint64(countin)}
|
||||
err = ptrace(PT_IO, pid, uintptr(unsafe.Pointer(&ioDesc)), 0)
|
||||
return int(ioDesc.Len), err
|
||||
}
|
||||
|
||||
@@ -57,7 +57,7 @@ func sendfile(outfd int, infd int, offset *int64, count int) (written int, err e
|
||||
func Syscall9(num, a1, a2, a3, a4, a5, a6, a7, a8, a9 uintptr) (r1, r2 uintptr, err syscall.Errno)
|
||||
|
||||
func PtraceIO(req int, pid int, addr uintptr, out []byte, countin int) (count int, err error) {
|
||||
ioDesc := PtraceIoDesc{Op: int32(req), Offs: (*byte)(unsafe.Pointer(addr)), Addr: (*byte)(unsafe.Pointer(&out[0])), Len: uint32(countin)}
|
||||
ioDesc := PtraceIoDesc{Op: int32(req), Offs: uintptr(unsafe.Pointer(addr)), Addr: uintptr(unsafe.Pointer(&out[0])), Len: uint32(countin)}
|
||||
err = ptrace(PT_IO, pid, uintptr(unsafe.Pointer(&ioDesc)), 0)
|
||||
return int(ioDesc.Len), err
|
||||
}
|
||||
|
||||
@@ -57,7 +57,7 @@ func sendfile(outfd int, infd int, offset *int64, count int) (written int, err e
|
||||
func Syscall9(num, a1, a2, a3, a4, a5, a6, a7, a8, a9 uintptr) (r1, r2 uintptr, err syscall.Errno)
|
||||
|
||||
func PtraceIO(req int, pid int, addr uintptr, out []byte, countin int) (count int, err error) {
|
||||
ioDesc := PtraceIoDesc{Op: int32(req), Offs: (*byte)(unsafe.Pointer(addr)), Addr: (*byte)(unsafe.Pointer(&out[0])), Len: uint64(countin)}
|
||||
ioDesc := PtraceIoDesc{Op: int32(req), Offs: uintptr(unsafe.Pointer(addr)), Addr: uintptr(unsafe.Pointer(&out[0])), Len: uint64(countin)}
|
||||
err = ptrace(PT_IO, pid, uintptr(unsafe.Pointer(&ioDesc)), 0)
|
||||
return int(ioDesc.Len), err
|
||||
}
|
||||
|
||||
@@ -57,7 +57,7 @@ func sendfile(outfd int, infd int, offset *int64, count int) (written int, err e
|
||||
func Syscall9(num, a1, a2, a3, a4, a5, a6, a7, a8, a9 uintptr) (r1, r2 uintptr, err syscall.Errno)
|
||||
|
||||
func PtraceIO(req int, pid int, addr uintptr, out []byte, countin int) (count int, err error) {
|
||||
ioDesc := PtraceIoDesc{Op: int32(req), Offs: (*byte)(unsafe.Pointer(addr)), Addr: (*byte)(unsafe.Pointer(&out[0])), Len: uint64(countin)}
|
||||
ioDesc := PtraceIoDesc{Op: int32(req), Offs: uintptr(unsafe.Pointer(addr)), Addr: uintptr(unsafe.Pointer(&out[0])), Len: uint64(countin)}
|
||||
err = ptrace(PT_IO, pid, uintptr(unsafe.Pointer(&ioDesc)), 0)
|
||||
return int(ioDesc.Len), err
|
||||
}
|
||||
|
||||
@@ -294,7 +294,7 @@ type PtraceLwpInfoStruct struct {
|
||||
Flags int32
|
||||
Sigmask Sigset_t
|
||||
Siglist Sigset_t
|
||||
Siginfo __Siginfo
|
||||
Siginfo __PtraceSiginfo
|
||||
Tdname [20]int8
|
||||
Child_pid int32
|
||||
Syscall_code uint32
|
||||
@@ -312,6 +312,17 @@ type __Siginfo struct {
|
||||
Value [4]byte
|
||||
_ [32]byte
|
||||
}
|
||||
type __PtraceSiginfo struct {
|
||||
Signo int32
|
||||
Errno int32
|
||||
Code int32
|
||||
Pid int32
|
||||
Uid uint32
|
||||
Status int32
|
||||
Addr uintptr
|
||||
Value [4]byte
|
||||
_ [32]byte
|
||||
}
|
||||
|
||||
type Sigset_t struct {
|
||||
Val [4]uint32
|
||||
@@ -350,8 +361,8 @@ type FpExtendedPrecision struct{}
|
||||
|
||||
type PtraceIoDesc struct {
|
||||
Op int32
|
||||
Offs *byte
|
||||
Addr *byte
|
||||
Offs uintptr
|
||||
Addr uintptr
|
||||
Len uint32
|
||||
}
|
||||
|
||||
|
||||
@@ -291,7 +291,7 @@ type PtraceLwpInfoStruct struct {
|
||||
Flags int32
|
||||
Sigmask Sigset_t
|
||||
Siglist Sigset_t
|
||||
Siginfo __Siginfo
|
||||
Siginfo __PtraceSiginfo
|
||||
Tdname [20]int8
|
||||
Child_pid int32
|
||||
Syscall_code uint32
|
||||
@@ -310,6 +310,18 @@ type __Siginfo struct {
|
||||
_ [40]byte
|
||||
}
|
||||
|
||||
type __PtraceSiginfo struct {
|
||||
Signo int32
|
||||
Errno int32
|
||||
Code int32
|
||||
Pid int32
|
||||
Uid uint32
|
||||
Status int32
|
||||
Addr uintptr
|
||||
Value [8]byte
|
||||
_ [40]byte
|
||||
}
|
||||
|
||||
type Sigset_t struct {
|
||||
Val [4]uint32
|
||||
}
|
||||
@@ -354,8 +366,8 @@ type FpExtendedPrecision struct{}
|
||||
|
||||
type PtraceIoDesc struct {
|
||||
Op int32
|
||||
Offs *byte
|
||||
Addr *byte
|
||||
Offs uintptr
|
||||
Addr uintptr
|
||||
Len uint64
|
||||
}
|
||||
|
||||
|
||||
@@ -293,7 +293,7 @@ type PtraceLwpInfoStruct struct {
|
||||
Flags int32
|
||||
Sigmask Sigset_t
|
||||
Siglist Sigset_t
|
||||
Siginfo __Siginfo
|
||||
Siginfo __PtraceSiginfo
|
||||
Tdname [20]int8
|
||||
Child_pid int32
|
||||
Syscall_code uint32
|
||||
@@ -312,6 +312,18 @@ type __Siginfo struct {
|
||||
_ [32]byte
|
||||
}
|
||||
|
||||
type __PtraceSiginfo struct {
|
||||
Signo int32
|
||||
Errno int32
|
||||
Code int32
|
||||
Pid int32
|
||||
Uid uint32
|
||||
Status int32
|
||||
Addr uintptr
|
||||
Value [4]byte
|
||||
_ [32]byte
|
||||
}
|
||||
|
||||
type Sigset_t struct {
|
||||
Val [4]uint32
|
||||
}
|
||||
@@ -337,8 +349,8 @@ type FpExtendedPrecision struct {
|
||||
|
||||
type PtraceIoDesc struct {
|
||||
Op int32
|
||||
Offs *byte
|
||||
Addr *byte
|
||||
Offs uintptr
|
||||
Addr uintptr
|
||||
Len uint32
|
||||
}
|
||||
|
||||
|
||||
@@ -291,7 +291,7 @@ type PtraceLwpInfoStruct struct {
|
||||
Flags int32
|
||||
Sigmask Sigset_t
|
||||
Siglist Sigset_t
|
||||
Siginfo __Siginfo
|
||||
Siginfo __PtraceSiginfo
|
||||
Tdname [20]int8
|
||||
Child_pid int32
|
||||
Syscall_code uint32
|
||||
@@ -310,6 +310,18 @@ type __Siginfo struct {
|
||||
_ [40]byte
|
||||
}
|
||||
|
||||
type __PtraceSiginfo struct {
|
||||
Signo int32
|
||||
Errno int32
|
||||
Code int32
|
||||
Pid int32
|
||||
Uid uint32
|
||||
Status int32
|
||||
Addr uintptr
|
||||
Value [8]byte
|
||||
_ [40]byte
|
||||
}
|
||||
|
||||
type Sigset_t struct {
|
||||
Val [4]uint32
|
||||
}
|
||||
@@ -334,8 +346,8 @@ type FpExtendedPrecision struct{}
|
||||
|
||||
type PtraceIoDesc struct {
|
||||
Op int32
|
||||
Offs *byte
|
||||
Addr *byte
|
||||
Offs uintptr
|
||||
Addr uintptr
|
||||
Len uint64
|
||||
}
|
||||
|
||||
|
||||
@@ -291,7 +291,7 @@ type PtraceLwpInfoStruct struct {
|
||||
Flags int32
|
||||
Sigmask Sigset_t
|
||||
Siglist Sigset_t
|
||||
Siginfo __Siginfo
|
||||
Siginfo __PtraceSiginfo
|
||||
Tdname [20]int8
|
||||
Child_pid int32
|
||||
Syscall_code uint32
|
||||
@@ -310,6 +310,18 @@ type __Siginfo struct {
|
||||
_ [40]byte
|
||||
}
|
||||
|
||||
type __PtraceSiginfo struct {
|
||||
Signo int32
|
||||
Errno int32
|
||||
Code int32
|
||||
Pid int32
|
||||
Uid uint32
|
||||
Status int32
|
||||
Addr uintptr
|
||||
Value [8]byte
|
||||
_ [40]byte
|
||||
}
|
||||
|
||||
type Sigset_t struct {
|
||||
Val [4]uint32
|
||||
}
|
||||
@@ -335,8 +347,8 @@ type FpExtendedPrecision struct{}
|
||||
|
||||
type PtraceIoDesc struct {
|
||||
Op int32
|
||||
Offs *byte
|
||||
Addr *byte
|
||||
Offs uintptr
|
||||
Addr uintptr
|
||||
Len uint64
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user