Skip to content

[z/OS] Add call to shmctl() to release shared memory on z/OS #130163

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 7, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions llvm/include/llvm/ExecutionEngine/Orc/MemoryMapper.h
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,7 @@ class SharedMemoryMapper final : public MemoryMapper {
struct Reservation {
void *LocalAddr;
size_t Size;
int SharedMemoryId;
};

ExecutorProcessControl &EPC;
Expand Down
11 changes: 7 additions & 4 deletions llvm/lib/ExecutionEngine/Orc/MemoryMapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -220,10 +220,11 @@ void SharedMemoryMapper::reserve(size_t NumBytes,
OnReservedFunction OnReserved) {
#if (defined(LLVM_ON_UNIX) && !defined(__ANDROID__)) || defined(_WIN32)

int SharedMemoryId = -1;
EPC.callSPSWrapperAsync<
rt::SPSExecutorSharedMemoryMapperServiceReserveSignature>(
SAs.Reserve,
[this, NumBytes, OnReserved = std::move(OnReserved)](
[this, NumBytes, OnReserved = std::move(OnReserved), SharedMemoryId](
Error SerializationErr,
Expected<std::pair<ExecutorAddr, std::string>> Result) mutable {
if (SerializationErr) {
Expand All @@ -248,7 +249,7 @@ void SharedMemoryMapper::reserve(size_t NumBytes,
SharedMemoryName.size());
auto HashedName = BLAKE3::hash<sizeof(key_t)>(Data);
key_t Key = *reinterpret_cast<key_t *>(HashedName.data());
int SharedMemoryId =
SharedMemoryId =
shmget(Key, NumBytes, IPC_CREAT | __IPC_SHAREAS | 0700);
if (SharedMemoryId < 0) {
return OnReserved(errorCodeToError(
Expand Down Expand Up @@ -298,7 +299,8 @@ void SharedMemoryMapper::reserve(size_t NumBytes,
#endif
{
std::lock_guard<std::mutex> Lock(Mutex);
Reservations.insert({RemoteAddr, {LocalAddr, NumBytes}});
Reservations.insert(
{RemoteAddr, {LocalAddr, NumBytes, SharedMemoryId}});
}

OnReserved(ExecutorAddrRange(RemoteAddr, NumBytes));
Expand Down Expand Up @@ -396,7 +398,8 @@ void SharedMemoryMapper::release(ArrayRef<ExecutorAddr> Bases,
#if defined(LLVM_ON_UNIX)

#if defined(__MVS__)
if (shmdt(Reservations[Base].LocalAddr) < 0)
if (shmdt(Reservations[Base].LocalAddr) < 0 ||
shmctl(Reservations[Base].SharedMemoryId, IPC_RMID, NULL) < 0)
Err = joinErrors(std::move(Err), errorCodeToError(errnoAsErrorCode()));
#else
if (munmap(Reservations[Base].LocalAddr, Reservations[Base].Size) != 0)
Expand Down