mirror of
https://github.com/JannisHeydemann/BoredOS.git
synced 2026-05-30 02:16:58 +00:00
CHECKP: multi-thread applications
This commit is contained in:
@@ -59,7 +59,17 @@ uint64_t exception_handler_c(registers_t *regs) {
|
||||
serial_write(buf);
|
||||
|
||||
if ((regs->cs & 0x3) != 0) {
|
||||
serial_write("\nUSER MODE EXCEPTION - Terminating process.\n");
|
||||
serial_write("\n*** USER MODE EXCEPTION ***\nVector: 0x");
|
||||
k_itoa_hex(vector, buf);
|
||||
serial_write(buf);
|
||||
serial_write("\nRIP: 0x");
|
||||
k_itoa_hex(regs->rip, buf);
|
||||
serial_write(buf);
|
||||
serial_write("\nError Code: 0x");
|
||||
k_itoa_hex(regs->err_code, buf);
|
||||
serial_write(buf);
|
||||
serial_write("\nTerminating process.\n");
|
||||
|
||||
if (cmd_get_cursor_col() != 0) cmd_write("\n");
|
||||
cmd_write("*** USER EXCEPTION ***\nVector: "); cmd_write_hex(vector);
|
||||
cmd_write("\nRIP: "); cmd_write_hex(regs->rip);
|
||||
@@ -234,6 +244,9 @@ void idt_register_interrupts(void) {
|
||||
extern void isr_sched_ipi_wrapper(void);
|
||||
idt_set_gate(0x41, isr_sched_ipi_wrapper, cs, 0x8E);
|
||||
|
||||
// Syscall Handler (vector 128) - DPL 3 for user access
|
||||
extern void isr128_wrapper(void);
|
||||
idt_set_gate(128, isr128_wrapper, cs, 0xEE);
|
||||
}
|
||||
|
||||
void idt_load(void) {
|
||||
|
||||
@@ -16,14 +16,18 @@ static volatile uint32_t *lapic_base = 0;
|
||||
#define LAPIC_ICR_LOW (0x300 / 4)
|
||||
#define LAPIC_ICR_HIGH (0x310 / 4)
|
||||
|
||||
void lapic_enable(void) {
|
||||
if (!lapic_base) return;
|
||||
// Enable the LAPIC by setting the Spurious Interrupt Vector Register
|
||||
// Bit 8 = APIC Software Enable, vector = 0xFF (spurious)
|
||||
lapic_base[LAPIC_SVR] = 0x1FF;
|
||||
}
|
||||
|
||||
void lapic_init(void) {
|
||||
extern uint64_t hhdm_offset;
|
||||
lapic_base = (volatile uint32_t *)(hhdm_offset + 0xFEE00000ULL);
|
||||
|
||||
// Enable the LAPIC by setting the Spurious Interrupt Vector Register
|
||||
// Bit 8 = APIC Software Enable, vector = 0xFF (spurious)
|
||||
lapic_base[LAPIC_SVR] = 0x1FF;
|
||||
|
||||
lapic_enable();
|
||||
serial_write("[LAPIC] Initialized at HHDM + 0xFEE00000\n");
|
||||
}
|
||||
|
||||
|
||||
@@ -12,6 +12,9 @@
|
||||
// Initialize LAPIC access (maps registers via HHDM)
|
||||
void lapic_init(void);
|
||||
|
||||
// Enable LAPIC (set SVR bit 8)
|
||||
void lapic_enable(void);
|
||||
|
||||
// Send End-of-Interrupt to the local APIC
|
||||
void lapic_eoi(void);
|
||||
|
||||
|
||||
@@ -57,8 +57,13 @@ void process_init(void) {
|
||||
current_process[0] = kernel_proc;
|
||||
}
|
||||
|
||||
void process_create(void* entry_point, bool is_user) {
|
||||
if (process_count >= MAX_PROCESSES) return;
|
||||
process_t* process_create(void (*entry_point)(void), bool is_user) {
|
||||
uint64_t rflags = spinlock_acquire_irqsave(&runqueue_lock);
|
||||
|
||||
if (process_count >= MAX_PROCESSES) {
|
||||
spinlock_release_irqrestore(&runqueue_lock, rflags);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
process_t *new_proc = &processes[process_count++];
|
||||
new_proc->pid = next_pid++;
|
||||
@@ -71,7 +76,10 @@ void process_create(void* entry_point, bool is_user) {
|
||||
new_proc->pml4_phys = paging_get_pml4_phys();
|
||||
}
|
||||
|
||||
if (!new_proc->pml4_phys) return;
|
||||
if (!new_proc->pml4_phys) {
|
||||
spinlock_release_irqrestore(&runqueue_lock, rflags);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
// 2. Allocate aligned stack
|
||||
void* user_stack = kmalloc_aligned(4096, 4096);
|
||||
@@ -140,14 +148,16 @@ void process_create(void* entry_point, bool is_user) {
|
||||
|
||||
new_proc->cpu_affinity = 0; // Non-ELF processes stay on BSP
|
||||
|
||||
// Add to linked list (Critical Section)
|
||||
uint64_t rflags = spinlock_acquire_irqsave(&runqueue_lock);
|
||||
// Add to linked list
|
||||
new_proc->next = current_process[0]->next;
|
||||
current_process[0]->next = new_proc;
|
||||
|
||||
spinlock_release_irqrestore(&runqueue_lock, rflags);
|
||||
return new_proc;
|
||||
}
|
||||
|
||||
process_t* process_create_elf(const char* filepath, const char* args_str) {
|
||||
uint64_t rflags = spinlock_acquire_irqsave(&runqueue_lock);
|
||||
process_t *new_proc = NULL;
|
||||
|
||||
// Find an available slot
|
||||
@@ -159,10 +169,14 @@ process_t* process_create_elf(const char* filepath, const char* args_str) {
|
||||
}
|
||||
}
|
||||
|
||||
if (!new_proc) return NULL;
|
||||
if (!new_proc) {
|
||||
spinlock_release_irqrestore(&runqueue_lock, rflags);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
new_proc->pid = next_pid++;
|
||||
new_proc->is_user = true;
|
||||
spinlock_release_irqrestore(&runqueue_lock, rflags);
|
||||
|
||||
// 1. Setup Page Table
|
||||
new_proc->pml4_phys = paging_create_user_pml4_phys();
|
||||
@@ -334,7 +348,7 @@ process_t* process_create_elf(const char* filepath, const char* args_str) {
|
||||
}
|
||||
|
||||
// Add to linked list (Critical Section)
|
||||
uint64_t rflags = spinlock_acquire_irqsave(&runqueue_lock);
|
||||
rflags = spinlock_acquire_irqsave(&runqueue_lock);
|
||||
new_proc->next = current_process[0]->next;
|
||||
current_process[0]->next = new_proc;
|
||||
spinlock_release_irqrestore(&runqueue_lock, rflags);
|
||||
@@ -345,6 +359,16 @@ process_t* process_create_elf(const char* filepath, const char* args_str) {
|
||||
return new_proc;
|
||||
}
|
||||
|
||||
process_t* process_get_current_for_cpu(uint32_t cpu_id) {
|
||||
if (cpu_id >= MAX_CPUS_SCHED) return NULL;
|
||||
return current_process[cpu_id];
|
||||
}
|
||||
|
||||
void process_set_current_for_cpu(uint32_t cpu_id, process_t* p) {
|
||||
if (cpu_id >= MAX_CPUS_SCHED) return;
|
||||
current_process[cpu_id] = p;
|
||||
}
|
||||
|
||||
process_t* process_get_current(void) {
|
||||
uint32_t cpu = smp_this_cpu_id();
|
||||
return current_process[cpu];
|
||||
@@ -373,8 +397,8 @@ uint64_t process_schedule(uint64_t current_rsp) {
|
||||
process_t *next_proc = cur->next;
|
||||
|
||||
while (next_proc != start) {
|
||||
// Only consider processes assigned to our CPU
|
||||
if (next_proc->cpu_affinity == my_cpu) {
|
||||
// Only consider processes assigned to our CPU and not terminated
|
||||
if (next_proc->cpu_affinity == my_cpu && next_proc->pid != 0xFFFFFFFF) {
|
||||
if (next_proc->pid == 0 || next_proc->sleep_until == 0 || next_proc->sleep_until <= now) {
|
||||
break;
|
||||
}
|
||||
@@ -382,9 +406,20 @@ uint64_t process_schedule(uint64_t current_rsp) {
|
||||
next_proc = next_proc->next;
|
||||
}
|
||||
|
||||
// If we didn't find a ready process for our CPU, stay on current
|
||||
if (next_proc->cpu_affinity != my_cpu) {
|
||||
return current_rsp;
|
||||
// If we didn't find a ready process for our CPU, stay on current (unless we are terminated)
|
||||
if (next_proc->cpu_affinity != my_cpu || next_proc->pid == 0xFFFFFFFF) {
|
||||
// Fallback to idle if current is terminated
|
||||
if (cur && cur->pid == 0xFFFFFFFF) {
|
||||
// Find the idle process for this CPU
|
||||
for (int i = 0; i < MAX_PROCESSES; i++) {
|
||||
if (processes[i].pid == 0 || (processes[i].cpu_affinity == my_cpu && processes[i].is_user == false)) {
|
||||
next_proc = &processes[i];
|
||||
break;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
return current_rsp;
|
||||
}
|
||||
}
|
||||
|
||||
current_process[my_cpu] = next_proc;
|
||||
@@ -465,12 +500,25 @@ void process_terminate(process_t *to_delete) {
|
||||
uint32_t cpu_count = smp_cpu_count();
|
||||
for (uint32_t c = 0; c < cpu_count && c < MAX_CPUS_SCHED; c++) {
|
||||
if (current_process[c] == to_delete) {
|
||||
current_process[c] = to_delete->next;
|
||||
process_t *np = to_delete->next;
|
||||
while (np != to_delete) {
|
||||
if (np->cpu_affinity == c && np->pid != 0xFFFFFFFF) break;
|
||||
np = np->next;
|
||||
}
|
||||
if (np == to_delete || np->cpu_affinity != c) {
|
||||
for (int i = 0; i < MAX_PROCESSES; i++) {
|
||||
if (processes[i].pid == 0 || (processes[i].cpu_affinity == c && processes[i].is_user == false)) {
|
||||
np = &processes[i]; break;
|
||||
}
|
||||
}
|
||||
}
|
||||
current_process[c] = np;
|
||||
}
|
||||
}
|
||||
|
||||
// Mark slot as free
|
||||
to_delete->pid = 0xFFFFFFFF;
|
||||
to_delete->cpu_affinity = 0xFFFFFFFF;
|
||||
|
||||
if (to_delete->user_stack_alloc) kfree(to_delete->user_stack_alloc);
|
||||
if (to_delete->kernel_stack_alloc) {
|
||||
@@ -518,10 +566,26 @@ uint64_t process_terminate_current(void) {
|
||||
}
|
||||
|
||||
prev->next = to_delete->next;
|
||||
current_process[my_cpu] = to_delete->next;
|
||||
|
||||
process_t *next_proc = to_delete->next;
|
||||
while (next_proc != to_delete) {
|
||||
if (next_proc->cpu_affinity == my_cpu && next_proc->pid != 0xFFFFFFFF) break;
|
||||
next_proc = next_proc->next;
|
||||
}
|
||||
|
||||
if (next_proc == to_delete || next_proc->cpu_affinity != my_cpu) {
|
||||
for (int i = 0; i < MAX_PROCESSES; i++) {
|
||||
if (processes[i].pid == 0 || (processes[i].cpu_affinity == my_cpu && processes[i].is_user == false)) {
|
||||
next_proc = &processes[i]; break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
current_process[my_cpu] = next_proc;
|
||||
|
||||
// Mark slot as free
|
||||
to_delete->pid = 0xFFFFFFFF;
|
||||
to_delete->cpu_affinity = 0xFFFFFFFF;
|
||||
|
||||
// 4. Load context for the NEXT process
|
||||
if (current_process[my_cpu]->is_user && current_process[my_cpu]->kernel_stack) {
|
||||
|
||||
@@ -63,9 +63,11 @@ typedef struct {
|
||||
} ProcessInfo;
|
||||
|
||||
void process_init(void);
|
||||
void process_create(void* entry_point, bool is_user);
|
||||
process_t* process_create(void (*entry_point)(void), bool is_user);
|
||||
process_t* process_create_elf(const char* filepath, const char* args_str);
|
||||
process_t* process_get_current(void);
|
||||
void process_set_current_for_cpu(uint32_t cpu_id, process_t* p);
|
||||
process_t* process_get_current_for_cpu(uint32_t cpu_id);
|
||||
uint64_t process_schedule(uint64_t current_rsp);
|
||||
uint64_t process_terminate_current(void);
|
||||
void process_terminate(process_t *proc);
|
||||
|
||||
@@ -8,6 +8,7 @@
|
||||
#include "idt.h"
|
||||
#include "platform.h"
|
||||
#include "paging.h"
|
||||
#include "process.h"
|
||||
|
||||
extern void serial_write(const char *str);
|
||||
extern void serial_write_num(uint32_t n);
|
||||
@@ -65,9 +66,10 @@ static void ap_entry(struct limine_smp_info *info) {
|
||||
asm volatile("mov %0, %%cr4" : : "r"(cr4));
|
||||
asm volatile("fninit");
|
||||
|
||||
// 3. Load the shared GDT (same one the BSP uses — all CPUs share kernel mappings)
|
||||
// 3. Load the shared GDT and properly reload all segments (including CS=0x08)
|
||||
extern struct gdt_ptr gdtr;
|
||||
asm volatile("lgdt %0" : : "m"(gdtr));
|
||||
extern void gdt_flush(uint64_t);
|
||||
gdt_flush((uint64_t)&gdtr);
|
||||
|
||||
// 4. Load per-CPU TSS
|
||||
gdt_load_ap_tss(my_id);
|
||||
@@ -80,7 +82,11 @@ static void ap_entry(struct limine_smp_info *info) {
|
||||
uint64_t kernel_cr3 = paging_get_pml4_phys();
|
||||
asm volatile("mov %0, %%cr3" : : "r"(kernel_cr3));
|
||||
|
||||
// 7. Mark ourselves as online
|
||||
// 7. Enable LAPIC on this core so it can receive IPIs
|
||||
extern void lapic_enable(void);
|
||||
lapic_enable();
|
||||
|
||||
// 8. Mark ourselves as online
|
||||
cpu_states[my_id].online = true;
|
||||
|
||||
serial_write("[SMP] AP ");
|
||||
@@ -89,7 +95,13 @@ static void ap_entry(struct limine_smp_info *info) {
|
||||
serial_write_num(cpu_states[my_id].lapic_id);
|
||||
serial_write(")\n");
|
||||
|
||||
// 8. Enable interrupts and enter idle halt loop.
|
||||
// 9. Initialize the current_process pointer for this CPU
|
||||
// Create a dedicated idle task for this AP (PID 0 is reserved for the BSP)
|
||||
process_t *ap_idle = process_create(NULL, false); // Idle process
|
||||
ap_idle->cpu_affinity = my_id;
|
||||
process_set_current_for_cpu(my_id, ap_idle);
|
||||
|
||||
// 10. Enable interrupts and enter idle halt loop.
|
||||
// APs will be woken by scheduling IPIs from BSP (vector 0x41).
|
||||
// The IPI handler does context switching for this CPU's processes.
|
||||
asm volatile("sti");
|
||||
|
||||
@@ -33,25 +33,10 @@ static inline void wrmsr(uint32_t msr, uint64_t value) {
|
||||
asm volatile("wrmsr" : : "c"(msr), "a"(low), "d"(high));
|
||||
}
|
||||
|
||||
// Implemented in assembly
|
||||
extern void syscall_entry(void);
|
||||
|
||||
extern uint64_t kernel_syscall_stack;
|
||||
extern void isr128_wrapper(void);
|
||||
|
||||
void syscall_init(void) {
|
||||
void* stack = kmalloc(16384);
|
||||
kernel_syscall_stack = (uint64_t)stack + 16384;
|
||||
uint64_t efer = rdmsr(MSR_EFER);
|
||||
efer |= 1; // SCE bit is bit 0
|
||||
wrmsr(MSR_EFER, efer);
|
||||
|
||||
|
||||
uint64_t star = ((uint64_t)0x08 << 32) | ((uint64_t)0x13 << 48);
|
||||
wrmsr(MSR_STAR, star);
|
||||
|
||||
wrmsr(MSR_LSTAR, (uint64_t)syscall_entry);
|
||||
|
||||
wrmsr(MSR_FMASK, 0x200);
|
||||
// SMP-Safe System Calls using int 0x80 (configured in idt.c)
|
||||
}
|
||||
|
||||
static void user_window_close(Window *win) {
|
||||
@@ -284,7 +269,7 @@ static uint64_t syscall_handler_inner(registers_t *regs) {
|
||||
extern void graphics_set_render_target(uint32_t *buffer, int w, int h);
|
||||
|
||||
uint64_t rflags;
|
||||
asm volatile("pushfq; pop %0; cli" : "=r"(rflags));
|
||||
rflags = wm_lock_acquire();
|
||||
|
||||
if (win->pixels) {
|
||||
// Strict user-to-window relative clamping
|
||||
@@ -304,7 +289,7 @@ static uint64_t syscall_handler_inner(registers_t *regs) {
|
||||
draw_rect(win->x + params[0], win->y + params[1], params[2], params[3], color);
|
||||
}
|
||||
|
||||
asm volatile("push %0; popfq" : : "r"(rflags));
|
||||
wm_lock_release(rflags);
|
||||
}
|
||||
} else if (cmd == GUI_CMD_DRAW_ROUNDED_RECT_FILLED) {
|
||||
Window *win = (Window *)arg2;
|
||||
@@ -318,7 +303,7 @@ static uint64_t syscall_handler_inner(registers_t *regs) {
|
||||
extern void graphics_set_render_target(uint32_t *buffer, int w, int h);
|
||||
|
||||
uint64_t rflags;
|
||||
asm volatile("pushfq; pop %0; cli" : "=r"(rflags));
|
||||
rflags = wm_lock_acquire();
|
||||
|
||||
if (win->pixels) {
|
||||
int rx = (int)params[0]; int ry = (int)params[1];
|
||||
@@ -336,7 +321,7 @@ static uint64_t syscall_handler_inner(registers_t *regs) {
|
||||
}
|
||||
}
|
||||
|
||||
asm volatile("push %0; popfq" : : "r"(rflags));
|
||||
wm_lock_release(rflags);
|
||||
}
|
||||
} else if (cmd == GUI_CMD_DRAW_STRING) {
|
||||
Window *win = (Window *)arg2;
|
||||
@@ -359,7 +344,7 @@ static uint64_t syscall_handler_inner(registers_t *regs) {
|
||||
kernel_str[i] = 0;
|
||||
|
||||
uint64_t rflags;
|
||||
asm volatile("pushfq; pop %0; cli" : "=r"(rflags));
|
||||
rflags = wm_lock_acquire();
|
||||
|
||||
ttf_font_t *font = win->font ? (ttf_font_t*)win->font : graphics_get_current_ttf();
|
||||
|
||||
@@ -395,7 +380,7 @@ static uint64_t syscall_handler_inner(registers_t *regs) {
|
||||
}
|
||||
}
|
||||
|
||||
asm volatile("push %0; popfq" : : "r"(rflags));
|
||||
wm_lock_release(rflags);
|
||||
}
|
||||
} else if (cmd == 10) { // GUI_CMD_DRAW_STRING_BITMAP
|
||||
Window *win = (Window *)arg2;
|
||||
@@ -418,7 +403,7 @@ static uint64_t syscall_handler_inner(registers_t *regs) {
|
||||
kernel_str[i] = 0;
|
||||
|
||||
uint64_t rflags;
|
||||
asm volatile("pushfq; pop %0; cli" : "=r"(rflags));
|
||||
rflags = wm_lock_acquire();
|
||||
|
||||
if (win->pixels) {
|
||||
if (ux >= -100 && ux < win->w && uy >= -100 && uy < (win->h - 20)) {
|
||||
@@ -430,7 +415,7 @@ static uint64_t syscall_handler_inner(registers_t *regs) {
|
||||
draw_string_bitmap(win->x + ux, win->y + uy, kernel_str, color);
|
||||
}
|
||||
|
||||
asm volatile("push %0; popfq" : : "r"(rflags));
|
||||
wm_lock_release(rflags);
|
||||
}
|
||||
} else if (cmd == 11) { // GUI_CMD_DRAW_STRING_SCALED
|
||||
Window *win = (Window *)arg2;
|
||||
@@ -457,7 +442,7 @@ static uint64_t syscall_handler_inner(registers_t *regs) {
|
||||
kernel_str[i] = 0;
|
||||
|
||||
uint64_t rflags;
|
||||
asm volatile("pushfq; pop %0; cli" : "=r"(rflags));
|
||||
rflags = wm_lock_acquire();
|
||||
|
||||
ttf_font_t *font = win->font ? (ttf_font_t*)win->font : graphics_get_current_ttf();
|
||||
|
||||
@@ -493,7 +478,7 @@ static uint64_t syscall_handler_inner(registers_t *regs) {
|
||||
}
|
||||
}
|
||||
|
||||
asm volatile("push %0; popfq" : : "r"(rflags));
|
||||
wm_lock_release(rflags);
|
||||
}
|
||||
} else if (cmd == 18) { // GUI_CMD_DRAW_STRING_SCALED_SLOPED
|
||||
Window *win = (Window *)arg2;
|
||||
@@ -530,7 +515,7 @@ static uint64_t syscall_handler_inner(registers_t *regs) {
|
||||
kernel_str[i] = 0;
|
||||
|
||||
uint64_t rflags;
|
||||
asm volatile("pushfq; pop %0; cli" : "=r"(rflags));
|
||||
rflags = wm_lock_acquire();
|
||||
|
||||
ttf_font_t *font = win->font ? (ttf_font_t*)win->font : graphics_get_current_ttf();
|
||||
|
||||
@@ -568,7 +553,7 @@ static uint64_t syscall_handler_inner(registers_t *regs) {
|
||||
}
|
||||
}
|
||||
|
||||
asm volatile("push %0; popfq" : : "r"(rflags));
|
||||
wm_lock_release(rflags);
|
||||
}
|
||||
} else if (cmd == GUI_CMD_DRAW_IMAGE) {
|
||||
Window *win = (Window *)arg2;
|
||||
@@ -579,7 +564,7 @@ static uint64_t syscall_handler_inner(registers_t *regs) {
|
||||
for (int i = 0; i < 4; i++) params[i] = u_params[i];
|
||||
|
||||
uint64_t rflags;
|
||||
asm volatile("pushfq; pop %0; cli" : "=r"(rflags));
|
||||
rflags = wm_lock_acquire();
|
||||
|
||||
if (win->pixels) {
|
||||
int rx = (int)params[0]; int ry = (int)params[1];
|
||||
@@ -614,9 +599,10 @@ static uint64_t syscall_handler_inner(registers_t *regs) {
|
||||
}
|
||||
}
|
||||
|
||||
asm volatile("push %0; popfq" : : "r"(rflags));
|
||||
wm_lock_release(rflags);
|
||||
}
|
||||
} else if (cmd == GUI_CMD_MARK_DIRTY) {
|
||||
uint64_t rflags = wm_lock_acquire();
|
||||
Window *win = (Window *)arg2;
|
||||
uint64_t *u_params = (uint64_t *)arg3;
|
||||
if (win && u_params) {
|
||||
@@ -630,6 +616,7 @@ static uint64_t syscall_handler_inner(registers_t *regs) {
|
||||
}
|
||||
wm_mark_dirty(win->x + (int)params[0], win->y + (int)params[1], (int)params[2], (int)params[3]);
|
||||
}
|
||||
wm_lock_release(rflags);
|
||||
} else if (cmd == GUI_CMD_GET_EVENT) {
|
||||
Window *win = (Window *)arg2;
|
||||
gui_event_t *ev_out = (gui_event_t *)arg3;
|
||||
@@ -1184,7 +1171,7 @@ static uint64_t syscall_handler_inner(registers_t *regs) {
|
||||
size_t total_used = stats.used_memory;
|
||||
size_t user_used = 0;
|
||||
for (int i = 0; i < 16; i++) {
|
||||
if (processes[i].pid != 0xFFFFFFFF && processes[i].pid != 0) {
|
||||
if (processes[i].pid != 0xFFFFFFFF && processes[i].pid != 0 && processes[i].is_user) {
|
||||
user_used += processes[i].used_memory;
|
||||
}
|
||||
}
|
||||
@@ -1192,13 +1179,19 @@ static uint64_t syscall_handler_inner(registers_t *regs) {
|
||||
else processes[0].used_memory = 0;
|
||||
|
||||
int count = 0;
|
||||
for (int i = 0; i < 16; i++) { // MAX_PROCESSES is 16
|
||||
if (processes[i].pid != 0xFFFFFFFF) {
|
||||
for (int i = 0; i < 16; i++) {
|
||||
if (processes[i].pid != 0xFFFFFFFF && (processes[i].is_user || processes[i].pid == 0)) {
|
||||
out[count].pid = processes[i].pid;
|
||||
extern void mem_memcpy(void *dest, const void *src, size_t len);
|
||||
mem_memcpy(out[count].name, processes[i].name, 64);
|
||||
out[count].ticks = processes[i].ticks;
|
||||
|
||||
if (processes[i].pid == 0) {
|
||||
out[count].name[0] = 'k'; out[count].name[1] = 'e'; out[count].name[2] = 'r';
|
||||
out[count].name[3] = 'n'; out[count].name[4] = 'e'; out[count].name[5] = 'l';
|
||||
out[count].name[6] = '\0';
|
||||
}
|
||||
|
||||
out[count].ticks = processes[i].ticks;
|
||||
out[count].used_memory = processes[i].used_memory;
|
||||
|
||||
count++;
|
||||
|
||||
Reference in New Issue
Block a user