Convert most syscall helper types to Rust#2765
Merged
sporksmith merged 12 commits intoshadow:mainfrom Feb 28, 2023
Merged
Conversation
stevenengler
approved these changes
Feb 27, 2023
In particular this lets us more easily export struct definitions from Rust to C without introducing circular dependencies.
This fixes the compilation errors, since we define these to use the original unions.
C code in the shadow-shim-helper-rs crate that depends on SysCallReg etc was failing to compile in clean builds, since those definitions are now in the dynamically generated bindings header instead of statically present. Moving these definitions into shadow-shim-helper-rs fixes this dependency issue, and will ultimately be needed anyway to implement more shim and shim-shared-memory code in Rust. Compilation currently fails due to conflicting trait implementations; fixed in next commit.
Now that SysCallReg lives in a different crate than the syscall type
formatting code, the compilation breaks because it no longer knows
whether TryFrom<SysCallReg> will be implemented, causing a potential
conflict between the blanket implementation of TryFromSysCallReg,
and the explicit implementations.
Implementing the TryFrom traits fixes the conflict.
i.e. this commit fixes compilation errors like:
```
error[E0119]: conflicting implementations of trait `host::syscall::type_formatting::TryFromSyscallReg` for type `nix::fcntl::OFlag`
--> main/host/syscall/type_formatting.rs:154:1
|
17 | impl<T: TryFrom<SysCallReg>> TryFromSyscallReg for T {
| ---------------------------------------------------- first implementation here
...
154 | impl TryFromSyscallReg for nix::fcntl::OFlag {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ conflicting implementation for `nix::fcntl::OFlag`
|
= note: upstream crates may add a new impl of trait `std::convert::From<shadow_shim_helper_rs::syscall_types::SysCallReg>` for type `nix::fcntl::OFlag` in future versions
```
8b20407 to
711c3ae
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
In particular this is needed so that we can move the types that the shim also needs to access (e.g. SysCallArg) to the shadow-shim-helper-rs crate.
This reconfigures our cbindgen a bit so that most Rust items, and in particular struct definitions, are exported via
bindings-opaque.h, which doesn't depend on any of the C shadow headers. This resolves a circular inclusion issue if we were to try exportingSysCallArgetc viabindings.hinstead.Migrating types used in unions that bindgen exports appears to cause bindgen to conservatively generate its own special union types instead of native Rust unions. This is resolved by migrating more types than I might have otherwise in this PR, including the union definitions themselves.