diff options
author | Freya Murphy <freya@freyacat.org> | 2025-04-15 22:20:59 -0400 |
---|---|---|
committer | Freya Murphy <freya@freyacat.org> | 2025-04-15 22:20:59 -0400 |
commit | 2dbf529c33aa3e24beff944758d586bb0608c1be (patch) | |
tree | 5b3381c3c8d9a74ccb988c8945fe0681c3ee7301 /kernel/memory/virtalloc.h | |
parent | fix %n (diff) | |
download | comus-2dbf529c33aa3e24beff944758d586bb0608c1be.tar.gz comus-2dbf529c33aa3e24beff944758d586bb0608c1be.tar.bz2 comus-2dbf529c33aa3e24beff944758d586bb0608c1be.zip |
expand memory manager work with userspace (more then one ctx)
Diffstat (limited to 'kernel/memory/virtalloc.h')
-rw-r--r-- | kernel/memory/virtalloc.h | 44 |
1 files changed, 41 insertions, 3 deletions
diff --git a/kernel/memory/virtalloc.h b/kernel/memory/virtalloc.h index a5ca840..9f974c5 100644 --- a/kernel/memory/virtalloc.h +++ b/kernel/memory/virtalloc.h @@ -9,23 +9,61 @@ #ifndef VIRTALLOC_H_ #define VIRTALLOC_H_ +#include <stddef.h> +#include <stdint.h> +#include <stdbool.h> + +#define BOOTSTRAP_VIRT_ALLOC_NODES 64 + +struct virt_addr_node { + /// first virtural address + uintptr_t start; + /// last virtural address + uintptr_t end; + /// next node in linked list + struct virt_addr_node *next; + /// prev node in linked list + struct virt_addr_node *prev; + /// if this node is storing any allocated data + uint8_t is_alloc; + /// if this node is in use by virtalloc + uint8_t is_used; +}; + +struct virt_ctx { + /// bootstrap nodes for the context (not in heap) + struct virt_addr_node bootstrap_nodes[BOOTSTRAP_VIRT_ALLOC_NODES]; + /// heap allocated nodes + struct virt_addr_node *alloc_nodes; + /// start node + struct virt_addr_node *start_node; + /// index of first free node + size_t free_node_start; + /// number of heap allocated nodes + size_t alloc_node_count; + /// number of used nodes + size_t used_node_count; + /// if we are currently allocating (recursion check) + bool is_allocating; +}; + /** * Initalizes the virtual address allocator */ -void virtaddr_init(void); +void virtaddr_init(struct virt_ctx *ctx); /** * Allocate a virtual address of length x pages * @param pages - x pages * @returns virt addr */ -void *virtaddr_alloc(int pages); +void *virtaddr_alloc(struct virt_ctx *ctx, int pages); /** * Free the virtual address from virtaddr_alloc * @param virtaddr - the addr to free * @returns number of pages used for virtaddr */ -long virtaddr_free(void *virtaddr); +long virtaddr_free(struct virt_ctx *ctx, void *virtaddr); #endif /* virtalloc.h */ |