Skip to content

Commit

Permalink
libs: add flatipc implementation
Browse files Browse the repository at this point in the history
flatipc is a new method for doing IPC. This is a zero-copy approach
where structs are given `repr(C)` implementations that are well-defined
and work across process boundaries.

If the same struct or enum is used in two processes that has the same
layout, then data can be freely passed between the two processes without
incurring a serialization or deserialization penalty, provided the
following hold:

1. The buffer must be page-aligned and be a multiple of the page size
2. The item must be `#[repr(C)]`
3. There must be no pointers or references of any kind

If these three things hold, then the object is safe to sling across the
process boundary.

This crate adds the ability to annotate structs with
`#[derive(flatipc::Ipc)]` to provide them with this functionality. When
doing so, objects gain the `.into_ipc()` call that turns them into
something that can be sent across process boundaries.

The resulting object has `.lend()`, `.lend_mut()`, `.try_lend()`, and
`.try_lend_mut()` as functions.

Signed-off-by: Sean Cross <[email protected]>
  • Loading branch information
xobs committed Sep 22, 2024
1 parent fd0eaaa commit a77fdac
Show file tree
Hide file tree
Showing 12 changed files with 1,288 additions and 1 deletion.
4 changes: 3 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -95,9 +95,11 @@ members = [
"kernel",
"loader",
"libs/chat",
"libs/flatipc",
"libs/flatipc-derive",
"libs/perflib",
"libs/userprefs",
"libs/tls",
"libs/userprefs",
"libs/xous-pio",
"libs/xous-bio",
"libs/xous-bio-bdma",
Expand Down
28 changes: 28 additions & 0 deletions libs/flatipc-derive/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# Copyright 2019 The Fuchsia Authors
#
# Licensed under a BSD-style license <LICENSE-BSD>, Apache License, Version 2.0
# <LICENSE-APACHE or https://www.apache.org/licenses/LICENSE-2.0>, or the MIT
# license <LICENSE-MIT or https://opensource.org/licenses/MIT>, at your option.
# This file may not be copied, modified, or distributed except according to
# those terms.

[package]
edition = "2021"
name = "flatipc-derive"
version = "0.1.0"
authors = ["Sean Cross <[email protected]>"]
description = "Custom derive for traits from the flatipc crate"
license = "BSD-2-Clause OR Apache-2.0 OR MIT"
repository = "https://github.com/betrusted/xous-flatipc"

[lib]
proc-macro = true

[dependencies]
proc-macro2 = "*"
quote = "*"
syn = { version = "2", features = ["parsing", "extra-traits"] }

[features]
xous = []
default = []
Loading

0 comments on commit a77fdac

Please sign in to comment.