VM: replaced calls to out_of_memory() with fatal_error()
No need for a special out of memory function -- it's just a kind of fatal error. Also make fatal_error() call dump_memory_layout() for easier debugging.db4
parent
cb55fcf20f
commit
7dfb352a7e
|
@ -18,7 +18,8 @@ void fatal_error(const char* msg, cell tagged) {
|
|||
|
||||
std::cout << "fatal_error: " << msg;
|
||||
std::cout << ": " << (void*)tagged;
|
||||
std::cout << std::endl;
|
||||
std::cout << std::endl << std::endl;
|
||||
current_vm()->dump_memory_layout(std::cout);
|
||||
abort();
|
||||
}
|
||||
|
||||
|
@ -30,12 +31,6 @@ void critical_error(const char* msg, cell tagged) {
|
|||
current_vm()->factorbug();
|
||||
}
|
||||
|
||||
void out_of_memory(const char *msg) {
|
||||
std::cout << "Out of memory: " << msg << "\n\n";
|
||||
current_vm()->dump_memory_layout(std::cout);
|
||||
abort();
|
||||
}
|
||||
|
||||
/* Allocates memory */
|
||||
void factor_vm::general_error(vm_error_type error, cell arg1_, cell arg2_) {
|
||||
|
||||
|
|
|
@ -28,7 +28,6 @@ enum vm_error_type {
|
|||
|
||||
void fatal_error(const char* msg, cell tagged);
|
||||
void critical_error(const char* msg, cell tagged);
|
||||
void out_of_memory(const char* msg);
|
||||
void memory_signal_handler_impl();
|
||||
void fp_signal_handler_impl();
|
||||
void synchronous_signal_handler_impl();
|
||||
|
|
|
@ -74,11 +74,6 @@ bool move_file(const vm_char* path1, const vm_char* path2) {
|
|||
return ret == 0;
|
||||
}
|
||||
|
||||
void check_ENOMEM(const char* msg) {
|
||||
if(errno == ENOMEM)
|
||||
out_of_memory(msg);
|
||||
}
|
||||
|
||||
segment::segment(cell size_, bool executable_p) {
|
||||
size = size_;
|
||||
|
||||
|
@ -90,11 +85,12 @@ segment::segment(cell size_, bool executable_p) {
|
|||
else
|
||||
prot = PROT_READ | PROT_WRITE;
|
||||
|
||||
char* array = (char*)mmap(NULL, 2 * pagesize + size, prot,
|
||||
cell alloc_size = 2 * pagesize + size;
|
||||
char* array = (char*)mmap(NULL, alloc_size, prot,
|
||||
MAP_ANON | MAP_PRIVATE, -1, 0);
|
||||
|
||||
if (array == (char*)-1)
|
||||
out_of_memory("mmap");
|
||||
fatal_error("Out of memory in mmap", alloc_size);
|
||||
|
||||
start = (cell)(array + pagesize);
|
||||
end = start + size;
|
||||
|
@ -106,13 +102,11 @@ void segment::set_border_locked(bool locked) {
|
|||
int pagesize = getpagesize();
|
||||
cell lo = start - pagesize;
|
||||
if (!set_memory_locked(lo, pagesize, locked)) {
|
||||
check_ENOMEM("mprotect low");
|
||||
fatal_error("Cannot (un)protect low guard page", lo);
|
||||
}
|
||||
|
||||
cell hi = end;
|
||||
if (!set_memory_locked(hi, pagesize, locked)) {
|
||||
check_ENOMEM("mprotect high");
|
||||
fatal_error("Cannot (un)protect high guard page", hi);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -93,12 +93,12 @@ segment::segment(cell size_, bool executable_p) {
|
|||
size = size_;
|
||||
|
||||
char* mem;
|
||||
|
||||
cell alloc_size = getpagesize() * 2 + size;
|
||||
if ((mem = (char*)VirtualAlloc(
|
||||
NULL, getpagesize() * 2 + size, MEM_COMMIT,
|
||||
NULL, alloc_size, MEM_COMMIT,
|
||||
executable_p ? PAGE_EXECUTE_READWRITE : PAGE_READWRITE)) ==
|
||||
0) {
|
||||
out_of_memory("VirtualAlloc");
|
||||
fatal_error("Out of memory in VirtualAlloc", alloc_size);
|
||||
}
|
||||
|
||||
start = (cell)mem + getpagesize();
|
||||
|
|
Loading…
Reference in New Issue