Changeset 5298


Ignore:
Timestamp:
Oct 5, 2006, 1:46:06 PM (18 years ago)
Author:
Gary Byers
Message:

Save the mxcsr, load it with a C-like value (all exceptions masked)
before doing a callback. (Not doing this meant that tcr.foreign_mxcsr
was often set to a "lispy" value, where most exceptions were unmasked,
and this caused FP exceptions when calling out to foreign code with
the "lispy" tcr.foreign_mxcsr in effect.)

Mach exception stuff arranges to return via sigreturn. Didn't fix
the spurious SIGTRAPs, but might be the right idea (and might save
a context switch or two.)

Mach exception stuff initializes rflags to exception rflags when arranging
to resume thread at handler. Leaving them uninitialized was causing
spurious SIGTRAPs, since the trace bit(s) may have been set.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/ccl/lisp-kernel/x86-exceptions.c

    r5287 r5298  
    372372
    373373
     374extern unsigned get_mxcsr();
     375extern void set_mxcsr(unsigned);
    374376 
    375377int
     
    380382  natural  callback_ptr, i;
    381383  int delta;
     384  unsigned old_mxcsr = get_mxcsr();
     385
     386  set_mxcsr(0x1f80);
    382387
    383388  /* Put the active stack pointers where .SPcallback expects them */
     
    393398  delta = ((int (*)())callback_ptr) (xp, arg1, arg2, arg3, arg4, arg5);
    394399  LOCK(lisp_global(EXCEPTION_LOCK), tcr);
     400  set_mxcsr(old_mxcsr);
    395401  return delta;
    396402}
     
    832838
    833839void
    834 signal_handler(int signum, siginfo_t *info, ExceptionInformation  *context, TCR *tcr)
     840signal_handler(int signum, siginfo_t *info, ExceptionInformation  *context, TCR *tcr, int old_valence)
    835841{
    836842#ifdef DARWIN_GS_HACK
     
    838844#endif
    839845  xframe_list xframe_link;
    840   int old_valence;
    841846#ifndef DARWIN
    842847  tcr = get_tcr(false);
     
    857862  }
    858863  unlock_exception_lock_in_handler(tcr);
    859 #ifndef DARWIN
    860864  exit_signal_handler(tcr, old_valence);
    861 #endif
    862865  /* raise_pending_interrupt(tcr); */
    863866#ifdef DARWIN_GS_HACK
     
    866869  }
    867870#endif
    868 #ifndef DARWIN
    869871  SIGRETURN(context);
    870 #endif
    871872}
    872873
    873874#ifdef DARWIN
    874 #endif
     875void
     876pseudo_signal_handler(int signum, siginfo_t *info, ExceptionInformation  *context, TCR *tcr, int old_valence)
     877{
     878  sigset_t mask;
     879
     880  sigfillset(&mask);
     881
     882  pthread_sigmask(SIG_SETMASK,&mask,&(context->uc_sigmask));
     883  signal_handler(signum, info, context, tcr, old_valence);
     884}
     885#endif
     886
     887
    875888
    876889#ifdef LINUX
     
    18861899#endif
    18871900  ExceptionInformation *pseudosigcontext;
    1888   int i, j;
     1901  int i, j, old_valence = tcr->valence;
    18891902  kern_return_t result;
    18901903  natural stackp, *stackpp;
     
    19191932  new_ts.__rdx = (natural)pseudosigcontext;
    19201933  new_ts.__rcx = (natural)tcr;
     1934  new_ts.__r8 = (natural)old_valence;
    19211935  new_ts.__rsp = stackp;
     1936  new_ts.__rflags = ts->__rflags;
    19221937
    19231938
     
    20532068      if (signum) {
    20542069        kret = setup_signal_frame(thread,
    2055                                   (void *)signal_handler,
     2070                                  (void *)pseudo_signal_handler,
    20562071                                  signum,
    20572072                                  code,
Note: See TracChangeset for help on using the changeset viewer.