genode/repos/base/src/lib/cxx/misc.cc

264 lines
4.9 KiB
C++
Raw Normal View History

2011-12-22 16:19:25 +01:00
/*
* \brief Dummy functions to make the damn thing link
* \author Norman Feske
* \date 2006-04-07
*/
/*
* Copyright (C) 2006-2017 Genode Labs GmbH
2011-12-22 16:19:25 +01:00
*
* This file is part of the Genode OS framework, which is distributed
* under the terms of the GNU Affero General Public License version 3.
2011-12-22 16:19:25 +01:00
*/
/* libsupc++ includes */
#include <cxxabi.h>
#include <exception>
/* Genode includes */
2011-12-22 16:19:25 +01:00
#include <base/env.h>
#include <base/log.h>
#include <base/sleep.h>
2011-12-22 16:19:25 +01:00
#include <base/stdint.h>
#include <base/thread.h>
2011-12-22 16:19:25 +01:00
#include <util/string.h>
/* base-internal includes */
#include <base/internal/globals.h>
2011-12-22 16:19:25 +01:00
extern "C" void __cxa_pure_virtual()
{
Genode::error(__func__, " called, return addr is ", __builtin_return_address(0));
std::terminate();
2011-12-22 16:19:25 +01:00
}
extern "C" void __pure_virtual()
{
Genode::error(__func__, " called, return addr is ", __builtin_return_address(0));
std::terminate();
2011-12-22 16:19:25 +01:00
}
/**
* Prototype for exit-handler support function provided by '_main.cc'
*/
extern int genode___cxa_atexit(void(*func)(void*), void *arg,
void *dso_handle);
extern "C" int __cxa_atexit(void(*func)(void*), void *arg,
void *dso_handle)
{
return genode___cxa_atexit(func, arg, dso_handle);
}
/**
* Prototype for finalize support function provided by '_main.cc'
*/
extern int genode___cxa_finalize(void *dso);
extern "C" void __cxa_finalize(void *dso)
{
genode___cxa_finalize(dso);
}
2011-12-22 16:19:25 +01:00
/***********************************
** Support required for ARM EABI **
***********************************/
extern "C" int __aeabi_atexit(void *arg, void(*func)(void*),
void *dso_handle)
{
return genode___cxa_atexit(func, arg, dso_handle);
}
2011-12-22 16:19:25 +01:00
extern "C" __attribute__((weak))
void *__tls_get_addr()
{
static long dummy_tls;
return &dummy_tls;
}
/**
* Not needed for exception-handling init on ARM EABI,
* but called from 'init_exception'
*/
extern "C" __attribute__((weak))
void __register_frame(void *) { }
/**
* Needed to build for OKL4-gta01 with ARM EABI
*/
extern "C" __attribute__((weak)) void raise()
{
Genode::warning("cxx: raise called - not implemented");
2011-12-22 16:19:25 +01:00
}
/***************************
** Support for libsupc++ **
***************************/
extern "C" void abort(void)
2011-12-22 16:19:25 +01:00
{
Genode::Thread const * const myself = Genode::Thread::myself();
Genode::Thread::Name name = "unknown";
if (myself)
name = myself->name();
Genode::warning("abort called - thread: ", name.string());
/* Notify the parent of failure */
if (name != "main")
genode_exit(1);
Genode::sleep_forever();
2011-12-22 16:19:25 +01:00
}
extern "C" int fputc(int, void*) {
2011-12-22 16:19:25 +01:00
return 0;
}
extern "C" int fputs(const char *s, void *) {
Genode::warning("C++ runtime: ", s);
2011-12-22 16:19:25 +01:00
return 0;
}
extern "C" size_t fwrite(const void*, size_t, size_t, void*) {
2011-12-22 16:19:25 +01:00
return 0;
}
extern "C" int memcmp(const void *p0, const void *p1, size_t size)
{
return Genode::memcmp(p0, p1, size);
}
extern "C" __attribute__((weak))
void *memcpy(void *dst, const void *src, size_t n)
2011-12-22 16:19:25 +01:00
{
return Genode::memcpy(dst, src, n);
}
extern "C" __attribute__((weak))
void *memmove(void *dst, const void *src, size_t n)
2011-12-22 16:19:25 +01:00
{
return Genode::memmove(dst, src, n);
}
extern "C" __attribute__((weak))
void *memset(void *s, int c, size_t n)
{
return Genode::memset(s, c, n);
}
extern "C" void *stderr(void) {
Genode::warning("stderr - not yet implemented");
2011-12-22 16:19:25 +01:00
return 0;
}
/*
* Used when having compiled libsupc++ with the FreeBSD libc
*/
struct FILE;
FILE *__stderrp;
extern "C" char *strcat(char *, const char *)
2011-12-22 16:19:25 +01:00
{
Genode::warning("strcat - not yet implemented");
2011-12-22 16:19:25 +01:00
return 0;
}
extern "C" int strncmp(const char *s1, const char *s2, size_t n)
{
return Genode::strcmp(s1, s2, n);
}
extern "C" char *strcpy(char *dest, const char *src)
{
Genode::copy_cstring(dest, src, ~0UL);
return dest;
2011-12-22 16:19:25 +01:00
}
extern "C" size_t strlen(const char *s)
{
return Genode::strlen(s);
}
extern "C" int strcmp(const char *s1, const char *s2)
{
return Genode::strcmp(s1, s2);
}
/*
* Needed by ARM EABI (gcc-4.4 Codesourcery release1039)
*/
Follow practices suggested by "Effective C++" The patch adjust the code of the base, base-<kernel>, and os repository. To adapt existing components to fix violations of the best practices suggested by "Effective C++" as reported by the -Weffc++ compiler argument. The changes follow the patterns outlined below: * A class with virtual functions can no longer publicly inherit base classed without a vtable. The inherited object may either be moved to a member variable, or inherited privately. The latter would be used for classes that inherit 'List::Element' or 'Avl_node'. In order to enable the 'List' and 'Avl_tree' to access the meta data, the 'List' must become a friend. * Instead of adding a virtual destructor to abstract base classes, we inherit the new 'Interface' class, which contains a virtual destructor. This way, single-line abstract base classes can stay as compact as they are now. The 'Interface' utility resides in base/include/util/interface.h. * With the new warnings enabled, all member variables must be explicitly initialized. Basic types may be initialized with '='. All other types are initialized with braces '{ ... }' or as class initializers. If basic types and non-basic types appear in a row, it is nice to only use the brace syntax (also for basic types) and align the braces. * If a class contains pointers as members, it must now also provide a copy constructor and assignment operator. In the most cases, one would make them private, effectively disallowing the objects to be copied. Unfortunately, this warning cannot be fixed be inheriting our existing 'Noncopyable' class (the compiler fails to detect that the inheriting class cannot be copied and still gives the error). For now, we have to manually add declarations for both the copy constructor and assignment operator as private class members. Those declarations should be prepended with a comment like this: /* * Noncopyable */ Thread(Thread const &); Thread &operator = (Thread const &); In the future, we should revisit these places and try to replace the pointers with references. In the presence of at least one reference member, the compiler would no longer implicitly generate a copy constructor. So we could remove the manual declaration. Issue #465
2017-12-21 15:42:15 +01:00
extern "C" int sprintf(char *, const char *, ...)
2011-12-22 16:19:25 +01:00
{
Genode::warning("sprintf - not implemented");
2011-12-22 16:19:25 +01:00
return 0;
}
/**********************************
** Support for stack protection **
**********************************/
extern "C" __attribute__((weak)) void __stack_chk_fail_local(void)
{
Genode::error("Violated stack boundary");
2011-12-22 16:19:25 +01:00
}
/*******************************
** Demangling of C++ symbols **
*******************************/
extern "C" void free(void *);
void Genode::cxx_demangle(char const *symbol, char *out, size_t size)
{
char *demangled_name = __cxxabiv1::__cxa_demangle(symbol, nullptr, nullptr, nullptr);
if (demangled_name) {
Genode::copy_cstring(out, demangled_name, size);
free(demangled_name);
} else {
Genode::copy_cstring(out, symbol, size);
}
}
void Genode::cxx_current_exception(char *out, size_t size)
{
std::type_info *t = __cxxabiv1::__cxa_current_exception_type();
if (!t)
return;
cxx_demangle(t->name(), out, size);
}