From 011c6b76ee277010a3ba5785067f6548e18cdddf Mon Sep 17 00:00:00 2001 From: Wilko Nienhaus Date: Thu, 1 Apr 2021 19:21:27 +0300 Subject: [PATCH] move uint64s to beginning of struct to ensure they are 64-bit aligned See https://golang.org/pkg/sync/atomic/#pkg-note-BUG for reference: "The first word in (...) an allocated struct (...) can be relied up to be 64-bit aligned" This fixes an "unaligned 64-bit atomic operation" panic on 32-bit ARM, (in my case a Raspberry Pi 4, running 32-bit Raspbian). The panic happens (at least) during the first login after a service (re)start. --- .../unreleased/fix-unaligned-atomic-operation-on-arm32.md | 7 +++++++ ocis-pkg/sync/cache.go | 5 +++-- 2 files changed, 10 insertions(+), 2 deletions(-) create mode 100644 changelog/unreleased/fix-unaligned-atomic-operation-on-arm32.md diff --git a/changelog/unreleased/fix-unaligned-atomic-operation-on-arm32.md b/changelog/unreleased/fix-unaligned-atomic-operation-on-arm32.md new file mode 100644 index 0000000000..8ddbc2b5b2 --- /dev/null +++ b/changelog/unreleased/fix-unaligned-atomic-operation-on-arm32.md @@ -0,0 +1,7 @@ +Bugfix: Fixes "unaligned 64-bit atomic operation" panic on 32-bit ARM + +sync/cache had uint64s that were not 64-bit aligned causing panics +on 32-bit systems during atomic access + +https://github.com/owncloud/ocis/pull/1888 +https://github.com/owncloud/ocis/issues/1887 diff --git a/ocis-pkg/sync/cache.go b/ocis-pkg/sync/cache.go index 0ffddf56b7..e63690b35d 100644 --- a/ocis-pkg/sync/cache.go +++ b/ocis-pkg/sync/cache.go @@ -8,10 +8,11 @@ import ( // Cache is a barebones cache implementation. type Cache struct { + // capacity and length have to be the first words + // in order to be 64-aligned on 32-bit architectures. + capacity, length uint64 // access atomically entries sync.Map pool sync.Pool - capacity uint64 - length uint64 } // CacheEntry represents an entry on the cache. You can type assert on V.