Changeset 11947


Ignore:
Timestamp:
Apr 13, 2009, 2:23:02 AM (10 years ago)
Author:
gz
Message:

Signal a lisp condition rather than dropping into the kernel debugger for more cases of memory faults (r11886:r11897 from trunk)

Location:
branches/working-0711/ccl
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • branches/working-0711/ccl/level-1/l1-error-system.lisp

    r11811 r11947  
    9191             (with-slots (address write-p) c
    9292               (format s "Fault during ~a memory address #x~x" (if write-p "write to" "read of") address)))))
    93  
     93
     94(define-condition invalid-memory-operation (storage-condition)
     95  ()
     96  (:report (lambda (c s)
     97             (declare (ignore c))
     98             (format s "Invalid memory operation."))))
     99
     100
    94101(define-condition type-error (error)
    95102  ((datum :initarg :datum)
  • branches/working-0711/ccl/level-1/x86-trap-support.lisp

    r11412 r11947  
    430430                        :void))))
    431431          ((= signal #+win32-target 10 #-win32-target #$SIGBUS)
    432            (%error (make-condition 'invalid-memory-access
    433                     :address addr
    434                     :write-p (not (zerop code)))
    435                    ()
    436                    frame-ptr))))
     432           (if (= code -1)
     433             (%error (make-condition 'invalid-memory-operation)
     434                     ()
     435                     frame-ptr)
     436             (%error (make-condition 'invalid-memory-access
     437                                     :address addr
     438                                     :write-p (not (zerop code)))
     439                     ()
     440                     frame-ptr)))))
    437441  0)
    438442
  • branches/working-0711/ccl/lisp-kernel/x86-exceptions.c

    r11660 r11947  
    798798#endif
    799799#endif
    800 
    801 
    802   if (addr && (addr == tcr->safe_ref_address)) {
    803     xpGPR(xp,Iimm0) = 0;
    804     xpPC(xp) = xpGPR(xp,Ira0);
    805     return true;
    806   } else {
    807     protected_area *a = find_protected_area(addr);
    808     protection_handler *handler;
    809 
    810     if (a) {
    811       handler = protection_handlers[a->why];
    812       return handler(xp, a, addr);
     800  Boolean valid = IS_PAGE_FAULT(info,xp);
     801
     802  if (valid) {
     803    if (addr && (addr == tcr->safe_ref_address)) {
     804      xpGPR(xp,Iimm0) = 0;
     805      xpPC(xp) = xpGPR(xp,Ira0);
     806      return true;
    813807    } else {
    814       if ((addr >= readonly_area->low) &&
    815           (addr < readonly_area->active)) {
    816         UnProtectMemory((LogicalAddress)(truncate_to_power_of_2(addr,log2_page_size)),
    817                         page_size);
    818         return true;
     808      protected_area *a = find_protected_area(addr);
     809      protection_handler *handler;
     810     
     811      if (a) {
     812        handler = protection_handlers[a->why];
     813        return handler(xp, a, addr);
     814      } else {
     815        if ((addr >= readonly_area->low) &&
     816            (addr < readonly_area->active)) {
     817          UnProtectMemory((LogicalAddress)(truncate_to_power_of_2(addr,log2_page_size)),
     818                          page_size);
     819          return true;
     820        }
    819821      }
    820822    }
     
    826828      (header_subtag(header_of(cmain)) == subtag_macptr)) {
    827829      xcf = create_exception_callback_frame(xp, tcr);
    828       callback_to_lisp(tcr, cmain, xp, xcf, SIGBUS, is_write_fault(xp,info), (natural)addr, 0);
     830      callback_to_lisp(tcr, cmain, xp, xcf, SIGBUS, valid ? is_write_fault(xp,info) : (natural)-1, valid ? (natural)addr : 0, 0);
    829831    }
    830832  }
  • branches/working-0711/ccl/lisp-kernel/x86-exceptions.h

    r11412 r11947  
    162162#ifdef LINUX
    163163#define SIGNUM_FOR_INTN_TRAP SIGSEGV
    164 #define IS_MAYBE_INT_TRAP(info,xp) (((info->si_code) &0x7f) == 0)
     164#define IS_MAYBE_INT_TRAP(info,xp) ((xpGPR(xp,REG_TRAPNO)==0xd)&&((xpGPR(xp,REG_ERR)&7)==2))
     165#define IS_PAGE_FAULT(info,xp) (xpGPR(xp,REG_TRAPNO)==0xe)
    165166#define SIGRETURN(context)
    166167#endif
     
    169170extern void freebsd_sigreturn(ExceptionInformation *);
    170171#define SIGNUM_FOR_INTN_TRAP SIGBUS
    171 #define IS_MAYBE_INT_TRAP(info,xp) (xp->uc_mcontext.mc_trapno == T_PROTFLT)
     172#define IS_MAYBE_INT_TRAP(info,xp) ((xp->uc_mcontext.mc_trapno == T_PROTFLT) && ((xp->uc_mcontext.mc_err & 7) == 2))
     173#define IS_PAGE_FAULT(info,xp) (xp->uc_mcontext.mc_trapno == T_PAGEFLT)
    172174#define SIGRETURN(context) freebsd_sigreturn(context)
    173175#endif
     
    175177#ifdef DARWIN
    176178#define SIGNUM_FOR_INTN_TRAP SIGSEGV /* Not really, but our Mach handler fakes that */
    177 #define IS_MAYBE_INT_TRAP(info,xp) (info->si_code == EXC_I386_GPFLT)
     179#define IS_MAYBE_INT_TRAP(info,xp) ((UC_MCONTEXT(xp)->__es.trapno == 0xd) && (((UC_MCONTEXT(xp)->__es.err)&7)==2))
     180#define IS_PAGE_FAULT(info,xp) (UC_MCONTEXT(xp)->__es.trapno == 0xe)
    178181/* The x86 version of sigreturn just needs the context argument; the
    179182   hidden, magic "flavor" argument that sigtramp uses is ignored. */
     
    185188#ifdef X8664
    186189#define IS_MAYBE_INT_TRAP(info,xp) ((xpGPR(xp,REG_TRAPNO)==0xd)&&((xpGPR(xp,REG_ERR)&7)==2))
     190#define IS_PAGE_FAULT(info,xp) (xpGPR(xp,REG_TRAPNO)==0xe)
    187191#else
    188192#define IS_MAYBE_INT_TRAP(info,xp) ((xpGPR(xp,TRAPNO)==0xd)&&((xpGPR(xp,ERR)&7)==2))
     193#define IS_PAGE_FAULT(info,xp) (xpGPR(xp,TRAPNO)==0xe)
    189194#endif
    190195#define SIGRETURN(context) setcontext(context)
     
    197202   (info->ExceptionInformation[0]==0) &&                       \
    198203   (info->ExceptionInformation[1]==(ULONG_PTR)(-1L)))
     204#define IS_PAGE_FAULT(info,xp) (1)
    199205#define SIGRETURN(context)      /* for now */
    200206#endif
Note: See TracChangeset for help on using the changeset viewer.