Commit graph

511 commits

Author SHA1 Message Date
bunnie
3f869ca389 bump utralib version for publication 2026-01-29 19:12:00 +08:00
bunnie
fba011db3a commit version bump so that we may publish our packages 2026-01-08 03:04:19 +08:00
bunnie
5be0ddbd0f 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.
2026-01-08 02:40:13 +08:00
bunnie
d623dc723e tech debt: add more error codes
since the swap update is going to require republishing the
Xous-rs crate, I'm adding a bunch of more descriptive error codes
that I wish Xous could have, and documented the cases in which
they would be used.

This makes it a bit easier to propagate errors up the stack on
more of the calls, at the expense of a more complicated error
type.
2026-01-08 02:22:23 +08:00
bunnie
e27b30d818 fix edge case in swapper
A particular edge case was finally reproduced & fixed. The edge
case occurs when a swap is triggered while handling an interrupt,
and an OOM happens during the context switch to/from the interrupt.

The background on this is that the hardware drivers for the swapper,
as well as much of the logical heavy lifting on e.g. what pages to
swap out, live in a userspace process known as xous-swapper.

The userspace process has to run free of interrupts - when you're
OOM'd or trying to swap, interrupts should not happen. The way to
do this in Xous is to run that code inside an interurpt context,
as interrupts are not interruptable.

Thus, the xous swapper userspace consists of two halves: a regular
userspace stub that provides some amount of control/debug over
the swapper, and a handler that gets run in a "pseudo-interrupt"
context.

Like all other interrupts, the handler "borrows" the stack of the currently
running thread - interrupt contexts don't have an explicit stack, they
just grow on top of the current stack of the current thread in the
current process at the time of the interrupt.

This is broken because when you have a swap event inside an interrupt
context, there are conditions where you might not have a stack. What
was in fact happening is that the stack pointer was being orphaned
as being the "exception stack" - which is a temporary location,
only accessible by the kernel, used for storing all the registers
going into and out of exceptions. Since no stack pointer is set up,
the moment the userspace starts to run and spill its registers to
stack, the system trips a "nested swap" event, which leads to a panic
because this is not allowed.

The fix to this is to devote two hard-wired pages, mapped in the
loader, to be the swapper's private stack area. Instead of behaving
like an interrupt and borrowing the caller's stack, the swapper instead
goes back to its hard-wired stack to do all the processing.

This should also improve the performance of swap handling in some
cases because we can now guarantee the stack is always in-memory
and doesn't need to be swapped in during swap processing.

One complication is that the "reserved memory" that the swapper
puts aside in case it *does* need to allocate extra pages during
handling can't be freed at the top of the OOM routine. Thus if
the swapper ends up using new pages, we should expect yet another
crash.

However, in practice, this doesn't seem to happen, because the
cases in which we hit needing a new page are typically related
to cases early on in boot where superpages/new page table entries
are being allocated, or if we're growing the heap that passes
data back and forth between swap and userspace. Because this call
triggers in such a specific condition, I hypothesize that actually
in practice it should generally be able to run without allocations.

One case where maybe it could hit an allocation is if the swapper
hit, for the first time, in an interrupt handler that was swapped
out, and never hit before, and the interrupt handler needed a
superpage to be allocated, thus triggering an allocation request
for a new PTE or two. I think this is probably pretty unlikely, but
if we do hit it, the fix would be to, for the purposes of targets
with "swap" enabled, to mark unmap_memory and map_memory to be
legal syscalls in interrupt contexts. These are normally illegal
because interrupts should always return - and these calls could
potentially fail or block. However, I think in this case it's
a trade-off between "we should be failing if we run out of memory"
and that failure being a potentially incorrect behavior that is guarded
against by a runtime check to discourage such calls.
2026-01-08 02:08:03 +08:00
bunnie
d874c3e5c2 commit for version bump 2025-12-16 02:02:37 +08:00
bunnie
dbb0a75118 bump versions
have to absorb a version change due to xous-semver change

might as well also update the utra/svd generator dependencies
since that's been held off for a long time now.
2025-10-06 13:23:18 +08:00
bunnie
e2379821e6 republish xous-rs to fix cargo test 2025-05-11 15:36:17 +08:00
bunnie
041369b059 add missing defines to the arch target of test/mem.rs 2025-05-11 15:34:30 +08:00
bunnie
8a4959056b bump version for xous crate update - commit so we can publish crates 2025-05-11 14:45:24 +08:00
bunnie
f8978d7511 move platform-specific locations into the xous-rs crates
This enables a couple of things that have been long wanting, including:

- the ability to know what PAGE_SIZE is from a single central define
- the ability to determine where certain virtual memory ranges are
located (useful for the userspace swapper).

Previously these were "hidden" from crates because they were embedded
directly in the kernel implementation module, which is not accessible
as a dependency, thus causing us to e.g. create redundant copies of
the PAGE_SIZE variable. This hopefully makes migrating to a larger
page size in some future version of the OS a bit simpler.
2025-05-11 12:27:41 +08:00
bunnie
5945634f5e add a flag for memory that is allocated as swapped
this indicates to the OS to reserve the virtual pages for
the memory, mark them as swapped, but don't actually put
anything in physical memory.
2025-05-11 12:26:47 +08:00
bunnie
75954de8d6 commit the version bump 2024-09-23 01:46:25 +08:00
bunnie
bb7209508b update formatting on the published crates
not doing a reformat of the entire project to match
nightly formatting changes, but capturing the published
crates so we can maybe save a version bump later on to get
the project clean.
2024-09-23 01:43:02 +08:00
bunnie
311154e231 absorb version bump 2024-06-27 00:26:12 +08:00
bunnie
84f33b61e9 we're going to have to bump all the pins because *formatting*
Cargo changed how it decided to format some comments in one of
our key dependency crates, which is breaking all of our CI checks.

This fixes that. *sigh*.
2024-06-27 00:22:27 +08:00
bunnie
a360f3ee52 bump xous pins for RawTrng API 2024-06-13 15:49:35 +08:00
bunnie
ed2b5ec84d add RawTrng SysCall to Xous API
This SysCall is introduced because not all hardware targets can
afford the luxury of a private TRNG port for the kernel.

In this case, an API is needed to exfiltrate random numbers from
the kernel so we can inspect them and check them for health.

If a TRNG is operating correctly, cherry-picking some values
out of it to QC the operation of the TRNG should be harmless.

Of course, nothing is truly stateless, and there is always a chance
that someone could construct a gadget using this to reduce the
potential state-space of the final random number generator. Therefore,
this API is (a) gated behind a feature flag and (b) any implementation
that plans to expose this should be coded with some countermeasures
to reduce data leakage after sampling.
2024-06-13 15:33:14 +08:00
bunnie
35e7cf3a5b bump xous dep revs 2024-05-29 02:07:06 +08:00
bunnie
b9856c8f1d fix various typos and annotate Debug derives 2024-05-29 02:05:27 +08:00
bunnie
a0fec13016 make the SwapOp syscall allowable to call in an interrupt context
SwapOp is guaranteed to return eventually, so, it's technically
not blocking; it's merely very slow.

also fix a number of typos
2024-05-29 02:04:44 +08:00
bunnie
9e66c1bee2 commit the version bump 2024-05-07 01:03:05 +08:00
bunnie
73414ff9d5 some ABI changes
- make the swapper API fully generic, so we don't have to change
the application ABI as the swapper requirements evolve
- assign the invalid opcode to a fixed number, so it doesn't move
between dissimilar versions.
2024-05-07 00:55:45 +08:00
bunnie
d6b33159a5 stage version pin bump 2024-04-01 15:46:26 +08:00
bunnie
39d549e9a0 cleanup hosted mode warnings 2024-04-01 15:38:32 +08:00
bunnie
6c4e899a5a cleanup comment formatting 2024-04-01 15:38:07 +08:00
bunnie
ed5dd7e538 fix argument order bug
just a dumb typo
2024-03-23 11:59:31 +08:00
bunnie
b62a639031 move AllocAdvice record to externally visible xous-rs definitions
this structure moves between swapper and userland.
2024-03-23 11:59:31 +08:00
bunnie
fac6a43b19 add arguments for handler and state to registration 2024-03-23 11:59:31 +08:00
bunnie
505dce8343 define the swapper PID 2024-03-23 11:59:31 +08:00
bunnie
47e1ae2141 add EvictPage implementation 2024-03-23 11:59:31 +08:00
bunnie
496d13b157 create swapper syscall entries; implement RegisterSwapper 2024-03-23 11:59:31 +08:00
bunnie
c1af9f32da set up for swap mods 2024-03-23 11:59:31 +08:00
bunnie
699004e7b0 bump xous pins 2024-02-06 14:49:10 +08:00
Sean Cross
058db866fe xous: support riscv32imac-unknown-none-elf
The kernel must go back to using this target, as the primary target no
longer supports building with `panic = "abort"`.

Signed-off-by: Sean Cross <sean@xobs.io>
2024-02-06 10:27:11 +08:00
bunnie
0267a56989 format Cargo.tomls
because apparently cargo fmt doesn't format Cargo.toml files???
2024-01-15 00:14:39 +08:00
bunnie
208c02f5af strip trailing whitespace on xous-rs 2024-01-15 00:00:53 +08:00
bunnie
1917c07a35 format xous-rs 2024-01-14 23:10:29 +08:00
bunnie
fda782663a bump version pins for xous change 2023-12-26 00:13:10 +08:00
bunnie
fa3f349a0a bump pins as xous-rs has changed 2023-12-01 21:20:01 +08:00
Jean-Pierre De Jesus DIAZ
b265985f06
xous-rs: Change into_iter to iter. 2023-12-01 11:47:37 +01:00
Jean-Pierre De Jesus DIAZ
2331086755
xous-rs: Omit 'static lifetime on consts. 2023-12-01 11:47:37 +01:00
Jean-Pierre De Jesus DIAZ
c85658def9
xous-rs: Do not pass reference to command args. 2023-12-01 11:47:37 +01:00
Jean-Pierre De Jesus DIAZ
b4e020b027
xous-rs: Simplify TcpStream::connect. 2023-12-01 11:47:37 +01:00
Jean-Pierre De Jesus DIAZ
0a1382224a
xous-rs: hosted: Do not pass &mut data.
data is already a &mut [_] so we were passing &mut &mut [_].
2023-12-01 11:47:37 +01:00
Jean-Pierre De Jesus DIAZ
94737e9be2
xous-rs: Simplify return expressions. 2023-12-01 11:47:37 +01:00
Jean-Pierre De Jesus DIAZ
0141378192
xous-rs: Remove reference on self match. 2023-12-01 11:47:37 +01:00
Jean-Pierre De Jesus DIAZ
6c9cc968f6
xous-rs: Remove usize castings when not necessary. 2023-12-01 11:47:37 +01:00
Jean-Pierre De Jesus DIAZ
9a393ed0aa
xous-rs: Fix doc comment warning. 2023-12-01 11:25:39 +01:00
Jean-Pierre De Jesus DIAZ
fd98acc82e
xous-rs: Remove build.rs.
Not used so it's best to remove it to avoid compiling it.

Signed-off-by: Jean-Pierre De Jesus DIAZ <me@jeandudey.tech>
2023-12-01 11:10:25 +01:00