mirror of
https://github.com/saymrwulf/xous-core.git
synced 2026-11-18 08:52:45 +00:00
add PlatformSpecific syscall & cleanup warnings
a number of warnings cropped up in the latest Rust, which have been cleaned up. In addition, a definition for a PlatformSpecific syscall has been added. This is a catch-all for meta-calls that can be experimented with on a specific platform without having to update the xous API. Xous API updates necessitate about a hundred files to get their versions bumped to absorb the new API, and so this is considered to be a fairly major task.
This commit is contained in:
parent
c7d8b88456
commit
5be0ddbd0f
5 changed files with 131 additions and 6 deletions
|
|
@ -16,7 +16,7 @@ impl<'a> ProcessArgs<'a> {
|
||||||
stub: &[u8],
|
stub: &[u8],
|
||||||
load_address: crate::MemoryAddress,
|
load_address: crate::MemoryAddress,
|
||||||
entrypoint: crate::MemoryAddress,
|
entrypoint: crate::MemoryAddress,
|
||||||
) -> ProcessArgs {
|
) -> ProcessArgs<'_> {
|
||||||
ProcessArgs {
|
ProcessArgs {
|
||||||
load_address,
|
load_address,
|
||||||
entrypoint,
|
entrypoint,
|
||||||
|
|
|
||||||
|
|
@ -5,6 +5,7 @@ pub mod arch;
|
||||||
pub mod carton;
|
pub mod carton;
|
||||||
pub mod definitions;
|
pub mod definitions;
|
||||||
|
|
||||||
|
pub mod pagebuffer;
|
||||||
pub mod process;
|
pub mod process;
|
||||||
pub mod services;
|
pub mod services;
|
||||||
pub mod string;
|
pub mod string;
|
||||||
|
|
@ -13,6 +14,7 @@ pub mod syscall;
|
||||||
|
|
||||||
pub use arch::{ProcessArgs, ProcessInit, ProcessKey, ProcessStartup, ThreadInit};
|
pub use arch::{ProcessArgs, ProcessInit, ProcessKey, ProcessStartup, ThreadInit};
|
||||||
pub use definitions::*;
|
pub use definitions::*;
|
||||||
|
pub use pagebuffer::*;
|
||||||
pub use string::*;
|
pub use string::*;
|
||||||
pub use stringbuffer::*;
|
pub use stringbuffer::*;
|
||||||
pub use syscall::*;
|
pub use syscall::*;
|
||||||
|
|
|
||||||
106
xous-rs/src/pagebuffer.rs
Normal file
106
xous-rs/src/pagebuffer.rs
Normal file
|
|
@ -0,0 +1,106 @@
|
||||||
|
use core::fmt;
|
||||||
|
|
||||||
|
/// A variant of StringBuffer that is stack-allocated. Used primarily for passing debug information
|
||||||
|
/// to and from the kernel.
|
||||||
|
#[repr(align(4096))]
|
||||||
|
pub struct PageBuf {
|
||||||
|
len: usize,
|
||||||
|
data: [u8; 4092],
|
||||||
|
}
|
||||||
|
|
||||||
|
impl PageBuf {
|
||||||
|
pub fn new() -> Self { Self { len: 0, data: [0u8; 4092] } }
|
||||||
|
|
||||||
|
/// Returns the written data as a byte slice
|
||||||
|
pub fn as_bytes(&self) -> &[u8] { &self.data[..self.len] }
|
||||||
|
|
||||||
|
/// Returns the written data as a string slice
|
||||||
|
/// Safe because we maintain UTF-8 validity in write_str
|
||||||
|
pub fn as_str(&self) -> &str { unsafe { core::str::from_utf8_unchecked(&self.data[..self.len]) } }
|
||||||
|
|
||||||
|
/// Clears the buffer
|
||||||
|
pub fn clear(&mut self) { self.len = 0; }
|
||||||
|
|
||||||
|
/// Returns the number of bytes written
|
||||||
|
pub fn len(&self) -> usize { self.len }
|
||||||
|
|
||||||
|
/// Returns remaining capacity
|
||||||
|
pub fn remaining(&self) -> usize { self.data.len() - self.len }
|
||||||
|
|
||||||
|
/// Reconstructs a PageBuf reference from a raw pointer address.
|
||||||
|
///
|
||||||
|
/// # Safety
|
||||||
|
///
|
||||||
|
/// The caller must ensure:
|
||||||
|
/// - The pointer points to a valid, initialized PageBuf
|
||||||
|
/// - The memory is properly aligned (4096 bytes)
|
||||||
|
/// - The memory will remain valid for the lifetime 'a
|
||||||
|
/// - No other mutable references to this memory exist
|
||||||
|
///
|
||||||
|
/// # Panics
|
||||||
|
///
|
||||||
|
/// Panics if:
|
||||||
|
/// - The pointer is null
|
||||||
|
/// - The pointer is not 4096-byte aligned
|
||||||
|
/// - The len field exceeds 4092
|
||||||
|
/// - The data[..len] contains invalid UTF-8
|
||||||
|
pub unsafe fn from_raw_ptr_mut<'a>(ptr: usize) -> &'a mut Self {
|
||||||
|
// Check non-null
|
||||||
|
assert_ne!(ptr, 0, "PageBuf pointer must not be null");
|
||||||
|
|
||||||
|
// Check alignment
|
||||||
|
assert_eq!(
|
||||||
|
ptr % 4096,
|
||||||
|
0,
|
||||||
|
"PageBuf pointer must be 4096-byte aligned, got alignment of {}",
|
||||||
|
ptr % 4096
|
||||||
|
);
|
||||||
|
|
||||||
|
// Cast to reference
|
||||||
|
let page_buf = &mut *(ptr as *mut PageBuf);
|
||||||
|
|
||||||
|
// Validate len field
|
||||||
|
assert!(page_buf.len <= 4092, "PageBuf len ({}) exceeds maximum (4092)", page_buf.len);
|
||||||
|
|
||||||
|
// Validate UTF-8 invariant
|
||||||
|
core::str::from_utf8(&page_buf.data[..page_buf.len]).expect("PageBuf data must contain valid UTF-8");
|
||||||
|
|
||||||
|
page_buf
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Returns the address of this PageBuf as a usize for passing across boundaries
|
||||||
|
pub fn as_ptr(&self) -> usize { self as *const Self as usize }
|
||||||
|
}
|
||||||
|
|
||||||
|
impl fmt::Write for PageBuf {
|
||||||
|
fn write_str(&mut self, s: &str) -> fmt::Result {
|
||||||
|
let bytes = s.as_bytes();
|
||||||
|
let available = self.data.len() - self.len;
|
||||||
|
|
||||||
|
if available == 0 {
|
||||||
|
// Buffer is full, silently discard
|
||||||
|
return Ok(());
|
||||||
|
}
|
||||||
|
|
||||||
|
let to_write = if bytes.len() <= available {
|
||||||
|
bytes.len()
|
||||||
|
} else {
|
||||||
|
// Find the last valid UTF-8 boundary within available space
|
||||||
|
// This prevents cutting in the middle of a multi-byte character
|
||||||
|
let mut boundary = available;
|
||||||
|
while boundary > 0 && !s.is_char_boundary(boundary) {
|
||||||
|
boundary -= 1;
|
||||||
|
}
|
||||||
|
boundary
|
||||||
|
};
|
||||||
|
|
||||||
|
self.data[self.len..self.len + to_write].copy_from_slice(&bytes[..to_write]);
|
||||||
|
self.len += to_write;
|
||||||
|
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Default for PageBuf {
|
||||||
|
fn default() -> Self { Self::new() }
|
||||||
|
}
|
||||||
|
|
@ -70,11 +70,11 @@ pub fn connect(name: &str) -> Option<crate::CID> {
|
||||||
|
|
||||||
if result == 0 {
|
if result == 0 {
|
||||||
let cid = unsafe { response_ptr.add(1).read() };
|
let cid = unsafe { response_ptr.add(1).read() };
|
||||||
let mut token = [0u32; 4];
|
// let mut token = [0u32; 4];
|
||||||
token[0] = unsafe { response_ptr.add(2).read() };
|
// token[0] = unsafe { response_ptr.add(2).read() };
|
||||||
token[1] = unsafe { response_ptr.add(3).read() };
|
// token[1] = unsafe { response_ptr.add(3).read() };
|
||||||
token[2] = unsafe { response_ptr.add(4).read() };
|
// token[2] = unsafe { response_ptr.add(4).read() };
|
||||||
token[3] = unsafe { response_ptr.add(5).read() };
|
// token[3] = unsafe { response_ptr.add(5).read() };
|
||||||
// println!("Successfully connected to {}. CID: {}, token: {:?}", name, cid, token);
|
// println!("Successfully connected to {}. CID: {}, token: {:?}", name, cid, token);
|
||||||
Some(cid)
|
Some(cid)
|
||||||
} else {
|
} else {
|
||||||
|
|
|
||||||
|
|
@ -561,6 +561,17 @@ pub enum SysCall {
|
||||||
#[cfg(feature = "raw-trng")]
|
#[cfg(feature = "raw-trng")]
|
||||||
RawTrng(usize, usize, usize, usize, usize, usize, usize),
|
RawTrng(usize, usize, usize, usize, usize, usize, usize),
|
||||||
|
|
||||||
|
/// Used for platform specific kernel ABIs. Generally reserved for things like debug,
|
||||||
|
/// performance-monitoring, and power management.
|
||||||
|
///
|
||||||
|
/// ## Arguments
|
||||||
|
/// * In general, the first `usize` is a meta-opcode that helps dispatch what the nature of the
|
||||||
|
/// remaining arguments should be.
|
||||||
|
///
|
||||||
|
/// ## Returns
|
||||||
|
/// Returns a Scalar5, whose ABI is determined by the meta-opcode
|
||||||
|
PlatformSpecific(usize, usize, usize, usize, usize, usize, usize),
|
||||||
|
|
||||||
/// 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),
|
||||||
|
|
@ -618,6 +629,7 @@ pub enum SysCallNumber {
|
||||||
SwapOp = 44,
|
SwapOp = 44,
|
||||||
#[cfg(feature = "raw-trng")]
|
#[cfg(feature = "raw-trng")]
|
||||||
RawTrng = 45,
|
RawTrng = 45,
|
||||||
|
PlatformSpecific = 46,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl SysCallNumber {
|
impl SysCallNumber {
|
||||||
|
|
@ -673,6 +685,7 @@ impl SysCallNumber {
|
||||||
44 => SwapOp,
|
44 => SwapOp,
|
||||||
#[cfg(feature = "raw-trng")]
|
#[cfg(feature = "raw-trng")]
|
||||||
45 => RawTrng,
|
45 => RawTrng,
|
||||||
|
46 => PlatformSpecific,
|
||||||
_ => Invalid,
|
_ => Invalid,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -926,6 +939,9 @@ impl SysCall {
|
||||||
SysCall::RawTrng(a1, a2, a3, a4, a5, a6, a7) => {
|
SysCall::RawTrng(a1, a2, a3, a4, a5, a6, a7) => {
|
||||||
[SysCallNumber::RawTrng as usize, *a1, *a2, *a3, *a4, *a5, *a6, *a7]
|
[SysCallNumber::RawTrng as usize, *a1, *a2, *a3, *a4, *a5, *a6, *a7]
|
||||||
}
|
}
|
||||||
|
SysCall::PlatformSpecific(a1, a2, a3, a4, a5, a6, a7) => {
|
||||||
|
[SysCallNumber::PlatformSpecific as usize, *a1, *a2, *a3, *a4, *a5, *a6, *a7]
|
||||||
|
}
|
||||||
SysCall::Invalid(a1, a2, a3, a4, a5, a6, a7) => {
|
SysCall::Invalid(a1, a2, a3, a4, a5, a6, a7) => {
|
||||||
[SysCallNumber::Invalid as usize, *a1, *a2, *a3, *a4, *a5, *a6, *a7]
|
[SysCallNumber::Invalid as usize, *a1, *a2, *a3, *a4, *a5, *a6, *a7]
|
||||||
}
|
}
|
||||||
|
|
@ -1080,6 +1096,7 @@ impl SysCall {
|
||||||
SysCallNumber::SwapOp => SysCall::SwapOp(a1, a2, a3, a4, a5, a6, a7),
|
SysCallNumber::SwapOp => SysCall::SwapOp(a1, a2, a3, a4, a5, a6, a7),
|
||||||
#[cfg(feature = "raw-trng")]
|
#[cfg(feature = "raw-trng")]
|
||||||
SysCallNumber::RawTrng => SysCall::RawTrng(a1, a2, a3, a4, a5, a6, a7),
|
SysCallNumber::RawTrng => SysCall::RawTrng(a1, a2, a3, a4, a5, a6, a7),
|
||||||
|
SysCallNumber::PlatformSpecific => SysCall::PlatformSpecific(a1, a2, a3, a4, a5, a6, a7),
|
||||||
SysCallNumber::Invalid => SysCall::Invalid(a1, a2, a3, a4, a5, a6, a7),
|
SysCallNumber::Invalid => SysCall::Invalid(a1, a2, a3, a4, a5, a6, a7),
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue