-
Notifications
You must be signed in to change notification settings - Fork 352
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
freebsd interceptions update proposal #3143
Conversation
Thanks for the PR! However, new functions without tests are generally not a good idea. Why is the |
3995215
to
7b9fc06
Compare
let [thread, name] = | ||
this.check_shim(abi, Abi::C { unwind: false }, link_name, args)?; | ||
let max_len = usize::MAX; // freebsd does not seem to have a limit. | ||
let max_len = 20; // freebsd silently truncates to MAXCOMLEN (+ 1). |
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.
And MAXCOMLEN is 19 then, I assume?
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
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.
Is there somewhere you can link to that documents 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.
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, please add those links to the code. :)
tests/pass-dep/shims/pthreads.rs
Outdated
libc::pthread_set_name_np(libc::pthread_self(), name.as_ptr().cast()) | ||
}; | ||
#[cfg(target_os = "freebsd")] | ||
return 0; |
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.
Why do you make it return 0? With a too long name it should fail, no?
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.
pthread_set_name_np functions differently than Linux's. The only errno returned to userland is ESRCH
.
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.
That's not what you implemented though. In src/shims/unix/freebsd/foreign_items.rs you're returning errors the same way Linux would.
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 for the suggestions.
tests/pass-dep/shims/pthreads.rs
Outdated
#[cfg(target_os = "freebsd")] | ||
unsafe { | ||
libc::pthread_get_name_np(libc::pthread_self(), buf.as_mut_ptr().cast(), buf.len()) | ||
}; | ||
let cstr = CStr::from_bytes_until_nul(&buf).unwrap(); | ||
assert!(cstr.to_bytes().len() >= 15); // POSIX seems to promise at least 15 chars |
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 assertion fails. Does it also fail locally when you do ./miri run --target x86_64-unknown-freebsd tests/pass-dep/shims/pthreads.rs
? If yes then you have a shot at debugging this. Having the assert!
print the actual length on failure would probably be a good start.
assert!(cstr.to_bytes().len() >= 15); // POSIX seems to promise at least 15 chars | |
assert!(cstr.to_bytes().len() >= 15, "name is too short: len={}", cstr.to_bytes().len()); // POSIX seems to promise at least 15 chars |
let [thread, name] = | ||
this.check_shim(abi, Abi::C { unwind: false }, link_name, args)?; | ||
let max_len = usize::MAX; // freebsd does not seem to have a limit. | ||
let max_len = 20; // freebsd silently truncates to MAXCOMLEN (+ 1). | ||
let res = this.pthread_setname_np( | ||
this.read_scalar(thread)?, | ||
this.read_scalar(name)?, | ||
max_len, | ||
)?; | ||
this.write_scalar(res, dest)?; |
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'm very surprised that this does not explode. Something is weird. This function returns nothing, and here we are assuming it returns an i32
, so that should fail somewhere...
@@ -26,17 +26,29 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriInterpCxExt<'mir, 'tcx> { | |||
this.check_shim(abi, Abi::C { unwind: false }, link_name, args)?; | |||
this.write_null(dest)?; | |||
} | |||
"pthread_set_name_np" => { | |||
// Old vs new name | |||
"pthread_set_name_np" | "pthread_setname_np" => { |
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.
According to the manpage these are not the same, they have different return types. So the implementation will also have to be different, and both variants need to be tested.
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 fact I ll remove the new names for now and focus on the current ones, not even libc crate have them.
809057d
to
ab5ae00
Compare
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.
Sorry for the silence, I didn't realize this was ready for another round of review. Please don't just push and assume we'll get notified; github does not always send notifications for force pushes and it's never clear whether such a push is meant to resolve all prior discussions or whether more pushes will come.
@rustbot author
(write @rustbot review
when this is ready for review again)
@@ -26,16 +26,26 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriInterpCxExt<'mir, 'tcx> { | |||
this.check_shim(abi, Abi::C { unwind: false }, link_name, args)?; | |||
this.write_null(dest)?; | |||
} | |||
// Old vs new name |
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 comment seems outdated?
tests/pass-dep/shims/pthreads.rs
Outdated
test_mutex_libc_init_errorcheck(); | ||
#[cfg(not(target_os = "freebsd"))] | ||
test_rwlock_libc_static_initializer(); | ||
test_named_thread_truncation(); |
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.
test_named_thread_truncation(); | |
test_named_thread_truncation(); |
tests/pass-dep/shims/pthreads.rs
Outdated
unsafe { | ||
libc::pthread_set_name_np(libc::pthread_self(), name.as_ptr().cast()) | ||
}; | ||
#[cfg(target_os = "freebsd")] | ||
return 0; |
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.
unsafe { | |
libc::pthread_set_name_np(libc::pthread_self(), name.as_ptr().cast()) | |
}; | |
#[cfg(target_os = "freebsd")] | |
return 0; | |
unsafe { | |
libc::pthread_set_name_np(libc::pthread_self(), name.as_ptr().cast()); | |
// pthread_set_name_np does not return anything, just assume it went well. | |
return 0; | |
}; |
tests/pass-dep/shims/pthreads.rs
Outdated
let cstr = CStr::from_bytes_until_nul(&buf).unwrap(); | ||
assert!(cstr.to_bytes().len() >= 15); // POSIX seems to promise at least 15 chars | ||
assert!(cstr.to_bytes().len() >= 15, "name is too short: len={}", cstr.to_bytes().len()); // POSIX seems to promise at least 15 chars | ||
assert!(long_name.as_bytes().starts_with(cstr.to_bytes())); | ||
|
||
// Also test directly calling pthread_setname to check its return value. | ||
assert_eq!(set_thread_name(&cstr), 0); | ||
// But with a too long name it should fail. |
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.
// But with a too long name it should fail. | |
// But with a too long name it should fail (except on FreeBSD where the function | |
// has no return value and hence cannot indicate failure). |
2c6a1df
to
beacc3c
Compare
beacc3c
to
bc154db
Compare
@rustbot review |
Looking good, thanks! I just did some tweaks. @bors r+ |
freebsd interceptions update proposal
19933b9
to
195776b
Compare
@bors r+ |
@bors force |
☀️ Test successful - checks-actions |
No description provided.