]> Cypherpunks repositories - gostls13.git/commitdiff
runtime/pprof: correct field alignment in machVMRegionBasicInfoData
authorCherry Mui <cherryyz@google.com>
Fri, 4 Aug 2023 20:30:40 +0000 (16:30 -0400)
committerCherry Mui <cherryyz@google.com>
Fri, 4 Aug 2023 23:35:39 +0000 (23:35 +0000)
The type machVMRegionBasicInfoData is generated from C type
vm_region_basic_info_data_64_t, which is a packed struct with a
64-bit field at offset 20. We cannot use uint64 as the field type
in the Go struct, as that will be aligned at offset 24, which does
not match the C struct. Change back to [8]byte (which is what the
cgo command generates), but keep the name Offset.

Updates #61707.
Updates #50891.

Change-Id: I2932328d7f9dfe9d79cff89752666c794d4d3788
Reviewed-on: https://go-review.googlesource.com/c/go/+/516156
Reviewed-by: Ian Lance Taylor <iant@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Run-TryBot: Cherry Mui <cherryyz@google.com>

src/runtime/pprof/defs_darwin_amd64.go
src/runtime/pprof/defs_darwin_arm64.go
src/runtime/pprof/vminfo_darwin.go

index 14226495d87c70b371783b4bfb10f623e688b02e..fa428b93862125c6d36787aa6450d4bbb7bf7b85 100644 (file)
@@ -9,7 +9,7 @@ type machVMRegionBasicInfoData struct {
        Inheritance      uint32
        Shared           uint32
        Reserved         uint32
-       Offset           uint64 // This is hand-edited since godefs generates: Pad_cgo_0 [8]byte
+       Offset           [8]byte // This is hand-edited since godefs generates: Pad_cgo_0 [8]byte. Cannot use uint64 due to alignment.
        Behavior         int32
        User_wired_count uint16
        Pad_cgo_1        [2]byte
index 2d34a80d80ca91357196a6bd64c3daf5e1e5d1f8..16c68a2b738812cfa1595a53be81be6c25250013 100644 (file)
@@ -9,7 +9,7 @@ type machVMRegionBasicInfoData struct {
        Inheritance      uint32
        Shared           int32
        Reserved         int32
-       Offset           uint64 // This is hand-edited since godefs generates: Pad_cgo_0 [8]byte
+       Offset           [8]byte // This is hand-edited since godefs generates: Pad_cgo_0 [8]byte. Cannot use uint64 due to alignment.
        Behavior         int32
        User_wired_count uint16
        Pad_cgo_1        [2]byte
index 7ddb0d1c6875cea5c0f022d3f537c53e72bd63f7..35b9e6d4879c565d1783b64e1b5215be8ce10db8 100644 (file)
@@ -39,7 +39,7 @@ func machVMInfo(addMapping func(lo, hi, offset uint64, file, buildID string)) bo
                        // offset is usually 0.
                        addMapping(addr,
                                addr+memRegionSize,
-                               uint64(info.Offset),
+                               read64(&info.Offset),
                                regionFilename(addr),
                                "")
                        added = true
@@ -48,6 +48,11 @@ func machVMInfo(addMapping func(lo, hi, offset uint64, file, buildID string)) bo
        }
 }
 
+func read64(p *[8]byte) uint64 {
+       // all supported darwin platforms are little endian
+       return uint64(p[0]) | uint64(p[1])<<8 | uint64(p[2])<<16 | uint64(p[3])<<24 | uint64(p[4])<<32 | uint64(p[5])<<40 | uint64(p[6])<<48 | uint64(p[7])<<56
+}
+
 func regionFilename(address uint64) string {
        buf := make([]byte, _MAXPATHLEN)
        r := proc_regionfilename(