mirror of
https://github.com/saymrwulf/xous-core.git
synced 2026-11-20 09:03:28 +00:00
Merge branch 'hardware' of github.com:betrusted-io/xous-core into hardware
This commit is contained in:
commit
e84845553e
13 changed files with 206 additions and 129 deletions
2
Cargo.lock
generated
2
Cargo.lock
generated
|
|
@ -1536,7 +1536,7 @@ checksum = "b07db065a5cf61a7e4ba64f29e67db906fb1787316516c4e6e5ff0fea1efcd8a"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "xous"
|
name = "xous"
|
||||||
version = "0.1.0"
|
version = "0.1.2"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"bitflags",
|
"bitflags",
|
||||||
"hex",
|
"hex",
|
||||||
|
|
|
||||||
2
kernel/Cargo.lock
generated
2
kernel/Cargo.lock
generated
|
|
@ -574,7 +574,7 @@ checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "xous"
|
name = "xous"
|
||||||
version = "0.1.0"
|
version = "0.1.2"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"bitflags",
|
"bitflags",
|
||||||
"hex",
|
"hex",
|
||||||
|
|
|
||||||
|
|
@ -792,6 +792,12 @@ pub fn handle_inner(pid: PID, tid: TID, in_irq: bool, call: SysCall) -> SysCallR
|
||||||
SysCall::Shutdown => {
|
SysCall::Shutdown => {
|
||||||
SystemServices::with_mut(|ss| ss.shutdown().map(|_| xous_kernel::Result::Ok))
|
SystemServices::with_mut(|ss| ss.shutdown().map(|_| xous_kernel::Result::Ok))
|
||||||
}
|
}
|
||||||
|
SysCall::GetProcessId => {
|
||||||
|
Ok(xous_kernel::Result::ProcessID(pid))
|
||||||
|
}
|
||||||
|
SysCall::GetThreadId => {
|
||||||
|
Ok(xous_kernel::Result::ThreadID(tid))
|
||||||
|
}
|
||||||
|
|
||||||
SysCall::Connect(sid) => {
|
SysCall::Connect(sid) => {
|
||||||
let result = SystemServices::with_mut(|ss| {
|
let result = SystemServices::with_mut(|ss| {
|
||||||
|
|
|
||||||
|
|
@ -4,37 +4,47 @@ The GAM provides abstract UI primitives to other modules.
|
||||||
|
|
||||||
The goal is to have this module work in close conjunction with the
|
The goal is to have this module work in close conjunction with the
|
||||||
`graphics-server`, and all other modules would route abstract UI
|
`graphics-server`, and all other modules would route abstract UI
|
||||||
requests through this module.
|
requests through this module.
|
||||||
|
|
||||||
## Structure
|
## Structure
|
||||||
|
At a high level, you can think of the GAM as a firewall around the `graphics-server`.
|
||||||
|
The `graphics-server` has no concept of what pixel belongs where; it's happy
|
||||||
|
to mutate a pixel that is anywhere within the physical hardware framebuffer.
|
||||||
|
|
||||||
|
Giving processes direct access to `graphics-server` means that a less trusted
|
||||||
|
program could draw into an OS-reserved area, thus presenting false information
|
||||||
|
to a user. The GAM solves this problem by dividing the screen into `Canvas` objects.
|
||||||
|
|
||||||
### Canvas
|
### Canvas
|
||||||
|
|
||||||
A `Canvas` is a minimal data structure that defines a physical region of the
|
A `Canvas` is a minimal data structure that defines a physical region of the
|
||||||
screen that will display a set of primitives. `Canvas` structures are domiciled
|
screen that will display a set of primitives. `Canvas` structures are domiciled
|
||||||
in the UI server, and are considered trusted by default, although there is
|
in the GAM server, and are considered trusted by default, although there is
|
||||||
a flag that can be cleared to make everything within it untrusted.
|
a flag that can be cleared to make everything within it untrusted.
|
||||||
|
|
||||||
Each `Canvas` has a 128-bit GUID. Application processes that wish to draw
|
Each `Canvas` has a 128-bit GUID. Application processes that wish to draw
|
||||||
something to the screen must refer to a `Canvas` by its 128-bit GUID; it is up
|
something to the screen must refer to a `Canvas` by its 128-bit GUID; it is up
|
||||||
to the GAM to not share secure GUIDs with insecure processes.
|
to the GAM to not share secure GUIDs with insecure processes. Thus the security
|
||||||
|
of a `Canvas` rests in the difficulty of guessing the 128-bit GUID, and also
|
||||||
|
in the system not leaking GUIDs.
|
||||||
|
|
||||||
The `Canvas` selection is modal on a per-connection basis. In other words,
|
Every GAM drawing object includes the GUID of the `Canvas` to which it should be drawn.
|
||||||
an application can request several `Canvas` objects to draw on, but it
|
Upon receiving a draw request, it validates that the GUID exists, and applies
|
||||||
must first send a `SelectCanvas` command first to pick the right `Canvas`.
|
any other relevant rules (for example, a higher security process can use the
|
||||||
By default, the last requested `Canvas` is the default `Canvas` for a
|
GAM to prohibit all drawing of lower security processes by marking their
|
||||||
given connection to the GAM.
|
`Canvas` as not drawable).
|
||||||
|
|
||||||
The region of the physical screen that can be drawn on by a `Canvas` is
|
All GAM drawing objects specify pixel offsets from a `(0,0)` top-left coordinate
|
||||||
defined by a `clip_rect`. The coordinate space of the `clip_rect` is fixed
|
system. The GAM then handles translating these offsets from a virtual `(0,0)`
|
||||||
|
Canvas offset to a physical region of a screen through the `clip_rect`
|
||||||
|
record within the `Canvas`. The coordinate space of the `clip_rect` is fixed
|
||||||
to the screen's coordinates, that is, `(0,0)` in the top left, X increasing
|
to the screen's coordinates, that is, `(0,0)` in the top left, X increasing
|
||||||
to the right, Y increasing down.
|
to the right, Y increasing down.
|
||||||
|
|
||||||
A `Canvas` stores a `pan_offset`. If the pan offset is `(0,0)`, then the top left
|
A `Canvas` also stores a `pan_offset`. The `pan_offset` is added to every
|
||||||
corner of the `clip_rect` corresponds to data drawn at location `(0,0)` inside
|
coordinate inside the objects that refer to a `Canvas` and then the result
|
||||||
the `Canvas`. The `pan_offset` is added to every coordinate inside the objects that
|
is clipped with `clip_rect`; this allows for easy implementation
|
||||||
refer to a `Canvas` at render time; this allows for easy implementation
|
of panning and scrolling. (Note: this feature is largely untested as of March 2021)
|
||||||
of panning and scrolling.
|
|
||||||
|
|
||||||
A `Canvas` has a `trust_level` associated with it. Higher numbers are more
|
A `Canvas` has a `trust_level` associated with it. Higher numbers are more
|
||||||
trusted; 255 is the highest level of trust. Rules for drawing are as follows:
|
trusted; 255 is the highest level of trust. Rules for drawing are as follows:
|
||||||
|
|
@ -81,13 +91,23 @@ control over customizing their interfaces, and also helps introduce a layer
|
||||||
of protection against phishing; however it also means that UX designers will not
|
of protection against phishing; however it also means that UX designers will not
|
||||||
be able to have exquisite control over the "look and feel" of their applications.
|
be able to have exquisite control over the "look and feel" of their applications.
|
||||||
|
|
||||||
`TextView` objects are domiciled on the application process. Process-local API
|
`TextView` objects are domiciled on the application process. The application
|
||||||
calls can "simulate" certain properties (such as figuring out the dynamic
|
process is responsible for guiding the rough layout of where `TextView`s go
|
||||||
width or height of a text box based on the size of the string within) to assist
|
in a canvas. Once the object is finalized, the `TextView` objects
|
||||||
with laying out `TextViews`. Once the layout is finalized, the `TextView` objects
|
are then mutably lent to the GAM using an `rkyv` lend wrapper;
|
||||||
are then immutably lent to the GAM using an `rkyv` lend wrapper;
|
|
||||||
the calling thread then blocks until the GAM completes the rendering operation.
|
the calling thread then blocks until the GAM completes the rendering operation.
|
||||||
|
|
||||||
|
For layouts that need to adjust in height based on variable-length text strings,
|
||||||
|
the calling application can use the `bounds_hint`/`TextBounds` to help manage this.
|
||||||
|
The bounds of a `TextView` can either be a fixed-sized rectangle, or a box that
|
||||||
|
grows up and out from a point plus a width. So, for example, a `TextView` could have
|
||||||
|
an anchor in the lower-right hand corner, plus a maximum width, and the height of the
|
||||||
|
box will be computed based as the text is rendered. The height of text can't be
|
||||||
|
known a-priori, because for example, emoji glyphs and hanzi characters will
|
||||||
|
have a different height than latin characters. A `dry_run` option is also
|
||||||
|
available for a `TextView` so one can simulate the rendering to determine the height
|
||||||
|
without paying the compuational price.
|
||||||
|
|
||||||
One can think of a `TextView` as a text bubble, that can have rounded or square
|
One can think of a `TextView` as a text bubble, that can have rounded or square
|
||||||
corners, and its content string can be rendered with a selection of options
|
corners, and its content string can be rendered with a selection of options
|
||||||
that specify the glyph style (*not* a font -- it's more of a hint than a specifier),
|
that specify the glyph style (*not* a font -- it's more of a hint than a specifier),
|
||||||
|
|
@ -95,40 +115,11 @@ aligment, and the size of the text bubble. The text bubble can either be of a
|
||||||
fixed size (such that the string will show ellipses `...` if it overruns the
|
fixed size (such that the string will show ellipses `...` if it overruns the
|
||||||
bubble), or of a dynamically growable size based on its content.
|
bubble), or of a dynamically growable size based on its content.
|
||||||
|
|
||||||
|
Thus, a typical "chat-style" app where text bubbles show a history of the chat
|
||||||
|
going from the most recent at the bottom of the screen to the oldest at the top,
|
||||||
|
would start by rendering variable-height text bubbles on the bottom, getting the
|
||||||
|
returned value of the rendered height, and setting the height of the next bubble
|
||||||
|
on top for rendering, and then rendering that.
|
||||||
|
|
||||||
`TextView` can both be directly rendered to a `Canvas`, or managed by secondary
|
`TextView` can both be directly rendered to a `Canvas`, or managed by secondary
|
||||||
object such as a `Menu` or `List` to compose other UI elements.
|
object such as a `Menu` or `List` to compose other UI elements.
|
||||||
|
|
||||||
`TextView` supports a `draw_order` attribute, which allows multiple `TextViews`
|
|
||||||
within a single application to be stacked on top of each other.
|
|
||||||
Note that `draw_order` can only be respected within the context of a single application;
|
|
||||||
if two applications are drawing to the same `Canvas`, then who gets the last
|
|
||||||
draw depend on who sends the last update request. This might be fixable later
|
|
||||||
on with a bit to "mutex" the drawing of other applications to enforce an order,
|
|
||||||
but for MVP we simply avoid having multiple applications contend for access to
|
|
||||||
the same `Canvas`.
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
--------------------
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
The problem is:
|
|
||||||
1. you don't have access to the drawing objects; they are domiciled in the apps
|
|
||||||
2. you don't want to just clear large regions of the FB; that will slow things down.
|
|
||||||
You want to take advantage of dirty bits as much as possible for good performance.
|
|
||||||
3. It would be nice to be able to have a more trusted "pop-up" on top of a less
|
|
||||||
trusted app, and have it obscure the lower app.
|
|
||||||
|
|
||||||
Options include:
|
|
||||||
|
|
||||||
1. A bitmap that stores the drawable mask based on a trust level. This would have
|
|
||||||
to be recalculated from the priority queue for each Canvas every time the queue
|
|
||||||
is updated. This structure consumes 24kiB per canvas in this case...
|
|
||||||
2. Coming up with an arbitrary polygonal region (that can also support holes) and
|
|
||||||
then doing maths to figure out if a point may or may not be updated. This would
|
|
||||||
be memory efficient but rather time and CPU-inefficient to compute.
|
|
||||||
3. Disallowing overlapping Canvas features??
|
|
||||||
4. Maintaining each Canvas with a bitmap that has the latest drawing on it,
|
|
||||||
updating only that bitmap, and then doing compositing and dirty bit computation
|
|
||||||
before sending off to the graphics engine?
|
|
||||||
|
|
|
||||||
|
|
@ -1,27 +1,39 @@
|
||||||
[package]
|
[package]
|
||||||
name = "xous"
|
name = "xous"
|
||||||
version = "0.1.0"
|
version = "0.1.2"
|
||||||
authors = ["Sean Cross <sean@xobs.io>"]
|
authors = ["Sean Cross <sean@xobs.io>"]
|
||||||
edition = "2018"
|
edition = "2018"
|
||||||
license = "MIT OR Apache-2.0"
|
license = "MIT OR Apache-2.0"
|
||||||
description = "System call interface for Xous"
|
description = "System call interface for Xous"
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
bitflags = "1"
|
bitflags = {version = "1", optional = true }
|
||||||
xous-macros = { path = "../macros", version = "0.1.0" }
|
xous-macros = { path = "../macros", version = "0.1.0" }
|
||||||
log = { version = "0.4", optional = true }
|
log = { version = "0.4", optional = true }
|
||||||
rkyv = { version = "0.3.1", default_features = false }
|
rkyv = { version = "0.3.1", default_features = false, optional = true }
|
||||||
|
core = { version = '1.0.0', optional = true, package = 'rustc-std-workspace-core' }
|
||||||
|
compiler_builtins = { version = '0.1.0', optional = true }
|
||||||
|
|
||||||
[features]
|
[features]
|
||||||
|
|
||||||
# If this is set, then the "Drop" feature of MemoryMessage structs
|
# If this is set, then the "Drop" feature of MemoryMessage structs
|
||||||
# will not be implemented. This should only be set by the kernel.
|
# will not be implemented. This should only be set by the kernel.
|
||||||
forget-memory-messages = []
|
forget-memory-messages = []
|
||||||
|
|
||||||
|
# Enable using `bitflags`
|
||||||
|
bit-flags = ["bitflags"]
|
||||||
|
|
||||||
|
# Enable sending commands using `rkyv`
|
||||||
|
archive = ["rkyv"]
|
||||||
|
|
||||||
# `logging` causes this program to connect to a log server on startup
|
# `logging` causes this program to connect to a log server on startup
|
||||||
# so you can run log commands such as `info!()`.
|
# so you can run log commands such as `info!()`.
|
||||||
logging = ["log"]
|
logging = ["log"]
|
||||||
|
|
||||||
default = []
|
# This is being built as part of libstd
|
||||||
|
rustc-dep-of-std = ['core', 'compiler_builtins/rustc-dep-of-std']
|
||||||
|
|
||||||
|
default = ["bit-flags", "archive"]
|
||||||
|
|
||||||
[target.'cfg(any(windows,unix))'.dependencies]
|
[target.'cfg(any(windows,unix))'.dependencies]
|
||||||
lazy_static = "1.4"
|
lazy_static = "1.4"
|
||||||
|
|
|
||||||
|
|
@ -1,9 +1,9 @@
|
||||||
#[cfg(target_os = "none")]
|
#[cfg(any(target_os = "none", target_os = "xous"))]
|
||||||
pub mod native;
|
pub mod native;
|
||||||
#[cfg(target_os = "none")]
|
#[cfg(any(target_os = "none", target_os = "xous"))]
|
||||||
pub use native::*;
|
pub use native::*;
|
||||||
|
|
||||||
#[cfg(not(target_os = "none"))]
|
#[cfg(not(any(target_os = "none", target_os = "xous")))]
|
||||||
pub mod hosted;
|
pub mod hosted;
|
||||||
#[cfg(not(target_os = "none"))]
|
#[cfg(not(any(target_os = "none", target_os = "xous")))]
|
||||||
pub use hosted::*;
|
pub use hosted::*;
|
||||||
|
|
|
||||||
|
|
@ -174,12 +174,12 @@ where
|
||||||
T: Send + 'static,
|
T: Send + 'static,
|
||||||
U: Send + 'static,
|
U: Send + 'static,
|
||||||
{
|
{
|
||||||
let stack = crate::map_memory(
|
#[cfg(feature = "bit-flags")]
|
||||||
None,
|
let flags = crate::MemoryFlags::R | crate::MemoryFlags::W | crate::MemoryFlags::RESERVE;
|
||||||
None,
|
#[cfg(not(feature = "bit-flags"))]
|
||||||
131_072,
|
let flags = 0b0000_0010 | 0b0000_0100 | 0b0000_0001;
|
||||||
crate::MemoryFlags::R | crate::MemoryFlags::W | crate::MemoryFlags::RESERVE,
|
|
||||||
)?;
|
let stack = crate::map_memory(None, None, 131_072, flags)?;
|
||||||
let start = unsafe { core::mem::transmute(*f) };
|
let start = unsafe { core::mem::transmute(*f) };
|
||||||
let arg = unsafe { core::mem::transmute(arg) };
|
let arg = unsafe { core::mem::transmute(arg) };
|
||||||
Ok(ThreadInit::new(start, stack, Some(arg), [0; 12]))
|
Ok(ThreadInit::new(start, stack, Some(arg), [0; 12]))
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,7 @@
|
||||||
use crate::{Result, Error, MemoryMessage, MemoryRange, MemoryFlags, MemorySize, Message, CID, map_memory, send_message};
|
use crate::{
|
||||||
|
map_memory, send_message, Error, MemoryMessage, MemoryRange, MemorySize, Message,
|
||||||
|
Result, CID,
|
||||||
|
};
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub struct XousBuffer<'a> {
|
pub struct XousBuffer<'a> {
|
||||||
|
|
@ -11,16 +14,23 @@ pub struct XousBuffer<'a> {
|
||||||
impl<'a> XousBuffer<'a> {
|
impl<'a> XousBuffer<'a> {
|
||||||
#[allow(dead_code)]
|
#[allow(dead_code)]
|
||||||
pub fn new(len: usize) -> Self {
|
pub fn new(len: usize) -> Self {
|
||||||
let remainder =
|
let remainder = if ((len & 0xFFF) == 0) && (len > 0) {
|
||||||
if ((len & 0xFFF) == 0) && (len > 0) { 0 }
|
0
|
||||||
else { 0x1000 - (len & 0xFFF) };
|
} else {
|
||||||
|
0x1000 - (len & 0xFFF)
|
||||||
|
};
|
||||||
|
|
||||||
|
#[cfg(feature = "bit-flags")]
|
||||||
|
let flags = crate::MemoryFlags::R | crate::MemoryFlags::W;
|
||||||
|
#[cfg(not(feature = "bit-flags"))]
|
||||||
|
let flags = 0b0000_0010 | 0b0000_0100;
|
||||||
|
|
||||||
let new_mem = map_memory(
|
let new_mem = map_memory(
|
||||||
None,
|
None,
|
||||||
None,
|
None,
|
||||||
// Ensure our byte size is a multiple of 4096
|
// Ensure our byte size is a multiple of 4096
|
||||||
len + remainder,
|
len + remainder,
|
||||||
MemoryFlags::R | MemoryFlags::W,
|
flags,
|
||||||
)
|
)
|
||||||
.expect("XousBuffer: error in new()/map_memory");
|
.expect("XousBuffer: error in new()/map_memory");
|
||||||
|
|
||||||
|
|
@ -28,7 +38,9 @@ impl<'a> XousBuffer<'a> {
|
||||||
valid.size = MemorySize::new(len + remainder).unwrap();
|
valid.size = MemorySize::new(len + remainder).unwrap();
|
||||||
XousBuffer {
|
XousBuffer {
|
||||||
range: new_mem,
|
range: new_mem,
|
||||||
slice: unsafe { core::slice::from_raw_parts_mut(new_mem.as_mut_ptr(), len + remainder) },
|
slice: unsafe {
|
||||||
|
core::slice::from_raw_parts_mut(new_mem.as_mut_ptr(), len + remainder)
|
||||||
|
},
|
||||||
valid,
|
valid,
|
||||||
should_drop: true,
|
should_drop: true,
|
||||||
}
|
}
|
||||||
|
|
@ -46,11 +58,7 @@ impl<'a> XousBuffer<'a> {
|
||||||
|
|
||||||
/// Perform a mutable lend of this Carton to the server.
|
/// Perform a mutable lend of this Carton to the server.
|
||||||
#[allow(dead_code)]
|
#[allow(dead_code)]
|
||||||
pub fn lend_mut(
|
pub fn lend_mut(&mut self, connection: CID, id: u32) -> core::result::Result<Result, Error> {
|
||||||
&mut self,
|
|
||||||
connection: CID,
|
|
||||||
id: u32,
|
|
||||||
) -> core::result::Result<Result, Error> {
|
|
||||||
let msg = MemoryMessage {
|
let msg = MemoryMessage {
|
||||||
id: id as usize,
|
id: id as usize,
|
||||||
buf: self.valid,
|
buf: self.valid,
|
||||||
|
|
@ -61,11 +69,7 @@ impl<'a> XousBuffer<'a> {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[allow(dead_code)]
|
#[allow(dead_code)]
|
||||||
pub fn lend(
|
pub fn lend(&self, connection: CID, id: u32) -> core::result::Result<Result, Error> {
|
||||||
&self,
|
|
||||||
connection: CID,
|
|
||||||
id: u32
|
|
||||||
) -> core::result::Result<Result, Error> {
|
|
||||||
let msg = MemoryMessage {
|
let msg = MemoryMessage {
|
||||||
id: id as usize,
|
id: id as usize,
|
||||||
buf: self.valid,
|
buf: self.valid,
|
||||||
|
|
@ -76,11 +80,7 @@ impl<'a> XousBuffer<'a> {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[allow(dead_code)]
|
#[allow(dead_code)]
|
||||||
pub fn send(
|
pub fn send(mut self, connection: CID, id: u32) -> core::result::Result<Result, Error> {
|
||||||
mut self,
|
|
||||||
connection: CID,
|
|
||||||
id: u32,
|
|
||||||
) -> core::result::Result<Result, Error> {
|
|
||||||
let msg = crate::MemoryMessage {
|
let msg = crate::MemoryMessage {
|
||||||
id: id as usize,
|
id: id as usize,
|
||||||
buf: self.valid,
|
buf: self.valid,
|
||||||
|
|
|
||||||
|
|
@ -19,13 +19,12 @@ impl<'a> Carton<'a> {
|
||||||
let remainder = bytes.len() & 4095;
|
let remainder = bytes.len() & 4095;
|
||||||
let size = bytes.len() + (4096 - remainder);
|
let size = bytes.len() + (4096 - remainder);
|
||||||
|
|
||||||
let new_mem = crate::map_memory(
|
#[cfg(feature = "bit-flags")]
|
||||||
None,
|
let flags = crate::MemoryFlags::R | crate::MemoryFlags::W;
|
||||||
None,
|
#[cfg(not(feature = "bit-flags"))]
|
||||||
size,
|
let flags = 0b0000_0010 | 0b0000_0100;
|
||||||
crate::MemoryFlags::R | crate::MemoryFlags::W,
|
|
||||||
)
|
let new_mem = crate::map_memory(None, None, size, flags).unwrap();
|
||||||
.unwrap();
|
|
||||||
|
|
||||||
// NOTE: Remaining bytes are not zeroed. We assume the kernel has done this for us.
|
// NOTE: Remaining bytes are not zeroed. We assume the kernel has done this for us.
|
||||||
unsafe {
|
unsafe {
|
||||||
|
|
|
||||||
|
|
@ -115,6 +115,7 @@ pub struct MemoryRange {
|
||||||
pub size: MemorySize,
|
pub size: MemorySize,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(feature = "bitflags")]
|
||||||
bitflags! {
|
bitflags! {
|
||||||
/// Flags to be passed to the MapMemory struct.
|
/// Flags to be passed to the MapMemory struct.
|
||||||
/// Note that it is an error to have memory be
|
/// Note that it is an error to have memory be
|
||||||
|
|
@ -138,6 +139,25 @@ bitflags! {
|
||||||
const X = 0b0000_1000;
|
const X = 0b0000_1000;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
#[cfg(feature = "bitflags")]
|
||||||
|
pub(crate) fn get_bits(bf: &MemoryFlags) -> usize {
|
||||||
|
bf.bits()
|
||||||
|
}
|
||||||
|
#[cfg(feature = "bitflags")]
|
||||||
|
pub(crate) fn from_bits(raw: usize) -> Option<MemoryFlags> {
|
||||||
|
MemoryFlags::from_bits(raw)
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg(not(feature = "bitflags"))]
|
||||||
|
pub type MemoryFlags = usize;
|
||||||
|
#[cfg(not(feature = "bitflags"))]
|
||||||
|
pub(crate) fn get_bits(bf: &MemoryFlags) -> usize {
|
||||||
|
*bf
|
||||||
|
}
|
||||||
|
#[cfg(not(feature = "bitflags"))]
|
||||||
|
pub(crate) fn from_bits(raw: usize) -> Option<MemoryFlags> {
|
||||||
|
Some(raw)
|
||||||
|
}
|
||||||
|
|
||||||
pub fn pid_from_usize(src: usize) -> core::result::Result<PID, Error> {
|
pub fn pid_from_usize(src: usize) -> core::result::Result<PID, Error> {
|
||||||
if src > u8::MAX as _ {
|
if src > u8::MAX as _ {
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,6 @@
|
||||||
#![cfg_attr(target_os = "none", no_std)]
|
#![cfg_attr(any(target_os = "none", target_os = "xous"), no_std)]
|
||||||
|
|
||||||
|
#[cfg(feature = "bitflags")]
|
||||||
#[macro_use]
|
#[macro_use]
|
||||||
extern crate bitflags;
|
extern crate bitflags;
|
||||||
|
|
||||||
|
|
@ -12,27 +13,30 @@ pub mod arch;
|
||||||
pub mod carton;
|
pub mod carton;
|
||||||
pub mod definitions;
|
pub mod definitions;
|
||||||
mod messages;
|
mod messages;
|
||||||
pub mod string;
|
|
||||||
pub mod buffer;
|
pub mod buffer;
|
||||||
pub mod syscall;
|
|
||||||
pub mod process;
|
pub mod process;
|
||||||
|
#[cfg(feature = "archive")]
|
||||||
|
pub mod string;
|
||||||
|
pub mod syscall;
|
||||||
|
|
||||||
pub mod names;
|
pub mod names;
|
||||||
|
|
||||||
pub use arch::{ProcessArgs, ProcessInit, ProcessKey, ThreadInit};
|
pub use arch::{ProcessArgs, ProcessInit, ProcessKey, ThreadInit};
|
||||||
|
pub use buffer::XousBuffer;
|
||||||
pub use definitions::*;
|
pub use definitions::*;
|
||||||
pub use messages::*;
|
pub use messages::*;
|
||||||
|
#[cfg(feature = "archive")]
|
||||||
pub use string::*;
|
pub use string::*;
|
||||||
pub use syscall::*;
|
pub use syscall::*;
|
||||||
pub use buffer::XousBuffer;
|
|
||||||
|
|
||||||
#[cfg(not(target_os = "none"))]
|
#[cfg(not(any(target_os = "none", target_os = "xous")))]
|
||||||
pub use arch::ProcessArgsAsThread;
|
pub use arch::ProcessArgsAsThread;
|
||||||
|
|
||||||
#[cfg(target_os = "none")]
|
#[cfg(any(target_os = "none", target_os = "xous"))]
|
||||||
pub fn init() {}
|
pub fn init() {}
|
||||||
|
|
||||||
#[cfg(not(target_os = "none"))]
|
#[cfg(not(any(target_os = "none", target_os = "xous")))]
|
||||||
pub fn init() {
|
pub fn init() {
|
||||||
use std::panic;
|
use std::panic;
|
||||||
panic::set_hook(Box::new(|arg| {
|
panic::set_hook(Box::new(|arg| {
|
||||||
|
|
@ -61,6 +65,7 @@ macro_rules! maybe_main {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
|
#[cfg(not(target_os = "xous"))]
|
||||||
xous::arch::ensure_connection().unwrap();
|
xous::arch::ensure_connection().unwrap();
|
||||||
unsafe { xous_entry() };
|
unsafe { xous_entry() };
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,17 +1,9 @@
|
||||||
#[cfg(not(target_os = "none"))]
|
|
||||||
pub fn id() -> u32 {
|
pub fn id() -> u32 {
|
||||||
std::process::id()
|
if let Ok(crate::Result::ProcessID(pid)) = crate::syscall::current_pid() {
|
||||||
|
pid.get() as u32
|
||||||
|
} else {
|
||||||
|
0
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(target_os = "none")]
|
pub fn set_id(_id: u32) {}
|
||||||
static PID_KEEPER: core::sync::atomic::AtomicU32 = core::sync::atomic::AtomicU32::new(0);
|
|
||||||
|
|
||||||
#[cfg(target_os = "none")]
|
|
||||||
pub fn id() -> u32 {
|
|
||||||
PID_KEEPER.load(core::sync::atomic::Ordering::Relaxed)
|
|
||||||
}
|
|
||||||
|
|
||||||
#[cfg(target_os = "none")]
|
|
||||||
pub fn set_id(id: u32) {
|
|
||||||
PID_KEEPER.store(id, core::sync::atomic::Ordering::Relaxed)
|
|
||||||
}
|
|
||||||
|
|
|
||||||
|
|
@ -8,7 +8,7 @@ use core::convert::TryInto;
|
||||||
// use num_derive::FromPrimitive;
|
// use num_derive::FromPrimitive;
|
||||||
// use num_traits::FromPrimitive;
|
// use num_traits::FromPrimitive;
|
||||||
|
|
||||||
#[cfg(not(target_os = "none"))]
|
#[cfg(not(any(target_os = "none", target_os = "xous")))]
|
||||||
use crate::ProcessArgsAsThread;
|
use crate::ProcessArgsAsThread;
|
||||||
|
|
||||||
#[derive(Debug, PartialEq)]
|
#[derive(Debug, PartialEq)]
|
||||||
|
|
@ -299,6 +299,12 @@ pub enum SysCall {
|
||||||
/// disclosing SIDs.
|
/// disclosing SIDs.
|
||||||
ConnectForProcess(PID, SID),
|
ConnectForProcess(PID, SID),
|
||||||
|
|
||||||
|
/// Get the current Thread ID
|
||||||
|
GetThreadId,
|
||||||
|
|
||||||
|
/// Get the current Process ID
|
||||||
|
GetProcessId,
|
||||||
|
|
||||||
/// This syscall does not exist. It captures all possible
|
/// This syscall does not exist. It captures all possible
|
||||||
/// arguments so detailed analysis can be performed.
|
/// arguments so detailed analysis can be performed.
|
||||||
Invalid(usize, usize, usize, usize, usize, usize, usize),
|
Invalid(usize, usize, usize, usize, usize, usize, usize),
|
||||||
|
|
@ -336,6 +342,8 @@ pub enum SysCallNumber {
|
||||||
CreateServer = 29,
|
CreateServer = 29,
|
||||||
ConnectForProcess = 30,
|
ConnectForProcess = 30,
|
||||||
CreateServerId = 31,
|
CreateServerId = 31,
|
||||||
|
GetThreadId = 32,
|
||||||
|
GetProcessId = 33,
|
||||||
Invalid,
|
Invalid,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -373,6 +381,8 @@ impl SysCallNumber {
|
||||||
29 => CreateServer,
|
29 => CreateServer,
|
||||||
30 => ConnectForProcess,
|
30 => ConnectForProcess,
|
||||||
31 => CreateServerId,
|
31 => CreateServerId,
|
||||||
|
32 => GetThreadId,
|
||||||
|
33 => GetProcessId,
|
||||||
_ => Invalid,
|
_ => Invalid,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -395,7 +405,7 @@ impl SysCall {
|
||||||
a1.map(|x| x.get()).unwrap_or_default(),
|
a1.map(|x| x.get()).unwrap_or_default(),
|
||||||
a2.map(|x| x.get()).unwrap_or_default(),
|
a2.map(|x| x.get()).unwrap_or_default(),
|
||||||
a3.get(),
|
a3.get(),
|
||||||
a4.bits(),
|
crate::get_bits(a4),
|
||||||
0,
|
0,
|
||||||
0,
|
0,
|
||||||
0,
|
0,
|
||||||
|
|
@ -499,7 +509,7 @@ impl SysCall {
|
||||||
SysCall::IncreaseHeap(a1, a2) => [
|
SysCall::IncreaseHeap(a1, a2) => [
|
||||||
SysCallNumber::IncreaseHeap as usize,
|
SysCallNumber::IncreaseHeap as usize,
|
||||||
*a1 as usize,
|
*a1 as usize,
|
||||||
a2.bits(),
|
crate::get_bits(a2),
|
||||||
0,
|
0,
|
||||||
0,
|
0,
|
||||||
0,
|
0,
|
||||||
|
|
@ -520,7 +530,7 @@ impl SysCall {
|
||||||
SysCallNumber::UpdateMemoryFlags as usize,
|
SysCallNumber::UpdateMemoryFlags as usize,
|
||||||
a1.get(),
|
a1.get(),
|
||||||
*a2 as usize,
|
*a2 as usize,
|
||||||
a3.bits(),
|
crate::get_bits(a3),
|
||||||
0,
|
0,
|
||||||
0,
|
0,
|
||||||
0,
|
0,
|
||||||
|
|
@ -668,6 +678,24 @@ impl SysCall {
|
||||||
0,
|
0,
|
||||||
0,
|
0,
|
||||||
],
|
],
|
||||||
|
SysCall::GetThreadId => [SysCallNumber::GetThreadId as usize,
|
||||||
|
0,
|
||||||
|
0,
|
||||||
|
0,
|
||||||
|
0,
|
||||||
|
0,
|
||||||
|
0,
|
||||||
|
0,
|
||||||
|
],
|
||||||
|
SysCall::GetProcessId => [SysCallNumber::GetProcessId as usize,
|
||||||
|
0,
|
||||||
|
0,
|
||||||
|
0,
|
||||||
|
0,
|
||||||
|
0,
|
||||||
|
0,
|
||||||
|
0,
|
||||||
|
],
|
||||||
SysCall::Invalid(a1, a2, a3, a4, a5, a6, a7) => [
|
SysCall::Invalid(a1, a2, a3, a4, a5, a6, a7) => [
|
||||||
SysCallNumber::Invalid as usize,
|
SysCallNumber::Invalid as usize,
|
||||||
*a1,
|
*a1,
|
||||||
|
|
@ -697,7 +725,7 @@ impl SysCall {
|
||||||
MemoryAddress::new(a1),
|
MemoryAddress::new(a1),
|
||||||
MemoryAddress::new(a2),
|
MemoryAddress::new(a2),
|
||||||
MemoryAddress::new(a3).ok_or(Error::InvalidSyscall)?,
|
MemoryAddress::new(a3).ok_or(Error::InvalidSyscall)?,
|
||||||
MemoryFlags::from_bits(a4).ok_or(Error::InvalidSyscall)?,
|
crate::from_bits(a4).ok_or(Error::InvalidSyscall)?,
|
||||||
),
|
),
|
||||||
SysCallNumber::UnmapMemory => {
|
SysCallNumber::UnmapMemory => {
|
||||||
SysCall::UnmapMemory(MemoryRange::new(a1, a2).or(Err(Error::InvalidSyscall))?)
|
SysCall::UnmapMemory(MemoryRange::new(a1, a2).or(Err(Error::InvalidSyscall))?)
|
||||||
|
|
@ -721,13 +749,13 @@ impl SysCall {
|
||||||
SysCallNumber::ReadyThreads => SysCall::ReadyThreads(pid_from_usize(a1)?),
|
SysCallNumber::ReadyThreads => SysCall::ReadyThreads(pid_from_usize(a1)?),
|
||||||
SysCallNumber::IncreaseHeap => SysCall::IncreaseHeap(
|
SysCallNumber::IncreaseHeap => SysCall::IncreaseHeap(
|
||||||
a1 as usize,
|
a1 as usize,
|
||||||
MemoryFlags::from_bits(a2).ok_or(Error::InvalidSyscall)?,
|
crate::from_bits(a2).ok_or(Error::InvalidSyscall)?,
|
||||||
),
|
),
|
||||||
SysCallNumber::DecreaseHeap => SysCall::DecreaseHeap(a1 as usize),
|
SysCallNumber::DecreaseHeap => SysCall::DecreaseHeap(a1 as usize),
|
||||||
SysCallNumber::UpdateMemoryFlags => SysCall::UpdateMemoryFlags(
|
SysCallNumber::UpdateMemoryFlags => SysCall::UpdateMemoryFlags(
|
||||||
MemoryAddress::new(a1).ok_or(Error::InvalidSyscall)?,
|
MemoryAddress::new(a1).ok_or(Error::InvalidSyscall)?,
|
||||||
a2 as usize,
|
a2 as usize,
|
||||||
MemoryFlags::from_bits(a3).ok_or(Error::InvalidSyscall)?,
|
crate::from_bits(a3).ok_or(Error::InvalidSyscall)?,
|
||||||
),
|
),
|
||||||
SysCallNumber::SetMemRegion => SysCall::SetMemRegion(
|
SysCallNumber::SetMemRegion => SysCall::SetMemRegion(
|
||||||
pid_from_usize(a1)?,
|
pid_from_usize(a1)?,
|
||||||
|
|
@ -867,6 +895,8 @@ impl SysCall {
|
||||||
SID::from_u32(a2 as _, a3 as _, a4 as _, a5 as _),
|
SID::from_u32(a2 as _, a3 as _, a4 as _, a5 as _),
|
||||||
),
|
),
|
||||||
SysCallNumber::CreateServerId => SysCall::CreateServerId,
|
SysCallNumber::CreateServerId => SysCall::CreateServerId,
|
||||||
|
SysCallNumber::GetThreadId => SysCall::GetThreadId,
|
||||||
|
SysCallNumber::GetProcessId => SysCall::GetProcessId,
|
||||||
SysCallNumber::Invalid => SysCall::Invalid(a1, a2, a3, a4, a5, a6, a7),
|
SysCallNumber::Invalid => SysCall::Invalid(a1, a2, a3, a4, a5, a6, a7),
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
@ -1334,7 +1364,7 @@ pub fn wait_thread<T>(joiner: crate::arch::WaitHandle<T>) -> SysCallResult {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Create a new process by running it in its own thread
|
/// Create a new process by running it in its own thread
|
||||||
#[cfg(not(target_os = "none"))]
|
#[cfg(not(any(target_os = "none", target_os = "xous")))]
|
||||||
pub fn create_process_as_thread<F>(
|
pub fn create_process_as_thread<F>(
|
||||||
args: ProcessArgsAsThread<F>,
|
args: ProcessArgsAsThread<F>,
|
||||||
) -> core::result::Result<crate::arch::ProcessHandleAsThread, Error>
|
) -> core::result::Result<crate::arch::ProcessHandleAsThread, Error>
|
||||||
|
|
@ -1352,7 +1382,7 @@ where
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Wait for a thread to finish
|
/// Wait for a thread to finish
|
||||||
#[cfg(not(target_os = "none"))]
|
#[cfg(not(any(target_os = "none", target_os = "xous")))]
|
||||||
pub fn wait_process_as_thread(joiner: crate::arch::ProcessHandleAsThread) -> SysCallResult {
|
pub fn wait_process_as_thread(joiner: crate::arch::ProcessHandleAsThread) -> SysCallResult {
|
||||||
crate::arch::wait_process_as_thread(joiner)
|
crate::arch::wait_process_as_thread(joiner)
|
||||||
}
|
}
|
||||||
|
|
@ -1375,6 +1405,28 @@ pub fn wait_process(joiner: crate::arch::ProcessHandle) -> SysCallResult {
|
||||||
crate::arch::wait_process(joiner)
|
crate::arch::wait_process(joiner)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Get the current process ID
|
||||||
|
pub fn current_pid() -> SysCallResult {
|
||||||
|
rsyscall(SysCall::GetProcessId).and_then(|result| {
|
||||||
|
if let Result::ProcessID(pid) = result {
|
||||||
|
Ok(Result::ProcessID(pid))
|
||||||
|
} else {
|
||||||
|
Err(Error::InternalError)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Get the current thread ID
|
||||||
|
pub fn current_tid() -> SysCallResult {
|
||||||
|
rsyscall(SysCall::GetProcessId).and_then(|result| {
|
||||||
|
if let Result::ThreadID(tid) = result {
|
||||||
|
Ok(Result::ThreadID(tid))
|
||||||
|
} else {
|
||||||
|
Err(Error::InternalError)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
pub fn rsyscall(call: SysCall) -> SysCallResult {
|
pub fn rsyscall(call: SysCall) -> SysCallResult {
|
||||||
let mut ret = Result::Ok;
|
let mut ret = Result::Ok;
|
||||||
let args = call.as_args();
|
let args = call.as_args();
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue