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 35const std::nothrow_t std::nothrow = {}; 36# else 37const nothrow_t std::nothrow = {}; 38# endif 39#endif 40 41const mynothrow_t mynothrow = {}; 42 43#if __GNUC__ == 2 44 45extern "C" void 46__pure_virtual() 47{ 48 panic("pure virtual function call\n"); 49} 50 51#elif __GNUC__ >= 3 52 53extern "C" void 54__cxa_pure_virtual() 55{ 56 panic("pure virtual function call\n"); 57} 58 59 60extern "C" int 61__cxa_atexit(void (*hook)(void*), void* data, void* dsoHandle) 62{ 63 return 0; 64} 65 66 67extern "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 78FILE *stderr = NULL; 79 80extern "C" 81int 82fprintf(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 91extern "C" 92size_t 93fwrite(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 99extern "C" 100int 101fputs(const char *string, FILE *stream) 102{ 103 dprintf("%s", string); 104 return 0; 105} 106 107extern "C" 108int 109fputc(int c, FILE *stream) 110{ 111 dprintf("%c", c); 112 return 0; 113} 114 115#ifndef _LOADER_MODE 116extern "C" 117int 118printf(const char *format, ...) 119{ 120 // TODO: Introduce a vdprintf()... 121 dprintf("printf(`%s',...)\n", format); 122 return 0; 123} 124#endif 125 126extern "C" 127int 128puts(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 138extern "C" 139void 140_Unwind_DeleteException() 141{ 142 panic("_Unwind_DeleteException"); 143} 144 145extern "C" 146void 147_Unwind_Find_FDE() 148{ 149 panic("_Unwind_Find_FDE"); 150} 151 152 153extern "C" 154void 155_Unwind_GetDataRelBase() 156{ 157 panic("_Unwind_GetDataRelBase"); 158} 159 160extern "C" 161void 162_Unwind_GetGR() 163{ 164 panic("_Unwind_GetGR"); 165} 166 167extern "C" 168void 169_Unwind_GetIP() 170{ 171 panic("_Unwind_GetIP"); 172} 173 174extern "C" 175void 176_Unwind_GetLanguageSpecificData() 177{ 178 panic("_Unwind_GetLanguageSpecificData"); 179} 180 181extern "C" 182void 183_Unwind_GetRegionStart() 184{ 185 panic("_Unwind_GetRegionStart"); 186} 187 188extern "C" 189void 190_Unwind_GetTextRelBase() 191{ 192 panic("_Unwind_GetTextRelBase"); 193} 194 195extern "C" 196void 197_Unwind_RaiseException() 198{ 199 panic("_Unwind_RaiseException"); 200} 201 202extern "C" 203void 204_Unwind_Resume() 205{ 206 panic("_Unwind_Resume"); 207} 208 209extern "C" 210void 211_Unwind_Resume_or_Rethrow() 212{ 213 panic("_Unwind_Resume_or_Rethrow"); 214} 215 216extern "C" 217void 218_Unwind_SetGR() 219{ 220 panic("_Unwind_SetGR"); 221} 222 223extern "C" 224void 225_Unwind_SetIP() 226{ 227 panic("_Unwind_SetIP"); 228} 229 230extern "C" 231void 232__deregister_frame_info() 233{ 234 panic("__deregister_frame_info"); 235} 236 237extern "C" 238void 239__register_frame_info() 240{ 241 panic("__register_frame_info"); 242} 243 244 245#endif // __GNUC__ >= 4 246 247extern "C" 248void 249abort() 250{ 251 panic("abort() called!"); 252} 253 254extern "C" 255void 256debugger(const char *message) 257{ 258 kernel_debugger(message); 259} 260 261#endif // _#if KERNEL_MODE 262