1 | /* $Id: kernel_cpp.h 43363 2012-09-20 09:56:07Z vboxsync $ */
|
---|
2 | /** @file
|
---|
3 | * Kernel C++, Haiku private.
|
---|
4 | */
|
---|
5 |
|
---|
6 | /*
|
---|
7 | * Copyright (C) 2012 Oracle Corporation
|
---|
8 | *
|
---|
9 | * This file is part of VirtualBox Open Source Edition (OSE), as
|
---|
10 | * available from http://www.virtualbox.org. This file is free software;
|
---|
11 | * you can redistribute it and/or modify it under the terms of the GNU
|
---|
12 | * General Public License (GPL) as published by the Free Software
|
---|
13 | * Foundation, in version 2 as it comes in the "COPYING" file of the
|
---|
14 | * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
|
---|
15 | * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
|
---|
16 | */
|
---|
17 |
|
---|
18 | /*
|
---|
19 | * This code is based on:
|
---|
20 | *
|
---|
21 | * VirtualBox Guest Additions for Haiku. C++ in the kernel.
|
---|
22 | *
|
---|
23 | * Copyright 2002-2009, Axel Dörfler, axeld@pinc-software.de.
|
---|
24 | * Distributed under the terms of the MIT License.
|
---|
25 | */
|
---|
26 |
|
---|
27 | #ifndef KERNEL_CPP_H
|
---|
28 | #define KERNEL_CPP_H
|
---|
29 |
|
---|
30 | #ifdef __cplusplus
|
---|
31 |
|
---|
32 | #include <new>
|
---|
33 | #include <stdlib.h>
|
---|
34 |
|
---|
35 | #if _KERNEL_MODE || _LOADER_MODE
|
---|
36 |
|
---|
37 | using namespace std;
|
---|
38 | extern const nothrow_t std::nothrow;
|
---|
39 |
|
---|
40 | // We need new() versions we can use when also linking against libgcc.
|
---|
41 | // std::nothrow can't be used since it's defined in both libgcc and
|
---|
42 | // kernel_cpp.cpp.
|
---|
43 | typedef struct {} mynothrow_t;
|
---|
44 | extern const mynothrow_t mynothrow;
|
---|
45 |
|
---|
46 |
|
---|
47 | inline void *
|
---|
48 | operator new(size_t size) throw (std::bad_alloc)
|
---|
49 | {
|
---|
50 | // we don't actually throw any exceptions, but we have to
|
---|
51 | // keep the prototype as specified in <new>, or else GCC 3
|
---|
52 | // won't like us
|
---|
53 | return malloc(size);
|
---|
54 | }
|
---|
55 |
|
---|
56 |
|
---|
57 | inline void *
|
---|
58 | operator new[](size_t size) throw (std::bad_alloc)
|
---|
59 | {
|
---|
60 | return malloc(size);
|
---|
61 | }
|
---|
62 |
|
---|
63 |
|
---|
64 | inline void *
|
---|
65 | operator new(size_t size, const std::nothrow_t &) throw ()
|
---|
66 | {
|
---|
67 | return malloc(size);
|
---|
68 | }
|
---|
69 |
|
---|
70 |
|
---|
71 | inline void *
|
---|
72 | operator new[](size_t size, const std::nothrow_t &) throw ()
|
---|
73 | {
|
---|
74 | return malloc(size);
|
---|
75 | }
|
---|
76 |
|
---|
77 |
|
---|
78 | inline void *
|
---|
79 | operator new(size_t size, const mynothrow_t &) throw ()
|
---|
80 | {
|
---|
81 | return malloc(size);
|
---|
82 | }
|
---|
83 |
|
---|
84 |
|
---|
85 | inline void *
|
---|
86 | operator new[](size_t size, const mynothrow_t &) throw ()
|
---|
87 | {
|
---|
88 | return malloc(size);
|
---|
89 | }
|
---|
90 |
|
---|
91 |
|
---|
92 | inline void
|
---|
93 | operator delete(void *ptr) throw ()
|
---|
94 | {
|
---|
95 | free(ptr);
|
---|
96 | }
|
---|
97 |
|
---|
98 |
|
---|
99 | inline void
|
---|
100 | operator delete[](void *ptr) throw ()
|
---|
101 | {
|
---|
102 | free(ptr);
|
---|
103 | }
|
---|
104 |
|
---|
105 | #endif // #if _KERNEL_MODE
|
---|
106 |
|
---|
107 | #endif // __cplusplus
|
---|
108 |
|
---|
109 | #endif /* KERNEL_CPP_H */
|
---|