提交 82968e19 创建 作者: Nickolai Zeldovich's avatar Nickolai Zeldovich

__cxa_guard_acquire / __cxa_guard_release

上级 49db292c
......@@ -103,7 +103,14 @@ namespace std {
void *operator new[](unsigned long nbytes);
// void operator delete(void *p);
void operator delete[](void *p);
/* Ref: http://sourcery.mentor.com/public/cxx-abi/abi.html */
extern "C" void __cxa_pure_virtual(void);
extern "C" int __cxa_guard_acquire(s64 *guard_object);
extern "C" void __cxa_guard_release(s64 *guard_object);
extern "C" void __cxa_guard_abort(s64 *guard_object);
extern "C" int __cxa_atexit(void (*f)(void *), void *p, void *d);
extern void *__dso_handle;
#define NEW_DELETE_OPS(classname) \
static void* operator new(unsigned long nbytes) { \
......
#include "types.h"
#include "kernel.hh"
#include "cpputil.hh"
#include "spinlock.h"
#include "amd64.h"
void *
operator new[](unsigned long nbytes)
......@@ -24,6 +26,44 @@ __cxa_pure_virtual(void)
panic("__cxa_pure_virtual");
}
int
__cxa_guard_acquire(s64 *guard)
{
volatile u8 *x = (u8*) guard;
volatile u32 *l = (u32*) (x+4);
pushcli();
while (xchg32(l, 1) != 0)
; /* spin */
if (*x) {
xchg32(l, 0);
popcli();
return 0;
}
return 1;
}
void
__cxa_guard_release(s64 *guard)
{
volatile u8 *x = (u8*) guard;
volatile u32 *l = (u32*) (x+4);
*x = 1;
__sync_synchronize();
xchg32(l, 0);
popcli();
}
int
__cxa_atexit(void (*f)(void*), void *p, void *d)
{
return 0;
}
void *__dso_handle;
namespace std {
template<>
......
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论