add NetBSD shims#5109
Conversation
| "getentropy" => { | ||
| // This function is non-standard but exists with the same signature and behavior on | ||
| // Linux, macOS, FreeBSD and Solaris/Illumos. | ||
| // This function is in the POSIX standard, but does not exist |
There was a problem hiding this comment.
| "readdir_r" | "readdir_r$INODE64" => { | ||
| let [dirp, entry, result] = | ||
| this.check_shim_sig_lenient(abi, CanonAbi::C, link_name, args)?; | ||
| let result = this.macos_readdir_r(dirp, entry, result)?; | ||
| this.write_scalar(result, dest)?; | ||
| } |
There was a problem hiding this comment.
Moved to the shared UNIX match.
| this.check_alias_used_on( | ||
| "__posix_getpwuid_r", | ||
| &[Os::Illumos, Os::Solaris], | ||
| link_name, | ||
| )?; |
There was a problem hiding this comment.
The helper exists now, so we might as well use it for Illumos and Solaris too.
|
Thanks for the PR! Please also add a netbsd job to Also, 500 lines is pretty big as PRs go. If this can be split up into multiple PRs, that would simplify review. |
| "unsetenv" | "__unsetenv13" => { | ||
| this.check_alias_used_on("__unsetenv13", &[Os::NetBsd], link_name)?; |
There was a problem hiding this comment.
Please move the __unsetenv13 case into the netbsd module. That matches how we handle the same situation on macOS / freeBSD.
There was a problem hiding this comment.
Are you sure? The unversioned function has different semantics on NetBSD, it returns void instead of int, so if someone accidentally messes up their function definition and calls it, that's UB, and miri can easily catch that. And additionally, there are versioned functions in this shared match already, so it's not like there isn't any precedent.
|
@joboet First of all, thanks for working on this, truly appreciated 👍 I don't really know if you expect anything from me or @he32 but, I've just tried a local test build on bare metal. Do let me know if you would like further support. For now, here's what I get: Do I need nightly to compile this? If it matters: |
|
@0323pin there's no specific ask, I just wanted you to be aware of this 😊. Also note that this is about interpreting with NetBSD as a target, not about using NetBSD as a host for miri. Though I'm unsurprised that |
|
@RalfJung sure thing, I'll split this up. PRs: |
NetBSD is a very useful test target for
std, since itCondvarimplementation that I want to eventually merge (c.f. std: use a queue-basedCondvaron NetBSD and other platforms rust#127578)and at the same time it is a UNIX system and can share most of the existing shims. Hence it'd be very useful for miri to support it. I'm willing to serve as target maintainer, though I should point out that I'm not involved with the platform otherwise.
Most of the changes necessary involve symbol names, which NetBSD uses for versioning. I've added a small
check_alias_used_onhelper that ensures that the alias is always and only used on the given platforms.As for the NetBSD specific shims, there are two interesting cases:
pthread_setname_npweirdly usesprintflike formatting, but with only a single argument. To avoid having to shim the entireprintfinfrastructure, the current version only supports a%sformat string since that's the only thing uses bystd._lwp_parkand_lwp_unparkpresent a new kind of synchronisation API to miri. Their semantics are pretty much identical to thethread::parkandThread::unparkfunction and method in the standard library.Currently, all test pass with the exception of two test that utilise
thread::park_timeout– those report undefined behaviour withinstd. This is not caused by the_lwp_parkshim but rather an incorrect definition of_lwp_parkinlibc, which acts together with the implicit immutable reborrow inserted by stacked borrows when coercing a mutable reference to an immutable pointer to cause unsoundness insidestd(c.f. rust-lang/libc#5169). I went ahead and added this to the trophy shelf...