From 52969bdfb074fda883092d31a9d2434a6543b43c Mon Sep 17 00:00:00 2001 From: Brad Fitzpatrick Date: Thu, 16 Jul 2020 13:38:21 -0700 Subject: [PATCH] derp: fix atomic padding on 32-bit again Broken by earlier OnlyDisco addition. --- derp/derp_server.go | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/derp/derp_server.go b/derp/derp_server.go index 3615bf77f..53f7ec1aa 100644 --- a/derp/derp_server.go +++ b/derp/derp_server.go @@ -40,7 +40,11 @@ const ( ) const host64bit = (^uint(0) >> 32) & 1 // 1 on 64-bit, 0 on 32-bit -const pad32bit = 4 - host64bit*4 // 0 on 64-bit, 4 on 32-bit + +// pad32bit is 4 on 32-bit machines and 0 on 64-bit. +// It exists so the Server struct's atomic fields can be aligned to 8 +// byte boundaries. (As tested by GOARCH=386 go test, etc) +const pad32bit = 4 - host64bit*4 // 0 on 64-bit, 4 on 32-bit // Server is a DERP server. type Server struct { @@ -53,6 +57,7 @@ type Server struct { // NAT traversal works (using DERP for out-of-band messaging) // but the packets themselves aren't going via DERP. OnlyDisco bool + _ [pad32bit]byte privateKey key.Private publicKey key.Public