vfs: check userland buffers before reading them.
[haiku.git] / src / system / kernel / util / kernel_cpp.cpp
blob0ad305a2bc9e491866255b996e7a0eec82916b3a
1 /*
2 * Copyright 2003-2007, Haiku Inc. All rights reserved.
3 * Distributed under the terms of the MIT License.
5 * Authors:
6 * Axel Dörfler, axeld@pinc-software.de.
7 * Ingo Weinhold, bonefish@users.sf.net.
8 */
10 //! C++ in the kernel
13 #include "util/kernel_cpp.h"
15 #ifdef _BOOT_MODE
16 # include <boot/platform.h>
17 #else
18 # include <KernelExport.h>
19 # include <stdio.h>
20 #endif
22 #ifdef _LOADER_MODE
23 # define panic printf
24 # define dprintf printf
25 # define kernel_debugger printf
26 #endif
29 // Always define the symbols needed when not linking against libgcc.a --
30 // we simply override them.
32 // ... it doesn't seem to work with this symbol at least.
33 #ifndef USING_LIBGCC
34 # if __GNUC__ >= 3
35 const std::nothrow_t std::nothrow = {};
36 # else
37 const nothrow_t std::nothrow = {};
38 # endif
39 #endif
41 const mynothrow_t mynothrow = {};
43 #if __GNUC__ == 2
45 extern "C" void
46 __pure_virtual()
48 panic("pure virtual function call\n");
51 #elif __GNUC__ >= 3
53 extern "C" void
54 __cxa_pure_virtual()
56 panic("pure virtual function call\n");
60 extern "C" int
61 __cxa_atexit(void (*hook)(void*), void* data, void* dsoHandle)
63 return 0;
67 extern "C" void
68 __cxa_finalize(void* dsoHandle)
72 #endif
74 // full C++ support in the kernel
75 #if (defined(_KERNEL_MODE) || defined(_LOADER_MODE))
76 void *
77 operator new(size_t size) throw (std::bad_alloc)
79 // we don't actually throw any exceptions, but we have to
80 // keep the prototype as specified in <new>, or else GCC 3
81 // won't like us
82 return malloc(size);
86 void *
87 operator new[](size_t size) throw (std::bad_alloc)
89 return malloc(size);
93 void *
94 operator new(size_t size, const std::nothrow_t &) throw ()
96 return malloc(size);
100 void *
101 operator new[](size_t size, const std::nothrow_t &) throw ()
103 return malloc(size);
107 void *
108 operator new(size_t size, const mynothrow_t &) throw ()
110 return malloc(size);
114 void *
115 operator new[](size_t size, const mynothrow_t &) throw ()
117 return malloc(size);
121 void
122 operator delete(void *ptr) throw ()
124 free(ptr);
128 void
129 operator delete[](void *ptr) throw ()
131 free(ptr);
134 #ifndef _BOOT_MODE
136 FILE *stderr = NULL;
138 extern "C"
140 fprintf(FILE *f, const char *format, ...)
142 // TODO: Introduce a vdprintf()...
143 dprintf("fprintf(`%s',...)\n", format);
144 return 0;
147 extern "C"
148 size_t
149 fwrite(const void *buffer, size_t size, size_t numItems, FILE *stream)
151 dprintf("%.*s", int(size * numItems), (char*)buffer);
152 return 0;
155 extern "C"
157 fputs(const char *string, FILE *stream)
159 dprintf("%s", string);
160 return 0;
163 extern "C"
165 fputc(int c, FILE *stream)
167 dprintf("%c", c);
168 return 0;
171 #ifndef _LOADER_MODE
172 extern "C"
174 printf(const char *format, ...)
176 // TODO: Introduce a vdprintf()...
177 dprintf("printf(`%s',...)\n", format);
178 return 0;
180 #endif // #ifndef _LOADER_MODE
182 extern "C"
184 puts(const char *string)
186 return fputs(string, NULL);
189 #endif // #ifndef _BOOT_MODE
191 #if __GNUC__ >= 4
193 extern "C"
194 void
195 _Unwind_DeleteException()
197 panic("_Unwind_DeleteException");
200 extern "C"
201 void
202 _Unwind_Find_FDE()
204 panic("_Unwind_Find_FDE");
208 extern "C"
209 void
210 _Unwind_GetDataRelBase()
212 panic("_Unwind_GetDataRelBase");
215 extern "C"
216 void
217 _Unwind_GetGR()
219 panic("_Unwind_GetGR");
222 extern "C"
223 void
224 _Unwind_GetIP()
226 panic("_Unwind_GetIP");
229 extern "C"
230 void
231 _Unwind_GetIPInfo()
233 panic("_Unwind_GetIPInfo");
236 extern "C"
237 void
238 _Unwind_GetLanguageSpecificData()
240 panic("_Unwind_GetLanguageSpecificData");
243 extern "C"
244 void
245 _Unwind_GetRegionStart()
247 panic("_Unwind_GetRegionStart");
250 extern "C"
251 void
252 _Unwind_GetTextRelBase()
254 panic("_Unwind_GetTextRelBase");
257 extern "C"
258 void
259 _Unwind_RaiseException()
261 panic("_Unwind_RaiseException");
264 extern "C"
265 void
266 _Unwind_Resume()
268 panic("_Unwind_Resume");
271 extern "C"
272 void
273 _Unwind_Resume_or_Rethrow()
275 panic("_Unwind_Resume_or_Rethrow");
278 extern "C"
279 void
280 _Unwind_SetGR()
282 panic("_Unwind_SetGR");
285 extern "C"
286 void
287 _Unwind_SetIP()
289 panic("_Unwind_SetIP");
292 extern "C"
293 void
294 __deregister_frame_info()
296 panic("__deregister_frame_info");
299 extern "C"
300 void
301 __register_frame_info()
303 panic("__register_frame_info");
306 /* ARM */
307 extern "C" void
308 __aeabi_unwind_cpp_pr0(void)
310 panic("__aeabi_unwind_cpp_pr0");
313 extern "C" void
314 __aeabi_unwind_cpp_pr1(void)
316 panic("__aeabi_unwind_cpp_pr1");
319 extern "C" void
320 __aeabi_unwind_cpp_pr2(void)
322 panic("__aeabi_unwind_cpp_pr2");
325 extern "C" void
326 _Unwind_Complete(void)
328 panic("_Unwind_Complete");
331 extern "C" void
332 _Unwind_VRS_Set(void)
334 panic("_Unwind_VRS_Set");
337 extern "C" void
338 _Unwind_VRS_Get(void)
340 panic("_Unwind_VRS_Get");
343 extern "C" void
344 __gnu_unwind_frame(void)
346 panic("__gnu_unwind_frame");
349 #endif // __GNUC__ >= 4
351 extern "C"
352 void
353 abort()
355 panic("abort() called!");
359 #ifndef _BOOT_MODE
361 extern "C"
362 void
363 debugger(const char *message)
365 kernel_debugger(message);
368 #endif // #ifndef _BOOT_MODE
370 #endif // #if (defined(_KERNEL_MODE) || defined(_LOADER_MODE))
373 extern "C"
374 void
375 exit(int status)
377 panic("exit() called with status code = %d!", status);