aboutsummaryrefslogtreecommitdiff
path: root/src/runtime/runtime_linux_test.go
diff options
context:
space:
mode:
authorRhys Hiltner <rhys@justin.tv>2021-09-29 17:35:27 -0700
committerIan Lance Taylor <iant@golang.org>2021-11-02 05:43:05 +0000
commita97c527ac491cc13f6778010a2a81c84642ea1ca (patch)
treec42e74ac36841f3ae0b439ef44243f9a2fcd0502 /src/runtime/runtime_linux_test.go
parent6f327f7b889b81549d551ce6963067267578bd70 (diff)
downloadgo-a97c527ac491cc13f6778010a2a81c84642ea1ca.tar.xz
runtime: add padding to Linux kernel structures
Go exchanges siginfo and sigevent structures with the kernel. They contain unions, but Go's use is limited to the first few fields. Pad out the rest so the size Go sees is the same as what the Linux kernel sees. This is a follow-up to CL 342052 which added the sigevent struct without padding, and to CL 353136 which added the padding but with an assertion that confused several type-checkers. It updates the siginfo struct as well so there are no bad examples in the defs_linux_*.go files. Reviewed-on: https://go-review.googlesource.com/c/go/+/353136 Change-Id: I9610632ff0ec43eba91f560536f5441fa907b36f Reviewed-on: https://go-review.googlesource.com/c/go/+/360094 Run-TryBot: Ian Lance Taylor <iant@golang.org> Reviewed-by: Ian Lance Taylor <iant@golang.org> Reviewed-by: Michael Pratt <mpratt@google.com>
Diffstat (limited to 'src/runtime/runtime_linux_test.go')
-rw-r--r--src/runtime/runtime_linux_test.go11
1 files changed, 11 insertions, 0 deletions
diff --git a/src/runtime/runtime_linux_test.go b/src/runtime/runtime_linux_test.go
index cd59368cb2..a753aeea58 100644
--- a/src/runtime/runtime_linux_test.go
+++ b/src/runtime/runtime_linux_test.go
@@ -61,3 +61,14 @@ func TestEpollctlErrorSign(t *testing.T) {
t.Errorf("epollctl = %v, want %v", v, -EBADF)
}
}
+
+func TestKernelStructSize(t *testing.T) {
+ // Check that the Go definitions of structures exchanged with the kernel are
+ // the same size as what the kernel defines.
+ if have, want := unsafe.Sizeof(Siginfo{}), uintptr(SiginfoMaxSize); have != want {
+ t.Errorf("Go's siginfo struct is %d bytes long; kernel expects %d", have, want)
+ }
+ if have, want := unsafe.Sizeof(Sigevent{}), uintptr(SigeventMaxSize); have != want {
+ t.Errorf("Go's sigevent struct is %d bytes long; kernel expects %d", have, want)
+ }
+}