Changeset 11231


Ignore:
Timestamp:
Oct 27, 2008, 12:17:51 AM (11 years ago)
Author:
gb
Message:

In windows suspend_tcr(): writing to a (new, uncommitted) page on
another thread's c stack doesn't work on Windows. Since we can
only have one active suspend_suspend context, pre-allocated one
and store a pointer to it in tcr.native_thread_info.

Still need to handle the interrupt case (where there can be
more than one pending interrupt context on a thread), and need
to verify that exception handling (where there's only one thread
involved) works.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/source/lisp-kernel/thread_manager.c

    r11184 r11231  
    12851285    CloseHandle((HANDLE)tcr->io_datum);
    12861286    tcr->io_datum = NULL;
     1287    free(tcr->native_thread_info);
     1288    tcr->native_thread_info = NULL;
    12871289#endif
    12881290    UNLOCK(lisp_global(TCR_AREA_LOCK),current);
     
    13811383#ifdef WINDOWS
    13821384  tcr->io_datum = (VOID *)CreateEvent(NULL, true, false, NULL);
     1385  tcr->native_thread_info = malloc(sizeof(CONTEXT));
    13831386#endif
    13841387  tcr->log2_allocation_quantum = unbox_fixnum(lisp_global(DEFAULT_ALLOCATION_QUANTUM));
     
    17351738  DWORD rc;
    17361739  if (suspend_count == 1) {
    1737     /* Can't seem to get gcc to align a CONTEXT structure correctly */
    1738     char _contextbuf[sizeof(CONTEXT)+__alignof(CONTEXT)];
    1739 
    1740     CONTEXT *suspend_context, *pcontext;
     1740    CONTEXT  *pcontext = (CONTEXT *)tcr->native_thread_info;
    17411741    HANDLE hthread = (HANDLE)(tcr->osid);
    17421742    pc where;
     
    17441744    LispObj foreign_rsp;
    17451745
    1746     pcontext = (CONTEXT *)((((natural)&_contextbuf)+15)&~15);
    1747 
     1746    if (hthread == NULL) {
     1747      return false;
     1748    }
    17481749    rc = SuspendThread(hthread);
    17491750    if (rc == -1) {
     
    17941795      } else {
    17951796        area *ts = tcr->ts_area;
    1796         /* If we're in the lisp heap, or in x86-spentry64.o, or in
    1797            x86-subprims64.o, or in the subprims jump table at #x15000,
     1797        /* If we're in the lisp heap, or in x86-spentry??.o, or in
     1798           x86-subprims??.o, or in the subprims jump table at #x15000,
    17981799           or on the tstack ... we're just executing lisp code.  Otherwise,
    17991800           we got an exception while executing lisp code, but haven't
     
    18311832    } else {
    18321833      if (tcr->valence == TCR_STATE_EXCEPTION_RETURN) {
     1834        if (!tcr->pending_exception_context) {
     1835          FBug(pcontext, "we're confused here.");
     1836        }
    18331837        *pcontext = *tcr->pending_exception_context;
    18341838        tcr->pending_exception_context = NULL;
     
    18361840      }
    18371841    }
    1838 
    1839     /* If the context's stack pointer is pointing into the cs_area,
    1840        copy the context below the stack pointer. else copy it
    1841        below tcr->foreign_rsp. */
    1842     foreign_rsp = xpGPR(pcontext,Isp);
    1843 
    1844     if ((foreign_rsp < (LispObj)(cs->low)) ||
    1845         (foreign_rsp >= (LispObj)(cs->high))) {
    1846       foreign_rsp = (LispObj)(tcr->foreign_sp);
    1847     }
    1848     foreign_rsp -= 0x200;
    1849     foreign_rsp &= ~15;
    1850     suspend_context = (CONTEXT *)(foreign_rsp)-1;
    1851     *suspend_context = *pcontext;
    1852     tcr->suspend_context = suspend_context;
     1842    tcr->suspend_context = pcontext;
    18531843    return true;
    18541844  }
     
    19601950
    19611951    if (context) {
     1952      context->ContextFlags = CONTEXT_ALL;
    19621953      tcr->suspend_context = NULL;
    19631954      SetThreadContext(hthread,context);
Note: See TracChangeset for help on using the changeset viewer.