diff options
| author | Jon Santmyer <jon@jonsantmyer.com> | 2026-10-04 10:49:41 -0400 |
|---|---|---|
| committer | Jon Santmyer <jon@jonsantmyer.com> | 2026-10-04 10:49:41 -0400 |
| commit | 8d48bbd9746228b63bafa5f92b621998d7d8f3d3 (patch) | |
| tree | fbaba69059c2e28d5098da4c9be357c38e406626 | |
| parent | 465cba0c00bfc5d89bf10ce353b0adf40bdc098d (diff) | |
| download | jove-kernel-8d48bbd9746228b63bafa5f92b621998d7d8f3d3.tar.gz jove-kernel-8d48bbd9746228b63bafa5f92b621998d7d8f3d3.tar.bz2 jove-kernel-8d48bbd9746228b63bafa5f92b621998d7d8f3d3.zip | |
move init fully to proc. remove init pages prealloc. prepare for scheduling
| -rw-r--r-- | api/error.h | 3 | ||||
| -rw-r--r-- | api/process.h | 8 | ||||
| -rw-r--r-- | api/syscall.h | 40 | ||||
| -rw-r--r-- | arch/x86_64/hal/paging.c | 2 | ||||
| -rw-r--r-- | arch/x86_64/hal/serial_com.c | 2 | ||||
| -rw-r--r-- | arch/x86_64/hal/smp.c | 2 | ||||
| -rw-r--r-- | arch/x86_64/lib/printf.c | 2 | ||||
| -rw-r--r-- | arch/x86_64/main.c | 2 | ||||
| -rw-r--r-- | arch/x86_64/proc/init.c | 33 | ||||
| -rw-r--r-- | arch/x86_64/proc/process.c | 4 | ||||
| -rw-r--r-- | arch/x86_64/proc/process.h | 3 | ||||
| -rw-r--r-- | boot/initrd.c | 2 | ||||
| -rw-r--r-- | boot/limine/framebuffer.c | 2 | ||||
| -rw-r--r-- | boot/limine/memorymap.c | 2 | ||||
| -rw-r--r-- | config.h | 1 | ||||
| -rw-r--r-- | doc/syscall.md | 90 | ||||
| -rw-r--r-- | hal/untyped.c | 4 | ||||
| -rw-r--r-- | lib/errstr.c | 10 | ||||
| -rw-r--r-- | lib/printf.c | 2 | ||||
| -rw-r--r-- | lib/virtterm.c | 2 | ||||
| -rw-r--r-- | proc/init.c | 34 | ||||
| -rw-r--r-- | proc/init.h (renamed from init.h) | 4 | ||||
| -rw-r--r-- | proc/process.c | 16 | ||||
| -rw-r--r-- | proc/process.h | 27 | ||||
| -rw-r--r-- | sys/syscall.c | 8 | ||||
| -rw-r--r-- | sys/syscall.h | 1 | ||||
| -rw-r--r-- | sys/syscall_pcb.c | 26 |
27 files changed, 275 insertions, 57 deletions
diff --git a/api/error.h b/api/error.h index de7d4b2..af85bd9 100644 --- a/api/error.h +++ b/api/error.h @@ -18,5 +18,8 @@ #define EOVERFLOW 15 #define EBADCALL 16 #define EPERM 17 +#define EBADPROC 18 +#define ENOMAIL 19 +#define ETIMEOUT 20 #endif diff --git a/api/process.h b/api/process.h new file mode 100644 index 0000000..080e001 --- /dev/null +++ b/api/process.h @@ -0,0 +1,8 @@ +#ifndef _JOVE_API_PROCESS_H +#define _JOVE_API_PROCESS_H 1 + +#include <stdint.h> + +typedef intmax_t pid_t; + +#endif diff --git a/api/syscall.h b/api/syscall.h index a116177..2502621 100644 --- a/api/syscall.h +++ b/api/syscall.h @@ -4,6 +4,7 @@ #include <stddef.h> #include <stdint.h> +#include "process.h" #include "obj.h" /* General syscall behavior: @@ -123,6 +124,45 @@ struct syscall_pagedir_unmap objpath_part_t none_path[]; }; +/**JOVE_OBJ_PCB syscalls. + * */ + +enum +{ + _SYSCALL_PCB_NONE = 0, + SYSCALL_PCB_YIELD, + SYSCALL_PCB_SEND, + SYSCALL_PCB_RECV +}; + +#define SYSCALL_PERM_PCB_YIELD (JOVE_PERM_WRITE) +#define SYSCALL_PERM_PCB_SEND (JOVE_PERM_MUTATE) +#define SYSCALL_PERM_PCB_RECV (JOVE_PERM_MUTATE) + +#define SYSCALL_PERM_PCB_SEND_TGT (JOVE_PERM_MUTATE) +#define SYSCALL_PERM_PCB_RECV_DST (JOVE_PERM_MUTATE) + +struct syscall_pcb_yield +{ + pid_t yield_target; +}; + +struct syscall_pcb_send +{ + pid_t send_target; + uintmax_t send_timeout; + uint16_t send_path_length; + objpath_part_t send_path[]; +}; + +struct syscall_pcb_recv +{ + pid_t recv_target; + uintmax_t recv_timeout; + uint16_t recv_path_length; + objpath_part_t recv_path[]; +}; + /**JOVE_OBJ_INITRD_FILE syscalls * */ diff --git a/arch/x86_64/hal/paging.c b/arch/x86_64/hal/paging.c index 408b5d5..a0d6ca9 100644 --- a/arch/x86_64/hal/paging.c +++ b/arch/x86_64/hal/paging.c @@ -2,7 +2,7 @@ #include "arch/x86_64/x86_64.h" #include "hal/memory.h" #include "jove.h" -#include "init.h" +#include "proc/init.h" #include "config.h" #include "hal/obj.h" #include "lib/string.h" diff --git a/arch/x86_64/hal/serial_com.c b/arch/x86_64/hal/serial_com.c index 8454c8a..343d2ae 100644 --- a/arch/x86_64/hal/serial_com.c +++ b/arch/x86_64/hal/serial_com.c @@ -2,7 +2,7 @@ #include "port.h" #include "jove.h" #include "hal/obj.h" -#include "init.h" +#include "proc/init.h" #include "lib/printf.h" static int diff --git a/arch/x86_64/hal/smp.c b/arch/x86_64/hal/smp.c index 4c79d79..b894eb9 100644 --- a/arch/x86_64/hal/smp.c +++ b/arch/x86_64/hal/smp.c @@ -1,5 +1,5 @@ #include "smp.h" -#include "init.h" +#include "proc/init.h" #include "config.h" #include "jove.h" #include "paging.h" diff --git a/arch/x86_64/lib/printf.c b/arch/x86_64/lib/printf.c index f60b943..794a592 100644 --- a/arch/x86_64/lib/printf.c +++ b/arch/x86_64/lib/printf.c @@ -1,7 +1,7 @@ #include "../hal/serial_com.h" #include "lib/printf.h" #include "lib/virtterm.h" -#include "init.h" +#include "proc/init.h" int kvprintf(const char *fmt, va_list ap) diff --git a/arch/x86_64/main.c b/arch/x86_64/main.c index f5a9d39..92f9fe1 100644 --- a/arch/x86_64/main.c +++ b/arch/x86_64/main.c @@ -1,6 +1,6 @@ #include "api/init.h" #include "jove.h" -#include "init.h" +#include "proc/init.h" #include "lib/string.h" #include "lib/printf.h" #include "lib/virtterm.h" diff --git a/arch/x86_64/proc/init.c b/arch/x86_64/proc/init.c index be1d556..3787c7b 100644 --- a/arch/x86_64/proc/init.c +++ b/arch/x86_64/proc/init.c @@ -1,4 +1,4 @@ -#include "init.h" +#include "proc/init.h" #include "arch/x86_64/hal/msr.h" #include "config.h" #include "proc/process.h" @@ -12,10 +12,6 @@ #include "boot/cmdline.h" #include "boot/initrd.h" -PAGEALIGN static uint8_t s_init_program_pages[INIT_PROGRAM_PAGES_MAX][0x1000]; -PAGEALIGN static uint8_t s_init_stack_pages[INIT_STACK_PAGES + 3][0x1000]; -PAGEALIGN static uint8_t s_init_message_page[0x1000]; - static int elf_is_valid(struct elf_header *ehdr) { @@ -78,7 +74,6 @@ init_setup(void) size_t last_base = 0; //Load the init ELF - size_t last_page = 0; for(size_t i = 0; i < init_ehdr->e_phnum; i++) { struct elf_phdr *phdr = init_data + init_ehdr->e_phoff + i * init_ehdr->e_phentsize; if(phdr->p_type != PT_LOAD) continue; @@ -93,18 +88,15 @@ init_setup(void) for(size_t i = 0; i < pages; i++) { uintptr_t page_virt = page_base + (i << 12); - if(last_page >= INIT_PROGRAM_PAGES_MAX) { - kpanic("Program exceeds size limit! (%i > %i)\n", last_page, INIT_PROGRAM_PAGES_MAX); - } int tblres = 0; + jove_owned_obj_t page_frame; do { - uintptr_t tbl_frame = KPTR_TOPHYS(&s_init_program_pages[last_page++]); - tblres = pagedir_map_table(pml4, tbl_frame, page_virt); - if(tblres == EHASMAP) last_page--; - }while(!tblres); + page_frame = init_pop_alloc(); + tblres = pagedir_map_table(pml4, obj_getvalue(&page_frame), page_virt); + }while(tblres == 0); - pagedir_map_frame(pml4, KPTR_TOPHYS(&s_init_program_pages[last_page++]), page_virt, + pagedir_map_frame(pml4, obj_getvalue(&page_frame), page_virt, PAGE_WRITEABLE | PAGE_USER); } @@ -116,25 +108,24 @@ init_setup(void) size_t stack_base = 0x00007FFFFFFFF000; int stack_mapres = 0; - last_page = 0; for(size_t i = 0; i < INIT_STACK_PAGES; i++) { uintptr_t page_virt = stack_base - (i << 12); int tblres = 0; + jove_owned_obj_t page_frame; do { - uintptr_t tbl_frame = KPTR_TOPHYS(&s_init_stack_pages[last_page++]); - tblres = pagedir_map_table(pml4, tbl_frame, page_virt); - if(tblres == EHASMAP) last_page--; + page_frame = init_pop_alloc(); + tblres = pagedir_map_table(pml4, obj_getvalue(&page_frame), page_virt); }while(!tblres); - pagedir_map_frame(pml4, KPTR_TOPHYS(&s_init_stack_pages[last_page++]), page_virt, + pagedir_map_frame(pml4, obj_getvalue(&page_frame), page_virt, PAGE_WRITEABLE | PAGE_USER | PAGE_XD); } //Map the syscall message. last_base = (last_base + 0xFFF) & ~0xFFF; - uintptr_t message_pptr = KPTR_TOPHYS(s_init_message_page); - pagedir_map_frame(pml4, message_pptr, last_base, + jove_owned_obj_t message_frame = init_pop_alloc(); + pagedir_map_frame(pml4, obj_getvalue(&message_frame), last_base, PAGE_WRITEABLE | PAGE_USER | PAGE_XD); extern struct init_payload _init_payload; diff --git a/arch/x86_64/proc/process.c b/arch/x86_64/proc/process.c index 6165585..d5513bc 100644 --- a/arch/x86_64/proc/process.c +++ b/arch/x86_64/proc/process.c @@ -6,7 +6,7 @@ #include "hal/obj.h" #include "hal/smp.h" #include "lib/string.h" -#include "init.h" +#include "proc/init.h" #include "jove.h" PAGEALIGN uint8_t s_init_iopb[0x2000]; @@ -28,6 +28,8 @@ processing_setup(void (*process_main)) init_pcb->header.pagedir = obj_release(objdir_getlocal(_rootdir_obj, ROOTDIR_PAGEDIR_I)); init_pcb->header.pid = 1; + init_pcb->header.state = PCB_STATE_RUNNING; + init_pcb->ksp = (void*)ksp; jove_owned_obj_t *iopb_obj = objdir_getlocal(_rootdir_obj, ROOTDIR_IOPB_I); diff --git a/arch/x86_64/proc/process.h b/arch/x86_64/proc/process.h index 534c8d5..6a0aa96 100644 --- a/arch/x86_64/proc/process.h +++ b/arch/x86_64/proc/process.h @@ -8,13 +8,10 @@ typedef struct process_control_block { struct pcb_expected_header header; - struct process_control_block *sched_next; jove_obj_t *iopb; - enum pcb_state state; int killed; - struct pcb_mailbox send, recv; struct cpu_context context; void *ksp; diff --git a/boot/initrd.c b/boot/initrd.c index e1a7ec3..f9bf47e 100644 --- a/boot/initrd.c +++ b/boot/initrd.c @@ -1,6 +1,6 @@ #include "initrd.h" #include "arch/x86_64/hal/obj.h" -#include "init.h" +#include "proc/init.h" #include "jove.h" #include "lib/printf.h" #include "lib/tar.h" diff --git a/boot/limine/framebuffer.c b/boot/limine/framebuffer.c index 3758167..87b124a 100644 --- a/boot/limine/framebuffer.c +++ b/boot/limine/framebuffer.c @@ -2,7 +2,7 @@ #include "jove.h" #include "lib/printf.h" #include "limine.h" -#include "init.h" +#include "proc/init.h" #include "hal/framebuffer.h" extern struct limine_framebuffer_response *_limine_framebuffers; diff --git a/boot/limine/memorymap.c b/boot/limine/memorymap.c index c6a9064..b90f176 100644 --- a/boot/limine/memorymap.c +++ b/boot/limine/memorymap.c @@ -4,7 +4,7 @@ #include "hal/memory.h" #include "hal/obj.h" #include "panic/panic.h" -#include "init.h" +#include "proc/init.h" #include "lib/printf.h" extern struct limine_memmap_response *_limine_memmap_resp; @@ -11,7 +11,6 @@ #define FRAMEBUFFER_MAX_WIDTH 1920 #define FRAMEBUFFER_MAX_HEIGHT 1080 -#define INIT_PROGRAM_PAGES_MAX 96 #define INIT_STACK_PAGES 2 #define LOCKSTACK_MAX 64 diff --git a/doc/syscall.md b/doc/syscall.md index 4fd55ad..1e03425 100644 --- a/doc/syscall.md +++ b/doc/syscall.md @@ -95,9 +95,11 @@ If the untyped path does not point to a `JOVE_OBJ_NONE` object, the kernel will ### JOVE_OBJ_OBJDIR -| Syscall | Permissions Required | -|------------------------|----------------------| -| SYSCALL_OBJDIR_OBJTYPE | JOVE_PERM_READ | +| Syscall | Target Permissions | +|------------------------|--------------------------------------| +| SYSCALL_OBJDIR_OBJTYPE | JOVE_PERM_READ | +| SYSCALL_OBJDIR_UNTYPE | JOVE_PERM_WRITE <br>JOVE_PERM_MUTATE | +| SYSCALL_OBJDIR_SEND | JOVE_PERM_MUTATE | #### SYSCALL_OBJDIR_OBJTYPE @@ -111,6 +113,18 @@ If the message is too small to hold the payload, the kernel will return `-ETOOSM If the entry index exceeds `JOVE_OBJDIR_ENTRIES`, the kernel returns `-EOOB`. +#### SYSCALL_OBJDIR_UNTYPE + +Converts the target object to an untyped object if possible. + +| Data | Entry Index | +|--------------|-------------| +| Size (bytes) | 2 | + +If the target object does not have underlying memory, the kernel will replace the object with `JOVE_OBJ_NONE`. + +If the target object has underlying memory, the kernel will replace the object with `JOVE_OBJ_UNTYPED`. + ### JOVE_OBJ_PAGEDIR @@ -263,6 +277,76 @@ If the page frame pointed to by virtual address does not correspond to a shared Successful unmapping returns `0`. +### JOVE_OBJ_PCB + +| Syscall | Target Permissions | Subject Permissions | +|-------------------|--------------------|---------------------| +| SYSCALL_PCB_YIELD | JOVE_PERM_WRITE | | +| SYSCALL_PCB_SEND | JOVE_PERM_MUTATE | JOVE_PERM_MUTATE | +| SYSCALL_PCB_RECV | JOVE_PERM_MUTATE | JOVE_PERM_MUTATE | + +#### SYSCALL_PCB_YIELD + +Yields control to the specified process. + +| Data | Yield target | +|--------------|---------------| +| Size (bytes) | sizeof(pid_t) | + +If the yield target = `0`, the scheduler will determine the next process. + +If the yield target does not exist, the kernel will return `-ENOPROC`. + +#### SYSCALL_PCB_SEND + +Attempts to send the target object to a process specified by destination process. + +If blocking timeout is zero, then the process will wait for the destination process to recieve the object forever. + +If the blocking timeout is non-zero, then the process will wait for the destination process to recieve the object for the specified number of scheduler ticks. + +| Data | Destination Process | Blocking Timeout | Send Path Length | Send Path | +|--------------|---------------------|-------------------|------------------|----------------------| +| Size (bytes) | sizeof(pid_t) | sizeof(uintmax_t) | 2 | 2 * send_path_length | + +While the object is being sent, the kernel will lock the object and copy a pointer to it into the send mailbox. + +If the target path does not represent a valid object, the kernel will return `-EBADPATH`. + +If the target path represents a `JOVE_OBJ_NONE` object, the kernel will return `-EBADOBJ`. + +If the target object does not have the `JOVE_PERM_MUTATE` permission, the kernel will return `-EPERM`. + +If the destination process does not represent a valid process, the kernel will return `-EBADPROC`. + +If the blocking timeout expires and the message was not sent, the kernel will return `-ETIMEOUT`. + +If the send is successful, the sent object is replaced by a `JOVE_OBJ_NONE` object and the kernel will return 0. + +#### SYSCALL_PCB_RECV + +Recieves kernel objects from the PCB mailbox. + +If a sender is specified, then the mailbox will only accept mail from that specific sender. + +Blocks on recieve until blocking timeout expires or forever if blocking timeout was zero. + +Destination object is locked until the timeout expires or an object is placed in the destination path. + +| Data | Sending Process | Blocking Timeout | Dest Path Length | Dest path | +|--------------|-----------------|-------------------|------------------|-------------------| +| Size (bytes) | sizeof(pid_t) | sizeof(uintmax_t) | 2 | 2 * dest_path_len | + +If the specified pid does not correspond to a process, the kernel will return `-ENOPROC`. + +If the destination path does not correspond to a `JOVE_OBJ_NONE` object, the kernel will return `-EFULL`. + +If the destination path does not have the `JOVE_PERM_MUTATE` permission, the kernel will return `-EPERM`. + +Recieved messages will be sent to the specified destination path. + +Successful retrieval returns `0`. + ### JOVE_OBJ_INITRD_FILE | Syscall | Target Permissions | diff --git a/hal/untyped.c b/hal/untyped.c index 6957175..ca69228 100644 --- a/hal/untyped.c +++ b/hal/untyped.c @@ -18,7 +18,7 @@ int untyped_split(jove_owned_obj_t *tgt, jove_owned_obj_t *dst, size_t bytes) { jove_untyped_t *tgt_untyped = obj_deref(tgt); - if(tgt_untyped->limit - bytes < JOVE_UNTYPED_MINSIZE) return ETOOSMALL; + if(tgt_untyped->limit - bytes < JOVE_UNTYPED_MINSIZE) return -ETOOSMALL; tgt_untyped->limit -= bytes; obj_settype(dst, JOVE_OBJ_UNTYPED); @@ -35,7 +35,7 @@ untyped_merge(jove_owned_obj_t *a, jove_owned_obj_t *b) jove_untyped_t *a_untyped = obj_deref(a); jove_untyped_t *b_untyped = obj_deref(b); if((uintptr_t)a_untyped + a_untyped->limit == (uintptr_t)b_untyped) { - return EBADARG; + return -EBADARG; } if((uintptr_t)b_untyped + b_untyped->limit == (uintptr_t)a_untyped) { return untyped_merge(b, a); diff --git a/lib/errstr.c b/lib/errstr.c index 6c4425d..d4aed8a 100644 --- a/lib/errstr.c +++ b/lib/errstr.c @@ -15,7 +15,15 @@ errstr(int err) [EHASMAP] = "HAS MAP", [EALIGN] = "ALIGNMENT ERROR", [EEXIST] = "ALREADY EXISTS", - [EBUSY] = "RESOURCE BUSY" + [EBUSY] = "RESOURCE BUSY", + [EEMPTY] = "EMPTY", + [EFULL] = "FULL", + [EOVERFLOW] = "OVERFLOW", + [EBADCALL] = "BAD CALL", + [EPERM] = "NO PERMISSION", + [EBADPROC] = "INVALID PROCESS", + [ENOMAIL] = "NO MAIL", + [ETIMEOUT] = "TIMEOUT" }; if(err >= sizeof(errstrs) / sizeof(const char*)) { return "UNKNOWN ERROR"; diff --git a/lib/printf.c b/lib/printf.c index 0a9cc15..7fa681e 100644 --- a/lib/printf.c +++ b/lib/printf.c @@ -1,6 +1,6 @@ #include "printf.h" #include "string.h" -#include "init.h" +#include "proc/init.h" #include "hal/obj.h" #include <stdint.h> diff --git a/lib/virtterm.c b/lib/virtterm.c index 0daa921..8518530 100644 --- a/lib/virtterm.c +++ b/lib/virtterm.c @@ -2,7 +2,7 @@ #include "boot/cmdline.h" #include "boot/initrd.h" #include "hal/obj.h" -#include "init.h" +#include "proc/init.h" #include "jove.h" #include "hal/framebuffer.h" #include "lib/printf.h" diff --git a/proc/init.c b/proc/init.c new file mode 100644 index 0000000..65299f4 --- /dev/null +++ b/proc/init.c @@ -0,0 +1,34 @@ +#include "init.h" +#include "hal/memory.h" +#include "panic/panic.h" + +objpath_part_t s_last_untyped = JOVE_OBJDIR_ENTRIES-1; + +jove_owned_obj_t +init_pop_alloc(void) +{ + jove_owned_obj_t *untyped_dir = objdir_trygetlocal(_rootdir_obj, ROOTDIR_UNTYPED_I); + if(untyped_dir == 0) { + kpanic("Untyped directory is locked!\n"); + } + int cycles = 0; + + while(cycles++ < 512) { + if(objdir_peeklocal(untyped_dir, s_last_untyped).type != JOVE_OBJ_UNTYPED) { + s_last_untyped--; + continue; + } + + jove_owned_obj_t frame = { 0 }; + jove_owned_obj_t *untyped = objdir_getlocal(untyped_dir, s_last_untyped); + + if(untyped_split(untyped, &frame, 0x1000) < 0) { + kpanic("%s: Failed to split last untyped.\n", __func__); + } + + obj_release(untyped); + obj_release(untyped_dir); + return frame; + } + kpanic("%s: Kernel is out of memory!\n", __func__); +} @@ -2,9 +2,13 @@ #define _JOVE_INIT_H 1 #include "api/init.h" +#include "hal/obj.h" extern void *_rootdir_obj; +extern struct init_payload _init_payload; void init_setup(void); +jove_owned_obj_t init_pop_alloc(void); + #endif diff --git a/proc/process.c b/proc/process.c index 55737f6..e811cb6 100644 --- a/proc/process.c +++ b/proc/process.c @@ -14,13 +14,25 @@ pcb_getpid(pcb_t *pcb) } jove_obj_t* -pcb_rootdir(pcb_t *pcb) +pcb_getrootdir(pcb_t *pcb) { return ((struct pcb_expected_header*)pcb)->rootdir; } jove_obj_t* -pcb_pagedir(pcb_t *pcb) +pcb_getpagedir(pcb_t *pcb) { return ((struct pcb_expected_header*)pcb)->pagedir; } + +enum pcb_state +pcb_getstate(pcb_t *pcb) +{ + return ((struct pcb_expected_header*)pcb)->state; +} + +intmax_t +pcb_getstatecode(pcb_t *pcb) +{ + return ((struct pcb_expected_header*)pcb)->state_code; +} diff --git a/proc/process.h b/proc/process.h index 2757f6f..ed40a4f 100644 --- a/proc/process.h +++ b/proc/process.h @@ -3,12 +3,16 @@ #include "hal/obj.h" #include "lib/rbtree.h" - -typedef uintmax_t pid_t; +#include "api/process.h" enum pcb_state { - PCB_DEAD, PCB_READY, PCB_RUNNING, PCB_BLOCKED + _PCB_STATE_INVALID = 0, + PCB_STATE_DEAD, + PCB_STATE_READY, + PCB_STATE_RUNNING, + PCB_STATE_WAITING, + PCB_STATE_BLOCKED_MAIL }; struct pcb_mailbox @@ -20,11 +24,16 @@ struct pcb_mailbox struct pcb_expected_header { struct rbtree_node tree_node; - struct process_control_block *sched_next; + struct pcb_expected_header *sched_next; pid_t pid; jove_obj_t *rootdir; jove_obj_t *pagedir; + + enum pcb_state state; + intmax_t state_code; + + struct pcb_mailbox send, recv; }; typedef struct process_control_block pcb_t; @@ -32,12 +41,12 @@ typedef struct process_control_block pcb_t; jove_owned_obj_t *process_current(void); void pcb_new(pcb_t *pcb); -/*Returns the process ID of the passed PCB. */ -pid_t pcb_getpid(pcb_t *pcb); -/*Returns the root kernel object directory of this PCB. */ -jove_obj_t *pcb_rootdir(pcb_t *pcb); -jove_obj_t *pcb_pagedir(pcb_t *pcb); +pid_t pcb_getpid(pcb_t *pcb); +jove_obj_t *pcb_getrootdir(pcb_t *pcb); +jove_obj_t *pcb_getpagedir(pcb_t *pcb); +enum pcb_state pcb_getstate(pcb_t *pcb); +intmax_t pcb_getstatecode(pcb_t *pcb); extern pcb_t *pcb_tree; diff --git a/sys/syscall.c b/sys/syscall.c index 7207708..54d5468 100644 --- a/sys/syscall.c +++ b/sys/syscall.c @@ -38,7 +38,7 @@ static const syscall_handle_t s_syscall_handles[128] = { [JOVE_OBJ_PAGEDIR] = _syscall_handle_pagedir, [JOVE_OBJ_PROCESSOR] = _syscall_handle_generic, [JOVE_OBJ_SHMEMORY] = _syscall_handle_generic, - [JOVE_OBJ_PCB] = _syscall_handle_generic, + [JOVE_OBJ_PCB] = _syscall_handle_pcb, [JOVE_OBJ_INT_HANDLE] = _syscall_handle_generic, [JOVE_OBJ_INITRD_FILE] = _syscall_handle_initrd_file, [JOVE_OBJ_FRAMEBUFFER] = _syscall_handle_generic, @@ -86,7 +86,7 @@ syscall_handler(uintmax_t message_path_raw, uint16_t message_pathlen) ctx.pcb = process_current(); pcb_t *pcb = obj_deref(ctx.pcb); - ctx.objdir = lockstack_push(&ctx.lockstack, obj_take(pcb_rootdir(pcb))); + ctx.objdir = lockstack_push(&ctx.lockstack, obj_take(pcb_getrootdir(pcb))); ctx.message = link_try_traverse_objdir( ctx.objdir, &ctx.lockstack, message_pathlen, message_path); @@ -113,7 +113,7 @@ syscall_handler(uintmax_t message_path_raw, uint16_t message_pathlen) } uintptr_t message_vptr = message_unmap(ctx.message.obj, - (jove_owned_obj_t*)pcb_pagedir(pcb)); + (jove_owned_obj_t*)pcb_getpagedir(pcb)); size_t messagelen = 0x1000; void *messagedata = (void*)message_getdata(ctx.message.obj); @@ -154,7 +154,7 @@ syscall_handler(uintmax_t message_path_raw, uint16_t message_pathlen) } remap_return: - message_remap(ctx.message.obj, (jove_owned_obj_t*)pcb_pagedir(pcb), message_vptr); + message_remap(ctx.message.obj, (jove_owned_obj_t*)pcb_getpagedir(pcb), message_vptr); release_return: lockstack_popall(&ctx.lockstack); diff --git a/sys/syscall.h b/sys/syscall.h index 461b104..082fe29 100644 --- a/sys/syscall.h +++ b/sys/syscall.h @@ -57,6 +57,7 @@ int _syscall_handle_vtt(syscall_context_t *ctx); int _syscall_handle_objdir(syscall_context_t *ctx); int _syscall_handle_untyped(syscall_context_t *ctx); int _syscall_handle_pagedir(syscall_context_t *ctx); +int _syscall_handle_pcb(syscall_context_t *ctx); int _syscall_handle_initrd_file(syscall_context_t *ctx); int _syscall_handle_message(syscall_context_t *ctx); diff --git a/sys/syscall_pcb.c b/sys/syscall_pcb.c new file mode 100644 index 0000000..b77be95 --- /dev/null +++ b/sys/syscall_pcb.c @@ -0,0 +1,26 @@ +#include "api/error.h" +#include "lib/printf.h" +#include "syscall.h" + +int +s_syscall_pcb_yield(jove_owned_obj_t *pcb_obj, + size_t bytes_left, + void *payload_data) +{ + kprintf("%s: Stub!\n", __func__); + return 0; +} + +int +_syscall_handle_pcb(syscall_context_t *ctx) +{ + switch(ctx->header->callid) { + case SYSCALL_PCB_YIELD: + if(ctx->target.permissions & SYSCALL_PERM_PCB_YIELD) + return s_syscall_pcb_yield(ctx->target.obj, ctx->bytes_left, ctx->payload); + return -EPERM; + + default: + return -EBADCALL; + } +} |
