Changeset 1164 for trunk/src


Ignore:
Timestamp:
Sep 30, 2007, 8:23:59 AM (18 years ago)
Author:
bird
Message:

Ctrl-C/Break stuff ported to 64-bit windows too.

Location:
trunk/src/kmk
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/kmk/Makefile.kmk

    r1162 r1164  
    123123kmk_DEFS.x86 = CONFIG_WITH_OPTIMIZATION_HACKS
    124124kmk_DEFS.amd64 = CONFIG_WITH_OPTIMIZATION_HACKS
    125 kmk_DEFS.win.x86 = CONFIG_NEW_WIN32_CTRL_EVENT
     125kmk_DEFS.win = CONFIG_NEW_WIN32_CTRL_EVENT
    126126
    127127kmk_SOURCES = \
  • trunk/src/kmk/job.c

    r903 r1164  
    702702                coredump = 0;
    703703              }
     704            else if (!process_used_slots())
     705              {
     706                /* The wait*() failed miserably.  Punt.  */
     707                errno = ECHILD;
     708                pfatal_with_name ("wait");
     709              }
     710
    704711            pid = (pid_t) hPID;
    705712          }
  • trunk/src/kmk/main.c

    r1140 r1164  
    950950#include <process.h>
    951951static UINT g_tidMainThread = 0;
    952 static int g_sigPending = 0; /* lazy bird */
    953 
     952static int volatile g_sigPending = 0; /* lazy bird */
     953# ifndef _M_IX86
     954static LONG volatile g_lTriggered = 0;
     955static CONTEXT g_Ctx;
     956# endif
     957
     958# ifdef _M_IX86
    954959static __declspec(naked) void dispatch_stub(void)
    955960{
     
    968973    }
    969974}
     975# else /* !_M_IX86 */
     976static void dispatch_stub(void)
     977{
     978    fflush(stdout);
     979    /*fprintf(stderr, "dbg: raising %s on the main thread (%d)\n", g_sigPending == SIGINT ? "SIGINT" : "SIGBREAK", _getpid());*/
     980    raise(g_sigPending);
     981
     982    SetThreadContext(GetCurrentThread(), &g_Ctx);
     983    fprintf(stderr, "fatal error: SetThreadContext failed with last error %d\n", GetLastError());
     984    for (;;)
     985        exit(131);
     986}
     987# endif /* !_M_IX86 */
    970988
    971989static BOOL WINAPI ctrl_event(DWORD CtrlType)
     
    975993    CONTEXT Ctx;
    976994
     995#ifndef _M_IX86
     996    /* only once. */
     997    if (InterlockedExchange(&g_lTriggered, 1))
     998    {
     999        Sleep(1);
     1000        return TRUE;
     1001    }
     1002#endif
     1003
    9771004    /* open the main thread and suspend it. */
    9781005    hThread = OpenThread(THREAD_ALL_ACCESS, FALSE, g_tidMainThread);
    9791006    SuspendThread(hThread);
    9801007
    981     /* Get the thread context and */
     1008    /* Get the thread context and if we've get a valid Esp, dispatch
     1009       it on the main thread otherwise raise the signal in the
     1010       ctrl-event thread (this). */
    9821011    memset(&Ctx, 0, sizeof(Ctx));
    9831012    Ctx.ContextFlags = CONTEXT_FULL;
    984     GetThreadContext(hThread, &Ctx);
    985 
    986     /* If we've got a valid Esp, dispatch it on the main thread
    987        otherwise raise the signal in the ctrl-event thread (this). */
    988     if (Ctx.Esp >= 0x1000)
    989     {
     1013    if (GetThreadContext(hThread, &Ctx)
     1014#ifdef _M_IX86
     1015        && Ctx.Esp >= 0x1000
     1016#else
     1017        && Ctx.Rsp >= 0x1000
     1018#endif
     1019       )
     1020    {
     1021#ifdef _M_IX86
    9901022        ((uintptr_t *)Ctx.Esp)[-1] = Ctx.Eip;
    9911023        Ctx.Esp -= sizeof(uintptr_t);
    9921024        Ctx.Eip = (uintptr_t)&dispatch_stub;
     1025#else
     1026        g_Ctx = Ctx;
     1027        Ctx.Rsp -= 0x20;
     1028        Ctx.Rsp &= ~(uintptr_t)0xf;
     1029        Ctx.Rip = (uintptr_t)&dispatch_stub;
     1030#endif
    9931031
    9941032        SetThreadContext(hThread, &Ctx);
     
    16001638#ifdef KMK
    16011639  /* Check for [Mm]akefile.kup and change directory when found.
    1602      Makefile.kmk overrides Makefile.kup but not plain Makefile. 
     1640     Makefile.kmk overrides Makefile.kup but not plain Makefile.
    16031641     If no -C arguments were given, fake one to indicate chdir. */
    16041642  if (makefiles == 0)
Note: See TracChangeset for help on using the changeset viewer.