feat: Add Rust Base64 codec, Process hierarchy (pstree, kill), and VFS visual tree/find applets

- Implement memory-safe RFC-4648 Base64 encoder and decoder in rust/src/crypto/base64.rs
- Add process parent hierarchy tracking (ppid, pgid), task_find_by_pid, task_kill, and task_dump_pstree in kernel/task.c
- Add list_for_each_entry macro in include/lib/list.h
- Add LazyBox applets: 'base64', 'pstree', 'kill', 'tree', 'find', and 'traceroute'
This commit is contained in:
subhobhai943 committed 2026-08-18 20:50:58 +05:30
1 parent a8b0eae694
commit cda9735b09
8 files changed
+443 -1

No files matched your search

+74 -1
View File
@@ -1,5 +1,6 @@
#include <kernel/task.h>
#include <kernel/sched.h>
#include <kernel/printk.h>
#include <mm/kmalloc.h>
#include <lib/string.h>
#include <arch/arch.h>
@@ -7,6 +8,7 @@
static pid_t next_pid = 1;
static task_t* current_task = NULL;
static task_t kernel_idle_task;
static LIST_HEAD(global_tasks);
static void task_wrapper(task_entry_fn_t entry, void* arg) {
if (entry) {
@@ -20,6 +22,8 @@ task_t* task_create(const char* name, task_entry_fn_t entry, void* arg, int prio
if (!task) return NULL;
task->pid = next_pid++;
task->ppid = current_task ? current_task->pid : 0;
task->pgid = task->pid;
strncpy(task->name, name ? name : "task", sizeof(task->name) - 1);
task->state = TASK_STATE_READY;
task->priority = priority;
@@ -43,14 +47,17 @@ task_t* task_create(const char* name, task_entry_fn_t entry, void* arg, int prio
task->rsp = (uint64_t)stack_top;
INIT_LIST_HEAD(&task->list);
INIT_LIST_HEAD(&task->all_list);
list_add_tail(&task->all_list, &global_tasks);
sched_add_task(task);
return task;
}
void task_exit(int exit_code) {
(void)exit_code;
if (current_task && current_task->pid != 0) {
current_task->exit_code = exit_code;
current_task->state = TASK_STATE_DEAD;
sched_remove_task(current_task);
sched_yield();
@@ -72,11 +79,77 @@ void task_set_current(task_t* task) {
current_task = task;
}
task_t* task_find_by_pid(pid_t pid) {
if (pid == 0) return &kernel_idle_task;
task_t* pos;
list_for_each_entry(pos, &global_tasks, all_list) {
if (pos->pid == pid) {
return pos;
}
}
return NULL;
}
int task_kill(pid_t pid, int sig) {
if (pid == 0) {
printk(ANSI_RED "Error: cannot signal swapper/0 (PID 0)\n" ANSI_RESET);
return -1;
}
task_t* t = task_find_by_pid(pid);
if (!t) {
printk(ANSI_RED "kill: (%d) - No such process\n" ANSI_RESET, pid);
return -1;
}
printk(ANSI_YELLOW "Signal %d sent to process '%s' (PID %d)\n" ANSI_RESET, sig, t->name, pid);
if (sig == 9 || sig == 15) { // SIGKILL / SIGTERM
t->state = TASK_STATE_DEAD;
sched_remove_task(t);
}
return 0;
}
static void print_process_tree_node(task_t* parent, int depth) {
for (int i = 0; i < depth; i++) {
printk(" │ ");
}
const char* state_col = (parent->state == TASK_STATE_RUNNING) ? ANSI_BRIGHT_GREEN :
(parent->state == TASK_STATE_READY) ? ANSI_BRIGHT_CYAN : ANSI_YELLOW;
printk(" ├─ " ANSI_BOLD "%s" ANSI_RESET " (pid: " ANSI_BRIGHT_YELLOW "%d" ANSI_RESET ", %s%s" ANSI_RESET ")\n",
parent->name, parent->pid, state_col,
parent->state == TASK_STATE_RUNNING ? "RUNNING" :
parent->state == TASK_STATE_READY ? "READY" :
parent->state == TASK_STATE_SLEEPING ? "SLEEP" : "BLOCKED");
task_t* pos;
list_for_each_entry(pos, &global_tasks, all_list) {
if (pos->ppid == parent->pid && pos != parent && pos->state != TASK_STATE_DEAD) {
print_process_tree_node(pos, depth + 1);
}
}
}
void task_dump_pstree(void) {
printk(ANSI_BRIGHT_CYAN "=== SUB-OS Process Tree Hierarchy (pstree) ===\n" ANSI_RESET);
printk(ANSI_BOLD "systemd/init (PID 1)\n" ANSI_RESET);
task_t* pos;
list_for_each_entry(pos, &global_tasks, all_list) {
if (pos->ppid <= 1 && pos->state != TASK_STATE_DEAD) {
print_process_tree_node(pos, 0);
}
}
}
void task_init_idle(void) {
memset(&kernel_idle_task, 0, sizeof(task_t));
kernel_idle_task.pid = 0;
kernel_idle_task.ppid = 0;
kernel_idle_task.pgid = 0;
strcpy(kernel_idle_task.name, "swapper/0");
kernel_idle_task.state = TASK_STATE_RUNNING;
INIT_LIST_HEAD(&kernel_idle_task.list);
INIT_LIST_HEAD(&kernel_idle_task.all_list);
INIT_LIST_HEAD(&global_tasks);
current_task = &kernel_idle_task;
}