exit(1);
}
-void factorvm::fatal_error(const char* msg, cell tagged)
+void fatal_error(const char* msg, cell tagged)
{
print_string("fatal_error: "); print_string(msg);
print_string(": "); print_cell_hex(tagged); nl();
PRIMITIVE(call_clear);
PRIMITIVE(unimplemented);
+void fatal_error(const char* msg, cell tagged);
void memory_signal_handler_impl();
void fp_signal_handler_impl();
void misc_signal_handler_impl();
/* Allocate a port on which the thread shall listen for exceptions. */
if (mach_port_allocate (self, MACH_PORT_RIGHT_RECEIVE, &our_exception_port)
!= KERN_SUCCESS)
- vm->fatal_error("mach_port_allocate() failed",0);
+ fatal_error("mach_port_allocate() failed",0);
/* See http://web.mit.edu/darwin/src/modules/xnu/osfmk/man/mach_port_insert_right.html. */
if (mach_port_insert_right (self, our_exception_port, our_exception_port,
MACH_MSG_TYPE_MAKE_SEND)
!= KERN_SUCCESS)
- vm->fatal_error("mach_port_insert_right() failed",0);
+ fatal_error("mach_port_insert_right() failed",0);
/* The exceptions we want to catch. */
mask = EXC_MASK_BAD_ACCESS | EXC_MASK_ARITHMETIC;
if (task_set_exception_ports (self, mask, our_exception_port,
EXCEPTION_DEFAULT, MACHINE_THREAD_STATE)
!= KERN_SUCCESS)
- vm->fatal_error("task_set_exception_ports() failed",0);
+ fatal_error("task_set_exception_ports() failed",0);
}
}
const char *iter = path;
while(*iter) { len++; iter++; }
- char *new_path = (char *)vm->safe_malloc(PATH_MAX + SUFFIX_LEN + 1);
+ char *new_path = (char *)safe_malloc(PATH_MAX + SUFFIX_LEN + 1);
memcpy(new_path,path,len + 1);
memcpy(new_path + len,SUFFIX,SUFFIX_LEN + 1);
return new_path;
/* Snarfed from SBCL linux-so.c. You must free() this yourself. */
const char *vm_executable_path()
{
- char *path = (char *)vm->safe_malloc(PATH_MAX + 1);
+ char *path = (char *)safe_malloc(PATH_MAX + 1);
int size = readlink("/proc/self/exe", path, PATH_MAX);
if (size < 0)
{
- vm->fatal_error("Cannot read /proc/self/exe",0);
+ fatal_error("Cannot read /proc/self/exe",0);
return NULL;
}
else
{
path[size] = '\0';
- return vm->safe_strdup(path);
+ return safe_strdup(path);
}
}
pthread_attr_t attr;
pthread_t thread;
if (pthread_attr_init (&attr) != 0)
- vm->fatal_error("pthread_attr_init() failed",0);
+ fatal_error("pthread_attr_init() failed",0);
if (pthread_attr_setdetachstate (&attr, PTHREAD_CREATE_DETACHED) != 0)
- vm->fatal_error("pthread_attr_setdetachstate() failed",0);
+ fatal_error("pthread_attr_setdetachstate() failed",0);
if (pthread_create (&thread, &attr, start_routine, args) != 0)
- vm->fatal_error("pthread_create() failed",0);
+ fatal_error("pthread_create() failed",0);
pthread_attr_destroy (&attr);
return (void*)thread;
}
vm->out_of_memory();
if(mprotect(array,pagesize,PROT_NONE) == -1)
- vm->fatal_error("Cannot protect low guard page",(cell)array);
+ fatal_error("Cannot protect low guard page",(cell)array);
if(mprotect(array + pagesize + size,pagesize,PROT_NONE) == -1)
- vm->fatal_error("Cannot protect high guard page",(cell)array);
+ fatal_error("Cannot protect high guard page",(cell)array);
- segment *retval = (segment *)vm->safe_malloc(sizeof(segment));
+ segment *retval = (segment *)safe_malloc(sizeof(segment));
retval->start = (cell)(array + pagesize);
retval->size = size;
pagesize + block->size + pagesize);
if(retval)
- vm->fatal_error("dealloc_segment failed",0);
+ fatal_error("dealloc_segment failed",0);
free(block);
}
while(ret == -1 && errno == EINTR);
if(ret == -1)
- vm->fatal_error("sigaction failed", 0);
+ fatal_error("sigaction failed", 0);
}
void unix_init_signals()
void safe_close(int fd)
{
if(close(fd) < 0)
- vm->fatal_error("error closing fd",errno);
+ fatal_error("error closing fd",errno);
}
bool check_write(int fd, void *data, ssize_t size)
void safe_write(int fd, void *data, ssize_t size)
{
if(!check_write(fd,data,size))
- vm->fatal_error("error writing fd",errno);
+ fatal_error("error writing fd",errno);
}
bool safe_read(int fd, void *data, ssize_t size)
return safe_read(fd,data,size);
else
{
- vm->fatal_error("error reading fd",errno);
+ fatal_error("error reading fd",errno);
return false;
}
}
break;
if(buf[0] != 'X')
- vm->fatal_error("stdin_loop: bad data on control fd",buf[0]);
+ fatal_error("stdin_loop: bad data on control fd",buf[0]);
for(;;)
{
int filedes[2];
if(pipe(filedes) < 0)
- vm->fatal_error("Error opening control pipe",errno);
+ fatal_error("Error opening control pipe",errno);
control_read = filedes[0];
control_write = filedes[1];
if(pipe(filedes) < 0)
- vm->fatal_error("Error opening size pipe",errno);
+ fatal_error("Error opening size pipe",errno);
size_read = filedes[0];
size_write = filedes[1];
if(pipe(filedes) < 0)
- vm->fatal_error("Error opening stdin pipe",errno);
+ fatal_error("Error opening stdin pipe",errno);
stdin_read = filedes[0];
stdin_write = filedes[1];
if(errno == EINTR)
wait_for_stdin();
else
- vm->fatal_error("Error writing control fd",errno);
+ fatal_error("Error writing control fd",errno);
}
}
{
/* If memory allocation fails, bail out */
-void *factorvm::safe_malloc(size_t size)
+void *safe_malloc(size_t size)
{
void *ptr = malloc(size);
if(!ptr) fatal_error("Out of memory in safe_malloc", 0);
return ptr;
}
-vm_char *factorvm::safe_strdup(const vm_char *str)
+vm_char *safe_strdup(const vm_char *str)
{
vm_char *ptr = STRDUP(str);
if(!ptr) fatal_error("Out of memory in safe_strdup", 0);
/* We don't use printf directly, because format directives are not portable.
Instead we define the common cases here. */
-void factorvm::nl()
+void nl()
{
fputs("\n",stdout);
}
-void factorvm::print_string(const char *str)
+void print_string(const char *str)
{
fputs(str,stdout);
}
-void factorvm::print_cell(cell x)
+void print_cell(cell x)
{
printf(CELL_FORMAT,x);
}
-void factorvm::print_cell_hex(cell x)
+void print_cell_hex(cell x)
{
printf(CELL_HEX_FORMAT,x);
}
-void factorvm::print_cell_hex_pad(cell x)
+void print_cell_hex_pad(cell x)
{
printf(CELL_HEX_PAD_FORMAT,x);
}
-void factorvm::print_fixnum(fixnum x)
+void print_fixnum(fixnum x)
{
printf(FIXNUM_FORMAT,x);
}
-cell factorvm::read_cell_hex()
+cell read_cell_hex()
{
cell cell;
if(scanf(CELL_HEX_FORMAT,&cell) < 0) exit(1);
namespace factor
{
-
+ void *safe_malloc(size_t size);
+ vm_char *safe_strdup(const vm_char *str);
+ void print_string(const char *str);
+ void nl();
+ void print_cell(cell x);
+ void print_cell_hex(cell x);
+ void print_cell_hex_pad(cell x);
+ void print_fixnum(fixnum x);
+ cell read_cell_hex();
}
unsigned int signal_fpu_status;
stack_frame *signal_callstack_top;
void out_of_memory();
- void fatal_error(const char* msg, cell tagged);
void critical_error(const char* msg, cell tagged);
void throw_error(cell error, stack_frame *callstack_top);
void not_implemented_error();
void factor_yield();
void factor_sleep(long us);
- //utilities
- void *safe_malloc(size_t size);
- vm_char *safe_strdup(const vm_char *str);
- void nl();
- void print_string(const char *str);
- void print_cell(cell x);
- void print_cell_hex(cell x);
- void print_cell_hex_pad(cell x);
- void print_fixnum(fixnum x);
- cell read_cell_hex();
-
-
-
-
// os-*
inline void vmprim_existsp();
long thread_id();