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 73 #endif 74 75 // full C++ support in the kernel 76 #if (defined(_KERNEL_MODE) || defined(_LOADER_MODE)) && !defined(_BOOT_MODE) 77 78 FILE *stderr = NULL; 79 80 extern "C" 81 int 82 fprintf(FILE *f, const char *format, ...) 83 { 84 // TODO: Introduce a vdprintf()... 85 dprintf("fprintf(`%s',...)\n", format); 86 return 0; 87 } 88 89 #if __GNUC__ >= 3 90 91 extern "C" 92 size_t 93 fwrite(const void *buffer, size_t size, size_t numItems, FILE *stream) 94 { 95 dprintf("%.*s", int(size * numItems), (char*)buffer); 96 return 0; 97 } 98 99 extern "C" 100 int 101 fputs(const char *string, FILE *stream) 102 { 103 dprintf("%s", string); 104 return 0; 105 } 106 107 extern "C" 108 int 109 fputc(int c, FILE *stream) 110 { 111 dprintf("%c", c); 112 return 0; 113 } 114 115 #ifndef _LOADER_MODE 116 extern "C" 117 int 118 printf(const char *format, ...) 119 { 120 // TODO: Introduce a vdprintf()... 121 dprintf("printf(`%s',...)\n", format); 122 return 0; 123 } 124 #endif 125 126 extern "C" 127 int 128 puts(const char *string) 129 { 130 return fputs(string, NULL); 131 } 132 133 134 #endif // __GNUC__ >= 3 135 136 #if __GNUC__ >= 4 && !defined(USING_LIBGCC) 137 138 extern "C" 139 void 140 _Unwind_DeleteException() 141 { 142 panic("_Unwind_DeleteException"); 143 } 144 145 extern "C" 146 void 147 _Unwind_Find_FDE() 148 { 149 panic("_Unwind_Find_FDE"); 150 } 151 152 153 extern "C" 154 void 155 _Unwind_GetDataRelBase() 156 { 157 panic("_Unwind_GetDataRelBase"); 158 } 159 160 extern "C" 161 void 162 _Unwind_GetGR() 163 { 164 panic("_Unwind_GetGR"); 165 } 166 167 extern "C" 168 void 169 _Unwind_GetIP() 170 { 171 panic("_Unwind_GetIP"); 172 } 173 174 extern "C" 175 void 176 _Unwind_GetLanguageSpecificData() 177 { 178 panic("_Unwind_GetLanguageSpecificData"); 179 } 180 181 extern "C" 182 void 183 _Unwind_GetRegionStart() 184 { 185 panic("_Unwind_GetRegionStart"); 186 } 187 188 extern "C" 189 void 190 _Unwind_GetTextRelBase() 191 { 192 panic("_Unwind_GetTextRelBase"); 193 } 194 195 extern "C" 196 void 197 _Unwind_RaiseException() 198 { 199 panic("_Unwind_RaiseException"); 200 } 201 202 extern "C" 203 void 204 _Unwind_Resume() 205 { 206 panic("_Unwind_Resume"); 207 } 208 209 extern "C" 210 void 211 _Unwind_Resume_or_Rethrow() 212 { 213 panic("_Unwind_Resume_or_Rethrow"); 214 } 215 216 extern "C" 217 void 218 _Unwind_SetGR() 219 { 220 panic("_Unwind_SetGR"); 221 } 222 223 extern "C" 224 void 225 _Unwind_SetIP() 226 { 227 panic("_Unwind_SetIP"); 228 } 229 230 extern "C" 231 void 232 __deregister_frame_info() 233 { 234 panic("__deregister_frame_info"); 235 } 236 237 extern "C" 238 void 239 __register_frame_info() 240 { 241 panic("__register_frame_info"); 242 } 243 244 245 #endif // __GNUC__ >= 4 246 247 extern "C" 248 void 249 abort() 250 { 251 panic("abort() called!"); 252 } 253 254 extern "C" 255 void 256 debugger(const char *message) 257 { 258 kernel_debugger(message); 259 } 260 261 #endif // _#if KERNEL_MODE 262