xref: /haiku/src/system/kernel/util/kernel_cpp.cpp (revision 1d9d47fc72028bb71b5f232a877231e59cfe2438)
1 /* cpp - C++ in the kernel
2 **
3 ** Initial version by Axel Dörfler, axeld@pinc-software.de
4 ** This file may be used under the terms of the OpenBeOS License.
5 */
6 
7 #include "util/kernel_cpp.h"
8 
9 #ifdef _BOOT_MODE
10 #	include <boot/platform.h>
11 #elif defined(_KERNEL_MODE)
12 #	include <KernelExport.h>
13 #endif
14 
15 // Always define the symbols needed when not linking against libgcc.a --
16 // we simply override them.
17 
18 // ... it doesn't seem to work with this symbol at least.
19 #ifndef USING_LIBGCC
20 const nothrow_t std::nothrow = {};
21 #endif
22 
23 #if __GNUC__ == 2
24 
25 extern "C" void
26 __pure_virtual()
27 {
28 	panic("pure virtual function call\n");
29 }
30 
31 #elif __GNUC__ >= 3
32 
33 extern "C" void
34 __cxa_pure_virtual()
35 {
36 	panic("pure virtual function call\n");
37 }
38 
39 #endif
40 
41 // full C++ support in the kernel
42 #if defined(_KERNEL_MODE) && !defined(_BOOT_MODE)
43 
44 #include <stdio.h>
45 
46 FILE *stderr = NULL;
47 
48 extern "C"
49 int
50 fprintf(FILE *f, const char *format, ...)
51 {
52 	// TODO: Introduce a vdprintf()...
53 	dprintf("fprintf(`%s',...)\n", format);
54 	return 0;
55 }
56 
57 #if __GNUC__ >= 3
58 
59 extern "C"
60 size_t
61 fwrite(const void *buffer, size_t size, size_t numItems, FILE *stream)
62 {
63 	dprintf("%.*s", int(size * numItems), (char*)buffer);
64 	return 0;
65 }
66 
67 extern "C"
68 int
69 fputs(const char *string, FILE *stream)
70 {
71 	dprintf("%s", string);
72 	return 0;
73 }
74 
75 extern "C"
76 int
77 fputc(int c, FILE *stream)
78 {
79 	dprintf("%c", c);
80 	return 0;
81 }
82 
83 extern "C"
84 int
85 printf(const char *format, ...)
86 {
87 	// TODO: Introduce a vdprintf()...
88 	dprintf("printf(`%s',...)\n", format);
89 	return 0;
90 }
91 
92 extern "C"
93 int
94 puts(const char *string)
95 {
96 	return fputs(string, NULL);
97 }
98 
99 
100 #endif	// __GNUC__ >= 3
101 
102 extern "C"
103 void
104 abort()
105 {
106 	panic("abort() called!");
107 }
108 
109 extern "C"
110 void
111 debugger(const char *message)
112 {
113 	kernel_debugger(message);
114 }
115 
116 #endif	// _#if KERNEL_MODE
117