From: John Hodge Date: Sun, 9 Mar 2014 07:44:45 +0000 (+0800) Subject: Usermode/libc++ - Basic C++ runtime implementation X-Git-Url: https://git.ucc.asn.au/?a=commitdiff_plain;h=515d24f4080529f45fc94c4522f2a0da3fe98148;p=tpg%2Facess2.git Usermode/libc++ - Basic C++ runtime implementation --- diff --git a/Usermode/Libraries/libc++.so_src/Makefile b/Usermode/Libraries/libc++.so_src/Makefile new file mode 100644 index 00000000..6cec94f1 --- /dev/null +++ b/Usermode/Libraries/libc++.so_src/Makefile @@ -0,0 +1,20 @@ +# Acess2 C++ Library +# Makefile + +-include ../Makefile.cfg + +CPPFLAGS += +CFLAGS += -Wall -Werror -Wextra +CXXFLAGS += -Wall -Werror -Wextra +ASFLAGS += +LDFLAGS += -Map map.txt -lc + +OBJ = misc.o new.o guard.o cxxabi.o typeinfo.o +DEPFILES := $(OBJ:%.o=%.d) +BIN = libc++.so +ifeq ($(ARCHDIR),native) + OBJ := $(filter-out heap.o,$(OBJ)) + BIN = libc++_acess.so +endif + +include ../Makefile.tpl diff --git a/Usermode/Libraries/libc++.so_src/cxxabi.cc b/Usermode/Libraries/libc++.so_src/cxxabi.cc new file mode 100644 index 00000000..adda291c --- /dev/null +++ b/Usermode/Libraries/libc++.so_src/cxxabi.cc @@ -0,0 +1,32 @@ +/* + * Acess2 C++ Library + * - By John Hodge (thePowersGang) + * + * cxxabi.cc + * - C++ ABI Namespace + */ +#include + +namespace __cxxabiv1 { + +// --- RTTI -- +// - No inheritance class +__class_type_info::~__class_type_info() +{ + // nop +} + +// - Single inheritance class +__si_class_type_info::~__si_class_type_info() +{ + +} + +// - Multiple inheritance class +__vmi_class_type_info::~__vmi_class_type_info() +{ + +} + +}; // namespace __cxxabiv1 + diff --git a/Usermode/Libraries/libc++.so_src/guard.cc b/Usermode/Libraries/libc++.so_src/guard.cc new file mode 100644 index 00000000..a075a7b6 --- /dev/null +++ b/Usermode/Libraries/libc++.so_src/guard.cc @@ -0,0 +1,29 @@ +/* + * Acess2 C++ Library + * - By John Hodge (thePowersGang) + * + * guard.cc + * - One-time construction API + */ +#include + +extern "C" int __cxa_guard_acquire ( int64_t *guard_object ) +{ + // TODO: Mutex! + if( *guard_object ) + return 1; + *guard_object = 1; + return 0; +} + +extern "C" void __cxa_guard_release ( int64_t *guard_object ) +{ + *guard_object = 0; +} + +extern "C" void __cxa_guard_abort ( int64_t *guard_object ) +{ + *guard_object = 0; + // TODO: abort +} + diff --git a/Usermode/Libraries/libc++.so_src/include_exp/cxxabi.h b/Usermode/Libraries/libc++.so_src/include_exp/cxxabi.h new file mode 100644 index 00000000..a8e1f5ca --- /dev/null +++ b/Usermode/Libraries/libc++.so_src/include_exp/cxxabi.h @@ -0,0 +1,76 @@ +/* + * Acess2 C++ Library + * - By John Hodge (thePowersGang) + * + * cxxabi.h + * - C++ ABI Namespace + */ +#ifndef _LIBCXX__CXXABI_H_ +#define _LIBCXX__CXXABI_H_ + +#include + +namespace __cxxabiv1 { + +class __class_type_info : public std::type_info +{ +public: + virtual ~__class_type_info(); +}; + +class __si_class_type_info : public __class_type_info +{ +public: + virtual ~__si_class_type_info(); + + const __class_type_info *__base_type; +}; + +struct __base_class_type_info +{ +public: + + const __class_type_info *__base_type; + long __offset_flags; + + enum __offset_flags_masks { + __virtual_mask = 0x1, + __public_mask = 0x2, + __offset_shift = 8 + }; + +}; + +class __vmi_class_type_info : public __class_type_info +{ +public: + virtual ~__vmi_class_type_info(); + + unsigned int __flags; + unsigned int __base_count; + __base_class_type_info __base_info[1]; + + enum __flags_masks { + __non_diamond_repeat_mask = 0x1, + __diamond_shaped_mask = 0x2, + }; +}; + +class __pbase_type_info : public std::type_info +{ +public: + unsigned int __flags; + const std::type_info *__pointee; + + enum __masks { + __const_mask = 0x1, + __volatile_mask = 0x2, + __restrict_mask = 0x4, + __incomplete_mask = 0x8, + __incomplete_class_mask = 0x10 + }; +}; + +}; // namespace __cxxabiv1 + +#endif diff --git a/Usermode/Libraries/libc++.so_src/include_exp/typeinfo b/Usermode/Libraries/libc++.so_src/include_exp/typeinfo new file mode 100644 index 00000000..c02d388b --- /dev/null +++ b/Usermode/Libraries/libc++.so_src/include_exp/typeinfo @@ -0,0 +1,35 @@ +/* + * Acess2 C++ Library + * - By John Hodge (thePowersGang) + * + * typeinfo (header) + * - typeid and dynamic_cast + */ +#ifndef _LIBCXX__TYPEINFO_ +#define _LIBCXX__TYPEINFO_ + +namespace std { + +// Type information class +class type_info +{ +public: + virtual ~type_info(); + bool operator==(const type_info &) const; + bool operator!=(const type_info &) const; + bool before(const type_info &) const; + const char* name() const; +private: + type_info (const type_info& rhs); + type_info& operator= (const type_info& rhs); + + // CXX ABI + const char *__type_name; +}; + +}; + +#endif + +// vim: ft=cpp + diff --git a/Usermode/Libraries/libc++.so_src/misc.cc b/Usermode/Libraries/libc++.so_src/misc.cc new file mode 100644 index 00000000..ed0a2eb6 --- /dev/null +++ b/Usermode/Libraries/libc++.so_src/misc.cc @@ -0,0 +1,78 @@ +/* + * Acess2 C++ Library + * - By John Hodge (thePowersGang) + * + * misc.cc + * - Miscelanious functions + */ +#include + +extern "C" int SoMain() +{ + // nope + return 0; +} + +extern "C" void __cxa_pure_virtual() +{ + // dunno +} + +extern "C" void __gxx_personality_v0() +{ + // TODO: Handle __gxx_personality_v0 somehow +} + + +// DSO Support +#define MAX_ATEXIT 32 +static struct { + void (*destructor) (void *); + void *arg; + void *dso_handle; +} __cxa_atexit_funcs[MAX_ATEXIT]; +static int __cxa_atexit_func_count; + +extern "C" int __cxa_atexit(void (*destructor) (void *), void *arg, void *dso_handle) +{ + if( __cxa_atexit_func_count == MAX_ATEXIT ) + { + return 1; + } + + __cxa_atexit_funcs[__cxa_atexit_func_count].destructor = destructor; + __cxa_atexit_funcs[__cxa_atexit_func_count].arg = arg; + __cxa_atexit_funcs[__cxa_atexit_func_count].dso_handle = dso_handle; + __cxa_atexit_func_count ++; + return 0; +} + +extern "C" void __cxa_finalize(void *f) +{ + if( f == 0 ) + { + for( int i = __cxa_atexit_func_count; i --; ) + { + if( __cxa_atexit_funcs[i].dso_handle == f ) + { + __cxa_atexit_funcs[i].destructor(__cxa_atexit_funcs[i].arg); + memmove( + &__cxa_atexit_funcs[i], + &__cxa_atexit_funcs[i+1], + (__cxa_atexit_func_count-i)*sizeof(__cxa_atexit_funcs[0]) + ); + i ++; + __cxa_atexit_func_count --; + } + } + } + else + { + for( int i = __cxa_atexit_func_count; i --; ) + { + __cxa_atexit_funcs[i].destructor(__cxa_atexit_funcs[i].arg); + } + __cxa_atexit_func_count = 0; + } +} + diff --git a/Usermode/Libraries/libc++.so_src/new.cc b/Usermode/Libraries/libc++.so_src/new.cc new file mode 100644 index 00000000..1d09fbc3 --- /dev/null +++ b/Usermode/Libraries/libc++.so_src/new.cc @@ -0,0 +1,31 @@ +/* + * Acess2 C++ Library + * - By John Hodge (thePowersGang) + * + * new.cc + * - new/delete + */ +#include +#include + +// === CODE === +void *operator new( size_t size ) +{ + return malloc( size ); +} + +void *operator new[]( size_t size ) +{ + return malloc( size ); +} + +void operator delete(void *ptr) +{ + free(ptr); +} + +void operator delete[](void *ptr) +{ + free(ptr); +} + diff --git a/Usermode/Libraries/libc++.so_src/typeinfo.cc b/Usermode/Libraries/libc++.so_src/typeinfo.cc new file mode 100644 index 00000000..b0a9b3e1 --- /dev/null +++ b/Usermode/Libraries/libc++.so_src/typeinfo.cc @@ -0,0 +1,50 @@ +/* + * Acess2 C++ Library + * - By John Hodge (thePowersGang) + * + * typeinfo.cc + * - typeid and dynamic_cast + */ +#include + +namespace std { + +type_info::~type_info() +{ + // nop +} + +bool type_info::operator==(const type_info& other) const +{ + return this->__type_name == other.__type_name; +} + +bool type_info::operator!=(const type_info& other) const +{ + return this->__type_name != other.__type_name; +} + +bool type_info::before(const type_info& other) const +{ + return this->__type_name < other.__type_name; +} + +const char *type_info::name() const +{ + return this->__type_name; +} + +// Private +type_info::type_info(const type_info& rhs): + __type_name(rhs.__type_name) +{ +} +type_info& type_info::operator=(const type_info& rhs) +{ + __type_name = rhs.__type_name; + return *this; +} + + +}; // namespace std +