Skip to content
This repository has been archived by the owner on Mar 24, 2022. It is now read-only.

Multiplatform signals #437

Merged
merged 3 commits into from
Apr 1, 2020
Merged

Multiplatform signals #437

merged 3 commits into from
Apr 1, 2020

Conversation

iximeow
Copy link
Contributor

@iximeow iximeow commented Feb 29, 2020

This mostly gets things in place for the Lucet signal handler to work properly on non-linux posix-y platforms, most interestingly: macos and flavors of bsd.

The gist of this change is to not context swap in the signal handler itself, but replace the address the guest continues with by the context swap function. So the signal handler can return on all platforms, passing through sigreturn-like mechanisms if present, and we have fewer cross-platform compatibility issues.

@iximeow
Copy link
Contributor Author

iximeow commented Feb 29, 2020

the remaining unhandled piece of work here is turning on macos CI, which is, I think, straightforward? I just haven't looked at it yet.

@iximeow iximeow mentioned this pull request Mar 2, 2020
Copy link
Member

@data-pup data-pup left a comment

Choose a reason for hiding this comment

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

I can't test this myself, but the changes here look good to me!

Copy link
Contributor

@acfoltzer acfoltzer left a comment

Choose a reason for hiding this comment

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

Really nice work! Just a few cleanup requests

lucet-runtime/lucet-runtime-internals/src/alloc/mod.rs Outdated Show resolved Hide resolved
lucet-runtime/lucet-runtime-internals/src/context/mod.rs Outdated Show resolved Hide resolved
lucet-runtime/lucet-runtime-internals/src/alloc/mod.rs Outdated Show resolved Hide resolved
lucet-runtime/lucet-runtime-internals/src/region/mmap.rs Outdated Show resolved Hide resolved
lucet-runtime/lucet-runtime-internals/src/region/mmap.rs Outdated Show resolved Hide resolved
lucet-runtime/lucet-runtime-tests/src/guest_fault.rs Outdated Show resolved Hide resolved
lucet-runtime/lucet-runtime-tests/src/guest_fault.rs Outdated Show resolved Hide resolved
@iximeow iximeow force-pushed the multiplatform-signals branch 3 times, most recently from 8963987 to 781fd9d Compare March 30, 2020 21:55
@iximeow
Copy link
Contributor Author

iximeow commented Mar 31, 2020

🎉 All checks have passed 🎉

This branch has picked up a few non-signal-handling-related changes now, so given a +1 I'll fix up the commit history here into the ~three commits I'd like to land ("change signal handling around", "fix C API signal stack sizes to the largest minimum we know we have to work with -- 32kb on macos", and "enable mac CI")

pchickey
pchickey previously approved these changes Mar 31, 2020
Copy link
Contributor

@pchickey pchickey left a comment

Choose a reason for hiding this comment

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

Thanks for getting Mac CI working again!

@iximeow iximeow force-pushed the multiplatform-signals branch 4 times, most recently from d2088fb to acfe0a2 Compare March 31, 2020 19:18
// pointing the instruction pointer at `lucet_context_set`, then by preparing the argument
// that `lucet_context_set` should read from `rdi` - the context to switch to.
//
// NOTE: it is absolutely critical that `lucet_context_set` does not use the guest stack!
Copy link
Contributor Author

Choose a reason for hiding this comment

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

full disclosure: I left most of the branch unchanged while adjusting the commits, but this NOTE: is new. I'd realized that there wasn't anything discussing the specific constraints on the function we continue into after handling a signal, and this addresses that.

iximeow added 3 commits March 31, 2020 12:22
This is in contrast to calling `Context::set_from_signal` directly,
which would skip over typical signal handling teardown some platforms
might require.

pthread_sigmask are removed here as they only served to reset signal
masks that Linux would apply when entering the signal handler. Now that
we return normally from the signal handler, on Linux signals are
unmasked normally.
* conditionally define signals for invalid memory accesses per platform

* add old macos module for version testing

binary blob for the module is probably similar to the linux
`old_module.so`, for which the source is not known. the macos
`old_module.dylib` is built from `fibonacci.wat` as existed in Lucet
commit `8639967` with the following command:

```
$ cargo run --bin lucetc ./lucetc/tests/wasm/fibonacci.wat
```

* make signal stacks sufficiently large in C API tests that mac CI passes
also involves fixing some wasi-sdk installation bitrot
@iximeow iximeow force-pushed the multiplatform-signals branch from acfe0a2 to 78aa0ed Compare March 31, 2020 19:23
@iximeow
Copy link
Contributor Author

iximeow commented Mar 31, 2020

Promise I'm done fiddling with this branch now, it's ready for a final +1! 🤞

Copy link
Contributor

@pchickey pchickey left a comment

Choose a reason for hiding this comment

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

Ship it!

@iximeow iximeow dismissed acfoltzer’s stale review April 1, 2020 17:34

changes have been made, and @pchickey has since approved

@iximeow iximeow merged commit caf30a6 into master Apr 1, 2020
@iximeow iximeow deleted the multiplatform-signals branch April 1, 2020 17:34
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants