Skip to content

Commit

Permalink
sysdeps/managarm: store cancelEvent in shared memory page
Browse files Browse the repository at this point in the history
  • Loading branch information
Geertiebear committed Dec 15, 2024
1 parent 4ab4cf1 commit ac7c83e
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
7 changes: 7 additions & 0 deletions sysdeps/managarm/generic/entry.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ namespace {
thread_local unsigned __mlibc_gsf_nesting;
thread_local void *__mlibc_cached_thread_page;
thread_local HelHandle *cachedFileTable;
thread_local HelHandle *cancelEvent;

// This construction is a bit weird: Even though the variables above
// are thread_local we still protect their initialization with a pthread_once_t
Expand All @@ -46,6 +47,7 @@ namespace {
__mlibc_cached_thread_page = data.threadPage;
cachedFileTable = data.fileTable;
__mlibc_clk_tracker_page = data.clockTrackerPage;
cancelEvent = data.cancelRequestEvent;
}
}

Expand Down Expand Up @@ -103,6 +105,11 @@ HelHandle getHandleForFd(int fd) {
return cacheFileTable()[fd];
}

void setCurrentRequestEvent(HelHandle event) {
pthread_once(&has_cached_infos, &actuallyCacheInfos);
__atomic_store_n(cancelEvent, event, __ATOMIC_RELEASE);
}

void clearCachedInfos() {
has_cached_infos = PTHREAD_ONCE_INIT;
}
Expand Down
5 changes: 4 additions & 1 deletion sysdeps/managarm/include/mlibc/posix-pipe.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -292,6 +292,7 @@ inline HelHandleResult *parseHandle(ElementHandle &element) {
HelHandle getPosixLane();
HelHandle *cacheFileTable();
HelHandle getHandleForFd(int fd);
void setCurrentRequestEvent(HelHandle event);
void clearCachedInfos();

extern thread_local Queue globalQueue;
Expand Down Expand Up @@ -324,12 +325,12 @@ auto exchangeMsgsSyncCancellable(HelHandle descriptor, HelHandle event,
auto results = helix_ng::createResultsTuple(args...);
auto actions = helix_ng::chainActionArrays(args...);

setCurrentRequestEvent(event);
HEL_CHECK(helSubmitAsync(descriptor, actions.data(),
actions.size(), globalQueue.getQueue(), 0, 0));

auto element = globalQueue.dequeueSingle(false);
if (!element) {
HEL_CHECK(helRaiseEvent(event));
element = globalQueue.dequeueSingle();
__ensure(element);
}
Expand All @@ -339,6 +340,8 @@ auto exchangeMsgsSyncCancellable(HelHandle descriptor, HelHandle event,
(results.template get<p>().parse(ptr, *element), ...);
} (std::make_index_sequence<std::tuple_size_v<decltype(results)>>{});

setCurrentRequestEvent(kHelNullHandle);

return results;
}

Expand Down

0 comments on commit ac7c83e

Please sign in to comment.