diff options
author | Alex Auvolat <alex.auvolat@ens.fr> | 2015-02-19 17:03:55 +0100 |
---|---|---|
committer | Alex Auvolat <alex.auvolat@ens.fr> | 2015-02-19 17:03:55 +0100 |
commit | 408faed4df730384538aaa0e338ae8ea7abe400d (patch) | |
tree | d391e7b94bab9de64ded62faf06d32f8a8340d3d /src/lib/include | |
parent | 396a630f55aae0105ce56d302afaa937632d15ed (diff) | |
download | kogata-408faed4df730384538aaa0e338ae8ea7abe400d.tar.gz kogata-408faed4df730384538aaa0e338ae8ea7abe400d.zip |
Implement userspace malloc
Diffstat (limited to 'src/lib/include')
-rw-r--r-- | src/lib/include/syscall.h | 5 | ||||
-rw-r--r-- | src/lib/include/user_region.h | 34 |
2 files changed, 39 insertions, 0 deletions
diff --git a/src/lib/include/syscall.h b/src/lib/include/syscall.h index 44b88cf..e0f08eb 100644 --- a/src/lib/include/syscall.h +++ b/src/lib/include/syscall.h @@ -5,6 +5,7 @@ #include <stdbool.h> #include <syscallproto.h> +#include <mmap.h> #include <fs.h> #include <debug.h> @@ -13,6 +14,10 @@ void dbg_print(const char* str); void yield(); void exit(int code); +bool mmap(void* addr, size_t size, int mode); +bool mchmap(void* addr, int mode); +bool munmap(void* addr); + // more todo /* vim: set ts=4 sw=4 tw=0 noet :*/ diff --git a/src/lib/include/user_region.h b/src/lib/include/user_region.h new file mode 100644 index 0000000..8a4c490 --- /dev/null +++ b/src/lib/include/user_region.h @@ -0,0 +1,34 @@ +#pragma once + +// User virtual memory region allocator + +// This is entirely thread-safe + +#include <stdint.h> +#include <stddef.h> +#include <stdbool.h> + +#include <syscall.h> + +#define PAGE_SIZE 0x1000 +#define PAGE_MASK 0xFFFFF000 +#define PAGE_ALIGN_DOWN(x) (((size_t)x) & PAGE_MASK) +#define PAGE_ALIGN_UP(x) ((((size_t)x)&(~PAGE_MASK)) == 0 ? ((size_t)x) : (((size_t)x) & PAGE_MASK) + PAGE_SIZE) + +struct region_info; + +typedef struct region_info { + void* addr; + size_t size; + char* type; +} region_info_t; + +void region_allocator_init(void* begin, void* end); + +void* region_alloc(size_t size, char* type); // returns 0 on error +region_info_t *find_region(void* addr); +void region_free(void* addr); + +void dbg_print_region_info(); + +/* vim: set ts=4 sw=4 tw=0 noet :*/ |