]> git.ipfire.org Git - thirdparty/wireguard-go.git/commit
device: make Peer fields safe for atomic access on 32-bit.
authorDavid Anderson <danderson@tailscale.com>
Sun, 1 Mar 2020 08:39:24 +0000 (00:39 -0800)
committerDavid Crawshaw <david@zentus.com>
Mon, 30 Mar 2020 09:10:36 +0000 (20:10 +1100)
commitd49f4e9fe36f344ff1fa75523bdac18bdcb31945
tree09d41b9c9f38123d9d162c810a2952170d7b41ec
parent224bc9e60c7e2e1f04573bc377121c8f844d57c6
device: make Peer fields safe for atomic access on 32-bit.

All atomic access must be aligned to 64 bits, even on 32-bit
platforms. Go promises that the start of allocated structs is
aligned to 64 bits. So, place the atomically-accessed things
first in the struct so that they benefit from that alignment.

As a side bonus, it cleanly separates fields that are accessed
by atomic ops, and those that should be accessed under mu.

Also adds a test that will fail consistently on 32-bit platforms
if the struct ever changes again to violate the rules. This is
likely not needed because unaligned access crashes reliably,
but this will reliably fail even if tests accidentally pass due
to lucky alignment.

Signed-Off-By: David Anderson <danderson@tailscale.com>
device/peer.go
device/peer_test.go [new file with mode: 0644]