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 if (len > Arch::page_size - sizeof(size_t))
40 len = (len + sizeof(size_t) + Arch::page_size - 1) / Arch::page_size;
41 Mem::Page *page = Mem::PageAlloc::alloc(len);
43 size_t *ptr = (size_t *)Mem::page_to_kvirt(page);
52 size_t *ptr = (size_t *)addr - 1;
54 Mem::Page *page = Mem::kvirt_to_page(addr);
55 Mem::PageAlloc::free(page, len);
59 void *operator new(size_t len)
64 void *operator new[](size_t len)
69 void operator delete(void *addr)
74 void operator delete[](void *addr)
79 extern "C" void __cxa_pure_virtual()
87 printf("abort() called in kernel\n");