aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--.gitignore1
-rw-r--r--src/library.js65
-rw-r--r--system/lib/debugging.cpp2
3 files changed, 60 insertions, 8 deletions
diff --git a/.gitignore b/.gitignore
index b40594b6..7a0f2f78 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,4 +1,5 @@
*.diff
*.pyc
*~
+*.bc
diff --git a/src/library.js b/src/library.js
index 56370b79..7036a3f3 100644
--- a/src/library.js
+++ b/src/library.js
@@ -4374,6 +4374,10 @@ LibraryManager.library = {
__cxa_guard_release: function() {},
__cxa_guard_abort: function() {},
+ _ZTVN10__cxxabiv119__pointer_type_infoE: [0], // is a pointer
+ _ZTVN10__cxxabiv117__class_type_infoE: [1], // no inherited classes
+ _ZTVN10__cxxabiv120__si_class_type_infoE: [2], // yes inherited classes
+
// Exceptions
__cxa_allocate_exception: function(size) {
return _malloc(size);
@@ -4383,6 +4387,18 @@ LibraryManager.library = {
},
__cxa_throw__deps: ['llvm_eh_exception', '_ZSt18uncaught_exceptionv', '__cxa_find_matching_catch'],
__cxa_throw: function(ptr, type, destructor) {
+ if (!___cxa_throw.initialized) {
+ try {
+ {{{ makeSetValue('__ZTVN10__cxxabiv119__pointer_type_infoE', '0', '0', 'i32') }}}; // Workaround for libcxxabi integration bug
+ } catch(e){}
+ try {
+ {{{ makeSetValue('__ZTVN10__cxxabiv117__class_type_infoE', '0', '1', 'i32') }}}; // Workaround for libcxxabi integration bug
+ } catch(e){}
+ try {
+ {{{ makeSetValue('__ZTVN10__cxxabiv120__si_class_type_infoE', '0', '2', 'i32') }}}; // Workaround for libcxxabi integration bug
+ } catch(e){}
+ ___cxa_throw.initialized = true;
+ }
#if EXCEPTION_DEBUG
print('Compiled code throwing an exception, ' + [ptr,type,destructor] + ', at ' + new Error().stack);
#endif
@@ -4416,9 +4432,6 @@ LibraryManager.library = {
llvm_eh_typeid_for: function(type) {
return type;
},
- _Unwind_Resume_or_Rethrow: function(ptr) {
- throw ptr;
- },
__cxa_begin_catch__deps: ['_ZSt18uncaught_exceptionv'],
__cxa_begin_catch: function(ptr) {
__ZSt18uncaught_exceptionv.uncaught_exception--;
@@ -4460,6 +4473,15 @@ LibraryManager.library = {
throw exception;
},
+ _Unwind_Resume_or_Rethrow: function(ptr) {
+ throw ptr;
+ },
+ _Unwind_RaiseException__deps: ['llvm_eh_exception', '__cxa_find_matching_catch'],
+ _Unwind_RaiseException: function(ptr) {
+ throw ptr;
+ },
+ _Unwind_DeleteException: function(ptr) {},
+
terminate: '__cxa_call_unexpected',
__gxx_personality_v0: function() {
@@ -4480,7 +4502,13 @@ LibraryManager.library = {
// If throwntype is a pointer, this means a pointer has been
// thrown. When a pointer is thrown, actually what's thrown
// is a pointer to the pointer. We'll dereference it.
- if (throwntype != 0) {
+ var isNumber = false; // Numbers are a simpler case, no need to deref
+ try { if (throwntype == __ZTIi) isNumber = true } catch(e){}
+ try { if (throwntype == __ZTIl) isNumber = true } catch(e){}
+ try { if (throwntype == __ZTIx) isNumber = true } catch(e){}
+ try { if (throwntype == __ZTIf) isNumber = true } catch(e){}
+ try { if (throwntype == __ZTId) isNumber = true } catch(e){}
+ if (throwntype != 0 && !isNumber) {
var throwntypeInfoAddr= {{{ makeGetValue('throwntype', '0', '*') }}} - {{{ Runtime.QUANTUM_SIZE*2 }}};
var throwntypeInfo= {{{ makeGetValue('throwntypeInfoAddr', '0', '*') }}};
if (throwntypeInfo == 0)
@@ -4491,7 +4519,7 @@ LibraryManager.library = {
// type of the thrown object. Find one which matches, and
// return the type of the catch block which should be called.
for (var i = 0; i < typeArray.length; i++) {
- if (___cxa_does_inherit(typeArray[i], throwntype))
+ if (___cxa_does_inherit(typeArray[i], throwntype, thrown))
return { 'f0':thrown, 'f1':typeArray[i]};
}
// Shouldn't happen unless we have bogus data in typeArray
@@ -4503,7 +4531,8 @@ LibraryManager.library = {
// Recursively walks up the base types of 'possibilityType'
// to see if any of them match 'definiteType'.
- __cxa_does_inherit: function(definiteType, possibilityType) {
+ __cxa_does_inherit: function(definiteType, possibilityType, possibility) {
+ if (possibility == 0) return false;
if (possibilityType == 0 || possibilityType == definiteType)
return true;
var possibility_type_infoAddr = {{{ makeGetValue('possibilityType', '0', '*') }}} - {{{ Runtime.QUANTUM_SIZE*2 }}};
@@ -4519,7 +4548,7 @@ LibraryManager.library = {
var defPointerBaseType = {{{ makeGetValue('defPointerBaseAddr', '0', '*') }}};
var possPointerBaseAddr = possibilityType+{{{ Runtime.QUANTUM_SIZE*2 }}};
var possPointerBaseType = {{{ makeGetValue('possPointerBaseAddr', '0', '*') }}};
- return ___cxa_does_inherit(defPointerBaseType, possPointerBaseType);
+ return ___cxa_does_inherit(defPointerBaseType, possPointerBaseType, possibility);
} else
return false; // one pointer and one non-pointer
case 1: // class with no base class
@@ -4527,7 +4556,7 @@ LibraryManager.library = {
case 2: // class with base class
var parentTypeAddr = possibilityType + {{{ Runtime.QUANTUM_SIZE*2 }}};
var parentType = {{{ makeGetValue('parentTypeAddr', '0', '*') }}};
- return ___cxa_does_inherit(definiteType, parentType);
+ return ___cxa_does_inherit(definiteType, parentType, possibility);
default:
return false; // some unencountered type
}
@@ -5884,6 +5913,26 @@ LibraryManager.library = {
return 0;
},
+ pthread_once: function(ptr, func) {
+ if (!_pthread_once.seen) _pthread_once.seen = {};
+ if (ptr in _pthread_once.seen) return;
+ FUNCTION_TABLE[func]();
+ _pthread_once.seen[ptr] = 1;
+ },
+
+ pthread_key_create: function(key, destructor) {
+ if (!_pthread_key_create.keys) _pthread_key_create.keys = {};
+ _pthread_key_create.keys[key] = null;
+ },
+
+ pthread_getspecific: function(key) {
+ return _pthread_key_create.keys[key];
+ },
+
+ pthread_setspecific: function(key, value) {
+ _pthread_key_create.keys[key] = value;
+ },
+
// ==========================================================================
// malloc.h
// ==========================================================================
diff --git a/system/lib/debugging.cpp b/system/lib/debugging.cpp
index ff9e0d68..5dfaf223 100644
--- a/system/lib/debugging.cpp
+++ b/system/lib/debugging.cpp
@@ -18,5 +18,7 @@ void __assert_func(const char *file, int line, const char *assertt, const char *
abort();
}
+//struct _reent *_impure_ptr;
+
}