-
Notifications
You must be signed in to change notification settings - Fork 356
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
Add _umtx_op
shim to freebsd
#2321
Conversation
This comment was marked as off-topic.
This comment was marked as off-topic.
This comment was marked as off-topic.
This comment was marked as off-topic.
This comment was marked as off-topic.
This comment was marked as off-topic.
This comment was marked as off-topic.
This comment was marked as off-topic.
This comment was marked as off-topic.
This comment was marked as off-topic.
sure, how could we do that? |
I opened #2324 for that |
This MR is ready for reviews |
f2982b4
to
14cfe9f
Compare
src/shims/unix/freebsd/futex.rs
Outdated
uaddr: &OpTy<'tcx, Tag>, | ||
uaddr2: &OpTy<'tcx, Tag>, |
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.
Use the Pointer
type for these two and move the conversion to the caller
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 couldn't make that work, I've posted about it on zulip
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.
ok, they are unused for now anyway, so let's just ignore them (keep OpTy and we'll see about them once they are used)
src/shims/unix/freebsd/futex.rs
Outdated
// The `val` value is invalid. Double check this against the manual. | ||
let einval = this.eval_libc("EINVAL").ok()?; | ||
this.set_last_error(einval).ok()?; | ||
None |
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 seems wrong. https://man7.org/linux/man-pages/man2/futex.2.html suggests that this is not an error case:
This operation tests that the value at the futex word
pointed to by the address uaddr still contains the
expected value val, and if so, then sleeps waiting for a
FUTEX_WAKE operation on the futex word.
If the futex value does not match val, then the call fails
immediately with the error EAGAIN.
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.
https://helpmanual.io/man2/_umtx_op-freebsd/ says
The current value of the variable pointed to by the Fa obj argument is compared with the Fa val . If they are equal, the requesting thread is put to interruptible sleep until woken up or the optionally specified timeout expires.
and does not say what happens if the value differs.
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 seems wrong. man7.org/linux/man-pages/man2/futex.2.html suggests that this is not an error case:
This operation tests that the value at the futex word
pointed to by the address uaddr still contains the
expected value val, and if so, then sleeps waiting for a
FUTEX_WAKE operation on the futex word.If the futex value does not match val, then the call fails
immediately with the error EAGAIN.
You seem to be looking at the linux futex
function, not the freebsd _umtx_op function
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, but the freebsd function does not document what happens if the value differs either. I guess erroring out is the safe thing to do and we can address this if it becomes a problem.
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, but the freebsd function does not document what happens if the value differs either. I guess erroring out is the safe thing to do and we can address this if it becomes a problem.
we do sort of error out, just with a different code
src/shims/unix/freebsd/futex.rs
Outdated
Ok(op) => | ||
match op { | ||
OpType::UmtxOpWait => | ||
if this.read_scalar(obj).ok()?.to_u64().ok()? == val { |
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 you want to deref_operand
first, otherwise you're comparing the pointer address with val
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.
Also I don't know what Pointer to a variable of type Vt long .
in the man pages means, could this be a pointer to a 32 bit value on 32 bit platforms?
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.
Also I don't know what
Pointer to a variable of type Vt long .
in the man pages means, could this be a pointer to a 32 bit value on 32 bit platforms?
I'm not entirely sure, I'll search around
ci.sh
Outdated
@@ -60,7 +60,7 @@ case $HOST_TARGET in | |||
MIRI_TEST_TARGET=i686-unknown-linux-gnu run_tests | |||
MIRI_TEST_TARGET=aarch64-apple-darwin run_tests | |||
MIRI_TEST_TARGET=i686-pc-windows-msvc run_tests | |||
MIRI_TEST_TARGET=x86_64-unknown-freebsd run_tests_minimal hello integer vec current_dir data_race env | |||
MIRI_TEST_TARGET=x86_64-unknown-freebsd run_tests_minimal hello integer vec current_dir data_race env concurrent-panic |
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 this adds support for futexes, shouldn't there be a lot more tests that work now?
concurrent-panic is an awfully specific test to check. It's not really about concurrency at all. Which part of the Rust stdlib uses _umtx_op that is called by concurrent-panic? AFAIK it uses an RwLock, is that where it comes from?
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.
Answering my own question, it's in condvar.
Specifically I don't think this will give us good test coverage for the new operation, that's why we also want some other tests. At least sync
should be added, I think. If those all pass, that gives me higher confidence that the implementation is correct.
} | ||
} | ||
|
||
struct Futex<'mir, 'tcx> {} |
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.
What is the point of this type? Please add a doc comment.
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.
What is the point of this type? Please add a doc comment.
This is just here to be able to bound an implementation
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.
In that case please remove it and follow the extension trait pattern that all the other files are using.
pub fn futex<'tcx>( | ||
this: &mut MiriEvalContext<'_, 'tcx>, | ||
// Object to operate on | ||
obj: &OpTy<'tcx, Tag>, |
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.
All the other arguments are already interpreted at some Rust type; please do the same with this one. The comment seems to indicate it's a pointer, so then this should have type Pointer<Option<Tag>>
.
use crate::InterpResult; | ||
use crate::OpTy; | ||
use crate::{MiriEvalContext, Tag}; | ||
use std::fmt::Pointer; |
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.
You do not want to import this trait here. It's the wrong Pointer
.^^
Best to start by copy-pasting the header from some other file. I think you can replace all your imports here by use crate::*;
which is what we have in most files.
this.futex_wait( | ||
this.read_scalar(obj)?.to_machine_usize()?, | ||
this.get_active_thread(), | ||
u32::MAX, |
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.
u32::MAX, | |
u32::MAX, // we set the bitset to include all bits |
I am not planning to continue on adding support to freebsd, having lost interest to code in rust (and therefore not wanting to do more on the related rust-lang projects) |
@InfRandomness that's a bummer. Anyway thanks for the work you did; adding new Unix targets is now easier than it used to be! :) |
This fixes the `concurrent-panic.rs` test on freebsd Signed-off-by: InfRandomness <infrandomness@gmail.com>
Signed-off-by: InfRandomness <infrandomness@gmail.com>
- Changes return type of futex() to InterpResult<'tcx> and removes every ok() calls - Add documentation and link to `_umtx_op` man pages - Move comments to parameters and remove pointless assignments - Replace `OpTy`s usages to `Pointer`s - Run `deref_operand` on `read_scalar` output in Futex wait operation - Replace `to_u64` to `to_machine_usize` Signed-off-by: InfRandomness <infrandomness@gmail.com>
There hasn't been any activity here for 4 months, so I am going to close this PR. @InfRandomness or anyone else who is interested, feel free to pick this up again in the future if/when you have time! |
This fixes the
concurrent-panic.rs
test on freebsdSigned-off-by: InfRandomness infrandomness@gmail.com