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

seemingly working c++ exception support

上级 53d7ac6f
......@@ -236,3 +236,8 @@ loadgdt:
movw %ax, %gs
ret
.section .eh_frame
.globl __EH_FRAME_BEGIN__
__EH_FRAME_BEGIN__:
......@@ -143,10 +143,20 @@ namespace __cxxabiv1 {
void (*__unexpected_handler)() = cxx_unexpected;
};
static char malloc_buf[65536];
static std::atomic<size_t> malloc_idx;
extern "C" void* malloc(size_t);
void*
malloc(size_t n)
{
if (n > PGSIZE) {
// libgcc_eh needs to allocate a large chunk of memory once
size_t myoff = atomic_fetch_add(&malloc_idx, n);
assert(myoff + n <= sizeof(malloc_buf));
return &malloc_buf[myoff];
}
u64* p = (u64*) kmalloc(n+8, "cpprt malloc");
*p = n;
return p+1;
......@@ -156,6 +166,9 @@ extern "C" void free(void*);
void
free(void* vp)
{
if (vp >= malloc_buf && vp < malloc_buf + sizeof(malloc_buf))
return;
u64* p = (u64*) vp;
kmfree(p-1, p[-1]+8);
}
......@@ -210,3 +223,11 @@ __cxa_get_globals_fast(void)
{
return myproc()->__cxa_eh_global;
}
extern "C" void __register_frame(u8*);
void
initcpprt(void)
{
extern u8 __EH_FRAME_BEGIN__[];
__register_frame(__EH_FRAME_BEGIN__);
}
......@@ -37,6 +37,7 @@ void initlockstat(void);
void initwq(void);
void initsperf(void);
void initidle(void);
void initcpprt(void);
void idleloop(void);
static volatile int bstate;
......@@ -131,6 +132,7 @@ cmain(u64 mbmagic, u64 mbaddr)
bootothers(); // start other processors
kpml4.e[0] = 0; // don't need 1 GB identity mapping anymore
lcr3(rcr3());
initcpprt();
idleloop();
......
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论