These calls can be used to print out thread information for debugging.
This augments the existing `print_thread()` call, which has been renamed
to `print_current_thread()`.
Signed-off-by: Sean Cross <sean@xobs.io>
Due to several errors, multi-page lending did not work properly.
To begin with, if a page was not allocated then it would not be able to
be sent. That is, if you allocated 8192 bytes but only ever accessed the
first 4096 bytes, then an error would be encountered when lending the
unaccessed upper page.
Furthermore, due to a striding error in accessing pointers, half-pages
were treated as full pages.
Signed-off-by: Sean Cross <sean@xobs.io>
This brings intra-process lending in-line with intra-process sending,
where memory is not remapped the pointer is simply reused.
We may change this at a later point in order to further enforce the
concept of lent-memory-is-inaccessible, so do not rely in this behavior.
Signed-off-by: Sean Cross <sean@xobs.io>
This implements a syscall to shut down a server. Servers may not be shut
down if they have outstanding messages that they have seen but not
responded to.
Signed-off-by: Sean Cross <sean@xobs.io>
When moving memory between processes, update the owner of that page to
match the new PID. Otherwise, memory can never be released.
Signed-off-by: Sean Cross <sean@xobs.io>
The `current_thread` variable is used to determine which thread to
switch back to after a context switch occurs. Keep track of the thread
more closely.
Signed-off-by: Sean Cross <sean@xobs.io>
This will enable us to have more information about the result that is
returned when mutable memory is modified by a server.
Signed-off-by: Sean Cross <sean@xobs.io>
The `can_resume` variable doesn't change, and can be made a constant.
This slightly improves reasoning about what the function is doing.
Signed-off-by: Sean Cross <sean@xobs.io>
This reworks the server queue to add a "generation counter". This
counter ensures messages are removed from the queue in the order they
were added, even if they are jumbled up within the queue itself.
Signed-off-by: Sean Cross <sean@xobs.io>
Instead of queueing the client thread number inside the server, queue
the server's thread number inside the server.
This prevents many spooky messages that were occurring when server
queues got full.
Signed-off-by: Sean Cross <sean@xobs.io>
If we switch to a thread and specify a thread ID, remember that as the
current thread ID.
This prevents thread starvation by repeatedly going back to the same
thread ID.
Signed-off-by: Sean Cross <sean@xobs.io>
Previously, we would only look at the top item on the server queue. If
it was not a known message, we would return an error.
This patch changes this behavior to look through the entire queue for
something we can take, and then clean it up as we go along.
This allow for having outstanding requests in the queue an forms the
backbone of the sleep server.
Signed-off-by: Sean Cross <sean@xobs.io>
When claiming an IRQ, we used to disable interrupts.
This is unnecessary, as interrupts are already disabled when running in
kernel mode.
Signed-off-by: Sean Cross <sean@xobs.io>
Keep interrupts nominally disabled in supervisor mode, and only enable
them for a brief period after WFI hits.
If an interrupt occurs, then WFI becomes a NOP. The `idle()` function is
only called when no more processes are running, which happens when all
processes are waiting for an interrupt.
Therefore, enable interrupts for a brief period when WFI returns in
order to drain all pending interrupts and return to the caller to handle
any change in the process table.
Signed-off-by: Sean Cross <sean@xobs.io>
When the kernel is running its main loop, interrupts are disabled as it
is running in supervisor mode.
As a result, we can ignore any interrupt enabling/disabling that may
need to occur.
Signed-off-by: Sean Cross <sean@xobs.io>
This feature works around a bug in Renode where unwrapped lines cause it
to crash. This forces columns to be wrapped at 80 characters.
Signed-off-by: Sean Cross <sean@xobs.io>
This fixes the case where there is only one process active and it tries
to send messages to itself, or it yields to itself.
This closes issue #42.
Signed-off-by: Sean Cross <sean@xobs.io>
This allows us to use println early on even before it's initialized,
which will allow us to ignore prints to an uninitialized port.
Signed-off-by: Sean Cross <sean@xobs.io>
Memory that was marked as reserved-but-not-in-use could get reallocated.
Practically speaking, this caused threads to share stack, which makes
things spooky.
Signed-off-by: Sean Cross <sean@xobs.io>
the code originally would pick the same thread over and over again
this fix starts the thread search at one plus the current thread
wrapping around to one plus the current thread, so we always try
to pick a new thread compared to the current one, instead of
generally picking the same thread most of the time.
When a page is shared, only report an address as being available when
we receive a `BadAddress` error when doing the translation. Otherwise,
assume it is in use.
Signed-off-by: Sean Cross <sean@xobs.io>
When memory has been shared, it is no longer valid. However, it is still
"in use".
Return a `ShareViolation` error in this case so we can check for it
elsewhere.
Signed-off-by: Sean Cross <sean@xobs.io>
Initially, we wanted to be able to immutably lend data in a one-to-many
fashion. However, this has proven challenging, and doesn't have any
immediately obvious useful benefits.
For now, only allow one-to-one immutable lends.
Signed-off-by: Sean Cross <sean@xobs.io>
Instead of hardcoding bit values, use the symbolic names. This will
ensure we don't make mistakes by using magic numbers.
Signed-off-by: Sean Cross <sean@xobs.io>
In an effort to homogonize platforms, we are moving away from `usize` in
favour of `u32`. Allow the `CID` type to be a `u32` in the kernel by
casting it to a `usize` as necessary.
Signed-off-by: Sean Cross <sean@xobs.io>
When allocating a page, it is only assigned a physical address once it
is actually needed. This on-demand paging works well, however we were
assuming that the first address of a page was accessed first.
This fixes an issue where a Message is allocated but the first byte
isn't accessed first.
Signed-off-by: Sean Cross <sean@xobs.io>
This tracks a variable that has been renamed, and was preventing the
kernel from compiling when debug printing is enabled.
This fixes#19.
Signed-off-by: Sean Cross <sean@xobs.io>
When compiling under non-test scenarios, the `rand` create conflicts
with the new `rand` module.
Disambiguate this field.
Signed-off-by: Sean Cross <sean@xobs.io>
Servers will, by default, get randomly-assigned SIDs. Certain servers
will want to have well-known SIDs, such as the log server or the
nameserver. These will use a separate call in order to perform this
priveledged operation.
A subsequent patch will add `CreateServer`.
Signed-off-by: Sean Cross <sean@xobs.io>
This parameter will determine whether a syscall is being handled from
within an interrupt context. This is because certain calls cannot be
called from such a context.
Signed-off-by: Sean Cross <sean@xobs.io>
This fixes issues regarding passing memory between processes.
We now properly catch `ReturnMemory` and give the memory back.
Signed-off-by: Sean Cross <sean@xobs.io>
These didn't correctly set the thread status in the server when
returning a value. Instead of marking a server as runnable, it remained
in an idle state.
This correctly sets the thread status in the server, and resumes the
client.
This has been tested in Renode as well as using `cargo test`.
Signed-off-by: Sean Cross <sean@xobs.io>
This function is used to decrement the program counter to re-run a given
instruction. This can be used as a cheap way to implement blocking
calls.
Signed-off-by: Sean Cross <sean@xobs.io>
this cleans up some namespace issues when including
the utra crate which also refers to utra::generated::utra,
and there are CONST at the crate-level, and also functions
at the module-level which need disambiguation. By naming
the crate utra-lib this saves a bit of syntatic wrangling
at the top of every file.
This adds svd2utra, which enables building for non-embedded harware.
It also fixes some build issues, and paves the way for generating UTRA
at compile-time.
Signed-off-by: Sean Cross <sean@xobs.io>
The `sender` was, previously, somewhat mislabeled. It was a combination
of PID and TID, except when it wasn't.
Instead, make this value a combination of ConnectionID and queue index.
This makes it easier to reason about which connection we're responding
to.
Additionally, don't expose teh global Server Index Table to userspace
programs.
Signed-off-by: Sean Cross <sean@xobs.io>
This fixes issue #1, which correctly noted the comment was correct but
the code implementation was not correct.
Signed-off-by: Sean Cross <sean@xobs.io>
Previously, each process could return one chunk of memory. With this
change, processes can now return one chunk of memory per thread. This
enables multiple threads to lend memory to a server.
Signed-off-by: Sean <xobs@ci.betrusted.io>
With the introduction of TrySendMessage, the kernel needs to know that
this data structure should be transmitted over the wire in the same
manner as SendMessage. Previously it was not special-casing this, which
resulted in memory errors.
Signed-off-by: Sean <xobs@ci.betrusted.io>
When the message coming in from the client to a server changes, print
an informative message rather than just "left != right".
Signed-off-by: Sean <xobs@ci.betrusted.io>
When running on Linux, attempting to shut down a network socket that
has already been closed results in an error. That is, if the client
disconnects, then the server will throw an error when it also attempts
to disconnect.
Ignore errors to `.shutdown()` to fix `cargo test` on Linux.
Signed-off-by: Sean Cross <sean@xobs.io>
Server IDs were being improperly indexed, resulting in a
probably-invalid server index being returned.
Adjust these so that correct server indices are returned.
Signed-off-by: Sean Cross <sean@xobs.io>
Cargo appears to cache packages in the workspace when multiple packages
use the same crate. Unfortunately, Xous uses different features
depending on whether it's running in the kernel or in userspace.
Pull the kernel version of "xous" in under a different namespace in
order to force it to use a different build.
Signed-off-by: Sean Cross <sean@xobs.io>