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

allocate exception memory from a per-proc bufer, so that we can

handle out-of-memory situations without requiring memory allocation.
上级 d53f7567
......@@ -85,6 +85,9 @@ struct proc : public rcu_freed {
int uaccess_;
u8 __cxa_eh_global[16];
std::atomic<int> exception_inuse;
u8 exception_buf[256];
static proc* alloc();
void set_state(procstate_t s);
procstate_t get_state(void) const { return state_; }
......
......@@ -149,6 +149,7 @@ namespace __cxxabiv1 {
static char malloc_buf[65536];
static std::atomic<size_t> malloc_idx;
static bool malloc_proc = false;
extern "C" void* malloc(size_t);
void*
......@@ -161,6 +162,12 @@ malloc(size_t n)
return &malloc_buf[myoff];
}
if (malloc_proc) {
assert(n <= sizeof(myproc()->exception_buf));
assert(cmpxch(&myproc()->exception_inuse, 0, 1));
return myproc()->exception_buf;
}
u64* p = (u64*) kmalloc(n+8, "cpprt malloc");
*p = n;
return p+1;
......@@ -173,6 +180,11 @@ free(void* vp)
if (vp >= malloc_buf && vp < malloc_buf + sizeof(malloc_buf))
return;
if (vp == myproc()->exception_buf) {
myproc()->exception_inuse = 0;
return;
}
u64* p = (u64*) vp;
kmfree(p-1, p[-1]+8);
}
......@@ -217,6 +229,7 @@ initcpprt(void)
throw 5;
} catch (int& x) {
assert(x == 5);
malloc_proc = true;
return;
}
......
......@@ -43,7 +43,7 @@ proc::proc(int npid) :
ftable(0), cwd(0), tsc(0), curcycles(0), cpuid(0), epoch(0),
cpu_pin(0), runq(0), oncv(0), cv_wakeup(0),
user_fs_(0), unmap_tlbreq_(0), in_exec_(0), uaccess_(0),
state_(EMBRYO)
exception_inuse(0), state_(EMBRYO)
{
snprintf(lockname, sizeof(lockname), "cv:proc:%d", pid);
initlock(&lock, lockname+3, LOCKSTAT_PROC);
......
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论