Usermode/libc++ - Implement map::insert and map::erase
[tpg/acess2.git] / Usermode / Libraries / libc++.so_src / new.cc
index 9dae853..f1ebc45 100644 (file)
@@ -8,6 +8,10 @@
 #include <stddef.h>
 #include <stdlib.h>
 #include <acess/sys.h>
+#include <new>
+
+// === IMPORTS ===
+extern "C" bool        _libc_free(void *mem);  // from libc.so, actual free.
 
 // === CODE ===
 void *operator new( size_t size )
@@ -15,32 +19,39 @@ void *operator new( size_t size )
        //_SysDebug("libc++ - operator new(%i)", size);
        return malloc( size );
 }
-void *operator new( size_t size, void* ptr )
-{
-       //_SysDebug("libc++ - operator new(%i, %p)", size, ptr);
-       size = size;
-       return ptr;
-}
 
 void *operator new[]( size_t size )
 {
        //_SysDebug("libc++ - operator new[](%i)", size);
        return malloc( size );
 }
-void *operator new[]( size_t size, void* ptr )
-{
-       //_SysDebug("libc++ - operator new[](%i, %p)", size, ptr);
-       size = size;
-       return ptr;
-}
 
 void operator delete(void *ptr)
 {
-       free(ptr);
+       if( !_libc_free(ptr) ) {
+               _SysDebug("delete of invalid by %p", __builtin_return_address(0));
+               throw ::std::bad_alloc();
+       }
 }
 
 void operator delete[](void *ptr)
 {
-       free(ptr);
+       if( !_libc_free(ptr) ) {
+               _SysDebug("delete[] of invalid by %p", __builtin_return_address(0));
+               throw ::std::bad_alloc();
+       }
+}
+
+
+::std::bad_alloc::bad_alloc() noexcept
+{
+}
+::std::bad_alloc::~bad_alloc() noexcept
+{
+}
+
+const char *::std::bad_alloc::what() const noexcept
+{
+       return "allocation failure";
 }
 

UCC git Repository :: git.ucc.asn.au