Skip to content

Commit

Permalink
Change shm_open() calling ABI on aarch64 Darwin
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
staticfloat committed Dec 15, 2021
1 parent f6b65ca commit bca1504
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions stdlib/SharedArrays/src/SharedArrays.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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)

This comment has been minimized.

Copy link
@KristofferC

KristofferC Dec 19, 2021

Member

I thought you needed @ccall for variadic arguments and that it wasn't supported with the non-macro version. Might be wrong...

This comment has been minimized.

Copy link
@yuyichao

yuyichao Dec 19, 2021

Contributor

No, the old ccall already support varadic arguments. It just have no way to express varadic arguments of non-uniform types.

This comment has been minimized.

Copy link
@KristofferC

KristofferC Dec 19, 2021

Member

Ah, ok, that was the difference. Thanks.

else
return ccall(:shm_open, Cint, (Cstring, Cint, Base.Cmode_t), shm_seg_name, oflags, permissions)
end
end
end # os-test

end # module

0 comments on commit bca1504

Please sign in to comment.