diff options
author | anonymous <local@localhost> | 2010-08-13 14:47:47 +0000 |
---|---|---|
committer | anonymous <local@localhost> | 2010-08-13 14:47:47 +0000 |
commit | 0b2ee73455bbfa4c5131c95f8b195d12d19ccb04 (patch) | |
tree | 650080e9afe7ce3bbb6af3829ed645495dc08cb4 /src | |
parent | 23725157c815e3fccfca988317624d7b0896e932 (diff) | |
parent | 44b2f6d2bf4a1c7695651a908b392a5c3faf6190 (diff) | |
download | libcxxrt-0b2ee73455bbfa4c5131c95f8b195d12d19ccb04.tar.gz libcxxrt-0b2ee73455bbfa4c5131c95f8b195d12d19ccb04.tar.bz2 libcxxrt-0b2ee73455bbfa4c5131c95f8b195d12d19ccb04.tar.xz |
Merge branch 'master' of github.com:pathscale/libcxxrt
Diffstat (limited to 'src')
-rw-r--r-- | src/CMakeLists.txt | 22 | ||||
-rw-r--r-- | src/Makefile | 12 | ||||
-rw-r--r-- | src/aux.cc | 13 | ||||
-rw-r--r-- | src/dwarf_eh.h | 2 | ||||
-rw-r--r-- | src/exception.cc | 13 | ||||
-rw-r--r-- | src/memory.cc | 23 | ||||
-rw-r--r-- | src/stdexcept.cc | 80 | ||||
-rw-r--r-- | src/stdexcept.h | 56 |
8 files changed, 220 insertions, 1 deletions
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt new file mode 100644 index 0000000..d30da28 --- /dev/null +++ b/src/CMakeLists.txt @@ -0,0 +1,22 @@ + +set(CXXRT_SOURCES + dynamic_cast.cc + exception.cc + guard.cc + terminate.cc + typeinfo.cc + stdexcept.cc + memory.cc + aux.cc + ) + + +add_library(cxxrt-static STATIC ${CXXRT_SOURCES}) +add_library(cxxrt-shared SHARED ${CXXRT_SOURCES}) + +set_target_properties(cxxrt-static cxxrt-shared PROPERTIES + OUTPUT_NAME "cxxrt" + ) + + + diff --git a/src/Makefile b/src/Makefile index d8240a7..499a05c 100644 --- a/src/Makefile +++ b/src/Makefile @@ -1,4 +1,5 @@ -OBJECTS = typeinfo.o exception.o dynamic_cast.o terminate.o guard.o +OBJECTS = typeinfo.o exception.o dynamic_cast.o terminate.o guard.o \ + stdexcept.o memory.o aux.o # Needed for building the shared library CXXFLAGS = -fPIC @@ -20,10 +21,16 @@ LDFLAGS += -L/usr/local/lib -L. -lpthread -fexceptions PRODUCTS = libcxxabi.so.1 +all: libcxxabi.so.1 libcxxabi.a + libcxxabi.so.1: $(OBJECTS) @echo Linking $@... @gcc -fexception -shared $(OBJECTS) $(LDFLAGS) -o libcxxabi.so.1 #-lunwind +libcxxabi.a: $(OBJECTS) + @ar cr libcxxabi.a $(OBJECTS) + + .cc.o: @echo Compiling $<... @$(CXX) $(CPPFLAGS) $(CXXFLAGS) -c -o $@ $< @@ -38,3 +45,6 @@ exception.o: exception.cc typeinfo.h abi_namespace.h typeinfo dwarf_eh.h guard.o: guard.cc terminate.o: terminate.cc typeinfo.o: typeinfo.cc typeinfo.h abi_namespace.h typeinfo +stdexcept.o: stdexcept.cc stdexcept.h +memory.o: memory.cc stdexcept.h +aux.o: aux.cc stdexcept.h diff --git a/src/aux.cc b/src/aux.cc new file mode 100644 index 0000000..c1590e5 --- /dev/null +++ b/src/aux.cc @@ -0,0 +1,13 @@ + +#include "stdexcept.h" + +extern "C" void __cxa_bad_cast() +{ + throw std::bad_cast(); +} + +extern "C" void __cxa_bad_typeid() +{ + throw std::bad_typeid(); +} + diff --git a/src/dwarf_eh.h b/src/dwarf_eh.h index 1ab25db..02b9db9 100644 --- a/src/dwarf_eh.h +++ b/src/dwarf_eh.h @@ -11,6 +11,8 @@ # include <unwind.h> #endif +#include <stdint.h> + typedef unsigned char *dw_eh_ptr_t; // Flag indicating a signed quantity #define DW_EH_PE_signed 0x08 diff --git a/src/exception.cc b/src/exception.cc index ce06435..5b2c011 100644 --- a/src/exception.cc +++ b/src/exception.cc @@ -7,6 +7,11 @@ #include "typeinfo.h" #include "dwarf_eh.h" + +namespace std { + void unexpected(); +} + /** * Class of exceptions to distinguish between this and other exception types. * @@ -753,7 +758,11 @@ extern "C" _Unwind_Reason_Code __gxx_personality_v0(int version, * pointer to the caught exception, which is either the adjusted pointer (for * C++ exceptions) of the unadjusted pointer (for foreign exceptions). */ +#if __GNUC_MINOR__ > 2 +extern "C" void *__cxa_begin_catch(void *e) throw() +#else extern "C" void *__cxa_begin_catch(void *e) +#endif { // Decrement the uncaught exceptions count __cxa_eh_globals *globals = __cxa_get_globals(); @@ -877,5 +886,9 @@ namespace std } terminate(); } + bool uncaught_exception() throw() { + __cxa_thread_info *info = thread_info(); + return info->globals.uncaughtExceptions != 0; + } } diff --git a/src/memory.cc b/src/memory.cc new file mode 100644 index 0000000..de4bc0c --- /dev/null +++ b/src/memory.cc @@ -0,0 +1,23 @@ + + +// This file contains definition of C++ new/delete operators + + +#include <stddef.h> +#include <malloc.h> +#include "stdexcept.h" + +void * operator new(size_t size) { + void * mem = malloc(size); + if(mem == NULL) { + throw std::bad_alloc(); + } + + return mem; +} + + +void operator delete(void * ptr) { + free(ptr); +} + diff --git a/src/stdexcept.cc b/src/stdexcept.cc new file mode 100644 index 0000000..3d4e086 --- /dev/null +++ b/src/stdexcept.cc @@ -0,0 +1,80 @@ + +#include "stdexcept.h" + +namespace std { + + +exception::exception() throw() { +} + +exception::exception(const exception&) throw() { +} + +exception& exception::operator=(const exception&) throw() { + return *this; +} + +exception::~exception() { +} + +const char* exception::what() const throw() { + return 0; +} + + +bad_alloc::bad_alloc() throw() { +} + +bad_alloc::bad_alloc(const bad_alloc&) throw() { +} + +bad_alloc& bad_alloc::operator=(const bad_alloc&) throw() { + return *this; +} + +bad_alloc::~bad_alloc() { +} + +const char* bad_alloc::what() const throw() { + return "cxxrt::bad_alloc"; +} + + + +bad_cast::bad_cast() throw() { +} + +bad_cast::bad_cast(const bad_cast&) throw() { +} + +bad_cast& bad_cast::operator=(const bad_cast&) throw() { + return *this; +} + +bad_cast::~bad_cast() { +} + +const char* bad_cast::what() const throw() { + return "std::bad_cast"; +} + + +bad_typeid::bad_typeid() throw() { +} + +bad_typeid::bad_typeid(const bad_typeid &__rhs) throw() { +} + +bad_typeid::~bad_typeid() { +} + +bad_typeid& bad_typeid::operator=(const bad_typeid &__rhs) throw() { + return *this; +} + +const char* bad_typeid::what() const throw() { + return "std::bad_typeid"; +} + +} + diff --git a/src/stdexcept.h b/src/stdexcept.h new file mode 100644 index 0000000..af06bda --- /dev/null +++ b/src/stdexcept.h @@ -0,0 +1,56 @@ + + +// This header defines standard exception classes which are needed +// for implementing new/delete operators + + +#ifndef __LIBCXXSUP_STDEXCEPT_H__ +#define __LIBCXXSUP_STDEXCEPT_H__ + +namespace std { + +class exception { +public: + exception() throw(); + exception(const exception&) throw(); + exception& operator=(const exception&) throw(); + virtual ~exception(); + virtual const char* what() const throw(); +}; + + +class bad_alloc: public exception { +public: + bad_alloc() throw(); + bad_alloc(const bad_alloc&) throw(); + bad_alloc& operator=(const bad_alloc&) throw(); + ~bad_alloc(); + virtual const char* what() const throw(); +}; + + +class bad_cast: public exception { +public: + bad_cast() throw(); + bad_cast(const bad_cast&) throw(); + bad_cast& operator=(const bad_cast&) throw(); + virtual ~bad_cast(); + virtual const char* what() const throw(); +}; + + +class bad_typeid: public exception { +public: + bad_typeid() throw(); + bad_typeid(const bad_typeid &__rhs) throw(); + virtual ~bad_typeid(); + bad_typeid& operator=(const bad_typeid &__rhs) throw(); + virtual const char* what() const throw(); +}; + + + +} // namespace std + +#endif // __LIBCXXSUP_STDEXCEPT_H__ + |