xref: /haiku/headers/private/kernel/util/kernel_cpp.h (revision 4a55cc230cf7566cadcbb23b1928eefff8aea9a2)
1 /*
2  * Copyright 2003-2022, Axel Dörfler, axeld@pinc-software.de.
3  * Copyright 2004-2022, Haiku, Inc. All rights reserved.
4  * Distributed under the terms of the MIT License.
5  */
6 #ifndef _KERNEL_UTIL_KERNEL_CPP_H
7 #define _KERNEL_UTIL_KERNEL_CPP_H
8 
9 #ifdef __cplusplus
10 
11 #include <new>
12 #include <stdlib.h>
13 
14 #if _KERNEL_MODE || _LOADER_MODE
15 
16 using std::nothrow;
17 
18 // We need new() versions we can use when also linking against libgcc.
19 // std::nothrow can't be used since it's defined in both libgcc and
20 // kernel_cpp.cpp.
21 typedef struct {} mynothrow_t;
22 extern const mynothrow_t mynothrow;
23 
24 #if __cplusplus >= 201103L
25 #define _THROW(x)
26 #define _NOEXCEPT noexcept
27 #else
28 #define _THROW(x) throw (x)
29 #define _NOEXCEPT throw ()
30 #endif
31 extern void* operator new(size_t size) _THROW(std::bad_alloc);
32 extern void* operator new[](size_t size) _THROW(std::bad_alloc);
33 extern void* operator new(size_t size, const std::nothrow_t &) _NOEXCEPT;
34 extern void* operator new[](size_t size, const std::nothrow_t &) _NOEXCEPT;
35 extern void* operator new(size_t size, const mynothrow_t &) _NOEXCEPT;
36 extern void* operator new[](size_t size, const mynothrow_t &) _NOEXCEPT;
37 extern void operator delete(void *ptr) _NOEXCEPT;
38 extern void operator delete[](void *ptr) _NOEXCEPT;
39 extern void operator delete(void *ptr, const std::nothrow_t &) _NOEXCEPT;
40 
41 #if __cplusplus >= 201402L
42 extern void operator delete(void* ptr, std::size_t) _NOEXCEPT;
43 extern void operator delete[](void* ptr, std::size_t) _NOEXCEPT;
44 #endif // __cplusplus >= 201402L
45 
46 #endif	// #if _KERNEL_MODE
47 
48 #endif	// __cplusplus
49 
50 #endif	/* _KERNEL_UTIL_KERNEL_CPP_H */
51