Skip to content
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

illumos support #3198

Merged
merged 1 commit into from
May 5, 2024
Merged

illumos support #3198

merged 1 commit into from
May 5, 2024

Conversation

devnexen
Copy link
Contributor

@devnexen devnexen commented Dec 1, 2023

No description provided.

@devnexen devnexen force-pushed the solarish_support branch 12 times, most recently from 8139798 to 92f989c Compare December 3, 2023 12:42
@bors
Copy link
Contributor

bors commented Jan 7, 2024

☔ The latest upstream changes (presumably #3260) made this pull request unmergeable. Please resolve the merge conflicts.

@RalfJung RalfJung added the S-waiting-on-author Status: Waiting for the PR author to address review comments label Feb 10, 2024
@RalfJung
Copy link
Member

@devnexen what is the status of this PR? You opened it as a draft, so I assume you are not currently looking for feedback. If you don't plan to work on it in the near future, it'd be better to close the PR -- this way the open PRs reflect things that people are actively working on. We can always reopen when you have time to get back to this!

@devnexen devnexen marked this pull request as ready for review March 4, 2024 19:24
@bors
Copy link
Contributor

bors commented Mar 31, 2024

☔ The latest upstream changes (presumably #3436) made this pull request unmergeable. Please resolve the merge conflicts.

@RalfJung
Copy link
Member

RalfJung commented May 4, 2024

marked this pull request as ready for review

Was this meant to ask for review? Github doesn't seem to send notifications on this event, so I missed this -- sorry. In the future, please just post a comment when a PR is ready. You can write @rustbot ready to automatically update the labels as well.

Copy link
Member

@RalfJung RalfJung left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The code mostly looks good, but is lacking test coverage.

Also, it will need a rebase to resolve conflicts.

src/shims/unix/solarish/foreign_items.rs Outdated Show resolved Hide resolved
ci/ci.sh Outdated Show resolved Hide resolved
@RalfJung
Copy link
Member

RalfJung commented May 4, 2024

Also, after rebasing, please add solaris/illumos to the unofficial target list in the README and set yourself as maintainer.

@devnexen devnexen force-pushed the solarish_support branch 3 times, most recently from b937325 to f7cab83 Compare May 4, 2024 13:05
ci/ci.sh Outdated Show resolved Hide resolved
@RalfJung
Copy link
Member

RalfJung commented May 4, 2024

Looks like something changed in std, and pthread_condattr_init is now required to make it into main.

@RalfJung
Copy link
Member

RalfJung commented May 4, 2024

Looks like something changed in std, and pthread_condattr_init is now required to make it into main.

Or, rather, previously only no_std was tested so the pre-main code was not even executed.

I think the PR should be adjusted to add only what is needed for main. getentropy, getrandom, threadname... those are all nice things to have eventually, but we have to walk before we can run.

The goal should be for MIRI_TEST_TARGET=x86_64-unknown-illumos ./miri test vec to pass.

@devnexen devnexen force-pushed the solarish_support branch from f7cab83 to 1fe8529 Compare May 4, 2024 14:57
@devnexen
Copy link
Contributor Author

devnexen commented May 4, 2024

Looks like something changed in std, and pthread_condattr_init is now required to make it into main.

Do I need to implement something in particular to fix the out-of-bounds issue ?

@RalfJung
Copy link
Member

RalfJung commented May 4, 2024

That looks like the pthread offsets don't work for Solarish.

This seems to be a mutex, so this is the relevant comment:

// pthread_mutex_t is between 24 and 48 bytes, depending on the platform.
// Our chosen memory layout for the emulated mutex (does not have to match the platform layout!):
// bytes 0-3: reserved for signature on macOS
// (need to avoid this because it is set by static initializer macros)
// bytes 4-7: mutex id as u32 or 0 if id is not assigned yet.
// bytes 12-15 or 16-19 (depending on platform): mutex kind, as an i32
// (the kind has to be at its offset for compatibility with static initializer macros)

It looks like something else is writing to the field that Miri uses to store the MutexId, and then Miri doesn't deal well with the invalid MutexId.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you are keeping this diff, please also add libc-misc to CI.

But probably it's better to drop this diff for now, and focus on the core that's needed to get started.

@devnexen devnexen force-pushed the solarish_support branch 2 times, most recently from e8d742b to 0309159 Compare May 4, 2024 19:34
@devnexen devnexen force-pushed the solarish_support branch from 0309159 to dbfa382 Compare May 4, 2024 20:31
@RalfJung
Copy link
Member

RalfJung commented May 4, 2024

Almost there. :) There's something wrong with the signature of pthread_join... I assume pthread_t has a different size on this platform than on others. We usually assume it is usize, but on Solarish it is u32.

So here

let thread_id = this.read_target_usize(thread)?;

you need to use something like this instead

let thread_id = this.read_scalar(thread)?.to_int(this.libc_ty_layout("pthread_t").size)?;

@RalfJung
Copy link
Member

RalfJung commented May 4, 2024

Also, is it possible there's something wrong with your system clock? Your commits show up as coming 20-50minutes from the future...^^

@devnexen devnexen force-pushed the solarish_support branch 6 times, most recently from 9e147d0 to 670e66e Compare May 4, 2024 22:01
Copy link
Member

@RalfJung RalfJung left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! This looks good, apart from a few nits. Why is it still marked WIP? :)

@@ -146,6 +146,7 @@ case $HOST_TARGET in
MIRI_TEST_TARGET=x86_64-unknown-freebsd run_tests_minimal $BASIC panic/panic concurrency/simple atomic threadname libc-getentropy libc-getrandom libc-misc fs env num_cpus
MIRI_TEST_TARGET=i686-unknown-freebsd run_tests_minimal $BASIC panic/panic concurrency/simple atomic threadname libc-getentropy libc-getrandom libc-misc fs env num_cpus
MIRI_TEST_TARGET=aarch64-linux-android run_tests_minimal $VERY_BASIC hello panic/panic
MIRI_TEST_TARGET=x86_64-unknown-illumos run_tests_minimal $VERY_BASIC hello panic/panic pthread-sync
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we also run tests with x86_64-pc-solaris? You've added two OSes everywhere but we're only testing one of them.

README.md Outdated
@@ -227,6 +227,7 @@ degree documented below):
- We have unofficial support (not maintained by the Miri team itself) for some further operating systems.
- `freebsd`: **maintainer wanted**. Supports `std::env` and parts of `std::{thread, fs}`, but not `std::sync`.
- `android`: **maintainer wanted**. Support very incomplete, but a basic "hello world" works.
- `solaris/illumos`: maintained by @devnexen. Support very incomplete, but a basic "hello world" works.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
- `solaris/illumos`: maintained by @devnexen. Support very incomplete, but a basic "hello world" works.
- `solaris`/`illumos`: maintained by @devnexen. Support very incomplete, but a basic "hello world" works.

let this = self.eval_context_mut();
match link_name.as_str() {
// errno
"__errno" => {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is __errno (with two _ right)? libc and std seem to use triple-underscore ___errno.

If this is dead code (i.e., not needed for these tests), then please remove it entirely.

Comment on lines 100 to 104
impl From<ThreadId> for i128 {
fn from(t: ThreadId) -> Self {
t.0.into()
}
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is not used, is it?

@devnexen devnexen force-pushed the solarish_support branch from 670e66e to 981d651 Compare May 5, 2024 07:48
@RalfJung RalfJung changed the title [WIP] solaris/illumos support. solaris/illumos support. May 5, 2024
@RalfJung
Copy link
Member

RalfJung commented May 5, 2024

Ah, Solaris in std has support for the stack guard, which seems to be disabled on illumos. That calls a bunch of very platform-specific functions (see this file).

This can be quite the rabbit hole of little functions that need to be added -- usually with stubs like this that don't actually do anything.

It's up to you whether you want to add that, or restrict the PR to illumos. (You should definitely test this locally though, iterating via CI will take way too long.)

@RalfJung RalfJung changed the title solaris/illumos support. solaris/illumos support May 5, 2024
@RalfJung
Copy link
Member

RalfJung commented May 5, 2024

You will probably have to extend this hack to also allow solaris, not just macos:

if this.frame_in_std() && this.tcx.sess.target.os == "macos" && (flags & map_fixed) != 0 {
return Ok(Scalar::from_maybe_pointer(Pointer::from_addr_invalid(addr), this));
}

It looks like stack_getbounds can just do nothing, but you're going to have to try this out. If not, this.machine.stack_addr and this.machine.stack_size are the fake values we are using elsewhere.

@devnexen devnexen force-pushed the solarish_support branch from 981d651 to 02451c7 Compare May 5, 2024 10:08
README.md Outdated
@@ -227,6 +227,7 @@ degree documented below):
- We have unofficial support (not maintained by the Miri team itself) for some further operating systems.
- `freebsd`: **maintainer wanted**. Supports `std::env` and parts of `std::{thread, fs}`, but not `std::sync`.
- `android`: **maintainer wanted**. Support very incomplete, but a basic "hello world" works.
- `solaris` / `illumos`: maintained by @devnexen. Support very incomplete, but a basic "hello world" works.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
- `solaris` / `illumos`: maintained by @devnexen. Support very incomplete, but a basic "hello world" works.
- `illumos`: maintained by @devnexen. Support very incomplete, but a basic "hello world" works.

@RalfJung RalfJung changed the title solaris/illumos support illumos support May 5, 2024
@devnexen devnexen force-pushed the solarish_support branch from 02451c7 to de54642 Compare May 5, 2024 10:52
@RalfJung
Copy link
Member

RalfJung commented May 5, 2024

Great, thanks!
@bors r+

@bors
Copy link
Contributor

bors commented May 5, 2024

📌 Commit de54642 has been approved by RalfJung

It is now in the queue for this repository.

@bors
Copy link
Contributor

bors commented May 5, 2024

⌛ Testing commit de54642 with merge 8528cc6...

@bors
Copy link
Contributor

bors commented May 5, 2024

☀️ Test successful - checks-actions
Approved by: RalfJung
Pushing 8528cc6 to master...

@bors bors merged commit 8528cc6 into rust-lang:master May 5, 2024
8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-author Status: Waiting for the PR author to address review comments
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants