This is the mail archive of the
cygwin-xfree
mailing list for the Cygwin XFree86 project.
[PATCH] Store pthread_ids and chain IOError handlers to avoid longjmp across threads
- From: Jon TURNEY <jon dot turney at dronecode dot org dot uk>
- To: cygwin-xfree at cygwin dot com
- Cc: Jon TURNEY <jon dot turney at dronecode dot org dot uk>
- Date: Mon, 5 Apr 2010 22:33:22 +0100
- Subject: [PATCH] Store pthread_ids and chain IOError handlers to avoid longjmp across threads
- References: <4BBA51CB.7040109@dronecode.org.uk>
- Reply-to: cygwin-xfree at cygwin dot com
Signed-off-by: Jon TURNEY <jon.turney@dronecode.org.uk>
---
hw/xwin/winclipboardthread.c | 24 +++++++++++++-----
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 f61037c..be8126f 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;
@@ -122,6 +125,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);
@@ -144,10 +152,6 @@ winClipboardProc (void *pvNotUsed)
/* Use our generated cookie for authentication */
winSetAuthorization();
- /* Set error handler */
- XSetErrorHandler (winClipboardErrorHandler);
- XSetIOErrorHandler (winClipboardIOErrorHandler);
-
/* Initialize retry count */
iRetries = 0;
@@ -452,8 +456,14 @@ 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 43c047c..3f231bc 100644
--- a/hw/xwin/winmultiwindowwm.c
+++ b/hw/xwin/winmultiwindowwm.c
@@ -203,7 +203,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;
@@ -900,9 +904,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)
@@ -918,10 +927,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);
@@ -1282,9 +1287,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)
@@ -1300,10 +1310,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);
@@ -1426,12 +1432,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;
}
@@ -1466,9 +1478,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;
}
--
1.7.0.4
--
Unsubscribe info: http://cygwin.com/ml/#unsubscribe-simple
Problem reports: http://cygwin.com/problems.html
Documentation: http://x.cygwin.com/docs/
FAQ: http://x.cygwin.com/docs/faq/