Started separating important structs from kernel.c
This commit is contained in:
16
include/addressspace.h
Normal file
16
include/addressspace.h
Normal file
@@ -0,0 +1,16 @@
|
||||
#ifndef QUARK_ADDRESSSPACE_H
|
||||
#define QUARK_ADDRESSSPACE_H
|
||||
|
||||
#include "types/physaddr.h"
|
||||
|
||||
typedef struct addressspace_t
|
||||
{
|
||||
physaddr_t page_table;
|
||||
int refcount;
|
||||
} addressspace_t;
|
||||
|
||||
addressspace_t *addressspace_construct();
|
||||
|
||||
|
||||
|
||||
#endif
|
||||
33
include/process.h
Normal file
33
include/process.h
Normal file
@@ -0,0 +1,33 @@
|
||||
#ifndef QUARK_PROCESS_H
|
||||
#define QUARK_PROCESS_H
|
||||
|
||||
#include "types/pid.h"
|
||||
#include "types/physaddr.h"
|
||||
#include "types/status.h"
|
||||
#include "queue.h"
|
||||
|
||||
typedef enum process_state_t
|
||||
{
|
||||
PROCESS_ACTIVE,
|
||||
PROCESS_REQUESTING,
|
||||
PROCESS_SENDING
|
||||
} process_state_t;
|
||||
|
||||
typedef struct process_t
|
||||
{
|
||||
pid_t pid;
|
||||
int priority;
|
||||
physaddr_t page_table;
|
||||
struct avltree_t *shared_objects;
|
||||
process_state_t state;
|
||||
struct queue_t sending_queue;
|
||||
struct queue_t message_queue;
|
||||
struct message_t *message_buffer;
|
||||
struct process_context_t *ctx;
|
||||
} process_t;
|
||||
|
||||
process_t *process_construct(pid_t pid, void *entry, void *stack, int priority, physaddr_t address_space);
|
||||
|
||||
error_t process_call_func(process_t *process, void *func, void *ret, int argc, ...);
|
||||
|
||||
#endif
|
||||
20
include/sharedobject.h
Normal file
20
include/sharedobject.h
Normal file
@@ -0,0 +1,20 @@
|
||||
#ifndef QUARK_SHARED_OBJECT_H
|
||||
#define QUARK_SHARED_OBJECT_H
|
||||
|
||||
#include "types/physaddr.h"
|
||||
#include <stddef.h>
|
||||
|
||||
struct shared_object_t
|
||||
{
|
||||
physaddr_t phys_addr;
|
||||
size_t size;
|
||||
unsigned long access_flags;
|
||||
unsigned long refcount;
|
||||
struct avltree_t *users;
|
||||
};
|
||||
|
||||
struct shared_object *create_shared_object(size_t size, unsigned long flags);
|
||||
|
||||
void destroy_shared_object(struct shared_object_t *obj);
|
||||
|
||||
#endif
|
||||
22
src/addressspace.c
Normal file
22
src/addressspace.c
Normal file
@@ -0,0 +1,22 @@
|
||||
#include "addressspace.h"
|
||||
#include "heap.h"
|
||||
#include "mmgr.h"
|
||||
|
||||
addressspace_t *addressspace_construct()
|
||||
{
|
||||
addressspace_t *as = kmalloc(sizeof(addressspace_t));
|
||||
if(as == NULL)
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
||||
as->page_table = create_address_space();
|
||||
if(as->page_table == ENOMEM)
|
||||
{
|
||||
kfree(as);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
as->refcount = 0;
|
||||
return as;
|
||||
}
|
||||
32
src/process.c
Normal file
32
src/process.c
Normal file
@@ -0,0 +1,32 @@
|
||||
#include "process.h"
|
||||
#include "heap.h"
|
||||
#include "platform/context.h"
|
||||
#include "string.h"
|
||||
|
||||
process_t *process_construct(pid_t pid, void *entry, void *stack, int priority, physaddr_t address_space)
|
||||
{
|
||||
process_t *new_process = (process_t*) kmalloc(sizeof(process_t));
|
||||
if(new_process == NULL)
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
||||
struct process_context_t *initial_context = kmalloc(sizeof(struct process_context_t));
|
||||
if(initial_context == NULL)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
context_construct(initial_context);
|
||||
set_context_pc(initial_context, entry);
|
||||
set_context_stack(initial_context, stack);
|
||||
new_process->priority = priority;
|
||||
new_process->pid = 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);
|
||||
return new_process;
|
||||
}
|
||||
37
src/sharedobject.c
Normal file
37
src/sharedobject.c
Normal file
@@ -0,0 +1,37 @@
|
||||
#include "sharedobject.h"
|
||||
#include "avltree.h"
|
||||
#include "mmgr.h"
|
||||
#include "heap.h"
|
||||
|
||||
struct shared_object *create_shared_object(size_t size, unsigned long flags)
|
||||
{
|
||||
physaddr_t phys_addr = reserve_pages(size);
|
||||
if(phys_addr == NULL)
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
||||
struct shared_object_t *obj = kmalloc(sizeof(struct shared_object_t));
|
||||
if(obj == NULL)
|
||||
{
|
||||
free_pages(phys_addr);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
obj->phys_addr = phys_addr;
|
||||
obj->size = size;
|
||||
obj->access_flags = flags;
|
||||
obj->refcount = 0;
|
||||
obj->users = NULL;
|
||||
return obj;
|
||||
}
|
||||
|
||||
void destroy_shared_object(struct shared_object_t *obj)
|
||||
{
|
||||
if(obj != NULL)
|
||||
{
|
||||
free_pages(obj->phys_addr);
|
||||
avl_clear(obj->users);
|
||||
kfree(obj);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user