diff options
author | Jon TURNEY <jon dot turney at dronecode dot org dot uk> | 2010-04-05 22:33:22 +0100 |
---|---|---|
committer | Yaakov Selkowitz <yselkowitz@users.sourceforge.net> | 2010-10-03 10:40:33 -0500 |
commit | 0c89b6257e86f3cf4c322d26ada30bce8833a2b8 (patch) | |
tree | d95f59b181227e90e062706cccba36e07341ed3f | |
parent | 866d86b1ef7901380f4c4da62e3215a52b5de0f1 (diff) |
Store pthread_ids and chain IOError handlers to avoid longjmp across threadswork
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; } |