Describe the bug
Go does not guarantee structs will be laid out in memory as they are defined. As a result, a large number of spots in this codebase are relying on undefined behaviour by directly casting bytes from unsafe.Pointer on C byte buffers directly to Go structs. See example in reproduction section.
Starting in Go 1.23, the intended way to handle this is: https://pkg.go.dev/structs#HostLayout
This field can be used as an "annotation" of sorts to force Go to pack the struct as the platform's C ABI dictates. This ensures that if Go decides to alter how they lay out structs in future versions, this codebase won't break in undefined ways.
To Reproduce
|
peb := (*processEnvironmentBlock64)(unsafe.Pointer(&buf[0])) |
Expected behavior
Everything works as expected now, but it is mostly by luck and could change with any future Go version.
Environment (please complete the following information):
N/A
Describe the bug
Go does not guarantee structs will be laid out in memory as they are defined. As a result, a large number of spots in this codebase are relying on undefined behaviour by directly casting bytes from
unsafe.Pointeron C byte buffers directly to Go structs. See example in reproduction section.Starting in Go 1.23, the intended way to handle this is: https://pkg.go.dev/structs#HostLayout
This field can be used as an "annotation" of sorts to force Go to pack the struct as the platform's C ABI dictates. This ensures that if Go decides to alter how they lay out structs in future versions, this codebase won't break in undefined ways.
To Reproduce
gopsutil/process/process_windows.go
Line 1018 in d0dd5e0
Expected behavior
Everything works as expected now, but it is mostly by luck and could change with any future Go version.
Environment (please complete the following information):
N/A