Skip to content

Commit

Permalink
Change shm_open() calling ABI on aarch64 Darwin (JuliaLang#43516)
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 authored and LilithHafner committed Feb 22, 2022
1 parent 53ba2d9 commit e994ff8
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)
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 e994ff8

Please sign in to comment.