-
Notifications
You must be signed in to change notification settings - Fork 3.4k
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
Fix dup
syscalls so that they handle pipes correctly
#14808
Conversation
How does this overlap with: #9396? |
Looks to me like #9396 also solves this problem. |
Would be good to at least add a test case for |
It would be nice to get a fix for this merged. I think when Pyodide is updated to use emscripten v3.1.6 the only remaining patch we will need is something to fix this problem. |
112b92b
to
6710c0c
Compare
Looks like a lot of dup related tests are failing. |
This fixes two problems with the `dup` system calls: 1. `dup` expects that every file descriptor has a corresponding file (so pipes and (emscripten-core#14640) files that have been unlinked (emscripten-core#15012) cannot be duplicated ). 2. The dup'd file descriptor does not share flags and position with the original file desciptor. This is a simplification of an upstream pull request that would fix this problem. https://github.com/emscripten-core/emscripten/pull/9396/files This patch is simpler than the upstream one but leaves NODERAWFS broken.
6710c0c
to
aa62950
Compare
Maybe I fixed it? I guess |
Good call... I guess we should just inline that function now. Do you want to send or PR for that? (if not I can do it). |
Do you know how to run the failing tests to debug them? (See https://emscripten.org/docs/getting_started/test-suite.html) |
I can do it, in this PR or you want a different one? |
I think it would make sense as its own PR to land before this one |
I'm trying to figure out even what isn't working on main. I'm getting test failures in Pyodide without this in |
It could be that our tests just need to be updated. Some of the tests support WASMFS as well as the legacy filesystem (the thing you are changing in this PR). It could be that the failing tests have an '#ifdef WASMFS` in there, that could be removed? |
Okay here's an example of a test that would pick up the bug: int main() {
int p[2];
pipe(p);
g = dup2(p[0], 7);
write(p[1], "abc", 3);
char buf[5];
read(g, buf, 5);
printf("buf: %s\n", buf); // should print "buf: abc\n" but it prints "buf: \n".
return 0;
} |
But it seems like there might be an additional bug now that's a regression since 2.0.16 because it does |
I think the issue it not lack of testing of the bug but the breakage of existing tests by this change. Adding to one of the existing tests would be nice too, but first they need to pass |
I think I fixed the test failures though, can you trigger the CI? |
Oh it's just waiting on build-linux. |
Great... sorry i didn't understand that. |
Guess not hmm. I must have made a mistake when I ran the tests locally... |
Okay now it should work. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So all
@sbc100 Could you look into the current test failure? When I try to compile and run the the |
I think its probably just a flake.. i restarted that test runner |
dup
syscalls so that they handle pipes correctly
I think this is looking good now. But I also think we do need to add some new testing. IIRC there might be some tests that are currently disabled .. taking a look. |
It looks like we have two
Currently the later is a lot more extensive and only runs under WASMFS due to current limitations. Some of those limitations seem to have been addressed by this PR (its fails in fewer places with patch applies). I think to land this PR we should add to the existing |
Yeah good thing we added the test since the patch was still slightly wrong. |
+1 for both of these. |
Does this need anything else? I think it's ready to merge? |
Looks good to me, thanks, landing. |
It looks like this is causing errors on our roller, Specifically
I would guess the NODERAWFS changes here are causing that. It looks like we missed this on CI here because the test is skipped:
That is, CI here runs as root I guess, while the chromium roller does not, so it can run an additional test, which failed. Given that, I think you should be able to reproduce this locally in order to debug it @hoodmane ? |
Yup reproduces locally. |
Is there an easy way to make the test runner print out the compiler invocations it is using? |
@hoodmane passing Doing See also notes here for saving temp files https://emscripten.org/docs/getting_started/test-suite.html#debugging-test-failures |
`refcnt` (and not `refcnf`) needs to be initialized by 1 when creating the filestream. Also, apply emscripten-core#16661 to the other `FS.createStream` invocations as well.
These arguments used to be used in `__syscall_pipe` and `__syscall_dup` but were replaced with calls to createStream in #14808.
These arguments used to be used in `__syscall_pipe` and `__syscall_dup` but were replaced with calls to createStream in #14808.
library_syscall
duplicates things withvar newStream = FS.open(stream.path, stream.flags, 0, arg);
This doesn't work for pipes because in that casestream.path
is e.g.,pipe[1]
and thenFS.open
raises an error because this is an invalid path.I changed
SYSCALL.doDup
so that it no longer closes the target pipe because this logic makes sense fordup2
anddup3
but not fordup
orfcntl
F_DUPFD
which don't close the target pipe. So nowdoDup
takes a file stream and an inclusive range of file descriptors (like the last two arguments ofcreateStream
). NowdoDup
also checks if the stream is a pipe, in which case it increments the pipe refcount and usescreateStream
to duplicate the pipe.