| Crates.io | tg-kernel-context |
| lib.rs | tg-kernel-context |
| version | 0.1.0-preview.1 |
| created_at | 2026-01-22 12:47:58.894586+00 |
| updated_at | 2026-01-22 12:47:58.894586+00 |
| description | Kernel context management for rCore tutorial OS, including task context switching. |
| homepage | https://github.com/rcore-os/rCore-Tutorial-in-single-workspace |
| repository | https://github.com/rcore-os/rCore-Tutorial-in-single-workspace/tree/tg-preview |
| max_upload_size | |
| id | 2061476 |
| size | 24,960 |
Kernel context management for the rCore tutorial operating system.
This crate provides context switching primitives for RISC-V based kernel development. It handles the low-level details of saving and restoring CPU state during context switches between kernel and user space.
foreign feature)use tg_kernel_context::LocalContext;
// Create a user-mode context with entry point
let ctx = LocalContext::user(entry_point);
// Create a kernel thread context
let ctx = LocalContext::thread(entry_point, true);
// Execute the context (unsafe - modifies CPU state)
unsafe {
let sstatus = ctx.execute();
}
foreign - Enable support for context switching across different address spacesThe execute method is unsafe as it directly manipulates critical CSRs (sscratch, sepc, sstatus, stvec) and performs a privilege level switch.
Licensed under either of MIT license or Apache License, Version 2.0 at your option.