1 #ifndef CPP_H 2 #define CPP_H 3 /* cpp - C++ in the kernel 4 ** 5 ** Initial version by Axel Dörfler, axeld@pinc-software.de 6 ** This file may be used under the terms of the OpenBeOS License. 7 */ 8 9 10 #include <new> 11 #include <stdlib.h> 12 13 #if _KERNEL_MODE 14 15 using namespace std; 16 extern const nothrow_t std::nothrow; 17 18 // Oh no! C++ in the kernel! Are you nuts? 19 // 20 // - no exceptions 21 // - (almost) no virtuals (well, the Query code now uses them) 22 // - it's basically only the C++ syntax, and type checking 23 // - since one tend to encapsulate everything in classes, it has a slightly 24 // higher memory overhead 25 // - nicer code 26 // - easier to maintain 27 28 29 inline void * 30 operator new(size_t size) throw (std::bad_alloc) 31 { 32 // we don't actually throw any exceptions, but we have to 33 // keep the prototype as specified in <new>, or else GCC 3 34 // won't like us 35 return malloc(size); 36 } 37 38 39 inline void * 40 operator new[](size_t size) throw (std::bad_alloc) 41 { 42 return malloc(size); 43 } 44 45 46 inline void * 47 operator new(size_t size, const std::nothrow_t &) throw () 48 { 49 return malloc(size); 50 } 51 52 53 inline void * 54 operator new[](size_t size, const std::nothrow_t &) throw () 55 { 56 return malloc(size); 57 } 58 59 60 inline void 61 operator delete(void *ptr) throw () 62 { 63 free(ptr); 64 } 65 66 67 inline void 68 operator delete[](void *ptr) throw () 69 { 70 free(ptr); 71 } 72 73 // we're using virtuals 74 extern "C" void __pure_virtual(); 75 76 #endif // #if _KERNEL_MODE 77 78 #endif /* CPP_H */ 79