Mark `MemoryRange::as_slice()` and `MemoryRange::as_slice_mut()` as
unsafe.
This is due to the fact that not all representable types can be cast to
an arbitrary value. For example, if Process A sends random values to
Process B, then Process B casts the memory to a slice of `bool`, then
any values that are not 0 or 1 are undefined.
Because these functions can leak UB into the program, they are marked as
unsafe.
This patch adds `unsafe {}` blocks to all instances where this function
is called. Additionally, all instances have been checked to verify that
they do not cast to any invalid types -- most use `u8` or `u32`.
Additionally, the long-deprecated `MemoryRange::from_parts()` call was
removed, since that causes UB without being marked as unsafe.
Signed-off-by: Sean Cross <sean@xobs.io>
Previously, `ProcessStartup' did not have `repr(C)' above it. This
meant that it was using rust layout, which is weird and is not
compatible with `_xous_syscall_return_result'
This change is made with the intention of making the xous-rs crate a bit
more freestanding without depending on the xtask build system.
Signed-off-by: Jean-Pierre De Jesus DIAZ <me@jeandudey.tech>
This way the crate will always fail to compile if it doesn't compile on
no_std.
It being no_std by default won't affect std build of other crates as
no_std and std crates can interop by default.
Signed-off-by: Jean-Pierre De Jesus DIAZ <me@jeandudey.tech>
- make the "base" field no longer public. It is accessible, but only
through an `unsafe` method, because, it is unsafe.
- add accessors to offest/mask fields. Because, it's not at all
unsafe to access these, and it can be useful for bit-ops that are
not part of the generic set of UTRA.
- add Arc to AtomicCSR, and require `std` for AtomicCSR types.
This should not break anything, I checked inside @foundation-devices
keyOS and they don't seem to be using AtomicCSR anywhere.
The Arc makes it a bit safer to clone the AtomicCSR base pointer
and share it between threads, but it will have an impact on performance.
The USB stack (which requires AtomicCSR) was regression testing and the
impact seems minimal.
Recall that the main purpose of AtomicCSR is to provide a CSR accessor
that does not require a mutable reference to the base object. This
can make certain Rust idioms a bit cleaner. We wrap the base accessor
in Arc+Atomic to try and improve the safety of throwing the borrow
checker under the bus, but it's still not perfect because hardware
mutable state can have side-effects within hardware itself that cannot
be modeled or checked by Rust's borrow checker.
Previously we used externally-linked assembly in order to make syscalls.
Now that `asm!()` is stable, use this macro.
This will help to optimize IPC between programs and the kernel.
Additionally, it resolves an unsoundness issue where we were filling in
values on the stack and hoping that Rust didn't reorder the structs.
Signed-off-by: Sean Cross <sean@xobs.io>
Much of the hosted machinery requires the ability to access memory on
syscalls. This feature was overlooked in the previous implementation of
ReplyAndReceiveNext, which caused it to not properly return memory.
Implement the ability to call `.memory()` on ReplyAndReceiveNext
messages.
Note that this requires the use of a sentinal value in the
previously-unused `valid` field.
Signed-off-by: Sean Cross <sean@xobs.io>
This call is used to return values while simultaneously listening for
new messages.
The -legacy suffix is used to disambiguate scalar values, so we know
whether to send Scalar1, Scalar2, or Scalar5 messages.
Signed-off-by: Sean Cross <sean@xobs.io>
This reflects the fact that up until now, the `Message` struct has
merely been the envelope that surrounds the message. It does not contain
any actual Message contents.
Signed-off-by: Sean Cross <sean@xobs.io>
With the addition of scalar5, existing api calls must be updated to take
advantage of it. This will allow `send_message()` to return a `scalar5`.
Signed-off-by: Sean Cross <sean@xobs.io>
Add syscall and return definitions for Scalar5, as well as
ReturnScalar5. This will enable us to pass up to five scalars as a
return from a blockingscalar call.
Signed-off-by: Sean Cross <sean@xobs.io>
The rationale is that xous-rs should have only architecture
specific code, e.g.: riscv, arm, x86, etc. To make other
crates that depend on it not specify the features.
This could be useful when using xous-rs with `libstd`
for example.
Signed-off-by: Jean-Pierre De Jesus DIAZ <me@jeandudey.tech>
Look at `target_os` to determine whether to enter "hosted" mode or not.
If `target_os` is "xous", then the Xous standard library should default
to using builtin Rust libstd features.
If it is "xous", then we should instead use our arch-specific
implementations.
This enables third-party programs to directly use the `xous` crate
without specifying feature flags.
Signed-off-by: Sean Cross <sean@xobs.io>
the Vex has a custom flush instruction, after contacting
charles he recommends maybe adding some nops to make sure it
completes (maybe hardware bug? unclear. we're about to find out.)
This allows for a more reliable detection of target_os configuration
in build scripts. The target is inconsistent between some architectures,
notably armv7a is `armv7a-none-eabi` skipping the `unknown` (the vendor,
I guess) part. This happen with some of the unrelated Cortex-M targets
present, and others may also be.
Signed-off-by: Jean-Pierre De Jesus DIAZ <me@jeandudey.tech>
This will allow for e.g. xous on riscv32-imac but not a precursor
target, for example: by using feature selectors we get to have
a bigger range of targets that we support, such as for implementations
that haven't been upstreamed or have official target-triples.
The downsides are:
- patch override libraries don't absorb feature flags. so, for
example, the AES crate that is used to patch other crates won't
be aware of the target features without modifying the referencing
crates.
- features are normally meant to be additive, but target features
are mutually exclusive. The mutex is enforced by a check in
utralib that throws a panic on build if two targets are accidentally
selected at the same time.
this will help speed up performance profiling as we can
resolve the physical address of the performance buffer allocated
in RAM and use a USB command to read it out, instead of streaming
it over serial.
The ServerID return type was placed in the middle of the results list,
which caused results 8-15 to be shifted by one to become results 9-15,
with result 8 being swapped with result 15.
This fixes this offset.
Signed-off-by: Sean Cross <sean@xobs.io>