From: John Hodge (sonata) Date: Fri, 26 Dec 2014 10:06:23 +0000 (+0800) Subject: Usermode/libc++ - cxa_guard behavior fix X-Git-Url: https://git.ucc.asn.au/?a=commitdiff_plain;h=3b951b6151e8836ca90eddd936452b67717bcda5;p=tpg%2Facess2.git Usermode/libc++ - cxa_guard behavior fix --- diff --git a/Usermode/Libraries/libc++.so_src/guard.cc b/Usermode/Libraries/libc++.so_src/guard.cc index a075a7b6..6468a676 100644 --- a/Usermode/Libraries/libc++.so_src/guard.cc +++ b/Usermode/Libraries/libc++.so_src/guard.cc @@ -6,24 +6,33 @@ * - One-time construction API */ #include +#include +#include + +#define FLAG_INIT_COMPLETE (1<<0) +#define FLAG_INIT_LOCKED (1<<1) extern "C" int __cxa_guard_acquire ( int64_t *guard_object ) { // TODO: Mutex! - if( *guard_object ) - return 1; - *guard_object = 1; - return 0; + if( *guard_object == FLAG_INIT_COMPLETE ) + return 0; + if( *guard_object == FLAG_INIT_LOCKED ) { + _SysDebug("ERROR: __cxa_guard_acquire - nested"); + } + *guard_object = FLAG_INIT_LOCKED; + return 1; } extern "C" void __cxa_guard_release ( int64_t *guard_object ) { - *guard_object = 0; + *guard_object = FLAG_INIT_COMPLETE; } extern "C" void __cxa_guard_abort ( int64_t *guard_object ) { - *guard_object = 0; - // TODO: abort + *guard_object = FLAG_INIT_COMPLETE; + _SysDebug("__cxa_guard_abort"); + abort(); }