diff options
Diffstat (limited to 'unix/mkpost.go')
-rw-r--r-- | unix/mkpost.go | 37 |
1 files changed, 37 insertions, 0 deletions
diff --git a/unix/mkpost.go b/unix/mkpost.go index 366b2d4..ec31df2 100644 --- a/unix/mkpost.go +++ b/unix/mkpost.go @@ -70,6 +70,34 @@ 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 the Offs field, which refers to an address + // in the child process (not the Go parent), with a uintptr. + ptraceIoDescStruct := regexp.MustCompile(`(?s:type PtraceIoDesc struct \{.*?\})`) + addrField := regexp.MustCompile(`(\bOffs\s+)\*byte`) + b = ptraceIoDescStruct.ReplaceAllFunc(b, func(in []byte) []byte { + return addrField.ReplaceAll(in, []byte(`${1}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}")) @@ -82,6 +110,15 @@ func main() { icmpV6Regex := regexp.MustCompile(`type (ICMPv6Filter) struct {(\s+)X__icmp6_filt(\s+\S+\s+)}`) b = icmpV6Regex.ReplaceAll(b, []byte("type $1 struct {${2}Filt$3}")) + // Intentionally export address storage field in SockaddrStorage convert it to [N]byte. + convertSockaddrStorageData := regexp.MustCompile(`(X__ss_padding)\s+\[(\d+)\]u?int8`) + sockaddrStorageType := regexp.MustCompile(`type SockaddrStorage struct {[^}]*}`) + sockaddrStorageStructs := sockaddrStorageType.FindAll(b, -1) + for _, s := range sockaddrStorageStructs { + newNames := convertSockaddrStorageData.ReplaceAll(s, []byte("Data [$2]byte")) + b = bytes.Replace(b, s, newNames, 1) + } + // If we have empty Ptrace structs, we should delete them. Only s390x emits // nonempty Ptrace structs. ptraceRexexp := regexp.MustCompile(`type Ptrace((Psw|Fpregs|Per) struct {\s*})`) |