From 10d10ac087ddf9393d0c086b90e7af8397fc9c55 Mon Sep 17 00:00:00 2001 From: toy <toy> Date: Fri, 24 Oct 2003 04:29:14 +0000 Subject: [PATCH] Add support for x86 heap-overflow checking. * x86-assem.S (multiple_value_return): Add new functions to handle heap overflow warnings and errors. * x86-arch.c (sigtrap_handler): Add cases for the two new heap overflow traps. * interrupt.c (interrupt_handle_space_overflow): Add support for x86. * parms.lisp (static-symbols): Add new static symbols for heap overflow checking. Add new trap types for heap overflow checking. --- compiler/x86/parms.lisp | 12 ++++++++++-- lisp/interrupt.c | 9 +++++++-- lisp/x86-arch.c | 14 +++++++++++++- lisp/x86-assem.S | 25 ++++++++++++++++++++++++- 4 files changed, 54 insertions(+), 6 deletions(-) diff --git a/compiler/x86/parms.lisp b/compiler/x86/parms.lisp index 88095da5b..216e44963 100644 --- a/compiler/x86/parms.lisp +++ b/compiler/x86/parms.lisp @@ -7,7 +7,7 @@ ;;; Scott Fahlman or slisp-group@cs.cmu.edu. ;;; (ext:file-comment - "$Header: /Volumes/share2/src/cmucl/cvs2git/cvsroot/src/compiler/x86/parms.lisp,v 1.25 2003/09/26 15:37:11 toy Exp $") + "$Header: /Volumes/share2/src/cmucl/cvs2git/cvsroot/src/compiler/x86/parms.lisp,v 1.26 2003/10/24 04:29:14 toy Exp $") ;;; ;;; ********************************************************************** ;;; @@ -197,6 +197,8 @@ (export '(halt-trap pending-interrupt-trap error-trap cerror-trap breakpoint-trap function-end-breakpoint-trap single-step-breakpoint-trap + dynamic-space-overflow-error-trap + dynamic-space-overflow-warning-trap object-not-list-trap object-not-instance-trap trace-table-normal trace-table-call-site trace-table-function-prologue trace-table-function-epilogue)) @@ -208,7 +210,10 @@ cerror breakpoint function-end-breakpoint - single-step-breakpoint) + single-step-breakpoint + dynamic-space-overflow-warning + dynamic-space-overflow-error + ) (defenum (:prefix object-not- :suffix -trap :start 16) list @@ -256,6 +261,8 @@ kernel::internal-error #+stack-checking kernel::yellow-zone-hit #+stack-checking kernel::red-zone-hit + #+heap-overflow-check kernel::dynamic-space-overflow-warning-hit + #+heap-overflow-check kernel::dynamic-space-overflow-error-hit di::handle-breakpoint lisp::fdefinition-object @@ -311,6 +318,7 @@ ;; Spare symbols. Rename these when you need to add some static ;; symbols and don't want to do a cross-compile. + spare-9 spare-8 spare-7 spare-6 diff --git a/lisp/interrupt.c b/lisp/interrupt.c index 3eda3821a..d8e1a6dfa 100644 --- a/lisp/interrupt.c +++ b/lisp/interrupt.c @@ -1,4 +1,4 @@ -/* $Header: /Volumes/share2/src/cmucl/cvs2git/cvsroot/src/lisp/interrupt.c,v 1.31 2003/10/24 02:57:00 toy Exp $ */ +/* $Header: /Volumes/share2/src/cmucl/cvs2git/cvsroot/src/lisp/interrupt.c,v 1.32 2003/10/24 04:29:14 toy Exp $ */ /* Interrupt handing magic. */ @@ -633,7 +633,11 @@ unsigned long install_handler(int signal, void interrupt_handle_space_overflow(lispobj error, struct sigcontext *context) { - +#ifdef i386 + /* ECX is the argument count. */ + context->sc_eip = (int) ((struct function *) PTR (error))->code; + context->sc_ecx = 0; +#elif build_fake_control_stack_frame (context); /* This part should be common to all non-x86 ports */ SC_PC(context) = (long) ((struct function *) PTR (error))->code; @@ -643,6 +647,7 @@ interrupt_handle_space_overflow(lispobj error, struct sigcontext *context) SC_REG(context, reg_CFP) = (long) current_control_frame_pointer; /* This is sparc specific */ SC_REG(context, reg_CODE) = ((long) PTR(error)) + type_FunctionPointer; +#endif } void interrupt_init(void) diff --git a/lisp/x86-arch.c b/lisp/x86-arch.c index a3d03951a..3be564896 100644 --- a/lisp/x86-arch.c +++ b/lisp/x86-arch.c @@ -1,6 +1,6 @@ /* x86-arch.c -*- Mode: C; comment-column: 40 -*- * - * $Header: /Volumes/share2/src/cmucl/cvs2git/cvsroot/src/lisp/x86-arch.c,v 1.19 2002/11/02 23:47:28 toy Exp $ + * $Header: /Volumes/share2/src/cmucl/cvs2git/cvsroot/src/lisp/x86-arch.c,v 1.20 2003/10/24 04:29:14 toy Exp $ * */ @@ -278,6 +278,18 @@ void sigtrap_handler(HANDLER_ARGS) context->sc_pc = (int) handle_function_end_breakpoint(signal, code, context); break; +#ifdef trap_DynamicSpaceOverflowWarning + case trap_DynamicSpaceOverflowWarning: + interrupt_handle_space_overflow(SymbolFunction(DYNAMIC_SPACE_OVERFLOW_WARNING_HIT), + context); + break; +#endif +#ifdef trap_DynamicSpaceOverflowError + case trap_DynamicSpaceOverflowError: + interrupt_handle_space_overflow(SymbolFunction(DYNAMIC_SPACE_OVERFLOW_ERROR_HIT), + context); + break; +#endif default: DPRINTF(0,(stderr,"[C--trap default %d %d %x]\n", signal, code,context)); #ifdef __linux__ diff --git a/lisp/x86-assem.S b/lisp/x86-assem.S index b307bc142..5581f9ea4 100644 --- a/lisp/x86-assem.S +++ b/lisp/x86-assem.S @@ -1,6 +1,6 @@ ### x86-assem.S -*- Mode: Asm; -*- /** - * $Header: /Volumes/share2/src/cmucl/cvs2git/cvsroot/src/lisp/x86-assem.S,v 1.23 2002/08/28 13:29:25 pmai Exp $ + * $Header: /Volumes/share2/src/cmucl/cvs2git/cvsroot/src/lisp/x86-assem.S,v 1.24 2003/10/24 04:29:14 toy Exp $ * * Authors: Paul F. Werkowski <pw@snoopy.mv.com> * Douglas T. Crosher @@ -327,6 +327,29 @@ GNAME(do_pending_interrupt): .byte trap_PendingInterrupt ret .size GNAME(do_pending_interrupt),.-GNAME(do_pending_interrupt) + +#ifdef trap_DynamicSpaceOverflowError + .global GNAME(do_dynamic_space_overflow_error) + .type GNAME(do_dynamic_space_overflow_error),@function + .align align_4byte,0x90 +GNAME(do_dynamic_space_overflow_error): + int3 + .byte trap_DynamicSpaceOverflowError + ret + .size GNAME(do_dynamic_space_overflow_error),.-GNAME(do_dynamic_space_overflow_error) +#endif + +#ifdef trap_DynamicSpaceOverflowWarning + .global GNAME(do_dynamic_space_overflow_warning) + .type GNAME(do_dynamic_space_overflow_warning),@function + .align align_4byte,0x90 +GNAME(do_dynamic_space_overflow_warning): + int3 + .byte trap_DynamicSpaceOverflowWarning + ret + .size GNAME(do_dynamic_space_overflow_warning),.-GNAME(do_dynamic_space_overflow_warning) +#endif + #ifdef WANT_CGC /* A copy function optimized for the Pentium and works ok on -- GitLab