1 // lib/libc.cc -- Standard C-library functions
3 // This software is copyright (c) 2006 Scott Wood <scott@buserror.net>.
5 // This software is provided 'as-is', without any express or implied warranty.
6 // In no event will the authors or contributors be held liable for any damages
7 // arising from the use of this software.
9 // Permission is hereby granted to everyone, free of charge, to use, copy,
10 // modify, prepare derivative works of, publish, distribute, perform,
11 // sublicense, and/or sell copies of the Software, provided that the above
12 // copyright notice and disclaimer of warranty be included in all copies or
13 // substantial portions of this software.
16 #include <kern/types.h>
17 #include <kern/libc.h>
18 #include <kern/console.h>
23 void bzero(void *b, size_t len)
25 char *c = static_cast<char *>(b);
31 #include <kern/pagealloc.h>
33 // Temporary hack until slab allocator is added
35 void *malloc(size_t len)
37 assert(len <= Arch::page_size - sizeof(size_t));
39 len = (len + sizeof(size_t) + Arch::page_size - 1) / Arch::page_size;
40 Mem::Page *page = Mem::PageAlloc::alloc(len);
42 size_t *ptr = (size_t *)Mem::page_to_kvirt(page);
51 size_t *ptr = (size_t *)addr - 1;
53 Mem::Page *page = Mem::kvirt_to_page(addr);
54 Mem::PageAlloc::free(page, len);
58 void *operator new(size_t len)
63 void *operator new[](size_t len)
68 void operator delete(void *addr)
73 void operator delete[](void *addr)
78 extern "C" void __cxa_pure_virtual()
86 printf("abort() called in kernel\n");