Various renaming and refactoring
This commit is contained in:
@@ -7,6 +7,7 @@
|
||||
#include "mmgr.h"
|
||||
#include "syscalls.h"
|
||||
#include "types/syscallid.h"
|
||||
#include "types/status.h"
|
||||
#include <stddef.h>
|
||||
|
||||
#define MAX_SYSCALL_ID 256
|
||||
@@ -83,29 +84,35 @@ struct kernel_t
|
||||
|
||||
void kernel_initialize(struct boot_info_t *boot_info);
|
||||
|
||||
int set_syscall(int id, int arg_count, int pid, void *func_ptr);
|
||||
enum error_t set_syscall(int id, int arg_count, int pid, void *func_ptr);
|
||||
|
||||
size_t do_syscall(enum syscall_id_t id, syscall_arg_t arg1, syscall_arg_t arg2, syscall_arg_t arg3, void *pc, void *stack, unsigned long flags);
|
||||
|
||||
int load_module(struct module_t *module);
|
||||
enum error_t kernel_load_module(struct module_t *module);
|
||||
|
||||
int active_process();
|
||||
unsigned long kernel_current_pid();
|
||||
|
||||
int add_process(void *program_entry, int priority, physaddr_t address_space);
|
||||
struct process_context_t *kernel_current_context();
|
||||
|
||||
struct process_context_t *next_process();
|
||||
enum error_t kernel_store_active_context(struct process_context_t *context, size_t size);
|
||||
|
||||
int terminate_process(size_t process_id);
|
||||
enum error_t kernel_spawn_process(void *program_entry, int priority, physaddr_t address_space);
|
||||
|
||||
int store_active_context(struct process_context_t *context, size_t size);
|
||||
struct process_context_t *kernel_advance_scheduler();
|
||||
|
||||
struct process_context_t *get_active_context();
|
||||
enum error_t kernel_terminate_process(size_t process_id);
|
||||
|
||||
int open_port(unsigned long id);
|
||||
enum error_t kernel_create_port(unsigned long id);
|
||||
|
||||
int close_port(unsigned long id);
|
||||
enum error_t kernel_remove_port(unsigned long id);
|
||||
|
||||
int send_message(int recipient, struct message_t *message, int flags);
|
||||
unsigned long kernel_get_port_owner(unsigned long id);
|
||||
|
||||
enum error_t kernel_send_message(int recipient, struct message_t *message);
|
||||
|
||||
enum error_t kernel_queue_sender(int recipient);
|
||||
|
||||
enum error_t kernel_queue_message(int recipient, struct message_t *message);
|
||||
|
||||
int receive_message(struct message_t *buffer, int flags);
|
||||
|
||||
|
||||
@@ -44,6 +44,6 @@ size_t send(syscall_arg_t recipient, syscall_arg_t message, syscall_arg_t flags)
|
||||
|
||||
size_t receive(syscall_arg_t buffer, syscall_arg_t flags);
|
||||
|
||||
size_t openport(syscall_arg_t id);
|
||||
size_t open_port(syscall_arg_t id);
|
||||
|
||||
size_t closeport(syscall_arg_t id);
|
||||
size_t close_port(syscall_arg_t id);
|
||||
|
||||
@@ -1,14 +1,15 @@
|
||||
#pragma once
|
||||
|
||||
enum status_t
|
||||
enum error_t
|
||||
{
|
||||
S_OK = 0,
|
||||
S_NULL_POINTER,
|
||||
S_OUT_OF_BOUNDS,
|
||||
S_INVALID_ARGUMENT,
|
||||
S_OUT_OF_MEMORY,
|
||||
S_DOESNT_EXIST,
|
||||
S_EXISTS,
|
||||
S_BAD_SYSCALL,
|
||||
S_BUSY
|
||||
ENONE = 0,
|
||||
ENULLPTR,
|
||||
EOUTOFBOUNDS,
|
||||
EINVALIDARG,
|
||||
ENOMEM,
|
||||
EDOESNTEXIST,
|
||||
EEXISTS,
|
||||
ENOSYSCALL,
|
||||
EPERM,
|
||||
EBUSY
|
||||
};
|
||||
12
src/elf.c
12
src/elf.c
@@ -17,18 +17,18 @@ int load_program(struct elf_file_header_t *elf)
|
||||
for(size_t n = 0; n < program_header->memsize; n += page_size)
|
||||
{
|
||||
physaddr_t page = reserve_page();
|
||||
if(page == S_OUT_OF_MEMORY)
|
||||
if(page == ENOMEM)
|
||||
{
|
||||
return S_OUT_OF_MEMORY;
|
||||
return ENOMEM;
|
||||
}
|
||||
int status = map_page(d + n, page, PAGE_RW | PAGE_USERMODE | PAGE_EXECUTABLE);
|
||||
switch(status)
|
||||
{
|
||||
case S_OUT_OF_MEMORY:
|
||||
case ENOMEM:
|
||||
return status;
|
||||
case S_OUT_OF_BOUNDS:
|
||||
case EOUTOFBOUNDS:
|
||||
return status;
|
||||
case S_OK:
|
||||
case ENONE:
|
||||
memcpy(d + n, s + n, n + page_size < program_header->memsize ? page_size : program_header->memsize - n);
|
||||
}
|
||||
}
|
||||
@@ -36,5 +36,5 @@ int load_program(struct elf_file_header_t *elf)
|
||||
count--;
|
||||
program_header = (struct elf_program_header_t*)((void*)program_header + elf->phsize);
|
||||
}
|
||||
return S_OK;
|
||||
return ENONE;
|
||||
}
|
||||
@@ -103,7 +103,7 @@ int heap_contruct(struct heap_t *heap, void *base, void *start, size_t heap_size
|
||||
if((flags & PAGE_PRESENT) == 0)
|
||||
{
|
||||
int status = map_page((void*)heap->header + i, reserve_page(), PAGE_RW);
|
||||
if(status != S_OK)
|
||||
if(status != ENONE)
|
||||
{
|
||||
return status;
|
||||
}
|
||||
@@ -129,7 +129,7 @@ int heap_contruct(struct heap_t *heap, void *base, void *start, size_t heap_size
|
||||
heap->header[i + (1 << heap->tree_height)].state = UNAVAIL;
|
||||
}
|
||||
}
|
||||
return S_OK;
|
||||
return ENONE;
|
||||
}
|
||||
|
||||
void *heap_allocate(struct heap_t *heap, size_t size)
|
||||
|
||||
185
src/kernel.c
185
src/kernel.c
@@ -32,7 +32,7 @@ void kernel_initialize(struct boot_info_t *boot_info)
|
||||
kernel.next_pid = 1;
|
||||
kernel.process_table = NULL;
|
||||
kernel.port_table = NULL;
|
||||
if(construct_priority_queue(&kernel.priority_queue, 512) != S_OK)
|
||||
if(construct_priority_queue(&kernel.priority_queue, 512) != ENONE)
|
||||
{
|
||||
panic("Failed to construct priority queue.");
|
||||
}
|
||||
@@ -42,63 +42,63 @@ void kernel_initialize(struct boot_info_t *boot_info)
|
||||
set_syscall(SYSCALL_MUNMAP, 2, 0, munmap);
|
||||
set_syscall(SYSCALL_SEND, 3, 0, send);
|
||||
set_syscall(SYSCALL_RECEIVE, 2, 0, receive);
|
||||
set_syscall(SYSCALL_OPEN_PORT, 1, 0, openport);
|
||||
set_syscall(SYSCALL_CLOSE_PORT, 1, 0, closeport);
|
||||
set_syscall(SYSCALL_OPEN_PORT, 1, 0, open_port);
|
||||
set_syscall(SYSCALL_CLOSE_PORT, 1, 0, close_port);
|
||||
for(int i = 0; i < boot_info->module_count; i++)
|
||||
{
|
||||
if(load_module(&boot_info->modules[i]) != S_OK)
|
||||
if(kernel_load_module(&boot_info->modules[i]) != ENONE)
|
||||
{
|
||||
panic("Failed to load modules.");
|
||||
}
|
||||
}
|
||||
|
||||
if(initialize_interrupts() != S_OK)
|
||||
if(initialize_interrupts() != ENONE)
|
||||
{
|
||||
panic("Failed to initialize interrupts.");
|
||||
}
|
||||
|
||||
irq_enable();
|
||||
load_context(next_process());
|
||||
load_context(kernel_advance_scheduler());
|
||||
}
|
||||
|
||||
int set_syscall(int id, int arg_count, int pid, void *func_ptr)
|
||||
enum error_t set_syscall(int id, int arg_count, int pid, void *func_ptr)
|
||||
{
|
||||
if(id < 0 || id > MAX_SYSCALL_ID)
|
||||
{
|
||||
return S_OUT_OF_BOUNDS;
|
||||
return EOUTOFBOUNDS;
|
||||
}
|
||||
else if(kernel.syscall_table[id].defined)
|
||||
{
|
||||
return S_INVALID_ARGUMENT;
|
||||
return EINVALIDARG;
|
||||
}
|
||||
else if(arg_count < 0 || arg_count > 3)
|
||||
{
|
||||
return S_INVALID_ARGUMENT;
|
||||
return EINVALIDARG;
|
||||
}
|
||||
else if(pid != 0 && avl_get(kernel.process_table, pid) == NULL)
|
||||
{
|
||||
return S_DOESNT_EXIST;
|
||||
return EDOESNTEXIST;
|
||||
}
|
||||
else if(func_ptr == NULL)
|
||||
{
|
||||
return S_NULL_POINTER;
|
||||
return ENULLPTR;
|
||||
}
|
||||
kernel.syscall_table[id].defined = true;
|
||||
kernel.syscall_table[id].arg_count = arg_count;
|
||||
kernel.syscall_table[id].process_id = pid;
|
||||
kernel.syscall_table[id].func_ptr_0 = func_ptr;
|
||||
return S_OK;
|
||||
return ENONE;
|
||||
}
|
||||
|
||||
size_t do_syscall(enum syscall_id_t id, syscall_arg_t arg1, syscall_arg_t arg2, syscall_arg_t arg3, void *pc, void *stack, unsigned long flags)
|
||||
{
|
||||
if(id < 0 || id > MAX_SYSCALL_ID)
|
||||
{
|
||||
return S_BAD_SYSCALL;
|
||||
return ENOSYSCALL;
|
||||
}
|
||||
else if(!kernel.syscall_table[id].defined)
|
||||
{
|
||||
return S_BAD_SYSCALL;
|
||||
return ENOSYSCALL;
|
||||
}
|
||||
bool switched_address_space = false;
|
||||
if(kernel.syscall_table[id].process_id > 0)
|
||||
@@ -107,7 +107,7 @@ size_t do_syscall(enum syscall_id_t id, syscall_arg_t arg1, syscall_arg_t arg2,
|
||||
if(callee == NULL)
|
||||
{
|
||||
kernel.syscall_table[id].defined = false;
|
||||
return S_BAD_SYSCALL;
|
||||
return ENOSYSCALL;
|
||||
}
|
||||
paging_load_address_space(callee->page_table);
|
||||
switched_address_space = true;
|
||||
@@ -138,10 +138,10 @@ size_t do_syscall(enum syscall_id_t id, syscall_arg_t arg1, syscall_arg_t arg2,
|
||||
return result;
|
||||
}
|
||||
|
||||
int load_module(struct module_t *module)
|
||||
enum error_t kernel_load_module(struct module_t *module)
|
||||
{
|
||||
physaddr_t module_address_space = create_address_space();
|
||||
if(module_address_space == S_OUT_OF_MEMORY) {
|
||||
if(module_address_space == ENOMEM) {
|
||||
panic("failed to create address space for module: out of memory");
|
||||
}
|
||||
paging_load_address_space(module_address_space);
|
||||
@@ -152,9 +152,9 @@ int load_module(struct module_t *module)
|
||||
int status = map_page(load_base + load_offset, p, PAGE_RW);
|
||||
switch(status)
|
||||
{
|
||||
case S_OUT_OF_MEMORY:
|
||||
case ENOMEM:
|
||||
panic("ran out of memory while mapping module");
|
||||
case S_OUT_OF_BOUNDS:
|
||||
case EOUTOFBOUNDS:
|
||||
panic("got out-of-bounds error while mapping module");
|
||||
}
|
||||
load_offset += page_size;
|
||||
@@ -163,9 +163,9 @@ int load_module(struct module_t *module)
|
||||
int status = load_program(load_base);
|
||||
switch(status)
|
||||
{
|
||||
case S_OUT_OF_MEMORY:
|
||||
case ENOMEM:
|
||||
panic("ran out of memory while reading ELF file");
|
||||
case S_OUT_OF_BOUNDS:
|
||||
case EOUTOFBOUNDS:
|
||||
panic("got out-of-bounds error while reading ELF file");
|
||||
}
|
||||
void *module_entry = ((struct elf_file_header_t*)load_base)->entry;
|
||||
@@ -176,16 +176,16 @@ int load_module(struct module_t *module)
|
||||
int status = unmap_page(load_base + load_offset);
|
||||
switch(status)
|
||||
{
|
||||
case S_OUT_OF_MEMORY:
|
||||
case ENOMEM:
|
||||
panic("ran out of memory while unmapping module");
|
||||
case S_OUT_OF_BOUNDS:
|
||||
case EOUTOFBOUNDS:
|
||||
panic("got out-of-bounds error while unmapping module");
|
||||
}
|
||||
load_offset += page_size;
|
||||
}
|
||||
if(add_process(module_entry, 1, current_address_space()) > 0)
|
||||
if(kernel_spawn_process(module_entry, 1, current_address_space()) > 0)
|
||||
{
|
||||
return S_OK;
|
||||
return ENONE;
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -193,7 +193,7 @@ int load_module(struct module_t *module)
|
||||
}
|
||||
}
|
||||
|
||||
int active_process()
|
||||
unsigned long kernel_current_pid()
|
||||
{
|
||||
if(kernel.active_process == NULL)
|
||||
{
|
||||
@@ -205,7 +205,19 @@ int active_process()
|
||||
}
|
||||
}
|
||||
|
||||
int add_process(void *program_entry, int priority, physaddr_t address_space)
|
||||
struct process_context_t *kernel_current_context()
|
||||
{
|
||||
if(kernel.active_process == NULL)
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
else
|
||||
{
|
||||
return kernel.active_process->ctx;
|
||||
}
|
||||
}
|
||||
|
||||
enum error_t kernel_spawn_process(void *program_entry, int priority, physaddr_t address_space)
|
||||
{
|
||||
struct process_t *new_process = (struct process_t*) kmalloc(sizeof(struct process_t));
|
||||
if(new_process == NULL)
|
||||
@@ -227,7 +239,7 @@ int add_process(void *program_entry, int priority, physaddr_t address_space)
|
||||
return new_process->pid;
|
||||
}
|
||||
|
||||
struct process_context_t *next_process()
|
||||
struct process_context_t *kernel_advance_scheduler()
|
||||
{
|
||||
if(kernel.active_process != NULL)
|
||||
{
|
||||
@@ -243,12 +255,12 @@ struct process_context_t *next_process()
|
||||
panic("no processes available to enter!");
|
||||
}
|
||||
|
||||
int terminate_process(size_t process_id)
|
||||
enum error_t kernel_terminate_process(size_t process_id)
|
||||
{
|
||||
struct process_t *process = avl_get(kernel.process_table, process_id);
|
||||
if(process == NULL)
|
||||
{
|
||||
return S_DOESNT_EXIST;
|
||||
return EDOESNTEXIST;
|
||||
}
|
||||
if(kernel.active_process == process)
|
||||
{
|
||||
@@ -258,79 +270,72 @@ int terminate_process(size_t process_id)
|
||||
priorityqueue_remove(&kernel.priority_queue, process);
|
||||
destroy_context(process->ctx);
|
||||
kfree(process);
|
||||
return S_OK;
|
||||
return ENONE;
|
||||
}
|
||||
|
||||
int store_active_context(struct process_context_t *context, size_t size)
|
||||
enum error_t kernel_store_active_context(struct process_context_t *context, size_t size)
|
||||
{
|
||||
if(kernel.active_process != NULL && kernel.active_process->ctx != NULL)
|
||||
{
|
||||
memcpy(kernel.active_process->ctx, context, size);
|
||||
return S_OK;
|
||||
return ENONE;
|
||||
}
|
||||
else
|
||||
{
|
||||
return S_DOESNT_EXIST;
|
||||
return EDOESNTEXIST;
|
||||
}
|
||||
}
|
||||
|
||||
int open_port(unsigned long id)
|
||||
enum error_t kernel_create_port(unsigned long id)
|
||||
{
|
||||
if(avl_get(kernel.port_table, id) != NULL)
|
||||
{
|
||||
return S_EXISTS;
|
||||
return EEXISTS;
|
||||
}
|
||||
printf("opening port %i -> %i\n", id, kernel.active_process->pid);
|
||||
struct port_t *port = kmalloc(sizeof(struct port_t));
|
||||
port->id = id;
|
||||
port->owner_pid = kernel.active_process->pid;
|
||||
kernel.port_table = avl_insert(kernel.port_table, id, port);
|
||||
return S_OK;
|
||||
return ENONE;
|
||||
}
|
||||
|
||||
int close_port(unsigned long id)
|
||||
enum error_t kernel_remove_port(unsigned long id)
|
||||
{
|
||||
struct port_t *port = avl_get(kernel.port_table, id);
|
||||
if(port == NULL)
|
||||
{
|
||||
return S_DOESNT_EXIST;
|
||||
return EDOESNTEXIST;
|
||||
}
|
||||
else if(port->owner_pid != kernel.active_process->pid)
|
||||
{
|
||||
return S_INVALID_ARGUMENT;
|
||||
return EPERM;
|
||||
}
|
||||
printf("closing port %i attached to %i\n", id, kernel.active_process->pid);
|
||||
kernel.port_table = avl_remove(kernel.port_table, id);
|
||||
kfree(port);
|
||||
return S_OK;
|
||||
return ENONE;
|
||||
}
|
||||
|
||||
int send_message(int recipient, struct message_t *message, int flags)
|
||||
unsigned long kernel_get_port_owner(unsigned long id)
|
||||
{
|
||||
int op_type = flags & IO_OP;
|
||||
int dest_type = flags & IO_RECIPIENT_TYPE;
|
||||
if((flags & ~(IO_OP | IO_RECIPIENT_TYPE)) != 0 || dest_type >= IO_MAILBOX)
|
||||
struct port_t *port = avl_get(kernel.port_table, id);
|
||||
if(port == NULL)
|
||||
{
|
||||
printf("Invalid flags on send_message\n");
|
||||
return S_INVALID_ARGUMENT;
|
||||
}
|
||||
if(dest_type == IO_PORT)
|
||||
{
|
||||
struct port_t *port = avl_get(kernel.port_table, recipient);
|
||||
if(port != NULL)
|
||||
{
|
||||
recipient = port->owner_pid;
|
||||
return 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
printf("Port %i does not exist\n", recipient);
|
||||
return S_DOESNT_EXIST;
|
||||
}
|
||||
return port->owner_pid;
|
||||
}
|
||||
}
|
||||
|
||||
enum error_t kernel_send_message(int recipient, struct message_t *message)
|
||||
{
|
||||
struct process_t *dest = avl_get(kernel.process_table, recipient);
|
||||
if(dest == NULL)
|
||||
{
|
||||
return S_DOESNT_EXIST;
|
||||
return EDOESNTEXIST;
|
||||
}
|
||||
else if(dest->message_buffer != NULL)
|
||||
{
|
||||
@@ -343,29 +348,51 @@ int send_message(int recipient, struct message_t *message, int flags)
|
||||
paging_load_address_space(kernel.active_process->page_table);
|
||||
dest->message_buffer = NULL;
|
||||
dest->state = PROCESS_ACTIVE;
|
||||
set_context_return(dest->ctx, S_OK);
|
||||
set_context_return(dest->ctx, ENONE);
|
||||
priorityqueue_insert(&kernel.priority_queue, dest, dest->priority);
|
||||
return S_OK;
|
||||
}
|
||||
else if(op_type == IO_ASYNC)
|
||||
{
|
||||
printf("Queueing message from %i to %i\n", kernel.active_process->pid, dest->pid);
|
||||
struct message_t *queued_msg = kmalloc(sizeof(struct message_t));
|
||||
if(queued_msg == NULL)
|
||||
{
|
||||
return S_OUT_OF_MEMORY;
|
||||
}
|
||||
memcpy(queued_msg, message, sizeof(struct message_t));
|
||||
queue_insert(&dest->message_queue, queued_msg);
|
||||
return S_OK;
|
||||
return ENONE;
|
||||
}
|
||||
else
|
||||
{
|
||||
return EBUSY;
|
||||
}
|
||||
}
|
||||
|
||||
enum error_t kernel_queue_sender(int recipient)
|
||||
{
|
||||
struct process_t *dest = avl_get(kernel.process_table, recipient);
|
||||
if(dest != NULL)
|
||||
{
|
||||
printf("Queueing process %i to %i\n", kernel.active_process->pid, dest->pid);
|
||||
queue_insert(&dest->sending_queue, kernel.active_process);
|
||||
kernel.active_process->state = PROCESS_SENDING;
|
||||
kernel.active_process = NULL;
|
||||
load_context(next_process());
|
||||
return ENONE;
|
||||
}
|
||||
else
|
||||
{
|
||||
return EDOESNTEXIST;
|
||||
}
|
||||
}
|
||||
|
||||
enum error_t kernel_queue_message(int recipient, struct message_t *message)
|
||||
{
|
||||
struct process_t *dest = avl_get(kernel.process_table, recipient);
|
||||
if(dest != NULL)
|
||||
{
|
||||
printf("Queueing message from %i to %i\n", kernel.active_process->pid, dest->pid);
|
||||
struct message_t *queued_msg = kmalloc(sizeof(struct message_t));
|
||||
if(queued_msg == NULL)
|
||||
{
|
||||
return ENOMEM;
|
||||
}
|
||||
memcpy(queued_msg, message, sizeof(struct message_t));
|
||||
queue_insert(&dest->message_queue, queued_msg);
|
||||
return ENONE;
|
||||
}
|
||||
else
|
||||
{
|
||||
return EDOESNTEXIST;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -381,27 +408,27 @@ int receive_message(struct message_t *buffer, int flags)
|
||||
paging_load_address_space(kernel.active_process->page_table);
|
||||
memcpy(buffer, &kernel_buffer, sizeof(struct message_t));
|
||||
sender->state = PROCESS_ACTIVE;
|
||||
set_context_return(sender->ctx, S_OK);
|
||||
set_context_return(sender->ctx, ENONE);
|
||||
priorityqueue_insert(&kernel.priority_queue, sender, sender->priority);
|
||||
return S_OK;
|
||||
return ENONE;
|
||||
}
|
||||
else if(kernel.active_process->message_queue.count > 0)
|
||||
{
|
||||
struct message_t *queued_msg = queue_get_next(&kernel.active_process->message_queue);
|
||||
memcpy(buffer, queued_msg, sizeof(struct message_t));
|
||||
kfree(queued_msg);
|
||||
return S_OK;
|
||||
return ENONE;
|
||||
}
|
||||
else if((flags & IO_OP) == IO_ASYNC)
|
||||
{
|
||||
return S_DOESNT_EXIST;
|
||||
return EDOESNTEXIST;
|
||||
}
|
||||
else
|
||||
{
|
||||
kernel.active_process->message_buffer = buffer;
|
||||
kernel.active_process->state = PROCESS_REQUESTING;
|
||||
kernel.active_process = NULL;
|
||||
load_context(next_process());
|
||||
load_context(kernel_advance_scheduler());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
38
src/mmgr.c
38
src/mmgr.c
@@ -54,15 +54,15 @@ int initialize_page_stack(struct memory_map_t *map, physaddr_t *stack_base)
|
||||
size_t location = (map->array[i].location + page_size - 1) & ~(page_size - 1);
|
||||
while(location + page_size <= map->array[i].location + map->array[i].size)
|
||||
{
|
||||
if(free_page(location) != S_OK)
|
||||
if(free_page(location) != ENONE)
|
||||
{
|
||||
return S_OUT_OF_MEMORY;
|
||||
return ENOMEM;
|
||||
}
|
||||
page_stack.total_pages++;
|
||||
location += page_size;
|
||||
}
|
||||
}
|
||||
return S_OK;
|
||||
return ENONE;
|
||||
}
|
||||
|
||||
physaddr_t reserve_page()
|
||||
@@ -74,7 +74,7 @@ physaddr_t reserve_page()
|
||||
*page_stack.stack_pointer = (physaddr_t) 0;
|
||||
return frame;
|
||||
}
|
||||
return S_OUT_OF_MEMORY;
|
||||
return ENOMEM;
|
||||
}
|
||||
|
||||
int free_page(physaddr_t location)
|
||||
@@ -83,21 +83,21 @@ int free_page(physaddr_t location)
|
||||
{
|
||||
*page_stack.stack_pointer = location;
|
||||
page_stack.stack_pointer++;
|
||||
return S_OK;
|
||||
return ENONE;
|
||||
}
|
||||
else
|
||||
{
|
||||
switch(map_page(page_stack.limit_pointer, location, PAGE_RW))
|
||||
{
|
||||
case S_OUT_OF_MEMORY:
|
||||
return S_OUT_OF_MEMORY;
|
||||
case S_OUT_OF_BOUNDS:
|
||||
return S_OUT_OF_BOUNDS;
|
||||
case S_OK:
|
||||
case ENOMEM:
|
||||
return ENOMEM;
|
||||
case EOUTOFBOUNDS:
|
||||
return EOUTOFBOUNDS;
|
||||
case ENONE:
|
||||
page_stack.limit_pointer += page_size / sizeof(*page_stack.limit_pointer);
|
||||
return S_OK;
|
||||
return ENONE;
|
||||
}
|
||||
return S_OUT_OF_MEMORY;
|
||||
return ENOMEM;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -120,9 +120,9 @@ physaddr_t create_address_space()
|
||||
{
|
||||
physaddr_t table = reserve_page();
|
||||
int result;
|
||||
if (table == S_OUT_OF_MEMORY)
|
||||
if (table == ENOMEM)
|
||||
{
|
||||
return S_OUT_OF_MEMORY;
|
||||
return ENOMEM;
|
||||
}
|
||||
else if((result = paging_init_top_table(table)))
|
||||
{
|
||||
@@ -143,7 +143,7 @@ int map_page(void *page, physaddr_t frame, int flags)
|
||||
{
|
||||
if (frame % page_size != 0)
|
||||
{
|
||||
return S_INVALID_ARGUMENT;
|
||||
return EINVALIDARG;
|
||||
}
|
||||
for(int level = 0; level < page_table_levels - 1; level++)
|
||||
{
|
||||
@@ -151,16 +151,16 @@ int map_page(void *page, physaddr_t frame, int flags)
|
||||
if(present == 0)
|
||||
{
|
||||
physaddr_t new_table = reserve_page();
|
||||
if(new_table == S_OUT_OF_MEMORY)
|
||||
if(new_table == ENOMEM)
|
||||
{
|
||||
return S_OUT_OF_MEMORY;
|
||||
return ENOMEM;
|
||||
}
|
||||
set_pte(page, level, PAGE_PRESENT | PAGE_USERMODE | PAGE_RW, new_table);
|
||||
wipe_page_table(page, level + 1);
|
||||
}
|
||||
}
|
||||
set_pte(page, page_table_levels - 1, PAGE_PRESENT | flags, frame);
|
||||
return S_OK;
|
||||
return ENONE;
|
||||
}
|
||||
|
||||
physaddr_t unmap_page(void *page)
|
||||
@@ -168,7 +168,7 @@ physaddr_t unmap_page(void *page)
|
||||
for(int level = 0; level < page_table_levels; level++)
|
||||
{
|
||||
if((get_pte_type(page, level) & PAGE_PRESENT) == 0)
|
||||
return S_OUT_OF_BOUNDS;
|
||||
return EOUTOFBOUNDS;
|
||||
}
|
||||
physaddr_t frame = get_pte_address(page, page_table_levels - 1);
|
||||
set_pte(page, page_table_levels - 1, 0, 0);
|
||||
|
||||
@@ -31,11 +31,11 @@ int construct_priority_queue(struct priority_queue_t *queue, int capacity)
|
||||
queue->heap = kmalloc(sizeof(struct priority_queue_node_t) * capacity);
|
||||
if(queue->heap == NULL)
|
||||
{
|
||||
return S_OUT_OF_MEMORY;
|
||||
return ENOMEM;
|
||||
}
|
||||
queue->capacity = capacity;
|
||||
queue->size = 0;
|
||||
return S_OK;
|
||||
return ENONE;
|
||||
}
|
||||
|
||||
void *priorityqueue_extract_min(struct priority_queue_t *queue)
|
||||
@@ -52,7 +52,7 @@ void *priorityqueue_extract_min(struct priority_queue_t *queue)
|
||||
int priorityqueue_insert(struct priority_queue_t *queue, void *value, int priority)
|
||||
{
|
||||
if(queue->size == queue->capacity)
|
||||
return S_OUT_OF_MEMORY;
|
||||
return ENOMEM;
|
||||
size_t i = queue->size;
|
||||
queue->size++;
|
||||
while(i > 0 && queue->heap[(i - 1) / 2].priority > priority)
|
||||
@@ -62,7 +62,7 @@ int priorityqueue_insert(struct priority_queue_t *queue, void *value, int priori
|
||||
}
|
||||
queue->heap[i].priority = priority;
|
||||
queue->heap[i].value = value;
|
||||
return S_OK;
|
||||
return ENONE;
|
||||
}
|
||||
|
||||
int priorityqueue_remove(struct priority_queue_t *queue, void *value)
|
||||
@@ -74,8 +74,8 @@ int priorityqueue_remove(struct priority_queue_t *queue, void *value)
|
||||
queue->size--;
|
||||
queue->heap[i] = queue->heap[queue->size];
|
||||
heapify(queue, i);
|
||||
return S_OK;
|
||||
return ENONE;
|
||||
}
|
||||
}
|
||||
return S_OUT_OF_BOUNDS;
|
||||
return EOUTOFBOUNDS;
|
||||
}
|
||||
@@ -2,6 +2,7 @@
|
||||
#include "kernel.h"
|
||||
#include "mmgr.h"
|
||||
#include "stdio.h"
|
||||
#include "platform/context.h"
|
||||
#include "types/status.h"
|
||||
|
||||
size_t test_syscall(syscall_arg_t str)
|
||||
@@ -17,29 +18,29 @@ size_t mmap(syscall_arg_t arg_location, syscall_arg_t arg_length, syscall_arg_t
|
||||
unsigned long flags = arg_flags.unsigned_int;
|
||||
if(location % page_size != 0 || length % page_size != 0)
|
||||
{
|
||||
return S_INVALID_ARGUMENT;
|
||||
return EINVALIDARG;
|
||||
}
|
||||
else if(location == NULL)
|
||||
{
|
||||
return S_NULL_POINTER;
|
||||
return ENULLPTR;
|
||||
}
|
||||
for(size_t i = 0; i < length; i += page_size)
|
||||
{
|
||||
if(page_type((void*)(location + i)) & PAGE_PRESENT)
|
||||
{
|
||||
return S_EXISTS;
|
||||
return EEXISTS;
|
||||
}
|
||||
}
|
||||
size_t n = 0;
|
||||
int status = S_OK;
|
||||
while(n < length && status == S_OK)
|
||||
int status = ENONE;
|
||||
while(n < length && status == ENONE)
|
||||
{
|
||||
physaddr_t frame = reserve_page();
|
||||
status = frame % page_size;
|
||||
if(status == S_OK)
|
||||
if(status == ENONE)
|
||||
{
|
||||
status = map_page((void*)(location + n), frame, PAGE_USERMODE | PAGE_RW);
|
||||
if(status != S_OK && free_page(frame) != S_OK)
|
||||
if(status != ENONE && free_page(frame) != ENONE)
|
||||
{
|
||||
panic("critical error reached during mmap.");
|
||||
}
|
||||
@@ -50,7 +51,7 @@ size_t mmap(syscall_arg_t arg_location, syscall_arg_t arg_length, syscall_arg_t
|
||||
break;
|
||||
}
|
||||
}
|
||||
if(status != S_OK && munmap(arg_location, arg_length) != S_OK)
|
||||
if(status != ENONE && munmap(arg_location, arg_length) != ENONE)
|
||||
{
|
||||
panic("critical error reached during mmap.");
|
||||
}
|
||||
@@ -63,15 +64,15 @@ size_t munmap(syscall_arg_t arg_location, syscall_arg_t arg_length)
|
||||
unsigned long length = arg_length.unsigned_int;
|
||||
if(location % page_size != 0 || length % page_size != 0)
|
||||
{
|
||||
return S_INVALID_ARGUMENT;
|
||||
return EINVALIDARG;
|
||||
}
|
||||
else if(location == 0)
|
||||
{
|
||||
return S_NULL_POINTER;
|
||||
return ENULLPTR;
|
||||
}
|
||||
size_t n = 0;
|
||||
int status = S_OK;
|
||||
while(n < length && status == S_OK)
|
||||
int status = ENONE;
|
||||
while(n < length && status == ENONE)
|
||||
{
|
||||
int type = page_type((void*)(location + n));
|
||||
physaddr_t frame;
|
||||
@@ -89,12 +90,47 @@ size_t munmap(syscall_arg_t arg_location, syscall_arg_t arg_length)
|
||||
|
||||
size_t terminate_self()
|
||||
{
|
||||
return terminate_process(active_process());
|
||||
return kernel_terminate_process(kernel_current_pid());
|
||||
}
|
||||
|
||||
size_t send(syscall_arg_t recipient, syscall_arg_t message, syscall_arg_t flags)
|
||||
{
|
||||
return send_message(recipient.unsigned_int, message.ptr, flags.unsigned_int);
|
||||
unsigned long op_type = flags.unsigned_int & IO_OP;
|
||||
unsigned long dest_type = flags.unsigned_int & IO_RECIPIENT_TYPE;
|
||||
if((flags.unsigned_int & ~(IO_OP | IO_RECIPIENT_TYPE)) != 0 || dest_type >= IO_MAILBOX)
|
||||
{
|
||||
printf("Invalid flags on send()\n");
|
||||
return EINVALIDARG;
|
||||
}
|
||||
if(dest_type == IO_PORT)
|
||||
{
|
||||
recipient.unsigned_int = kernel_get_port_owner(recipient.unsigned_int);
|
||||
if(recipient.unsigned_int == 0)
|
||||
{
|
||||
return EDOESNTEXIST;
|
||||
}
|
||||
}
|
||||
enum error_t status = kernel_send_message(recipient.unsigned_int, message.ptr);
|
||||
if(status == EBUSY && op_type == IO_SYNC)
|
||||
{
|
||||
status = kernel_queue_sender(recipient.unsigned_int);
|
||||
if(status)
|
||||
{
|
||||
return status;
|
||||
}
|
||||
else
|
||||
{
|
||||
load_context(kernel_advance_scheduler());
|
||||
}
|
||||
}
|
||||
else if(status == EBUSY && op_type == IO_ASYNC)
|
||||
{
|
||||
return kernel_queue_message(recipient.unsigned_int, message.ptr);
|
||||
}
|
||||
else
|
||||
{
|
||||
return status;
|
||||
}
|
||||
}
|
||||
|
||||
size_t receive(syscall_arg_t buffer, syscall_arg_t flags)
|
||||
@@ -102,12 +138,12 @@ size_t receive(syscall_arg_t buffer, syscall_arg_t flags)
|
||||
return receive_message(buffer.ptr, flags.unsigned_int);
|
||||
}
|
||||
|
||||
size_t openport(syscall_arg_t id)
|
||||
size_t open_port(syscall_arg_t id)
|
||||
{
|
||||
return open_port(id.unsigned_int);
|
||||
return kernel_create_port(id.unsigned_int);
|
||||
}
|
||||
|
||||
size_t closeport(syscall_arg_t id)
|
||||
size_t close_port(syscall_arg_t id)
|
||||
{
|
||||
return close_port(id.unsigned_int);
|
||||
return kernel_remove_port(id.unsigned_int);
|
||||
}
|
||||
|
||||
@@ -41,7 +41,7 @@ void destroy_context(void *ctx)
|
||||
|
||||
void save_context(struct process_context_t *context)
|
||||
{
|
||||
store_active_context(context, sizeof(*context));
|
||||
kernel_store_active_context(context, sizeof(*context));
|
||||
}
|
||||
|
||||
void set_context_pc(struct process_context_t *context, void *pc)
|
||||
|
||||
@@ -87,7 +87,7 @@ isr_preempt:
|
||||
call save_context
|
||||
mov %ebp, %esp
|
||||
|
||||
call next_process
|
||||
call kernel_advance_scheduler
|
||||
|
||||
push %eax
|
||||
call load_context
|
||||
|
||||
Reference in New Issue
Block a user