-
Notifications
You must be signed in to change notification settings - Fork 385
Implement file read/write/seek in Windows #4275
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
base: master
Are you sure you want to change the base?
Conversation
@rustbot ready |
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.
Looks great overall, thanks! Just some minor comments. Nice to see that the blocking read/write API works for the Windows functions as well.
@rustbot author
Reminder, once the PR becomes ready for a review, use |
@CraftSpider what's the status of this? A standard library test started using |
There's a FIXME added in rust-lang/miri-test-libstd#96 that we can hopefully remove when this lands. |
I'll try to get this updated soon, I've just been doing other stuff - hopefully later today or tomorrow. |
This comment has been minimized.
This comment has been minimized.
81db8b2
to
e5b2f1e
Compare
(modulo tests passing) |
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.
Actually it seems there's one pretty big issue, see the comments regarding when the callback is called...
@rustbot author
// Return whether this was a success. 0 is a success. | ||
// We wrote the return status into the IO_STATUS_BLOCK in the above callback, | ||
// just pull it from there. |
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.
This doesn't work -- the entire reason that that's a callback is that desc.write
may block the current thread, return immediately, and run the callback later!
This function needs to take a dest
argument to capture the return place, pass that into the callback, and then write the return value that way.
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.
This took me a moment to get - for future reference when I'm fixing this: if the callback doesn't happen immediately, we will return the (possibly uninit) value that is in the IO_STATUS_BLOCK we were passed, then before the user code resumes, the callback will happen, write the value into IO_STATUS_BLOCK, then resume execution. We have to pass the return place into the callback to avoid that problem.
This is fairly obvious in retrospect, but it wasn't clear to me until I reread your comment a couple times.
src/shims/windows/fs.rs
Outdated
// See NtWriteFile for commentary on this | ||
interp_ok(this.read_scalar(&io_status)?) |
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.
Same here regarding the callback being potentially invoked later.
@@ -230,19 +230,11 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> { | |||
let stderr = this.eval_windows("c", "STD_ERROR_HANDLE").to_i32()?; | |||
|
|||
let fd_num = if which == stdin { |
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.
Please add a comment saying where those numbers come from. AFAIK those are the typical Unix numbers, right? Miri just happens to set them up always, even on Windows.
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.
Will do. And yeah, this is just taking advantage of the existing setup. The user won't even see these values directly, due to handle encoding.
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.
If we added support for SetStdHandle
, then we'd need to add state to track the current values of these handles. But since we don't support that, this will just only ever return these values. Adding such support is completely possible, but not really important for std
as far as I can tell.
I can split seek off if desired, though that means I can't enable the whole file read/write shim test in
fs.rs
in one go