Skip to content

Commit 9e1f761

Browse files
aarzilligopherbot
authored andcommitted
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 <[email protected]> Run-TryBot: Michael Pratt <[email protected]> Reviewed-by: Russ Cox <[email protected]> Run-TryBot: Russ Cox <[email protected]> Auto-Submit: Russ Cox <[email protected]>
1 parent d48e67d commit 9e1f761

11 files changed

+105
-20
lines changed

unix/mkpost.go

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,32 @@ func main() {
7070
b = convertEprocRegex.ReplaceAll(b, []byte("$1$2[$3]byte"))
7171
}
7272

73+
if goos == "freebsd" {
74+
// Inside PtraceLwpInfoStruct replace __Siginfo with __PtraceSiginfo,
75+
// Create __PtraceSiginfo as a copy of __Siginfo where every *byte instance is replaced by uintptr
76+
ptraceLwpInfoStruct := regexp.MustCompile(`(?s:type PtraceLwpInfoStruct struct \{.*?\})`)
77+
b = ptraceLwpInfoStruct.ReplaceAllFunc(b, func(in []byte) []byte {
78+
return bytes.ReplaceAll(in, []byte("__Siginfo"), []byte("__PtraceSiginfo"))
79+
})
80+
81+
siginfoStruct := regexp.MustCompile(`(?s:type __Siginfo struct \{.*?\})`)
82+
b = siginfoStruct.ReplaceAllFunc(b, func(in []byte) []byte {
83+
out := append([]byte{}, in...)
84+
out = append(out, '\n', '\n')
85+
out = append(out,
86+
bytes.ReplaceAll(
87+
bytes.ReplaceAll(in, []byte("__Siginfo"), []byte("__PtraceSiginfo")),
88+
[]byte("*byte"), []byte("uintptr"))...)
89+
return out
90+
})
91+
92+
// Inside PtraceIoDesc replace all *byte with uintptr
93+
ptraceIoDescStruct := regexp.MustCompile(`(?s:type PtraceIoDesc struct \{.*?\})`)
94+
b = ptraceIoDescStruct.ReplaceAllFunc(b, func(in []byte) []byte {
95+
return bytes.ReplaceAll(in, []byte("*byte"), []byte("uintptr"))
96+
})
97+
}
98+
7399
// Intentionally export __val fields in Fsid and Sigset_t
74100
valRegex := regexp.MustCompile(`type (Fsid|Sigset_t) struct {(\s+)X__(bits|val)(\s+\S+\s+)}`)
75101
b = valRegex.ReplaceAll(b, []byte("type $1 struct {${2}Val$4}"))

unix/syscall_freebsd_386.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ func PtraceGetFsBase(pid int, fsbase *int64) (err error) {
6161
}
6262

6363
func PtraceIO(req int, pid int, addr uintptr, out []byte, countin int) (count int, err error) {
64-
ioDesc := PtraceIoDesc{Op: int32(req), Offs: (*byte)(unsafe.Pointer(addr)), Addr: (*byte)(unsafe.Pointer(&out[0])), Len: uint32(countin)}
64+
ioDesc := PtraceIoDesc{Op: int32(req), Offs: uintptr(unsafe.Pointer(addr)), Addr: uintptr(unsafe.Pointer(&out[0])), Len: uint32(countin)}
6565
err = ptrace(PT_IO, pid, uintptr(unsafe.Pointer(&ioDesc)), 0)
6666
return int(ioDesc.Len), err
6767
}

unix/syscall_freebsd_amd64.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ func PtraceGetFsBase(pid int, fsbase *int64) (err error) {
6161
}
6262

6363
func PtraceIO(req int, pid int, addr uintptr, out []byte, countin int) (count int, err error) {
64-
ioDesc := PtraceIoDesc{Op: int32(req), Offs: (*byte)(unsafe.Pointer(addr)), Addr: (*byte)(unsafe.Pointer(&out[0])), Len: uint64(countin)}
64+
ioDesc := PtraceIoDesc{Op: int32(req), Offs: uintptr(unsafe.Pointer(addr)), Addr: uintptr(unsafe.Pointer(&out[0])), Len: uint64(countin)}
6565
err = ptrace(PT_IO, pid, uintptr(unsafe.Pointer(&ioDesc)), 0)
6666
return int(ioDesc.Len), err
6767
}

unix/syscall_freebsd_arm.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ func sendfile(outfd int, infd int, offset *int64, count int) (written int, err e
5757
func Syscall9(num, a1, a2, a3, a4, a5, a6, a7, a8, a9 uintptr) (r1, r2 uintptr, err syscall.Errno)
5858

5959
func PtraceIO(req int, pid int, addr uintptr, out []byte, countin int) (count int, err error) {
60-
ioDesc := PtraceIoDesc{Op: int32(req), Offs: (*byte)(unsafe.Pointer(addr)), Addr: (*byte)(unsafe.Pointer(&out[0])), Len: uint32(countin)}
60+
ioDesc := PtraceIoDesc{Op: int32(req), Offs: uintptr(unsafe.Pointer(addr)), Addr: uintptr(unsafe.Pointer(&out[0])), Len: uint32(countin)}
6161
err = ptrace(PT_IO, pid, uintptr(unsafe.Pointer(&ioDesc)), 0)
6262
return int(ioDesc.Len), err
6363
}

unix/syscall_freebsd_arm64.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ func sendfile(outfd int, infd int, offset *int64, count int) (written int, err e
5757
func Syscall9(num, a1, a2, a3, a4, a5, a6, a7, a8, a9 uintptr) (r1, r2 uintptr, err syscall.Errno)
5858

5959
func PtraceIO(req int, pid int, addr uintptr, out []byte, countin int) (count int, err error) {
60-
ioDesc := PtraceIoDesc{Op: int32(req), Offs: (*byte)(unsafe.Pointer(addr)), Addr: (*byte)(unsafe.Pointer(&out[0])), Len: uint64(countin)}
60+
ioDesc := PtraceIoDesc{Op: int32(req), Offs: uintptr(unsafe.Pointer(addr)), Addr: uintptr(unsafe.Pointer(&out[0])), Len: uint64(countin)}
6161
err = ptrace(PT_IO, pid, uintptr(unsafe.Pointer(&ioDesc)), 0)
6262
return int(ioDesc.Len), err
6363
}

unix/syscall_freebsd_riscv64.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ func sendfile(outfd int, infd int, offset *int64, count int) (written int, err e
5757
func Syscall9(num, a1, a2, a3, a4, a5, a6, a7, a8, a9 uintptr) (r1, r2 uintptr, err syscall.Errno)
5858

5959
func PtraceIO(req int, pid int, addr uintptr, out []byte, countin int) (count int, err error) {
60-
ioDesc := PtraceIoDesc{Op: int32(req), Offs: (*byte)(unsafe.Pointer(addr)), Addr: (*byte)(unsafe.Pointer(&out[0])), Len: uint64(countin)}
60+
ioDesc := PtraceIoDesc{Op: int32(req), Offs: uintptr(unsafe.Pointer(addr)), Addr: uintptr(unsafe.Pointer(&out[0])), Len: uint64(countin)}
6161
err = ptrace(PT_IO, pid, uintptr(unsafe.Pointer(&ioDesc)), 0)
6262
return int(ioDesc.Len), err
6363
}

unix/ztypes_freebsd_386.go

Lines changed: 14 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

unix/ztypes_freebsd_amd64.go

Lines changed: 15 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

unix/ztypes_freebsd_arm.go

Lines changed: 15 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

unix/ztypes_freebsd_arm64.go

Lines changed: 15 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

unix/ztypes_freebsd_riscv64.go

Lines changed: 15 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)