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 77 #ifndef _BOOT_MODE 78 79 FILE *stderr = NULL; 80 81 extern "C" 82 int 83 fprintf(FILE *f, const char *format, ...) 84 { 85 // TODO: Introduce a vdprintf()... 86 dprintf("fprintf(`%s',...)\n", format); 87 return 0; 88 } 89 90 extern "C" 91 size_t 92 fwrite(const void *buffer, size_t size, size_t numItems, FILE *stream) 93 { 94 dprintf("%.*s", int(size * numItems), (char*)buffer); 95 return 0; 96 } 97 98 extern "C" 99 int 100 fputs(const char *string, FILE *stream) 101 { 102 dprintf("%s", string); 103 return 0; 104 } 105 106 extern "C" 107 int 108 fputc(int c, FILE *stream) 109 { 110 dprintf("%c", c); 111 return 0; 112 } 113 114 #ifndef _LOADER_MODE 115 extern "C" 116 int 117 printf(const char *format, ...) 118 { 119 // TODO: Introduce a vdprintf()... 120 dprintf("printf(`%s',...)\n", format); 121 return 0; 122 } 123 #endif // #ifndef _LOADER_MODE 124 125 extern "C" 126 int 127 puts(const char *string) 128 { 129 return fputs(string, NULL); 130 } 131 132 #endif // #ifndef _BOOT_MODE 133 134 #if __GNUC__ >= 4 135 136 extern "C" 137 void 138 _Unwind_DeleteException() 139 { 140 panic("_Unwind_DeleteException"); 141 } 142 143 extern "C" 144 void 145 _Unwind_Find_FDE() 146 { 147 panic("_Unwind_Find_FDE"); 148 } 149 150 151 extern "C" 152 void 153 _Unwind_GetDataRelBase() 154 { 155 panic("_Unwind_GetDataRelBase"); 156 } 157 158 extern "C" 159 void 160 _Unwind_GetGR() 161 { 162 panic("_Unwind_GetGR"); 163 } 164 165 extern "C" 166 void 167 _Unwind_GetIP() 168 { 169 panic("_Unwind_GetIP"); 170 } 171 172 extern "C" 173 void 174 _Unwind_GetIPInfo() 175 { 176 panic("_Unwind_GetIPInfo"); 177 } 178 179 extern "C" 180 void 181 _Unwind_GetLanguageSpecificData() 182 { 183 panic("_Unwind_GetLanguageSpecificData"); 184 } 185 186 extern "C" 187 void 188 _Unwind_GetRegionStart() 189 { 190 panic("_Unwind_GetRegionStart"); 191 } 192 193 extern "C" 194 void 195 _Unwind_GetTextRelBase() 196 { 197 panic("_Unwind_GetTextRelBase"); 198 } 199 200 extern "C" 201 void 202 _Unwind_RaiseException() 203 { 204 panic("_Unwind_RaiseException"); 205 } 206 207 extern "C" 208 void 209 _Unwind_Resume() 210 { 211 panic("_Unwind_Resume"); 212 } 213 214 extern "C" 215 void 216 _Unwind_Resume_or_Rethrow() 217 { 218 panic("_Unwind_Resume_or_Rethrow"); 219 } 220 221 extern "C" 222 void 223 _Unwind_SetGR() 224 { 225 panic("_Unwind_SetGR"); 226 } 227 228 extern "C" 229 void 230 _Unwind_SetIP() 231 { 232 panic("_Unwind_SetIP"); 233 } 234 235 extern "C" 236 void 237 __deregister_frame_info() 238 { 239 panic("__deregister_frame_info"); 240 } 241 242 extern "C" 243 void 244 __register_frame_info() 245 { 246 panic("__register_frame_info"); 247 } 248 249 /* ARM */ 250 extern "C" void 251 __aeabi_unwind_cpp_pr0(void) 252 { 253 panic("__aeabi_unwind_cpp_pr0"); 254 } 255 256 extern "C" void 257 __aeabi_unwind_cpp_pr1(void) 258 { 259 panic("__aeabi_unwind_cpp_pr1"); 260 } 261 262 extern "C" void 263 __aeabi_unwind_cpp_pr2(void) 264 { 265 panic("__aeabi_unwind_cpp_pr2"); 266 } 267 268 extern "C" void 269 _Unwind_Complete(void) 270 { 271 panic("_Unwind_Complete"); 272 } 273 274 extern "C" void 275 _Unwind_VRS_Set(void) 276 { 277 panic("_Unwind_VRS_Set"); 278 } 279 280 extern "C" void 281 _Unwind_VRS_Get(void) 282 { 283 panic("_Unwind_VRS_Get"); 284 } 285 286 extern "C" void 287 __gnu_unwind_frame(void) 288 { 289 panic("__gnu_unwind_frame"); 290 } 291 292 #endif // __GNUC__ >= 4 293 294 extern "C" 295 void 296 abort() 297 { 298 panic("abort() called!"); 299 } 300 301 302 #ifndef _BOOT_MODE 303 304 extern "C" 305 void 306 debugger(const char *message) 307 { 308 kernel_debugger(message); 309 } 310 311 #endif // #ifndef _BOOT_MODE 312 313 #endif // #if (defined(_KERNEL_MODE) || defined(_LOADER_MODE)) 314 315 316 extern "C" 317 void 318 exit(int status) 319 { 320 panic("exit() called with status code = %d!", status); 321 } 322 323