diff --git a/sandbox/base/main.c b/sandbox/base/main.c index 955c6f9..795e768 100644 --- a/sandbox/base/main.c +++ b/sandbox/base/main.c @@ -50,7 +50,7 @@ int main(int argc, const char **argv) memblock_reserve(0x30000, 0x40000); memblock_reserve(0x100000, 0x10000); - phys_addr_t alloc = memblock_alloc(512); + phys_addr_t alloc = memblock_alloc_phys(512); printf("allocated 512 bytes at 0x%" PRIxPTR "\n", alloc); printf("memory regions:\n"); diff --git a/sandbox/memblock/include/socks/memblock.h b/sandbox/memblock/include/socks/memblock.h index dd18129..f5856d0 100644 --- a/sandbox/memblock/include/socks/memblock.h +++ b/sandbox/memblock/include/socks/memblock.h @@ -80,8 +80,11 @@ extern int memblock_init(uintptr_t alloc_start, uintptr_t alloc_end, uintptr_t v extern int memblock_add(phys_addr_t base, size_t size); extern int memblock_reserve(phys_addr_t base, size_t size); -extern phys_addr_t memblock_alloc(size_t size); -extern int memblock_free(phys_addr_t addr, size_t size); +extern void *memblock_alloc(size_t size); +extern phys_addr_t memblock_alloc_phys(size_t size); + +extern int memblock_free(void *addr, size_t size); +extern int memblock_free_phys(phys_addr_t addr, size_t size); extern void __next_memory_region(memblock_iter_t *it, \ memblock_type_t *type_a, memblock_type_t *type_b, diff --git a/sandbox/memblock/memblock.c b/sandbox/memblock/memblock.c index d832333..fd94698 100644 --- a/sandbox/memblock/memblock.c +++ b/sandbox/memblock/memblock.c @@ -236,7 +236,16 @@ static phys_addr_t do_alloc(size_t size) return allocated_base; } -phys_addr_t memblock_alloc(size_t size) +void *memblock_alloc(size_t size) +{ + if (memblock.reserved.count >= memblock.reserved.max - 2) { + memblock_double_capacity(&memblock.reserved); + } + + return (void *)(do_alloc(size) + memblock.m_voffset); +} + +phys_addr_t memblock_alloc_phys(size_t size) { if (memblock.reserved.count >= memblock.reserved.max - 2) { memblock_double_capacity(&memblock.reserved); @@ -245,7 +254,12 @@ phys_addr_t memblock_alloc(size_t size) return do_alloc(size); } -int memblock_free(phys_addr_t addr, size_t size) +int memblock_free(void *p, size_t size) +{ + return 0; +} + +int memblock_free_phys(phys_addr_t addr, size_t size) { return 0; }