Correctly handle transitions to and from exception handling.
Previously, the thread ID was incorrectly set such that the exception
handler became a valid thread. This has been adjusted so that the
exception handler is no longer considered a thread, and all other
threads will cease scheduling during this process.
Signed-off-by: Sean Cross <sean@xobs.io>
Memory is on-demand allocated, meaning it's entirely possible to
allocate and free memory without ever touching physical pages.
Previously, when we attempted to free memory, it would skip over pages
that were never backed by real memory.
With this patch, we continue to free the virtual page even if there is
no associated physical page.
Signed-off-by: Sean Cross <sean@xobs.io>
Memory is on-demand allocated, meaning it's entirely possible to
allocate and free memory without ever touching physical pages.
Previously, when we attempted to free memory, it would skip over pages
that were never backed by real memory.
With this patch, we continue to free the virtual page even if there is
no associated physical page.
Signed-off-by: Sean Cross <sean@xobs.io>
If a process is currently running, it needs to be placed into the
`Debug` state rather than the `Ready` state.
Additionally, the process that's being switched to must enter the
`Running` state.
Signed-off-by: Sean Cross <sean@xobs.io>
If a process fails for some reason (e.g. by performing a fault) and
there is no exception handler, either terminate the process or (if
gdbserver is enabled) have it suspend the process.
Signed-off-by: Sean Cross <sean@xobs.io>
Previously, we were creating a stack beginning at the initial page,
and then growing it upwards. The correct behavior is to begin it at
the top and grow it downwards.
In order to do this, subtract the size of the stack from the initial
pointer.
Signed-off-by: Sean Cross <sean@xobs.io>
This fixes the exception handler so that it can support user-defined
exceptions. Additionally, kernel mode errors are called out now.
Signed-off-by: Sean Cross <sean@xobs.io>
When the program counter is NULL, we can still get exceptions. This
happens when we jump to an invalid address, for example.
Signed-off-by: Sean Cross <sean@xobs.io>
This compresses the entirety of the memory range finder into a single
statement. As a result, duplicate code is removed and we can elide more
range checks.
Signed-off-by: Sean Cross <sean@xobs.io>
By vendoring this package, we can avoid causing a rebuild unnecessarily.
This will be removed when Rust 1.55 is released and we can bring the
`kernel` package back into the main workspace.
Signed-off-by: Sean Cross <sean@xobs.io>
This fixes the MemoryRange refactor where `.addr` and `.size` are now
private fields.
Previously it had only been tested on baremetal mode.
Signed-off-by: Sean Cross <sean@xobs.io>
Mark the private fields in a `MemoryRange` struct as being private. This
allows us to perform operations on the memory range armed with the
knowledge that the entire range is valid and unaliased.
Signed-off-by: Sean Cross <sean@xobs.io>
Since `MemoryRange::new()` is now unsafe, add an `unsafe {}` note when
calling this function on Hosted mode.
This fixes the build.
Signed-off-by: Sean Cross <sean@xobs.io>
This function allows for creating arbitrary memory ranges. Mark this
function as `unsafe` in order to warn users that this can be used to
create invalid memory regions.
Signed-off-by: Sean Cross <sean@xobs.io>
This allows us to support different printers in the kernel. For example,
this can be used to swap out the println!() function to print to GDB
when a debugger is attached.
Signed-off-by: Sean Cross <sean@xobs.io>
Ensure pages of memory can be written to when we write to them. This
lets us patch program code to, for example, insert breakpoints.
Signed-off-by: Sean Cross <sean@xobs.io>
When running in CI, cause processes to panic rather than waiting for a
debugger to attach. This will ensure test failures are caught sooner
rather than later.
Signed-off-by: Sean Cross <sean@xobs.io>
Switch to the message client when returning memory in Hosted mode. This
properly marks a process as ready-to-run, which was otherwise not
correctly done.
Signed-off-by: Sean Cross <sean@xobs.io>
This changes the `p` command to only print processes, and renames the
existing behavior to `P` which prints processes and threads.
Signed-off-by: Sean Cross <sean@xobs.io>
This enables processes to be "suspended" by going into a Debug state.
Messages will back up and processes will continue to be scheduled around
the suspended process, while the system will continue to operate.
Signed-off-by: Sean Cross <sean@xobs.io>
When a process is terminated, we disconnect it from all other processes.
We also need to free the slot in the server table.
Signed-off-by: Sean Cross <sean@xobs.io>