Changeset 9988


Ignore:
Timestamp:
Jul 10, 2008, 9:57:08 AM (11 years ago)
Author:
gb
Message:

New traps for thread ops, other changes from trunk.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/working-0711/ccl/lisp-kernel/x86-exceptions.c

    r8705 r9988  
    3535#include <sysexits.h>
    3636#endif
     37#ifndef WINDOWS
    3738#include <sys/syslog.h>
     39#endif
    3840
    3941
     
    155157  area *a = active_dynamic_area;
    156158  Boolean egc_was_enabled = (a->older != NULL);
     159 
    157160  natural gc_previously_deferred = gc_deferred;
    158161
     
    217220      full_gc_deferred = 0;
    218221    }
    219     if (selector & GC_TRAP_FUNCTION_PURIFY) {
    220       purify_from_xp(xp, 0L);
    221       gc_from_xp(xp, 0L);
    222     }
    223     if (selector & GC_TRAP_FUNCTION_SAVE_APPLICATION) {
    224       OSErr err;
    225       extern OSErr save_application(unsigned);
    226       area *vsarea = tcr->vs_area;
     222    if (selector > GC_TRAP_FUNCTION_GC) {
     223      if (selector & GC_TRAP_FUNCTION_IMPURIFY) {
     224        impurify_from_xp(xp, 0L);
     225        /*        nrs_GC_EVENT_STATUS_BITS.vcell |= gc_integrity_check_bit; */
     226        gc_from_xp(xp, 0L);
     227        release_readonly_area();
     228      }
     229      if (selector & GC_TRAP_FUNCTION_PURIFY) {
     230        purify_from_xp(xp, 0L);
     231        gc_from_xp(xp, 0L);
     232      }
     233      if (selector & GC_TRAP_FUNCTION_SAVE_APPLICATION) {
     234        OSErr err;
     235        extern OSErr save_application(unsigned);
     236        area *vsarea = tcr->vs_area;
    227237       
    228       nrs_TOPLFUNC.vcell = *((LispObj *)(vsarea->high)-1);
    229       err = save_application(arg);
    230       if (err == noErr) {
    231         _exit(0);
     238        nrs_TOPLFUNC.vcell = *((LispObj *)(vsarea->high)-1);
     239        err = save_application(arg);
     240        if (err == noErr) {
     241          _exit(0);
     242        }
     243        fatal_oserr(": save_application", err);
    232244      }
    233       fatal_oserr(": save_application", err);
    234     }
    235     switch (selector) {
    236     case GC_TRAP_FUNCTION_SET_HONS_AREA_SIZE:
    237       xpGPR(xp, Iimm0) = 0;
    238       break;
    239     case GC_TRAP_FUNCTION_FREEZE:
    240       a->active = (BytePtr) align_to_power_of_2(a->active, log2_page_size);
    241       tenured_area->static_dnodes = area_dnode(a->active, a->low);
    242       xpGPR(xp, Iimm0) = tenured_area->static_dnodes << dnode_shift;
    243       break;
    244     default:
    245       break;
     245      switch (selector) {
     246      case GC_TRAP_FUNCTION_SET_HONS_AREA_SIZE:
     247        xpGPR(xp, Iimm0) = 0;
     248        break;
     249      case GC_TRAP_FUNCTION_FREEZE:
     250        a->active = (BytePtr) align_to_power_of_2(a->active, log2_page_size);
     251        tenured_area->static_dnodes = area_dnode(a->active, a->low);
     252        xpGPR(xp, Iimm0) = tenured_area->static_dnodes << dnode_shift;
     253        break;
     254      default:
     255        break;
     256      }
    246257    }
    247258    if (egc_was_enabled) {
     
    423434}
    424435
    425 extern unsigned get_mxcsr();
    426 extern void set_mxcsr(unsigned);
    427436 
    428437int
     
    430439                  natural arg1, natural arg2, natural arg3, natural arg4, natural arg5)
    431440{
    432   sigset_t mask;
    433   natural  callback_ptr, i;
     441  natural  callback_ptr;
    434442  int delta;
    435443  unsigned old_mxcsr = get_mxcsr();
     
    616624}
    617625
     626#ifdef WINDOWS
    618627Boolean
    619628handle_fault(TCR *tcr, ExceptionInformation *xp, siginfo_t *info, int old_valence)
    620629{
     630}
     631
     632Boolean
     633handle_floating_point_exception(TCR *tcr, ExceptionInformation *xp, siginfo_t *info)
     634{
     635}
     636#else
     637#ifdef BOOTSTRAP
     638void
     639bootstrap_fix_lowmem_ref(BytePtr addr, pc where, ExceptionInformation *xp)
     640{
     641}
     642#endif
     643Boolean
     644handle_fault(TCR *tcr, ExceptionInformation *xp, siginfo_t *info, int old_valence)
     645{
    621646#ifdef FREEBSD
    622647  BytePtr addr = (BytePtr) xp->uc_mcontext.mc_addr;
    623648#else
    624649  BytePtr addr = (BytePtr) info->si_addr;
     650#endif
     651
     652#ifdef BOOTSTRAP
     653  if ((addr >= (BytePtr)0x2000) &&
     654      (addr <  (BytePtr)(0x2000+0x2000))) {
     655    bootstrap_fix_lowmem_ref(addr,(pc)xpPC(xp), xp);
     656    return true;
     657  }
    625658#endif
    626659
     
    636669      handler = protection_handlers[a->why];
    637670      return handler(xp, a, addr);
     671    } else {
     672      if ((addr >= readonly_area->low) &&
     673          (addr < readonly_area->active)) {
     674        UnProtectMemory((LogicalAddress)(truncate_to_power_of_2(addr,log2_page_size)),
     675                        page_size);
     676        return true;
     677      }
    638678    }
    639679  }
     
    653693handle_floating_point_exception(TCR *tcr, ExceptionInformation *xp, siginfo_t *info)
    654694{
    655   int code = info->si_code, rfn = 0, skip;
    656   pc program_counter = (pc)xpPC(xp);
    657   LispObj rpc = (LispObj) program_counter, xcf, cmain = nrs_CMAIN.vcell,
     695  int code = info->si_code, skip;
     696  LispObj  xcf, cmain = nrs_CMAIN.vcell,
    658697
    659698    save_rbp = xpGPR(xp,Irbp), save_vsp = xpGPR(xp,Isp);
     
    671710  }
    672711}
     712#endif
    673713
    674714Boolean
     
    773813}
    774814
     815#ifdef WINDOWS
     816Boolean
     817handle_exception(int signum, siginfo_t *info, ExceptionInformation  *context, TCR *tcr, int old_valence)
     818{
     819}
     820#else
    775821Boolean
    776822handle_exception(int signum, siginfo_t *info, ExceptionInformation  *context, TCR *tcr, int old_valence)
     
    839885    if ((program_counter[0] == XUUO_OPCODE_0) &&
    840886        (program_counter[1] == XUUO_OPCODE_1)) {
     887      TCR *target = (TCR *)xpGPR(context, Iarg_z);
     888
    841889      switch (program_counter[2]) {
    842890      case XUUO_TLB_TOO_SMALL:
     
    855903        xpPC(context)+=3;
    856904        return true;
     905
     906      case XUUO_INTERRUPT:
     907        raise_thread_interrupt(target);
     908        xpPC(context)+=3;
     909        return true;
     910
     911      case XUUO_SUSPEND:
     912        xpGPR(context,Iimm0) = (LispObj) lisp_suspend_tcr(target);
     913        xpPC(context)+=3;
     914        return true;
     915
     916      case XUUO_SUSPEND_ALL:
     917        lisp_suspend_other_threads();
     918        xpPC(context)+=3;
     919        return true;
     920
     921
     922      case XUUO_RESUME:
     923        xpGPR(context,Iimm0) = (LispObj) lisp_resume_tcr(target);
     924        xpPC(context)+=3;
     925        return true;
     926       
     927      case XUUO_RESUME_ALL:
     928        lisp_resume_other_threads();
     929        xpPC(context)+=3;
     930        return true;
    857931       
    858932      default:
     
    895969  }
    896970}
    897 
     971#endif
    898972
    899973/*
     
    9481022   that the thread sees it as soon as it's able to run.
    9491023*/
     1024#ifdef WINDOWS
     1025void
     1026raise_pending_interrupt(TCR *tcr)
     1027{
     1028}
     1029void
     1030exit_signal_handler(TCR *tcr, int old_valence)
     1031{
     1032}
     1033void
     1034signal_handler(int signum, siginfo_t *info, ExceptionInformation  *context, TCR *tcr, int old_valence)
     1035{
     1036}
     1037#else
    9501038void
    9511039raise_pending_interrupt(TCR *tcr)
     
    10111099#endif
    10121100}
     1101#endif
    10131102
    10141103#ifdef DARWIN
     
    10731162#endif
    10741163
     1164#ifdef WINDOWS
     1165LispObj *
     1166copy_ucontext(ExceptionInformation *context, LispObj *current, copy_ucontext_last_arg_t fp)
     1167{
     1168}
     1169#else
    10751170LispObj *
    10761171copy_ucontext(ExceptionInformation *context, LispObj *current, copy_ucontext_last_arg_t fp)
     
    10911186  return (LispObj *)dest;
    10921187}
     1188#endif
    10931189
    10941190LispObj *
     
    11001196    rsp = (LispObj)(tcr->foreign_sp);
    11011197  }
    1102   return (LispObj *) ((rsp-128 & ~15));
     1198  return (LispObj *) (((rsp-128) & ~15));
    11031199}
    11041200
     
    12221318}
    12231319
     1320#ifdef WINDOWS
     1321void
     1322interrupt_handler (int signum, siginfo_t *info, ExceptionInformation *context)
     1323{
     1324}
     1325#else
    12241326void
    12251327interrupt_handler (int signum, siginfo_t *info, ExceptionInformation *context)
     
    12921394  SIGRETURN(context);
    12931395}
     1396#endif
    12941397
    12951398#ifndef USE_SIGALTSTACK
     
    13461449#endif
    13471450
    1348 
     1451#ifdef WINDOWS
     1452void
     1453install_signal_handler(int signo, void * handler)
     1454{
     1455}
     1456#else
    13491457void
    13501458install_signal_handler(int signo, void * handler)
     
    13631471#endif
    13641472  sa.sa_flags =
    1365 #if 1
    1366     0
    1367 #else
    1368     SA_RESTART
    1369 #endif
     1473    0 /* SA_RESTART */
    13701474#ifdef USE_SIGALTSTACK
    13711475    | SA_ONSTACK
     
    13751479  sigaction(signo, &sa, NULL);
    13761480}
    1377 
    1378 
     1481#endif
     1482
     1483#ifdef WINDOWS
     1484void
     1485install_pmcl_exception_handlers()
     1486{
     1487}
     1488#else
    13791489void
    13801490install_pmcl_exception_handlers()
     
    14131523  signal(SIGPIPE, SIG_IGN);
    14141524}
     1525#endif
    14151526
    14161527#ifndef USE_SIGALTSTACK
     
    14721583#endif
    14731584
     1585#ifdef WINDOWS
     1586void
     1587quit_handler(int signum, siginfo_t *info, ExceptionInformation *xp)
     1588{
     1589}
     1590#else
    14741591void
    14751592quit_handler(int signum, siginfo_t *info, ExceptionInformation *xp)
     
    15011618  pthread_exit(NULL);
    15021619}
     1620#endif
    15031621
    15041622#ifndef USE_SIGALTSTACK
     1623void
    15051624arbstack_quit_handler(int signum, siginfo_t *info, ExceptionInformation *context)
    15061625{
     
    15661685#endif
    15671686
     1687#ifdef WINDOWS
    15681688void
    15691689thread_signal_setup()
    15701690{
     1691}
     1692#else
     1693void
     1694thread_signal_setup()
     1695{
    15711696  thread_suspend_signal = SIG_SUSPEND_THREAD;
    1572   thread_resume_signal = SIG_RESUME_THREAD;
    15731697
    15741698  install_signal_handler(thread_suspend_signal, (void *)SUSPEND_RESUME_HANDLER);
    1575   install_signal_handler(thread_resume_signal, (void *)SUSPEND_RESUME_HANDLER);
    15761699  install_signal_handler(SIGQUIT, (void *)QUIT_HANDLER);
    15771700}
    1578 
     1701#endif
    15791702
    15801703void
     
    16951818}
    16961819     
    1697  
     1820#ifdef WINDOWS 
     1821void
     1822pc_luser_xp(ExceptionInformation *xp, TCR *tcr, signed_natural *interrupt_displacement)
     1823{
     1824}
     1825#else
    16981826void
    16991827pc_luser_xp(ExceptionInformation *xp, TCR *tcr, signed_natural *interrupt_displacement)
     
    18001928  if ((program_counter >= &egc_write_barrier_start) &&
    18011929      (program_counter < &egc_write_barrier_end)) {
    1802     LispObj *ea = 0, val, root;
     1930    LispObj *ea = 0, val, root = 0;
    18031931    bitvector refbits = (bitvector)(lisp_global(REFBITS));
    18041932    Boolean need_store = true, need_check_memo = true, need_memoize_root = false;
     
    18581986  }
    18591987}
     1988#endif
    18601989
    18611990void
     
    18631992{
    18641993  void *cur_allocptr = (void *)(tcr->save_allocptr);
    1865   LispObj lisprsp, lisptsp;
     1994  LispObj lisprsp;
    18661995  area *a;
    18671996
     
    19082037{
    19092038  TCR *tcr = get_tcr(false), *other_tcr;
    1910   ExceptionInformation* other_xp;
    19112039  int result;
    19122040  signed_natural inhibit;
     
    21242252restore_mach_thread_state(mach_port_t thread, ExceptionInformation *pseudosigcontext)
    21252253{
    2126   int i, j;
    21272254  kern_return_t kret;
    21282255#if WORD_SIZE == 64
     
    22012328{
    22022329  mach_msg_type_number_t thread_state_count;
    2203   kern_return_t result;
    2204   int i,j;
    22052330  ExceptionInformation *pseudosigcontext;
    22062331#ifdef X8664
     
    22092334  struct mcontext *mc;
    22102335#endif
    2211   natural stackp, backlink;
     2336  natural stackp;
    22122337
    22132338 
     
    22952420#endif
    22962421  ExceptionInformation *pseudosigcontext;
    2297   int i, j, old_valence = tcr->valence;
    2298   kern_return_t result;
     2422  int  old_valence = tcr->valence;
    22992423  natural stackp, *stackpp;
    23002424  siginfo_t *info;
     
    24062530                      mach_msg_type_number_t code_count)
    24072531{
    2408   int signum = 0, code = *code_vector, code1;
     2532  int signum = 0, code = *code_vector;
    24092533  TCR *tcr = TCR_FROM_EXCEPTION_PORT(exception_port);
    24102534  kern_return_t kret, call_kret;
     
    26892813  mach_port_t
    26902814    thread_exception_port = TCR_TO_EXCEPTION_PORT(tcr),
    2691     target_thread = pthread_mach_thread_np((pthread_t)ptr_from_lispobj(tcr->osid)),
    26922815    task_self = mach_task_self();
    26932816  kern_return_t kret;
Note: See TracChangeset for help on using the changeset viewer.