miri icon indicating copy to clipboard operation
miri copied to clipboard

Test the interactions of O_APPEND and seek + write/read/pwrite/pread

Open RalfJung opened this issue 3 weeks ago • 3 comments

Apparently that interaction is far from obvious: does it use an explicitly set file cursor position or always write at the end? The docs seem to say that the file cursor position should be entirely ignored. What about reads? What about pwrite? There, apparently the position should matter, but we implement it via seek + write, which may ignore the position. We're likely getting this wrong at the moment.

Also Linux has bugs here where pwrite ignores the position. We're not going to try to emulate the bug, but we should be aware of it while testing.

Also see https://github.com/rust-lang/rust/pull/143166 -- though when I am talking about tests above I mean direct libc tests, so what std does is not super relevant to us.

RalfJung avatar Nov 11 '26 11:11 RalfJung

We could handle O_APPEND with seek(End) + write() to avoid the pwrite issue, though that would introduce a race if another host process writes to the same file in between. I'm curious whether we'd want to preserve that atomicity as well, or if Miri's sequential execution is enough for this case?

darkraider01 avatar Nov 11 '26 13:11 darkraider01

Given that there could be concurrent modification of the same file from outside Miri, we should do our best to make this race-free. We do sometimes accept race conditions, but the other ones we have I think can only lead to strange errors, not to data corruption.

RalfJung avatar Nov 11 '26 17:11 RalfJung

Got it!!! We probably don't want to risk corrupting external writes just to fix pwrite. I'll look into whether there's a way to handle positioned writes separately without losing the host's append atomicity. @rustbot claim

darkraider01 avatar Nov 11 '26 17:11 darkraider01