1 /* 2 * Copyright 2003-2007, Haiku Inc. All rights reserved. 3 * Distributed under the terms of the MIT License. 4 * 5 * Authors: 6 * Axel Dörfler, axeld@pinc-software.de. 7 * Ingo Weinhold, bonefish@users.sf.net. 8 */ 9 10 //! C++ in the kernel 11 12 13 #include "util/kernel_cpp.h" 14 15 #ifdef _BOOT_MODE 16 # include <boot/platform.h> 17 #else 18 # include <KernelExport.h> 19 # include <stdio.h> 20 #endif 21 22 #ifdef _LOADER_MODE 23 # define panic printf 24 # define dprintf printf 25 # define kernel_debugger printf 26 #endif 27 28 29 // Always define the symbols needed when not linking against libgcc.a -- 30 // we simply override them. 31 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 40 41 const mynothrow_t mynothrow = {}; 42 43 #if __GNUC__ == 2 44 45 extern "C" void 46 __pure_virtual() 47 { 48 panic("pure virtual function call\n"); 49 } 50 51 #elif __GNUC__ >= 3 52 53 extern "C" void 54 __cxa_pure_virtual() 55 { 56 panic("pure virtual function call\n"); 57 } 58 59 60 extern "C" int 61 __cxa_atexit(void (*hook)(void*), void* data, void* dsoHandle) 62 { 63 return 0; 64 } 65 66 67 extern "C" void 68 __cxa_finalize(void* dsoHandle) 69 { 70 } 71 72 #endif 73 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) 78 { 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); 83 } 84 85 86 void * 87 operator new[](size_t size) throw (std::bad_alloc) 88 { 89 return malloc(size); 90 } 91 92 93 void * 94 operator new(size_t size, const std::nothrow_t &) throw () 95 { 96 return malloc(size); 97 } 98 99 100 void * 101 operator new[](size_t size, const std::nothrow_t &) throw () 102 { 103 return malloc(size); 104 } 105 106 107 void * 108 operator new(size_t size, const mynothrow_t &) throw () 109 { 110 return malloc(size); 111 } 112 113 114 void * 115 operator new[](size_t size, const mynothrow_t &) throw () 116 { 117 return malloc(size); 118 } 119 120 121 void 122 operator delete(void *ptr) throw () 123 { 124 free(ptr); 125 } 126 127 128 void 129 operator delete[](void *ptr) throw () 130 { 131 free(ptr); 132 } 133 134 #ifndef _BOOT_MODE 135 136 FILE *stderr = NULL; 137 138 extern "C" 139 int 140 fprintf(FILE *f, const char *format, ...) 141 { 142 // TODO: Introduce a vdprintf()... 143 dprintf("fprintf(`%s',...)\n", format); 144 return 0; 145 } 146 147 extern "C" 148 size_t 149 fwrite(const void *buffer, size_t size, size_t numItems, FILE *stream) 150 { 151 dprintf("%.*s", int(size * numItems), (char*)buffer); 152 return 0; 153 } 154 155 extern "C" 156 int 157 fputs(const char *string, FILE *stream) 158 { 159 dprintf("%s", string); 160 return 0; 161 } 162 163 extern "C" 164 int 165 fputc(int c, FILE *stream) 166 { 167 dprintf("%c", c); 168 return 0; 169 } 170 171 #ifndef _LOADER_MODE 172 extern "C" 173 int 174 printf(const char *format, ...) 175 { 176 // TODO: Introduce a vdprintf()... 177 dprintf("printf(`%s',...)\n", format); 178 return 0; 179 } 180 #endif // #ifndef _LOADER_MODE 181 182 extern "C" 183 int 184 puts(const char *string) 185 { 186 return fputs(string, NULL); 187 } 188 189 #endif // #ifndef _BOOT_MODE 190 191 #if __GNUC__ >= 4 192 193 extern "C" 194 void 195 _Unwind_DeleteException() 196 { 197 panic("_Unwind_DeleteException"); 198 } 199 200 extern "C" 201 void 202 _Unwind_Find_FDE() 203 { 204 panic("_Unwind_Find_FDE"); 205 } 206 207 208 extern "C" 209 void 210 _Unwind_GetDataRelBase() 211 { 212 panic("_Unwind_GetDataRelBase"); 213 } 214 215 extern "C" 216 void 217 _Unwind_GetGR() 218 { 219 panic("_Unwind_GetGR"); 220 } 221 222 extern "C" 223 void 224 _Unwind_GetIP() 225 { 226 panic("_Unwind_GetIP"); 227 } 228 229 extern "C" 230 void 231 _Unwind_GetIPInfo() 232 { 233 panic("_Unwind_GetIPInfo"); 234 } 235 236 extern "C" 237 void 238 _Unwind_GetLanguageSpecificData() 239 { 240 panic("_Unwind_GetLanguageSpecificData"); 241 } 242 243 extern "C" 244 void 245 _Unwind_GetRegionStart() 246 { 247 panic("_Unwind_GetRegionStart"); 248 } 249 250 extern "C" 251 void 252 _Unwind_GetTextRelBase() 253 { 254 panic("_Unwind_GetTextRelBase"); 255 } 256 257 extern "C" 258 void 259 _Unwind_RaiseException() 260 { 261 panic("_Unwind_RaiseException"); 262 } 263 264 extern "C" 265 void 266 _Unwind_Resume() 267 { 268 panic("_Unwind_Resume"); 269 } 270 271 extern "C" 272 void 273 _Unwind_Resume_or_Rethrow() 274 { 275 panic("_Unwind_Resume_or_Rethrow"); 276 } 277 278 extern "C" 279 void 280 _Unwind_SetGR() 281 { 282 panic("_Unwind_SetGR"); 283 } 284 285 extern "C" 286 void 287 _Unwind_SetIP() 288 { 289 panic("_Unwind_SetIP"); 290 } 291 292 extern "C" 293 void 294 __deregister_frame_info() 295 { 296 panic("__deregister_frame_info"); 297 } 298 299 extern "C" 300 void 301 __register_frame_info() 302 { 303 panic("__register_frame_info"); 304 } 305 306 /* ARM */ 307 extern "C" void 308 __aeabi_unwind_cpp_pr0(void) 309 { 310 panic("__aeabi_unwind_cpp_pr0"); 311 } 312 313 extern "C" void 314 __aeabi_unwind_cpp_pr1(void) 315 { 316 panic("__aeabi_unwind_cpp_pr1"); 317 } 318 319 extern "C" void 320 __aeabi_unwind_cpp_pr2(void) 321 { 322 panic("__aeabi_unwind_cpp_pr2"); 323 } 324 325 extern "C" void 326 _Unwind_Complete(void) 327 { 328 panic("_Unwind_Complete"); 329 } 330 331 extern "C" void 332 _Unwind_VRS_Set(void) 333 { 334 panic("_Unwind_VRS_Set"); 335 } 336 337 extern "C" void 338 _Unwind_VRS_Get(void) 339 { 340 panic("_Unwind_VRS_Get"); 341 } 342 343 extern "C" void 344 __gnu_unwind_frame(void) 345 { 346 panic("__gnu_unwind_frame"); 347 } 348 349 #endif // __GNUC__ >= 4 350 351 extern "C" 352 void 353 abort() 354 { 355 panic("abort() called!"); 356 } 357 358 359 #ifndef _BOOT_MODE 360 361 extern "C" 362 void 363 debugger(const char *message) 364 { 365 kernel_debugger(message); 366 } 367 368 #endif // #ifndef _BOOT_MODE 369 370 #endif // #if (defined(_KERNEL_MODE) || defined(_LOADER_MODE)) 371 372 373 extern "C" 374 void 375 exit(int status) 376 { 377 panic("exit() called with status code = %d!", status); 378 } 379 380