From b9b3aadbd4aab0f9325d2aa9bb6e40561d999c96 Mon Sep 17 00:00:00 2001 From: Elliot Saba Date: Thu, 30 Dec 2021 16:42:26 -0800 Subject: [PATCH] Change `shm_open()` calling ABI on aarch64 Darwin (#43516) Beacuse `shm_open()` is a variadic function, if we don't declare it as such, the kernel receives trash as the `permissions` value, which occasionally results in errors when creating shared memory segments. This did not happen on `x86_64` because the calling convention doesn't change so much between variadic and non-vadiadic functions. --- stdlib/SharedArrays/src/SharedArrays.jl | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/stdlib/SharedArrays/src/SharedArrays.jl b/stdlib/SharedArrays/src/SharedArrays.jl index 1348a68dca9571..a961be4e534b36 100644 --- a/stdlib/SharedArrays/src/SharedArrays.jl +++ b/stdlib/SharedArrays/src/SharedArrays.jl @@ -693,9 +693,15 @@ function _shm_mmap_array(T, dims, shm_seg_name, mode) end shm_unlink(shm_seg_name) = ccall(:shm_unlink, Cint, (Cstring,), shm_seg_name) -shm_open(shm_seg_name, oflags, permissions) = ccall(:shm_open, Cint, - (Cstring, Cint, Base.Cmode_t), shm_seg_name, oflags, permissions) - +function shm_open(shm_seg_name, oflags, permissions) + # On macOS, `shm_open()` is a variadic function, so to properly match + # calling ABI, we must declare our arguments as variadic as well. + @static if Sys.isapple() + return ccall(:shm_open, Cint, (Cstring, Cint, Base.Cmode_t...), shm_seg_name, oflags, permissions) + else + return ccall(:shm_open, Cint, (Cstring, Cint, Base.Cmode_t), shm_seg_name, oflags, permissions) + end +end end # os-test end # module