-
Notifications
You must be signed in to change notification settings - Fork 417
Implement SetFileInformationByHandle, as well as direct shim test for it #4547
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
|
Thank you for contributing to Miri! |
This comment has been minimized.
This comment has been minimized.
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.
Thanks!
|
@rustbot author There's also a conflict that prevents CI from running, so please rebase to resolve that. |
|
Reminder, once the PR becomes ready for a review, use |
749eede to
e9b084e
Compare
|
This PR was rebased onto a different master commit. Here's a range-diff highlighting what actually changed. Rebasing is a normal part of keeping PRs up to date, so no action is needed—this note is just to help reviewers. |
|
@rustbot ready Still pending CI, but rebased and responded to review (finally) |
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.
Thanks! Unfortunately there's some new code which causes confusion, probably due to my complete lack of understanding of Windows APIs. ;)
| } else if class == this.eval_windows_u32("c", "FileAllocationInfo") { | ||
| // File allocation size is independent of file EOF position on Windows, except that | ||
| // EOF must be <= allocation size. So we only do something if the file is bigger than | ||
| // the requested allocation size. |
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 in other words, we don't grow, we only shrink? I don't understand what that has to do with "EOF position" vs "allocation size". I also don't know what those terms even mean. ;)
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.
EOF position is the file's length. Allocation size is generally a multiple of the underlying storage's sector size, and is effectively the file's pre-allocated capacity before writing will have to map more physical storage.
Rust std doesn't expose this cross-platform, and we don't support it in GetFileInformationByHandle, so the only observable side effect of setting it is truncating length to be less than capacity.
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.
Okay. I have made a suggestion for updating the comment.
However, I am a bit concerned about just silently doing nothing for the other case, where the allocation size is grown beyond the EOF position. Can't that break stuff? Or is it okay to consider this more of a hint, in some sense?
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.
I think this is okay to consider as a hint.
- Extra allocation beyond file size is automatically freed when the last HANDLE to a file is closed
- Programs should be resilient to different cluster allocation sizes, since it's configurable.
- A quick look through the first couple pages of a GitHub search shows mostly uses to set a file size to 0, and a couple uses to pre-allocate space solely for write efficiency.
- I think we could emulate it with a side map tracking a HANDLE's allocation size, updated on writes beyond it, if we need to. This may be worth it if we want/need to support
GetFileInformationByHandlefor allocation size.
@ChrisDenton, I know you're familiar with Windows, so I'd appreciate your thoughts. Is this value guaranteed observable in other ways that I'm not finding it my search?
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.
Yes, that sounds right. Its intended use is as a performance optimisation. It's similar to Vec::with_capacity in that you can reserve some space upfront then write into it later. It's not really observable outside of directly querying it. And of course write performance if your writes would have otherwise triggered the allocation to grow.
| file_information, | ||
| this.windows_ty_layout("FILE_END_OF_FILE_INFO"), | ||
| )?; | ||
| let ptr = this |
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.
It is somewhat odd to call this a ptr when it is not a Pointer, unlike file_information which is a Pointer but not called ptr. ;)
Name suggestions: place, file_information.
| interp_ok(this.eval_windows("c", "FALSE")) | ||
| } | ||
| } | ||
| } else if class == this.eval_windows_u32("c", "FileAllocationInfo") { |
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 have a direct test.
| // File allocation size is independent of file EOF position on Windows, except that | ||
| // EOF must be <= allocation size. So we only do something if the file is bigger than | ||
| // the requested allocation size. |
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, is this correct?
| // File allocation size is independent of file EOF position on Windows, except that | |
| // EOF must be <= allocation size. So we only do something if the file is bigger than | |
| // the requested allocation size. | |
| // File allocation size is independent of file EOF position (i.e. the length of the file | |
| // contents, which can be changed with set_len) on Windows, | |
| // except that EOF must be <= allocation size. This means that | |
| // *growing* the allocation size cannot be implemented or observed with std APIs. | |
| // Shrinking the allocation size below EOF length however truncates the file, | |
| // which is visible -- so that's the only case in which we do anything. |
Fixes #4483