xserver: Branch 'master' - 9 commits

Keith Packard keithp at kemper.freedesktop.org
Fri Sep 23 06:57:01 UTC 2016


 configure.ac                  |    2 
 dix/dispatch.c                |    7 +-
 dix/main.c                    |   21 -------
 hw/xquartz/X11Application.h   |    3 -
 hw/xquartz/X11Application.m   |   55 ------------------
 hw/xquartz/darwin.c           |    1 
 hw/xquartz/darwinEvents.c     |  125 +++++++++++++-----------------------------
 hw/xquartz/pbproxy/app-main.m |    3 -
 hw/xquartz/pbproxy/main.m     |   18 ------
 hw/xquartz/quartzStartup.c    |    9 +++
 include/dix.h                 |    6 ++
 mi/mieq.c                     |   22 -------
 mi/mipointer.c                |   12 ----
 os/WaitFor.c                  |    2 
 os/io.c                       |    3 -
 os/ospoll.c                   |    8 ++
 test/ddxstubs.c               |   16 -----
 17 files changed, 71 insertions(+), 242 deletions(-)

New commits:
commit ade315386cee9a65a3885c65e96256880ac6f00a
Author: Keith Packard <keithp at keithp.com>
Date:   Fri Sep 23 09:52:21 2016 +0300

    Require xproto 7.0.31
    
    xproto 7.0.30 had a typo which caused compiles to fail on anything
    other than clang
    
    Signed-off-by: Keith Packard <keithp at keithp.com>

diff --git a/configure.ac b/configure.ac
index 922ee0c..dcc3968 100644
--- a/configure.ac
+++ b/configure.ac
@@ -812,7 +812,7 @@ APPLEWMPROTO="applewmproto >= 1.4"
 LIBXSHMFENCE="xshmfence >= 1.1"
 
 dnl Required modules
-XPROTO="xproto >= 7.0.30"
+XPROTO="xproto >= 7.0.31"
 RANDRPROTO="randrproto >= 1.5.0"
 RENDERPROTO="renderproto >= 0.11"
 XEXTPROTO="xextproto >= 7.2.99.901"
commit f72ff1f7ac784f3911fe2f8d746f62f7709f0edc
Author: Jeremy Huddleston Sequoia <jeremyhu at apple.com>
Date:   Mon Sep 19 09:34:50 2016 -0700

    XQuartz: Silence an expected TSan warning
    
    This code is safe.  If the data race fails, the result is that we take the
    lock and recheck.
    
    ==================
    WARNING: ThreadSanitizer: data race (pid=31401)
      Read of size 1 at 0x00010f5d2500 by thread T11:
        #0 wait_for_mieq_init darwinEvents.c:102 (X11.bin+0x00010003155a)
        #1 -[X11Application(Private) sendX11NSEvent:] X11Application.m:1330 (X11.bin+0x00010001d652)
        #2 __28-[X11Application sendEvent:]_block_invoke X11Application.m:476 (X11.bin+0x00010001887f)
        #3 __tsan::invoke_and_release_block(void*) <null>:144 (libclang_rt.tsan_osx_dynamic.dylib+0x00000005d97b)
        #4 _dispatch_client_callout <null>:33 (libdispatch.dylib+0x0000000020ef)
    
      Previous write of size 1 at 0x00010f5d2500 by thread T8:
        [failed to restore the stack]
    
      Location is global 'mieqInitialized' at 0x00010f5d2500 (X11.bin+0x000100599500)
    
      Thread T11 (tid=4367138, running) created by thread T-1
        [failed to restore the stack]
    
      Thread T8 (tid=4367130, running) created by main thread at:
        #0 pthread_create <null>:144 (libclang_rt.tsan_osx_dynamic.dylib+0x000000024490)
        #1 create_thread quartzStartup.c:78 (X11.bin+0x000100039d2d)
        #2 QuartzInitServer quartzStartup.c:95 (X11.bin+0x000100039b96)
        #3 X11ApplicationMain X11Application.m:1238 (X11.bin+0x00010001cd54)
        #4 X11ControllerMain X11Controller.m:984 (X11.bin+0x00010002a5b2)
        #5 server_main quartzStartup.c:136 (X11.bin+0x000100039fbb)
        #6 do_start_x11_server bundle-main.c:436 (X11.bin+0x000100002e25)
        #7 _Xstart_x11_server mach_startupServer.c:189 (X11.bin+0x000100004e09)
        #8 mach_startup_server mach_startupServer.c:399 (X11.bin+0x0001000056a4)
        #9 mach_msg_server mach_msg.c:563 (libsystem_kernel.dylib+0x000000012186)
        #10 start <null>:29 (libdyld.dylib+0x000000005254)
    
    SUMMARY: ThreadSanitizer: data race darwinEvents.c:102 in wait_for_mieq_init
    ==================
    
    Signed-off-by: Jeremy Huddleston Sequoia <jeremyhu at apple.com>

diff --git a/hw/xquartz/darwinEvents.c b/hw/xquartz/darwinEvents.c
index a3b70f5..fd87e96 100644
--- a/hw/xquartz/darwinEvents.c
+++ b/hw/xquartz/darwinEvents.c
@@ -96,6 +96,7 @@ static BOOL mieqInitialized;
 static pthread_mutex_t mieqInitializedMutex = PTHREAD_MUTEX_INITIALIZER;
 static pthread_cond_t mieqInitializedCond = PTHREAD_COND_INITIALIZER;
 
+_X_NOTSAN
 extern inline void
 wait_for_mieq_init(void)
 {
@@ -108,6 +109,7 @@ wait_for_mieq_init(void)
     }
 }
 
+_X_NOTSAN
 static inline void
 signal_mieq_init(void)
 {
commit 7d6ebf3f4e4d517bb846d15a5deb131da19a267c
Author: Jeremy Huddleston Sequoia <jeremyhu at apple.com>
Date:   Mon Sep 19 00:21:44 2016 -0700

    XQuartz: Adopt input_lock() and input_unlock()
    
    This allows us to remove darwinEvents_lock() and darwinEvents_unlock()
    and remove the serverRunning hack from dix
    
    Signed-off-by: Jeremy Huddleston Sequoia <jeremyhu at apple.com>

diff --git a/dix/main.c b/dix/main.c
index 0fa561e..4947062 100644
--- a/dix/main.c
+++ b/dix/main.c
@@ -120,12 +120,6 @@ Equipment Corporation.
 
 extern void Dispatch(void);
 
-#ifdef XQUARTZ
-BOOL serverRunning;
-pthread_mutex_t serverRunningMutex = PTHREAD_MUTEX_INITIALIZER;
-pthread_cond_t serverRunningCond = PTHREAD_COND_INITIALIZER;
-#endif
-
 CallbackListPtr RootWindowFinalizeCallback = NULL;
 
 int
@@ -286,27 +280,12 @@ dix_main(int argc, char *argv[], char *envp[])
             }
         }
 
-#ifdef XQUARTZ
-        /* Let the other threads know the server is done with its init */
-        pthread_mutex_lock(&serverRunningMutex);
-        serverRunning = TRUE;
-        pthread_cond_broadcast(&serverRunningCond);
-        pthread_mutex_unlock(&serverRunningMutex);
-#endif
-
         NotifyParentProcess();
 
         InputThreadInit();
 
         Dispatch();
 
-#ifdef XQUARTZ
-        /* Let the other threads know the server is no longer running */
-        pthread_mutex_lock(&serverRunningMutex);
-        serverRunning = FALSE;
-        pthread_mutex_unlock(&serverRunningMutex);
-#endif
-
         UndisplayDevices();
         DisableAllDevices();
 
diff --git a/hw/xquartz/X11Application.m b/hw/xquartz/X11Application.m
index 19e9451..768eecf 100644
--- a/hw/xquartz/X11Application.m
+++ b/hw/xquartz/X11Application.m
@@ -1311,9 +1311,7 @@ untrusted_str(NSEvent *e)
 #endif
 
 extern void
-darwinEvents_lock(void);
-extern void
-darwinEvents_unlock(void);
+wait_for_mieq_init(void);
 
 - (void) sendX11NSEvent:(NSEvent *)e
 {
@@ -1329,8 +1327,7 @@ darwinEvents_unlock(void);
 
     if (!darwinTabletCurrent) {
         /* Ensure that the event system is initialized */
-        darwinEvents_lock();
-        darwinEvents_unlock();
+        wait_for_mieq_init();
         assert(darwinTabletStylus);
 
         tilt = NSZeroPoint;
diff --git a/hw/xquartz/darwinEvents.c b/hw/xquartz/darwinEvents.c
index 7f34e0c..a3b70f5 100644
--- a/hw/xquartz/darwinEvents.c
+++ b/hw/xquartz/darwinEvents.c
@@ -92,10 +92,30 @@ static pthread_mutex_t fd_add_lock = PTHREAD_MUTEX_INITIALIZER;
 static pthread_cond_t fd_add_ready_cond = PTHREAD_COND_INITIALIZER;
 static pthread_t fd_add_tid = NULL;
 
-static InternalEvent* darwinEvents = NULL;
+static BOOL mieqInitialized;
+static pthread_mutex_t mieqInitializedMutex = PTHREAD_MUTEX_INITIALIZER;
+static pthread_cond_t mieqInitializedCond = PTHREAD_COND_INITIALIZER;
 
-static pthread_mutex_t mieq_lock = PTHREAD_MUTEX_INITIALIZER;
-static pthread_cond_t mieq_ready_cond = PTHREAD_COND_INITIALIZER;
+extern inline void
+wait_for_mieq_init(void)
+{
+    if (!mieqInitialized) {
+        pthread_mutex_lock(&mieqInitializedMutex);
+        while (!mieqInitialized) {
+            pthread_cond_wait(&mieqInitializedCond, &mieqInitializedMutex);
+        }
+        pthread_mutex_unlock(&mieqInitializedMutex);
+    }
+}
+
+static inline void
+signal_mieq_init(void)
+{
+    pthread_mutex_lock(&mieqInitializedMutex);
+    mieqInitialized = TRUE;
+    pthread_cond_broadcast(&mieqInitializedCond);
+    pthread_mutex_unlock(&mieqInitializedMutex);
+}
 
 /*** Pthread Magics ***/
 static pthread_t
@@ -113,35 +133,6 @@ create_thread(void *(*func)(void *), void *arg)
     return tid;
 }
 
-void
-darwinEvents_lock(void);
-void
-darwinEvents_lock(void)
-{
-    int err;
-    if ((err = pthread_mutex_lock(&mieq_lock))) {
-        ErrorF("%s:%s:%d: Failed to lock mieq_lock: %d\n",
-               __FILE__, __FUNCTION__, __LINE__, err);
-        xorg_backtrace();
-    }
-    if (darwinEvents == NULL) {
-        pthread_cond_wait(&mieq_ready_cond, &mieq_lock);
-    }
-}
-
-void
-darwinEvents_unlock(void);
-void
-darwinEvents_unlock(void)
-{
-    int err;
-    if ((err = pthread_mutex_unlock(&mieq_lock))) {
-        ErrorF("%s:%s:%d: Failed to unlock mieq_lock: %d\n",
-               __FILE__, __FUNCTION__, __LINE__, err);
-        xorg_backtrace();
-    }
-}
-
 /*
  * DarwinPressModifierKey
  * Press or release the given modifier key (one of NX_MODIFIERKEY_* constants)
@@ -379,24 +370,11 @@ DarwinEQInit(void)
     mieqInit();
     mieqSetHandler(ET_XQuartz, DarwinEventHandler);
 
-    /* Note that this *could* cause a potential async issue, since we're checking
-     * darwinEvents without holding the lock, but darwinEvents is only ever set
-     * here, so I don't bother.
-     */
-    if (!darwinEvents) {
-        darwinEvents = InitEventList(GetMaximumEventsNum());
-
-        if (!darwinEvents)
-            FatalError("Couldn't allocate event buffer\n");
-
-        darwinEvents_lock();
-        pthread_cond_broadcast(&mieq_ready_cond);
-        darwinEvents_unlock();
-    }
-
     if (!fd_add_tid)
         fd_add_tid = create_thread(DarwinProcessFDAdditionQueue_thread, NULL);
 
+    signal_mieq_init();
+
     return TRUE;
 }
 
@@ -437,7 +415,7 @@ DarwinPokeEQ(void)
 void
 DarwinInputReleaseButtonsAndKeys(DeviceIntPtr pDev)
 {
-    darwinEvents_lock();
+    input_lock();
     {
         int i;
         if (pDev->button) {
@@ -458,7 +436,7 @@ DarwinInputReleaseButtonsAndKeys(DeviceIntPtr pDev)
             }
         }
         DarwinPokeEQ();
-    } darwinEvents_unlock();
+    } input_unlock();
 }
 
 void
@@ -470,12 +448,6 @@ DarwinSendTabletEvents(DeviceIntPtr pDev, int ev_type, int ev_button,
     ScreenPtr screen;
     ValuatorMask valuators;
 
-    if (!darwinEvents) {
-        DEBUG_LOG("%s called before darwinEvents was initialized\n",
-                  __FUNCTION__);
-        return;
-    }
-
     screen = miPointerGetScreen(pDev);
     if (!screen) {
         DEBUG_LOG("%s called before screen was initialized\n",
@@ -498,7 +470,7 @@ DarwinSendTabletEvents(DeviceIntPtr pDev, int ev_type, int ev_button,
     valuator_mask_set_double(&valuators, 3, XQUARTZ_VALUATOR_LIMIT * tilt_x);
     valuator_mask_set_double(&valuators, 4, XQUARTZ_VALUATOR_LIMIT * tilt_y);
 
-    darwinEvents_lock();
+    input_lock();
     {
         if (ev_type == ProximityIn || ev_type == ProximityOut) {
             QueueProximityEvents(pDev, ev_type, &valuators);
@@ -507,7 +479,7 @@ DarwinSendTabletEvents(DeviceIntPtr pDev, int ev_type, int ev_button,
                                &valuators);
         }
         DarwinPokeEQ();
-    } darwinEvents_unlock();
+    } input_unlock();
 }
 
 void
@@ -519,12 +491,6 @@ DarwinSendPointerEvents(DeviceIntPtr pDev, int ev_type, int ev_button,
     ScreenPtr screen;
     ValuatorMask valuators;
 
-    if (!darwinEvents) {
-        DEBUG_LOG("%s called before darwinEvents was initialized\n",
-                  __FUNCTION__);
-        return;
-    }
-
     screen = miPointerGetScreen(pDev);
     if (!screen) {
         DEBUG_LOG("%s called before screen was initialized\n",
@@ -587,29 +553,22 @@ DarwinSendPointerEvents(DeviceIntPtr pDev, int ev_type, int ev_button,
             valuator_mask_set_double(&valuators, 3, pointer_dy);
     }
 
-    darwinEvents_lock();
+    input_lock();
     {
         QueuePointerEvents(pDev, ev_type, ev_button, POINTER_ABSOLUTE,
                            &valuators);
         DarwinPokeEQ();
-    } darwinEvents_unlock();
+    } input_unlock();
 }
 
 void
 DarwinSendKeyboardEvents(int ev_type, int keycode)
 {
-
-    if (!darwinEvents) {
-        DEBUG_LOG(
-            "DarwinSendKeyboardEvents called before darwinEvents was initialized\n");
-        return;
-    }
-
-    darwinEvents_lock();
+    input_lock();
     {
         QueueKeyboardEvents(darwinKeyboard, ev_type, keycode + MIN_KEYCODE);
         DarwinPokeEQ();
-    } darwinEvents_unlock();
+    } input_unlock();
 }
 
 /* Send the appropriate number of button clicks to emulate scroll wheel */
@@ -618,12 +577,6 @@ DarwinSendScrollEvents(double scroll_x, double scroll_y) {
     ScreenPtr screen;
     ValuatorMask valuators;
 
-    if (!darwinEvents) {
-        DEBUG_LOG(
-            "DarwinSendScrollEvents called before darwinEvents was initialized\n");
-        return;
-    }
-
     screen = miPointerGetScreen(darwinPointer);
     if (!screen) {
         DEBUG_LOG(
@@ -635,12 +588,12 @@ DarwinSendScrollEvents(double scroll_x, double scroll_y) {
     valuator_mask_set_double(&valuators, 4, scroll_y);
     valuator_mask_set_double(&valuators, 5, scroll_x);
 
-    darwinEvents_lock();
+    input_lock();
     {
         QueuePointerEvents(darwinPointer, MotionNotify, 0,
                            POINTER_RELATIVE, &valuators);
         DarwinPokeEQ();
-    } darwinEvents_unlock();
+    } input_unlock();
 }
 
 /* Send the appropriate KeyPress/KeyRelease events to GetKeyboardEvents to
@@ -682,9 +635,11 @@ DarwinSendDDXEvent(int type, int argc, ...)
         va_end(args);
     }
 
-    darwinEvents_lock();
+    wait_for_mieq_init();
+
+    input_lock();
     {
         mieqEnqueue(NULL, (InternalEvent *)&e);
         DarwinPokeEQ();
-    } darwinEvents_unlock();
+    } input_unlock();
 }
diff --git a/mi/mieq.c b/mi/mieq.c
index e31e4f1..a6e867d 100644
--- a/mi/mieq.c
+++ b/mi/mieq.c
@@ -87,24 +87,6 @@ typedef struct _EventQueue {
 
 static EventQueueRec miEventQueue;
 
-#ifdef XQUARTZ
-extern BOOL serverRunning;
-extern pthread_mutex_t serverRunningMutex;
-extern pthread_cond_t serverRunningCond;
-
-static inline void
-wait_for_server_init(void)
-{
-    /* If the server hasn't finished initializing, wait for it... */
-    if (!serverRunning) {
-        pthread_mutex_lock(&serverRunningMutex);
-        while (!serverRunning)
-            pthread_cond_wait(&serverRunningCond, &serverRunningMutex);
-        pthread_mutex_unlock(&serverRunningMutex);
-    }
-}
-#endif
-
 static size_t
 mieqNumEnqueued(EventQueuePtr eventQueue)
 {
@@ -219,10 +201,6 @@ mieqEnqueue(DeviceIntPtr pDev, InternalEvent *e)
     Time time;
     size_t n_enqueued;
 
-#ifdef XQUARTZ
-    wait_for_server_init();
-#endif
-
     verify_internal_event(e);
 
     n_enqueued = mieqNumEnqueued(&miEventQueue);
diff --git a/mi/mipointer.c b/mi/mipointer.c
index 01f3bd2..75be1ae 100644
--- a/mi/mipointer.c
+++ b/mi/mipointer.c
@@ -709,12 +709,6 @@ miPointerGetPosition(DeviceIntPtr pDev, int *x, int *y)
     *y = MIPOINTER(pDev)->y;
 }
 
-#ifdef XQUARTZ
-#include <pthread.h>
-void darwinEvents_lock(void);
-void darwinEvents_unlock(void);
-#endif
-
 /**
  * Move the device's pointer to the x/y coordinates on the given screen.
  * This function generates and enqueues pointer events.
@@ -752,13 +746,7 @@ miPointerMove(DeviceIntPtr pDev, ScreenPtr pScreen, int x, int y)
                                POINTER_NORAW, &mask);
 
     input_lock();
-#ifdef XQUARTZ
-    darwinEvents_lock();
-#endif
     for (i = 0; i < nevents; i++)
         mieqEnqueue(pDev, &mipointermove_events[i]);
-#ifdef XQUARTZ
-    darwinEvents_unlock();
-#endif
     input_unlock();
 }
diff --git a/test/ddxstubs.c b/test/ddxstubs.c
index 3647dc5..58bc0c4 100644
--- a/test/ddxstubs.c
+++ b/test/ddxstubs.c
@@ -83,26 +83,10 @@ LegalModifier(unsigned int key, DeviceIntPtr pDev)
 }
 
 #ifdef XQUARTZ
-#include <pthread.h>
-
-BOOL serverRunning = TRUE;
-pthread_mutex_t serverRunningMutex = PTHREAD_MUTEX_INITIALIZER;
-pthread_cond_t serverRunningCond = PTHREAD_COND_INITIALIZER;
-
 int darwinMainScreenX = 0;
 int darwinMainScreenY = 0;
 
 BOOL no_configure_window = FALSE;
-
-void
-darwinEvents_lock(void)
-{
-}
-
-void
-darwinEvents_unlock(void)
-{
-}
 #endif
 
 #ifdef DDXBEFORERESET
commit 8bc4727f475321a8adcbbd859f3f8dd9eeb64aa4
Author: Jeremy Huddleston Sequoia <jeremyhu at apple.com>
Date:   Sun Sep 18 23:17:19 2016 -0700

    XQuartz: pbproxy shouldn't need to wait for server initialization.
    
    Just block on the socket like every other client does.
    
    Signed-off-by: Jeremy Huddleston Sequoia <jeremyhu at apple.com>

diff --git a/hw/xquartz/pbproxy/app-main.m b/hw/xquartz/pbproxy/app-main.m
index 37b5782..eda9a9e 100644
--- a/hw/xquartz/pbproxy/app-main.m
+++ b/hw/xquartz/pbproxy/app-main.m
@@ -40,9 +40,6 @@ CFStringRef app_prefs_domain_cfstr;
 
 /* Stubs */
 char *display = NULL;
-BOOL serverRunning = YES;
-pthread_mutex_t serverRunningMutex = PTHREAD_MUTEX_INITIALIZER;
-pthread_cond_t serverRunningCond = PTHREAD_COND_INITIALIZER;
 
 static void
 signal_handler(int sig)
diff --git a/hw/xquartz/pbproxy/main.m b/hw/xquartz/pbproxy/main.m
index abedb08..2d2f761 100644
--- a/hw/xquartz/pbproxy/main.m
+++ b/hw/xquartz/pbproxy/main.m
@@ -48,22 +48,6 @@ BOOL xpbproxy_is_standalone = NO;
 
 x_selection *_selection_object;
 
-extern BOOL serverRunning;
-extern pthread_mutex_t serverRunningMutex;
-extern pthread_cond_t serverRunningCond;
-
-static inline void
-wait_for_server_init(void)
-{
-    /* If the server hasn't finished initializing, wait for it... */
-    if (!serverRunning) {
-        pthread_mutex_lock(&serverRunningMutex);
-        while (!serverRunning)
-            pthread_cond_wait(&serverRunningCond, &serverRunningMutex);
-        pthread_mutex_unlock(&serverRunningMutex);
-    }
-}
-
 static int
 x_io_error_handler(Display *dpy)
 {
@@ -97,8 +81,6 @@ xpbproxy_run(void)
     NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
     size_t i;
 
-    wait_for_server_init();
-
     for (i = 0, xpbproxy_dpy = NULL; !xpbproxy_dpy && i < 5; i++) {
         xpbproxy_dpy = XOpenDisplay(NULL);
 
commit 81493d30981d7deb38f57bca2a35487add5ea509
Author: Jeremy Huddleston Sequoia <jeremyhu at apple.com>
Date:   Sun Sep 18 23:13:20 2016 -0700

    XQuartz: Remove X11ApplicationFatalError
    
    AppKit handles crashes on app launch with their own dialog now, so we shouldn't need to do this ourselves.
    
    Signed-off-by: Jeremy Huddleston Sequoia <jeremyhu at apple.com>

diff --git a/hw/xquartz/X11Application.h b/hw/xquartz/X11Application.h
index 87cba6d..740a807 100644
--- a/hw/xquartz/X11Application.h
+++ b/hw/xquartz/X11Application.h
@@ -87,9 +87,6 @@ Bool
 X11ApplicationCanEnterRandR(void);
 
 void
-X11ApplicationFatalError(const char *f, va_list args) __printflike(1, 0);
-
-void
 X11ApplicationMain(int argc, char **argv, char **envp);
 
 #define PREFS_APPSMENU                "apps_menu"
diff --git a/hw/xquartz/X11Application.m b/hw/xquartz/X11Application.m
index 9a22909..19e9451 100644
--- a/hw/xquartz/X11Application.m
+++ b/hw/xquartz/X11Application.m
@@ -84,7 +84,6 @@ static dispatch_queue_t eventTranslationQueue;
 
 extern Bool noTestExtensions;
 extern Bool noRenderExtension;
-extern BOOL serverRunning;
 
 #if MAC_OS_X_VERSION_MIN_REQUIRED >= 1050
 static TISInputSourceRef last_key_layout;
@@ -1096,53 +1095,6 @@ X11ApplicationCanEnterRandR(void)
     }
 }
 
-void
-X11ApplicationFatalError(const char *f, va_list args)
-{
-#ifdef HAVE_LIBDISPATCH
-    NSString *title, *msg;
-    char *error_msg;
-
-    /* This is called by FatalError() in the server thread just before
-     * we would abort.  If the server never got off the ground, We should
-     * inform the user of the error rather than letting the ever-so-friendly
-     * CrashReporter do it for us.
-     *
-     * This also has the benefit of forcing user interaction rather than
-     * allowing an infinite throttled-restart if the crash occurs before
-     * we can drain the launchd socket.
-     */
-
-    if (serverRunning) {
-        return;
-    }
-
-    title = NSLocalizedString(@"The application X11 could not be opened.",
-                              @"Dialog title when encountering a fatal error");
-    msg = NSLocalizedString(
-        @"An error occurred while starting the X11 server: \"%s\"\n\nClick Quit to quit X11. Click Report to see more details or send a report to Apple.",
-        @"Dialog when encountering a fatal error");
-
-    vasprintf(&error_msg, f, args);
-    msg = [NSString stringWithFormat:msg, error_msg];
-
-    /* We want the AppKit thread to actually service the alert or we will race [NSApp run] and create an
-     * 'NSInternalInconsistencyException', reason: 'NSApp with wrong _running count'
-     */
-    dispatch_sync(dispatch_get_main_queue(), ^{
-                      if (NSAlertDefaultReturn ==
-                          NSRunAlertPanel (title, @"%@",
-                                           NSLocalizedString (@"Quit", @""),
-                                           NSLocalizedString (@"Report...", @""),
-                                           nil, msg)) {
-                          exit (EXIT_FAILURE);
-                      }
-                  });
-
-    /* fall back to caller to do the abort() in the DIX */
-#endif
-}
-
 static void
 check_xinitrc(void)
 {
diff --git a/hw/xquartz/darwin.c b/hw/xquartz/darwin.c
index c0d0b8a..36c149c 100644
--- a/hw/xquartz/darwin.c
+++ b/hw/xquartz/darwin.c
@@ -680,7 +680,6 @@ InitOutput(ScreenInfo *pScreenInfo, int argc, char **argv)
 void
 OsVendorFatalError(const char *f, va_list args)
 {
-    X11ApplicationFatalError(f, args);
 }
 
 /*
commit 9153ec8464336c280f2a6e79ffa443104bbeb98c
Author: Jeremy Huddleston Sequoia <jeremyhu at apple.com>
Date:   Sun Sep 18 22:45:16 2016 -0700

    XQuartz: Don't respond to SIGALRM on the AppKit thread
    
    ==================
    WARNING: ThreadSanitizer: data race (pid=69627)
      Write of size 8 at 0x00010dae73f8 by main thread (mutexes: write M262):
        #0 SmartScheduleTimer utils.c:1245 (X11.bin+0x0001004b21f9)
        #1 __tsan::CallUserSignalHandler(__tsan::ThreadState*, bool, bool, bool, int, my_siginfo_t*, void*) <null>:144 (libclang_rt.tsan_osx_dynamic.dylib+0x0000000279f6)
        #2 __CFRunLoopRun <null>:77 (CoreFoundation+0x000000087e17)
        #3 X11ControllerMain X11Controller.m:984 (X11.bin+0x00010002a062)
        #4 server_main quartzStartup.c:127 (X11.bin+0x000100039b6b)
        #5 do_start_x11_server bundle-main.c:436 (X11.bin+0x0001000022c5)
        #6 _Xstart_x11_server mach_startupServer.c:189 (X11.bin+0x0001000042a9)
        #7 mach_startup_server mach_startupServer.c:399 (X11.bin+0x000100004b44)
        #8 mach_msg_server mach_msg.c:563 (libsystem_kernel.dylib+0x000000012186)
        #9 start <null>:29 (libdyld.dylib+0x000000005254)
    
      Previous read of size 8 at 0x00010dae73f8 by thread T7:
        [failed to restore the stack]
    
      Location is global 'SmartScheduleTime' at 0x00010dae73f8 (X11.bin+0x0001005b03f8)
    
      Mutex M262 (0x7d300000bd10) created at:
        #0 pthread_mutex_init <null>:144 (libclang_rt.tsan_osx_dynamic.dylib+0x0000000253c3)
        #1 __CFRunLoopCreate <null>:77 (CoreFoundation+0x000000054e63)
        #2 X11ControllerMain X11Controller.m:984 (X11.bin+0x00010002a062)
        #3 server_main quartzStartup.c:127 (X11.bin+0x000100039b6b)
        #4 do_start_x11_server bundle-main.c:436 (X11.bin+0x0001000022c5)
        #5 _Xstart_x11_server mach_startupServer.c:189 (X11.bin+0x0001000042a9)
        #6 mach_startup_server mach_startupServer.c:399 (X11.bin+0x000100004b44)
        #7 mach_msg_server mach_msg.c:563 (libsystem_kernel.dylib+0x000000012186)
        #8 start <null>:29 (libdyld.dylib+0x000000005254)
    
      Thread T7 (tid=4051693, running) created by main thread at:
        #0 pthread_create <null>:144 (libclang_rt.tsan_osx_dynamic.dylib+0x000000024490)
        #1 create_thread quartzStartup.c:78 (X11.bin+0x0001000398dd)
        #2 QuartzInitServer quartzStartup.c:95 (X11.bin+0x000100039813)
        #3 X11ApplicationMain X11Application.m:1286 (X11.bin+0x00010001c804)
        #4 X11ControllerMain X11Controller.m:984 (X11.bin+0x00010002a062)
        #5 server_main quartzStartup.c:127 (X11.bin+0x000100039b6b)
        #6 do_start_x11_server bundle-main.c:436 (X11.bin+0x0001000022c5)
        #7 _Xstart_x11_server mach_startupServer.c:189 (X11.bin+0x0001000042a9)
        #8 mach_startup_server mach_startupServer.c:399 (X11.bin+0x000100004b44)
        #9 mach_msg_server mach_msg.c:563 (libsystem_kernel.dylib+0x000000012186)
        #10 start <null>:29 (libdyld.dylib+0x000000005254)
    
    SUMMARY: ThreadSanitizer: data race utils.c:1245 in SmartScheduleTimer
    ==================
    ==================
    WARNING: ThreadSanitizer: signal handler spoils errno (pid=69627)
        #0 SmartScheduleTimer utils.c:1244 (X11.bin+0x0001004b21a0)
        #1 __CFRunLoopRun <null>:77 (CoreFoundation+0x000000087e17)
        #2 X11ControllerMain X11Controller.m:984 (X11.bin+0x00010002a062)
        #3 server_main quartzStartup.c:127 (X11.bin+0x000100039b6b)
        #4 do_start_x11_server bundle-main.c:436 (X11.bin+0x0001000022c5)
        #5 _Xstart_x11_server mach_startupServer.c:189 (X11.bin+0x0001000042a9)
        #6 mach_startup_server mach_startupServer.c:399 (X11.bin+0x000100004b44)
        #7 mach_msg_server mach_msg.c:563 (libsystem_kernel.dylib+0x000000012186)
        #8 start <null>:29 (libdyld.dylib+0x000000005254)
    
    SUMMARY: ThreadSanitizer: signal handler spoils errno utils.c:1244 in SmartScheduleTimer
    ==================
    
    Signed-off-by: Jeremy Huddleston Sequoia <jeremyhu at apple.com>

diff --git a/hw/xquartz/quartzStartup.c b/hw/xquartz/quartzStartup.c
index 4dc4dd6..bb92b6d 100644
--- a/hw/xquartz/quartzStartup.c
+++ b/hw/xquartz/quartzStartup.c
@@ -95,6 +95,15 @@ QuartzInitServer(int argc, char **argv, char **envp)
     if (!create_thread(server_thread, args)) {
         FatalError("can't create secondary thread\n");
     }
+
+    /* Block signals on the AppKit thread that the X11 expects to handle on its thread */
+    sigset_t set;
+    sigemptyset(&set);
+    sigaddset(&set, SIGALRM);
+#ifdef BUSFAULT
+    sigaddset(&set, SIGBUS);
+#endif
+    pthread_sigmask(SIG_BLOCK, &set, NULL);
 }
 
 int
commit 2740dc1937e8ab32b4930f4086c302e6602a7bad
Author: Jeremy Huddleston Sequoia <jeremyhu at apple.com>
Date:   Mon Sep 19 01:25:13 2016 -0700

    dix: Silence TSan warnings when checking for pending input
    
    V2: Moves InputCheckPending() into dix.h
    
    Bumps required version of xproto to 7.0.30
    
    ==================
    WARNING: ThreadSanitizer: data race (pid=4943)
      Read of size 4 at 0x00010c4e3854 by thread T8:
        #0 WaitForSomething WaitFor.c:237 (X11.bin+0x00010049216c)
        #1 Dispatch dispatch.c:413 (X11.bin+0x000100352ed9)
        #2 dix_main main.c:287 (X11.bin+0x00010036e894)
        #3 server_thread quartzStartup.c:66 (X11.bin+0x000100039e63)
    
      Previous write of size 4 at 0x00010c4e3854 by thread T12 (mutexes: write M856, write M1976):
        #0 mieqEnqueue mieq.c:263 (X11.bin+0x000100448d14)
        #1 DarwinSendDDXEvent darwinEvents.c:641 (X11.bin+0x000100033613)
        #2 DarwinProcessFDAdditionQueue_thread darwinEvents.c:338 (X11.bin+0x000100032039)
    
      Location is global 'miEventQueue' at 0x00010c4e3850 (X11.bin+0x0001005ab854)
    
      Mutex M856 (0x00010c4c8c80) created at:
        #0 pthread_mutex_lock <null>:144 (libclang_rt.tsan_osx_dynamic.dylib+0x0000000321fe)
        #1 DarwinListenOnOpenFD darwinEvents.c:300 (X11.bin+0x000100031607)
        #2 socket_handoff bundle-main.c:288 (X11.bin+0x000100002b40)
        #3 __do_request_fd_handoff_socket_block_invoke bundle-main.c:379 (X11.bin+0x0001000029ba)
        #4 __tsan::invoke_and_release_block(void*) <null>:144 (libclang_rt.tsan_osx_dynamic.dylib+0x00000005d97b)
        #5 _dispatch_client_callout <null>:33 (libdispatch.dylib+0x0000000020ef)
    
      Mutex M1976 (0x00010c4e3d68) created at:
        #0 pthread_mutex_init <null>:144 (libclang_rt.tsan_osx_dynamic.dylib+0x0000000253c3)
        #1 input_lock inputthread.c:103 (X11.bin+0x00010049fd10)
        #2 TimerSet WaitFor.c:343 (X11.bin+0x0001004926c2)
        #3 RootlessQueueRedisplay rootlessScreen.c:594 (X11.bin+0x000100065d7f)
        #4 RootlessInstallColormap rootlessScreen.c:514 (X11.bin+0x000100069f1a)
        #5 miSpriteInstallColormap misprite.c:562 (X11.bin+0x000100467095)
        #6 miCreateDefColormap micmap.c:270 (X11.bin+0x000100440399)
        #7 DarwinScreenInit darwin.c:285 (X11.bin+0x0001000303bb)
        #8 AddScreen dispatch.c:3908 (X11.bin+0x00010036c417)
        #9 InitOutput darwin.c:671 (X11.bin+0x00010002fdeb)
        #10 dix_main main.c:197 (X11.bin+0x00010036e228)
        #11 server_thread quartzStartup.c:66 (X11.bin+0x000100039e63)
    
      Thread T8 (tid=4198779, running) created by main thread at:
        #0 pthread_create <null>:144 (libclang_rt.tsan_osx_dynamic.dylib+0x000000024490)
        #1 create_thread quartzStartup.c:78 (X11.bin+0x000100039dad)
        #2 QuartzInitServer quartzStartup.c:95 (X11.bin+0x000100039c16)
        #3 X11ApplicationMain X11Application.m:1238 (X11.bin+0x00010001cde4)
        #4 X11ControllerMain X11Controller.m:984 (X11.bin+0x00010002a642)
        #5 server_main quartzStartup.c:136 (X11.bin+0x00010003a03b)
        #6 do_start_x11_server bundle-main.c:436 (X11.bin+0x000100002eb5)
        #7 _Xstart_x11_server mach_startupServer.c:189 (X11.bin+0x000100004e99)
        #8 mach_startup_server mach_startupServer.c:399 (X11.bin+0x000100005734)
        #9 mach_msg_server mach_msg.c:563 (libsystem_kernel.dylib+0x000000012186)
        #10 start <null>:29 (libdyld.dylib+0x000000005254)
    
      Thread T12 (tid=4198797, running) created by thread T8 at:
        #0 pthread_create <null>:144 (libclang_rt.tsan_osx_dynamic.dylib+0x000000024490)
        #1 create_thread darwinEvents.c:121 (X11.bin+0x000100031ecf)
        #2 DarwinEQInit darwinEvents.c:365 (X11.bin+0x000100031860)
        #3 InitInput darwin.c:571 (X11.bin+0x00010002ea09)
        #4 dix_main main.c:261 (X11.bin+0x00010036e7ce)
        #5 server_thread quartzStartup.c:66 (X11.bin+0x000100039e63)
    
    SUMMARY: ThreadSanitizer: data race WaitFor.c:237 in WaitForSomething
    ==================
    ==================
    WARNING: ThreadSanitizer: data race (pid=22841)
      Write of size 4 at 0x000105bbd864 by main thread (mutexes: write M1945):
        #0 mieqEnqueue mieq.c:263 (X11.bin+0x000100448cf4)
        #1 DarwinSendDDXEvent darwinEvents.c:642 (X11.bin+0x000100033693)
        #2 -[X11Controller set_window_menu:] X11Controller.m:275 (X11.bin+0x0001000222fd)
        #3 -[X11Application set_window_menu:] X11Application.m:486 (X11.bin+0x000100018b44)
        #4 -[X11Application handleMachMessage:] X11Application.m:177 (X11.bin+0x000100016678)
        #5 __NSFireMachPort <null>:69 (Foundation+0x00000009b62b)
        #6 X11ControllerMain X11Controller.m:984 (X11.bin+0x00010002a5f2)
        #7 server_main quartzStartup.c:136 (X11.bin+0x000100039ffb)
        #8 do_start_x11_server bundle-main.c:436 (X11.bin+0x000100002e65)
        #9 _Xstart_x11_server mach_startupServer.c:189 (X11.bin+0x000100004e49)
        #10 mach_startup_server mach_startupServer.c:399 (X11.bin+0x0001000056e4)
        #11 mach_msg_server mach_msg.c:563 (libsystem_kernel.dylib+0x000000012186)
        #12 start <null>:29 (libdyld.dylib+0x000000005254)
    
      Previous read of size 4 at 0x000105bbd864 by thread T7:
        #0 Dispatch dispatch.c:434 (X11.bin+0x000100352fc8)
        #1 dix_main main.c:287 (X11.bin+0x00010036e874)
        #2 server_thread quartzStartup.c:66 (X11.bin+0x000100039e23)
    
      Location is global 'miEventQueue' at 0x000105bbd860 (X11.bin+0x0001005ab864)
    
      Mutex M1945 (0x000105bbdd78) created at:
        #0 pthread_mutex_init <null>:144 (libclang_rt.tsan_osx_dynamic.dylib+0x0000000253c3)
        #1 input_lock inputthread.c:103 (X11.bin+0x00010049fd10)
        #2 TimerSet WaitFor.c:348 (X11.bin+0x0001004926c2)
        #3 RootlessQueueRedisplay rootlessScreen.c:594 (X11.bin+0x000100065d3f)
        #4 RootlessInstallColormap rootlessScreen.c:514 (X11.bin+0x000100069eda)
        #5 miSpriteInstallColormap misprite.c:562 (X11.bin+0x000100467075)
        #6 miCreateDefColormap micmap.c:270 (X11.bin+0x000100440379)
        #7 DarwinScreenInit darwin.c:285 (X11.bin+0x00010003036b)
        #8 AddScreen dispatch.c:3914 (X11.bin+0x00010036c3f7)
        #9 InitOutput darwin.c:671 (X11.bin+0x00010002fd9b)
        #10 dix_main main.c:197 (X11.bin+0x00010036e208)
        #11 server_thread quartzStartup.c:66 (X11.bin+0x000100039e23)
    
      Thread T7 (tid=4257217, running) created by main thread at:
        #0 pthread_create <null>:144 (libclang_rt.tsan_osx_dynamic.dylib+0x000000024490)
        #1 create_thread quartzStartup.c:78 (X11.bin+0x000100039d6d)
        #2 QuartzInitServer quartzStartup.c:95 (X11.bin+0x000100039bd6)
        #3 X11ApplicationMain X11Application.m:1238 (X11.bin+0x00010001cd94)
        #4 X11ControllerMain X11Controller.m:984 (X11.bin+0x00010002a5f2)
        #5 server_main quartzStartup.c:136 (X11.bin+0x000100039ffb)
        #6 do_start_x11_server bundle-main.c:436 (X11.bin+0x000100002e65)
        #7 _Xstart_x11_server mach_startupServer.c:189 (X11.bin+0x000100004e49)
        #8 mach_startup_server mach_startupServer.c:399 (X11.bin+0x0001000056e4)
        #9 mach_msg_server mach_msg.c:563 (libsystem_kernel.dylib+0x000000012186)
        #10 start <null>:29 (libdyld.dylib+0x000000005254)
    
    SUMMARY: ThreadSanitizer: data race mieq.c:263 in mieqEnqueue
    ==================
    
    Signed-off-by: Jeremy Huddleston Sequoia <jeremyhu at apple.com>
    Reviewed-by: Keith Packard <keithp at keithp.com>

diff --git a/configure.ac b/configure.ac
index c09b854..922ee0c 100644
--- a/configure.ac
+++ b/configure.ac
@@ -812,7 +812,7 @@ APPLEWMPROTO="applewmproto >= 1.4"
 LIBXSHMFENCE="xshmfence >= 1.1"
 
 dnl Required modules
-XPROTO="xproto >= 7.0.28"
+XPROTO="xproto >= 7.0.30"
 RANDRPROTO="randrproto >= 1.5.0"
 RENDERPROTO="renderproto >= 0.11"
 XEXTPROTO="xextproto >= 7.2.99.901"
diff --git a/dix/dispatch.c b/dix/dispatch.c
index 26a461b..adcc9cf 100644
--- a/dix/dispatch.c
+++ b/dix/dispatch.c
@@ -195,7 +195,7 @@ UpdateCurrentTime(void)
     systime.milliseconds = GetTimeInMillis();
     if (systime.milliseconds < currentTime.milliseconds)
         systime.months++;
-    if (*checkForInput[0] != *checkForInput[1])
+    if (InputCheckPending())
         ProcessInputEvents();
     if (CompareTimeStamps(systime, currentTime) == LATER)
         currentTime = systime;
@@ -395,7 +395,6 @@ Dispatch(void)
 {
     int result;
     ClientPtr client;
-    HWEventQueuePtr *icheck = checkForInput;
     long start_tick;
 
     nextFreeClientID = 1;
@@ -405,7 +404,7 @@ Dispatch(void)
     init_client_ready();
 
     while (!dispatchException) {
-        if (*icheck[0] != *icheck[1]) {
+        if (InputCheckPending()) {
             ProcessInputEvents();
             FlushIfCriticalOutputPending();
         }
@@ -425,7 +424,7 @@ Dispatch(void)
 
             start_tick = SmartScheduleTime;
             while (!isItTimeToYield) {
-                if (*icheck[0] != *icheck[1])
+                if (InputCheckPending())
                     ProcessInputEvents();
 
                 FlushIfCriticalOutputPending();
diff --git a/include/dix.h b/include/dix.h
index ae9719a..240018b 100644
--- a/include/dix.h
+++ b/include/dix.h
@@ -136,6 +136,12 @@ typedef HWEventQueueType *HWEventQueuePtr;
 
 extern _X_EXPORT HWEventQueuePtr checkForInput[2];
 
+static inline _X_NOTSAN Bool
+InputCheckPending(void)
+{
+    return (*checkForInput[0] != *checkForInput[1]);
+}
+
 typedef struct _TimeStamp {
     CARD32 months;              /* really ~49.7 days */
     CARD32 milliseconds;
diff --git a/os/WaitFor.c b/os/WaitFor.c
index 024df35..7d5aa32 100644
--- a/os/WaitFor.c
+++ b/os/WaitFor.c
@@ -234,7 +234,7 @@ WaitForSomething(Bool are_ready)
         } else
             are_ready = clients_are_ready();
 
-        if (*checkForInput[0] != *checkForInput[1])
+        if (InputCheckPending())
             return FALSE;
 
         if (are_ready) {
commit 7ff8a74945c0cb525a2d197e28426fd098a407cf
Author: Keith Packard <keithp at keithp.com>
Date:   Thu Sep 22 02:53:46 2016 +0300

    os: Clear saved poll events in listen so that edge triggering works
    
    When a client is marked as write blocked, clear any old 'write ready'
    bit in the osfds structure so that a new indication of write ready
    (which is marked as edge trigggered) will trigger the callback.
    
    Signed-off-by: Keith Packard <keithp at keithp.com>
    Reviewed-by: Jeremy Huddleston Sequoia <jeremyhu at apple.com>
    Tested-by: Jeremy Huddleston Sequoia <jeremyhu at apple.com>
    Tested-by: Matthieu Herrb <matthieu at herrb.eu>

diff --git a/os/ospoll.c b/os/ospoll.c
index b00d422..51bd02d 100644
--- a/os/ospoll.c
+++ b/os/ospoll.c
@@ -352,10 +352,14 @@ ospoll_listen(struct ospoll *ospoll, int fd, int xevents)
         epoll_mod(ospoll, osfd);
 #endif
 #if POLL
-        if (xevents & X_NOTIFY_READ)
+        if (xevents & X_NOTIFY_READ) {
             ospoll->fds[pos].events |= POLLIN;
-        if (xevents & X_NOTIFY_WRITE)
+            ospoll->osfds[pos].revents &= ~POLLIN;
+        }
+        if (xevents & X_NOTIFY_WRITE) {
             ospoll->fds[pos].events |= POLLOUT;
+            ospoll->osfds[pos].revents &= ~POLLOUT;
+        }
 #endif
     }
 }
commit 1d365f1ffe0362732b64e565db6ae8af718758f2
Author: Keith Packard <keithp at keithp.com>
Date:   Thu Sep 22 02:53:45 2016 +0300

    os: Ready clients with pending output aren't flushed, so set NewOutputPending
    
    When a client with pending output is ready (has request data pending),
    FlushAllOutput will skip it to get all of the requests processed
    before sending any queued output. That means FlushAllOutput is going
    to return with some output pending to a client which isn't known to be
    write blocked. And that means NewOutputPending needs to be set so that
    FlushAllOutput will get called again to actually go flush this client.
    
    It might be interesting to try just flushing the client to send any
    queued data along the way. This patch just restores the server
    behavior to what it was before the ospoll changes.
    
    Signed-off-by: Keith Packard <keithp at keithp.com>
    Reviewed-by: Jeremy Huddleston Sequoia <jeremyhu at apple.com>
    Tested-by: Jeremy Huddleston Sequoia <jeremyhu at apple.com>
    Tested-by: Matthieu Herrb <matthieu at herrb.eu>

diff --git a/os/io.c b/os/io.c
index ff0ec3d..5ba1e86 100644
--- a/os/io.c
+++ b/os/io.c
@@ -615,7 +615,8 @@ FlushAllOutput(void)
         if (!client_is_ready(client)) {
             oc = (OsCommPtr) client->osPrivate;
             (void) FlushClient(client, oc, (char *) NULL, 0);
-        }
+        } else
+            NewOutputPending = TRUE;
     }
 }
 


More information about the xorg-commit mailing list