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

Rework sel4-externally-shared crate #33

Merged
merged 1 commit into from
Oct 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 1 addition & 4 deletions crates/examples/microkit/banscii/pds/artist/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,9 @@ license = "BSD-2-Clause"
[dependencies]
banscii-artist-interface-types = { path = "./interface-types" }
rsa = { version = "0.8.1", default-features = false, features = ["pem", "sha2"] }
sel4-externally-shared = { path = "../../../../../sel4-externally-shared", features = ["unstable"] }
sel4-microkit-message = { path = "../../../../../sel4-microkit/message" }

[dependencies.sel4-externally-shared]
path = "../../../../../sel4-externally-shared"
features = ["unstable", "alloc"]

[dependencies.sel4-microkit]
path = "../../../../../sel4-microkit"
default-features = false
Expand Down
23 changes: 13 additions & 10 deletions crates/examples/microkit/banscii/pds/artist/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,11 @@

extern crate alloc;

use alloc::vec;

use sel4_externally_shared::{
access::{ReadOnly, ReadWrite},
ExternallySharedRef,
ExternallySharedRef, ExternallySharedRefExt,
};
use sel4_microkit::{memory_region_symbol, protection_domain, Channel, Handler, MessageInfo};
use sel4_microkit_message::MessageInfoExt as _;
Expand All @@ -27,13 +29,11 @@ const REGION_SIZE: usize = 0x4_000;
#[protection_domain(heap_size = 0x10000)]
fn init() -> HandlerImpl {
let region_in = unsafe {
ExternallySharedRef::<'static, [u8]>::new_read_only(
memory_region_symbol!(region_in_start: *mut [u8], n = REGION_SIZE),
)
ExternallySharedRef::new(memory_region_symbol!(region_in_start: *mut [u8], n = REGION_SIZE))
};

let region_out = unsafe {
ExternallySharedRef::<'static, [u8]>::new(
ExternallySharedRef::new(
memory_region_symbol!(region_out_start: *mut [u8], n = REGION_SIZE),
)
};
Expand Down Expand Up @@ -62,11 +62,14 @@ impl Handler for HandlerImpl {
Ok(req) => {
let draft_height = req.height;
let draft_width = req.width;
let draft = self
.region_in
.as_ptr()
.index(req.draft_start..req.draft_start + req.draft_size)
.copy_to_vec();
let draft = {
let mut buf = vec![0; req.draft_size];
self.region_in
.as_ptr()
.index(req.draft_start..req.draft_start + req.draft_size)
.copy_into_slice(&mut buf);
buf
};

let masterpiece = Masterpiece::complete(draft_height, draft_width, &draft);

Expand Down
5 changes: 1 addition & 4 deletions crates/examples/microkit/banscii/pds/assistant/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,9 @@ banscii-artist-interface-types = { path = "../artist/interface-types" }
banscii-assistant-core = { path = "./core" }
banscii-pl011-driver-interface-types = { path = "../pl011-driver/interface-types" }
hex = { version = "0.4.3", default-features = false, features = ["alloc"] }
sel4-externally-shared = { path = "../../../../../sel4-externally-shared", features = ["unstable"] }
sel4-microkit-message = { path = "../../../../../sel4-microkit/message" }

[dependencies.sel4-externally-shared]
path = "../../../../../sel4-externally-shared"
features = ["unstable", "alloc"]

[dependencies.sel4-microkit]
path = "../../../../../sel4-microkit"
default-features = false
Expand Down
37 changes: 21 additions & 16 deletions crates/examples/microkit/banscii/pds/assistant/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

extern crate alloc;

use alloc::vec;
use alloc::vec::Vec;
use core::fmt;
use core::fmt::Write;
Expand All @@ -13,7 +14,7 @@ use core::str;

use sel4_externally_shared::{
access::{ReadOnly, ReadWrite},
ExternallySharedRef,
ExternallySharedRef, ExternallySharedRefExt,
};
use sel4_microkit::{memory_region_symbol, protection_domain, Channel, Handler, MessageInfo};
use sel4_microkit_message::MessageInfoExt as _;
Expand All @@ -32,13 +33,11 @@ const MAX_SUBJECT_LEN: usize = 16;
#[protection_domain(heap_size = 0x10000)]
fn init() -> impl Handler {
let region_in = unsafe {
ExternallySharedRef::<'static, [u8]>::new_read_only(
memory_region_symbol!(region_in_start: *mut [u8], n = REGION_SIZE),
)
ExternallySharedRef::new(memory_region_symbol!(region_in_start: *mut [u8], n = REGION_SIZE))
};

let region_out = unsafe {
ExternallySharedRef::<'static, [u8]>::new(
ExternallySharedRef::new(
memory_region_symbol!(region_out_start: *mut [u8], n = REGION_SIZE),
)
};
Expand Down Expand Up @@ -135,17 +134,23 @@ impl HandlerImpl {
let height = resp.height;
let width = resp.width;

let pixel_data = self
.region_in
.as_ptr()
.index(resp.masterpiece_start..resp.masterpiece_start + resp.masterpiece_size)
.copy_to_vec();

let signature = self
.region_in
.as_ptr()
.index(resp.signature_start..resp.signature_start + resp.signature_size)
.copy_to_vec();
let pixel_data = {
let mut buf = vec![0; resp.masterpiece_size];
self.region_in
.as_ptr()
.index(resp.masterpiece_start..resp.masterpiece_start + resp.masterpiece_size)
.copy_into_slice(&mut buf);
buf
};

let signature = {
let mut buf = vec![0; resp.signature_size];
self.region_in
.as_ptr()
.index(resp.signature_start..resp.signature_start + resp.signature_size)
.copy_into_slice(&mut buf);
buf
};

newline();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use core::ptr::{self, NonNull};
use virtio_drivers::{BufferDirection, Hal, PhysAddr, PAGE_SIZE};

use sel4_bounce_buffer_allocator::{Basic, BounceBufferAllocator};
use sel4_externally_shared::ExternallySharedRef;
use sel4_externally_shared::{ExternallySharedRef, ExternallySharedRefExt};
use sel4_immediate_sync_once_cell::ImmediateSyncOnceCell;
use sel4_sync::{GenericMutex, PanickingMutexSyncOps};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ sel4-async-block-io-fat = { path = "../../../../../sel4-async/block-io/fat" }
sel4-async-network = { path = "../../../../../sel4-async/network" }
sel4-async-time = { path = "../../../../../sel4-async/time" }
sel4-bounce-buffer-allocator = { path = "../../../../../sel4-bounce-buffer-allocator" }
sel4-externally-shared = { path = "../../../../../sel4-externally-shared", features = ["unstable"] }
sel4-immediate-sync-once-cell = { path = "../../../../../sel4-immediate-sync-once-cell" }
sel4-logging = { path = "../../../../../sel4-logging" }
sel4-microkit-message = { path = "../../../../../sel4-microkit/message" }
Expand All @@ -36,10 +37,6 @@ path = "../virtio-net-driver/interface-types"
[dependencies.sel4-async-single-threaded-executor]
path = "../../../../../sel4-async/single-threaded-executor"

[dependencies.sel4-externally-shared]
path = "../../../../../sel4-externally-shared"
features = ["unstable", "alloc"]

[dependencies.sel4-microkit]
path = "../../../../../sel4-microkit"
default-features = false
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ use sel4_async_block_io::{
constant_block_sizes::BlockSize512, disk::Disk, CachedBlockIO, ConstantBlockSize,
};
use sel4_bounce_buffer_allocator::{Basic, BounceBufferAllocator};
use sel4_externally_shared::ExternallySharedRef;
use sel4_externally_shared::{ExternallySharedRef, ExternallySharedRefExt};
use sel4_logging::{LevelFilter, Logger, LoggerBuilder};
use sel4_microkit::{memory_region_symbol, protection_domain, var, Channel, Handler};
use sel4_shared_ring_buffer::RingBuffers;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ use virtio_drivers::{
},
};

use sel4_externally_shared::ExternallySharedRef;
use sel4_externally_shared::{ExternallySharedRef, ExternallySharedRefExt};
use sel4_microkit::{memory_region_symbol, protection_domain, var, Channel, Handler, MessageInfo};
use sel4_microkit_message::MessageInfoExt as _;
use sel4_shared_ring_buffer::{roles::Use, RingBuffers};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ use virtio_drivers::{
},
};

use sel4_externally_shared::ExternallySharedRef;
use sel4_externally_shared::{ExternallySharedRef, ExternallySharedRefExt};
use sel4_microkit::{memory_region_symbol, protection_domain, var, Channel, Handler, MessageInfo};
use sel4_microkit_message::MessageInfoExt as _;
use sel4_shared_ring_buffer::{roles::Use, RingBuffers};
Expand Down
2 changes: 1 addition & 1 deletion crates/private/meta/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ sel4-sys = { path = "../../sel4/sys" }

[dependencies.sel4-externally-shared]
path = "../../sel4-externally-shared"
features = ["alloc", "unstable", "very_unstable"]
features = ["unstable", "very_unstable"]

[target."cfg(not(target_arch = \"x86_64\"))".dependencies]
sel4-platform-info = { path = "../../sel4-platform-info", optional = true }
Expand Down
15 changes: 9 additions & 6 deletions crates/sel4-externally-shared/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,15 @@ name = "sel4-externally-shared"
version = "0.1.0"
authors = ["Nick Spinale <nick.spinale@coliasgroup.com>"]
edition = "2021"
license = "MIT OR Apache-2.0"
license = "BSD-2-Clause"

[features]
alloc = []
unstable = []
very_unstable = ["unstable"]
unstable = ["volatile/unstable"]
very_unstable = ["volatile/very_unstable"]

[dev-dependencies]
rand = "0.8.3"
[dependencies]
zerocopy = "0.7.6"

[dependencies.volatile]
git = "https://github.com/coliasgroup/volatile.git"
tag = "keep/8aee5539716d3d38247f46eddd42b382"
Loading