summaryrefslogtreecommitdiff
path: root/Source/Library/Userland
diff options
context:
space:
mode:
authorAlexis211 <alexis211@gmail.com>2009-10-18 18:39:52 +0200
committerAlexis211 <alexis211@gmail.com>2009-10-18 18:39:52 +0200
commitccf807eb4ff541bb849c4f370d34123cb23d7d76 (patch)
tree7f97fcf3f83ef1efcdc0ae72e11aab1f8332a667 /Source/Library/Userland
parenteb7b832d47bcbd74181028c62e871d407ba63a23 (diff)
downloadMelon-ccf807eb4ff541bb849c4f370d34123cb23d7d76.tar.gz
Melon-ccf807eb4ff541bb849c4f370d34123cb23d7d76.zip
Heap included as well in userland library
Diffstat (limited to 'Source/Library/Userland')
-rw-r--r--Source/Library/Userland/Binding/Process.class.h3
-rw-r--r--Source/Library/Userland/Start.cpp27
-rw-r--r--Source/Library/Userland/common.h16
3 files changed, 46 insertions, 0 deletions
diff --git a/Source/Library/Userland/Binding/Process.class.h b/Source/Library/Userland/Binding/Process.class.h
index c484e19..88af9d6 100644
--- a/Source/Library/Userland/Binding/Process.class.h
+++ b/Source/Library/Userland/Binding/Process.class.h
@@ -16,4 +16,7 @@ class Process : public RessourceCaller {
void allocPage(u32int pos) {
doCall(PR_IFACE_ALLOCPAGE, pos);
}
+ void freePage(u32int pos) {
+ doCall(PR_IFACE_FREEPAGE, pos);
+ }
};
diff --git a/Source/Library/Userland/Start.cpp b/Source/Library/Userland/Start.cpp
index 02eb951..e185189 100644
--- a/Source/Library/Userland/Start.cpp
+++ b/Source/Library/Userland/Start.cpp
@@ -1,8 +1,35 @@
#include <types.h>
+#include <Heap.class.h>
+
+extern "C" void __cxa_pure_virtual() {} //Required when using abstract classes
+void *__dso_handle; //Required when using global objects
+extern "C" int __cxa_atexit(void (*f)(void*), void *p, void *d) { return 0; }
+
+extern u32int start_ctors, end_ctors, start_dtors, end_dtors;
+
+Heap heap;
+
int main();
extern "C" void start() {
+ //Call static constructors
+ for(u32int * call = &start_ctors; call < &end_ctors; call++) {
+ ((void (*)(void))*call)();
+ }
+
+ heap.create(0x40000000, 0x00100000, 0x00003000); //Initially create a 1M heap with 12ko index
u32int r = main();
+
+ //Call static destructors
+ for(u32int * call = &start_dtors; call < &end_dtors; call++) {
+ ((void (*)(void))*call)();
+ }
+
asm volatile("int $66" : : "a"(r));
}
+
+namespace Mem {
+ void* alloc (u32int sz) { return heap.alloc(sz); }
+ void free(void* ptr) { heap.free(ptr); }
+}
diff --git a/Source/Library/Userland/common.h b/Source/Library/Userland/common.h
index 27218f7..3508513 100644
--- a/Source/Library/Userland/common.h
+++ b/Source/Library/Userland/common.h
@@ -7,4 +7,20 @@
#include <CMem.ns.h>
+namespace Mem {
+ void* alloc(u32int);
+ void free(void*);
+}
+
+//Standard implemenations of operator new/delete
+inline void* operator new(u32int, void *p) { return p; }
+inline void* operator new[](u32int, void *p) { return p; }
+inline void operator delete(void*, void*) { }
+inline void operator delete[](void*, void*) { }
+
+inline void* operator new(u32int sz) { return Mem::alloc(sz); }
+inline void* operator new[](u32int sz) { return Mem::alloc(sz); }
+inline void operator delete(void *ptr) { Mem::free(ptr); }
+inline void operator delete[](void *ptr) { Mem::free(ptr); }
+
#endif