From 3b951b6151e8836ca90eddd936452b67717bcda5 Mon Sep 17 00:00:00 2001 From: "John Hodge (sonata)" Date: Fri, 26 Dec 2014 18:06:23 +0800 Subject: [PATCH] Usermode/libc++ - cxa_guard behavior fix --- Usermode/Libraries/libc++.so_src/guard.cc | 23 ++++++++++++++++------- 1 file changed, 16 insertions(+), 7 deletions(-) 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(); } -- 2.20.1