kernel_cpp.h revision 9ac30627
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 MIT License.
7*/
8
9#ifdef __cplusplus
10
11#include <new>
12#include <stdlib.h>
13
14#if _KERNEL_MODE || _LOADER_MODE
15
16using namespace std;
17extern 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.
22typedef struct {} mynothrow_t;
23extern const mynothrow_t mynothrow;
24
25#if __cplusplus >= 201402L
26#define _THROW(x)
27#define _NOEXCEPT noexcept
28#else
29#define _THROW(x) throw (x)
30#define _NOEXCEPT throw ()
31#endif
32extern void* operator new(size_t size) _THROW(std::bad_alloc);
33extern void* operator new[](size_t size) _THROW(std::bad_alloc);
34extern void* operator new(size_t size, const std::nothrow_t &) _NOEXCEPT;
35extern void* operator new[](size_t size, const std::nothrow_t &) _NOEXCEPT;
36extern void* operator new(size_t size, const mynothrow_t &) _NOEXCEPT;
37extern void* operator new[](size_t size, const mynothrow_t &) _NOEXCEPT;
38extern void operator delete(void *ptr) _NOEXCEPT;
39extern void operator delete[](void *ptr) _NOEXCEPT;
40
41#if __cplusplus >= 201402L
42
43inline void
44operator delete(void *ptr, size_t size) throw ()
45{
46	free(ptr);
47}
48
49#endif // __cplusplus >= 201402L
50
51#endif	// #if _KERNEL_MODE
52
53#endif	// __cplusplus
54
55#endif	/* KERNEL_CPP_H */
56