xref: /haiku/headers/private/kernel/util/kernel_cpp.h (revision 2222d0559df303a9846a2fad53741f8b20b14d7c)
1 #ifndef KERNEL_CPP_H
2 #define KERNEL_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 #ifdef __cplusplus
10 
11 #include <new>
12 #include <stdlib.h>
13 
14 #if _KERNEL_MODE || _LOADER_MODE
15 
16 using namespace std;
17 extern const nothrow_t std::nothrow;
18 
19 // We need new() versions we can use when also linking against libgcc.
20 // std::nothrow can't be used since it's defined in both libgcc and
21 // kernel_cpp.cpp.
22 typedef struct {} mynothrow_t;
23 extern const mynothrow_t mynothrow;
24 
25 
26 inline void *
27 operator new(size_t size) throw (std::bad_alloc)
28 {
29 	// we don't actually throw any exceptions, but we have to
30 	// keep the prototype as specified in <new>, or else GCC 3
31 	// won't like us
32 	return malloc(size);
33 }
34 
35 
36 inline void *
37 operator new[](size_t size) throw (std::bad_alloc)
38 {
39 	return malloc(size);
40 }
41 
42 
43 inline void *
44 operator new(size_t size, const std::nothrow_t &) throw ()
45 {
46 	return malloc(size);
47 }
48 
49 
50 inline void *
51 operator new[](size_t size, const std::nothrow_t &) throw ()
52 {
53 	return malloc(size);
54 }
55 
56 
57 inline void *
58 operator new(size_t size, const mynothrow_t &) throw ()
59 {
60 	return malloc(size);
61 }
62 
63 
64 inline void *
65 operator new[](size_t size, const mynothrow_t &) throw ()
66 {
67 	return malloc(size);
68 }
69 
70 
71 inline void
72 operator delete(void *ptr) throw ()
73 {
74 	free(ptr);
75 }
76 
77 
78 inline void
79 operator delete[](void *ptr) throw ()
80 {
81 	free(ptr);
82 }
83 
84 #endif	// #if _KERNEL_MODE
85 
86 #endif	// __cplusplus
87 
88 #endif	/* KERNEL_CPP_H */
89