Testing shared memory on linux and macos with Rust and C and Assembly.
- memory accesses that are aligned to their access size are guaranteed to be atomic
- atomics implemented using lock cmpxchg and lock xchg for unaligned accesses
- ldrexd/strexd faults if the base register is not 8 byte aligned
- ldrex/strex (? alignment restrictions)
- atomics implemented using load/store exclusives
- ldxr/stxr (? alignment restrictions)
- atomics implemented using load/store exclusives
cargo runto setup shared memory- compile and run writer.c to write to shared memory
- for some strange reason
nasmdoes not export the global symbols, so the atomics are written for theasassembler instead ofnasm
cargo runto setup shared memory- compile and run writer.c to write to shared memory
cargo runto setup shared memory- compile and run writer.c to write to shared memory
cargo runto setup shared memory- compile and run writer.c to write to shared memory
- strangely running writer.c and attempting to access shared memory fails with Permission Denied, but works fine when run using
sudo
- strangely running writer.c and attempting to access shared memory fails with Permission Denied, but works fine when run using
- symbols exported from assembly must have
_prefixed to them, a quirk of macos - when building a static library use the
arprovided by the system, otherwise linking will fail with the unhelpful errorbuilding for macOS-arm64 but attempting to link with file built for macOS-arm64
- compile the assembler files using
as - generate a static library using
ar - library file names must always start with lib
example assembler file tmp.s
as tmp.s -o tmp.o
ar -rcs libtmp.a tmp.o