Usermode/libc++ - Implement map::insert and map::erase
[tpg/acess2.git] / Usermode / Libraries / libc++.so_src / new.cc
1 /*
2  * Acess2 C++ Library
3  * - By John Hodge (thePowersGang)
4  *
5  * new.cc
6  * - new/delete
7  */
8 #include <stddef.h>
9 #include <stdlib.h>
10 #include <acess/sys.h>
11 #include <new>
12
13 // === IMPORTS ===
14 extern "C" bool _libc_free(void *mem);  // from libc.so, actual free.
15
16 // === CODE ===
17 void *operator new( size_t size )
18 {
19         //_SysDebug("libc++ - operator new(%i)", size);
20         return malloc( size );
21 }
22
23 void *operator new[]( size_t size )
24 {
25         //_SysDebug("libc++ - operator new[](%i)", size);
26         return malloc( size );
27 }
28
29 void operator delete(void *ptr)
30 {
31         if( !_libc_free(ptr) ) {
32                 _SysDebug("delete of invalid by %p", __builtin_return_address(0));
33                 throw ::std::bad_alloc();
34         }
35 }
36
37 void operator delete[](void *ptr)
38 {
39         if( !_libc_free(ptr) ) {
40                 _SysDebug("delete[] of invalid by %p", __builtin_return_address(0));
41                 throw ::std::bad_alloc();
42         }
43 }
44
45
46 ::std::bad_alloc::bad_alloc() noexcept
47 {
48 }
49 ::std::bad_alloc::~bad_alloc() noexcept
50 {
51 }
52
53 const char *::std::bad_alloc::what() const noexcept
54 {
55         return "allocation failure";
56 }
57

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