Skip to content
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

Changes for managarm cancelable syscalls #884

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

Geertiebear
Copy link
Member

Since the changes are incomplete and a little unstable, marking it as draft right now.

@@ -60,31 +60,42 @@ int sys_waitpid(pid_t pid, int *status, int flags, struct rusage *ru, pid_t *ret
return ENOSYS;
}

SignalGuard sguard;
//SignalGuard sguard;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Leftover I guess.

HEL_CHECK(recv_resp.error());

managarm::posix::SvrResponse<MemoryAllocator> resp(getSysdepsAllocator());
resp.ParseFromArray(recv_resp.data(), recv_resp.length());
if(resp.error() == managarm::posix::Errors::ILLEGAL_ARGUMENTS) {
return EINVAL;
}
if (resp.error() == managarm::posix::Errors::INTERRUPTED) {
mlibc::infoLogger() << "returning EINT" << frg::endlog;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we put this behind some debug flag?

@Geertiebear
Copy link
Member Author

Yeah there are quite some debug logs left currently 😅

Copy link
Member

@ElectrodeYT ElectrodeYT left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

I do have a question, since this is not instantly obvious to me: would this code work without the changes in managarm, or are we looking at circular dependencies here? To my knowledge, merging in the managarm side first would result in some weird behavior.

@@ -1,3 +1,4 @@
#include "mlibc/debug.hpp"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this LSP? In any case, this should be replaced with <>

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, this should be <>.

@Geertiebear Geertiebear marked this pull request as ready for review December 24, 2024 14:47
@@ -1,3 +1,4 @@
#include "mlibc/debug.hpp"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, this should be <>.

Comment on lines +321 to +325
auto element = globalQueue.dequeueSingle(false);
if (!element) {
element = globalQueue.dequeueSingle();
__ensure(element);
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the only call where we pass false to dequeueSingle() (AFAICT) and we immediately call into dequeueSingle() again. So what is the difference compared to just doing dequeueSingle(true) here?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note we use protocol errors to signify cancellation (e.g., in read() you check for managarm::fs::Errors::INTERRUPTED), so maybe the ignoreCancel = false case is not necessary (and we can always re-try if helFutexWait is interrupted)?

Comment on lines -151 to +154
auto result = parseSimple(element);
if (!element) {
return EINTR;
}
auto result = parseSimple(*element);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We have this change for sleep but AFAICT sleep() is still not cancelable since we don't integrate it with the cancellation event. We could drop support for sleep() in the initial PR.

@@ -1628,12 +1629,14 @@ int sys_mknodat(int dirfd, const char *path, int mode, int dev) {
}

int sys_read(int fd, void *data, size_t max_size, ssize_t *bytes_read) {
SignalGuard sguard;
Copy link
Member

@avdgrinten avdgrinten Dec 30, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do we need to do this?

This prevents a signal to be raised (= posix-subsystem won't jump to the signal handler), but it should not prevent POSIX from interrupting the thread. I think we still want to keep this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants