From e75774c59fb4c1fbf652f8cb29eadef2970b46d9 Mon Sep 17 00:00:00 2001 From: slava Date: Sun, 17 Dec 2006 22:40:21 +0000 Subject: [PATCH] Fix runtime compile warnings; working on native stack traces again --- vm/bignumint.h | 2 +- vm/cpu-amd64.h | 5 ++++- vm/cpu-ppc.h | 3 +++ vm/cpu-x86.h | 8 ++++---- vm/data_gc.c | 2 +- vm/os-linux-ppc.h | 4 ++++ vm/os-macosx-ppc.h | 2 +- vm/platform.h | 6 +++++- vm/run.c | 26 +++++++++++++++++--------- vm/stack.c | 4 ++-- vm/stack.h | 10 +++++----- vm/types.c | 6 +++--- 12 files changed, 50 insertions(+), 28 deletions(-) create mode 100644 vm/os-linux-ppc.h diff --git a/vm/bignumint.h b/vm/bignumint.h index cb6a42b5f7..aacde5d195 100644 --- a/vm/bignumint.h +++ b/vm/bignumint.h @@ -46,7 +46,7 @@ typedef F_FIXNUM bignum_digit_type; typedef F_FIXNUM bignum_length_type; /* BIGNUM_TO_POINTER casts a bignum object to a digit array pointer. */ -#define BIGNUM_TO_POINTER(bignum) ((CELL*)AREF(bignum,0)) +#define BIGNUM_TO_POINTER(bignum) ((bignum_digit_type *)AREF(bignum,0)) /* BIGNUM_EXCEPTION is invoked to handle assertion violations. */ #define BIGNUM_EXCEPTION abort diff --git a/vm/cpu-amd64.h b/vm/cpu-amd64.h index 7e75bdc0e0..99318ab687 100644 --- a/vm/cpu-amd64.h +++ b/vm/cpu-amd64.h @@ -10,5 +10,8 @@ void *native_stack_pointer(void); typedef struct _F_STACK_FRAME { struct _F_STACK_FRAME *previous; - CELL *return_address; + CELL return_address; } F_STACK_FRAME; + +#define PREVIOUS_FRAME(frame) (frame->previous) +#define RETURN_ADDRESS(frame) (frame->return_address) diff --git a/vm/cpu-ppc.h b/vm/cpu-ppc.h index 8d8f2bace3..3e4a0f3214 100644 --- a/vm/cpu-ppc.h +++ b/vm/cpu-ppc.h @@ -7,3 +7,6 @@ register CELL cards_offset asm("r16"); void flush_icache(CELL start, CELL len); void *native_stack_pointer(void); + +#define PREVIOUS_FRAME(frame) (frame->previous) +#define RETURN_ADDRESS(frame) (frame->return_address) diff --git a/vm/cpu-x86.h b/vm/cpu-x86.h index ee0472f9f7..51e511f53f 100644 --- a/vm/cpu-x86.h +++ b/vm/cpu-x86.h @@ -8,7 +8,7 @@ INLINE void flush_icache(CELL start, CELL len) {} void *native_stack_pointer(void); -typedef struct _F_STACK_FRAME { - struct _F_STACK_FRAME *previous; - CELL *return_address; -} F_STACK_FRAME; +typedef CELL F_STACK_FRAME; + +#define PREVIOUS_FRAME(frame) (frame + 1) +#define RETURN_ADDRESS(frame) (*(frame)) diff --git a/vm/data_gc.c b/vm/data_gc.c index bbd0310b11..f11a1c416e 100644 --- a/vm/data_gc.c +++ b/vm/data_gc.c @@ -311,7 +311,7 @@ the user environment and extra roots registered with REGISTER_ROOT */ void collect_roots(void) { int i; - F_STACKS *stacks; + F_CONTEXT *stacks; copy_handle(&T); copy_handle(&bignum_zero); diff --git a/vm/os-linux-ppc.h b/vm/os-linux-ppc.h new file mode 100644 index 0000000000..4dae4c62cf --- /dev/null +++ b/vm/os-linux-ppc.h @@ -0,0 +1,4 @@ +typedef struct _F_STACK_FRAME { + struct _F_STACK_FRAME *previous; + CELL return_address; +} F_STACK_FRAME; diff --git a/vm/os-macosx-ppc.h b/vm/os-macosx-ppc.h index 36706ba8ce..d1ac388a42 100644 --- a/vm/os-macosx-ppc.h +++ b/vm/os-macosx-ppc.h @@ -1,7 +1,7 @@ typedef struct _F_STACK_FRAME { struct _F_STACK_FRAME *previous; CELL padding1; - CELL *return_address; + CELL return_address; CELL padding2; } F_STACK_FRAME; diff --git a/vm/platform.h b/vm/platform.h index 5d125c4535..d892e7c98c 100644 --- a/vm/platform.h +++ b/vm/platform.h @@ -27,7 +27,11 @@ #ifdef __FreeBSD__ #include "os-freebsd.h" #elif defined(linux) - #include "os-linux.h" + #ifdef FACTOR_PPC + #include "os-linux-ppc.h" + #endif + + #include "os-linux.h" #elif defined(__sun) #include "os-solaris.h" #else diff --git a/vm/run.c b/vm/run.c index ca3b476dc9..a247ab9327 100644 --- a/vm/run.c +++ b/vm/run.c @@ -263,19 +263,27 @@ CELL allot_native_stack_trace(void) F_STACK_FRAME *frame = native_stack_pointer(); GROWABLE_ARRAY(array); - while((CELL)frame < (CELL)stack_chain->native_stack_pointer) + while(frame < stack_chain->native_stack_pointer) { - REGISTER_ARRAY(array); - CELL cell = allot_cell((CELL)frame->return_address); - UNREGISTER_ARRAY(array); - GROWABLE_ADD(array,cell); - if((CELL)frame->previous <= (CELL)frame) + CELL return_address = RETURN_ADDRESS(frame); + + if(return_address >= compiling.base + && return_address <= compiling.limit) { - fprintf(stderr,"Factor warning: unusual C stack layout\n"); + REGISTER_ARRAY(array); + CELL cell = allot_cell(return_address); + UNREGISTER_ARRAY(array); + GROWABLE_ADD(array,cell); + } + + if(PREVIOUS_FRAME(frame) <= frame) + { + fprintf(stderr,"*** Unusual C stack layout (why?)\n"); fflush(stderr); break; } - frame = frame->previous; + + frame = PREVIOUS_FRAME(frame); } GROWABLE_TRIM(array); @@ -288,7 +296,7 @@ void throw_error(CELL error, bool keep_stacks) early_error(error); REGISTER_ROOT(error); - thrown_native_stack_trace = F; /* allot_native_stack_trace(); */ + thrown_native_stack_trace = allot_native_stack_trace(); UNREGISTER_ROOT(error); throwing = true; diff --git a/vm/stack.c b/vm/stack.c index d9008beaca..e23e632eb3 100644 --- a/vm/stack.c +++ b/vm/stack.c @@ -43,7 +43,7 @@ void save_stacks(void) /* called on entry into a compiled callback */ void nest_stacks(void) { - F_STACKS *new_stacks = safe_malloc(sizeof(F_STACKS)); + F_CONTEXT *new_stacks = safe_malloc(sizeof(F_CONTEXT)); /* note that these register values are not necessarily valid stack pointers. they are merely saved non-volatile registers, and are @@ -101,7 +101,7 @@ void unnest_stacks(void) extra_roots = stack_chain->extra_roots; - F_STACKS *old_stacks = stack_chain; + F_CONTEXT *old_stacks = stack_chain; stack_chain = old_stacks->next; free(old_stacks); } diff --git a/vm/stack.h b/vm/stack.h index 037a57016f..e5d5395911 100644 --- a/vm/stack.h +++ b/vm/stack.h @@ -1,4 +1,4 @@ -typedef struct _F_STACKS { +typedef struct _F_CONTEXT { /* current datastack top pointer */ CELL data; /* saved contents of ds register on entry to callback */ @@ -35,15 +35,15 @@ typedef struct _F_STACKS { CELL extra_roots; /* C stack pointer on entry */ - void *native_stack_pointer; + F_STACK_FRAME *native_stack_pointer; /* error handler longjmp buffer */ JMP_BUF toplevel; - struct _F_STACKS *next; -} F_STACKS; + struct _F_CONTEXT *next; +} F_CONTEXT; -F_STACKS *stack_chain; +F_CONTEXT *stack_chain; CELL ds_size, rs_size, cs_size; diff --git a/vm/types.c b/vm/types.c index 0e79c08f10..387d12b085 100644 --- a/vm/types.c +++ b/vm/types.c @@ -245,15 +245,15 @@ void primitive_resize_string(void) void primitive_memory_to_##type##_string(void) \ { \ CELL length = unbox_unsigned_cell(); \ - type *string = (type*)unbox_unsigned_cell(); \ + const type *string = (const type*)unbox_unsigned_cell(); \ dpush(tag_object(memory_to_##type##_string(string,length))); \ } \ F_STRING *from_##type##_string(const type *str) \ { \ CELL length = 0; \ - type *scan = str; \ + const type *scan = str; \ while(*scan++) length++; \ - return memory_to_##type##_string((type*)str,length); \ + return memory_to_##type##_string(str,length); \ } \ void box_##type##_string(const type *str) \ { \