diff options
| author | Ada Christine <adachristine18@gmail.com> | 2022-03-14 14:20:34 +0000 |
|---|---|---|
| committer | Ada Christine <adachristine18@gmail.com> | 2022-03-14 20:59:18 +0000 |
| commit | 73e5768d3a159b2e9b554fa5396a759f3d283c6c (patch) | |
| tree | 1ac5a51e6d9d02377bced4ed55bea97087a4e1dd /kc | |
| parent | 54ba636ecc8cbd44776c998a68a666b0b6f6abae (diff) | |
some updates to page handling
whoops
squash me
Diffstat (limited to 'kc')
| -rw-r--r-- | kc/core/memory.h | 3 | ||||
| -rw-r--r-- | kc/core/memory/memory.c | 18 | ||||
| -rw-r--r-- | kc/core/memory/page_stack.c | 1 | ||||
| -rw-r--r-- | kc/core/timer.h | 4 |
4 files changed, 24 insertions, 2 deletions
diff --git a/kc/core/memory.h b/kc/core/memory.h index ea86912..6b7a816 100644 --- a/kc/core/memory.h +++ b/kc/core/memory.h @@ -56,6 +56,9 @@ void page_set_present(kc_phys_addr page); void page_set_allocated(kc_phys_addr page); void page_set_free(kc_phys_addr page); +int page_inc_ref(kc_phys_addr page); +int page_dec_ref(kc_phys_addr page); + void *page_map(phys_addr_t paddr, enum page_map_flags flags); void page_unmap(void *vaddr); diff --git a/kc/core/memory/memory.c b/kc/core/memory/memory.c index 0fbc941..9a1f42f 100644 --- a/kc/core/memory/memory.c +++ b/kc/core/memory/memory.c @@ -243,9 +243,22 @@ static void *page_map_at( } } + // take a reference to the page + page_inc_ref(paddr); + return (char *)vaddr + offset; } +int page_inc_ref(kc_phys_addr page) +{ + return page_stack_inc_ref(page); +} + +int page_dec_ref(kc_phys_addr page) +{ + return page_stack_dec_ref(page); +} + #define VM_HEAP_SIZE 16 * page_size(2) static void *temp_page_alloc(void) @@ -471,8 +484,7 @@ void *heap_alloc(size_t size) void heap_free(void *block) { - struct heap_header *header = (void *) - ((char *)block - sizeof(*header)); + struct heap_header *header = (void *)((char *)block - sizeof(*header)); header->next = heap_root; heap_root = header; @@ -611,6 +623,8 @@ void page_fault_handler(struct isr_context *context) kprintf("error: vm object at %p has no fault handler\n"); PANIC(UNHANDLED_FAULT); } + + node->object->handler(node, context->entry_state.code, address); } void general_protection_handler(struct isr_context *context) diff --git a/kc/core/memory/page_stack.c b/kc/core/memory/page_stack.c index aed38f2..1afd46a 100644 --- a/kc/core/memory/page_stack.c +++ b/kc/core/memory/page_stack.c @@ -110,6 +110,7 @@ int page_stack_inc_ref(kc_phys_addr page) { unsigned index = page_stack_index(page); // taking a reference only makes sense for an allocated page + // and a page that's actually physical if (stack_state.stack[index].allocated) { return ++stack_state.stack[index].next_refs; diff --git a/kc/core/timer.h b/kc/core/timer.h index b41aa35..5a30747 100644 --- a/kc/core/timer.h +++ b/kc/core/timer.h @@ -1,4 +1,5 @@ #pragma once + #include <stdint.h> #define TIMER_MILLISECOND 1000ULL @@ -7,6 +8,9 @@ typedef int (*timer_callback)(uint64_t nanoseconds); +typedef uint64_t kc_time_stamp; +typedef uint64_t kc_time_delta; + struct timer_callback_list { timer_callback func; |
