Renamed some syscalls
This commit is contained in:
@@ -14,4 +14,4 @@ To build the kernel for the x86 platform, run:
|
||||
- `make`
|
||||
|
||||
So far this code has only been tested to compile using GCC. Some modifications might be necessary to build this project using other compilers. For a guide on building
|
||||
a cross-compiler, see the article on [osdev.org](https://wiki.osdev.org/GCC_Cross-Compiler).
|
||||
a cross-compiler, see the article on [osdev.org](https://wiki.osdev.org/GCC_Cross-Compiler).
|
||||
|
||||
@@ -9,6 +9,7 @@
|
||||
#include "types/status.h"
|
||||
#include "types/pid.h"
|
||||
#include "types/oid.h"
|
||||
#include "types/sighandler.h"
|
||||
#include <libmalloc/memmap.h>
|
||||
#include <stddef.h>
|
||||
|
||||
@@ -24,8 +25,6 @@
|
||||
#define IO_PORT 1 << 1
|
||||
#define IO_MAILBOX 2 << 1
|
||||
|
||||
typedef unsigned long (*signal_handler_t)(void*, void*);
|
||||
|
||||
struct process_context_t;
|
||||
|
||||
struct module_t
|
||||
@@ -54,7 +53,7 @@ struct message_t
|
||||
|
||||
void kernel_initialize(struct boot_info_t *boot_info);
|
||||
|
||||
error_t kernel_set_syscall(int id, int arg_count, pid_t pid, void *func_ptr);
|
||||
error_t kernel_set_syscall(int id, int arg_count, void *func_ptr);
|
||||
|
||||
size_t kernel_do_syscall(syscall_id_t id, syscall_arg_t arg1, syscall_arg_t arg2, syscall_arg_t arg3, void *pc, void *stack, unsigned long flags);
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
#ifndef _QUARK_SYSCALLS_H
|
||||
#define _QUARK_SYSCALLS_S
|
||||
#define _QUARK_SYSCALLS_H
|
||||
|
||||
#include <types/syscallarg.h>
|
||||
#include <types/syscallid.h>
|
||||
@@ -26,7 +26,7 @@ static inline int mmap(void *addr, unsigned long length, long flags)
|
||||
arg1.ptr = addr;
|
||||
arg2.unsigned_int = length;
|
||||
arg3.signed_int = flags;
|
||||
return (int) _do_syscall(SYSCALL_MMAP, arg1, arg2, arg3);
|
||||
return (int) _do_syscall(SYSCALL_MAP_ANON, arg1, arg2, arg3);
|
||||
}
|
||||
|
||||
static inline int munmap(void *addr, unsigned long length)
|
||||
@@ -37,7 +37,7 @@ static inline int munmap(void *addr, unsigned long length)
|
||||
arg1.ptr = addr;
|
||||
arg2.unsigned_int = length;
|
||||
arg3.unsigned_int = 0UL;
|
||||
return (int) _do_syscall(SYSCALL_MUNMAP, arg1, arg2, arg3);
|
||||
return (int) _do_syscall(SYSCALL_UNMAP_ANON, arg1, arg2, arg3);
|
||||
}
|
||||
|
||||
static inline int map_physical(void *addr, physaddr_t phys_addr, unsigned long length)
|
||||
|
||||
@@ -1,16 +1,23 @@
|
||||
#pragma once
|
||||
#ifndef QUARK_SYSCALL_DEF_H
|
||||
#define QUARK_SYSCALL_DEF_H
|
||||
|
||||
#include "types/syscallarg.h"
|
||||
#include "types/sigaction.h"
|
||||
#include "types/pid.h"
|
||||
#include "types/oid.h"
|
||||
#include "types/syscallret.h"
|
||||
#include <stdbool.h>
|
||||
#include <stddef.h>
|
||||
|
||||
typedef size_t (*syscall_ptr_0_t)();
|
||||
extern void *syscall_table[];
|
||||
|
||||
typedef size_t (*syscall_ptr_1_t)(syscall_arg_t);
|
||||
typedef syscallret_t (*syscall_ptr_0_t)();
|
||||
|
||||
typedef size_t (*syscall_ptr_2_t)(syscall_arg_t, syscall_arg_t);
|
||||
typedef syscallret_t (*syscall_ptr_1_t)(syscall_arg_t);
|
||||
|
||||
typedef size_t (*syscall_ptr_3_t)(syscall_arg_t, syscall_arg_t, syscall_arg_t);
|
||||
typedef syscallret_t (*syscall_ptr_2_t)(syscall_arg_t, syscall_arg_t);
|
||||
|
||||
typedef syscallret_t (*syscall_ptr_3_t)(syscall_arg_t, syscall_arg_t, syscall_arg_t);
|
||||
|
||||
struct syscall_t
|
||||
{
|
||||
@@ -26,28 +33,106 @@ struct syscall_t
|
||||
};
|
||||
};
|
||||
|
||||
size_t test_syscall(syscall_arg_t str);
|
||||
/**
|
||||
* @brief Outputs the given string from kernel mode.
|
||||
*
|
||||
* @param str The string to output.
|
||||
*/
|
||||
syscallret_t test_syscall(syscall_arg_t str);
|
||||
|
||||
size_t syscall_mmap(syscall_arg_t location, syscall_arg_t length, syscall_arg_t flags);
|
||||
/**
|
||||
*
|
||||
*/
|
||||
syscallret_t syscall_map_anon(syscall_arg_t location, syscall_arg_t length, syscall_arg_t flags);
|
||||
|
||||
size_t syscall_munmap(syscall_arg_t location, syscall_arg_t length);
|
||||
/**
|
||||
*
|
||||
*/
|
||||
syscallret_t syscall_unmap_anon(syscall_arg_t location, syscall_arg_t length);
|
||||
|
||||
size_t syscall_map_physical(syscall_arg_t arg_addr, syscall_arg_t arg_phys_addr, syscall_arg_t arg_length);
|
||||
/**
|
||||
*
|
||||
*/
|
||||
syscallret_t syscall_map_physical(syscall_arg_t arg_addr, syscall_arg_t arg_phys_addr, syscall_arg_t arg_length);
|
||||
|
||||
size_t syscall_unmap_physical(syscall_arg_t arg_addr, syscall_arg_t arg_length);
|
||||
/**
|
||||
*
|
||||
*/
|
||||
syscallret_t syscall_unmap_physical(syscall_arg_t arg_addr, syscall_arg_t arg_length);
|
||||
|
||||
size_t syscall_terminate_self();
|
||||
/**
|
||||
*
|
||||
*/
|
||||
syscallret_t syscall_open_port(syscall_arg_t id);
|
||||
|
||||
size_t syscall_create_object();
|
||||
/**
|
||||
*
|
||||
*/
|
||||
syscallret_t syscall_close_port(syscall_arg_t id);
|
||||
|
||||
size_t syscall_aquire_object();
|
||||
/**
|
||||
*
|
||||
*/
|
||||
syscallret_t syscall_send_pid(syscall_arg_t recipient, syscall_arg_t message, syscall_arg_t flags);
|
||||
|
||||
size_t syscall_release_object();
|
||||
/**
|
||||
*
|
||||
*/
|
||||
syscallret_t syscall_send_port(syscall_arg_t recipient, syscall_arg_t message, syscall_arg_t flags);
|
||||
|
||||
size_t syscall_send(syscall_arg_t recipient, syscall_arg_t message, syscall_arg_t flags);
|
||||
/**
|
||||
*
|
||||
*/
|
||||
syscallret_t syscall_receive(syscall_arg_t buffer, syscall_arg_t flags);
|
||||
|
||||
size_t syscall_receive(syscall_arg_t buffer, syscall_arg_t flags);
|
||||
/**
|
||||
*
|
||||
*/
|
||||
syscallret_t syscall_create_object(void *location, size_t size, int flags);
|
||||
|
||||
size_t syscall_open_port(syscall_arg_t id);
|
||||
/**
|
||||
*
|
||||
*/
|
||||
syscallret_t syscall_aquire_object(oid_t id, void *location);
|
||||
|
||||
size_t syscall_close_port(syscall_arg_t id);
|
||||
/**
|
||||
*
|
||||
*/
|
||||
syscallret_t syscall_release_object(oid_t id);
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
syscallret_t syscall_get_pid();
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
syscallret_t syscall_clone(void (*entry)(void*), void *arg, void *stack, int flags);
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
syscallret_t syscall_signal_action(int id, struct signal_action_t *action, int flags);
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
syscallret_t syscall_signal_return();
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
syscallret_t syscall_signal_raise(pid_t pid, int sigid);
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
syscallret_t syscall_intr_action(int id, struct signal_action_t *action, int flags);
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
syscallret_t syscall_intr_return();
|
||||
|
||||
#endif
|
||||
|
||||
@@ -4,16 +4,25 @@
|
||||
typedef enum
|
||||
{
|
||||
SYSCALL_TEST = 1,
|
||||
SYSCALL_MMAP,
|
||||
SYSCALL_MUNMAP,
|
||||
SYSCALL_MAP_ANON,
|
||||
SYSCALL_UNMAP_ANON,
|
||||
SYSCALL_MAP_PHYS,
|
||||
SYSCALL_UNMAP_PHYS,
|
||||
SYSCALL_YIELD,
|
||||
SYSCALL_EXIT,
|
||||
SYSCALL_SEND,
|
||||
SYSCALL_RECEIVE,
|
||||
SYSCALL_OPEN_PORT,
|
||||
SYSCALL_CLOSE_PORT
|
||||
SYSCALL_CLOSE_PORT,
|
||||
SYSCALL_SEND_PID,
|
||||
SYSCALL_SEND_PORT,
|
||||
SYSCALL_RECEIVE,
|
||||
SYSCALL_CREATE_OBJECT,
|
||||
SYSCALL_AQUIRE_OBJECT,
|
||||
SYSCALL_RELEASE_OBJECT,
|
||||
SYSCALL_GET_PID,
|
||||
SYSCALL_CLONE,
|
||||
SYSCALL_SIGNAL_ACTION,
|
||||
SYSCALL_SIGNAL_RETURN,
|
||||
SYSCALL_SIGNAL_RAISE,
|
||||
SYSCALL_INTR_ACTION,
|
||||
SYSCALL_INTR_RETURN
|
||||
} syscall_id_t;
|
||||
|
||||
#endif
|
||||
@@ -1,5 +1,5 @@
|
||||
bin_PROGRAMS = quark-kernel
|
||||
quark_kernel_SOURCES = kernel.c mmgr.c priorityqueue.c stdio.c string.c elf.c syscalls.c heap.c avltree.c queue.c math.c
|
||||
quark_kernel_SOURCES = kernel.c mmgr.c priorityqueue.c stdio.c string.c elf.c syscalls.c heap.c avltree.c queue.c math.c process.c sharedobject.c
|
||||
quark_kernel_LDADD = -lgcc -lmalloc
|
||||
quark_kernel_CFLAGS = -I$(top_srcdir)/include -I$(prefix)/include -ffreestanding -mgeneral-regs-only -O0 -Wall -ggdb
|
||||
quark_kernel_LDFLAGS = -L$(prefix)/lib -nostdlib
|
||||
|
||||
158
src/kernel.c
158
src/kernel.c
@@ -7,11 +7,34 @@
|
||||
#include "string.h"
|
||||
#include "config.h"
|
||||
#include "system.h"
|
||||
#include "process.h"
|
||||
#include "platform/interrupts.h"
|
||||
#include "platform/context.h"
|
||||
#include "platform/putc.h"
|
||||
#include "types/status.h"
|
||||
#include "types/syscallid.h"
|
||||
#include "types/sigaction.h"
|
||||
|
||||
void *syscall_table[] = {
|
||||
NULL,
|
||||
(void*)test_syscall,
|
||||
(void*)syscall_map_anon,
|
||||
(void*)syscall_unmap_anon,
|
||||
(void*)syscall_map_physical,
|
||||
(void*)syscall_unmap_physical,
|
||||
(void*)syscall_open_port,
|
||||
(void*)syscall_close_port,
|
||||
(void*)syscall_send_pid,
|
||||
(void*)syscall_receive,
|
||||
(void*)syscall_create_object,
|
||||
(void*)syscall_aquire_object,
|
||||
(void*)syscall_release_object,
|
||||
(void*)syscall_get_pid,
|
||||
(void*)syscall_clone,
|
||||
(void*)syscall_signal_action,
|
||||
(void*)syscall_signal_return,
|
||||
(void*)syscall_signal_raise
|
||||
};
|
||||
|
||||
struct shared_object_t
|
||||
{
|
||||
@@ -23,28 +46,10 @@ struct shared_object_t
|
||||
};
|
||||
|
||||
struct shared_object_mapping_t
|
||||
{
|
||||
void *virt_addr;
|
||||
};
|
||||
|
||||
enum process_state_t
|
||||
{
|
||||
PROCESS_ACTIVE,
|
||||
PROCESS_REQUESTING,
|
||||
PROCESS_SENDING
|
||||
};
|
||||
|
||||
struct process_t
|
||||
{
|
||||
pid_t pid;
|
||||
int priority;
|
||||
physaddr_t page_table;
|
||||
struct avltree_t *shared_objects;
|
||||
enum process_state_t state;
|
||||
struct queue_t sending_queue;
|
||||
struct queue_t message_queue;
|
||||
struct message_t *message_buffer;
|
||||
struct process_context_t *ctx;
|
||||
oid_t oid;
|
||||
void *virt_addr;
|
||||
};
|
||||
|
||||
struct port_t
|
||||
@@ -53,14 +58,6 @@ struct port_t
|
||||
pid_t owner_pid;
|
||||
};
|
||||
|
||||
struct signal_action_t
|
||||
{
|
||||
pid_t pid;
|
||||
signal_handler_t func_ptr;
|
||||
void (*trampoline_ptr)();
|
||||
void *userdata;
|
||||
};
|
||||
|
||||
struct signal_context_t
|
||||
{
|
||||
unsigned long signal_id;
|
||||
@@ -121,15 +118,25 @@ void kernel_initialize(struct boot_info_t *boot_info)
|
||||
kernel_panic("Failed to construct priority queue.");
|
||||
}
|
||||
memset(kernel.syscall_table, 0, sizeof(struct syscall_t) * MAX_SYSCALL_ID);
|
||||
kernel_set_syscall(SYSCALL_TEST, 1, 0, test_syscall);
|
||||
kernel_set_syscall(SYSCALL_MMAP, 3, 0, syscall_mmap);
|
||||
kernel_set_syscall(SYSCALL_MUNMAP, 2, 0, syscall_munmap);
|
||||
kernel_set_syscall(SYSCALL_MAP_PHYS, 3, 0, syscall_map_physical);
|
||||
kernel_set_syscall(SYSCALL_UNMAP_PHYS, 2, 0, syscall_unmap_physical);
|
||||
kernel_set_syscall(SYSCALL_SEND, 3, 0, syscall_send);
|
||||
kernel_set_syscall(SYSCALL_RECEIVE, 2, 0, syscall_receive);
|
||||
kernel_set_syscall(SYSCALL_OPEN_PORT, 1, 0, syscall_open_port);
|
||||
kernel_set_syscall(SYSCALL_CLOSE_PORT, 1, 0, syscall_close_port);
|
||||
kernel_set_syscall(SYSCALL_TEST, 1, test_syscall);
|
||||
kernel_set_syscall(SYSCALL_MAP_ANON, 3, syscall_map_anon);
|
||||
kernel_set_syscall(SYSCALL_UNMAP_ANON, 2, syscall_unmap_anon);
|
||||
kernel_set_syscall(SYSCALL_MAP_PHYS, 3, syscall_map_physical);
|
||||
kernel_set_syscall(SYSCALL_UNMAP_PHYS, 2, syscall_unmap_physical);
|
||||
kernel_set_syscall(SYSCALL_OPEN_PORT, 1, syscall_open_port);
|
||||
kernel_set_syscall(SYSCALL_CLOSE_PORT, 1, syscall_close_port);
|
||||
kernel_set_syscall(SYSCALL_SEND_PID, 3, syscall_send_pid);
|
||||
kernel_set_syscall(SYSCALL_SEND_PORT, 3, syscall_send_port);
|
||||
kernel_set_syscall(SYSCALL_RECEIVE, 2, syscall_receive);
|
||||
kernel_set_syscall(SYSCALL_CREATE_OBJECT, 3, syscall_create_object);
|
||||
kernel_set_syscall(SYSCALL_AQUIRE_OBJECT, 2, syscall_aquire_object);
|
||||
kernel_set_syscall(SYSCALL_RELEASE_OBJECT, 1, syscall_release_object);
|
||||
kernel_set_syscall(SYSCALL_GET_PID, 0, syscall_get_pid);
|
||||
kernel_set_syscall(SYSCALL_SIGNAL_ACTION, 3, syscall_signal_action);
|
||||
kernel_set_syscall(SYSCALL_SIGNAL_RETURN, 0, syscall_signal_return);
|
||||
kernel_set_syscall(SYSCALL_SIGNAL_RAISE, 2, syscall_signal_raise);
|
||||
kernel_set_syscall(SYSCALL_INTR_ACTION, 3, syscall_intr_action);
|
||||
kernel_set_syscall(SYSCALL_INTR_RETURN, 0, syscall_intr_return);
|
||||
for(int i = 0; i < boot_info->module_count; i++)
|
||||
{
|
||||
if(kernel_load_module(&boot_info->modules[i]) != ENONE)
|
||||
@@ -147,7 +154,7 @@ void kernel_initialize(struct boot_info_t *boot_info)
|
||||
load_context(kernel_advance_scheduler());
|
||||
}
|
||||
|
||||
error_t kernel_set_syscall(int id, int arg_count, pid_t pid, void *func_ptr)
|
||||
error_t kernel_set_syscall(int id, int arg_count, void *func_ptr)
|
||||
{
|
||||
if(id < 0 || id > MAX_SYSCALL_ID)
|
||||
{
|
||||
@@ -161,17 +168,12 @@ error_t kernel_set_syscall(int id, int arg_count, pid_t pid, void *func_ptr)
|
||||
{
|
||||
return EINVALIDARG;
|
||||
}
|
||||
else if(pid != 0 && avl_get(kernel.process_table, pid) == NULL)
|
||||
{
|
||||
return EDOESNTEXIST;
|
||||
}
|
||||
else if(func_ptr == NULL)
|
||||
{
|
||||
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 ENONE;
|
||||
}
|
||||
@@ -186,18 +188,6 @@ size_t kernel_do_syscall(syscall_id_t id, syscall_arg_t arg1, syscall_arg_t arg2
|
||||
{
|
||||
return ENOSYSCALL;
|
||||
}
|
||||
bool switched_address_space = false;
|
||||
if(kernel.syscall_table[id].process_id > 0)
|
||||
{
|
||||
struct process_t *callee = avl_get(kernel.process_table, kernel.syscall_table[id].process_id);
|
||||
if(callee == NULL)
|
||||
{
|
||||
kernel.syscall_table[id].defined = false;
|
||||
return ENOSYSCALL;
|
||||
}
|
||||
paging_load_address_space(callee->page_table);
|
||||
switched_address_space = true;
|
||||
}
|
||||
set_context_pc(kernel.active_process->ctx, pc);
|
||||
set_context_stack(kernel.active_process->ctx, stack);
|
||||
set_context_flags(kernel.active_process->ctx, flags);
|
||||
@@ -217,10 +207,6 @@ size_t kernel_do_syscall(syscall_id_t id, syscall_arg_t arg1, syscall_arg_t arg2
|
||||
result = kernel.syscall_table[id].func_ptr_3(arg1, arg2, arg3);
|
||||
break;
|
||||
}
|
||||
if(switched_address_space)
|
||||
{
|
||||
paging_load_address_space(kernel.active_process->page_table);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -232,20 +218,8 @@ error_t kernel_load_module(struct module_t *module)
|
||||
}
|
||||
paging_load_address_space(module_address_space);
|
||||
void *const load_base = (void*)0x80000000;
|
||||
size_t load_offset = 0;
|
||||
for(physaddr_t p = module->start & ~(page_size - 1); p < module->end; p += page_size)
|
||||
{
|
||||
int status = map_page(load_base + load_offset, p, PAGE_RW);
|
||||
switch(status)
|
||||
{
|
||||
case ENOMEM:
|
||||
kernel_panic("ran out of memory while mapping module");
|
||||
case EOUTOFBOUNDS:
|
||||
kernel_panic("got out-of-bounds error while mapping module");
|
||||
}
|
||||
load_offset += page_size;
|
||||
|
||||
}
|
||||
physaddr_t p = module->start & ~(page_size - 1);
|
||||
map_region(load_base, p, module->end - p, PAGE_RW);
|
||||
int status = load_program(load_base);
|
||||
switch(status)
|
||||
{
|
||||
@@ -256,7 +230,7 @@ error_t kernel_load_module(struct module_t *module)
|
||||
}
|
||||
void *module_entry = ((struct elf_file_header_t*)load_base)->entry;
|
||||
printf("loaded module with entry point %08x\n", (unsigned int)module_entry);
|
||||
load_offset = 0;
|
||||
size_t load_offset = 0;
|
||||
for(physaddr_t p = module->start & ~(page_size - 1); p < module->end; p += page_size)
|
||||
{
|
||||
int status = unmap_page(load_base + load_offset);
|
||||
@@ -305,34 +279,20 @@ struct process_context_t *kernel_current_context()
|
||||
|
||||
pid_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)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
struct process_context_t *initial_context = kmalloc(sizeof(struct process_context_t));
|
||||
if(initial_context == NULL)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
physaddr_t stack_page = reserve_page();
|
||||
if(stack_page % page_size)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
map_page((void*)&_kernel_start - page_size, stack_page, PAGE_PRESENT | PAGE_USERMODE | PAGE_RW);
|
||||
memset(initial_context, 0, sizeof(struct process_context_t));
|
||||
set_context_pc(initial_context, program_entry);
|
||||
set_context_flags(initial_context, DEFAULT_FLAGS);
|
||||
set_context_stack(initial_context, &_kernel_start);
|
||||
new_process->priority = priority;
|
||||
new_process->pid = kernel.next_pid;
|
||||
new_process->page_table = address_space;
|
||||
new_process->state = PROCESS_ACTIVE;
|
||||
new_process->message_buffer = NULL;
|
||||
new_process->ctx = initial_context;
|
||||
queue_construct(&new_process->sending_queue);
|
||||
queue_construct(&new_process->message_queue);
|
||||
struct process_t *new_process = process_construct(kernel.next_pid, &_kernel_start, program_entry, priority, address_space);
|
||||
if(new_process == NULL)
|
||||
{
|
||||
free_page(stack_page);
|
||||
return 0;
|
||||
}
|
||||
|
||||
kernel.process_table = avl_insert(kernel.process_table, new_process->pid, new_process);
|
||||
priorityqueue_insert(&kernel.priority_queue, new_process, new_process->priority);
|
||||
kernel.next_pid++;
|
||||
@@ -596,7 +556,7 @@ error_t kernel_create_object(size_t size, unsigned long flags, oid_t *id)
|
||||
struct shared_object_t *obj = kmalloc(sizeof(struct shared_object_t));
|
||||
if(obj == NULL)
|
||||
{
|
||||
free_pages(phys_addr, size);
|
||||
free_pages(phys_addr);
|
||||
return ENOMEM;
|
||||
}
|
||||
|
||||
@@ -608,6 +568,10 @@ error_t kernel_create_object(size_t size, unsigned long flags, oid_t *id)
|
||||
kernel.object_table = avl_insert(kernel.object_table, kernel.next_oid, obj);
|
||||
*id = kernel.next_oid;
|
||||
kernel.next_oid++;
|
||||
if(kernel.next_oid <= 0)
|
||||
{
|
||||
kernel.next_oid = 1;
|
||||
}
|
||||
return ENONE;
|
||||
}
|
||||
|
||||
|
||||
113
src/syscalls.c
113
src/syscalls.c
@@ -5,13 +5,16 @@
|
||||
#include "platform/context.h"
|
||||
#include "types/status.h"
|
||||
|
||||
size_t test_syscall(syscall_arg_t str)
|
||||
syscallret_t test_syscall(syscall_arg_t str)
|
||||
{
|
||||
printf("%s", (char*)str.ptr);
|
||||
if(str.ptr != NULL)
|
||||
{
|
||||
printf("%s", (char*)str.ptr);
|
||||
}
|
||||
return 17;
|
||||
}
|
||||
|
||||
size_t syscall_mmap(syscall_arg_t arg_location, syscall_arg_t arg_length, syscall_arg_t arg_flags)
|
||||
syscallret_t syscall_map_anon(syscall_arg_t arg_location, syscall_arg_t arg_length, syscall_arg_t arg_flags)
|
||||
{
|
||||
unsigned long location = arg_location.unsigned_int;
|
||||
unsigned long length = arg_length.unsigned_int;
|
||||
@@ -24,6 +27,7 @@ size_t syscall_mmap(syscall_arg_t arg_location, syscall_arg_t arg_length, syscal
|
||||
{
|
||||
return ENULLPTR;
|
||||
}
|
||||
|
||||
for(size_t i = 0; i < length; i += page_size)
|
||||
{
|
||||
if(page_type((void*)(location + i)) & PAGE_PRESENT)
|
||||
@@ -31,34 +35,22 @@ size_t syscall_mmap(syscall_arg_t arg_location, syscall_arg_t arg_length, syscal
|
||||
return EEXISTS;
|
||||
}
|
||||
}
|
||||
size_t n = 0;
|
||||
int status = ENONE;
|
||||
while(n < length && status == ENONE)
|
||||
|
||||
physaddr_t frame = reserve_pages(length);
|
||||
if(frame % page_size != 0)
|
||||
{
|
||||
physaddr_t frame = reserve_page();
|
||||
status = frame % page_size;
|
||||
if(status == ENONE)
|
||||
{
|
||||
status = map_page((void*)(location + n), frame, PAGE_USERMODE | PAGE_RW);
|
||||
if(status != ENONE && free_page(frame) != ENONE)
|
||||
{
|
||||
kernel_panic("critical error reached during mmap.");
|
||||
}
|
||||
n += page_size;
|
||||
}
|
||||
else
|
||||
{
|
||||
break;
|
||||
}
|
||||
return frame % page_size;
|
||||
}
|
||||
if(status != ENONE && syscall_munmap(arg_location, arg_length) != ENONE)
|
||||
|
||||
error_t status = map_region(location, frame, length, PAGE_USERMODE | PAGE_RW);
|
||||
if(status != ENONE)
|
||||
{
|
||||
kernel_panic("critical error reached during mmap.");
|
||||
kernel_panic("Unexpected failure to map virtual memory.");
|
||||
}
|
||||
return status;
|
||||
return ENONE;
|
||||
}
|
||||
|
||||
size_t syscall_munmap(syscall_arg_t arg_location, syscall_arg_t arg_length)
|
||||
syscallret_t syscall_unmap_anon(syscall_arg_t arg_location, syscall_arg_t arg_length)
|
||||
{
|
||||
unsigned long location = arg_location.unsigned_int;
|
||||
unsigned long length = arg_length.unsigned_int;
|
||||
@@ -88,7 +80,7 @@ size_t syscall_munmap(syscall_arg_t arg_location, syscall_arg_t arg_length)
|
||||
return status;
|
||||
}
|
||||
|
||||
size_t syscall_map_physical(syscall_arg_t arg_addr, syscall_arg_t arg_phys_addr, syscall_arg_t arg_length)
|
||||
syscallret_t syscall_map_physical(syscall_arg_t arg_addr, syscall_arg_t arg_phys_addr, syscall_arg_t arg_length)
|
||||
{
|
||||
void *addr = arg_addr.ptr;
|
||||
physaddr_t frame = arg_phys_addr.unsigned_int;
|
||||
@@ -105,7 +97,7 @@ size_t syscall_map_physical(syscall_arg_t arg_addr, syscall_arg_t arg_phys_addr,
|
||||
return status;
|
||||
}
|
||||
|
||||
size_t syscall_unmap_physical(syscall_arg_t arg_addr, syscall_arg_t arg_length)
|
||||
syscallret_t syscall_unmap_physical(syscall_arg_t arg_addr, syscall_arg_t arg_length)
|
||||
{
|
||||
void *addr = arg_addr.ptr;
|
||||
unsigned long length = arg_length.unsigned_int;
|
||||
@@ -121,12 +113,17 @@ size_t syscall_unmap_physical(syscall_arg_t arg_addr, syscall_arg_t arg_length)
|
||||
return status;
|
||||
}
|
||||
|
||||
size_t syscall_terminate_self()
|
||||
syscallret_t syscall_open_port(syscall_arg_t id)
|
||||
{
|
||||
return kernel_terminate_process(kernel_current_pid());
|
||||
return kernel_create_port(id.unsigned_int);
|
||||
}
|
||||
|
||||
size_t syscall_send(syscall_arg_t recipient, syscall_arg_t message, syscall_arg_t flags)
|
||||
syscallret_t syscall_close_port(syscall_arg_t id)
|
||||
{
|
||||
return kernel_remove_port(id.unsigned_int);
|
||||
}
|
||||
|
||||
syscallret_t syscall_send_pid(syscall_arg_t recipient, syscall_arg_t message, syscall_arg_t flags)
|
||||
{
|
||||
unsigned long op_type = flags.unsigned_int & IO_OP;
|
||||
unsigned long dest_type = flags.unsigned_int & IO_RECIPIENT_TYPE;
|
||||
@@ -154,17 +151,63 @@ size_t syscall_send(syscall_arg_t recipient, syscall_arg_t message, syscall_arg_
|
||||
}
|
||||
}
|
||||
|
||||
size_t syscall_receive(syscall_arg_t buffer, syscall_arg_t flags)
|
||||
syscallret_t syscall_send_port(syscall_arg_t recipient, syscall_arg_t message, syscall_arg_t flags)
|
||||
{
|
||||
return ENOSYSCALL;
|
||||
}
|
||||
|
||||
syscallret_t syscall_receive(syscall_arg_t buffer, syscall_arg_t flags)
|
||||
{
|
||||
return kernel_receive_message(buffer.ptr, flags.unsigned_int);
|
||||
}
|
||||
|
||||
size_t syscall_open_port(syscall_arg_t id)
|
||||
syscallret_t syscall_create_object(void *location, size_t size, int flags)
|
||||
{
|
||||
return kernel_create_port(id.unsigned_int);
|
||||
|
||||
return ENOSYSCALL;
|
||||
}
|
||||
|
||||
size_t syscall_close_port(syscall_arg_t id)
|
||||
syscallret_t syscall_aquire_object(oid_t id, void *location)
|
||||
{
|
||||
return kernel_remove_port(id.unsigned_int);
|
||||
return ENOSYSCALL;
|
||||
}
|
||||
|
||||
syscallret_t syscall_release_object(oid_t id)
|
||||
{
|
||||
return ENOSYSCALL;
|
||||
}
|
||||
|
||||
syscallret_t syscall_get_pid()
|
||||
{
|
||||
return kernel_current_pid();
|
||||
}
|
||||
|
||||
syscallret_t syscall_clone(void (*entry)(void*), void *arg, void *stack, int flags)
|
||||
{
|
||||
return ENOSYSCALL;
|
||||
}
|
||||
|
||||
syscallret_t syscall_signal_action(int id, struct signal_action_t *action, int flags)
|
||||
{
|
||||
return ENOSYSCALL;
|
||||
}
|
||||
|
||||
syscallret_t syscall_signal_return()
|
||||
{
|
||||
return ENOSYSCALL;
|
||||
}
|
||||
|
||||
syscallret_t syscall_signal_raise(pid_t pid, int sigid)
|
||||
{
|
||||
return ENOSYSCALL;
|
||||
}
|
||||
|
||||
syscallret_t syscall_intr_action(int id, struct signal_action_t *action, int flags)
|
||||
{
|
||||
return ENOSYSCALL;
|
||||
}
|
||||
|
||||
syscallret_t syscall_intr_return()
|
||||
{
|
||||
return ENOSYSCALL;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user