[heap] Move some things, fix stuff
This commit is contained in:
parent
3f80a64d2c
commit
8ea4834a3e
28
core/array.h
28
core/array.h
@ -1,28 +0,0 @@
|
||||
#ifndef ARRAY_H
|
||||
#define ARRAY_H
|
||||
#include <system.h>
|
||||
|
||||
typedef void * type_t;
|
||||
typedef signed char (*lessthan_predicate_t)(type_t, type_t);
|
||||
typedef struct {
|
||||
type_t *array;
|
||||
uint32_t size;
|
||||
uint32_t max_size;
|
||||
lessthan_predicate_t less_than;
|
||||
} ordered_array_t;
|
||||
|
||||
signed char standard_lessthan_predicate(type_t a, type_t b);
|
||||
|
||||
ordered_array_t create_ordered_array(uint32_t max_size, lessthanpredicate_t less_than);
|
||||
ordered_array_t place_ordered_array(void *addr, uint32_t max_size, lessthan_predicate_t less_than);
|
||||
|
||||
void destroy_ordered_array(ordered_array_t *array);
|
||||
|
||||
void insert_ordered_array(type_t item, ordered_array_t *array);
|
||||
|
||||
type_t loopup_ordered_array(uint32_t i, ordered_array_t *array);
|
||||
|
||||
void remove_ordered_array(uint32_t i, ordered_array_t *array);
|
||||
|
||||
|
||||
#endif
|
65
core/mem.c
65
core/mem.c
@ -5,17 +5,6 @@
|
||||
|
||||
#include <system.h>
|
||||
|
||||
typedef struct {
|
||||
uint32_t magic;
|
||||
char is_hole;
|
||||
uint32_t size;
|
||||
} header_t;
|
||||
|
||||
typedef struct {
|
||||
uint32_t magic;
|
||||
header_t * header;
|
||||
} footer_t;
|
||||
|
||||
extern uintptr_t end;
|
||||
uintptr_t placement_pointer = &end;
|
||||
|
||||
@ -77,28 +66,6 @@ kvmalloc_p(
|
||||
return kmalloc_real(size, 1, phys);
|
||||
}
|
||||
|
||||
uintptr_t heap_end = NULL;
|
||||
|
||||
void *
|
||||
heap_install() {
|
||||
heap_end = placement_pointer;
|
||||
}
|
||||
|
||||
void *
|
||||
sbrk(
|
||||
uintptr_t increment
|
||||
) {
|
||||
ASSERT(increment % 0x1000 == 0);
|
||||
uintptr_t address = heap_end;
|
||||
heap_end += increment;
|
||||
int i;
|
||||
for (i = address; i < heap_end; i += 0x1000) {
|
||||
get_page(i, 1, kernel_directory);
|
||||
alloc_frame(get_page(i, 1, kernel_directory), 0, 0);
|
||||
}
|
||||
return address;
|
||||
}
|
||||
|
||||
/*
|
||||
* Frame Allocation
|
||||
*/
|
||||
@ -255,3 +222,35 @@ page_fault(
|
||||
kprintf("Page fault! (p:%d,rw:%d,user:%d,res:%d) at 0x%x\n", present, rw, user, reserved, faulting_address);
|
||||
HALT_AND_CATCH_FIRE("Page fault");
|
||||
}
|
||||
|
||||
/*
|
||||
* Heap
|
||||
* Stop using kalloc and friends after installing the heap
|
||||
* otherwise shit will break. I've conveniently broken
|
||||
* kalloc when installing the heap, just for those of you
|
||||
* who feel the need to screw up.
|
||||
*/
|
||||
|
||||
uintptr_t heap_end = (uintptr_t)NULL;
|
||||
|
||||
void
|
||||
heap_install() {
|
||||
heap_end = placement_pointer;
|
||||
placement_pointer = 0;
|
||||
}
|
||||
|
||||
void *
|
||||
sbrk(
|
||||
uintptr_t increment
|
||||
) {
|
||||
ASSERT(increment % 0x1000 == 0);
|
||||
uintptr_t address = heap_end;
|
||||
heap_end += increment;
|
||||
uintptr_t i;
|
||||
for (i = address; i < heap_end; i += 0x1000) {
|
||||
get_page(i, 1, kernel_directory);
|
||||
alloc_frame(get_page(i, 1, kernel_directory), 0, 0);
|
||||
}
|
||||
return (void *)address;
|
||||
}
|
||||
|
||||
|
@ -119,7 +119,7 @@ extern void switch_page_directory(page_directory_t *new);
|
||||
extern page_t *get_page(uintptr_t address, int make, page_directory_t *dir);
|
||||
extern void page_fault(struct regs *r);
|
||||
|
||||
void * heap_install();
|
||||
void heap_install();
|
||||
|
||||
/* klmalloc */
|
||||
void * __attribute__ ((malloc)) malloc(size_t size);
|
||||
|
Loading…
Reference in New Issue
Block a user