Added privilidges
This commit is contained in:
@@ -157,7 +157,14 @@ void kmain(BootInfo *Boot)
|
||||
/* ---- Spawn Starling Terminal as its own task ---- */
|
||||
ctx = (StarlingContext *)kmalloc(sizeof(StarlingContext));
|
||||
...
|
||||
terminal_task = task_create(L"starling-term", starling_terminal_task, ctx);
|
||||
ctx->Boot = Boot;
|
||||
ctx->depth = 0;
|
||||
ctx->shell_priv = TASK_PRIV_USER;
|
||||
|
||||
terminal_task = task_create_with_priv(L"starling-term",
|
||||
starling_terminal_task,
|
||||
ctx,
|
||||
TASK_PRIV_USER);
|
||||
if (terminal_task == NULL) {
|
||||
...
|
||||
starling_terminal_task(Boot);
|
||||
@@ -180,7 +187,7 @@ void kmain(BootInfo *Boot)
|
||||
- `idt_init(Boot)` to install the kernel's Interrupt Descriptor Table and exception handlers.
|
||||
- `memory_init(Boot)` to bring up the physical allocator, paging helpers, and heap.
|
||||
- `task_init(Boot)` to bootstrap the cooperative scheduler and register the current thread as task 0.
|
||||
3. **User interface** – prints a banner and spawns the Starling Terminal as a separate task via `task_create`, then turns the core thread into an idle loop that continuously `task_yield`s to allow other tasks to run.
|
||||
3. **User interface** – prints a banner and spawns the Starling Terminal as a separate task via `task_create_with_priv` with `TASK_PRIV_USER` privilege, then turns the core thread into an idle loop that continuously `task_yield`s to allow other tasks to run.
|
||||
|
||||
At this point, the system has:
|
||||
|
||||
@@ -206,10 +213,12 @@ static void starling_terminal_task(void *arg)
|
||||
return;
|
||||
}
|
||||
|
||||
Boot = ctx->Boot;
|
||||
depth = ctx->depth;
|
||||
Boot = ctx->Boot;
|
||||
depth = ctx->depth;
|
||||
shell_priv = ctx->shell_priv;
|
||||
|
||||
SAFE_PRINT(Boot, L"\n\r[Starling Terminal depth %d] ready.\n\r\n\r", depth);
|
||||
SAFE_PRINT(Boot, L"\n\r[Starling Terminal depth %d, priv %d] ready.\n\r\n\r",
|
||||
depth, (INT32)shell_priv);
|
||||
SAFE_PRINT(Boot, L"starling> ");
|
||||
|
||||
while (TRUE) {
|
||||
@@ -234,7 +243,7 @@ static void starling_terminal_task(void *arg)
|
||||
trim_spaces_inplace(line);
|
||||
...
|
||||
} else {
|
||||
Task *cmd_task = execute_command(Boot, line);
|
||||
Task *cmd_task = execute_command(Boot, line, shell_priv);
|
||||
|
||||
/* If a command task was spawned, wait for it to finish. */
|
||||
if (cmd_task != NULL) {
|
||||
@@ -258,7 +267,7 @@ Key points:
|
||||
|
||||
- **Non-blocking idle**: when `try_read_key` returns no key, the terminal calls `task_yield()` so other tasks can run while the user is idle.
|
||||
- **Line editing**: handles printable ASCII and backspace to maintain a simple line buffer (`line[128]`).
|
||||
- **Command execution**: on Enter, the line is trimmed and passed to `execute_command(Boot, line)` in `commands.c`. If that function spawns a dedicated command task, the terminal waits for it via `task_wait`.
|
||||
- **Command execution**: on Enter, the line is trimmed and passed to `execute_command(Boot, line, shell_priv)` in `commands.c`, propagating the shell's privilege level. If that function spawns a dedicated command task, the terminal waits for it via `task_wait`.
|
||||
- **Nested terminals**: entering `starling` recursively spawns another Starling Terminal task with increased `depth`, demonstrating multi-level shells.
|
||||
|
||||
The command registry and dispatch path are documented in detail in `commands-and-terminal.md`.
|
||||
@@ -278,15 +287,17 @@ The kernel is organised into focused subsystems, each in its own translation uni
|
||||
- **Tasks and scheduler** (`task.c` + `task.h`):
|
||||
- Static process control block (PCB) pool.
|
||||
- Cooperative round-robin scheduler.
|
||||
- Software privilege levels (`TASK_PRIV_USER`, `TASK_PRIV_DRIVER`, `TASK_PRIV_KERNEL`) for access control.
|
||||
- Stack management and context switch support (via an external `context_switch` assembly routine).
|
||||
- **Interrupts and exceptions** (`idt.c` + `idt.h`):
|
||||
- IDT mirroring of firmware entries.
|
||||
- Replacement of CPU exception vectors 0–31 with kernel stubs.
|
||||
- Central `isr_handler` that prints diagnostics and halts on unrecoverable faults.
|
||||
- **Commands and shell** (`commands.c` + `commands.h`):
|
||||
- Command registry and help/man system.
|
||||
- Command registry with per-command minimum privilege levels and help/man system.
|
||||
- System control commands (`shutdown`, `about`, `mem`, `ps`).
|
||||
- Test commands (`memtest`, `tasktest`, `spawn`) that exercise memory and scheduler subsystems in isolation.
|
||||
- Privilege escalation command (`kusr`) for running commands with elevated privilege.
|
||||
|
||||
Each of these subsystems is covered in a dedicated document:
|
||||
|
||||
|
||||
Reference in New Issue
Block a user