diff options
author | Jon TURNEY <jon.turney@dronecode.org.uk> | 2010-04-05 13:57:24 +0100 |
---|---|---|
committer | Jon TURNEY <jon.turney@dronecode.org.uk> | 2010-08-13 14:59:08 +0100 |
commit | ec40625137807eafbae8cb7e921aff48e796e3af (patch) | |
tree | 4acc346daf4bd90c8387e542502371cc1c22afdb | |
parent | a895a12a5979601e479f939e6bad67bf34d02ca5 (diff) |
Cygwin/X: Store pthread_ids and chain IOError handlers to avoid longjmp across threads
Signed-off-by: Jon TURNEY <jon.turney@dronecode.org.uk>
-rw-r--r-- | hw/xwin/winclipboardthread.c | 24 | ||||
-rw-r--r-- | hw/xwin/winmultiwindowwm.c | 54 |
2 files changed, 53 insertions, 25 deletions
diff --git a/hw/xwin/winclipboardthread.c b/hw/xwin/winclipboardthread.c index 9788d883b..ea9459910 100644 --- a/hw/xwin/winclipboardthread.c +++ b/hw/xwin/winclipboardthread.c @@ -58,6 +58,9 @@ extern Window g_iClipboardWindow; */ static jmp_buf g_jmpEntry; +static XIOErrorHandler g_winClipboardOldIOErrorHandler; +static pthread_t g_winClipboardProcThread; + Bool g_fUnicodeSupport = FALSE; Bool g_fUseUnicode = FALSE; @@ -126,6 +129,11 @@ winClipboardProc (void *pvNotUsed) ErrorF ("winClipboardProc - Warning: Locale not supported by X.\n"); } + /* Set error handler */ + XSetErrorHandler (winClipboardErrorHandler); + g_winClipboardProcThread = pthread_self(); + g_winClipboardOldIOErrorHandler = XSetIOErrorHandler (winClipboardIOErrorHandler); + /* Set jump point for Error exits */ iReturn = setjmp (g_jmpEntry); @@ -148,10 +156,6 @@ winClipboardProc (void *pvNotUsed) /* Use our generated cookie for authentication */ winSetAuthorization(); - /* Set error handler */ - XSetErrorHandler (winClipboardErrorHandler); - XSetIOErrorHandler (winClipboardIOErrorHandler); - /* Initialize retry count */ iRetries = 0; @@ -462,9 +466,15 @@ winClipboardIOErrorHandler (Display *pDisplay) { ErrorF ("winClipboardIOErrorHandler!\n\n"); - /* Restart at the main entry point */ - longjmp (g_jmpEntry, WIN_JMP_ERROR_IO); - + if (pthread_equal(pthread_self(),g_winClipboardProcThread)) + { + /* Restart at the main entry point */ + longjmp (g_jmpEntry, WIN_JMP_ERROR_IO); + } + + if (g_winClipboardOldIOErrorHandler) + g_winClipboardOldIOErrorHandler(pDisplay); + return 0; } diff --git a/hw/xwin/winmultiwindowwm.c b/hw/xwin/winmultiwindowwm.c index 6c2812c6f..c507ca1b3 100644 --- a/hw/xwin/winmultiwindowwm.c +++ b/hw/xwin/winmultiwindowwm.c @@ -206,7 +206,11 @@ winUpdateWindowPosition (HWND hWnd, Bool reshape, HWND *zstyle); */ static jmp_buf g_jmpWMEntry; +static XIOErrorHandler g_winMultiWindowWMOldIOErrorHandler; +static pthread_t g_winMultiWindowWMThread; static jmp_buf g_jmpXMsgProcEntry; +static XIOErrorHandler g_winMultiWindowXMsgProcOldIOErrorHandler; +static pthread_t g_winMultiWindowXMsgProcThread; static Bool g_shutdown = FALSE; static Bool redirectError = FALSE; static Bool g_fAnotherWMRunning = FALSE; @@ -910,9 +914,14 @@ winMultiWindowXMsgProc (void *pArg) ErrorF ("winMultiWindowXMsgProc - pthread_mutex_unlock () returned.\n"); + /* Install our error handler */ + XSetErrorHandler (winMultiWindowXMsgProcErrorHandler); + g_winMultiWindowXMsgProcThread = pthread_self(); + g_winMultiWindowXMsgProcOldIOErrorHandler = XSetIOErrorHandler (winMultiWindowXMsgProcIOErrorHandler); + /* Set jump point for IO Error exits */ iReturn = setjmp (g_jmpXMsgProcEntry); - + /* Check if we should continue operations */ if (iReturn != WIN_JMP_ERROR_IO && iReturn != WIN_JMP_OKAY) @@ -928,10 +937,6 @@ winMultiWindowXMsgProc (void *pArg) pthread_exit (NULL); } - /* Install our error handler */ - XSetErrorHandler (winMultiWindowXMsgProcErrorHandler); - XSetIOErrorHandler (winMultiWindowXMsgProcIOErrorHandler); - /* Setup the display connection string x */ winGetDisplayName(pszDisplay, (int)pProcArg->dwScreen); @@ -1292,9 +1297,14 @@ winInitMultiWindowWM (WMInfoPtr pWMInfo, WMProcArgPtr pProcArg) ErrorF ("winInitMultiWindowWM - pthread_mutex_unlock () returned.\n"); + /* Install our error handler */ + XSetErrorHandler (winMultiWindowWMErrorHandler); + g_winMultiWindowWMThread = pthread_self(); + g_winMultiWindowWMOldIOErrorHandler = XSetIOErrorHandler (winMultiWindowWMIOErrorHandler); + /* Set jump point for IO Error exits */ iReturn = setjmp (g_jmpWMEntry); - + /* Check if we should continue operations */ if (iReturn != WIN_JMP_ERROR_IO && iReturn != WIN_JMP_OKAY) @@ -1310,10 +1320,6 @@ winInitMultiWindowWM (WMInfoPtr pWMInfo, WMProcArgPtr pProcArg) pthread_exit (NULL); } - /* Install our error handler */ - XSetErrorHandler (winMultiWindowWMErrorHandler); - XSetIOErrorHandler (winMultiWindowWMIOErrorHandler); - /* Setup the display connection string x */ winGetDisplayName(pszDisplay, (int)pProcArg->dwScreen); @@ -1436,12 +1442,18 @@ winMultiWindowWMIOErrorHandler (Display *pDisplay) { ErrorF ("winMultiWindowWMIOErrorHandler!\n\n"); - if (g_shutdown) - pthread_exit(NULL); + if (pthread_equal(pthread_self(),g_winMultiWindowWMThread)) + { + if (g_shutdown) + pthread_exit(NULL); + + /* Restart at the main entry point */ + longjmp (g_jmpWMEntry, WIN_JMP_ERROR_IO); + } + + if (g_winMultiWindowWMOldIOErrorHandler) + g_winMultiWindowWMOldIOErrorHandler(pDisplay); - /* Restart at the main entry point */ - longjmp (g_jmpWMEntry, WIN_JMP_ERROR_IO); - return 0; } @@ -1476,9 +1488,15 @@ winMultiWindowXMsgProcIOErrorHandler (Display *pDisplay) { ErrorF ("winMultiWindowXMsgProcIOErrorHandler!\n\n"); - /* Restart at the main entry point */ - longjmp (g_jmpXMsgProcEntry, WIN_JMP_ERROR_IO); - + if (pthread_equal(pthread_self(),g_winMultiWindowXMsgProcThread)) + { + /* Restart at the main entry point */ + longjmp (g_jmpXMsgProcEntry, WIN_JMP_ERROR_IO); + } + + if (g_winMultiWindowXMsgProcOldIOErrorHandler) + g_winMultiWindowXMsgProcOldIOErrorHandler(pDisplay); + return 0; } |