Skip to content

Convert most syscall helper types to Rust#2765

Merged
sporksmith merged 12 commits intoshadow:mainfrom
sporksmith:syscall-types2
Feb 28, 2023
Merged

Convert most syscall helper types to Rust#2765
sporksmith merged 12 commits intoshadow:mainfrom
sporksmith:syscall-types2

Conversation

@sporksmith
Copy link
Copy Markdown
Contributor

@sporksmith sporksmith commented Feb 24, 2023

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 exporting SysCallArg etc via bindings.h instead.

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.

@github-actions github-actions bot added Component: Main Composing the core Shadow executable Component: Libraries Support functions like LD_PRELOAD and logging labels Feb 24, 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
```
@sporksmith sporksmith enabled auto-merge February 28, 2023 18:31
@sporksmith sporksmith merged commit 47b2bc4 into shadow:main Feb 28, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Component: Libraries Support functions like LD_PRELOAD and logging Component: Main Composing the core Shadow executable

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants