And made timerRunWithTimeout() use the non-reentrant code on all architectures. Windows code done.

This commit is contained in:
Pietro Gagliardi 2019-05-03 10:41:27 -04:00
parent 020cabc61e
commit e9fd8cc878
2 changed files with 5 additions and 48 deletions

View File

@ -52,7 +52,7 @@ static void queued(void *data)
int *flag = (int *) data; int *flag = (int *) data;
*flag = 1; *flag = 1;
// uiQuit(); uiQuit();
} }
// TODO the timing for this is strange because it is the first to call uiMain() // TODO the timing for this is strange because it is the first to call uiMain()

View File

@ -197,28 +197,6 @@ timerDuration timerTimeSub(timerTime end, timerTime start)
// note: the idea for the SetThreadContext() nuttery is from https://www.codeproject.com/Articles/71529/Exception-Injection-Throwing-an-Exception-in-Other // note: the idea for the SetThreadContext() nuttery is from https://www.codeproject.com/Articles/71529/Exception-Injection-Throwing-an-Exception-in-Other
#if defined(_AMD64_)
#define timerprivReentrant 1
#define timerprivCall
#elif defined(_ARM_)
// TODO figure out how to set arguments properly to avoid this
#define timerprivReentrant 0
#define timerprivCall
#elif defined(_ARM64_)
// TODO figure out how to set arguments properly to avoid this
#define timerprivReentrant 0
#define timerprivCall
#elif defined(_X86_)
#define timerprivReentrant 1
#define timerprivCall __fastcall
#elif defined(_IA64_)
// TODO figure out how to set arguments properly to avoid this
#define timerprivReentrant 0
#define timerprivCall
#else
#error unknown CPU architecture; cannot create CONTEXT objects for CPU-specific Windows test code
#endif
struct timeoutParams { struct timeoutParams {
jmp_buf retpos; jmp_buf retpos;
HANDLE timer; HANDLE timer;
@ -228,30 +206,11 @@ struct timeoutParams {
HRESULT hr; HRESULT hr;
}; };
#if timerprivReentrant
static void timerprivCall onTimeout(struct timeoutParams *p)
{
longjmp(p->retpos, 1);
}
static HRESULT setupNonReentrance(struct timeoutParams *p)
{
return S_OK;
}
static void teardownNonReentrance(void)
{
// do nothing
}
#else
static DWORD timeoutParamsSlot; static DWORD timeoutParamsSlot;
static HRESULT timeoutParamsHRESULT = S_OK; static HRESULT timeoutParamsHRESULT = S_OK;
static INIT_ONCE timeoutParamsOnce = INIT_ONCE_STATIC_INIT; static INIT_ONCE timeoutParamsOnce = INIT_ONCE_STATIC_INIT;
static void timerprivCall onTimeout(void) static void onTimeout(void)
{ {
struct timeoutParams *p; struct timeoutParams *p;
@ -288,23 +247,21 @@ static void teardownNonReentrance(void)
TlsSetValue(timeoutParamsSlot, NULL); TlsSetValue(timeoutParamsSlot, NULL);
} }
#endif
static void redirectToOnTimeout(CONTEXT *ctx, struct timeoutParams *p) static void redirectToOnTimeout(CONTEXT *ctx, struct timeoutParams *p)
{ {
#if defined(_AMD64_) #if defined(_AMD64_)
ctx->Rip = (DWORD64) onTimeout; ctx->Rip = (DWORD64) onTimeout;
ctx->Rcx = (DWORD64) p;
#elif defined(_ARM_) #elif defined(_ARM_)
ctx->Pc = (DWORD) onTimeout; ctx->Pc = (DWORD) onTimeout;
#elif defined(_ARM64_) #elif defined(_ARM64_)
ctx->Pc = (DWORD64) onTimeout; ctx->Pc = (DWORD64) onTimeout;
#elif defined(_X86_) #elif defined(_X86_)
ctx->Eip = (DWORD) onTimeout; ctx->Eip = (DWORD) onTimeout;
ctx->Ecx = (DWORD) p;
#elif defined(_IA64_) #elif defined(_IA64_)
// TODO verify that this is correct // TODO verify that this is correct
ctx->StIIP = (ULONGLONG) onTimeout; ctx->StIIP = (ULONGLONG) onTimeout;
#else
#error unknown CPU architecture; cannot create CONTEXT objects for CPU-specific Windows test code
#endif #endif
} }
@ -338,7 +295,7 @@ static unsigned __stdcall timerThreadProc(void *data)
if (hr != S_OK) if (hr != S_OK)
criticalCallFailed("SuspendThread()", hr); criticalCallFailed("SuspendThread()", hr);
ZeroMemory(&ctx, sizeof (CONTEXT)); ZeroMemory(&ctx, sizeof (CONTEXT));
ctx.ContextFlags = CONTEXT_CONTROL | CONTEXT_INTEGER; ctx.ContextFlags = CONTEXT_CONTROL;
hr = hrGetThreadContext(p->targetThread, &ctx); hr = hrGetThreadContext(p->targetThread, &ctx);
if (hr != S_OK) if (hr != S_OK)
criticalCallFailed("GetThreadContext()", hr); criticalCallFailed("GetThreadContext()", hr);