xserver: Branch 'XACE-SELINUX' - 161 commits

Eamon Walsh ewalsh at kemper.freedesktop.org
Fri Feb 8 14:40:46 PST 2008


 .gitignore                                                 |    2 
 GL/glx/Makefile.am                                         |    3 
 GL/glx/glxdri.c                                            |   82 -
 GL/glx/indirect_size_get.c                                 |    6 
 Xext/EVI.c                                                 |   15 
 Xext/Makefile.am                                           |    2 
 Xext/cup.c                                                 |    3 
 Xext/dpmsstubs.c                                           |    2 
 Xext/mbuf.c                                                |   40 
 Xext/sampleEVI.c                                           |   29 
 Xext/security.c                                            |    5 
 Xext/shm.c                                                 |   50 
 Xext/xace.c                                                |  227 ---
 Xext/xace.h                                                |   24 
 Xext/xacestr.h                                             |   11 
 Xext/xcalibrate.c                                          |   47 
 Xext/xevie.c                                               |    2 
 Xext/xres.c                                                |   10 
 Xext/xselinux.c                                            |  779 +++++++----
 Xext/xselinux.h                                            |   36 
 Xext/xvdisp.c                                              |   52 
 Xi/chgfctl.c                                               |    7 
 Xi/chgkmap.c                                               |   14 
 Xi/chgprop.c                                               |   10 
 Xi/getdctl.c                                               |    8 
 Xi/grabdev.c                                               |   12 
 Xi/grabdevb.c                                              |   10 
 Xi/grabdevk.c                                              |    9 
 Xi/selectev.c                                              |   11 
 Xi/sendexev.c                                              |   14 
 config/dbus-core.c                                         |   10 
 config/dbus.c                                              |    5 
 config/hal.c                                               |   32 
 configure.ac                                               |   70 -
 dix/devices.c                                              |    3 
 dix/dispatch.c                                             |   13 
 dix/dixfonts.c                                             |    7 
 dix/dixutils.c                                             |    2 
 dix/events.c                                               |    2 
 dix/getevents.c                                            |  165 +-
 dix/main.c                                                 |    4 
 dix/privates.c                                             |    2 
 dix/property.c                                             |  227 +--
 dix/window.c                                               |    7 
 exa/exa.h                                                  |    3 
 exa/exa_accel.c                                            |    8 
 exa/exa_priv.h                                             |    3 
 hw/dmx/glxProxy/Makefile.am                                |    1 
 hw/kdrive/ati/ati_stub.c                                   |    9 
 hw/kdrive/ephyr/ephyr.c                                    |    4 
 hw/kdrive/ephyr/ephyrdriext.c                              |    2 
 hw/kdrive/ephyr/ephyrlog.h                                 |    4 
 hw/kdrive/ephyr/hostx.c                                    |   20 
 hw/kdrive/fbdev/fbinit.c                                   |   12 
 hw/kdrive/src/kdrive.h                                     |    5 
 hw/kdrive/src/kinput.c                                     |   12 
 hw/kdrive/vesa/vesainit.c                                  |   10 
 hw/xfree86/common/xf86Bus.c                                |    6 
 hw/xfree86/common/xf86DPMS.c                               |    5 
 hw/xfree86/common/xf86Init.c                               |   11 
 hw/xfree86/common/xf86MiscExt.c                            |    4 
 hw/xfree86/common/xf86Mode.c                               |   35 
 hw/xfree86/common/xf86Module.h                             |    4 
 hw/xfree86/common/xf86Xinput.c                             |   83 -
 hw/xfree86/ddc/edid.h                                      |   65 
 hw/xfree86/ddc/interpret_edid.c                            |   80 +
 hw/xfree86/ddc/print_edid.c                                |  367 +++--
 hw/xfree86/dixmods/extmod/modinit.c                        |    9 
 hw/xfree86/dixmods/extmod/modinit.h                        |    7 
 hw/xfree86/dixmods/extmod/xf86misc.c                       |   33 
 hw/xfree86/doc/man/xorg.conf.man.pre                       |   38 
 hw/xfree86/dummylib/Makefile.am                            |    2 
 hw/xfree86/dummylib/dixprivates.c                          |   19 
 hw/xfree86/dummylib/xf86getpagesize.c                      |   21 
 hw/xfree86/loader/dixsym.c                                 |    1 
 hw/xfree86/loader/loadmod.c                                |    2 
 hw/xfree86/modes/xf86Crtc.c                                |   18 
 hw/xfree86/modes/xf86Crtc.h                                |    4 
 hw/xfree86/modes/xf86Cursors.c                             |    2 
 hw/xfree86/modes/xf86EdidModes.c                           |   73 -
 hw/xfree86/modes/xf86Rotate.c                              |    3 
 hw/xfree86/os-support/bsd/i386_video.c                     |    2 
 hw/xfree86/os-support/bus/Sbus.c                           |    2 
 hw/xfree86/os-support/hurd/hurd_video.c                    |    4 
 hw/xfree86/os-support/linux/lnx_video.c                    |   11 
 hw/xfree86/os-support/solaris/sun_mouse.c                  |    6 
 hw/xfree86/utils/ioport/ioport.c                           |    1 
 hw/xprint/Makefile.am                                      |    2 
 hw/xprint/pcl/PclMisc.c                                    |   17 
 hw/xprint/pcl/PclWindow.c                                  |    6 
 hw/xprint/ps/PsMisc.c                                      |   17 
 hw/xprint/ps/PsWindow.c                                    |    6 
 hw/xquartz/Makefile.am                                     |   11 
 hw/xquartz/X11Application.h                                |   53 
 hw/xquartz/X11Application.m                                |   75 -
 hw/xquartz/X11Controller.h                                 |    4 
 hw/xquartz/X11Controller.m                                 |   10 
 hw/xquartz/applewm.c                                       |   29 
 hw/xquartz/bundle/Dutch.lproj/InfoPlist.strings            |binary
 hw/xquartz/bundle/Dutch.lproj/Localizable.strings          |binary
 hw/xquartz/bundle/Dutch.lproj/main.nib/keyedobjects.nib    |binary
 hw/xquartz/bundle/French.lproj/InfoPlist.strings           |binary
 hw/xquartz/bundle/French.lproj/Localizable.strings         |binary
 hw/xquartz/bundle/French.lproj/main.nib/keyedobjects.nib   |binary
 hw/xquartz/bundle/German.lproj/InfoPlist.strings           |binary
 hw/xquartz/bundle/German.lproj/Localizable.strings         |binary
 hw/xquartz/bundle/German.lproj/main.nib/keyedobjects.nib   |binary
 hw/xquartz/bundle/Info.plist                               |    4 
 hw/xquartz/bundle/Italian.lproj/InfoPlist.strings          |binary
 hw/xquartz/bundle/Italian.lproj/Localizable.strings        |binary
 hw/xquartz/bundle/Italian.lproj/main.nib/keyedobjects.nib  |binary
 hw/xquartz/bundle/Japanese.lproj/InfoPlist.strings         |binary
 hw/xquartz/bundle/Japanese.lproj/Localizable.strings       |binary
 hw/xquartz/bundle/Japanese.lproj/main.nib/keyedobjects.nib |binary
 hw/xquartz/bundle/Makefile.am                              |   14 
 hw/xquartz/bundle/Spanish.lproj/InfoPlist.strings          |binary
 hw/xquartz/bundle/Spanish.lproj/Localizable.strings        |binary
 hw/xquartz/bundle/Spanish.lproj/main.nib/keyedobjects.nib  |binary
 hw/xquartz/bundle/X11.xcodeproj/project.pbxproj            |  130 +
 hw/xquartz/bundle/bundle-main.c                            |   88 +
 hw/xquartz/bundle/da.lproj/InfoPlist.strings               |binary
 hw/xquartz/bundle/da.lproj/Localizable.strings             |binary
 hw/xquartz/bundle/da.lproj/main.nib/keyedobjects.nib       |binary
 hw/xquartz/bundle/fi.lproj/InfoPlist.strings               |binary
 hw/xquartz/bundle/fi.lproj/Localizable.strings             |binary
 hw/xquartz/bundle/fi.lproj/main.nib/keyedobjects.nib       |binary
 hw/xquartz/bundle/ko.lproj/InfoPlist.strings               |binary
 hw/xquartz/bundle/ko.lproj/Localizable.strings             |binary
 hw/xquartz/bundle/ko.lproj/main.nib/keyedobjects.nib       |binary
 hw/xquartz/bundle/launcher-main.c                          |   81 -
 hw/xquartz/bundle/no.lproj/InfoPlist.strings               |binary
 hw/xquartz/bundle/no.lproj/Localizable.strings             |binary
 hw/xquartz/bundle/no.lproj/main.nib/keyedobjects.nib       |binary
 hw/xquartz/bundle/org.x.X11.plist.pre                      |   23 
 hw/xquartz/bundle/pl.lproj/InfoPlist.strings               |binary
 hw/xquartz/bundle/pl.lproj/Localizable.strings             |binary
 hw/xquartz/bundle/pl.lproj/main.nib/keyedobjects.nib       |binary
 hw/xquartz/bundle/pt.lproj/InfoPlist.strings               |binary
 hw/xquartz/bundle/pt.lproj/Localizable.strings             |binary
 hw/xquartz/bundle/pt.lproj/main.nib/keyedobjects.nib       |binary
 hw/xquartz/bundle/pt_PT.lproj/InfoPlist.strings            |binary
 hw/xquartz/bundle/pt_PT.lproj/Localizable.strings          |binary
 hw/xquartz/bundle/pt_PT.lproj/main.nib/keyedobjects.nib    |binary
 hw/xquartz/bundle/ru.lproj/InfoPlist.strings               |binary
 hw/xquartz/bundle/ru.lproj/Localizable.strings             |binary
 hw/xquartz/bundle/ru.lproj/main.nib/keyedobjects.nib       |binary
 hw/xquartz/bundle/server-main.c                            |  903 -------------
 hw/xquartz/bundle/sv.lproj/InfoPlist.strings               |binary
 hw/xquartz/bundle/sv.lproj/Localizable.strings             |binary
 hw/xquartz/bundle/sv.lproj/main.nib/keyedobjects.nib       |binary
 hw/xquartz/bundle/zh_CN.lproj/InfoPlist.strings            |binary
 hw/xquartz/bundle/zh_CN.lproj/Localizable.strings          |binary
 hw/xquartz/bundle/zh_CN.lproj/main.nib/keyedobjects.nib    |binary
 hw/xquartz/bundle/zh_TW.lproj/InfoPlist.strings            |binary
 hw/xquartz/bundle/zh_TW.lproj/Localizable.strings          |binary
 hw/xquartz/bundle/zh_TW.lproj/main.nib/keyedobjects.nib    |binary
 hw/xquartz/darwin.c                                        |  177 --
 hw/xquartz/darwin.h                                        |   12 
 hw/xquartz/darwinEvents.c                                  |    7 
 hw/xquartz/darwinEvents.h                                  |    5 
 hw/xquartz/darwinKeyboard.c                                |    6 
 hw/xquartz/darwinXinput.c                                  |    9 
 hw/xquartz/pseudoramiX.c                                   |    2 
 hw/xquartz/quartz.c                                        |   63 
 hw/xquartz/quartzAudio.c                                   |    2 
 hw/xquartz/quartzCocoa.m                                   |    1 
 hw/xquartz/quartzCommon.h                                  |    1 
 hw/xquartz/quartzForeground.c                              |    2 
 hw/xquartz/quartzForeground.h                              |    2 
 hw/xquartz/quartzPasteboard.c                              |   16 
 hw/xquartz/quartzPasteboard.h                              |    4 
 hw/xquartz/quartzStartup.c                                 |   34 
 hw/xquartz/x11-exec.c                                      |   74 -
 hw/xquartz/xpr/appledri.c                                  |    1 
 hw/xquartz/xpr/xpr.h                                       |    2 
 hw/xquartz/xpr/xprFrame.c                                  |    4 
 hw/xquartz/xpr/xprScreen.c                                 |  172 +-
 hw/xwin/winwin32rootless.c                                 |    4 
 include/property.h                                         |    7 
 include/registry.h                                         |   10 
 include/xkbsrv.h                                           |    3 
 mi/mieq.c                                                  |   17 
 mi/miinitext.c                                             |   28 
 mi/mipointer.c                                             |    8 
 mi/miscrinit.c                                             |    2 
 miext/rootless/accel/rlAccel.c                             |    5 
 miext/rootless/rootlessWindow.c                            |    6 
 os/connection.c                                            |    3 
 os/io.c                                                    |    2 
 xfixes/cursor.c                                            |    5 
 xfixes/select.c                                            |    3 
 xkb/xkbInit.c                                              |    4 
 xkb/xkbLEDs.c                                              |    3 
 xkb/xkbUtils.c                                             |    2 
 194 files changed, 2467 insertions(+), 2796 deletions(-)

New commits:
commit c46728b8196972aeb609c003a697a241691d6531
Author: Eamon Walsh <ewalsh at tycho.nsa.gov>
Date:   Fri Feb 8 17:33:54 2008 -0500

    xselinux: Implement support for property polyinstantiation.

diff --git a/Xext/xselinux.c b/Xext/xselinux.c
index c24c5a8..f329cf7 100644
--- a/Xext/xselinux.c
+++ b/Xext/xselinux.c
@@ -251,6 +251,62 @@ SELinuxEventToSID(unsigned type, security_id_t sid_of_window,
 }
 
 /*
+ * Looks up the SID corresponding to the given property name
+ */
+static int
+SELinuxPropertyToSID(Atom propertyName, security_id_t ssid,
+		     security_id_t *sid_rtn, int *poly_rtn)
+{
+    const char *name = NameForAtom(propertyName);
+    security_context_t con;
+    security_id_t tsid;
+    int poly = 1;
+
+    /* Look in the mappings of property names to contexts */
+    if (selabel_lookup(label_hnd, &con, name, SELABEL_X_PROP) == 0) {
+	poly = 0;
+    } else if (errno != ENOENT) {
+	ErrorF("SELinux: a property label lookup failed!\n");
+	return BadValue;
+    } else if (selabel_lookup(label_hnd, &con, name, SELABEL_X_POLYPROP) < 0) {
+	ErrorF("SELinux: a property label lookup failed!\n");
+	return BadValue;
+    }
+
+    if (poly_rtn)
+	*poly_rtn = poly;
+
+    /* Get a SID for context */
+    if (avc_context_to_sid(con, &tsid) < 0) {
+	ErrorF("SELinux: a context_to_SID call failed!\n");
+	freecon(con);
+	return BadAlloc;
+    }
+    freecon(con);
+
+    /* Perform a transition */
+    if (avc_compute_create(ssid, tsid, SECCLASS_X_PROPERTY, sid_rtn) < 0) {
+	ErrorF("SELinux: a compute_create call failed!\n");
+	sidput(tsid);
+	return BadValue;
+    }
+    sidput(tsid);
+
+    /* Polyinstantiate if necessary to obtain the final SID */
+    if (poly) {
+	tsid = *sid_rtn;
+	if (avc_compute_member(ssid, tsid, SECCLASS_X_PROPERTY, sid_rtn) < 0) {
+	    ErrorF("SELinux: a compute_member call failed!\n");
+	    sidput(tsid);
+	    return BadValue;
+	}
+	sidput(tsid);
+    }
+
+    return Success;
+}
+
+/*
  * Returns the object class corresponding to the given resource type.
  */
 static security_class_t
@@ -677,8 +733,9 @@ SELinuxProperty(CallbackListPtr *pcbl, pointer unused, pointer calldata)
     XacePropertyAccessRec *rec = calldata;
     SELinuxSubjectRec *subj;
     SELinuxObjectRec *obj;
-    SELinuxAuditRec auditdata = { .client = rec->client };
     PropertyPtr pProp = *rec->ppProp;
+    Atom name = pProp->propertyName;
+    SELinuxAuditRec auditdata = { .client = rec->client, .property = name };
     int rc;
 
     subj = dixLookupPrivate(&rec->client->devPrivates, subjectKey);
@@ -686,38 +743,38 @@ SELinuxProperty(CallbackListPtr *pcbl, pointer unused, pointer calldata)
 
     /* If this is a new object that needs labeling, do it now */
     if (rec->access_mode & DixCreateAccess) {
-	const char *name = NameForAtom(pProp->propertyName);
-	security_context_t con;
-	security_id_t sid;
-
-	/* Look in the mappings of property names to contexts */
-	if (selabel_lookup(label_hnd, &con, name, SELABEL_X_PROP) < 0) {
-	    ErrorF("SELinux: a property label lookup failed!\n");
-	    rec->status = BadValue;
+	sidput(obj->sid);
+	rc = SELinuxPropertyToSID(name, subj->sid, &obj->sid, &obj->poly);
+	if (rc != Success) {
+	    rec->status = rc;
 	    return;
 	}
-	/* Get a SID for context */
-	if (avc_context_to_sid(con, &sid) < 0) {
-	    ErrorF("SELinux: a context_to_SID call failed!\n");
-	    rec->status = BadAlloc;
+    }
+    /* If this is a polyinstantiated object, find the right instance */
+    else if (obj->poly) {
+	security_id_t tsid;
+	rc = SELinuxPropertyToSID(name, subj->sid, &tsid, NULL);
+	if (rc != Success) {
+	    rec->status = rc;
 	    return;
 	}
 
-	sidput(obj->sid);
+	while (pProp->propertyName != name || obj->sid != tsid) {
+	    if ((pProp = pProp->next) == NULL)
+		break;
+	    obj = dixLookupPrivate(&pProp->devPrivates, objectKey);
+	}
+	sidput(tsid);
 
-	/* Perform a transition to obtain the final SID */
-	if (avc_compute_create(subj->sid, sid, SECCLASS_X_PROPERTY,
-			       &obj->sid) < 0) {
-	    ErrorF("SELinux: a SID transition call failed!\n");
-	    freecon(con);
-	    rec->status = BadValue;
+	if (pProp)
+	    *rec->ppProp = pProp;
+	else {
+	    rec->status = BadMatch;
 	    return;
 	}
-	freecon(con);
     }
 
     /* Perform the security check */
-    auditdata.property = pProp->propertyName;
     rc = SELinuxDoCheck(subj, obj, SECCLASS_X_PROPERTY, rec->access_mode,
 			&auditdata);
     if (rc != Success)
commit 716be2e5eceac137f3406c332940dc946f4f8673
Author: Eamon Walsh <ewalsh at tycho.nsa.gov>
Date:   Fri Feb 1 15:29:12 2008 -0500

    dix: Modify callers of property API to use new interface.

diff --git a/hw/xfree86/common/xf86Init.c b/hw/xfree86/common/xf86Init.c
index d12b6bd..0196b75 100644
--- a/hw/xfree86/common/xf86Init.c
+++ b/hw/xfree86/common/xf86Init.c
@@ -173,12 +173,11 @@ xf86CreateRootWindow(WindowPtr pWin)
 	  Atom prop;
 
 	  prop = MakeAtom(pProp->name, strlen(pProp->name), TRUE);
-	  err = ChangeWindowProperty(pWin,
-				     prop, pProp->type,
-				     pProp->format, PropModeReplace,
-				     pProp->size, pProp->data,
-				     FALSE
-				     );
+	  err = dixChangeWindowProperty(serverClient, pWin,
+					prop, pProp->type,
+					pProp->format, PropModeReplace,
+					pProp->size, pProp->data,
+					FALSE);
 	}
       
       /* Look at err */
diff --git a/hw/xprint/pcl/PclMisc.c b/hw/xprint/pcl/PclMisc.c
index e0b7dce..0b37836 100644
--- a/hw/xprint/pcl/PclMisc.c
+++ b/hw/xprint/pcl/PclMisc.c
@@ -115,7 +115,7 @@ GetPropString(
     if(atom != BAD_RESOURCE)
     {
         WindowPtr pPropWin;
-	int n;
+	int rc, n;
 
 	/*
 	 * The atom has been defined, but it might only exist as a
@@ -124,15 +124,12 @@ GetPropString(
         for(pPropWin = pWin; pPropWin != (WindowPtr)NULL; 
 	    pPropWin = pPropWin->parent)
         {
-	    for(pProp = (PropertyPtr)(wUserProps(pPropWin)); 
-		pProp != (PropertyPtr)NULL;
-	        pProp = pProp->next)
-	    {
-                if (pProp->propertyName == atom)
-                    break;
-	    }
-	    if(pProp != (PropertyPtr)NULL)
-	        break;
+	    rc = dixLookupProperty(&pProp, pPropWin, atom,
+				   serverClient, DixReadAccess);
+	    if (rc == Success)
+		break;
+	    else
+		pProp = NULL;
         }
 	if(pProp == (PropertyPtr)NULL)
 	    return (char *)NULL;
diff --git a/hw/xprint/pcl/PclWindow.c b/hw/xprint/pcl/PclWindow.c
index a87dc0e..950933e 100644
--- a/hw/xprint/pcl/PclWindow.c
+++ b/hw/xprint/pcl/PclWindow.c
@@ -128,9 +128,9 @@ PclCreateWindow(
 	    {
                 propName = MakeAtom(propStrings[i], strlen(propStrings[i]),
 				    TRUE);
-	        ChangeWindowProperty(pWin, propName, XA_STRING, 8, 
-			             PropModeReplace,  strlen(propVal), 
-			             (pointer)propVal, FALSE);
+	        dixChangeWindowProperty(serverClient, pWin, propName, XA_STRING,
+					8, PropModeReplace, strlen(propVal),
+					(pointer)propVal, FALSE);
 	        xfree(propVal);
 	    }
 	}
diff --git a/hw/xprint/ps/PsMisc.c b/hw/xprint/ps/PsMisc.c
index 0df039e..8d5005f 100644
--- a/hw/xprint/ps/PsMisc.c
+++ b/hw/xprint/ps/PsMisc.c
@@ -175,7 +175,7 @@ GetPropString(
     if(atom != BAD_RESOURCE)
     {
         WindowPtr pPropWin;
-	int n;
+	int rc, n;
 */
 
 	/*
@@ -186,15 +186,12 @@ GetPropString(
         for(pPropWin = pWin; pPropWin != (WindowPtr)NULL; 
 	    pPropWin = pPropWin->parent)
         {
-	    for(pProp = (PropertyPtr)(wUserProps(pPropWin)); 
-		pProp != (PropertyPtr)NULL;
-	        pProp = pProp->next)
-	    {
-                if (pProp->propertyName == atom)
-                    break;
-	    }
-	    if(pProp != (PropertyPtr)NULL)
-	        break;
+	    rc = dixLookupProperty(&pProp, pPropWin, atom,
+				   serverClient, DixReadAccess);
+	    if (rc == Success)
+		break;
+	    else
+		pProp = NULL;
         }
 	if(pProp == (PropertyPtr)NULL)
 	    return (char *)NULL;
diff --git a/hw/xprint/ps/PsWindow.c b/hw/xprint/ps/PsWindow.c
index d17cf8c..8bfde4b 100644
--- a/hw/xprint/ps/PsWindow.c
+++ b/hw/xprint/ps/PsWindow.c
@@ -154,9 +154,9 @@ PsCreateWindow(WindowPtr pWin)
 	    {
                 propName = MakeAtom(propStrings[i], strlen(propStrings[i]),
 				    TRUE);
-	        ChangeWindowProperty(pWin, propName, XA_STRING, 8, 
-			             PropModeReplace,  strlen(propVal), 
-			             (pointer)propVal, FALSE);
+	        dixChangeWindowProperty(serverClient, pWin, propName, XA_STRING,
+					8, PropModeReplace, strlen(propVal),
+					(pointer)propVal, FALSE);
 	        xfree(propVal);
 	    }
 	}
diff --git a/hw/xquartz/applewm.c b/hw/xquartz/applewm.c
index c460ec6..072e57f 100644
--- a/hw/xquartz/applewm.c
+++ b/hw/xquartz/applewm.c
@@ -154,8 +154,8 @@ AppleWMSetScreenOrigin(
     data[1] = (dixScreenOrigins[pWin->drawable.pScreen->myNum].y
                 + darwinMainScreenY);
 
-    ChangeWindowProperty(pWin, xa_native_screen_origin(), XA_INTEGER,
-                         32, PropModeReplace, 2, data, TRUE);
+    dixChangeWindowProperty(serverClient, pWin, xa_native_screen_origin(),
+			    XA_INTEGER, 32, PropModeReplace, 2, data, TRUE);
 }
 
 /* Window managers can set the _APPLE_NO_ORDER_IN property on windows
@@ -169,15 +169,11 @@ AppleWMDoReorderWindow(
 {
     Atom atom;
     PropertyPtr prop;
+    int rc;
 
     atom = xa_apple_no_order_in();
-    for (prop = wUserProps(pWin); prop != NULL; prop = prop->next)
-    {
-        if (prop->propertyName == atom && prop->type == atom)
-            return FALSE;
-    }
-
-    return TRUE;
+    rc = dixLookupProperty(&prop, pWin, atom, serverClient, DixReadAccess);
+    return (rc == Success) && (prop->type == atom);
 }
 
 
diff --git a/hw/xquartz/quartzPasteboard.c b/hw/xquartz/quartzPasteboard.c
index 0cecff5..837e448 100644
--- a/hw/xquartz/quartzPasteboard.c
+++ b/hw/xquartz/quartzPasteboard.c
@@ -54,18 +54,16 @@ extern int NumCurrentSelections;
 // Returns NULL if there is no cut text or there is not enough memory.
 static char * QuartzReadCutBuffer(void)
 {
-    int i;
+    int rc, i;
     char *text = NULL;
 
     for (i = 0; i < screenInfo.numScreens; i++) {
         ScreenPtr pScreen = screenInfo.screens[i];
         PropertyPtr pProp;
 
-        pProp = wUserProps (WindowTable[pScreen->myNum]);
-        while (pProp && pProp->propertyName != XA_CUT_BUFFER0) {
-	    pProp = pProp->next;
-        }
-        if (! pProp) continue;
+	rc = dixLookupProperty(&pProp, WindowTable[pScreen->myNum],
+			       XA_CUT_BUFFER0, serverClient, DixReadAccess);
+        if (rc != Success) continue;
         if (pProp->type != XA_STRING) continue;
         if (pProp->format != 8) continue;
 
@@ -114,9 +112,9 @@ void QuartzReadPasteboard(void)
 	    ScreenPtr pScreen = screenInfo.screens[scrn];
 	    // Set the cut buffers on each screen
 	    // fixme really on each screen?
-	    ChangeWindowProperty(WindowTable[pScreen->myNum], XA_CUT_BUFFER0,
-				 XA_STRING, 8, PropModeReplace,
-				 strlen(text), (pointer)text, TRUE);
+	    dixChangeWindowProperty(serverClient, WindowTable[pScreen->myNum],
+				    XA_CUT_BUFFER0, XA_STRING, 8, PropModeReplace,
+				    strlen(text), (pointer)text, TRUE);
         }
 
         // Undo any current X selection (similar to code in dispatch.c)
diff --git a/hw/xquartz/xpr/xprFrame.c b/hw/xquartz/xpr/xprFrame.c
index b9a33de..864ef0d 100644
--- a/hw/xquartz/xpr/xprFrame.c
+++ b/hw/xquartz/xpr/xprFrame.c
@@ -90,8 +90,8 @@ xprSetNativeProperty(RootlessWindowPtr pFrame)
         /* FIXME: move this to AppleWM extension */
 
         data = native_id;
-        ChangeWindowProperty(pFrame->win, xa_native_window_id(),
-                             XA_INTEGER, 32, PropModeReplace, 1, &data, TRUE);
+        dixChangeWindowProperty(serverClient, pFrame->win, xa_native_window_id(),
+				XA_INTEGER, 32, PropModeReplace, 1, &data, TRUE);
     }
 }
 
diff --git a/hw/xwin/winwin32rootless.c b/hw/xwin/winwin32rootless.c
index 4b4cd3d..6f4e2c9 100755
--- a/hw/xwin/winwin32rootless.c
+++ b/hw/xwin/winwin32rootless.c
@@ -1087,6 +1087,6 @@ winMWExtWMSetNativeProperty (RootlessWindowPtr pFrame)
   /* FIXME: move this to WindowsWM extension */
 
   lData = (long) pRLWinPriv->hWnd;
-  ChangeWindowProperty (pFrame->win, AtmWindowsWmNativeHwnd (),
-			XA_INTEGER, 32, PropModeReplace, 1, &lData, TRUE);
+  dixChangeWindowProperty(serverClient, pFrame->win, AtmWindowsWmNativeHwnd(),
+			  XA_INTEGER, 32, PropModeReplace, 1, &lData, TRUE);
 }
diff --git a/miext/rootless/rootlessWindow.c b/miext/rootless/rootlessWindow.c
index 7285f95..0dad44a 100644
--- a/miext/rootless/rootlessWindow.c
+++ b/miext/rootless/rootlessWindow.c
@@ -181,8 +181,8 @@ set_screen_origin (WindowPtr pWin)
   data[1] = (dixScreenOrigins[pWin->drawable.pScreen->myNum].y
 	     + darwinMainScreenY);
 
-  ChangeWindowProperty (pWin, xa_native_screen_origin (), XA_INTEGER,
-			32, PropModeReplace, 2, data, TRUE);
+  dixChangeWindowProperty(serverClient, pWin, xa_native_screen_origin(),
+			  XA_INTEGER, 32, PropModeReplace, 2, data, TRUE);
 }
 
 /*
diff --git a/xkb/xkbInit.c b/xkb/xkbInit.c
index 6301a32..0908154 100644
--- a/xkb/xkbInit.c
+++ b/xkb/xkbInit.c
@@ -221,8 +221,8 @@ char *			pval;
 	ErrorF("Internal Error! bad size (%d!=%d) for _XKB_RULES_NAMES\n",
 								out,len);
     }
-    ChangeWindowProperty(WindowTable[0],name,XA_STRING,8,PropModeReplace,
-							len,pval,True);
+    dixChangeWindowProperty(serverClient, WindowTable[0], name, XA_STRING, 8,
+			    PropModeReplace, len, pval, True);
     xfree(pval);
     return True;
 }
commit 9e0eb0615ca66512a8648cc600ec11bbcd499828
Author: Eamon Walsh <ewalsh at tycho.nsa.gov>
Date:   Thu Feb 7 17:01:01 2008 -0500

    XACE: Add generic support for property polyinstantiation.

diff --git a/Xext/security.c b/Xext/security.c
index 0696559..4febda3 100644
--- a/Xext/security.c
+++ b/Xext/security.c
@@ -887,7 +887,7 @@ SecurityProperty(CallbackListPtr *pcbl, pointer unused, pointer calldata)
 {    
     XacePropertyAccessRec *rec = calldata;
     SecurityStateRec *subj, *obj;
-    ATOM name = rec->pProp->propertyName;
+    ATOM name = (*rec->ppProp)->propertyName;
     Mask requested = rec->access_mode;
     Mask allowed = SecurityAllowedMask | DixReadAccess;
 
diff --git a/Xext/xace.c b/Xext/xace.c
index b2c7e4a..12be1bf 100644
--- a/Xext/xace.c
+++ b/Xext/xace.c
@@ -56,9 +56,9 @@ int XaceHookDispatch(ClientPtr client, int major)
 }
 
 int XaceHookPropertyAccess(ClientPtr client, WindowPtr pWin,
-			   PropertyPtr pProp, Mask access_mode)
+			   PropertyPtr *ppProp, Mask access_mode)
 {
-    XacePropertyAccessRec rec = { client, pWin, pProp, access_mode, Success };
+    XacePropertyAccessRec rec = { client, pWin, ppProp, access_mode, Success };
     CallCallbacks(&XaceHooks[XACE_PROPERTY_ACCESS], &rec);
     return rec.status;
 }
diff --git a/Xext/xace.h b/Xext/xace.h
index 6f1f267..502170c 100644
--- a/Xext/xace.h
+++ b/Xext/xace.h
@@ -68,7 +68,7 @@ extern int XaceHook(
  */
 extern int XaceHookDispatch(ClientPtr ptr, int major);
 extern int XaceHookPropertyAccess(ClientPtr ptr, WindowPtr pWin,
-				  PropertyPtr pProp, Mask access_mode);
+				  PropertyPtr *ppProp, Mask access_mode);
 extern void XaceHookAuditEnd(ClientPtr ptr, int result);
 
 /* Register a callback for a given hook.
diff --git a/Xext/xacestr.h b/Xext/xacestr.h
index e31d424..2b2de94 100644
--- a/Xext/xacestr.h
+++ b/Xext/xacestr.h
@@ -59,7 +59,7 @@ typedef struct {
 typedef struct {
     ClientPtr client;
     WindowPtr pWin;
-    PropertyPtr pProp;
+    PropertyPtr *ppProp;
     Mask access_mode;
     int status;
 } XacePropertyAccessRec;
diff --git a/Xext/xselinux.c b/Xext/xselinux.c
index 9acc93c..c24c5a8 100644
--- a/Xext/xselinux.c
+++ b/Xext/xselinux.c
@@ -678,14 +678,15 @@ SELinuxProperty(CallbackListPtr *pcbl, pointer unused, pointer calldata)
     SELinuxSubjectRec *subj;
     SELinuxObjectRec *obj;
     SELinuxAuditRec auditdata = { .client = rec->client };
+    PropertyPtr pProp = *rec->ppProp;
     int rc;
 
     subj = dixLookupPrivate(&rec->client->devPrivates, subjectKey);
-    obj = dixLookupPrivate(&rec->pProp->devPrivates, objectKey);
+    obj = dixLookupPrivate(&pProp->devPrivates, objectKey);
 
     /* If this is a new object that needs labeling, do it now */
     if (rec->access_mode & DixCreateAccess) {
-	const char *name = NameForAtom(rec->pProp->propertyName);
+	const char *name = NameForAtom(pProp->propertyName);
 	security_context_t con;
 	security_id_t sid;
 
@@ -716,7 +717,7 @@ SELinuxProperty(CallbackListPtr *pcbl, pointer unused, pointer calldata)
     }
 
     /* Perform the security check */
-    auditdata.property = rec->pProp->propertyName;
+    auditdata.property = pProp->propertyName;
     rc = SELinuxDoCheck(subj, obj, SECCLASS_X_PROPERTY, rec->access_mode,
 			&auditdata);
     if (rc != Success)
@@ -1226,16 +1227,8 @@ ProcSELinuxGetPropertyContext(ClientPtr client)
     if (rc != Success)
 	return rc;
 
-    pProp = wUserProps(pWin);
-    while (pProp) {
-	if (pProp->propertyName == stuff->property)
-	    break;
-	pProp = pProp->next;
-    }
-    if (!pProp)
-	return BadValue;
-
-    rc = XaceHookPropertyAccess(client, pWin, pProp, DixGetAttrAccess);
+    rc = dixLookupProperty(&pProp, pWin, stuff->property, client,
+			   DixGetAttrAccess);
     if (rc != Success)
 	return rc;
 
diff --git a/dix/property.c b/dix/property.c
index e74becf..be68f07 100644
--- a/dix/property.c
+++ b/dix/property.c
@@ -103,7 +103,7 @@ dixLookupProperty(PropertyPtr *result, WindowPtr pWin, Atom propertyName,
 	    break;
 
     if (pProp)
-	rc = XaceHookPropertyAccess(client, pWin, pProp, access_mode);
+	rc = XaceHookPropertyAccess(client, pWin, &pProp, access_mode);
     *result = pProp;
     return rc;
 }
@@ -284,7 +284,7 @@ dixChangeWindowProperty(ClientPtr pClient, WindowPtr pWin, Atom property,
 	    memmove((char *)data, (char *)value, totalSize);
 	pProp->size = len;
 	pProp->devPrivates = NULL;
-	rc = XaceHookPropertyAccess(pClient, pWin, pProp,
+	rc = XaceHookPropertyAccess(pClient, pWin, &pProp,
 				    DixCreateAccess|DixWriteAccess);
 	if (rc != Success) {
 	    xfree(data);
@@ -588,7 +588,7 @@ ProcListProperties(ClientPtr client)
     temppAtoms = pAtoms;
     for (pProp = wUserProps(pWin); pProp; pProp = pProp->next) {
 	realProp = pProp;
-	rc = XaceHookPropertyAccess(client, pWin, pProp, DixGetAttrAccess);
+	rc = XaceHookPropertyAccess(client, pWin, &realProp, DixGetAttrAccess);
 	if (rc == Success && realProp == pProp) {
 	    *temppAtoms++ = pProp->propertyName;
 	    numProps++;
commit 67fd0cc2488ee3c0d1a87f381db3568ba3a8f960
Author: Eamon Walsh <ewalsh at tycho.nsa.gov>
Date:   Tue Feb 5 21:30:32 2008 -0500

    dix: Refactoring of property code to allow for polyinstantiation.
    Introduces dixLookupProperty() API.

diff --git a/dix/property.c b/dix/property.c
index ce61169..e74becf 100644
--- a/dix/property.c
+++ b/dix/property.c
@@ -63,11 +63,10 @@ SOFTWARE.
 /*****************************************************************
  * Property Stuff
  *
- *    ChangeProperty, DeleteProperty, GetProperties,
- *    ListProperties
+ *    dixLookupProperty, dixChangeProperty, DeleteProperty
  *
- *   Properties below to windows.  A allocate slots each time
- *   a property is added.  No fancy searching done.
+ *   Properties belong to windows.  The list of properties should not be
+ *   traversed directly.  Instead, use the three functions listed above.
  *
  *****************************************************************/
 
@@ -91,17 +90,22 @@ PrintPropertys(WindowPtr pWin)
 }
 #endif
 
-static _X_INLINE PropertyPtr
-FindProperty(WindowPtr pWin, Atom propertyName)
+_X_EXPORT int
+dixLookupProperty(PropertyPtr *result, WindowPtr pWin, Atom propertyName,
+		  ClientPtr client, Mask access_mode)
 {
-    PropertyPtr pProp = wUserProps(pWin);
-    while (pProp)
-    {
+    PropertyPtr pProp;
+    int rc = BadMatch;
+    client->errorValue = propertyName;
+
+    for (pProp = wUserProps(pWin); pProp; pProp = pProp->next)
 	if (pProp->propertyName == propertyName)
 	    break;
-	pProp = pProp->next;
-    }
-    return pProp;
+
+    if (pProp)
+	rc = XaceHookPropertyAccess(client, pWin, pProp, access_mode);
+    *result = pProp;
+    return rc;
 }
 
 static void
@@ -125,65 +129,69 @@ ProcRotateProperties(ClientPtr client)
     WindowPtr pWin;
     Atom * atoms;
     PropertyPtr * props;               /* array of pointer */
-    PropertyPtr pProp;
+    PropertyPtr pProp, saved;
 
     REQUEST_FIXED_SIZE(xRotatePropertiesReq, stuff->nAtoms << 2);
     UpdateCurrentTime();
     rc = dixLookupWindow(&pWin, stuff->window, client, DixSetPropAccess);
-    if (rc != Success)
+    if (rc != Success || stuff->nAtoms <= 0)
         return rc;
-    if (!stuff->nAtoms)
-	return(Success);
+
     atoms = (Atom *) & stuff[1];
     props = (PropertyPtr *)xalloc(stuff->nAtoms * sizeof(PropertyPtr));
-    if (!props)
-	return(BadAlloc);
+    saved = (PropertyPtr)xalloc(stuff->nAtoms * sizeof(PropertyRec));
+    if (!props || !saved) {
+	rc = BadAlloc;
+	goto out;
+    }
+
     for (i = 0; i < stuff->nAtoms; i++)
     {
         if (!ValidAtom(atoms[i])) {
-            xfree(props);
+	    rc = BadAtom;
 	    client->errorValue = atoms[i];
-            return BadAtom;
+	    goto out;
         }
         for (j = i + 1; j < stuff->nAtoms; j++)
             if (atoms[j] == atoms[i])
             {
-                xfree(props);
-                return BadMatch;
+		rc = BadMatch;
+		goto out;
             }
-	pProp = FindProperty(pWin, atoms[i]);
-	if (!pProp) {
-	    xfree(props);
-	    return BadMatch;
-	}
-	rc = XaceHookPropertyAccess(client, pWin, pProp,
-				    DixReadAccess|DixWriteAccess);
-	if (rc != Success) {
-	    xfree(props);
-	    client->errorValue = atoms[i];
-            return rc;
-	}
+
+	rc = dixLookupProperty(&pProp, pWin, atoms[i], client,
+			       DixReadAccess|DixWriteAccess);
+	if (rc != Success)
+	    goto out;
+
         props[i] = pProp;
+	saved[i] = *pProp;
     }
     delta = stuff->nPositions;
 
     /* If the rotation is a complete 360 degrees, then moving the properties
 	around and generating PropertyNotify events should be skipped. */
 
-    if ( (stuff->nAtoms != 0) && (abs(delta) % stuff->nAtoms) != 0 ) 
+    if (abs(delta) % stuff->nAtoms)
     {
 	while (delta < 0)                  /* faster if abs value is small */
             delta += stuff->nAtoms;
     	for (i = 0; i < stuff->nAtoms; i++)
  	{
-	    deliverPropertyNotifyEvent(pWin, PropertyNewValue,
-				       props[i]->propertyName);
- 
-            props[i]->propertyName = atoms[(i + delta) % stuff->nAtoms];
+	    j = (i + delta) % stuff->nAtoms;
+	    deliverPropertyNotifyEvent(pWin, PropertyNewValue, atoms[i]);
+
+	    /* Preserve name and devPrivates */
+	    props[j]->type = saved[i].type;
+	    props[j]->format = saved[i].format;
+	    props[j]->size = saved[i].size;
+	    props[j]->data = saved[i].data;
 	}
     }
+out:
+    xfree(saved);
     xfree(props);
-    return Success;
+    return rc;
 }
 
 int 
@@ -253,9 +261,9 @@ dixChangeWindowProperty(ClientPtr pClient, WindowPtr pWin, Atom property,
     totalSize = len * sizeInBytes;
 
     /* first see if property already exists */
-    pProp = FindProperty(pWin, property);
+    rc = dixLookupProperty(&pProp, pWin, property, pClient, DixWriteAccess);
 
-    if (!pProp)   /* just add to list */
+    if (rc == BadMatch)   /* just add to list */
     {
 	if (!pWin->optional && !MakeWindowOptional (pWin))
 	    return(BadAlloc);
@@ -287,13 +295,8 @@ dixChangeWindowProperty(ClientPtr pClient, WindowPtr pWin, Atom property,
         pProp->next = pWin->optional->userProps;
         pWin->optional->userProps = pProp;
     }
-    else
+    else if (rc == Success)
     {
-	rc = XaceHookPropertyAccess(pClient, pWin, pProp, DixWriteAccess);
-	if (rc != Success) {
-	    pClient->errorValue = property;
-	    return rc;
-	}
 	/* To append or prepend to a property the request format and type
 		must match those of the already defined property.  The
 		existing format and type are irrelevant when using the mode
@@ -347,6 +350,8 @@ dixChangeWindowProperty(ClientPtr pClient, WindowPtr pWin, Atom property,
             pProp->size += len;
 	}
     }
+    else
+	return rc;
 
     if (sendevent)
 	deliverPropertyNotifyEvent(pWin, PropertyNewValue, pProp->propertyName);
@@ -369,37 +374,29 @@ DeleteProperty(ClientPtr client, WindowPtr pWin, Atom propName)
     PropertyPtr pProp, prevProp;
     int rc;
 
-    if (!(pProp = wUserProps (pWin)))
-	return(Success);
-    prevProp = (PropertyPtr)NULL;
-    while (pProp)
-    {
-	if (pProp->propertyName == propName)
-	    break;
-        prevProp = pProp;
-	pProp = pProp->next;
-    }
-    if (pProp) 
-    {		    
-	rc = XaceHookPropertyAccess(client, pWin, pProp, DixDestroyAccess);
-	if (rc != Success)
-	    return rc;
+    rc = dixLookupProperty(&pProp, pWin, propName, client, DixDestroyAccess);
+    if (rc == BadMatch)
+	return Success; /* Succeed if property does not exist */
 
-        if (prevProp == (PropertyPtr)NULL)      /* takes care of head */
-        {
+    if (rc == Success) {
+	if (pWin->optional->userProps == pProp) {
+	    /* Takes care of head */
             if (!(pWin->optional->userProps = pProp->next))
 		CheckWindowOptionalNeed (pWin);
-        }
-	else
-        {
-            prevProp->next = pProp->next;
-        }
+	} else {
+	    /* Need to traverse to find the previous element */
+	    prevProp = pWin->optional->userProps;
+	    while (prevProp->next != pProp)
+		prevProp = prevProp->next;
+	    prevProp->next = pProp->next;
+	}
+
 	deliverPropertyNotifyEvent(pWin, PropertyDelete, pProp->propertyName);
 	dixFreePrivates(pProp->devPrivates);
 	xfree(pProp->data);
         xfree(pProp);
     }
-    return(Success);
+    return rc;
 }
 
 void
@@ -453,15 +450,16 @@ ProcGetProperty(ClientPtr client)
     int rc;
     WindowPtr pWin;
     xGetPropertyReply reply;
-    Mask access_mode = DixGetPropAccess;
+    Mask win_mode = DixGetPropAccess, prop_mode = DixReadAccess;
     REQUEST(xGetPropertyReq);
 
     REQUEST_SIZE_MATCH(xGetPropertyReq);
     if (stuff->delete) {
 	UpdateCurrentTime();
-	access_mode |= DixSetPropAccess;
+	win_mode |= DixSetPropAccess;
+	prop_mode |= DixDestroyAccess;
     }
-    rc = dixLookupWindow(&pWin, stuff->window, client, access_mode);
+    rc = dixLookupWindow(&pWin, stuff->window, client, win_mode);
     if (rc != Success)
 	return rc;
 
@@ -481,30 +479,14 @@ ProcGetProperty(ClientPtr client)
 	return(BadAtom);
     }
 
-    pProp = wUserProps (pWin);
-    prevProp = (PropertyPtr)NULL;
-    while (pProp)
-    {
-	if (pProp->propertyName == stuff->property) 
-	    break;
-	prevProp = pProp;
-	pProp = pProp->next;
-    }
-
     reply.type = X_Reply;
     reply.sequenceNumber = client->sequence;
-    if (!pProp) 
-	return NullPropertyReply(client, None, 0, &reply);
 
-    access_mode = DixReadAccess;
-    if (stuff->delete)
-	access_mode |= DixDestroyAccess;
-
-    rc = XaceHookPropertyAccess(client, pWin, pProp, access_mode);
-    if (rc != Success) {
-	client->errorValue = stuff->property;
+    rc = dixLookupProperty(&pProp, pWin, stuff->property, client, prop_mode);
+    if (rc == BadMatch)
+	return NullPropertyReply(client, None, 0, &reply);
+    else if (rc != Success)
 	return rc;
-    }
 
     /* If the request type and actual type don't match. Return the
     property information, but not the data. */
@@ -560,15 +542,20 @@ ProcGetProperty(ClientPtr client)
 				 (char *)pProp->data + ind);
     }
 
-    if (stuff->delete && (reply.bytesAfter == 0))
-    { /* delete the Property */
-	if (prevProp == (PropertyPtr)NULL) /* takes care of head */
-	{
-	    if (!(pWin->optional->userProps = pProp->next))
+    if (stuff->delete && (reply.bytesAfter == 0)) {
+	/* Delete the Property */
+	if (pWin->optional->userProps == pProp) {
+	    /* Takes care of head */
+            if (!(pWin->optional->userProps = pProp->next))
 		CheckWindowOptionalNeed (pWin);
-	}
-	else
+	} else {
+	    /* Need to traverse to find the previous element */
+	    prevProp = pWin->optional->userProps;
+	    while (prevProp->next != pProp)
+		prevProp = prevProp->next;
 	    prevProp->next = pProp->next;
+	}
+
 	dixFreePrivates(pProp->devPrivates);
 	xfree(pProp->data);
 	xfree(pProp);
@@ -583,7 +570,7 @@ ProcListProperties(ClientPtr client)
     xListPropertiesReply xlpr;
     int	rc, numProps = 0;
     WindowPtr pWin;
-    PropertyPtr pProp;
+    PropertyPtr pProp, realProp;
     REQUEST(xResourceReq);
 
     REQUEST_SIZE_MATCH(xResourceReq);
@@ -591,34 +578,34 @@ ProcListProperties(ClientPtr client)
     if (rc != Success)
         return rc;
 
-    pProp = wUserProps (pWin);
-    while (pProp)
-    {        
-        pProp = pProp->next;
+    for (pProp = wUserProps(pWin); pProp; pProp = pProp->next)
 	numProps++;
+
+    if (numProps && !(pAtoms = (Atom *)xalloc(numProps * sizeof(Atom))))
+	return BadAlloc;
+
+    numProps = 0;
+    temppAtoms = pAtoms;
+    for (pProp = wUserProps(pWin); pProp; pProp = pProp->next) {
+	realProp = pProp;
+	rc = XaceHookPropertyAccess(client, pWin, pProp, DixGetAttrAccess);
+	if (rc == Success && realProp == pProp) {
+	    *temppAtoms++ = pProp->propertyName;
+	    numProps++;
+	}
     }
-    if (numProps)
-        if(!(pAtoms = (Atom *)xalloc(numProps * sizeof(Atom))))
-            return(BadAlloc);
 
     xlpr.type = X_Reply;
     xlpr.nProperties = numProps;
     xlpr.length = (numProps * sizeof(Atom)) >> 2;
     xlpr.sequenceNumber = client->sequence;
-    pProp = wUserProps (pWin);
-    temppAtoms = pAtoms;
-    while (pProp)
-    {
-	*temppAtoms++ = pProp->propertyName;
-	pProp = pProp->next;
-    }
     WriteReplyToClient(client, sizeof(xGenericReply), &xlpr);
     if (numProps)
     {
         client->pSwapReplyFunc = (ReplySwapPtr)Swap32Write;
         WriteSwappedDataToClient(client, numProps * sizeof(Atom), pAtoms);
-        xfree(pAtoms);
     }
+    xfree(pAtoms);
     return(client->noClientException);
 }
 
diff --git a/hw/xfree86/loader/dixsym.c b/hw/xfree86/loader/dixsym.c
index 49c7d27..e6c37fe 100644
--- a/hw/xfree86/loader/dixsym.c
+++ b/hw/xfree86/loader/dixsym.c
@@ -193,6 +193,7 @@ _X_HIDDEN void *dixLookupTab[] = {
     SYMFUNC(XineramaGetCursorScreen)
 #endif
     /* property.c */
+    SYMFUNC(dixLookupProperty)
     SYMFUNC(ChangeWindowProperty)
     SYMFUNC(dixChangeWindowProperty)
     /* extension.c */
diff --git a/include/property.h b/include/property.h
index ba7d226..1207e81 100644
--- a/include/property.h
+++ b/include/property.h
@@ -52,6 +52,13 @@ SOFTWARE.
 
 typedef struct _Property *PropertyPtr;
 
+extern int dixLookupProperty(
+    PropertyPtr * /*result*/,
+    WindowPtr /*pWin*/,
+    Atom /*proprty*/,
+    ClientPtr /*pClient*/,
+    Mask /*access_mode*/);
+
 extern int dixChangeWindowProperty(
     ClientPtr /*pClient*/,
     WindowPtr /*pWin*/,
commit de16a8c53046764dbdf26a87acc5c984ef00d818
Author: Eamon Walsh <ewalsh at tycho.nsa.gov>
Date:   Thu Feb 7 20:14:16 2008 -0500

    XACE: Correct some protocol error values in the colormap routines.

diff --git a/dix/dispatch.c b/dix/dispatch.c
index 663bf7d..0bca441 100644
--- a/dix/dispatch.c
+++ b/dix/dispatch.c
@@ -2537,7 +2537,7 @@ ProcFreeColormap(ClientPtr client)
     else 
     {
 	client->errorValue = stuff->id;
-	return rc;
+	return (rc == BadValue) ? BadColor : rc;
     }
 }
 
@@ -2566,7 +2566,7 @@ ProcCopyColormapAndFree(ClientPtr client)
     else
     {
 	client->errorValue = stuff->srcCmap;
-	return rc;
+	return (rc == BadValue) ? BadColor : rc;
     }
 }
 
@@ -2658,7 +2658,7 @@ ProcListInstalledColormaps(ClientPtr client)
     xfree(preply);
     rc = client->noClientException;
 out:
-    return (rc == BadValue) ? BadColor : rc;
+    return rc;
 }
 
 int
commit 31934132a490b1b8ae73010c44e0b23217d8dab2
Author: Eamon Walsh <ewalsh at tycho.nsa.gov>
Date:   Thu Feb 7 16:32:06 2008 -0500

    xselinux: Use the device name in debugging output.

diff --git a/Xext/xselinux.c b/Xext/xselinux.c
index 60f0cc8..9acc93c 100644
--- a/Xext/xselinux.c
+++ b/Xext/xselinux.c
@@ -92,6 +92,7 @@ static int audit_fd;
 /* structure passed to auditing callback */
 typedef struct {
     ClientPtr client;	/* client */
+    DeviceIntPtr dev;	/* device */
     char *command;	/* client's executable path */
     unsigned id;	/* resource id, if any */
     int restype;	/* resource type, if any */
@@ -461,11 +462,15 @@ SELinuxAudit(void *auditdata,
     propertyName = audit->property ? NameForAtom(audit->property) : NULL;
     selectionName = audit->selection ? NameForAtom(audit->selection) : NULL;
 
-    return snprintf(msgbuf, msgbufsize, "%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s",
+    return snprintf(msgbuf, msgbufsize,
+		    "%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s",
 		    (major >= 0) ? "request=" : "",
 		    (major >= 0) ? LookupRequestName(major, minor) : "",
 		    audit->command ? " comm=" : "",
 		    audit->command ? audit->command : "",
+		    audit->dev ? " xdevice=\"" : "",
+		    audit->dev ? audit->dev->name : "",
+		    audit->dev ? "\"" : "",
 		    audit->id ? " resid=" : "",
 		    audit->id ? idNum : "",
 		    audit->restype ? " restype=" : "",
@@ -504,7 +509,7 @@ SELinuxDevice(CallbackListPtr *pcbl, pointer unused, pointer calldata)
     XaceDeviceAccessRec *rec = calldata;
     SELinuxSubjectRec *subj;
     SELinuxObjectRec *obj;
-    SELinuxAuditRec auditdata = { .client = rec->client };
+    SELinuxAuditRec auditdata = { .client = rec->client, .dev = rec->dev };
     int rc;
 
     subj = dixLookupPrivate(&rec->client->devPrivates, subjectKey);
@@ -537,7 +542,7 @@ SELinuxSend(CallbackListPtr *pcbl, pointer unused, pointer calldata)
     XaceSendAccessRec *rec = calldata;
     SELinuxSubjectRec *subj;
     SELinuxObjectRec *obj, ev_sid;
-    SELinuxAuditRec auditdata = { .client = rec->client };
+    SELinuxAuditRec auditdata = { .client = rec->client, .dev = rec->dev };
     security_class_t class;
     int rc, i, type;
 
commit 6dcb7d732bfeadc214228d68c5a13eef30248eb1
Author: Eamon Walsh <ewalsh at tycho.nsa.gov>
Date:   Thu Feb 7 16:00:52 2008 -0500

    xselinux: Split devPrivate state into subject and object records.

diff --git a/Xext/xselinux.c b/Xext/xselinux.c
index c7ab8d0..60f0cc8 100644
--- a/Xext/xselinux.c
+++ b/Xext/xselinux.c
@@ -61,7 +61,8 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  */
 
 /* private state record */
-static DevPrivateKey stateKey = &stateKey;
+static DevPrivateKey subjectKey = &subjectKey;
+static DevPrivateKey objectKey = &objectKey;
 
 /* This is what we store for security state */
 typedef struct {
@@ -69,7 +70,12 @@ typedef struct {
     struct avc_entry_ref aeref;
     char *command;
     int privileged;
-} SELinuxStateRec;
+} SELinuxSubjectRec;
+
+typedef struct {
+    security_id_t sid;
+    int poly;
+} SELinuxObjectRec;
 
 /* selection manager */
 typedef struct {
@@ -155,7 +161,7 @@ static pointer truep = (pointer)1;
  * Looks up the SID corresponding to the given selection atom
  */
 static int
-SELinuxSelectionToSID(Atom selection, SELinuxStateRec *sid_return)
+SELinuxSelectionToSID(Atom selection, SELinuxObjectRec *sid_return)
 {
     const char *name;
     unsigned i, size;
@@ -202,7 +208,7 @@ SELinuxSelectionToSID(Atom selection, SELinuxStateRec *sid_return)
  */
 static int
 SELinuxEventToSID(unsigned type, security_id_t sid_of_window,
-		  SELinuxStateRec *sid_return)
+		  SELinuxObjectRec *sid_return)
 {
     const char *name = LookupEventName(type);
     security_context_t con;
@@ -293,7 +299,7 @@ SELinuxTypeToClass(RESTYPE type)
  * Performs an SELinux permission check.
  */
 static int
-SELinuxDoCheck(SELinuxStateRec *subj, SELinuxStateRec *obj,
+SELinuxDoCheck(SELinuxSubjectRec *subj, SELinuxObjectRec *obj,
 	       security_class_t class, Mask mode, SELinuxAuditRec *auditdata)
 {
     /* serverClient requests OK */
@@ -321,11 +327,14 @@ static void
 SELinuxLabelClient(ClientPtr client)
 {
     XtransConnInfo ci = ((OsCommPtr)client->osPrivate)->trans_conn;
-    SELinuxStateRec *state;
+    SELinuxSubjectRec *subj;
+    SELinuxObjectRec *obj;
     security_context_t ctx;
 
-    state = dixLookupPrivate(&client->devPrivates, stateKey);
-    sidput(state->sid);
+    subj = dixLookupPrivate(&client->devPrivates, subjectKey);
+    sidput(subj->sid);
+    obj = dixLookupPrivate(&client->devPrivates, objectKey);
+    sidput(obj->sid);
 
     if (_XSERVTransIsLocal(ci)) {
 	int fd = _XSERVTransGetConnectionNumber(ci);
@@ -354,12 +363,12 @@ SELinuxLabelClient(ClientPtr client)
 	if (bytes <= 0)
 	    goto finish;
 
-	state->command = xalloc(bytes);
-	if (!state->command)
+	subj->command = xalloc(bytes);
+	if (!subj->command)
 	    goto finish;
 
-	memcpy(state->command, path, bytes);
-	state->command[bytes - 1] = 0;
+	memcpy(subj->command, path, bytes);
+	subj->command[bytes - 1] = 0;
     } else
 	/* For remote clients, need to use a default context */
 	if (selabel_lookup(label_hnd, &ctx, NULL, SELABEL_X_CLIENT) < 0)
@@ -368,10 +377,12 @@ SELinuxLabelClient(ClientPtr client)
 
 finish:
     /* Get a SID from the context */
-    if (avc_context_to_sid(ctx, &state->sid) < 0)
+    if (avc_context_to_sid(ctx, &subj->sid) < 0)
 	FatalError("Client %d: context_to_sid(%s) failed\n",
 		   client->index, ctx);
 
+    sidget(subj->sid);
+    obj->sid = subj->sid;
     freecon(ctx);
 }
 
@@ -383,23 +394,27 @@ SELinuxLabelInitial(void)
 {
     int i;
     XaceScreenAccessRec srec;
-    SELinuxStateRec *state;
+    SELinuxSubjectRec *subj;
+    SELinuxObjectRec *obj;
     security_context_t ctx;
     pointer unused;
 
     /* Do the serverClient */
-    state = dixLookupPrivate(&serverClient->devPrivates, stateKey);
-    state->privileged = 1;
-    sidput(state->sid);
+    subj = dixLookupPrivate(&serverClient->devPrivates, subjectKey);
+    obj = dixLookupPrivate(&serverClient->devPrivates, objectKey);
+    subj->privileged = 1;
+    sidput(subj->sid);
 
     /* Use the context of the X server process for the serverClient */
     if (getcon(&ctx) < 0)
 	FatalError("Couldn't get context of X server process\n");
 
     /* Get a SID from the context */
-    if (avc_context_to_sid(ctx, &state->sid) < 0)
+    if (avc_context_to_sid(ctx, &subj->sid) < 0)
 	FatalError("serverClient: context_to_sid(%s) failed\n", ctx);
 
+    sidget(subj->sid);
+    obj->sid = subj->sid;
     freecon(ctx);
 
     srec.client = serverClient;
@@ -487,20 +502,27 @@ static void
 SELinuxDevice(CallbackListPtr *pcbl, pointer unused, pointer calldata)
 {
     XaceDeviceAccessRec *rec = calldata;
-    SELinuxStateRec *subj, *obj;
+    SELinuxSubjectRec *subj;
+    SELinuxObjectRec *obj;
     SELinuxAuditRec auditdata = { .client = rec->client };
     int rc;
 
-    subj = dixLookupPrivate(&rec->client->devPrivates, stateKey);
-    obj = dixLookupPrivate(&rec->dev->devPrivates, stateKey);
+    subj = dixLookupPrivate(&rec->client->devPrivates, subjectKey);
+    obj = dixLookupPrivate(&rec->dev->devPrivates, objectKey);
 
     /* If this is a new object that needs labeling, do it now */
     if (rec->access_mode & DixCreateAccess) {
+	SELinuxSubjectRec *dsubj;
+	dsubj = dixLookupPrivate(&rec->dev->devPrivates, subjectKey);
+
+	sidput(dsubj->sid);
 	sidput(obj->sid);
 
 	/* Label the device directly with the process SID */
 	sidget(subj->sid);
 	obj->sid = subj->sid;
+	sidget(subj->sid);
+	dsubj->sid = subj->sid;
     }
 
     rc = SELinuxDoCheck(subj, obj, SECCLASS_X_DEVICE, rec->access_mode,
@@ -513,17 +535,18 @@ static void
 SELinuxSend(CallbackListPtr *pcbl, pointer unused, pointer calldata)
 {
     XaceSendAccessRec *rec = calldata;
-    SELinuxStateRec *subj, *obj, ev_sid;
+    SELinuxSubjectRec *subj;
+    SELinuxObjectRec *obj, ev_sid;
     SELinuxAuditRec auditdata = { .client = rec->client };
     security_class_t class;
     int rc, i, type;
 
     if (rec->dev)
-	subj = dixLookupPrivate(&rec->dev->devPrivates, stateKey);
+	subj = dixLookupPrivate(&rec->dev->devPrivates, subjectKey);
     else
-	subj = dixLookupPrivate(&rec->client->devPrivates, stateKey);
+	subj = dixLookupPrivate(&rec->client->devPrivates, subjectKey);
 
-    obj = dixLookupPrivate(&rec->pWin->devPrivates, stateKey);
+    obj = dixLookupPrivate(&rec->pWin->devPrivates, objectKey);
 
     /* Check send permission on window */
     rc = SELinuxDoCheck(subj, obj, SECCLASS_X_DRAWABLE, DixSendAccess,
@@ -554,13 +577,14 @@ static void
 SELinuxReceive(CallbackListPtr *pcbl, pointer unused, pointer calldata)
 {
     XaceReceiveAccessRec *rec = calldata;
-    SELinuxStateRec *subj, *obj, ev_sid;
+    SELinuxSubjectRec *subj;
+    SELinuxObjectRec *obj, ev_sid;
     SELinuxAuditRec auditdata = { .client = NULL };
     security_class_t class;
     int rc, i, type;
 
-    subj = dixLookupPrivate(&rec->client->devPrivates, stateKey);
-    obj = dixLookupPrivate(&rec->pWin->devPrivates, stateKey);
+    subj = dixLookupPrivate(&rec->client->devPrivates, subjectKey);
+    obj = dixLookupPrivate(&rec->pWin->devPrivates, objectKey);
 
     /* Check receive permission on window */
     rc = SELinuxDoCheck(subj, obj, SECCLASS_X_DRAWABLE, DixReceiveAccess,
@@ -591,12 +615,13 @@ static void
 SELinuxExtension(CallbackListPtr *pcbl, pointer unused, pointer calldata)
 {
     XaceExtAccessRec *rec = calldata;
-    SELinuxStateRec *subj, *obj, *serv;
+    SELinuxSubjectRec *subj, *serv;
+    SELinuxObjectRec *obj;
     SELinuxAuditRec auditdata = { .client = rec->client };
     int rc;
 
-    subj = dixLookupPrivate(&rec->client->devPrivates, stateKey);
-    obj = dixLookupPrivate(&rec->ext->devPrivates, stateKey);
+    subj = dixLookupPrivate(&rec->client->devPrivates, subjectKey);
+    obj = dixLookupPrivate(&rec->ext->devPrivates, objectKey);
 
     /* If this is a new object that needs labeling, do it now */
     /* XXX there should be a separate callback for this */
@@ -605,9 +630,9 @@ SELinuxExtension(CallbackListPtr *pcbl, pointer unused, pointer calldata)
 	security_context_t con;
 	security_id_t sid;
 
-	serv = dixLookupPrivate(&serverClient->devPrivates, stateKey);
+	serv = dixLookupPrivate(&serverClient->devPrivates, subjectKey);
 
-	/* Look in the mappings of property names to contexts */
+	/* Look in the mappings of extension names to contexts */
 	if (selabel_lookup(label_hnd, &con, name, SELABEL_X_EXT) < 0) {
 	    ErrorF("SELinux: a property label lookup failed!\n");
 	    rec->status = BadValue;
@@ -645,12 +670,13 @@ static void
 SELinuxProperty(CallbackListPtr *pcbl, pointer unused, pointer calldata)
 {
     XacePropertyAccessRec *rec = calldata;
-    SELinuxStateRec *subj, *obj;
+    SELinuxSubjectRec *subj;
+    SELinuxObjectRec *obj;
     SELinuxAuditRec auditdata = { .client = rec->client };
     int rc;
 
-    subj = dixLookupPrivate(&rec->client->devPrivates, stateKey);
-    obj = dixLookupPrivate(&rec->pProp->devPrivates, stateKey);
+    subj = dixLookupPrivate(&rec->client->devPrivates, subjectKey);
+    obj = dixLookupPrivate(&rec->pProp->devPrivates, objectKey);
 
     /* If this is a new object that needs labeling, do it now */
     if (rec->access_mode & DixCreateAccess) {
@@ -696,13 +722,15 @@ static void
 SELinuxResource(CallbackListPtr *pcbl, pointer unused, pointer calldata)
 {
     XaceResourceAccessRec *rec = calldata;
-    SELinuxStateRec *subj, *obj, *pobj;
+    SELinuxSubjectRec *subj;
+    SELinuxObjectRec *obj, *sobj, *pobj;
     SELinuxAuditRec auditdata = { .client = rec->client };
     PrivateRec **privatePtr;
     security_class_t class;
     int rc, offset;
 
-    subj = dixLookupPrivate(&rec->client->devPrivates, stateKey);
+    subj = dixLookupPrivate(&rec->client->devPrivates, subjectKey);
+    sobj = dixLookupPrivate(&rec->client->devPrivates, objectKey);
 
     /* Determine if the resource object has a devPrivates field */
     offset = dixLookupPrivateOffset(rec->rtype);
@@ -710,12 +738,12 @@ SELinuxResource(CallbackListPtr *pcbl, pointer unused, pointer calldata)
 	/* No: use the SID of the owning client */
 	class = SECCLASS_X_RESOURCE;
 	privatePtr = &clients[CLIENT_ID(rec->id)]->devPrivates;
-	obj = dixLookupPrivate(privatePtr, stateKey);
+	obj = dixLookupPrivate(privatePtr, objectKey);
     } else {
 	/* Yes: use the SID from the resource object itself */
 	class = SELinuxTypeToClass(rec->rtype);
 	privatePtr = DEVPRIV_AT(rec->res, offset);
-	obj = dixLookupPrivate(privatePtr, stateKey);
+	obj = dixLookupPrivate(privatePtr, objectKey);
     }
 
     /* If this is a new object that needs labeling, do it now */
@@ -724,10 +752,10 @@ SELinuxResource(CallbackListPtr *pcbl, pointer unused, pointer calldata)
 	    offset = dixLookupPrivateOffset(rec->ptype);
 	if (rec->parent && offset >= 0)
 	    /* Use the SID of the parent object in the labeling operation */
-	    pobj = dixLookupPrivate(DEVPRIV_AT(rec->parent, offset), stateKey);
+	    pobj = dixLookupPrivate(DEVPRIV_AT(rec->parent, offset), objectKey);
 	else
 	    /* Use the SID of the subject */
-	    pobj = subj;
+	    pobj = sobj;
 
 	sidput(obj->sid);
 
@@ -751,13 +779,14 @@ static void
 SELinuxScreen(CallbackListPtr *pcbl, pointer is_saver, pointer calldata)
 {
     XaceScreenAccessRec *rec = calldata;
-    SELinuxStateRec *subj, *obj;
+    SELinuxSubjectRec *subj;
+    SELinuxObjectRec *obj;
     SELinuxAuditRec auditdata = { .client = rec->client };
     Mask access_mode = rec->access_mode;
     int rc;
 
-    subj = dixLookupPrivate(&rec->client->devPrivates, stateKey);
-    obj = dixLookupPrivate(&rec->screen->devPrivates, stateKey);
+    subj = dixLookupPrivate(&rec->client->devPrivates, subjectKey);
+    obj = dixLookupPrivate(&rec->screen->devPrivates, objectKey);
 
     /* If this is a new object that needs labeling, do it now */
     if (access_mode & DixCreateAccess) {
@@ -784,12 +813,13 @@ static void
 SELinuxClient(CallbackListPtr *pcbl, pointer unused, pointer calldata)
 {
     XaceClientAccessRec *rec = calldata;
-    SELinuxStateRec *subj, *obj;
+    SELinuxSubjectRec *subj;
+    SELinuxObjectRec *obj;
     SELinuxAuditRec auditdata = { .client = rec->client };
     int rc;
 
-    subj = dixLookupPrivate(&rec->client->devPrivates, stateKey);
-    obj = dixLookupPrivate(&rec->target->devPrivates, stateKey);
+    subj = dixLookupPrivate(&rec->client->devPrivates, subjectKey);
+    obj = dixLookupPrivate(&rec->target->devPrivates, objectKey);
 
     rc = SELinuxDoCheck(subj, obj, SECCLASS_X_CLIENT, rec->access_mode,
 			&auditdata);
@@ -801,12 +831,13 @@ static void
 SELinuxServer(CallbackListPtr *pcbl, pointer unused, pointer calldata)
 {
     XaceServerAccessRec *rec = calldata;
-    SELinuxStateRec *subj, *obj;
+    SELinuxSubjectRec *subj;
+    SELinuxObjectRec *obj;
     SELinuxAuditRec auditdata = { .client = rec->client };
     int rc;
 
-    subj = dixLookupPrivate(&rec->client->devPrivates, stateKey);
-    obj = dixLookupPrivate(&serverClient->devPrivates, stateKey);
+    subj = dixLookupPrivate(&rec->client->devPrivates, subjectKey);
+    obj = dixLookupPrivate(&serverClient->devPrivates, objectKey);
 
     rc = SELinuxDoCheck(subj, obj, SECCLASS_X_SERVER, rec->access_mode,
 			&auditdata);
@@ -818,11 +849,12 @@ static void
 SELinuxSelection(CallbackListPtr *pcbl, pointer unused, pointer calldata)
 {
     XaceSelectionAccessRec *rec = (XaceSelectionAccessRec *)calldata;
-    SELinuxStateRec *subj, sel_sid;
+    SELinuxSubjectRec *subj;
+    SELinuxObjectRec sel_sid;
     SELinuxAuditRec auditdata = { .client = rec->client };
     int rc;
 
-    subj = dixLookupPrivate(&rec->client->devPrivates, stateKey);
+    subj = dixLookupPrivate(&rec->client->devPrivates, subjectKey);
 
     rc = SELinuxSelectionToSID(rec->name, &sel_sid);
     if (rc != Success) {
@@ -869,18 +901,19 @@ static void
 SELinuxResourceState(CallbackListPtr *pcbl, pointer unused, pointer calldata)
 {
     ResourceStateInfoRec *rec = calldata;
-    SELinuxStateRec *state;
+    SELinuxSubjectRec *subj;
+    SELinuxObjectRec *obj;
     WindowPtr pWin;
 
     if (rec->type != RT_WINDOW)
 	return;
 
     pWin = (WindowPtr)rec->value;
-    state = dixLookupPrivate(&wClient(pWin)->devPrivates, stateKey);
+    subj = dixLookupPrivate(&wClient(pWin)->devPrivates, subjectKey);
 
-    if (state->sid) {
+    if (subj->sid) {
 	security_context_t ctx;
-	int rc = avc_sid_to_context(state->sid, &ctx);
+	int rc = avc_sid_to_context(subj->sid, &ctx);
 	if (rc < 0)
 	    FatalError("SELinux: Failed to get security context!\n");
 	rc = dixChangeWindowProperty(serverClient,
@@ -892,11 +925,11 @@ SELinuxResourceState(CallbackListPtr *pcbl, pointer unused, pointer calldata)
     } else
 	FatalError("SELinux: Unexpected unlabeled client found\n");
 
-    state = dixLookupPrivate(&pWin->devPrivates, stateKey);
+    obj = dixLookupPrivate(&pWin->devPrivates, objectKey);
 
-    if (state->sid) {
+    if (obj->sid) {
 	security_context_t ctx;
-	int rc = avc_sid_to_context(state->sid, &ctx);
+	int rc = avc_sid_to_context(obj->sid, &ctx);
 	if (rc < 0)
 	    FatalError("SELinux: Failed to get security context!\n");
 	rc = dixChangeWindowProperty(serverClient,
@@ -913,7 +946,8 @@ static void
 SELinuxSelectionState(CallbackListPtr *pcbl, pointer unused, pointer calldata)
 {
     SelectionInfoRec *rec = calldata;
-    SELinuxStateRec *subj, *obj;
+    SELinuxSubjectRec *subj;
+    SELinuxObjectRec *obj;
 
     switch (rec->kind) {
     case SelectionSetOwner:
@@ -922,8 +956,8 @@ SELinuxSelectionState(CallbackListPtr *pcbl, pointer unused, pointer calldata)
 	rec->selection->alt_window = rec->selection->window;
 
 	/* figure out the new label for the content */
-	subj = dixLookupPrivate(&rec->client->devPrivates, stateKey);
-	obj = dixLookupPrivate(&rec->selection->devPrivates, stateKey);
+	subj = dixLookupPrivate(&rec->client->devPrivates, subjectKey);
+	obj = dixLookupPrivate(&rec->selection->devPrivates, objectKey);
 	sidput(obj->sid);
 
 	if (avc_compute_create(subj->sid, subj->sid, SECCLASS_X_SELECTION,
@@ -959,27 +993,47 @@ SELinuxSelectionState(CallbackListPtr *pcbl, pointer unused, pointer calldata)
  */
 
 static void
-SELinuxStateInit(CallbackListPtr *pcbl, pointer unused, pointer calldata)
+SELinuxSubjectInit(CallbackListPtr *pcbl, pointer unused, pointer calldata)
 {
     PrivateCallbackRec *rec = calldata;
-    SELinuxStateRec *state = *rec->value;
+    SELinuxSubjectRec *subj = *rec->value;
 
     sidget(unlabeled_sid);
-    state->sid = unlabeled_sid;
+    subj->sid = unlabeled_sid;
+
+    avc_entry_ref_init(&subj->aeref);
+}
+
+static void
+SELinuxSubjectFree(CallbackListPtr *pcbl, pointer unused, pointer calldata)
+{
+    PrivateCallbackRec *rec = calldata;
+    SELinuxSubjectRec *subj = *rec->value;
+
+    xfree(subj->command);
 
-    avc_entry_ref_init(&state->aeref);
+    if (avc_active)
+	sidput(subj->sid);
 }
 
 static void
-SELinuxStateFree(CallbackListPtr *pcbl, pointer unused, pointer calldata)
+SELinuxObjectInit(CallbackListPtr *pcbl, pointer unused, pointer calldata)
 {
     PrivateCallbackRec *rec = calldata;
-    SELinuxStateRec *state = *rec->value;
+    SELinuxObjectRec *obj = *rec->value;
 
-    xfree(state->command);
+    sidget(unlabeled_sid);
+    obj->sid = unlabeled_sid;
+}
+
+static void
+SELinuxObjectFree(CallbackListPtr *pcbl, pointer unused, pointer calldata)
+{
+    PrivateCallbackRec *rec = calldata;
+    SELinuxObjectRec *obj = *rec->value;
 
     if (avc_active)
-	sidput(state->sid);
+	sidput(obj->sid);
 }
 
 
@@ -1070,7 +1124,8 @@ ProcSELinuxSetDeviceContext(ClientPtr client)
     char *ctx;
     security_id_t sid;
     DeviceIntPtr dev;
-    SELinuxStateRec *state;
+    SELinuxSubjectRec *subj;
+    SELinuxObjectRec *obj;
     int rc;
 
     REQUEST(SELinuxSetContextReq);
@@ -1088,9 +1143,13 @@ ProcSELinuxSetDeviceContext(ClientPtr client)
     if (rc != Success)
 	return BadValue;
 
-    state = dixLookupPrivate(&dev->devPrivates, stateKey);
-    sidput(state->sid);
-    state->sid = sid;
+    subj = dixLookupPrivate(&dev->devPrivates, subjectKey);
+    sidput(subj->sid);
+    subj->sid = sid;
+    obj = dixLookupPrivate(&dev->devPrivates, objectKey);
+    sidput(obj->sid);
+    obj->sid = sid;
+
     return Success;
 }
 
@@ -1099,7 +1158,7 @@ ProcSELinuxGetDeviceContext(ClientPtr client)
 {
     char *ctx;
     DeviceIntPtr dev;
-    SELinuxStateRec *state;
+    SELinuxSubjectRec *subj;
     SELinuxGetContextReply rep;
     int rc;
 
@@ -1110,8 +1169,8 @@ ProcSELinuxGetDeviceContext(ClientPtr client)
     if (rc != Success)
 	return rc;
 
-    state = dixLookupPrivate(&dev->devPrivates, stateKey);
-    rc = avc_sid_to_context(state->sid, &ctx);
+    subj = dixLookupPrivate(&dev->devPrivates, subjectKey);
+    rc = avc_sid_to_context(subj->sid, &ctx);
     if (rc != Success)
 	return BadValue;
 
@@ -1151,7 +1210,7 @@ ProcSELinuxGetPropertyContext(ClientPtr client)
     char *ctx;
     WindowPtr pWin;
     PropertyPtr pProp;
-    SELinuxStateRec *state;
+    SELinuxObjectRec *obj;
     SELinuxGetContextReply rep;
     int rc;
 
@@ -1175,8 +1234,8 @@ ProcSELinuxGetPropertyContext(ClientPtr client)
     if (rc != Success)
 	return rc;
 
-    state = dixLookupPrivate(&pProp->devPrivates, stateKey);
-    rc = avc_sid_to_context(state->sid, &ctx);
+    obj = dixLookupPrivate(&pProp->devPrivates, objectKey);
+    rc = avc_sid_to_context(obj->sid, &ctx);
     if (rc != Success)
 	return BadValue;
 
@@ -1215,7 +1274,7 @@ ProcSELinuxGetWindowContext(ClientPtr client)
 {
     char *ctx;
     WindowPtr pWin;
-    SELinuxStateRec *state;
+    SELinuxObjectRec *obj;
     SELinuxGetContextReply rep;
     int rc;
 
@@ -1226,8 +1285,8 @@ ProcSELinuxGetWindowContext(ClientPtr client)
     if (rc != Success)
 	return rc;
 
-    state = dixLookupPrivate(&pWin->devPrivates, stateKey);
-    rc = avc_sid_to_context(state->sid, &ctx);
+    obj = dixLookupPrivate(&pWin->devPrivates, objectKey);
+    rc = avc_sid_to_context(obj->sid, &ctx);
     if (rc != Success)
 	return BadValue;
 
@@ -1521,7 +1580,8 @@ SELinuxExtensionInit(INITARGS)
 	FatalError("SELinux: Failed to open the system audit log\n");
 
     /* Allocate private storage */
-    if (!dixRequestPrivate(stateKey, sizeof(SELinuxStateRec)))
+    if (!dixRequestPrivate(subjectKey, sizeof(SELinuxSubjectRec)) ||
+	!dixRequestPrivate(objectKey, sizeof(SELinuxObjectRec)))
 	FatalError("SELinux: Failed to allocate private storage.\n");
 
     /* Create atoms for doing window labeling */
@@ -1533,8 +1593,10 @@ SELinuxExtensionInit(INITARGS)
 	FatalError("SELinux: Failed to create atom\n");
 
     /* Register callbacks */
-    ret &= dixRegisterPrivateInitFunc(stateKey, SELinuxStateInit, NULL);
-    ret &= dixRegisterPrivateDeleteFunc(stateKey, SELinuxStateFree, NULL);
+    ret &= dixRegisterPrivateInitFunc(subjectKey, SELinuxSubjectInit, NULL);
+    ret &= dixRegisterPrivateDeleteFunc(subjectKey, SELinuxSubjectFree, NULL);
+    ret &= dixRegisterPrivateInitFunc(objectKey, SELinuxObjectInit, NULL);
+    ret &= dixRegisterPrivateDeleteFunc(objectKey, SELinuxObjectFree, NULL);
 
     ret &= AddCallback(&ClientStateCallback, SELinuxClientState, NULL);
     ret &= AddCallback(&ResourceStateCallback, SELinuxResourceState, NULL);
commit 2259b144f0fd4855085a656111a0c64246733e78
Author: Eamon Walsh <ewalsh at tycho.nsa.gov>
Date:   Thu Feb 7 14:35:02 2008 -0500

    xselinux: Add getattr and setattr to the permission map for properties.

diff --git a/Xext/xselinux.c b/Xext/xselinux.c
index b3d938b..c7ab8d0 100644
--- a/Xext/xselinux.c
+++ b/Xext/xselinux.c
@@ -127,7 +127,7 @@ static struct security_class_mapping map[] = {
     { "x_gc", { "", "", "destroy", "create", "getattr", "setattr", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "use", NULL }},
     { "x_font", { "", "", "destroy", "create", "getattr", "", "", "", "", "", "", "", "add_glyph", "remove_glyph", "", "", "", "", "", "", "", "", "", "", "use", NULL }},
     { "x_colormap", { "read", "write", "destroy", "create", "getattr", "", "", "", "", "", "", "", "add_color", "remove_color", "", "", "", "", "", "", "install", "uninstall", "", "", "use", NULL }},
-    { "x_property", { "read", "write", "destroy", "create", NULL }},
+    { "x_property", { "read", "write", "destroy", "create", "getattr", "setattr", NULL }},
     { "x_selection", { "read", "", "", "", "getattr", "setattr", NULL }},
     { "x_cursor", { "read", "write", "destroy", "create", "getattr", "setattr", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "use", NULL }},
     { "x_client", { "", "", "destroy", "", "getattr", "setattr", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "manage", NULL }},
commit 5c30327275509576b7848a5f842e7a1bffabe980
Author: Eamon Walsh <ewalsh at tycho.nsa.gov>
Date:   Tue Feb 5 21:06:05 2008 -0500

    XACE: Push the dix "structure" includes down to the security modules.

diff --git a/Xext/security.c b/Xext/security.c
index 6aab3a3..0696559 100644
--- a/Xext/security.c
+++ b/Xext/security.c
@@ -29,6 +29,9 @@ in this Software without prior written authorization from The Open Group.
 #endif
 
 #include "scrnintstr.h"
+#include "inputstr.h"
+#include "windowstr.h"
+#include "propertyst.h"
 #include "colormapst.h"
 #include "privates.h"
 #include "registry.h"
diff --git a/Xext/xace.c b/Xext/xace.c
index 9ffac45..b2c7e4a 100644
--- a/Xext/xace.c
+++ b/Xext/xace.c
@@ -23,6 +23,10 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 
 #include <stdarg.h>
 #include "scrnintstr.h"
+#include "extnsionst.h"
+#include "pixmapstr.h"
+#include "regionstr.h"
+#include "gcstruct.h"
 #include "xacestr.h"
 
 CallbackListPtr XaceHooks[XACE_NUM_HOOKS] = {0};
diff --git a/Xext/xace.h b/Xext/xace.h
index 24b9dce..6f1f267 100644
--- a/Xext/xace.h
+++ b/Xext/xace.h
@@ -25,10 +25,10 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 #define XACE_MAJOR_VERSION		2
 #define XACE_MINOR_VERSION		0
 
-#include "pixmap.h"     /* for DrawablePtr */
-#include "regionstr.h"  /* for RegionPtr */
-#include "window.h"  /* for WindowPtr */
-#include "property.h" /* for PropertyPtr */
+#include "pixmap.h"
+#include "region.h"
+#include "window.h"
+#include "property.h"
 
 /* Default window background */
 #define XaceBackgroundNoneState		None
diff --git a/Xext/xacestr.h b/Xext/xacestr.h
index 045f836..e31d424 100644
--- a/Xext/xacestr.h
+++ b/Xext/xacestr.h
@@ -20,13 +20,12 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 #ifndef _XACESTR_H
 #define _XACESTR_H
 
-#include "dixstruct.h"
+#include "dix.h"
 #include "resource.h"
 #include "extnsionst.h"
-#include "gcstruct.h"
-#include "windowstr.h"
-#include "inputstr.h"
-#include "propertyst.h"
+#include "window.h"
+#include "input.h"
+#include "property.h"
 #include "selection.h"
 #include "xace.h"
 
diff --git a/Xext/xselinux.c b/Xext/xselinux.c
index 47383a4..b3d938b 100644
--- a/Xext/xselinux.c
+++ b/Xext/xselinux.c
@@ -22,21 +22,28 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  * All rights reserved.
  */
 
+#ifdef HAVE_DIX_CONFIG_H
+#include <dix-config.h>
+#endif
+
+#include <sys/socket.h>
+#include <stdio.h>
+#include <stdarg.h>
+
 #include <selinux/selinux.h>
 #include <selinux/label.h>
 #include <selinux/avc.h>
 
 #include <libaudit.h>
 
-#ifdef HAVE_DIX_CONFIG_H
-#include <dix-config.h>
-#endif
-
 #include <X11/Xatom.h>
 #include "resource.h"
 #include "privates.h"
 #include "registry.h"
 #include "dixstruct.h"
+#include "inputstr.h"
+#include "windowstr.h"
+#include "propertyst.h"
 #include "extnsionst.h"
 #include "scrnintstr.h"
 #include "selection.h"
@@ -46,8 +53,6 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 #define TRANS_SERVER
 #include <X11/Xtrans/Xtrans.h>
 #include "../os/osdep.h"
-#include <stdio.h>
-#include <stdarg.h>
 #include "modinit.h"
 
 
commit bb1a577a6822f781f1e38d2434a13914e74f89aa
Author: Eamon Walsh <ewalsh at tycho.nsa.gov>
Date:   Tue Feb 5 20:07:08 2008 -0500

    XACE: Move the property access hook to its own function.

diff --git a/Xext/xace.c b/Xext/xace.c
index 0470e44..9ffac45 100644
--- a/Xext/xace.c
+++ b/Xext/xace.c
@@ -51,6 +51,14 @@ int XaceHookDispatch(ClientPtr client, int major)
     }
 }
 
+int XaceHookPropertyAccess(ClientPtr client, WindowPtr pWin,
+			   PropertyPtr pProp, Mask access_mode)
+{
+    XacePropertyAccessRec rec = { client, pWin, pProp, access_mode, Success };
+    CallCallbacks(&XaceHooks[XACE_PROPERTY_ACCESS], &rec);
+    return rec.status;
+}
+
 void XaceHookAuditEnd(ClientPtr ptr, int result)
 {
     XaceAuditRec rec = { ptr, result };
@@ -100,18 +108,6 @@ int XaceHook(int hook, ...)
 	    prv = &rec.status;
 	    break;
 	}
-	case XACE_PROPERTY_ACCESS: {
-	    XacePropertyAccessRec rec = {
-		va_arg(ap, ClientPtr),
-		va_arg(ap, WindowPtr),
-		va_arg(ap, PropertyPtr),
-		va_arg(ap, Mask),
-		Success /* default allow */
-	    };
-	    calldata = &rec;
-	    prv = &rec.status;
-	    break;
-	}
 	case XACE_SEND_ACCESS: {
 	    XaceSendAccessRec rec = {
 		va_arg(ap, ClientPtr),
diff --git a/Xext/xace.h b/Xext/xace.h
index 4100ba1..24b9dce 100644
--- a/Xext/xace.h
+++ b/Xext/xace.h
@@ -27,6 +27,8 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 
 #include "pixmap.h"     /* for DrawablePtr */
 #include "regionstr.h"  /* for RegionPtr */
+#include "window.h"  /* for WindowPtr */
+#include "property.h" /* for PropertyPtr */
 
 /* Default window background */
 #define XaceBackgroundNoneState		None
@@ -65,6 +67,8 @@ extern int XaceHook(
 /* Special-cased hook functions
  */
 extern int XaceHookDispatch(ClientPtr ptr, int major);
+extern int XaceHookPropertyAccess(ClientPtr ptr, WindowPtr pWin,
+				  PropertyPtr pProp, Mask access_mode);
 extern void XaceHookAuditEnd(ClientPtr ptr, int result);
 
 /* Register a callback for a given hook.
@@ -101,11 +105,13 @@ extern void XaceCensorImage(
 #ifdef __GNUC__
 #define XaceHook(args...) Success
 #define XaceHookDispatch(args...) Success
+#define XaceHookPropertyAccess(args...) Success
 #define XaceHookAuditEnd(args...) { ; }
 #define XaceCensorImage(args...) { ; }
 #else
 #define XaceHook(...) Success
 #define XaceHookDispatch(...) Success
+#define XaceHookPropertyAccess(...) Success
 #define XaceHookAuditEnd(...) { ; }
 #define XaceCensorImage(...) { ; }
 #endif
diff --git a/Xext/xselinux.c b/Xext/xselinux.c
index a6e27e6..47383a4 100644
--- a/Xext/xselinux.c
+++ b/Xext/xselinux.c
@@ -1166,7 +1166,7 @@ ProcSELinuxGetPropertyContext(ClientPtr client)
     if (!pProp)
 	return BadValue;
 
-    rc = XaceHook(XACE_PROPERTY_ACCESS, client, pWin, pProp, DixGetAttrAccess);
+    rc = XaceHookPropertyAccess(client, pWin, pProp, DixGetAttrAccess);
     if (rc != Success)
 	return rc;
 
diff --git a/dix/property.c b/dix/property.c
index 3c0eaf1..ce61169 100644
--- a/dix/property.c
+++ b/dix/property.c
@@ -156,8 +156,8 @@ ProcRotateProperties(ClientPtr client)
 	    xfree(props);
 	    return BadMatch;
 	}
-	rc = XaceHook(XACE_PROPERTY_ACCESS, client, pWin, pProp,
-		      DixReadAccess|DixWriteAccess);
+	rc = XaceHookPropertyAccess(client, pWin, pProp,
+				    DixReadAccess|DixWriteAccess);
 	if (rc != Success) {
 	    xfree(props);
 	    client->errorValue = atoms[i];
@@ -276,8 +276,8 @@ dixChangeWindowProperty(ClientPtr pClient, WindowPtr pWin, Atom property,
 	    memmove((char *)data, (char *)value, totalSize);
 	pProp->size = len;
 	pProp->devPrivates = NULL;
-	rc = XaceHook(XACE_PROPERTY_ACCESS, pClient, pWin, pProp,
-		      DixCreateAccess|DixWriteAccess);
+	rc = XaceHookPropertyAccess(pClient, pWin, pProp,
+				    DixCreateAccess|DixWriteAccess);
 	if (rc != Success) {
 	    xfree(data);
 	    xfree(pProp);
@@ -289,8 +289,7 @@ dixChangeWindowProperty(ClientPtr pClient, WindowPtr pWin, Atom property,
     }
     else
     {
-	rc = XaceHook(XACE_PROPERTY_ACCESS, pClient, pWin, pProp,
-		      DixWriteAccess);
+	rc = XaceHookPropertyAccess(pClient, pWin, pProp, DixWriteAccess);
 	if (rc != Success) {
 	    pClient->errorValue = property;
 	    return rc;
@@ -382,8 +381,7 @@ DeleteProperty(ClientPtr client, WindowPtr pWin, Atom propName)
     }
     if (pProp) 
     {		    
-	rc = XaceHook(XACE_PROPERTY_ACCESS, client, pWin, pProp,
-		      DixDestroyAccess);
+	rc = XaceHookPropertyAccess(client, pWin, pProp, DixDestroyAccess);
 	if (rc != Success)
 	    return rc;
 
@@ -502,7 +500,7 @@ ProcGetProperty(ClientPtr client)
     if (stuff->delete)
 	access_mode |= DixDestroyAccess;
 
-    rc = XaceHook(XACE_PROPERTY_ACCESS, client, pWin, pProp, access_mode);
+    rc = XaceHookPropertyAccess(client, pWin, pProp, access_mode);
     if (rc != Success) {
 	client->errorValue = stuff->property;
 	return rc;
commit 019ad5acd20e34dc2aa3b89cc426138db5164c48
Author: Eamon Walsh <ewalsh at tycho.nsa.gov>
Date:   Tue Feb 5 15:44:41 2008 -0500

    XFixes: squash a pointer/integer size mismatch warning.

diff --git a/xfixes/cursor.c b/xfixes/cursor.c
index 1d122fa..d51251f 100755
--- a/xfixes/cursor.c
+++ b/xfixes/cursor.c
@@ -707,7 +707,8 @@ SProcXFixesChangeCursor (ClientPtr client)
 static Bool
 TestForCursorName (CursorPtr pCursor, pointer closure)
 {
-    return (pCursor->name == (Atom) closure);
+    Atom *pName = closure;
+    return (pCursor->name == *pName);
 }
 
 int
@@ -724,7 +725,7 @@ ProcXFixesChangeCursorByName (ClientPtr client)
     tchar = (char *) &stuff[1];
     name = MakeAtom (tchar, stuff->nbytes, FALSE);
     if (name)
-	ReplaceCursor (pSource, TestForCursorName, (pointer) name);
+	ReplaceCursor (pSource, TestForCursorName, &name);
     return (client->noClientException);
 }
 
commit d3c36fe721edc55636438bc3e0e7a6c03f62784e
Author: liuhong <liuhong at devlinux-hong.sh.intel.com>
Date:   Tue Feb 5 10:54:58 2008 +0800

    validate mode clock for probed modes
    
    Some modes claimed in monitor EDID data may not be supported by
    the monitor. So also validating the max clock for probed modes.

diff --git a/hw/xfree86/modes/xf86Crtc.c b/hw/xfree86/modes/xf86Crtc.c
index da035f2..4ecf4b3 100644
--- a/hw/xfree86/modes/xf86Crtc.c
+++ b/hw/xfree86/modes/xf86Crtc.c
@@ -1410,9 +1410,12 @@ xf86ProbeOutputModes (ScrnInfoPtr scrn, int maxX, int maxY)
 	/*
 	 * Check default modes against monitor max clock
 	 */
-	if (max_clock)
+	if (max_clock) {
 	    xf86ValidateModesClocks(scrn, default_modes,
 				    &min_clock, &max_clock, 1);
+	    xf86ValidateModesClocks(scrn, output_modes,
+				    &min_clock, &max_clock, 1);
+	}
 	
 	output->probed_modes = NULL;
 	output->probed_modes = xf86ModesAdd (output->probed_modes, config_modes);
commit 4b5b6e7baab58072a983d2ec136965f404c3a74a
Author: liuhong <liuhong at devlinux-hong.sh.intel.com>
Date:   Tue Feb 5 10:54:10 2008 +0800

    fix max clock unit
    
    max clock from EDID data is in MHz, while we need KHz to validate modes.

diff --git a/hw/xfree86/modes/xf86Crtc.c b/hw/xfree86/modes/xf86Crtc.c
index 10db862..da035f2 100644
--- a/hw/xfree86/modes/xf86Crtc.c
+++ b/hw/xfree86/modes/xf86Crtc.c
@@ -1362,8 +1362,8 @@ xf86ProbeOutputModes (ScrnInfoPtr scrn, int maxX, int maxY)
 			if (sync_source == sync_default)
 			    sync_source = sync_edid;
 		    }
-		    if (ranges->max_clock > max_clock)
-			max_clock = ranges->max_clock;
+		    if (ranges->max_clock * 1000 > max_clock)
+			max_clock = ranges->max_clock * 1000;
 		}
 	    }
 	}
commit a56ef7aaa4b6ac13c8181f68fc7dad3ca89e6973
Author: Magnus Vigerlöf <Magnus.Vigerlof at ipbo.se>
Date:   Sat Feb 2 23:04:46 2008 +0100

    dix: Move motion history update until after screen crossing and clipping
    
    Cross screen and clip the coordinates before updating the motion history
    so that it will have the same contents as the events that are reported.

diff --git a/dix/getevents.c b/dix/getevents.c
index bc64d31..3e6fe5a 100644
--- a/dix/getevents.c
+++ b/dix/getevents.c
@@ -667,15 +667,6 @@ GetPointerEvents(xEvent *events, DeviceIntPtr pDev, int type, int buttons,
         }
     }
 
-    /* Drop x and y back into the valuators list, if they were originally
-     * present. */
-    if (first_valuator == 0 && num_valuators >= 1)
-        valuators[0] = x;
-    if (first_valuator <= 1 && num_valuators >= (2 - first_valuator))
-        valuators[1 - first_valuator] = y;
-
-    updateMotionHistory(pDev, ms, first_valuator, num_valuators, valuators);
-
     pDev->valuator->lastx = x;
     pDev->valuator->lasty = y;
     /* Convert the dev coord back to screen coord if we're
@@ -721,6 +712,15 @@ GetPointerEvents(xEvent *events, DeviceIntPtr pDev, int type, int buttons,
         cp->valuator->lasty = y;
     }
 
+    /* Drop x and y back into the valuators list, if they were originally
+     * present. */
+    if (first_valuator == 0 && num_valuators >= 1)
+        valuators[0] = pDev->valuator->lastx;
+    if (first_valuator <= 1 && num_valuators >= (2 - first_valuator))
+        valuators[1 - first_valuator] = pDev->valuator->lasty;
+
+    updateMotionHistory(pDev, ms, first_valuator, num_valuators, valuators);
+
     /* for some reason inputInfo.pointer does not have coreEvents set */
     if (coreOnly || pDev->coreEvents) {
         events->u.u.type = type;
commit a0284d577aabea8406b72dd63773e341430ebe56
Author: Magnus Vigerlöf <Magnus.Vigerlof at ipbo.se>
Date:   Sat Feb 2 23:03:51 2008 +0100

    dix: Skip call to clipAxis for relative core-events
    
    Relative events that generates both core and extention
    events will have its axis cliped and screen changed by
    miPointerSetPosition when the events are processed. For
    absolute and non core-generating relative events the
    axis must be clipped if we shouldn't end up completely
    outside the defined ranges (if any).

diff --git a/dix/getevents.c b/dix/getevents.c
index c2736e4..bc64d31 100644
--- a/dix/getevents.c
+++ b/dix/getevents.c
@@ -609,6 +609,10 @@ GetPointerEvents(xEvent *events, DeviceIntPtr pDev, int type, int buttons,
                     y = cp->valuator->lasty;
             }
         }
+
+        /* Clip both x and y to the defined limits (usually co-ord space limit). */
+        clipAxis(pDev, 0, &x);
+        clipAxis(pDev, 1, &y);
     }
     else {
         if (flags & POINTER_ACCELERATE)
@@ -647,22 +651,22 @@ GetPointerEvents(xEvent *events, DeviceIntPtr pDev, int type, int buttons,
                 y += valuators[1 - first_valuator];
         }
         else {
+            x = pDev->valuator->lastx;
+            y = pDev->valuator->lasty;
             if (first_valuator == 0 && num_valuators >= 1)
-                x = pDev->valuator->lastx + valuators[0];
-            else
-                x = pDev->valuator->lastx;
-
+                x += valuators[0];
             if (first_valuator <= 1 && num_valuators >= (2 - first_valuator))
-                y = pDev->valuator->lasty + valuators[1 - first_valuator];
-            else
-                y = pDev->valuator->lasty;
+                y += valuators[1 - first_valuator];
+
+            if(!coreOnly) {
+                /* Since we're not sending core-events we must clip both x and y
+                 * to the defined limits so we don't run outside the box. */
+                clipAxis(pDev, 0, &x);
+                clipAxis(pDev, 1, &y);
+            }
         }
     }
 
-    /* Clip both x and y to the defined limits (usually co-ord space limit). */
-    clipAxis(pDev, 0, &x);
-    clipAxis(pDev, 1, &y);
-
     /* Drop x and y back into the valuators list, if they were originally
      * present. */
     if (first_valuator == 0 && num_valuators >= 1)
@@ -695,6 +699,24 @@ GetPointerEvents(xEvent *events, DeviceIntPtr pDev, int type, int buttons,
     miPointerSetPosition(pDev, &x, &y, ms);
 
     if (pDev->coreEvents) {
+        /* miPointerSetPosition may have changed screen */
+        scr = miPointerGetScreen(pDev);
+        if(x != cp->valuator->lastx) {
+            int min = pDev->valuator->axes[0].min_value;
+            int max = pDev->valuator->axes[0].max_value;
+            cp->valuator->lastx = pDev->valuator->lastx = x;
+            if(min < max)
+                pDev->valuator->lastx = (int)((float)(x)*(max-min+1)/scr->width)+min;
+        }
+        if(y != cp->valuator->lasty) {
+            int min = pDev->valuator->axes[1].min_value;
+            int max = pDev->valuator->axes[1].max_value;
+            cp->valuator->lasty = pDev->valuator->lasty = y;
+            if(min < max)
+                pDev->valuator->lasty = (int)((float)(y)*(max-min+1)/scr->height)+min;
+        }
+    }
+    else if (coreOnly) {
         cp->valuator->lastx = x;
         cp->valuator->lasty = y;
     }
commit d9e23c4ff1607a62164b34717ef9afd352ce2b94
Author: Magnus Vigerlöf <Magnus.Vigerlof at ipbo.se>
Date:   Sat Feb 2 22:57:32 2008 +0100

    Bug # 10324: dix: Add scaling of X and Y on the reported pointer-events
    
    Restore the rescaling code for x and y axis when generating
    motion events.

diff --git a/dix/getevents.c b/dix/getevents.c
index ea1c764..c2736e4 100644
--- a/dix/getevents.c
+++ b/dix/getevents.c
@@ -531,6 +531,7 @@ GetPointerEvents(xEvent *events, DeviceIntPtr pDev, int type, int buttons,
     DeviceIntPtr cp = inputInfo.pointer;
     int x = 0, y = 0;
     Bool coreOnly = (pDev == inputInfo.pointer);
+    ScreenPtr scr = miPointerGetScreen(pDev);
 
     /* Sanity checks. */
     if (type != MotionNotify && type != ButtonPress && type != ButtonRelease)
@@ -574,20 +575,39 @@ GetPointerEvents(xEvent *events, DeviceIntPtr pDev, int type, int buttons,
             x = valuators[0];
         }
         else {
-            if (pDev->coreEvents)
-                x = cp->valuator->lastx;
-            else
-                x = pDev->valuator->lastx;
+            /* If we're sending core events but didn't provide a value,
+             * translate the core value (but use the device coord if
+             * it translates to the same coord to preserve sub-pixel
+             * coord information). If we're not sending core events use
+             * whatever value we have */
+            x = pDev->valuator->lastx;
+            if(pDev->coreEvents) {
+                int min = pDev->valuator->axes[0].min_value;
+                int max = pDev->valuator->axes[0].max_value;
+                if(min < max) {
+                    if((int)((float)(x-min)*scr->width/(max-min+1)) != cp->valuator->lastx)
+                        x = (int)((float)(cp->valuator->lastx)*(max-min+1)/scr->width)+min;
+                }
+                else
+                    x = cp->valuator->lastx;
+            }
         }
 
         if (first_valuator <= 1 && num_valuators >= (2 - first_valuator)) {
             y = valuators[1 - first_valuator];
         }
         else {
-            if (pDev->coreEvents)
-                y = cp->valuator->lasty;
-            else
-                y = pDev->valuator->lasty;
+            y = pDev->valuator->lasty;
+            if(pDev->coreEvents) {
+                int min = pDev->valuator->axes[1].min_value;
+                int max = pDev->valuator->axes[1].max_value;
+                if(min < max) {
+                    if((int)((float)(y-min)*scr->height/(max-min+1)) != cp->valuator->lasty)
+                        y = (int)((float)(cp->valuator->lasty)*(max-min+1)/scr->height)+min;
+                }
+                else
+                    y = cp->valuator->lasty;
+            }
         }
     }
     else {
@@ -596,15 +616,35 @@ GetPointerEvents(xEvent *events, DeviceIntPtr pDev, int type, int buttons,
                               valuators);
 
         if (pDev->coreEvents) {
-            if (first_valuator == 0 && num_valuators >= 1)
-                x = cp->valuator->lastx + valuators[0];
+            /* Get and convert the core pointer coordinate space into
+             * device coordinates. Use the device coords if it translates
+             * into the same position as the core to preserve relative sub-
+             * pixel movements from the device. */
+            int min = pDev->valuator->axes[0].min_value;
+            int max = pDev->valuator->axes[0].max_value;
+            if(min < max) {
+                x = pDev->valuator->lastx;
+                if((int)((float)(x-min)*scr->width/(max-min+1)) != cp->valuator->lastx)
+                    x = (int)((float)(cp->valuator->lastx)*(max-min+1)/scr->width)+min;
+            }
             else
                 x = cp->valuator->lastx;
 
-            if (first_valuator <= 1 && num_valuators >= (2 - first_valuator))
-                y = cp->valuator->lasty + valuators[1 - first_valuator];
+            min = pDev->valuator->axes[1].min_value;
+            max = pDev->valuator->axes[1].max_value;
+            if(min < max) {
+                y = pDev->valuator->lasty;
+                if((int)((float)(y-min)*scr->height/(max-min+1)) != cp->valuator->lasty)
+                    y = (int)((float)(cp->valuator->lasty)*(max-min+1)/scr->height)+min;
+            }
             else
                 y = cp->valuator->lasty;
+
+            /* Add relative movement */
+            if (first_valuator == 0 && num_valuators >= 1)
+                x += valuators[0];
+            if (first_valuator <= 1 && num_valuators >= (2 - first_valuator))
+                y += valuators[1 - first_valuator];
         }
         else {
             if (first_valuator == 0 && num_valuators >= 1)
@@ -623,11 +663,6 @@ GetPointerEvents(xEvent *events, DeviceIntPtr pDev, int type, int buttons,
     clipAxis(pDev, 0, &x);
     clipAxis(pDev, 1, &y);
 
-    /* This takes care of crossing screens for us, as well as clipping
-     * to the current screen.  Right now, we only have one history buffer,
-     * so we don't set this for both the device and core.*/
-    miPointerSetPosition(pDev, &x, &y, ms);
-
     /* Drop x and y back into the valuators list, if they were originally
      * present. */
     if (first_valuator == 0 && num_valuators >= 1)
@@ -637,12 +672,32 @@ GetPointerEvents(xEvent *events, DeviceIntPtr pDev, int type, int buttons,
 
     updateMotionHistory(pDev, ms, first_valuator, num_valuators, valuators);
 
+    pDev->valuator->lastx = x;
+    pDev->valuator->lasty = y;
+    /* Convert the dev coord back to screen coord if we're
+     * sending core events */
+    if (pDev->coreEvents) {
+        int min = pDev->valuator->axes[0].min_value;
+        int max = pDev->valuator->axes[0].max_value;
+        if(min < max)
+            x = (int)((float)(x-min)*scr->width/(max-min+1));
+        cp->valuator->lastx = x;
+        min = pDev->valuator->axes[1].min_value;
+        max = pDev->valuator->axes[1].max_value;
+        if(min < max)
+            y = (int)((float)(y-min)*scr->height/(max-min+1));
+        cp->valuator->lasty = y;
+    }
+
+    /* This takes care of crossing screens for us, as well as clipping
+     * to the current screen.  Right now, we only have one history buffer,
+     * so we don't set this for both the device and core.*/
+    miPointerSetPosition(pDev, &x, &y, ms);
+
     if (pDev->coreEvents) {
         cp->valuator->lastx = x;
         cp->valuator->lasty = y;
     }
-    pDev->valuator->lastx = x;
-    pDev->valuator->lasty = y;
 
     /* for some reason inputInfo.pointer does not have coreEvents set */
     if (coreOnly || pDev->coreEvents) {
@@ -680,8 +735,8 @@ GetPointerEvents(xEvent *events, DeviceIntPtr pDev, int type, int buttons,
             kbp->detail = pDev->button->map[buttons];
         }
 
-        kbp->root_x = x;
-        kbp->root_y = y;
+        kbp->root_x = pDev->valuator->lastx;
+        kbp->root_y = pDev->valuator->lasty;
 
         events++;
         if (num_valuators) {
commit f04c0838699f1a733735838e74cfbb1677b15dc4
Author: Magnus Vigerlöf <Magnus.Vigerlof at ipbo.se>
Date:   Sat Feb 2 22:45:31 2008 +0100

    Bug # 10324: dix: Allow arbitrary value ranges in GetPointerEvents
    
    Don't use a possitive value as a marker for if a max-value
    is defined on the valuators. Use the existence of a valid
    value range instead. This will also make it possible to
    define arbitrary start and end-values for min and max as
    long as min < max.

diff --git a/dix/getevents.c b/dix/getevents.c
index 94cbd15..ea1c764 100644
--- a/dix/getevents.c
+++ b/dix/getevents.c
@@ -308,10 +308,13 @@ clipAxis(DeviceIntPtr pDev, int axisNum, int *val)
 {
     AxisInfoPtr axes = pDev->valuator->axes + axisNum;
 
-    if (*val < axes->min_value)
-        *val = axes->min_value;
-    if (axes->max_value >= 0 && *val > axes->max_value)
-        *val = axes->max_value;
+    /* No clipping if the value-range <= 0 */
+    if(axes->min_value < axes->min_value) {
+        if (*val < axes->min_value)
+            *val = axes->min_value;
+        if (*val > axes->max_value)
+            *val = axes->max_value;
+    }
 }
 
 /**
commit 12e532403210c15a25200ef448bfe9701735ab20
Author: Magnus Vigerlöf <Magnus.Vigerlof at ipbo.se>
Date:   Sat Feb 2 22:44:31 2008 +0100

    dix: Always add valuator information if present
    
    Send valuator information for all event types, not only for
    MotionEvents and absolute button events.

diff --git a/dix/getevents.c b/dix/getevents.c
index 12cb950..94cbd15 100644
--- a/dix/getevents.c
+++ b/dix/getevents.c
@@ -525,9 +525,6 @@ GetPointerEvents(xEvent *events, DeviceIntPtr pDev, int type, int buttons,
     int num_events = 0, final_valuator = 0;
     CARD32 ms = 0;
     deviceKeyButtonPointer *kbp = NULL;
-    /* Thanks to a broken lib, we _always_ have to chase DeviceMotionNotifies
-     * with DeviceValuators. */
-    Bool sendValuators = (type == MotionNotify || flags & POINTER_ABSOLUTE);
     DeviceIntPtr cp = inputInfo.pointer;
     int x = 0, y = 0;
     Bool coreOnly = (pDev == inputInfo.pointer);
@@ -553,7 +550,7 @@ GetPointerEvents(xEvent *events, DeviceIntPtr pDev, int type, int buttons,
         return 0;
 
     /* Do we need to send a DeviceValuator event? */
-    if (!coreOnly && sendValuators) {
+    if (!coreOnly && num_valuators) {
         if ((((num_valuators - 1) / 6) + 1) > MAX_VALUATOR_EVENTS)
             num_valuators = MAX_VALUATOR_EVENTS * 6;
         num_events += ((num_valuators - 1) / 6) + 1;
@@ -684,7 +681,7 @@ GetPointerEvents(xEvent *events, DeviceIntPtr pDev, int type, int buttons,
         kbp->root_y = y;
 
         events++;
-        if (sendValuators) {
+        if (num_valuators) {
             kbp->deviceid |= MORE_EVENTS;
             clipValuators(pDev, first_valuator, num_valuators, valuators);
             events = getValuatorEvents(events, pDev, first_valuator,
commit 41991fb991313202e8e6b513fe928ba14f8fcb87
Author: Peter Hutterer <peter at cs.unisa.edu.au>
Date:   Tue Feb 5 16:01:56 2008 +1030

    xkb: when copying sections, make sure num_rows is set too.

diff --git a/xkb/xkbUtils.c b/xkb/xkbUtils.c
index 1fb47ed..9f813e5 100644
--- a/xkb/xkbUtils.c
+++ b/xkb/xkbUtils.c
@@ -1806,6 +1806,7 @@ XkbCopyKeymap(XkbDescPtr src, XkbDescPtr dst, Bool sendNotifies)
                         return FALSE;
                     dsection->rows = tmp;
                 }
+                dsection->num_rows = ssection->num_rows;
                 for (j = 0, srow = ssection->rows, drow = dsection->rows;
                      j < ssection->num_rows;
                      j++, srow++, drow++) {
commit 521a7f26e088029707fb9a2bb80c9ddc734a3f8b
Author: Peter Hutterer <peter at cs.unisa.edu.au>
Date:   Tue Feb 5 18:34:31 2008 +1030

    mi: Only UpdateSpriteForScreen if we actually changed the screen. (Bug #12650)
    
    X.Org Bug 12650 <http://bugs.freedesktop.org/show_bug.cgi?id=12650>

diff --git a/mi/mipointer.c b/mi/mipointer.c
index 2c3c689..b55e68b 100644
--- a/mi/mipointer.c
+++ b/mi/mipointer.c
@@ -231,10 +231,14 @@ miPointerWarpCursor (pScreen, x, y)
     ScreenPtr	pScreen;
     int		x, y;
 {
+    BOOL changedScreen = FALSE;
     SetupScreen (pScreen);
 
     if (miPointer.pScreen != pScreen)
+    {
 	(*pScreenPriv->screenFuncs->NewEventScreen) (pScreen, TRUE);
+        changedScreen = TRUE;
+    }
 
     if (GenerateEvent)
     {
@@ -255,7 +259,9 @@ miPointerWarpCursor (pScreen, x, y)
 	miPointer.y = y;
 	miPointer.pScreen = pScreen;
     }
-    UpdateSpriteForScreen (pScreen) ;
+
+    if (changedScreen)
+        UpdateSpriteForScreen (pScreen) ;
 }
 
 /*
commit 10617dc0fb7166ccd5b2e92fa708390c2d7d0d27
Author: Peter Hutterer <peter at cs.unisa.edu.au>
Date:   Fri Feb 1 14:24:04 2008 +1030

    xfree86: stick two more checks in for num_valuators < MAX_VALUATORS

diff --git a/hw/xfree86/common/xf86Xinput.c b/hw/xfree86/common/xf86Xinput.c
index 3e9a479..eafc0e9 100644
--- a/hw/xfree86/common/xf86Xinput.c
+++ b/hw/xfree86/common/xf86Xinput.c
@@ -507,6 +507,12 @@ xf86PostMotionEventP(DeviceIntPtr	device,
     int index;
     int flags = 0;
 
+    if (num_valuators > MAX_VALUATORS) {
+	xf86Msg(X_ERROR, "xf86PostMotionEvent: num_valuator %d"
+	    " is greater than MAX_VALUATORS\n", num_valuators);
+	return;
+    }
+
     if (is_absolute)
         flags = POINTER_ABSOLUTE;
     else
@@ -644,6 +650,12 @@ xf86PostKeyEvent(DeviceIntPtr	device,
            "badly south after this message, then xf86PostKeyEvent is "
            "broken.\n");
 
+    if (num_valuators > MAX_VALUATORS) {
+	xf86Msg(X_ERROR, "xf86PostMotionEvent: num_valuator %d"
+	    " is greater than MAX_VALUATORS\n", num_valuators);
+	return;
+    }
+
     if (!xf86Events)
         FatalError("Didn't allocate event store\n");
 
commit c68f063be639f39c2facbb496e8455e8e3771b41
Author: Matthieu Herrb <matthieu.herrb at laas.fr>
Date:   Fri Feb 1 14:13:29 2008 +1030

    xfree86: don't call xalloc from signal handlers when posting events.
    
    Reviewed-by: Peter Hutterer <peter at cs.unisa.edu.au>

diff --git a/hw/xfree86/common/xf86Xinput.c b/hw/xfree86/common/xf86Xinput.c
index 9a94c04..3e9a479 100644
--- a/hw/xfree86/common/xf86Xinput.c
+++ b/hw/xfree86/common/xf86Xinput.c
@@ -133,6 +133,11 @@ xf86ProcessCommonOptions(LocalDevicePtr local,
 
     /* Backwards compatibility. */
     local->history_size = GetMotionHistorySize();
+    /* Preallocate xEvent store */
+    if (!xf86Events)
+        xf86Events = (xEvent *)xcalloc(sizeof(xEvent), GetMaximumEventsNum());
+    if (!xf86Events)
+        FatalError("Couldn't allocate event store\n");
 }
 
 /***********************************************************************
@@ -461,6 +466,8 @@ DeleteInputDeviceRequest(DeviceIntPtr pDev)
  * convenient functions to post events
  */
 
+#define MAX_VALUATORS 36 /* XXX from comment in dix/getevents.c */
+
 _X_EXPORT void
 xf86PostMotionEvent(DeviceIntPtr	device,
                     int			is_absolute,
@@ -470,17 +477,12 @@ xf86PostMotionEvent(DeviceIntPtr	device,
 {
     va_list var;
     int i = 0;
-    static int *valuators = NULL;
-    static int n_valuators = 0;
-
-    if (num_valuators > n_valuators) {
-	xfree (valuators);
-	valuators = NULL;
-    }
+    static int valuators[MAX_VALUATORS];
 
-    if (!valuators) {
-	valuators = xcalloc(sizeof(int), num_valuators);
-	n_valuators = num_valuators;
+    if (num_valuators > MAX_VALUATORS) {
+	xf86Msg(X_ERROR, "xf86PostMotionEvent: num_valuator %d"
+	    " is greater than MAX_VALUATORS\n", num_valuators);
+	return;
     }
 
     va_start(var, num_valuators);
@@ -529,9 +531,7 @@ xf86PostMotionEventP(DeviceIntPtr	device,
 #endif
 
     if (!xf86Events)
-        xf86Events = (xEvent *)xcalloc(sizeof(xEvent), GetMaximumEventsNum());
-    if (!xf86Events)
-        FatalError("Couldn't allocate event store\n");
+        FatalError("Didn't allocate event store\n");
 
     nevents = GetPointerEvents(xf86Events, device, MotionNotify, 0,
                                flags, first_valuator, num_valuators,
@@ -555,9 +555,15 @@ xf86PostProximityEvent(DeviceIntPtr	device,
                        ...)
 {
     va_list var;
-    int i, nevents, *valuators = NULL;
+    int i, nevents;
+    int valuators[MAX_VALUATORS];
 
-    valuators = xcalloc(sizeof(int), num_valuators);
+
+    if (num_valuators > MAX_VALUATORS) {
+	xf86Msg(X_ERROR, "xf86PostMotionEvent: num_valuator %d"
+	    " is greater than MAX_VALUATORS\n", num_valuators);
+	return;
+    }
 
     va_start(var, num_valuators);
     for (i = 0; i < num_valuators; i++)
@@ -565,9 +571,7 @@ xf86PostProximityEvent(DeviceIntPtr	device,
     va_end(var);
 
     if (!xf86Events)
-        xf86Events = (xEvent *)xcalloc(sizeof(xEvent), GetMaximumEventsNum());
-    if (!xf86Events)
-        FatalError("Couldn't allocate event store\n");
+        FatalError("Didn't allocate event store\n");
 
     nevents = GetProximityEvents(xf86Events, device,
                                  is_in ? ProximityIn : ProximityOut, 
@@ -575,7 +579,6 @@ xf86PostProximityEvent(DeviceIntPtr	device,
     for (i = 0; i < nevents; i++)
         mieqEnqueue(device, xf86Events + i);
 
-    xfree(valuators);
 }
 
 _X_EXPORT void
@@ -588,7 +591,7 @@ xf86PostButtonEvent(DeviceIntPtr	device,
                     ...)
 {
     va_list var;
-    int *valuators = NULL;
+    int valuators[MAX_VALUATORS];
     int i = 0, nevents = 0;
     int index;
 
@@ -599,18 +602,19 @@ xf86PostButtonEvent(DeviceIntPtr	device,
             return;
     }
 #endif
+    if (num_valuators > MAX_VALUATORS) {
+	xf86Msg(X_ERROR, "xf86PostMotionEvent: num_valuator %d"
+	    " is greater than MAX_VALUATORS\n", num_valuators);
+	return;
+    }
     
-    valuators = xcalloc(sizeof(int), num_valuators);
-
     va_start(var, num_valuators);
     for (i = 0; i < num_valuators; i++)
         valuators[i] = va_arg(var, int);
     va_end(var);
 
     if (!xf86Events)
-        xf86Events = (xEvent *)xcalloc(sizeof(xEvent), GetMaximumEventsNum());
-    if (!xf86Events)
-        FatalError("Couldn't allocate event store\n");
+        FatalError("Didn't allocate event store\n");
 
     nevents = GetPointerEvents(xf86Events, device,
                                is_down ? ButtonPress : ButtonRelease, button,
@@ -620,8 +624,6 @@ xf86PostButtonEvent(DeviceIntPtr	device,
 
     for (i = 0; i < nevents; i++)
         mieqEnqueue(device, xf86Events + i);
-
-    xfree(valuators);
 }
 
 _X_EXPORT void
@@ -634,7 +636,8 @@ xf86PostKeyEvent(DeviceIntPtr	device,
                  ...)
 {
     va_list var;
-    int i = 0, nevents = 0, *valuators = NULL;
+    int i = 0, nevents = 0;
+    static int valuators[MAX_VALUATORS];
 
     /* instil confidence in the user */
     DebugF("this function has never been tested properly.  if things go quite "
@@ -642,12 +645,9 @@ xf86PostKeyEvent(DeviceIntPtr	device,
            "broken.\n");
 
     if (!xf86Events)
-        xf86Events = (xEvent *)xcalloc(sizeof(xEvent), GetMaximumEventsNum());
-    if (!xf86Events)
-        FatalError("Couldn't allocate event store\n");
+        FatalError("Didn't allocate event store\n");
 
     if (is_absolute) {
-        valuators = xcalloc(sizeof(int), num_valuators);
         va_start(var, num_valuators);
         for (i = 0; i < num_valuators; i++)
             valuators[i] = va_arg(var, int);
@@ -657,7 +657,6 @@ xf86PostKeyEvent(DeviceIntPtr	device,
                                             is_down ? KeyPress : KeyRelease,
                                             key_code, first_valuator,
                                             num_valuators, valuators);
-        xfree(valuators);
     }
     else {
         nevents = GetKeyboardEvents(xf86Events, device,
@@ -686,9 +685,7 @@ xf86PostKeyboardEvent(DeviceIntPtr      device,
 #endif
 
     if (!xf86Events)
-        xf86Events = (xEvent *)xcalloc(sizeof(xEvent), GetMaximumEventsNum());
-    if (!xf86Events)
-        FatalError("Couldn't allocate event store\n");
+        FatalError("Didn't allocate event store\n");
 
     nevents = GetKeyboardEvents(xf86Events, device,
                                 is_down ? KeyPress : KeyRelease, key_code);
commit 1692dcf197470d074f69d5af1608cb2ff1d08872
Author: Peter Hutterer <peter at cs.unisa.edu.au>
Date:   Wed Jan 30 13:04:58 2008 +1030

    dix: print out event type if a bogus pointer event occurs.

diff --git a/dix/events.c b/dix/events.c
index 15aa16e..4a8e480 100644
--- a/dix/events.c
+++ b/dix/events.c
@@ -3312,7 +3312,7 @@ ProcessPointerEvent (xEvent *xE, DeviceIntPtr mouse, int count)
 		deactivateGrab = TRUE;
 	    break;
 	default: 
-	    FatalError("bogus pointer event from ddx");
+	    FatalError("bogus pointer event from ddx: %d", xE->u.u.type);
 	}
     }
     else if (!CheckMotion(xE))
commit d954f9c80348de294602d931d387e5cd1ef4b9a5
Author: Peter Hutterer <peter at cs.unisa.edu.au>
Date:   Wed Jan 30 10:39:54 2008 +1030

    xkb: don't update LEDs if they don't exist. (Bug #13961)
    
    In some weird cases we call this function when there is no SrvLedInfo on the
    device. And it turns out null-pointer dereferences are bad.
    
    X.Org Bug 13961 <http://bugs.freedesktop.org/show_bug.cgi?id=13961>

diff --git a/xkb/xkbLEDs.c b/xkb/xkbLEDs.c
index 2877af0..55ce12a 100644
--- a/xkb/xkbLEDs.c
+++ b/xkb/xkbLEDs.c
@@ -63,6 +63,9 @@ XkbSrvLedInfoPtr	sli;
 
     sli= XkbFindSrvLedInfo(dev,XkbDfltXIClass,XkbDfltXIId,0);
 
+    if (!sli)
+        return update;
+
     if (state_changes&(XkbModifierStateMask|XkbGroupStateMask))
 	update|= sli->usesEffective;
     if (state_changes&(XkbModifierBaseMask|XkbGroupBaseMask))
commit df325be394e1f75c396b2768f81373f2989aef7c
Author: Coleman Kane <cokane at cokane.org>
Date:   Tue Jan 29 09:47:00 2008 -0800

    Bug 13101: xorg-server has a typo in hw/xfree86/os-support/bsd/i386_video.c
    
    X.Org Bug #13101 <https://bugs.freedesktop.org/show_bug.cgi?id=13101>
    Patch #12360 <https://bugs.freedesktop.org/attachment.cgi?id=12360>

diff --git a/hw/xfree86/os-support/bsd/i386_video.c b/hw/xfree86/os-support/bsd/i386_video.c
index 42b9054..0dcff66 100644
--- a/hw/xfree86/os-support/bsd/i386_video.c
+++ b/hw/xfree86/os-support/bsd/i386_video.c
@@ -602,7 +602,7 @@ cleanMTRR()
 #ifdef DEBUG
 			ErrorF("Clean for (0x%lx,0x%lx)\n",
 				(unsigned long)mrd[i].mr_base,
-				(unsigned long)rd[i].mr_len);
+				(unsigned long)mrd[i].mr_len);
 #endif
 			if (mrd[i].mr_flags & MDF_FIXACTIVE) {
 				mro.mo_arg[0] = MEMRANGE_SET_UPDATE;
commit 94f412cb7e954fe872fed979057cbdfbef953c6f
Author: Julien Goodwin <julien at studio442.com.au>
Date:   Sun Jan 27 12:30:16 2008 +1100

    Loader: Fix verbosity confusion
    
    'Loading foo' is verbosity 3, whereas 'already built-in' is verbosity 0.
    This means that gdm's log would just be full of bare 'module already
    built-in' messages.

diff --git a/hw/xfree86/loader/loadmod.c b/hw/xfree86/loader/loadmod.c
index 584cabf..45e9cb3 100644
--- a/hw/xfree86/loader/loadmod.c
+++ b/hw/xfree86/loader/loadmod.c
@@ -864,7 +864,7 @@ doLoadModule(const char *module, const char *path, const char **subdirlist,
     for (cim = compiled_in_modules; *cim; cim++)
 	if (!strcmp (module, *cim))
 	{
-	    xf86MsgVerb(X_INFO, 0, "Module \"%s\" already built-in\n", module);
+	    xf86MsgVerb(X_INFO, 3, "Module \"%s\" already built-in\n", module);
 	    return (ModuleDescPtr) 1;
 	}
 
commit 442838fcb3bf07ac57553ae5600d9e6c59a559bb
Author: Julien Goodwin <julien at studio442.com.au>
Date:   Sun Jan 27 12:27:26 2008 +1100

    xorg.conf.man: Fix monitor/output confusion in monitor positioning
    
    On the Intel driver at least, LeftOf/RightOf/Above/Below in xorg.conf refers
    to output names, not monitor names.  Fix nomenclature in xorg.conf.man.

diff --git a/hw/xfree86/doc/man/xorg.conf.man.pre b/hw/xfree86/doc/man/xorg.conf.man.pre
index 1369a16..608ba37 100644
--- a/hw/xfree86/doc/man/xorg.conf.man.pre
+++ b/hw/xfree86/doc/man/xorg.conf.man.pre
@@ -1432,24 +1432,24 @@ This optional entry specifies the position of the monitor within the X
 screen.
 (RandR 1.2-supporting drivers only)
 .TP 7
-.BI "Option " "\*qLeftOf\*q  " \*qmonitor\*q
+.BI "Option " "\*qLeftOf\*q  " \*qoutput\*q
 This optional entry specifies that the monitor should be positioned to the
-left of the monitor of the given name.
+left of the output (not monitor) of the given name.
 (RandR 1.2-supporting drivers only)
 .TP 7
-.BI "Option " "\*qRightOf\*q  " \*qmonitor\*q
+.BI "Option " "\*qRightOf\*q  " \*qoutput\*q
 This optional entry specifies that the monitor should be positioned to the
-right of the monitor of the given name.
+right of the output (not monitor) of the given name.
 (RandR 1.2-supporting drivers only)
 .TP 7
-.BI "Option " "\*qAbove\*q  " \*qmonitor\*q
+.BI "Option " "\*qAbove\*q  " \*qoutput\*q
 This optional entry specifies that the monitor should be positioned above the
-monitor of the given name.
+output (not monitor) of the given name.
 (RandR 1.2-supporting drivers only)
 .TP 7
-.BI "Option " "\*qBelow\*q  " \*qmonitor\*q
+.BI "Option " "\*qBelow\*q  " \*qoutput\*q
 This optional entry specifies that the monitor should be positioned below the
-monitor of the given name.
+output (not monitor) of the given name.
 (RandR 1.2-supporting drivers only)
 .TP 7
 .BI "Option " "\*qEnable\*q  " \*qbool\*q
commit 5b8641a5fdc112c19e78ca2954878712e328d403
Author: Peter Hutterer <peter at cs.unisa.edu.au>
Date:   Tue Jan 29 10:01:37 2008 +1030

    xfree86: fix AlwaysCore handling. (Bug #14256)
    
    Assume AlwaysCore being set by default, just like the other options.
    
    X.Org Bug 14256 <http://bugs.freedesktop.org/show_bug.cgi?id=14256>

diff --git a/hw/xfree86/common/xf86Xinput.c b/hw/xfree86/common/xf86Xinput.c
index cd0c30a..9a94c04 100644
--- a/hw/xfree86/common/xf86Xinput.c
+++ b/hw/xfree86/common/xf86Xinput.c
@@ -115,7 +115,7 @@ _X_EXPORT void
 xf86ProcessCommonOptions(LocalDevicePtr local,
                          pointer	list)
 {
-    if (xf86SetBoolOption(list, "AlwaysCore", 0) ||
+    if (!xf86SetBoolOption(list, "AlwaysCore", 1) ||
         !xf86SetBoolOption(list, "SendCoreEvents", 1) ||
         !xf86SetBoolOption(list, "CorePointer", 1) ||
         !xf86SetBoolOption(list, "CoreKeyboard", 1)) {
commit 975ab11799c819a81da1dfe83505194410dbcb95
Author: Peter Hutterer <peter at cs.unisa.edu.au>
Date:   Sat Jan 26 09:39:54 2008 +1030

    config: don't reset connection info on disconnect.
    
    If dbus is restarted, we try to connect again and this is difficult if the
    busname and/or busobject is not set.
    (cherry picked from commit 210eeef495770c1883c842ff003c28ce25f279d4)

diff --git a/config/dbus.c b/config/dbus.c
index f6ac4c1..0be42af 100644
--- a/config/dbus.c
+++ b/config/dbus.c
@@ -396,9 +396,6 @@ err_start:
 static void
 disconnect_hook(void *data)
 {
-    struct connection_info *info = data;
-
-    reset_info(info);
 }
 
 #if 0
@@ -440,4 +437,6 @@ void
 config_dbus_fini(void)
 {
     config_dbus_core_remove_hook(&core_hook);
+    connection_data.busname[0] = '\0';
+    connection_data.busobject[0] = '\0';
 }
commit 7dde5a694a06efed0a9186f05d33f5be6f5dba71
Author: Peter Hutterer <peter at cs.unisa.edu.au>
Date:   Fri Jan 25 13:54:47 2008 +1030

    config: check connection != NULL before getting dbus' dispatch status.
    
    (cherry picked from commit d23266522390a4ef7203ae7c062b2b920e45f9d7)

diff --git a/config/dbus-core.c b/config/dbus-core.c
index 9cf1530..b349c6e 100644
--- a/config/dbus-core.c
+++ b/config/dbus-core.c
@@ -56,8 +56,9 @@ wakeup_handler(pointer data, int err, pointer read_mask)
     if (info->connection && FD_ISSET(info->fd, (fd_set *) read_mask)) {
         do {
             dbus_connection_read_write_dispatch(info->connection, 0);
-        } while (dbus_connection_get_dispatch_status(info->connection) ==
-                  DBUS_DISPATCH_DATA_REMAINS);
+        } while (info->connection &&
+                 dbus_connection_get_is_connected(info->connection) &&
+                 dbus_connection_get_dispatch_status(info->connection) == DBUS_DISPATCH_DATA_REMAINS);
     }
 }
 
commit f0ba7707161b8866e6fde32d6f25be6afcdecb48
Author: Peter Hutterer <peter at cs.unisa.edu.au>
Date:   Fri Jan 25 13:45:22 2008 +1030

    config: only shutdown libhal if the connection is valid.
    
    Thanks to libdbus' extensive use of assert we won't just get an error, it'll
    bring the whole server down for us.
    (cherry picked from commit fb07fab2c07e7b0834724541dc47bfba02ba8574)

diff --git a/config/hal.c b/config/hal.c
index 52a0113..1575422 100644
--- a/config/hal.c
+++ b/config/hal.c
@@ -283,12 +283,14 @@ disconnect_hook(void *data)
     struct config_hal_info *info = data;
 
     if (info->hal_ctx) {
-        dbus_error_init(&error);
-        if (!libhal_ctx_shutdown(info->hal_ctx, &error))
-            DebugF("[config/hal] couldn't shut down context: %s (%s)\n",
-                   error.name, error.message);
+        if (dbus_connection_get_is_connected(info->system_bus)) {
+            dbus_error_init(&error);
+            if (!libhal_ctx_shutdown(info->hal_ctx, &error))
+                DebugF("[config/hal] couldn't shut down context: %s (%s)\n",
+                        error.name, error.message);
+            dbus_error_free(&error);
+        }
         libhal_ctx_free(info->hal_ctx);
-        dbus_error_free(&error);
     }
 
     info->hal_ctx = NULL;
commit 2cb0ebec2b85d96289c23c17cfdcdf97ef6877d2
Author: Peter Hutterer <peter at cs.unisa.edu.au>
Date:   Fri Jan 25 11:48:13 2008 +1030

    config: add a debug message, fix a whitespace error.
    
    (cherry picked from commit 7732898aaa70e076000f6e6aa9420482896ed996)

diff --git a/config/hal.c b/config/hal.c
index 4ab2961..52a0113 100644
--- a/config/hal.c
+++ b/config/hal.c
@@ -105,7 +105,7 @@ get_prop_string(LibHalContext *hal_ctx, const char *udi, const char *name)
     char *prop, *ret;
 
     prop = libhal_device_get_property_string(hal_ctx, udi, name, NULL);
-    DebugF(" [config/hal] getting %s on %s returned %s\n", name, udi, prop);
+    DebugF("[config/hal] getting %s on %s returned %s\n", name, udi, prop);
     if (prop) {
         ret = xstrdup(prop);
         libhal_free_string(prop);
@@ -234,8 +234,9 @@ device_added(LibHalContext *hal_ctx, const char *udi)
     if (xkb_options)
         add_option(&options, "xkb_options", xkb_options);
 
+    DebugF("[config/hal] Adding device %s\n", name);
     if (NewInputDeviceRequest(options, &dev) != Success) {
-        DebugF("[config/hal] NewInputDeviceRequest failed\n");
+        ErrorF("[config/hal] NewInputDeviceRequest failed\n");
         dev = NULL;
         goto unwind;
     }
commit 4fc2d3cef8d7868b025aa14af7ed4b730e8f2c49
Author: Jeremy Huddleston <jeremy at tifa.local>
Date:   Mon Jan 28 12:18:43 2008 -0800

    Rootless: RootlessEnsureFrame: Added check for !IsRoot
    This was causing an issue with Apple-DRI and was reported here:
    http://trac.macosforge.org/projects/xquartz/ticket/51
    (cherry picked from commit 116800279d2ec783c63f43d3902627edde6a4cff)

diff --git a/miext/rootless/rootlessWindow.c b/miext/rootless/rootlessWindow.c
index b953398..7285f95 100644
--- a/miext/rootless/rootlessWindow.c
+++ b/miext/rootless/rootlessWindow.c
@@ -471,7 +471,7 @@ RootlessEnsureFrame(WindowPtr pWin)
     if (WINREC(pWin) != NULL)
         return WINREC(pWin);
 
-    if (!IsTopLevel(pWin))
+    if (!IsTopLevel(pWin) && !IsRoot(pWin))
         return NULL;
 
     if (pWin->drawable.class != InputOutput)
commit 16b0614c8c441eb1692bde9e58fadf54a9c6f00f
Merge: 1a88aed... e915a26...
Author: David Nusinow <dnusinow at debian.org>
Date:   Sat Jan 26 16:13:25 2008 -0500

    Merge commit 'upstream/master'

commit e915a2639752bc0ea9e6e192e020cc2031c08063
Author: Eamon Walsh <ewalsh at tycho.nsa.gov>
Date:   Fri Jan 25 19:22:19 2008 -0500

    xselinux: Move the extension to extmod instead of being built-in.

diff --git a/Xext/Makefile.am b/Xext/Makefile.am
index f57e599..648736d 100644
--- a/Xext/Makefile.am
+++ b/Xext/Makefile.am
@@ -76,7 +76,7 @@ endif
 # requires X-ACE extension
 XSELINUX_SRCS = xselinux.c xselinux.h
 if XSELINUX
-BUILTIN_SRCS += $(XSELINUX_SRCS)
+MODULE_SRCS += $(XSELINUX_SRCS)
 endif
 
 # Security extension: multi-level security to protect clients from each other
diff --git a/hw/xfree86/dixmods/extmod/modinit.c b/hw/xfree86/dixmods/extmod/modinit.c
index acd7006..d0d892a 100644
--- a/hw/xfree86/dixmods/extmod/modinit.c
+++ b/hw/xfree86/dixmods/extmod/modinit.c
@@ -38,6 +38,15 @@ static MODULESETUPPROTO(extmodSetup);
  * Array describing extensions to be initialized
  */
 static ExtensionModule extensionModules[] = {
+#ifdef XSELINUX
+    {
+	SELinuxExtensionInit,
+	SELINUX_EXTENSION_NAME,
+	NULL,
+	NULL,
+	NULL
+    },
+#endif
 #ifdef SHAPE
     {
 	ShapeExtensionInit,
diff --git a/hw/xfree86/dixmods/extmod/modinit.h b/hw/xfree86/dixmods/extmod/modinit.h
index 116cb2e..3c2e202 100644
--- a/hw/xfree86/dixmods/extmod/modinit.h
+++ b/hw/xfree86/dixmods/extmod/modinit.h
@@ -127,6 +127,7 @@ extern void ShmRegisterFuncs(
 
 #ifdef XSELINUX
 extern void SELinuxExtensionInit(INITARGS);
+#include "xselinux.h"
 #endif
 
 #if 1
diff --git a/mi/miinitext.c b/mi/miinitext.c
index 30cbc7a..261fac9 100644
--- a/mi/miinitext.c
+++ b/mi/miinitext.c
@@ -690,9 +690,6 @@ static ExtensionModule staticExtensions[] = {
 #ifdef XCSECURITY
     { SecurityExtensionInit, SECURITY_EXTENSION_NAME, &noSecurityExtension, NULL, NULL },
 #endif
-#ifdef XSELINUX
-    { SELinuxExtensionInit, SELINUX_EXTENSION_NAME, NULL, NULL, NULL },
-#endif
 #ifdef XPRINT
     { XpExtensionInit, XP_PRINTNAME, NULL, NULL, NULL },
 #endif
commit f6a78ee143e3a3ad69538adf2b9675d724468ffa
Author: Eamon Walsh <ewalsh at tycho.nsa.gov>
Date:   Fri Jan 25 18:04:10 2008 -0500

    XACE: Remove the extension code entirely, XACE is completely static now.

diff --git a/Xext/xace.c b/Xext/xace.c
index 0b3baf6..0470e44 100644
--- a/Xext/xace.c
+++ b/Xext/xace.c
@@ -24,7 +24,6 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 #include <stdarg.h>
 #include "scrnintstr.h"
 #include "xacestr.h"
-#include "modinit.h"
 
 CallbackListPtr XaceHooks[XACE_NUM_HOOKS] = {0};
 
@@ -222,14 +221,6 @@ int XaceHook(int hook, ...)
     return prv ? *prv : Success;
 }
 
-/* XaceExtensionInit
- *
- * Initialize the XACE Extension
- */
-void XaceExtensionInit(INITARGS)
-{
-}
-
 /* XaceCensorImage
  *
  * Called after pScreen->GetImage to prevent pieces or trusted windows from
diff --git a/Xext/xace.h b/Xext/xace.h
index a8fac98..4100ba1 100644
--- a/Xext/xace.h
+++ b/Xext/xace.h
@@ -22,7 +22,6 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 
 #ifdef XACE
 
-#define XACE_EXTENSION_NAME		"XAccessControlExtension"
 #define XACE_MAJOR_VERSION		2
 #define XACE_MINOR_VERSION		0
 
diff --git a/hw/xfree86/dixmods/extmod/modinit.h b/hw/xfree86/dixmods/extmod/modinit.h
index 99d714c..116cb2e 100644
--- a/hw/xfree86/dixmods/extmod/modinit.h
+++ b/hw/xfree86/dixmods/extmod/modinit.h
@@ -125,10 +125,6 @@ extern void ShmRegisterFuncs(
     ShmFuncsPtr funcs);
 #endif
 
-#ifdef XACE
-extern void XaceExtensionInit(INITARGS);
-#endif
-
 #ifdef XSELINUX
 extern void SELinuxExtensionInit(INITARGS);
 #endif
diff --git a/mi/miinitext.c b/mi/miinitext.c
index b146907..30cbc7a 100644
--- a/mi/miinitext.c
+++ b/mi/miinitext.c
@@ -244,9 +244,6 @@ typedef void (*InitExtension)(INITARGS);
 #define _XAG_SERVER_
 #include <X11/extensions/Xagstr.h>
 #endif
-#ifdef XACE
-#include "xace.h"
-#endif
 #ifdef XCSECURITY
 #include "securitysrv.h"
 #include <X11/extensions/securstr.h>
@@ -323,9 +320,6 @@ extern void DbeExtensionInit(INITARGS);
 #ifdef XAPPGROUP
 extern void XagExtensionInit(INITARGS);
 #endif
-#ifdef XACE
-extern void XaceExtensionInit(INITARGS);
-#endif
 #ifdef XCSECURITY
 extern void SecurityExtensionInit(INITARGS);
 #endif
@@ -599,9 +593,6 @@ InitExtensions(argc, argv)
 #ifdef XAPPGROUP
     if (!noXagExtension) XagExtensionInit();
 #endif
-#ifdef XACE
-    XaceExtensionInit();
-#endif
 #ifdef XCSECURITY
     if (!noSecurityExtension) SecurityExtensionInit();
 #endif
@@ -696,9 +687,6 @@ static ExtensionModule staticExtensions[] = {
 #ifdef XAPPGROUP
     { XagExtensionInit, XAGNAME, &noXagExtension, NULL, NULL },
 #endif
-#ifdef XACE
-    { XaceExtensionInit, XACE_EXTENSION_NAME, NULL, NULL, NULL },
-#endif
 #ifdef XCSECURITY
     { SecurityExtensionInit, SECURITY_EXTENSION_NAME, &noSecurityExtension, NULL, NULL },
 #endif
commit 7724c30a751c653ca3e2e8a6752af27bc37de3f0
Author: Eamon Walsh <ewalsh at tycho.nsa.gov>
Date:   Fri Jan 25 17:28:17 2008 -0500

    XACE: Stop using fake requestVectors in favor of a simple hook call.

diff --git a/Xext/xace.c b/Xext/xace.c
index 6326735..0b3baf6 100644
--- a/Xext/xace.c
+++ b/Xext/xace.c
@@ -28,27 +28,28 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 
 CallbackListPtr XaceHooks[XACE_NUM_HOOKS] = {0};
 
-/* Proc vectors for untrusted clients, swapped and unswapped versions.
- * These are the same as the normal proc vectors except that extensions
- * that haven't declared themselves secure will have ProcBadRequest plugged
- * in for their major opcode dispatcher.  This prevents untrusted clients
- * from guessing extension major opcodes and using the extension even though
- * the extension can't be listed or queried.
- */
-static int (*UntrustedProcVector[256])(
-    ClientPtr /*client*/
-);
-static int (*SwappedUntrustedProcVector[256])(
-    ClientPtr /*client*/
-);
-
 /* Special-cased hook functions.  Called by Xserver.
  */
-void XaceHookAuditBegin(ClientPtr ptr)
+int XaceHookDispatch(ClientPtr client, int major)
 {
-    XaceAuditRec rec = { ptr, 0 };
-    /* call callbacks, there is no return value. */
+    /* Call the audit begin callback, there is no return value. */
+    XaceAuditRec rec = { client, 0 };
     CallCallbacks(&XaceHooks[XACE_AUDIT_BEGIN], &rec);
+
+    if (major < 128) {
+	/* Call the core dispatch hook */
+	XaceCoreDispatchRec rec = { client, Success /* default allow */ };
+	CallCallbacks(&XaceHooks[XACE_CORE_DISPATCH], &rec);
+	return rec.status;
+    } else {
+	/* Call the extension dispatch hook */
+	ExtensionEntry *ext = GetExtensionEntry(major);
+	XaceExtAccessRec rec = { client, ext, DixUseAccess, Success };
+	if (ext)
+	    CallCallbacks(&XaceHooks[XACE_EXT_DISPATCH], &rec);
+	/* On error, pretend extension doesn't exist */
+	return (rec.status == Success) ? Success : BadRequest;
+    }
 }
 
 void XaceHookAuditEnd(ClientPtr ptr, int result)
@@ -221,116 +222,12 @@ int XaceHook(int hook, ...)
     return prv ? *prv : Success;
 }
 
-static int
-XaceCatchDispatchProc(ClientPtr client)
-{
-    REQUEST(xReq);
-    int major = stuff->reqType;
-    XaceCoreDispatchRec rec = { client, Success /* default allow */ };
-
-    if (!ProcVector[major])
-	return BadRequest;
-
-    /* call callbacks and return result, if any. */
-    CallCallbacks(&XaceHooks[XACE_CORE_DISPATCH], &rec);
-
-    if (rec.status != Success)
-	return rec.status;
-
-    return client->swapped ? 
-	(* SwappedProcVector[major])(client) :
-	(* ProcVector[major])(client);
-}
-
-static int
-XaceCatchExtProc(ClientPtr client)
-{
-    REQUEST(xReq);
-    int major = stuff->reqType;
-    ExtensionEntry *ext = GetExtensionEntry(major);
-    XaceExtAccessRec rec = { client, ext, DixUseAccess, Success };
-
-    if (!ext || !ProcVector[major])
-	return BadRequest;
-
-    /* call callbacks and return result, if any. */
-    CallCallbacks(&XaceHooks[XACE_EXT_DISPATCH], &rec);
-
-    if (rec.status != Success)
-	return BadRequest; /* pretend extension doesn't exist */
-
-    return client->swapped ?
-	(* SwappedProcVector[major])(client) :
-	(* ProcVector[major])(client);
-}
-
-	
-/* SecurityClientStateCallback
- *
- * Arguments:
- *	pcbl is &ClientStateCallback.
- *	nullata is NULL.
- *	calldata is a pointer to a NewClientInfoRec (include/dixstruct.h)
- *	which contains information about client state changes.
- *
- * Returns: nothing.
- *
- * Side Effects:
- * 
- * If a new client is connecting, its authorization ID is copied to
- * client->authID.  If this is a generated authorization, its reference
- * count is bumped, its timer is cancelled if it was running, and its
- * trustlevel is copied to TRUSTLEVEL(client).
- * 
- * If a client is disconnecting and the client was using a generated
- * authorization, the authorization's reference count is decremented, and
- * if it is now zero, the timer for this authorization is started.
- */
-
-static void
-XaceClientStateCallback(
-    CallbackListPtr *pcbl,
-    pointer nulldata,
-    pointer calldata)
-{
-    NewClientInfoRec *pci = (NewClientInfoRec *)calldata;
-    ClientPtr client = pci->client;
-
-    switch (client->clientState)
-    {
-	case ClientStateRunning:
-	{ 
-	    client->requestVector = client->swapped ?
-		SwappedUntrustedProcVector : UntrustedProcVector;
-	    break;
-	}
-	default: break; 
-    }
-} /* XaceClientStateCallback */
-
 /* XaceExtensionInit
  *
  * Initialize the XACE Extension
  */
 void XaceExtensionInit(INITARGS)
 {
-    ExtensionEntry	*extEntry;
-    int i;
-
-    if (!AddCallback(&ClientStateCallback, XaceClientStateCallback, NULL))
-	return;
-
-    /* initialize dispatching intercept functions */
-    for (i = 0; i < 128; i++)
-    {
-	UntrustedProcVector[i] = XaceCatchDispatchProc;
-	SwappedUntrustedProcVector[i] = XaceCatchDispatchProc;
-    }
-    for (i = 128; i < 256; i++)
-    {
-	UntrustedProcVector[i] = XaceCatchExtProc;
-	SwappedUntrustedProcVector[i] = XaceCatchExtProc;
-    }
 }
 
 /* XaceCensorImage
diff --git a/Xext/xace.h b/Xext/xace.h
index fdf91d1..a8fac98 100644
--- a/Xext/xace.h
+++ b/Xext/xace.h
@@ -65,8 +65,8 @@ extern int XaceHook(
 
 /* Special-cased hook functions
  */
+extern int XaceHookDispatch(ClientPtr ptr, int major);
 extern void XaceHookAuditEnd(ClientPtr ptr, int result);
-extern void XaceHookAuditBegin(ClientPtr ptr);
 
 /* Register a callback for a given hook.
  */
@@ -101,13 +101,13 @@ extern void XaceCensorImage(
 
 #ifdef __GNUC__
 #define XaceHook(args...) Success
+#define XaceHookDispatch(args...) Success
 #define XaceHookAuditEnd(args...) { ; }
-#define XaceHookAuditBegin(args...) { ; }
 #define XaceCensorImage(args...) { ; }
 #else
 #define XaceHook(...) Success
+#define XaceHookDispatch(...) Success
 #define XaceHookAuditEnd(...) { ; }
-#define XaceHookAuditBegin(...) { ; }
 #define XaceCensorImage(...) { ; }
 #endif
 
diff --git a/dix/dispatch.c b/dix/dispatch.c
index 004509c..663bf7d 100644
--- a/dix/dispatch.c
+++ b/dix/dispatch.c
@@ -463,8 +463,9 @@ Dispatch(void)
 		if (result > (maxBigRequestSize << 2))
 		    result = BadLength;
 		else {
-		    XaceHookAuditBegin(client);
-		    result = (* client->requestVector[MAJOROP])(client);
+		    result = XaceHookDispatch(client, MAJOROP);
+		    if (result == Success)
+			result = (* client->requestVector[MAJOROP])(client);
 		    XaceHookAuditEnd(client, result);
 		}
 #ifdef XSERVER_DTRACE
commit f82329b0811469ddae5c44dcfffa38185c11a67c
Author: Eamon Walsh <ewalsh at tycho.nsa.gov>
Date:   Fri Jan 25 16:20:46 2008 -0500

    XACE: Don't need to actually register a protocol extension.

diff --git a/Xext/xace.c b/Xext/xace.c
index e85a517..6326735 100644
--- a/Xext/xace.c
+++ b/Xext/xace.c
@@ -222,51 +222,6 @@ int XaceHook(int hook, ...)
 }
 
 static int
-ProcXaceDispatch(ClientPtr client)
-{
-    REQUEST(xReq);
-
-    switch (stuff->data)
-    {
-	default:
-	    return BadRequest;
-    }
-} /* ProcXaceDispatch */
-
-static int
-SProcXaceDispatch(ClientPtr client)
-{
-    REQUEST(xReq);
-
-    switch (stuff->data)
-    {
-	default:
-	    return BadRequest;
-    }
-} /* SProcXaceDispatch */
-
-
-/* XaceResetProc
- *
- * Arguments:
- *	extEntry is the extension information for the XACE extension.
- *
- * Returns: nothing.
- *
- * Side Effects:
- *	Performs any cleanup needed by XACE at server shutdown time.
- */
-static void
-XaceResetProc(ExtensionEntry *extEntry)
-{
-    int i;
-
-    for (i=0; i<XACE_NUM_HOOKS; i++)
-	DeleteCallbackList(&XaceHooks[i]);
-} /* XaceResetProc */
-
-
-static int
 XaceCatchDispatchProc(ClientPtr client)
 {
     REQUEST(xReq);
@@ -365,11 +320,6 @@ void XaceExtensionInit(INITARGS)
     if (!AddCallback(&ClientStateCallback, XaceClientStateCallback, NULL))
 	return;
 
-    extEntry = AddExtension(XACE_EXTENSION_NAME,
-			    XaceNumberEvents, XaceNumberErrors,
-			    ProcXaceDispatch, SProcXaceDispatch,
-			    XaceResetProc, StandardMinorOpcode);
-
     /* initialize dispatching intercept functions */
     for (i = 0; i < 128; i++)
     {
diff --git a/Xext/xace.h b/Xext/xace.h
index 6f92290..fdf91d1 100644
--- a/Xext/xace.h
+++ b/Xext/xace.h
@@ -29,9 +29,6 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 #include "pixmap.h"     /* for DrawablePtr */
 #include "regionstr.h"  /* for RegionPtr */
 
-#define XaceNumberEvents		0
-#define XaceNumberErrors		0
-
 /* Default window background */
 #define XaceBackgroundNoneState		None
 
commit 46794d0c9665f07913980830d038c88d00407612
Author: Eamon Walsh <ewalsh at tycho.nsa.gov>
Date:   Thu Jan 24 19:49:13 2008 -0500

    xselinux: Rename SelectionManager to more generic SecurityManager.

diff --git a/Xext/xselinux.c b/Xext/xselinux.c
index 53ea6c1..a6e27e6 100644
--- a/Xext/xselinux.c
+++ b/Xext/xselinux.c
@@ -72,8 +72,8 @@ typedef struct {
     security_id_t sid;
 } SELinuxSelectionRec;
 
-static ClientPtr selectionManager;
-static Window selectionWindow;
+static ClientPtr securityManager;
+static Window securityWindow;
 
 /* audit file descriptor */
 static int audit_fd;
@@ -849,9 +849,9 @@ SELinuxClientState(CallbackListPtr *pcbl, pointer unused, pointer calldata)
 
     case ClientStateRetained:
     case ClientStateGone:
-	if (pci->client == selectionManager) {
-	    selectionManager = NULL;
-	    selectionWindow = 0;
+	if (pci->client == securityManager) {
+	    securityManager = NULL;
+	    securityWindow = 0;
 	}
 	break;
 
@@ -935,9 +935,9 @@ SELinuxSelectionState(CallbackListPtr *pcbl, pointer unused, pointer calldata)
 
     case SelectionConvertSelection:
 	/* redirect the convert request if necessary */
-	if (selectionManager && selectionManager != rec->client) {
-	    rec->selection->client = selectionManager;
-	    rec->selection->window = selectionWindow;
+	if (securityManager && securityManager != rec->client) {
+	    rec->selection->client = securityManager;
+	    rec->selection->window = securityWindow;
 	} else {
 	    rec->selection->client = rec->selection->alt_client;
 	    rec->selection->window = rec->selection->alt_window;
@@ -1004,39 +1004,39 @@ ProcSELinuxQueryVersion(ClientPtr client)
 }
 
 static int
-ProcSELinuxSetSelectionManager(ClientPtr client)
+ProcSELinuxSetSecurityManager(ClientPtr client)
 {
     WindowPtr pWin;
     int rc;
 
-    REQUEST(SELinuxSetSelectionManagerReq);
-    REQUEST_SIZE_MATCH(SELinuxSetSelectionManagerReq);
+    REQUEST(SELinuxSetSecurityManagerReq);
+    REQUEST_SIZE_MATCH(SELinuxSetSecurityManagerReq);
 
     if (stuff->window == None) {
-	selectionManager = NULL;
-	selectionWindow = None;
+	securityManager = NULL;
+	securityWindow = None;
     } else {
 	rc = dixLookupResource((pointer *)&pWin, stuff->window, RT_WINDOW,
 			       client, DixGetAttrAccess);
 	if (rc != Success)
 	    return rc;
 
-	selectionManager = client;
-	selectionWindow = stuff->window;
+	securityManager = client;
+	securityWindow = stuff->window;
     }
 
     return Success;
 }
 
 static int
-ProcSELinuxGetSelectionManager(ClientPtr client)
+ProcSELinuxGetSecurityManager(ClientPtr client)
 {
-    SELinuxGetSelectionManagerReply rep;
+    SELinuxGetSecurityManagerReply rep;
 
     rep.type = X_Reply;
     rep.length = 0;
     rep.sequenceNumber = client->sequence;
-    rep.window = selectionWindow;
+    rep.window = securityWindow;
     if (client->swapped) {
 	int n;
 	swaps(&rep.sequenceNumber, n);
@@ -1251,10 +1251,10 @@ ProcSELinuxDispatch(ClientPtr client)
     switch (stuff->data) {
     case X_SELinuxQueryVersion:
 	return ProcSELinuxQueryVersion(client);
-    case X_SELinuxSetSelectionManager:
-	return ProcSELinuxSetSelectionManager(client);
-    case X_SELinuxGetSelectionManager:
-	return ProcSELinuxGetSelectionManager(client);
+    case X_SELinuxSetSecurityManager:
+	return ProcSELinuxSetSecurityManager(client);
+    case X_SELinuxGetSecurityManager:
+	return ProcSELinuxGetSecurityManager(client);
     case X_SELinuxSetDeviceCreateContext:
 	return ProcSELinuxSetDeviceCreateContext(client);
     case X_SELinuxGetDeviceCreateContext:
@@ -1293,14 +1293,14 @@ SProcSELinuxQueryVersion(ClientPtr client)
 }
 
 static int
-SProcSELinuxSetSelectionManager(ClientPtr client)
+SProcSELinuxSetSecurityManager(ClientPtr client)
 {
-    REQUEST(SELinuxSetSelectionManagerReq);
+    REQUEST(SELinuxSetSecurityManagerReq);
     int n;
 
-    REQUEST_SIZE_MATCH(SELinuxSetSelectionManagerReq);
+    REQUEST_SIZE_MATCH(SELinuxSetSecurityManagerReq);
     swapl(&stuff->window, n);
-    return ProcSELinuxSetSelectionManager(client);
+    return ProcSELinuxSetSecurityManager(client);
 }
 
 static int
@@ -1393,10 +1393,10 @@ SProcSELinuxDispatch(ClientPtr client)
     switch (stuff->data) {
     case X_SELinuxQueryVersion:
 	return SProcSELinuxQueryVersion(client);
-    case X_SELinuxSetSelectionManager:
-	return SProcSELinuxSetSelectionManager(client);
-    case X_SELinuxGetSelectionManager:
-	return ProcSELinuxGetSelectionManager(client);
+    case X_SELinuxSetSecurityManager:
+	return SProcSELinuxSetSecurityManager(client);
+    case X_SELinuxGetSecurityManager:
+	return ProcSELinuxGetSecurityManager(client);
     case X_SELinuxSetDeviceCreateContext:
 	return SProcSELinuxSetDeviceCreateContext(client);
     case X_SELinuxGetDeviceCreateContext:
diff --git a/Xext/xselinux.h b/Xext/xselinux.h
index ba1380b..7eeea50 100644
--- a/Xext/xselinux.h
+++ b/Xext/xselinux.h
@@ -31,8 +31,8 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 
 /* Extension protocol */
 #define X_SELinuxQueryVersion			0
-#define X_SELinuxSetSelectionManager		1
-#define X_SELinuxGetSelectionManager		2
+#define X_SELinuxSetSecurityManager		1
+#define X_SELinuxGetSecurityManager		2
 #define X_SELinuxSetDeviceCreateContext		3
 #define X_SELinuxGetDeviceCreateContext		4
 #define X_SELinuxSetDeviceContext		5
@@ -72,13 +72,13 @@ typedef struct {
     CARD8   SELinuxReqType;
     CARD16  length;
     CARD32  window;
-} SELinuxSetSelectionManagerReq;
+} SELinuxSetSecurityManagerReq;
 
 typedef struct {
     CARD8   reqType;
     CARD8   SELinuxReqType;
     CARD16  length;
-} SELinuxGetSelectionManagerReq;
+} SELinuxGetSecurityManagerReq;
 
 typedef struct {
     CARD8   type;
@@ -91,7 +91,7 @@ typedef struct {
     CARD32  pad4;
     CARD32  pad5;
     CARD32  pad6;
-} SELinuxGetSelectionManagerReply;
+} SELinuxGetSecurityManagerReply;
 
 typedef struct {
     CARD8   reqType;
commit 6ffeecabb7f3f3173864e0f0af21a99bdc5b5044
Author: Eamon Walsh <ewalsh at tycho.nsa.gov>
Date:   Thu Jan 24 18:11:49 2008 -0500

    xselinux: Use a privileged bit in the state instead of passing an index
    to the permission checking function.

diff --git a/Xext/xselinux.c b/Xext/xselinux.c
index 1432916..53ea6c1 100644
--- a/Xext/xselinux.c
+++ b/Xext/xselinux.c
@@ -63,6 +63,7 @@ typedef struct {
     security_id_t sid;
     struct avc_entry_ref aeref;
     char *command;
+    int privileged;
 } SELinuxStateRec;
 
 /* selection manager */
@@ -287,11 +288,11 @@ SELinuxTypeToClass(RESTYPE type)
  * Performs an SELinux permission check.
  */
 static int
-SELinuxDoCheck(int clientIndex, SELinuxStateRec *subj, SELinuxStateRec *obj,
+SELinuxDoCheck(SELinuxStateRec *subj, SELinuxStateRec *obj,
 	       security_class_t class, Mask mode, SELinuxAuditRec *auditdata)
 {
     /* serverClient requests OK */
-    if (clientIndex == 0)
+    if (subj->privileged)
 	return Success;
 
     auditdata->command = subj->command;
@@ -383,6 +384,7 @@ SELinuxLabelInitial(void)
 
     /* Do the serverClient */
     state = dixLookupPrivate(&serverClient->devPrivates, stateKey);
+    state->privileged = 1;
     sidput(state->sid);
 
     /* Use the context of the X server process for the serverClient */
@@ -496,8 +498,8 @@ SELinuxDevice(CallbackListPtr *pcbl, pointer unused, pointer calldata)
 	obj->sid = subj->sid;
     }
 
-    rc = SELinuxDoCheck(rec->client->index, subj, obj, SECCLASS_X_DEVICE,
-			rec->access_mode, &auditdata);
+    rc = SELinuxDoCheck(subj, obj, SECCLASS_X_DEVICE, rec->access_mode,
+			&auditdata);
     if (rc != Success)
 	rec->status = rc;
 }
@@ -509,21 +511,18 @@ SELinuxSend(CallbackListPtr *pcbl, pointer unused, pointer calldata)
     SELinuxStateRec *subj, *obj, ev_sid;
     SELinuxAuditRec auditdata = { .client = rec->client };
     security_class_t class;
-    int rc, i, type, clientIndex;
+    int rc, i, type;
 
-    if (rec->dev) {
+    if (rec->dev)
 	subj = dixLookupPrivate(&rec->dev->devPrivates, stateKey);
-	clientIndex = -1; /* some nonzero value */
-    } else {
+    else
 	subj = dixLookupPrivate(&rec->client->devPrivates, stateKey);
-	clientIndex = rec->client->index;
-    }
 
     obj = dixLookupPrivate(&rec->pWin->devPrivates, stateKey);
 
     /* Check send permission on window */
-    rc = SELinuxDoCheck(clientIndex, subj, obj, SECCLASS_X_DRAWABLE,
-			DixSendAccess, &auditdata);
+    rc = SELinuxDoCheck(subj, obj, SECCLASS_X_DRAWABLE, DixSendAccess,
+			&auditdata);
     if (rc != Success)
 	goto err;
 
@@ -537,8 +536,7 @@ SELinuxSend(CallbackListPtr *pcbl, pointer unused, pointer calldata)
 	    goto err;
 
 	auditdata.event = type;
-	rc = SELinuxDoCheck(clientIndex, subj, &ev_sid, class,
-			    DixSendAccess, &auditdata);
+	rc = SELinuxDoCheck(subj, &ev_sid, class, DixSendAccess, &auditdata);
 	if (rc != Success)
 	    goto err;
     }
@@ -560,8 +558,8 @@ SELinuxReceive(CallbackListPtr *pcbl, pointer unused, pointer calldata)
     obj = dixLookupPrivate(&rec->pWin->devPrivates, stateKey);
 
     /* Check receive permission on window */
-    rc = SELinuxDoCheck(rec->client->index, subj, obj, SECCLASS_X_DRAWABLE,
-			DixReceiveAccess, &auditdata);
+    rc = SELinuxDoCheck(subj, obj, SECCLASS_X_DRAWABLE, DixReceiveAccess,
+			&auditdata);
     if (rc != Success)
 	goto err;
 
@@ -575,8 +573,7 @@ SELinuxReceive(CallbackListPtr *pcbl, pointer unused, pointer calldata)
 	    goto err;
 
 	auditdata.event = type;
-	rc = SELinuxDoCheck(rec->client->index, subj, &ev_sid, class,
-			    DixReceiveAccess, &auditdata);
+	rc = SELinuxDoCheck(subj, &ev_sid, class, DixReceiveAccess, &auditdata);
 	if (rc != Success)
 	    goto err;
     }
@@ -633,8 +630,8 @@ SELinuxExtension(CallbackListPtr *pcbl, pointer unused, pointer calldata)
 
     /* Perform the security check */
     auditdata.extension = rec->ext->name;
-    rc = SELinuxDoCheck(rec->client->index, subj, obj, SECCLASS_X_EXTENSION,
-			rec->access_mode, &auditdata);
+    rc = SELinuxDoCheck(subj, obj, SECCLASS_X_EXTENSION, rec->access_mode,
+			&auditdata);
     if (rc != Success)
 	rec->status = rc;
 }
@@ -680,13 +677,12 @@ SELinuxProperty(CallbackListPtr *pcbl, pointer unused, pointer calldata)
 	    return;
 	}
 	freecon(con);
-	avc_entry_ref_init(&obj->aeref);
     }
 
     /* Perform the security check */
     auditdata.property = rec->pProp->propertyName;
-    rc = SELinuxDoCheck(rec->client->index, subj, obj, SECCLASS_X_PROPERTY,
-			rec->access_mode, &auditdata);
+    rc = SELinuxDoCheck(subj, obj, SECCLASS_X_PROPERTY, rec->access_mode,
+			&auditdata);
     if (rc != Success)
 	rec->status = rc;
 }
@@ -741,8 +737,7 @@ SELinuxResource(CallbackListPtr *pcbl, pointer unused, pointer calldata)
     /* Perform the security check */
     auditdata.restype = rec->rtype;
     auditdata.id = rec->id;
-    rc = SELinuxDoCheck(rec->client->index, subj, obj, class,
-			rec->access_mode, &auditdata);
+    rc = SELinuxDoCheck(subj, obj, class, rec->access_mode, &auditdata);
     if (rc != Success)
 	rec->status = rc;
 }
@@ -775,8 +770,7 @@ SELinuxScreen(CallbackListPtr *pcbl, pointer is_saver, pointer calldata)
     if (is_saver)
 	access_mode <<= 2;
 
-    rc = SELinuxDoCheck(rec->client->index, subj, obj, SECCLASS_X_SCREEN,
-			access_mode, &auditdata);
+    rc = SELinuxDoCheck(subj, obj, SECCLASS_X_SCREEN, access_mode, &auditdata);
     if (rc != Success)
 	rec->status = rc;
 }
@@ -792,8 +786,8 @@ SELinuxClient(CallbackListPtr *pcbl, pointer unused, pointer calldata)
     subj = dixLookupPrivate(&rec->client->devPrivates, stateKey);
     obj = dixLookupPrivate(&rec->target->devPrivates, stateKey);
 
-    rc = SELinuxDoCheck(rec->client->index, subj, obj, SECCLASS_X_CLIENT,
-			rec->access_mode, &auditdata);
+    rc = SELinuxDoCheck(subj, obj, SECCLASS_X_CLIENT, rec->access_mode,
+			&auditdata);
     if (rc != Success)
 	rec->status = rc;
 }
@@ -809,8 +803,8 @@ SELinuxServer(CallbackListPtr *pcbl, pointer unused, pointer calldata)
     subj = dixLookupPrivate(&rec->client->devPrivates, stateKey);
     obj = dixLookupPrivate(&serverClient->devPrivates, stateKey);
 
-    rc = SELinuxDoCheck(rec->client->index, subj, obj, SECCLASS_X_SERVER,
-			rec->access_mode, &auditdata);
+    rc = SELinuxDoCheck(subj, obj, SECCLASS_X_SERVER, rec->access_mode,
+			&auditdata);
     if (rc != Success)
 	rec->status = rc;
 }
@@ -832,8 +826,8 @@ SELinuxSelection(CallbackListPtr *pcbl, pointer unused, pointer calldata)
     }
 
     auditdata.selection = rec->name;
-    rc = SELinuxDoCheck(rec->client->index, subj, &sel_sid,
-			SECCLASS_X_SELECTION, rec->access_mode, &auditdata);
+    rc = SELinuxDoCheck(subj, &sel_sid, SECCLASS_X_SELECTION, rec->access_mode,
+			&auditdata);
     if (rc != Success)
 	rec->status = rc;
 }
commit 7ba8e97cbabfef4d614a6a38314830ec0f925471
Author: Eamon Walsh <ewalsh at tycho.nsa.gov>
Date:   Thu Jan 24 19:09:58 2008 -0500

    xselinux: Implement "get context" protocol requests.

diff --git a/Xext/xselinux.c b/Xext/xselinux.c
index ede0350..1432916 100644
--- a/Xext/xselinux.c
+++ b/Xext/xselinux.c
@@ -1098,7 +1098,40 @@ ProcSELinuxSetDeviceContext(ClientPtr client)
 static int
 ProcSELinuxGetDeviceContext(ClientPtr client)
 {
-    return Success;
+    char *ctx;
+    DeviceIntPtr dev;
+    SELinuxStateRec *state;
+    SELinuxGetContextReply rep;
+    int rc;
+
+    REQUEST(SELinuxGetContextReq);
+    REQUEST_SIZE_MATCH(SELinuxGetContextReq);
+
+    rc = dixLookupDevice(&dev, stuff->id, client, DixGetAttrAccess);
+    if (rc != Success)
+	return rc;
+
+    state = dixLookupPrivate(&dev->devPrivates, stateKey);
+    rc = avc_sid_to_context(state->sid, &ctx);
+    if (rc != Success)
+	return BadValue;
+
+    rep.type = X_Reply;
+    rep.length = (strlen(ctx) + 4) >> 2;
+    rep.sequenceNumber = client->sequence;
+    rep.context_len = strlen(ctx) + 1;
+
+    if (client->swapped) {
+	int n;
+	swapl(&rep.length, n);
+	swaps(&rep.sequenceNumber, n);
+	swaps(&rep.context_len, n);
+    }
+
+    WriteToClient(client, sizeof(SELinuxGetContextReply), (char *)&rep);
+    WriteToClient(client, rep.context_len, ctx);
+    free(ctx);
+    return client->noClientException;
 }
 
 static int
@@ -1116,7 +1149,54 @@ ProcSELinuxGetPropertyCreateContext(ClientPtr client)
 static int
 ProcSELinuxGetPropertyContext(ClientPtr client)
 {
-    return Success;
+    char *ctx;
+    WindowPtr pWin;
+    PropertyPtr pProp;
+    SELinuxStateRec *state;
+    SELinuxGetContextReply rep;
+    int rc;
+
+    REQUEST(SELinuxGetPropertyContextReq);
+    REQUEST_SIZE_MATCH(SELinuxGetPropertyContextReq);
+
+    rc = dixLookupWindow(&pWin, stuff->window, client, DixGetPropAccess);
+    if (rc != Success)
+	return rc;
+
+    pProp = wUserProps(pWin);
+    while (pProp) {
+	if (pProp->propertyName == stuff->property)
+	    break;
+	pProp = pProp->next;
+    }
+    if (!pProp)
+	return BadValue;
+
+    rc = XaceHook(XACE_PROPERTY_ACCESS, client, pWin, pProp, DixGetAttrAccess);
+    if (rc != Success)
+	return rc;
+
+    state = dixLookupPrivate(&pProp->devPrivates, stateKey);
+    rc = avc_sid_to_context(state->sid, &ctx);
+    if (rc != Success)
+	return BadValue;
+
+    rep.type = X_Reply;
+    rep.length = (strlen(ctx) + 4) >> 2;
+    rep.sequenceNumber = client->sequence;
+    rep.context_len = strlen(ctx) + 1;
+
+    if (client->swapped) {
+	int n;
+	swapl(&rep.length, n);
+	swaps(&rep.sequenceNumber, n);
+	swaps(&rep.context_len, n);
+    }
+
+    WriteToClient(client, sizeof(SELinuxGetContextReply), (char *)&rep);
+    WriteToClient(client, rep.context_len, ctx);
+    free(ctx);
+    return client->noClientException;
 }
 
 static int
@@ -1134,7 +1214,40 @@ ProcSELinuxGetWindowCreateContext(ClientPtr client)
 static int
 ProcSELinuxGetWindowContext(ClientPtr client)
 {
-    return Success;
+    char *ctx;
+    WindowPtr pWin;
+    SELinuxStateRec *state;
+    SELinuxGetContextReply rep;
+    int rc;
+
+    REQUEST(SELinuxGetContextReq);
+    REQUEST_SIZE_MATCH(SELinuxGetContextReq);
+
+    rc = dixLookupWindow(&pWin, stuff->id, client, DixGetAttrAccess);
+    if (rc != Success)
+	return rc;
+
+    state = dixLookupPrivate(&pWin->devPrivates, stateKey);
+    rc = avc_sid_to_context(state->sid, &ctx);
+    if (rc != Success)
+	return BadValue;
+
+    rep.type = X_Reply;
+    rep.length = (strlen(ctx) + 4) >> 2;
+    rep.sequenceNumber = client->sequence;
+    rep.context_len = strlen(ctx) + 1;
+
+    if (client->swapped) {
+	int n;
+	swapl(&rep.length, n);
+	swaps(&rep.sequenceNumber, n);
+	swaps(&rep.context_len, n);
+    }
+
+    WriteToClient(client, sizeof(SELinuxGetContextReply), (char *)&rep);
+    WriteToClient(client, rep.context_len, ctx);
+    free(ctx);
+    return client->noClientException;
 }
 
 static int
commit f0bf9a5231d4f612ac916355118484d055715f32
Author: Eamon Walsh <ewalsh at tycho.nsa.gov>
Date:   Thu Jan 24 19:02:35 2008 -0500

    xselinux: Whitespace fixups.

diff --git a/Xext/xselinux.c b/Xext/xselinux.c
index 4629e90..ede0350 100644
--- a/Xext/xselinux.c
+++ b/Xext/xselinux.c
@@ -271,7 +271,7 @@ SELinuxTypeToClass(RESTYPE type)
 	    knownTypes[type] = SECCLASS_X_CURSOR;
 	if (fulltype == RT_COLORMAP)
 	    knownTypes[type] = SECCLASS_X_COLORMAP;
-	
+
 	/* Need to do a string lookup */
 	str = LookupResourceName(fulltype);
 	if (!strcmp(str, "PICTURE"))
@@ -890,8 +890,7 @@ SELinuxResourceState(CallbackListPtr *pcbl, pointer unused, pointer calldata)
 	if (rc != Success)
 	    FatalError("SELinux: Failed to set label property on window!\n");
 	freecon(ctx);
-    }
-    else
+    } else
 	FatalError("SELinux: Unexpected unlabeled client found\n");
 
     state = dixLookupPrivate(&pWin->devPrivates, stateKey);
@@ -907,8 +906,7 @@ SELinuxResourceState(CallbackListPtr *pcbl, pointer unused, pointer calldata)
 	if (rc != Success)
 	    FatalError("SELinux: Failed to set label property on window!\n");
 	freecon(ctx);
-    }
-    else
+    } else
 	FatalError("SELinux: Unexpected unlabeled window found\n");
 }
 
@@ -1181,9 +1179,9 @@ SProcSELinuxQueryVersion(ClientPtr client)
     REQUEST(SELinuxQueryVersionReq);
     int n;
 
-    REQUEST_SIZE_MATCH (SELinuxQueryVersionReq);
-    swaps(&stuff->client_major,n);
-    swaps(&stuff->client_minor,n);
+    REQUEST_SIZE_MATCH(SELinuxQueryVersionReq);
+    swaps(&stuff->client_major, n);
+    swaps(&stuff->client_minor, n);
     return ProcSELinuxQueryVersion(client);
 }
 
@@ -1193,8 +1191,8 @@ SProcSELinuxSetSelectionManager(ClientPtr client)
     REQUEST(SELinuxSetSelectionManagerReq);
     int n;
 
-    REQUEST_SIZE_MATCH (SELinuxSetSelectionManagerReq);
-    swapl(&stuff->window,n);
+    REQUEST_SIZE_MATCH(SELinuxSetSelectionManagerReq);
+    swapl(&stuff->window, n);
     return ProcSELinuxSetSelectionManager(client);
 }
 
@@ -1205,7 +1203,7 @@ SProcSELinuxSetDeviceCreateContext(ClientPtr client)
     int n;
 
     REQUEST_AT_LEAST_SIZE(SELinuxSetCreateContextReq);
-    swaps(&stuff->context_len,n);
+    swaps(&stuff->context_len, n);
     return ProcSELinuxSetDeviceCreateContext(client);
 }
 
@@ -1216,8 +1214,8 @@ SProcSELinuxSetDeviceContext(ClientPtr client)
     int n;
 
     REQUEST_AT_LEAST_SIZE(SELinuxSetContextReq);
-    swapl(&stuff->id,n);
-    swaps(&stuff->context_len,n);
+    swapl(&stuff->id, n);
+    swaps(&stuff->context_len, n);
     return ProcSELinuxSetDeviceContext(client);
 }
 
@@ -1228,7 +1226,7 @@ SProcSELinuxGetDeviceContext(ClientPtr client)
     int n;
 
     REQUEST_SIZE_MATCH(SELinuxGetContextReq);
-    swapl(&stuff->id,n);
+    swapl(&stuff->id, n);
     return ProcSELinuxGetDeviceContext(client);
 }
 
@@ -1239,7 +1237,7 @@ SProcSELinuxSetPropertyCreateContext(ClientPtr client)
     int n;
 
     REQUEST_AT_LEAST_SIZE(SELinuxSetCreateContextReq);
-    swaps(&stuff->context_len,n);
+    swaps(&stuff->context_len, n);
     return ProcSELinuxSetPropertyCreateContext(client);
 }
 
@@ -1250,8 +1248,8 @@ SProcSELinuxGetPropertyContext(ClientPtr client)
     int n;
 
     REQUEST_SIZE_MATCH(SELinuxGetPropertyContextReq);
-    swapl(&stuff->window,n);
-    swapl(&stuff->property,n);
+    swapl(&stuff->window, n);
+    swapl(&stuff->property, n);
     return ProcSELinuxGetPropertyContext(client);
 }
 
@@ -1262,7 +1260,7 @@ SProcSELinuxSetWindowCreateContext(ClientPtr client)
     int n;
 
     REQUEST_AT_LEAST_SIZE(SELinuxSetCreateContextReq);
-    swaps(&stuff->context_len,n);
+    swaps(&stuff->context_len, n);
     return ProcSELinuxSetWindowCreateContext(client);
 }
 
@@ -1273,7 +1271,7 @@ SProcSELinuxGetWindowContext(ClientPtr client)
     int n;
 
     REQUEST_SIZE_MATCH(SELinuxGetContextReq);
-    swapl(&stuff->id,n);
+    swapl(&stuff->id, n);
     return ProcSELinuxGetWindowContext(client);
 }
 
@@ -1287,31 +1285,31 @@ SProcSELinuxDispatch(ClientPtr client)
 
     switch (stuff->data) {
     case X_SELinuxQueryVersion:
-        return SProcSELinuxQueryVersion(client);
+	return SProcSELinuxQueryVersion(client);
     case X_SELinuxSetSelectionManager:
 	return SProcSELinuxSetSelectionManager(client);
     case X_SELinuxGetSelectionManager:
-    	return ProcSELinuxGetSelectionManager(client);
+	return ProcSELinuxGetSelectionManager(client);
     case X_SELinuxSetDeviceCreateContext:
-    	return SProcSELinuxSetDeviceCreateContext(client);
+	return SProcSELinuxSetDeviceCreateContext(client);
     case X_SELinuxGetDeviceCreateContext:
-    	return ProcSELinuxGetDeviceCreateContext(client);
+	return ProcSELinuxGetDeviceCreateContext(client);
     case X_SELinuxSetDeviceContext:
-    	return SProcSELinuxSetDeviceContext(client);
+	return SProcSELinuxSetDeviceContext(client);
     case X_SELinuxGetDeviceContext:
-    	return SProcSELinuxGetDeviceContext(client);
+	return SProcSELinuxGetDeviceContext(client);
     case X_SELinuxSetPropertyCreateContext:
-    	return SProcSELinuxSetPropertyCreateContext(client);
+	return SProcSELinuxSetPropertyCreateContext(client);
     case X_SELinuxGetPropertyCreateContext:
-    	return ProcSELinuxGetPropertyCreateContext(client);
+	return ProcSELinuxGetPropertyCreateContext(client);
     case X_SELinuxGetPropertyContext:
-    	return SProcSELinuxGetPropertyContext(client);
+	return SProcSELinuxGetPropertyContext(client);
     case X_SELinuxSetWindowCreateContext:
-    	return SProcSELinuxSetWindowCreateContext(client);
+	return SProcSELinuxSetWindowCreateContext(client);
     case X_SELinuxGetWindowCreateContext:
-    	return ProcSELinuxGetWindowCreateContext(client);
+	return ProcSELinuxGetWindowCreateContext(client);
     case X_SELinuxGetWindowContext:
-    	return SProcSELinuxGetWindowContext(client);
+	return SProcSELinuxGetWindowContext(client);
     default:
 	return BadRequest;
     }
@@ -1376,8 +1374,8 @@ SELinuxExtensionInit(INITARGS)
 
     /* Setup SELinux stuff */
     if (!is_selinux_enabled()) {
-        ErrorF("SELinux: SELinux not enabled, disabling SELinux support.\n");
-        return;
+	ErrorF("SELinux: SELinux not enabled, disabling SELinux support.\n");
+	return;
     }
 
     selinux_set_callback(SELINUX_CB_LOG, (union selinux_callback)SELinuxLog);
@@ -1408,7 +1406,7 @@ SELinuxExtensionInit(INITARGS)
     /* Prepare for auditing */
     audit_fd = audit_open();
     if (audit_fd < 0)
-        FatalError("SELinux: Failed to open the system audit log\n");
+	FatalError("SELinux: Failed to open the system audit log\n");
 
     /* Allocate private storage */
     if (!dixRequestPrivate(stateKey, sizeof(SELinuxStateRec)))
commit 734e115871ce98badb8800383c423493802ae3d3
Author: Hong Liu <hong.liu at intel.com>
Date:   Wed Jan 23 21:04:32 2008 +0800

    Bug #12439: add a quirk to use +hsync +vsync for the probed detailed mode.
    
    Samsung 205BW quirk is somehow reworked.

diff --git a/hw/xfree86/modes/xf86EdidModes.c b/hw/xfree86/modes/xf86EdidModes.c
index 87a8127..b865727 100644
--- a/hw/xfree86/modes/xf86EdidModes.c
+++ b/hw/xfree86/modes/xf86EdidModes.c
@@ -66,6 +66,8 @@ typedef enum {
     DDC_QUIRK_DETAILED_USE_MAXIMUM_SIZE = 1 << 5,
     /* Monitor forgot to set the first detailed is preferred bit. */
     DDC_QUIRK_FIRST_DETAILED_PREFERRED = 1 << 6,
+    /* use +hsync +vsync for detailed mode */
+    DDC_QUIRK_DETAILED_SYNC_PP = 1 << 7,
 } ddc_quirk_t;
 
 static Bool quirk_prefer_large_60 (int scrnIndex, xf86MonPtr DDC)
@@ -160,6 +162,15 @@ static Bool quirk_first_detailed_preferred (int scrnIndex, xf86MonPtr DDC)
     return FALSE;
 }
 
+static Bool quirk_detailed_sync_pp(int scrnIndex, xf86MonPtr DDC)
+{
+    /* Bug #12439: Samsung SyncMaster 205BW */
+    if (memcmp (DDC->vendor.name, "SAM", 4) == 0 &&
+	DDC->vendor.prod_id == 541)
+	return TRUE;
+    return FALSE;
+}
+
 typedef struct {
     Bool	(*detect) (int scrnIndex, xf86MonPtr DDC);
     ddc_quirk_t	quirk;
@@ -195,6 +206,10 @@ static const ddc_quirk_map_t ddc_quirks[] = {
 	quirk_first_detailed_preferred, DDC_QUIRK_FIRST_DETAILED_PREFERRED,
 	"First detailed timing was not marked as preferred."
     },
+    {
+	quirk_detailed_sync_pp, DDC_QUIRK_DETAILED_SYNC_PP,
+	"Use +hsync +vsync for detailed timing."
+    },
     { 
 	NULL,		DDC_QUIRK_NONE,
 	"No known quirks"
@@ -341,15 +356,19 @@ DDCModeFromDetailedTiming(int scrnIndex, struct detailed_timings *timing,
     if (timing->interlaced)
         Mode->Flags |= V_INTERLACE;
 
-    if (timing->misc & 0x02)
-	Mode->Flags |= V_PVSYNC;
-    else
-	Mode->Flags |= V_NVSYNC;
-
-    if (timing->misc & 0x01)
-	Mode->Flags |= V_PHSYNC;
-    else
-	Mode->Flags |= V_NHSYNC;
+    if (quirks & DDC_QUIRK_DETAILED_SYNC_PP)
+	Mode->Flags |= V_PVSYNC | V_PHSYNC;
+    else {
+	if (timing->misc & 0x02)
+	    Mode->Flags |= V_PVSYNC;
+	else
+	    Mode->Flags |= V_NVSYNC;
+
+	if (timing->misc & 0x01)
+	    Mode->Flags |= V_PHSYNC;
+	else
+	    Mode->Flags |= V_NHSYNC;
+    }
 
     return Mode;
 }
commit cc22b05ea06e08568d0f0abdaccf67bd32662e94
Author: Adam Jackson <ajax at redhat.com>
Date:   Tue Jan 22 18:57:11 2008 -0500

    There is no such thing as /dev/cpu/mtrr.

diff --git a/hw/xfree86/os-support/linux/lnx_video.c b/hw/xfree86/os-support/linux/lnx_video.c
index ad2b66f..1bd2d57 100644
--- a/hw/xfree86/os-support/linux/lnx_video.c
+++ b/hw/xfree86/os-support/linux/lnx_video.c
@@ -142,17 +142,8 @@ mtrr_open(int verbosity)
 	/* Only report absence of /proc/mtrr once. */
 	static Bool warned = FALSE;
 
-	char **fn;
-	static char *mtrr_files[] = {
-		"/dev/cpu/mtrr",	/* Possible future name */
-		"/proc/mtrr",		/* Current name */
-		NULL
-	};
-
 	if (mtrr_fd == MTRR_FD_UNOPENED) { 
-		/* So open it. */
-		for (fn = mtrr_files; mtrr_fd < 0 && *fn; fn++)
-			mtrr_fd = open(*fn, O_WRONLY);
+		mtrr_fd = open("/proc/mtrr", O_WRONLY);
 
 		if (mtrr_fd < 0)
 			mtrr_fd = MTRR_FD_PROBLEM;
commit 1a88aed5c82c7c131e3d473ef7b8766a418fdf1b
Author: David Nusinow <dnusinow at debian.org>
Date:   Mon Jan 21 21:16:13 2008 -0500

    Add tags/TAGS to .gitignore for ctags usage

diff --git a/.gitignore b/.gitignore
index b52664b..406b74c 100644
--- a/.gitignore
+++ b/.gitignore
@@ -27,6 +27,8 @@ install-sh
 libtool
 ltmain.sh
 missing
+TAGS
+tags
 ylwrap
 xorg-server.pc
 stamp-h?
commit be6c17fcf9efebc0bbcc3d9a25f8c5a2450c2161
Author: Matthias Hopf <mhopf at suse.de>
Date:   Mon Jan 21 16:13:21 2008 +0100

    CVE-2007-6429: Always test for size+offset wrapping.

diff --git a/Xext/shm.c b/Xext/shm.c
index e46f6fc..a7a1ecf 100644
--- a/Xext/shm.c
+++ b/Xext/shm.c
@@ -799,10 +799,10 @@ CreatePmap:
     if (sizeof(size) == 4 && BitsPerPixel(depth) > 8) {
         if (size < width * height)
             return BadAlloc;
-        /* thankfully, offset is unsigned */
-        if (stuff->offset + size < size)
-            return BadAlloc;
     }
+    /* thankfully, offset is unsigned */
+    if (stuff->offset + size < size)
+	return BadAlloc;
 
     VERIFY_SHMSIZE(shmdesc, stuff->offset, size, client);
 
@@ -1144,10 +1144,10 @@ CreatePmap:
     if (sizeof(size) == 4 && BitsPerPixel(depth) > 8) {
 	if (size < width * height)
 	    return BadAlloc;
-	/* thankfully, offset is unsigned */
-	if (stuff->offset + size < size)
-	    return BadAlloc;
     }
+    /* thankfully, offset is unsigned */
+    if (stuff->offset + size < size)
+	return BadAlloc;
 
     VERIFY_SHMSIZE(shmdesc, stuff->offset, size, client);
     pMap = (*shmFuncs[pDraw->pScreen->myNum]->CreatePixmap)(
commit 94a21d757ce58254accbd5dd3a86810aadeec9f0
Author: Michel Dänzer <michel at tungstengraphics.com>
Date:   Sat Jan 19 13:17:45 2008 +0100

    AIGLX: Fix GLX_EXT_texture_from_pixmap fallback with EXA.
    
    Use pScreen->GetImage to obtain the pixmap contents instead of dereferencing
    pPixmap->devPrivate.ptr directly.

diff --git a/GL/glx/glxdri.c b/GL/glx/glxdri.c
index c0da07b..6c1a199 100644
--- a/GL/glx/glxdri.c
+++ b/GL/glx/glxdri.c
@@ -47,6 +47,8 @@
 #include <xf86.h>
 #include <dri.h>
 
+#include "servermd.h"
+
 #define DRI_NEW_INTERFACE_ONLY
 #include "glxserver.h"
 #include "glxutil.h"
@@ -308,18 +310,20 @@ __glXDRIcontextForceCurrent(__GLXcontext *baseContext)
 }
 
 static void
-glxFillAlphaChannel (PixmapPtr pixmap, int x, int y, int width, int height)
+glxFillAlphaChannel (CARD32 *pixels, CARD32 rowstride, int width, int height)
 {
     int i;
-    CARD32 *p, *end, *pixels = (CARD32 *)pixmap->devPrivate.ptr;
-    CARD32 rowstride = pixmap->devKind / 4;
+    CARD32 *p, *end;
+
+    rowstride /= 4;
     
-    for (i = y; i < y + height; i++)
+    for (i = 0; i < height; i++)
     {
-	p = &pixels[i * rowstride + x];
+	p = pixels;
 	end = p + width;
 	while (p < end)
 	  *p++ |= 0xFF000000;
+	pixels += rowstride;
     }
 }
 
@@ -430,22 +434,31 @@ nooverride:
 	type = GL_UNSIGNED_SHORT_5_6_5;
     }
 
-    CALL_PixelStorei( GET_DISPATCH(), (GL_UNPACK_ROW_LENGTH,
-				       pixmap->devKind / bpp) );
-
     if (pRegion == NULL)
     {
-	if (!override && pixmap->drawable.depth == 24)
-	    glxFillAlphaChannel(pixmap,
-				pixmap->drawable.x,
-				pixmap->drawable.y,
-				pixmap->drawable.width,
-				pixmap->drawable.height);
-
-        CALL_PixelStorei( GET_DISPATCH(), (GL_UNPACK_SKIP_PIXELS,
-					   pixmap->drawable.x) );
-	CALL_PixelStorei( GET_DISPATCH(), (GL_UNPACK_SKIP_ROWS,
-					   pixmap->drawable.y) );
+	void *data = NULL;
+
+	if (!override) {
+	    unsigned pitch = PixmapBytePad(pixmap->drawable.width,
+					   pixmap->drawable.depth); 
+
+	    data = xalloc(pitch * pixmap->drawable.height);
+
+	    pScreen->GetImage(&pixmap->drawable, 0 /*pixmap->drawable.x*/,
+			      0 /*pixmap->drawable.y*/, pixmap->drawable.width,
+			      pixmap->drawable.height, ZPixmap, ~0, data);
+
+	    if (pixmap->drawable.depth == 24)
+		glxFillAlphaChannel(data,
+				    pitch,
+				    pixmap->drawable.width,
+				    pixmap->drawable.height);
+
+	    CALL_PixelStorei( GET_DISPATCH(), (GL_UNPACK_ROW_LENGTH,
+					       pitch / bpp) );
+	    CALL_PixelStorei( GET_DISPATCH(), (GL_UNPACK_SKIP_PIXELS, 0) );
+	    CALL_PixelStorei( GET_DISPATCH(), (GL_UNPACK_SKIP_ROWS, 0) );
+	}
 
 	CALL_TexImage2D( GET_DISPATCH(),
 			 (glxPixmap->target,
@@ -456,26 +469,37 @@ nooverride:
 			  0,
 			  format,
 			  type,
-			  override ? NULL : pixmap->devPrivate.ptr) );
+			  data) );
+
+	xfree(data);
     } else if (!override) {
         int i, numRects;
 	BoxPtr p;
 
 	numRects = REGION_NUM_RECTS (pRegion);
 	p = REGION_RECTS (pRegion);
+
+	CALL_PixelStorei( GET_DISPATCH(), (GL_UNPACK_SKIP_PIXELS, 0) );
+	CALL_PixelStorei( GET_DISPATCH(), (GL_UNPACK_SKIP_ROWS, 0) );
+
 	for (i = 0; i < numRects; i++)
 	{
+	    unsigned pitch = PixmapBytePad(p[i].x2 - p[i].x1,
+					   pixmap->drawable.depth);
+	    void *data = xalloc(pitch * (p[i].y2 - p[i].y1));
+
+	    pScreen->GetImage(&pixmap->drawable, /*pixmap->drawable.x +*/ p[i].x1,
+			      /*pixmap->drawable.y*/ + p[i].y1, p[i].x2 - p[i].x1,
+			      p[i].y2 - p[i].y1, ZPixmap, ~0, data);
+
 	    if (pixmap->drawable.depth == 24)
-		glxFillAlphaChannel(pixmap,
-				    pixmap->drawable.x + p[i].x1,
-				    pixmap->drawable.y + p[i].y1,
+		glxFillAlphaChannel(data,
+				    pitch,
 				    p[i].x2 - p[i].x1,
 				    p[i].y2 - p[i].y1);
 
-	    CALL_PixelStorei( GET_DISPATCH(), (GL_UNPACK_SKIP_PIXELS,
-					       pixmap->drawable.x + p[i].x1) );
-	    CALL_PixelStorei( GET_DISPATCH(), (GL_UNPACK_SKIP_ROWS,
-					       pixmap->drawable.y + p[i].y1) );
+	    CALL_PixelStorei( GET_DISPATCH(), (GL_UNPACK_ROW_LENGTH,
+					       pitch / bpp) );
 
 	    CALL_TexSubImage2D( GET_DISPATCH(),
 				(glxPixmap->target,
@@ -484,7 +508,9 @@ nooverride:
 				 p[i].x2 - p[i].x1, p[i].y2 - p[i].y1,
 				 format,
 				 type,
-				 pixmap->devPrivate.ptr) );
+				 data) );
+
+	    xfree(data);
 	}
     }
 
commit e9fa7c1c88a8130a48f772c92b186b8b777986b5
Author: Adam Jackson <ajax at redhat.com>
Date:   Fri Jan 18 14:41:20 2008 -0500

    CVE-2007-6429: Don't spuriously reject <8bpp shm pixmaps.
    
    Move size validation after depth validation, and only validate size if
    the bpp of the pixmap format is > 8.  If bpp < 8 then we're already
    protected from overflow by the width and height checks.

diff --git a/Xext/shm.c b/Xext/shm.c
index c545e49..e46f6fc 100644
--- a/Xext/shm.c
+++ b/Xext/shm.c
@@ -783,14 +783,6 @@ ProcPanoramiXShmCreatePixmap(
     }
     if (width > 32767 || height > 32767)
         return BadAlloc;
-    size = PixmapBytePad(width, depth) * height;
-    if (sizeof(size) == 4) {
-        if (size < width * height)
-            return BadAlloc;
-        /* thankfully, offset is unsigned */
-        if (stuff->offset + size < size)
-            return BadAlloc;
-    }
 
     if (stuff->depth != 1)
     {
@@ -801,7 +793,17 @@ ProcPanoramiXShmCreatePixmap(
 	client->errorValue = stuff->depth;
         return BadValue;
     }
+
 CreatePmap:
+    size = PixmapBytePad(width, depth) * height;
+    if (sizeof(size) == 4 && BitsPerPixel(depth) > 8) {
+        if (size < width * height)
+            return BadAlloc;
+        /* thankfully, offset is unsigned */
+        if (stuff->offset + size < size)
+            return BadAlloc;
+    }
+
     VERIFY_SHMSIZE(shmdesc, stuff->offset, size, client);
 
     if(!(newPix = (PanoramiXRes *) xalloc(sizeof(PanoramiXRes))))
@@ -1126,14 +1128,6 @@ ProcShmCreatePixmap(client)
     }
     if (width > 32767 || height > 32767)
 	return BadAlloc;
-    size = PixmapBytePad(width, depth) * height;
-    if (sizeof(size) == 4) {
-	if (size < width * height)
-	    return BadAlloc;
-	/* thankfully, offset is unsigned */
-	if (stuff->offset + size < size)
-	    return BadAlloc;
-    }
 
     if (stuff->depth != 1)
     {
@@ -1144,7 +1138,17 @@ ProcShmCreatePixmap(client)
 	client->errorValue = stuff->depth;
         return BadValue;
     }
+
 CreatePmap:
+    size = PixmapBytePad(width, depth) * height;
+    if (sizeof(size) == 4 && BitsPerPixel(depth) > 8) {
+	if (size < width * height)
+	    return BadAlloc;
+	/* thankfully, offset is unsigned */
+	if (stuff->offset + size < size)
+	    return BadAlloc;
+    }
+
     VERIFY_SHMSIZE(shmdesc, stuff->offset, size, client);
     pMap = (*shmFuncs[pDraw->pScreen->myNum]->CreatePixmap)(
 			    pDraw->pScreen, stuff->width,
commit 23f3f0e27dc90b7b3a375f2a5dd094e6f53552b5
Author: Jeremy Huddleston <jeremy at yuffie.local>
Date:   Sun Jan 13 14:00:25 2008 -0800

    XQuartz: Moved SetFrontProcess haco to set_front_process
    So it is done by the other thread...
    (cherry picked from commit 7429379eb1001ee3dc769daa8fe6b3aef1b9cc8a)

diff --git a/hw/xquartz/X11Application.m b/hw/xquartz/X11Application.m
index f688985..be5511d 100644
--- a/hw/xquartz/X11Application.m
+++ b/hw/xquartz/X11Application.m
@@ -314,7 +314,11 @@ static void message_kit_thread (SEL selector, NSObject *arg) {
 }
 
 - (void) set_front_process:unused {
-//    [self activateX:YES];
+    /* Hackery needed due to argv[0] hackery */
+    //    [self activateX:YES];
+    ProcessSerialNumber psn = { 0, kCurrentProcess };
+    SetFrontProcess(&psn);
+
     QuartzMessageServerThread(kXDarwinBringAllToFront, 0);
 }
 
@@ -711,10 +715,6 @@ void X11ApplicationSetWindowMenuCheck (int idx) {
 
 void X11ApplicationSetFrontProcess (void) {
     message_kit_thread (@selector (set_front_process:), nil);
-
-    /* Hackery needed due to argv[0] hackery */
-    ProcessSerialNumber psn = { 0, kCurrentProcess };
-    SetFrontProcess(&psn);
 }
 
 void X11ApplicationSetCanQuit (int state) {
commit 8e133d96740d010a4fd969a8188e6e71fb2cafe2
Author: Matthieu Herrb <matthieu at bluenote.herrb.com>
Date:   Thu Jan 17 15:29:06 2008 +0100

    Fix for CVE-2008-0006 - PCF Font parser buffer overflow.

diff --git a/dix/dixfonts.c b/dix/dixfonts.c
index 2979c64..04f1f1b 100644
--- a/dix/dixfonts.c
+++ b/dix/dixfonts.c
@@ -326,6 +326,13 @@ doOpenFont(ClientPtr client, OFclosurePtr c)
 	err = BadFontName;
 	goto bail;
     }
+    /* check values for firstCol, lastCol, firstRow, and lastRow */
+    if (pfont->info.firstCol > pfont->info.lastCol ||
+       pfont->info.firstRow > pfont->info.lastRow ||
+       pfont->info.lastCol - pfont->info.firstCol > 255) {
+       err = AllocError;
+       goto bail;
+    }
     if (!pfont->fpe)
 	pfont->fpe = fpe;
     pfont->refcnt++;
commit 6de61f82728df22ea01f9659df6581b87f33f11d
Author: Matthieu Herrb <matthieu at bluenote.herrb.com>
Date:   Thu Jan 17 15:28:42 2008 +0100

    Fix for CVE-2007-6429 - MIT-SHM and EVI extensions integer overflows.

diff --git a/Xext/EVI.c b/Xext/EVI.c
index 4bd050c..a637bae 100644
--- a/Xext/EVI.c
+++ b/Xext/EVI.c
@@ -34,6 +34,7 @@ THE USE OR PERFORMANCE OF THIS SOFTWARE.
 #include <X11/extensions/XEVIstr.h>
 #include "EVIstruct.h"
 #include "modinit.h"
+#include "scrnintstr.h"
 
 static EviPrivPtr eviPriv;
 
@@ -84,10 +85,22 @@ ProcEVIGetVisualInfo(ClientPtr client)
 {
     REQUEST(xEVIGetVisualInfoReq);
     xEVIGetVisualInfoReply rep;
-    int n, n_conflict, n_info, sz_info, sz_conflict;
+    int i, n, n_conflict, n_info, sz_info, sz_conflict;
     VisualID32 *conflict;
+    unsigned int total_visuals = 0;
     xExtendedVisualInfo *eviInfo;
     int status;
+
+    /*
+     * do this first, otherwise REQUEST_FIXED_SIZE can overflow.  we assume
+     * here that you don't have more than 2^32 visuals over all your screens;
+     * this seems like a safe assumption.
+     */
+    for (i = 0; i < screenInfo.numScreens; i++)
+	total_visuals += screenInfo.screens[i]->numVisuals;
+    if (stuff->n_visual > total_visuals)
+	return BadValue;
+
     REQUEST_FIXED_SIZE(xEVIGetVisualInfoReq, stuff->n_visual * sz_VisualID32);
     status = eviPriv->getVisualInfo((VisualID32 *)&stuff[1], (int)stuff->n_visual,
 		&eviInfo, &n_info, &conflict, &n_conflict);
diff --git a/Xext/sampleEVI.c b/Xext/sampleEVI.c
index 7508aa7..b871bfd 100644
--- a/Xext/sampleEVI.c
+++ b/Xext/sampleEVI.c
@@ -34,6 +34,13 @@ THE USE OR PERFORMANCE OF THIS SOFTWARE.
 #include <X11/extensions/XEVIstr.h>
 #include "EVIstruct.h"
 #include "scrnintstr.h"
+
+#if HAVE_STDINT_H
+#include <stdint.h>
+#elif !defined(UINT32_MAX)
+#define UINT32_MAX 0xffffffffU
+#endif
+
 static int sampleGetVisualInfo(
     VisualID32 *visual,
     int n_visual,
@@ -42,24 +49,36 @@ static int sampleGetVisualInfo(
     VisualID32 **conflict_rn,
     int *n_conflict_rn)
 {
-    int max_sz_evi = n_visual * sz_xExtendedVisualInfo * screenInfo.numScreens;
+    unsigned int max_sz_evi;
     VisualID32 *temp_conflict;
     xExtendedVisualInfo *evi;
-    int max_visuals = 0, max_sz_conflict, sz_conflict = 0;
+    unsigned int max_visuals = 0, max_sz_conflict, sz_conflict = 0;
     register int visualI, scrI, sz_evi = 0, conflictI, n_conflict;
-    *evi_rn = evi = (xExtendedVisualInfo *)xalloc(max_sz_evi);
-    if (!*evi_rn)
-         return BadAlloc;
+
+    if (n_visual > UINT32_MAX/(sz_xExtendedVisualInfo * screenInfo.numScreens))
+	return BadAlloc;
+    max_sz_evi = n_visual * sz_xExtendedVisualInfo * screenInfo.numScreens;
+    
     for (scrI = 0; scrI < screenInfo.numScreens; scrI++) {
         if (screenInfo.screens[scrI]->numVisuals > max_visuals)
             max_visuals = screenInfo.screens[scrI]->numVisuals;
     }
+
+    if (n_visual > UINT32_MAX/(sz_VisualID32 * screenInfo.numScreens 
+			       * max_visuals)) 
+	return BadAlloc;
     max_sz_conflict = n_visual * sz_VisualID32 * screenInfo.numScreens * max_visuals;
+
+    *evi_rn = evi = (xExtendedVisualInfo *)xalloc(max_sz_evi);
+    if (!*evi_rn)
+         return BadAlloc;
+
     temp_conflict = (VisualID32 *)xalloc(max_sz_conflict);
     if (!temp_conflict) {
         xfree(*evi_rn);
         return BadAlloc;
     }
+
     for (scrI = 0; scrI < screenInfo.numScreens; scrI++) {
         for (visualI = 0; visualI < n_visual; visualI++) {
 	    evi[sz_evi].core_visual_id = visual[visualI];
diff --git a/Xext/shm.c b/Xext/shm.c
index e3d7a23..c545e49 100644
--- a/Xext/shm.c
+++ b/Xext/shm.c
@@ -757,6 +757,8 @@ ProcPanoramiXShmCreatePixmap(
     int i, j, result, rc;
     ShmDescPtr shmdesc;
     REQUEST(xShmCreatePixmapReq);
+    unsigned int width, height, depth;
+    unsigned long size;
     PanoramiXRes *newPix;
 
     REQUEST_SIZE_MATCH(xShmCreatePixmapReq);
@@ -770,11 +772,26 @@ ProcPanoramiXShmCreatePixmap(
 	return rc;
 
     VERIFY_SHMPTR(stuff->shmseg, stuff->offset, TRUE, shmdesc, client);
-    if (!stuff->width || !stuff->height)
+
+    width = stuff->width;
+    height = stuff->height;
+    depth = stuff->depth;
+    if (!width || !height || !depth)
     {
 	client->errorValue = 0;
         return BadValue;
     }
+    if (width > 32767 || height > 32767)
+        return BadAlloc;
+    size = PixmapBytePad(width, depth) * height;
+    if (sizeof(size) == 4) {
+        if (size < width * height)
+            return BadAlloc;
+        /* thankfully, offset is unsigned */
+        if (stuff->offset + size < size)
+            return BadAlloc;
+    }
+
     if (stuff->depth != 1)
     {
         pDepth = pDraw->pScreen->allowedDepths;
@@ -785,9 +802,7 @@ ProcPanoramiXShmCreatePixmap(
         return BadValue;
     }
 CreatePmap:
-    VERIFY_SHMSIZE(shmdesc, stuff->offset,
-		   PixmapBytePad(stuff->width, stuff->depth) * stuff->height,
-		   client);
+    VERIFY_SHMSIZE(shmdesc, stuff->offset, size, client);
 
     if(!(newPix = (PanoramiXRes *) xalloc(sizeof(PanoramiXRes))))
 	return BadAlloc;
@@ -1086,6 +1101,8 @@ ProcShmCreatePixmap(client)
     register int i, rc;
     ShmDescPtr shmdesc;
     REQUEST(xShmCreatePixmapReq);
+    unsigned int width, height, depth;
+    unsigned long size;
 
     REQUEST_SIZE_MATCH(xShmCreatePixmapReq);
     client->errorValue = stuff->pid;
@@ -1098,11 +1115,26 @@ ProcShmCreatePixmap(client)
 	return rc;
 
     VERIFY_SHMPTR(stuff->shmseg, stuff->offset, TRUE, shmdesc, client);
-    if (!stuff->width || !stuff->height)
+    
+    width = stuff->width;
+    height = stuff->height;
+    depth = stuff->depth;
+    if (!width || !height || !depth)
     {
 	client->errorValue = 0;
         return BadValue;
     }
+    if (width > 32767 || height > 32767)
+	return BadAlloc;
+    size = PixmapBytePad(width, depth) * height;
+    if (sizeof(size) == 4) {
+	if (size < width * height)
+	    return BadAlloc;
+	/* thankfully, offset is unsigned */
+	if (stuff->offset + size < size)
+	    return BadAlloc;
+    }
+
     if (stuff->depth != 1)
     {
         pDepth = pDraw->pScreen->allowedDepths;
@@ -1113,9 +1145,7 @@ ProcShmCreatePixmap(client)
         return BadValue;
     }
 CreatePmap:
-    VERIFY_SHMSIZE(shmdesc, stuff->offset,
-		   PixmapBytePad(stuff->width, stuff->depth) * stuff->height,
-		   client);
+    VERIFY_SHMSIZE(shmdesc, stuff->offset, size, client);
     pMap = (*shmFuncs[pDraw->pScreen->myNum]->CreatePixmap)(
 			    pDraw->pScreen, stuff->width,
 			    stuff->height, stuff->depth,
commit 7dc1717ff0f96b99271a912b8948dfce5164d5ad
Author: Matthieu Herrb <matthieu at bluenote.herrb.com>
Date:   Thu Jan 17 15:28:03 2008 +0100

    Fix for CVE-2007-6428 - TOG-cup extension memory corruption.

diff --git a/Xext/cup.c b/Xext/cup.c
index d0e820c..fd1409e 100644
--- a/Xext/cup.c
+++ b/Xext/cup.c
@@ -176,6 +176,9 @@ int ProcGetReservedColormapEntries(
 
     REQUEST_SIZE_MATCH (xXcupGetReservedColormapEntriesReq);
 
+    if (stuff->screen >= screenInfo.numScreens)
+	return BadValue;
+
 #ifndef HAVE_SPECIAL_DESKTOP_COLORS
     citems[CUP_BLACK_PIXEL].pixel = 
 	screenInfo.screens[stuff->screen]->blackPixel;
commit dd5e0f5cd5f3a87fee86d99c073ffa7cf89b0a27
Author: Matthieu Herrb <matthieu at bluenote.herrb.com>
Date:   Thu Jan 17 15:27:34 2008 +0100

    Fix for CVE-2007-6427 - Xinput extension memory corruption.

diff --git a/Xi/chgfctl.c b/Xi/chgfctl.c
index 8fc24d5..696b74a 100644
--- a/Xi/chgfctl.c
+++ b/Xi/chgfctl.c
@@ -302,18 +302,13 @@ ChangeStringFeedback(ClientPtr client, DeviceIntPtr dev,
 		     xStringFeedbackCtl * f)
 {
     char n;
-    long *p;
     int i, j;
     KeySym *syms, *sup_syms;
 
     syms = (KeySym *) (f + 1);
     if (client->swapped) {
 	swaps(&f->length, n);	/* swapped num_keysyms in calling proc */
-	p = (long *)(syms);
-	for (i = 0; i < f->num_keysyms; i++) {
-	    swapl(p, n);
-	    p++;
-	}
+	SwapLongs((CARD32 *) syms, f->num_keysyms);
     }
 
     if (f->num_keysyms > s->ctrl.max_symbols)
diff --git a/Xi/chgkmap.c b/Xi/chgkmap.c
index 3361e98..df334c1 100644
--- a/Xi/chgkmap.c
+++ b/Xi/chgkmap.c
@@ -75,18 +75,14 @@ int
 SProcXChangeDeviceKeyMapping(ClientPtr client)
 {
     char n;
-    long *p;
-    int i, count;
+    unsigned int count;
 
     REQUEST(xChangeDeviceKeyMappingReq);
     swaps(&stuff->length, n);
     REQUEST_AT_LEAST_SIZE(xChangeDeviceKeyMappingReq);
-    p = (long *)&stuff[1];
     count = stuff->keyCodes * stuff->keySymsPerKeyCode;
-    for (i = 0; i < count; i++) {
-	swapl(p, n);
-	p++;
-    }
+    REQUEST_FIXED_SIZE(xChangeDeviceKeyMappingReq, count * sizeof(CARD32));
+    SwapLongs((CARD32 *) (&stuff[1]), count);
     return (ProcXChangeDeviceKeyMapping(client));
 }
 
@@ -102,10 +98,14 @@ ProcXChangeDeviceKeyMapping(ClientPtr client)
     int ret;
     unsigned len;
     DeviceIntPtr dev;
+    unsigned int count;
 
     REQUEST(xChangeDeviceKeyMappingReq);
     REQUEST_AT_LEAST_SIZE(xChangeDeviceKeyMappingReq);
 
+    count = stuff->keyCodes * stuff->keySymsPerKeyCode;
+    REQUEST_FIXED_SIZE(xChangeDeviceKeyMappingReq, count * sizeof(CARD32));
+
     ret = dixLookupDevice(&dev, stuff->deviceid, client, DixSetAttrAccess);
     if (ret != Success)
 	return ret;
diff --git a/Xi/chgprop.c b/Xi/chgprop.c
index 58db886..3fb33e1 100644
--- a/Xi/chgprop.c
+++ b/Xi/chgprop.c
@@ -77,19 +77,15 @@ int
 SProcXChangeDeviceDontPropagateList(ClientPtr client)
 {
     char n;
-    long *p;
-    int i;
 
     REQUEST(xChangeDeviceDontPropagateListReq);
     swaps(&stuff->length, n);
     REQUEST_AT_LEAST_SIZE(xChangeDeviceDontPropagateListReq);
     swapl(&stuff->window, n);
     swaps(&stuff->count, n);
-    p = (long *)&stuff[1];
-    for (i = 0; i < stuff->count; i++) {
-	swapl(p, n);
-	p++;
-    }
+    REQUEST_FIXED_SIZE(xChangeDeviceDontPropagateListReq,
+                      stuff->count * sizeof(CARD32));
+    SwapLongs((CARD32 *) (&stuff[1]), stuff->count);
     return (ProcXChangeDeviceDontPropagateList(client));
 }
 
diff --git a/Xi/grabdev.c b/Xi/grabdev.c
index 110fc6b..0671e0e 100644
--- a/Xi/grabdev.c
+++ b/Xi/grabdev.c
@@ -78,8 +78,6 @@ int
 SProcXGrabDevice(ClientPtr client)
 {
     char n;
-    long *p;
-    int i;
 
     REQUEST(xGrabDeviceReq);
     swaps(&stuff->length, n);
@@ -87,11 +85,11 @@ SProcXGrabDevice(ClientPtr client)
     swapl(&stuff->grabWindow, n);
     swapl(&stuff->time, n);
     swaps(&stuff->event_count, n);
-    p = (long *)&stuff[1];
-    for (i = 0; i < stuff->event_count; i++) {
-	swapl(p, n);
-	p++;
-    }
+
+    if (stuff->length != (sizeof(xGrabDeviceReq) >> 2) + stuff->event_count)
+       return BadLength;
+    
+    SwapLongs((CARD32 *) (&stuff[1]), stuff->event_count);
 
     return (ProcXGrabDevice(client));
 }
diff --git a/Xi/grabdevb.c b/Xi/grabdevb.c
index c2661e8..ce0dcc5 100644
--- a/Xi/grabdevb.c
+++ b/Xi/grabdevb.c
@@ -77,8 +77,6 @@ int
 SProcXGrabDeviceButton(ClientPtr client)
 {
     char n;
-    long *p;
-    int i;
 
     REQUEST(xGrabDeviceButtonReq);
     swaps(&stuff->length, n);
@@ -86,11 +84,9 @@ SProcXGrabDeviceButton(ClientPtr client)
     swapl(&stuff->grabWindow, n);
     swaps(&stuff->modifiers, n);
     swaps(&stuff->event_count, n);
-    p = (long *)&stuff[1];
-    for (i = 0; i < stuff->event_count; i++) {
-	swapl(p, n);
-	p++;
-    }
+    REQUEST_FIXED_SIZE(xGrabDeviceButtonReq,
+                      stuff->event_count * sizeof(CARD32));
+    SwapLongs((CARD32 *) (&stuff[1]), stuff->event_count);
 
     return (ProcXGrabDeviceButton(client));
 }
diff --git a/Xi/grabdevk.c b/Xi/grabdevk.c
index 43b1928..d4b7fe8 100644
--- a/Xi/grabdevk.c
+++ b/Xi/grabdevk.c
@@ -77,8 +77,6 @@ int
 SProcXGrabDeviceKey(ClientPtr client)
 {
     char n;
-    long *p;
-    int i;
 
     REQUEST(xGrabDeviceKeyReq);
     swaps(&stuff->length, n);
@@ -86,11 +84,8 @@ SProcXGrabDeviceKey(ClientPtr client)
     swapl(&stuff->grabWindow, n);
     swaps(&stuff->modifiers, n);
     swaps(&stuff->event_count, n);
-    p = (long *)&stuff[1];
-    for (i = 0; i < stuff->event_count; i++) {
-	swapl(p, n);
-	p++;
-    }
+    REQUEST_FIXED_SIZE(xGrabDeviceKeyReq, stuff->event_count * sizeof(CARD32));
+    SwapLongs((CARD32 *) (&stuff[1]), stuff->event_count);
     return (ProcXGrabDeviceKey(client));
 }
 
diff --git a/Xi/selectev.c b/Xi/selectev.c
index b93618a..d3670ab 100644
--- a/Xi/selectev.c
+++ b/Xi/selectev.c
@@ -127,19 +127,16 @@ int
 SProcXSelectExtensionEvent(ClientPtr client)
 {
     char n;
-    long *p;
-    int i;
 
     REQUEST(xSelectExtensionEventReq);
     swaps(&stuff->length, n);
     REQUEST_AT_LEAST_SIZE(xSelectExtensionEventReq);
     swapl(&stuff->window, n);
     swaps(&stuff->count, n);
-    p = (long *)&stuff[1];
-    for (i = 0; i < stuff->count; i++) {
-	swapl(p, n);
-	p++;
-    }
+    REQUEST_FIXED_SIZE(xSelectExtensionEventReq,
+                      stuff->count * sizeof(CARD32));
+    SwapLongs((CARD32 *) (&stuff[1]), stuff->count);
+
     return (ProcXSelectExtensionEvent(client));
 }
 
diff --git a/Xi/sendexev.c b/Xi/sendexev.c
index e4e38d7..588c910 100644
--- a/Xi/sendexev.c
+++ b/Xi/sendexev.c
@@ -80,7 +80,7 @@ int
 SProcXSendExtensionEvent(ClientPtr client)
 {
     char n;
-    long *p;
+    CARD32 *p;
     int i;
     xEvent eventT;
     xEvent *eventP;
@@ -91,6 +91,11 @@ SProcXSendExtensionEvent(ClientPtr client)
     REQUEST_AT_LEAST_SIZE(xSendExtensionEventReq);
     swapl(&stuff->destination, n);
     swaps(&stuff->count, n);
+
+    if (stuff->length != (sizeof(xSendExtensionEventReq) >> 2) + stuff->count +
+       (stuff->num_events * (sizeof(xEvent) >> 2)))
+       return BadLength;
+
     eventP = (xEvent *) & stuff[1];
     for (i = 0; i < stuff->num_events; i++, eventP++) {
 	proc = EventSwapVector[eventP->u.u.type & 0177];
@@ -100,11 +105,8 @@ SProcXSendExtensionEvent(ClientPtr client)
 	*eventP = eventT;
     }
 
-    p = (long *)(((xEvent *) & stuff[1]) + stuff->num_events);
-    for (i = 0; i < stuff->count; i++) {
-	swapl(p, n);
-	p++;
-    }
+    p = (CARD32 *)(((xEvent *) & stuff[1]) + stuff->num_events);
+    SwapLongs(p, stuff->count);
     return (ProcXSendExtensionEvent(client));
 }
 
commit bbde5b62a137ba726a747b838d81e92d72c1b42b
Author: Matthieu Herrb <matthieu at bluenote.herrb.com>
Date:   Thu Jan 17 15:26:41 2008 +0100

    Fix for CVE-2007-5760 - XFree86 Misc extension out of bounds array index

diff --git a/hw/xfree86/common/xf86MiscExt.c b/hw/xfree86/common/xf86MiscExt.c
index c1b9c60..40c196a 100644
--- a/hw/xfree86/common/xf86MiscExt.c
+++ b/hw/xfree86/common/xf86MiscExt.c
@@ -548,6 +548,10 @@ MiscExtPassMessage(int scrnIndex, const char *msgtype, const char *msgval,
 {
     ScrnInfoPtr pScr = xf86Screens[scrnIndex];
 
+    /* should check this in the protocol, but xf86NumScreens isn't exported */
+    if (scrnIndex >= xf86NumScreens)
+	return BadValue;
+
     if (*pScr->HandleMessage == NULL)
 	    return BadImplementation;
     return (*pScr->HandleMessage)(scrnIndex, msgtype, msgval, retstr);
commit e85130c85f727466fc27be1cfa46c88b257499fb
Author: Daniel Stone <daniel at fooishbar.org>
Date:   Sat Jan 5 10:47:39 2008 +0200

    Xephyr: One-time keyboard leak fix
    
    Don't leak the originally-allocated keysym map.

diff --git a/hw/kdrive/ephyr/ephyr.c b/hw/kdrive/ephyr/ephyr.c
index c5c8a56..6ec95d6 100644
--- a/hw/kdrive/ephyr/ephyr.c
+++ b/hw/kdrive/ephyr/ephyr.c
@@ -1031,6 +1031,7 @@ EphyrKeyboardInit (KdKeyboardInfo *ki)
   ki->minScanCode = ki->keySyms.minKeyCode;
   ki->maxScanCode = ki->keySyms.maxKeyCode;
   ki->keySyms.mapWidth = ephyrKeySyms.mapWidth;
+  xfree(ki->keySyms.map);
   ki->keySyms.map = ephyrKeySyms.map;
   ki->name = KdSaveString("Xephyr virtual keyboard");
   ephyrKbd = ki;
commit 0137b0394a248f694448a7d97c9a1a3efcf24e81
Author: Daniel Stone <daniel at fooishbar.org>
Date:   Sat Jan 5 10:43:53 2008 +0200

    XKB: XkbCopyKeymap: Don't leak all the sections
    
    Previously, we'd just keep num_sections at 0, which would break the
    geometry and lead us to leak sections.  Don't do that.

diff --git a/xkb/xkbUtils.c b/xkb/xkbUtils.c
index 31c1a9f..1fb47ed 100644
--- a/xkb/xkbUtils.c
+++ b/xkb/xkbUtils.c
@@ -1793,6 +1793,7 @@ XkbCopyKeymap(XkbDescPtr src, XkbDescPtr dst, Bool sendNotifies)
             if (!tmp)
                 return FALSE;
             dst->geom->sections = tmp;
+            dst->geom->num_sections = src->geom->num_sections;
 
             for (i = 0,
                   ssection = src->geom->sections,
commit b99a43dfe97c1813e1c61f298b1c83c5d5ca88a2
Author: Daniel Stone <daniel at fooishbar.org>
Date:   Sat Jan 5 10:38:16 2008 +0200

    OS: IO: Zero out client buffers
    
    For alignment reasons, we can write out uninitialised bytes, so allocate
    the whole thing with xcalloc.

diff --git a/os/io.c b/os/io.c
index 968f40a..be89021 100644
--- a/os/io.c
+++ b/os/io.c
@@ -1196,7 +1196,7 @@ AllocateOutputBuffer(void)
     oco = (ConnectionOutputPtr)xalloc(sizeof(ConnectionOutput));
     if (!oco)
 	return (ConnectionOutputPtr)NULL;
-    oco->buf = (unsigned char *) xalloc(BUFSIZE);
+    oco->buf = (unsigned char *) xcalloc(1, BUFSIZE);
     if (!oco->buf)
     {
 	xfree(oco);
commit a6a7fadbb03ee99312dfb15ac478ab3c414c1c0b
Author: Kristian Høgsberg <krh at redhat.com>
Date:   Wed Jan 16 20:24:11 2008 -0500

    Don't break grab and focus state for a window when redirecting it.
    
    Composite uses an unmap/map cycle to trigger backing pixmap allocation
    and cliprect recomputation when a window is redirected or unredirected.
    To avoid protocol visible side effects, map and unmap events are
    disabled temporarily.  However, when a window is unmapped it is also
    removed from grabs and loses focus, but these state changes are not
    disabled.
    
    This change supresses the unmap side effects during the composite
    unmap/map cycle and fixes this bug:
    
      http://bugzilla.gnome.org/show_bug.cgi?id=488264
    
    where compiz would cause gnome-screensaver to lose its grab when
    compiz unredirects the fullscreen lock window.

diff --git a/dix/window.c b/dix/window.c
index 33cf76b..1ccf126 100644
--- a/dix/window.c
+++ b/dix/window.c
@@ -2993,7 +2993,8 @@ UnrealizeTree(
 	    } 
 #endif
 	    (* Unrealize)(pChild);
-	    DeleteWindowFromAnyEvents(pChild, FALSE);
+	    if (MapUnmapEventsEnabled(pWin))
+		DeleteWindowFromAnyEvents(pChild, FALSE);
 	    if (pChild->viewable)
 	    {
 #ifdef DO_SAVE_UNDERS
commit e46f6ddeccd082b2d507a1e8b57ea30e6b0a2c83
Author: Michel Dänzer <michel at tungstengraphics.com>
Date:   Wed Jan 16 14:24:22 2008 +0100

    Yet another Xv extension byte swapping fix.

diff --git a/Xext/xvdisp.c b/Xext/xvdisp.c
index 237ad51..de0128e 100644
--- a/Xext/xvdisp.c
+++ b/Xext/xvdisp.c
@@ -1588,6 +1588,7 @@ SProcXvSetPortAttribute(ClientPtr client)
   swaps(&stuff->length, n);
   swapl(&stuff->port, n);
   swapl(&stuff->attribute, n);
+  swapl(&stuff->value, n);
   return XvProcVector[xv_SetPortAttribute](client);
 }
 
commit 7a0d16ef0a103bcb25fa8a20322685f017aaf5a3
Author: Tiago Vignatti <vignatti at c3sl.ufpr.br>
Date:   Tue Jan 15 03:27:16 2008 -0200

    Removed some warnings.

diff --git a/hw/kdrive/ephyr/ephyrdriext.c b/hw/kdrive/ephyr/ephyrdriext.c
index b6be47f..1b9dce5 100644
--- a/hw/kdrive/ephyr/ephyrdriext.c
+++ b/hw/kdrive/ephyr/ephyrdriext.c
@@ -206,7 +206,7 @@ ephyrDRIScreenInit (ScreenPtr a_screen)
     a_screen->ClipNotify = ephyrDRIClipNotify ;
 
     is_ok = TRUE ;
-out:
+
     return is_ok ;
 }
 
diff --git a/hw/kdrive/ephyr/ephyrlog.h b/hw/kdrive/ephyr/ephyrlog.h
index 4c6435e..71f7977 100644
--- a/hw/kdrive/ephyr/ephyrlog.h
+++ b/hw/kdrive/ephyr/ephyrlog.h
@@ -33,8 +33,8 @@
 
 #ifdef NDEBUG
 /*we are not in debug mode*/
-#define EPHYR_LOG
-#define EPHYR_LOG_ERROR
+#define EPHYR_LOG(...)
+#define EPHYR_LOG_ERROR(...)
 #endif /*NDEBUG*/
 
 #define ERROR_LOG_LEVEL 3
diff --git a/hw/kdrive/ephyr/hostx.c b/hw/kdrive/ephyr/hostx.c
index b5ffdd0..a5413b8 100644
--- a/hw/kdrive/ephyr/hostx.c
+++ b/hw/kdrive/ephyr/hostx.c
@@ -1078,16 +1078,6 @@ out:
 
 }
 
-typedef struct {
-    int is_valid ;
-    int local_id ;
-    int remote_id ;
-} ResourcePair ;
-
-#define RESOURCE_PEERS_SIZE 1024*10
-static ResourcePair resource_peers[RESOURCE_PEERS_SIZE] ;
-
-
 int
 hostx_create_window (int a_screen_number,
                      EphyrBox *a_geometry,
@@ -1259,6 +1249,16 @@ hostx_has_xshape (void)
 }
 
 #ifdef XEPHYR_DRI
+typedef struct {
+    int is_valid ;
+    int local_id ;
+    int remote_id ;
+} ResourcePair ;
+
+#define RESOURCE_PEERS_SIZE 1024*10
+static ResourcePair resource_peers[RESOURCE_PEERS_SIZE] ;
+
+
 int
 hostx_allocate_resource_id_peer (int a_local_resource_id,
                                  int *a_remote_resource_id)
commit 315d6a2b1d2a3de308e98d548afe780c59a784fc
Author: Tiago Vignatti <vignatti at c3sl.ufpr.br>
Date:   Tue Jan 15 02:59:56 2008 -0200

    Fix Xephyr compilation without GLX.

diff --git a/configure.ac b/configure.ac
index 0742040..566ddcb 100644
--- a/configure.ac
+++ b/configure.ac
@@ -1901,7 +1901,7 @@ if test "$KDRIVE" = yes; then
         XEPHYR=$xephyr
     fi
     XEPHYR_DRI=no
-    if test x$XEPHYR = xyes -a x$DRI = xyes; then
+    if test x$XEPHYR = xyes -a x$DRI = xyes && test "x$GLX" = xyes; then
         XEPHYR_DRI=yes
         XEPHYR_DRI_LIBS=-lGL
         AC_SUBST(XEPHYR_DRI_LIBS)
diff --git a/hw/kdrive/ephyr/ephyr.c b/hw/kdrive/ephyr/ephyr.c
index 2a762a2..c5c8a56 100644
--- a/hw/kdrive/ephyr/ephyr.c
+++ b/hw/kdrive/ephyr/ephyr.c
@@ -635,7 +635,9 @@ ephyrInitScreen (ScreenPtr pScreen)
   if (!ephyrNoDRI && !hostx_has_dri ()) {
       EPHYR_LOG ("host x does not support DRI. Disabling DRI forwarding\n") ;
       ephyrNoDRI = TRUE ;
+#ifdef GLXEXT
       noGlxVisualInit = FALSE ;
+#endif
   }
   if (!ephyrNoDRI) {
     ephyrDRIExtensionInit (pScreen) ;
commit 1f83f40525acd3aff8f50b3c519bc1f307ff1e19
Author: Dave Airlie <airlied at linux.ie>
Date:   Tue Jan 15 10:20:50 2008 +1000

    xf86Cursors: fix memset for non-square cursors

diff --git a/hw/xfree86/modes/xf86Cursors.c b/hw/xfree86/modes/xf86Cursors.c
index acf34c1..5a4d0f6 100644
--- a/hw/xfree86/modes/xf86Cursors.c
+++ b/hw/xfree86/modes/xf86Cursors.c
@@ -400,7 +400,7 @@ xf86_crtc_load_cursor_image (xf86CrtcPtr crtc, CARD8 *src)
 	int flags = cursor_info->Flags;
 	
 	cursor_image = xf86_config->cursor_image;
-	memset(cursor_image, 0, cursor_info->MaxWidth * stride);
+	memset(cursor_image, 0, cursor_info->MaxHeight * stride);
 	
         for (y = 0; y < cursor_info->MaxHeight; y++)
 	    for (x = 0; x < cursor_info->MaxWidth; x++) 
commit e6ea3147bfb686798dac381eb8900f9f18beb88e
Author: Bernardo Innocenti <bernie at codewiz.org>
Date:   Sun Jan 13 19:50:37 2008 -0500

    exa: make the prototype for exaGetPixmapFirstPixel() public
    
    This fixes a warning in amd_drv which is using it.
    
    Signed-off-by: Bernardo Innocenti <bernie at codewiz.org>

diff --git a/exa/exa.h b/exa/exa.h
index 1ff0518..0774a70 100644
--- a/exa/exa.h
+++ b/exa/exa.h
@@ -790,6 +790,9 @@ exaMoveOutPixmap (PixmapPtr pPixmap);
 void *
 exaGetPixmapDriverPrivate(PixmapPtr p);
 
+CARD32
+exaGetPixmapFirstPixel (PixmapPtr pPixmap);
+
 /**
  * Returns TRUE if the given planemask covers all the significant bits in the
  * pixel values for pDrawable.
diff --git a/exa/exa_priv.h b/exa/exa_priv.h
index de8b2f5..89f4718 100644
--- a/exa/exa_priv.h
+++ b/exa/exa_priv.h
@@ -291,9 +291,6 @@ ExaCheckGetSpans (DrawablePtr pDrawable,
 		 int nspans,
 		 char *pdstStart);
 
-CARD32
-exaGetPixmapFirstPixel (PixmapPtr pPixmap); 
-
 /* exa_accel.c */
 
 static _X_INLINE Bool
commit 180a5aba4de3104fed8bc4e7d42a1e3a51575318
Author: Jeremy Huddleston <jeremy at yuffie.local>
Date:   Sat Jan 12 21:24:34 2008 -0800

    XQuartz: Fixed copy-paste error with login_shell commit
    (cherry picked from commit 6deec3acc6f8010b5b53a1e55a0a2c4080ba69d2)

diff --git a/hw/xquartz/X11Controller.m b/hw/xquartz/X11Controller.m
index e13edc1..d3f8365 100644
--- a/hw/xquartz/X11Controller.m
+++ b/hw/xquartz/X11Controller.m
@@ -302,7 +302,7 @@
   argv[0] = "/usr/bin/login";
   argv[1] = "-fp";
   argv[2] = getlogin();
-  argv[3] = [X11App prefs_get_string:@PREFS_FAKE_BUTTON2 default:"/bin/sh"];
+  argv[3] = [X11App prefs_get_string:@PREFS_LOGIN_SHELL default:"/bin/sh"];
   argv[4] = "-c";
   argv[5] = command;
   argv[6] = NULL;
commit 6fd4a5e2e4d0be0ba0773df831687e11e1262c72
Author: Jeremy Huddleston <jeremy at yuffie.local>
Date:   Sat Jan 12 11:56:00 2008 -0800

    XQuartz: Corrected copyright X.org Project -> X.org Foundation
    (cherry picked from commit f21631444816fc12b8a534c2cf79e6ac6c2af7c9)

diff --git a/hw/xquartz/bundle/Info.plist b/hw/xquartz/bundle/Info.plist
index 5babdfe..6ba02dd 100644
--- a/hw/xquartz/bundle/Info.plist
+++ b/hw/xquartz/bundle/Info.plist
@@ -27,7 +27,7 @@
 	<key>NSHumanReadableCopyright</key>
 		<string>Copyright © 2003-2008, Apple Inc.
 Copyright © 2003, XFree86 Project, Inc.
-Copyright © 2003-2008, X.org Project, Inc.
+Copyright © 2003-2008, X.org Foundation, Inc.
 </string>
 	<key>NSMainNibFile</key>
 		<string>main</string>
commit f72255639c065d795f7767683e851b1b5b2d9480
Author: Jeremy Huddleston <jeremy at yuffie.local>
Date:   Sat Jan 12 11:35:48 2008 -0800

    XQuartz: added 'login_shell' option to defaults
    so the user can choose something other than /bin/sh
    (cherry picked from commit b549cf18cebd3435d70f62855239484974c455a1)

diff --git a/hw/xquartz/X11Application.h b/hw/xquartz/X11Application.h
index a1be751..af5aea2 100644
--- a/hw/xquartz/X11Application.h
+++ b/hw/xquartz/X11Application.h
@@ -97,5 +97,6 @@ extern int quartzHasRoot, quartzEnableRootless;
 #define PREFS_SWAP_ALT_META         "swap_alt_meta"
 #define PREFS_XP_OPTIONS            "xp_options"
 #define PREFS_ENABLE_STEREO         "enable_stereo"
+#define PREFS_LOGIN_SHELL           "login_shell"
 
 #endif /* X11APPLICATION_H */
diff --git a/hw/xquartz/X11Controller.m b/hw/xquartz/X11Controller.m
index 6b7c351..e13edc1 100644
--- a/hw/xquartz/X11Controller.m
+++ b/hw/xquartz/X11Controller.m
@@ -302,7 +302,7 @@
   argv[0] = "/usr/bin/login";
   argv[1] = "-fp";
   argv[2] = getlogin();
-  argv[3] = "/bin/sh";
+  argv[3] = [X11App prefs_get_string:@PREFS_FAKE_BUTTON2 default:"/bin/sh"];
   argv[4] = "-c";
   argv[5] = command;
   argv[6] = NULL;
diff --git a/hw/xquartz/bundle/Makefile.am b/hw/xquartz/bundle/Makefile.am
index 9511670..00d540f 100644
--- a/hw/xquartz/bundle/Makefile.am
+++ b/hw/xquartz/bundle/Makefile.am
@@ -18,8 +18,6 @@ EXTRA_DIST = \
 	Info.plist \
 	X11.icns \
 	bundle-main.c \
-	launcher-main.c \
-	server-main.c \
 	English.lproj/InfoPlist.strings \
 	English.lproj/Localizable.strings \
 	English.lproj/main.nib/classes.nib \
diff --git a/hw/xquartz/bundle/bundle-main.c b/hw/xquartz/bundle/bundle-main.c
index df78d7f..54d0136 100644
--- a/hw/xquartz/bundle/bundle-main.c
+++ b/hw/xquartz/bundle/bundle-main.c
@@ -38,6 +38,7 @@
 
 #define DEFAULT_CLIENT "/usr/X11/bin/xterm"
 #define DEFAULT_STARTX "/usr/X11/bin/startx"
+#define DEFAULT_SHELL  "/bin/sh"
 
 static int execute(const char *command);
 static char *command_from_prefs(const char *key, const char *default_value);
@@ -82,7 +83,7 @@ static int execute(const char *command) {
     newargv[0] = "/usr/bin/login";
     newargv[1] = "-fp";
     newargv[2] = getlogin();
-    newargv[3] = "/bin/sh";
+    newargv[3] = command_from_prefs("login_shell", DEFAULT_SHELL);
     newargv[4] = "-c";
     newargv[5] = command;
     newargv[6] = NULL;
commit ec24a6b5aa732ec6999a27889d9a33cf80123886
Author: Jeremy Huddleston <jeremy at yuffie.local>
Date:   Sun Jan 6 18:29:54 2008 -0800

    XQuartz: Fixed switching into XQuartz via expose.
    (cherry picked from commit 627ed60ce5d7499761028edf379ebd95250d3e04)

diff --git a/hw/xquartz/X11Application.m b/hw/xquartz/X11Application.m
index 72537bb..f688985 100644
--- a/hw/xquartz/X11Application.m
+++ b/hw/xquartz/X11Application.m
@@ -164,7 +164,7 @@ static void message_kit_thread (SEL selector, NSObject *arg) {
 	 have it activated while X is active (unless using the old
 	 keymapping files) */
     static TSMDocumentID x11_document;
-	
+	DEBUG_LOG("state=%d, _x_active=%d, \n", state, _x_active)
     if (state) {
       QuartzMessageServerThread (kXDarwinActivate, 0);
       
@@ -314,6 +314,7 @@ static void message_kit_thread (SEL selector, NSObject *arg) {
 }
 
 - (void) set_front_process:unused {
+//    [self activateX:YES];
     QuartzMessageServerThread(kXDarwinBringAllToFront, 0);
 }
 
@@ -710,6 +711,10 @@ void X11ApplicationSetWindowMenuCheck (int idx) {
 
 void X11ApplicationSetFrontProcess (void) {
     message_kit_thread (@selector (set_front_process:), nil);
+
+    /* Hackery needed due to argv[0] hackery */
+    ProcessSerialNumber psn = { 0, kCurrentProcess };
+    SetFrontProcess(&psn);
 }
 
 void X11ApplicationSetCanQuit (int state) {
commit 6844bd2e63490870bab3c469eec6030354ef2865
Author: Alan Coopersmith <alan.coopersmith at sun.com>
Date:   Wed Jan 9 19:52:00 2008 -0800

    More Xv extension byte swapping fixes

diff --git a/Xext/xvdisp.c b/Xext/xvdisp.c
index 17ff1d7..237ad51 100644
--- a/Xext/xvdisp.c
+++ b/Xext/xvdisp.c
@@ -1532,6 +1532,7 @@ SProcXvShmPutImage(ClientPtr client)
   swapl(&stuff->gc, n);
   swapl(&stuff->shmseg, n);
   swapl(&stuff->id, n);
+  swapl(&stuff->offset, n);
   swaps(&stuff->src_x, n);
   swaps(&stuff->src_y, n);
   swaps(&stuff->src_w, n);
@@ -1540,7 +1541,6 @@ SProcXvShmPutImage(ClientPtr client)
   swaps(&stuff->drw_y, n);
   swaps(&stuff->drw_w, n);
   swaps(&stuff->drw_h, n);
-  swaps(&stuff->offset, n);
   swaps(&stuff->width, n);
   swaps(&stuff->height, n);
   return XvProcVector[xv_ShmPutImage](client);
@@ -1632,9 +1632,10 @@ SProcXvQueryImageAttributes(ClientPtr client)
   char n;
   REQUEST(xvQueryImageAttributesReq);
   swaps(&stuff->length, n);
+  swapl(&stuff->port, n);
   swapl(&stuff->id, n);
   swaps(&stuff->width, n);
-  swaps(&stuff->width, n);
+  swaps(&stuff->height, n);
   return XvProcVector[xv_QueryImageAttributes](client);
 }
 
commit 0883e838e25227f0af84d2a90979175724166d16
Author: Peter Harris <peter.harris at hummingbird.com>
Date:   Wed Jan 9 14:52:33 2008 -0500

    xf86misc.c: Avoid use of swapped values

diff --git a/hw/xfree86/dixmods/extmod/xf86misc.c b/hw/xfree86/dixmods/extmod/xf86misc.c
index 66278a2..8f44346 100644
--- a/hw/xfree86/dixmods/extmod/xf86misc.c
+++ b/hw/xfree86/dixmods/extmod/xf86misc.c
@@ -250,6 +250,7 @@ ProcXF86MiscGetMouseSettings(client)
     char *devname;
     pointer mouse;
     register int n;
+    int devnamelen;
 
     DEBUG_P("XF86MiscGetMouseSettings");
 
@@ -269,7 +270,7 @@ ProcXF86MiscGetMouseSettings(client)
     rep.emulate3timeout = MiscExtGetMouseValue(mouse, MISC_MSE_EM3TIMEOUT);
     rep.chordmiddle =	  MiscExtGetMouseValue(mouse, MISC_MSE_CHORDMIDDLE);
     rep.flags =		  MiscExtGetMouseValue(mouse, MISC_MSE_FLAGS);
-    rep.devnamelen = (devname? strlen(devname): 0);
+    devnamelen = rep.devnamelen = (devname? strlen(devname): 0);
     rep.length = (sizeof(xXF86MiscGetMouseSettingsReply) -
 		  sizeof(xGenericReply) + ((rep.devnamelen+3) & ~3)) >> 2;
     
@@ -289,8 +290,8 @@ ProcXF86MiscGetMouseSettings(client)
     WriteToClient(client, SIZEOF(xXF86MiscGetMouseSettingsReply), (char *)&rep);
     MiscExtDestroyStruct(mouse, MISC_POINTER);
     
-    if (rep.devnamelen)
-        WriteToClient(client, rep.devnamelen, devname);
+    if (devnamelen)
+        WriteToClient(client, devnamelen, devname);
     return (client->noClientException);
 }
 
@@ -508,6 +509,7 @@ ProcXF86MiscGetFilePaths(client)
     const char *modulepath;
     const char *logfile;
     register int n;
+    int configlen, modulelen, loglen;
 
     DEBUG_P("XF86MiscGetFilePaths");
 
@@ -518,9 +520,9 @@ ProcXF86MiscGetFilePaths(client)
     if (!MiscExtGetFilePaths(&configfile, &modulepath, &logfile))
 	return BadValue;
 
-    rep.configlen = (configfile? strlen(configfile): 0);
-    rep.modulelen = (modulepath? strlen(modulepath): 0);
-    rep.loglen = (logfile? strlen(logfile): 0);
+    configlen = rep.configlen = (configfile? strlen(configfile): 0);
+    modulelen = rep.modulelen = (modulepath? strlen(modulepath): 0);
+    loglen = rep.loglen = (logfile? strlen(logfile): 0);
     rep.length = (SIZEOF(xXF86MiscGetFilePathsReply) - SIZEOF(xGenericReply) +
 		  ((rep.configlen + 3) & ~3) +
 		  ((rep.modulelen + 3) & ~3) +
@@ -535,12 +537,12 @@ ProcXF86MiscGetFilePaths(client)
     }
     WriteToClient(client, SIZEOF(xXF86MiscGetFilePathsReply), (char *)&rep);
     
-    if (rep.configlen)
-        WriteToClient(client, rep.configlen, (char *)configfile);
-    if (rep.modulelen)
-        WriteToClient(client, rep.modulelen, (char *)modulepath);
-    if (rep.loglen)
-        WriteToClient(client, rep.loglen, (char *)logfile);
+    if (configlen)
+        WriteToClient(client, configlen, (char *)configfile);
+    if (modulelen)
+        WriteToClient(client, modulelen, (char *)modulepath);
+    if (loglen)
+        WriteToClient(client, loglen, (char *)logfile);
 
     return (client->noClientException);
 }
@@ -553,6 +555,7 @@ ProcXF86MiscPassMessage(client)
     char *msgtype, *msgval, *retstr;
     int retval, size;
     register int n;
+    int mesglen;
 
     REQUEST(xXF86MiscPassMessageReq);
 
@@ -589,7 +592,7 @@ ProcXF86MiscPassMessage(client)
 
     rep.type = X_Reply;
     rep.sequenceNumber = client->sequence;
-    rep.mesglen = (retstr? strlen(retstr): 0);
+    mesglen = rep.mesglen = (retstr? strlen(retstr): 0);
     rep.length = (SIZEOF(xXF86MiscPassMessageReply) - SIZEOF(xGenericReply) +
 		  ((rep.mesglen + 3) & ~3)) >> 2;
     rep.status = 0;
@@ -601,8 +604,8 @@ ProcXF86MiscPassMessage(client)
     }
     WriteToClient(client, SIZEOF(xXF86MiscPassMessageReply), (char *)&rep);
     
-    if (rep.mesglen)
-        WriteToClient(client, rep.mesglen, (char *)retstr);
+    if (mesglen)
+        WriteToClient(client, mesglen, (char *)retstr);
 
     xfree(msgtype);
     xfree(msgval);
commit 59a63d72a1407a8aaf9878eeff7ee7a66f65a42b
Author: Alan Coopersmith <alan.coopersmith at sun.com>
Date:   Wed Jan 9 18:42:58 2008 -0800

    Fix reference to old versions of XFree86 to not say "Xorg 4.2 or earlier"

diff --git a/hw/xfree86/doc/man/xorg.conf.man.pre b/hw/xfree86/doc/man/xorg.conf.man.pre
index 7eaf5d5..1369a16 100644
--- a/hw/xfree86/doc/man/xorg.conf.man.pre
+++ b/hw/xfree86/doc/man/xorg.conf.man.pre
@@ -2029,7 +2029,7 @@ These both specify that the upper left corner's coordinates are
 The
 .B Absolute
 keyword is optional.
-Some older versions of __xservername__ (4.2 and earlier) don't recognise the
+Some older versions of XFree86 (4.2 and earlier) don't recognise the
 .B Absolute
 keyword, so it's safest to just specify the coordinates without it.
 .TP 4
commit e070c2cbef0d6fbbafce8d417e8b29231c2fdc50
Author: Peter Hutterer <peter at cs.unisa.edu.au>
Date:   Fri Dec 7 20:18:49 2007 +1030

    mi: change infamous "Tossed event ..." error for something more explanatory.
    
    Few whitespace errors fixed.
    Two ErrorF's prefixed with [mi].
    (cherry picked from commit 117458d2db49efd3f04432ff45871b44c7d4ad57)

diff --git a/mi/mieq.c b/mi/mieq.c
index c2f687a..aaa247d 100644
--- a/mi/mieq.c
+++ b/mi/mieq.c
@@ -122,7 +122,7 @@ mieqEnqueue(DeviceIntPtr pDev, xEvent *e)
      * motion event they need to be attached to.  Sigh. */
     if (e->u.u.type == DeviceValuator) {
         if (laste->nevents > 6) {
-            ErrorF("mieqEnqueue: more than six valuator events; dropping.\n");
+            ErrorF("[mi] mieqEnqueue: more than six valuator events; dropping.\n");
             return;
         }
         if (oldtail == miEventQueue.head ||
@@ -133,7 +133,7 @@ mieqEnqueue(DeviceIntPtr pDev, xEvent *e)
               lastkbp->type == ProximityOut) ||
             ((lastkbp->deviceid & DEVICE_BITS) !=
              (v->deviceid & DEVICE_BITS))) {
-            ErrorF("mieqEnequeue: out-of-order valuator event; dropping.\n");
+            ErrorF("[mi] mieqEnequeue: out-of-order valuator event; dropping.\n");
             return;
         }
         memcpy(&(laste->event[laste->nevents++]), e, sizeof(xEvent));
@@ -145,12 +145,13 @@ mieqEnqueue(DeviceIntPtr pDev, xEvent *e)
 	oldtail = (oldtail - 1) % QUEUE_SIZE;
     }
     else {
-    	newtail = (oldtail + 1) % QUEUE_SIZE;
-    	/* Toss events which come in late.  Usually this means your server's
+	newtail = (oldtail + 1) % QUEUE_SIZE;
+	/* Toss events which come in late.  Usually this means your server's
          * stuck in an infinite loop somewhere, but SIGIO is still getting
          * handled. */
-    	if (newtail == miEventQueue.head) {
-            ErrorF("tossed event which came in late\n");
+	if (newtail == miEventQueue.head) {
+            ErrorF("[mi] EQ overflowing. The server is probably stuck "
+                   "in an infinite loop.\n");
 	    return;
         }
 	miEventQueue.tail = newtail;
commit c31aead0fe9fe424120ce221cd9f76cb6d29a5b5
Author: Richard Purdie <rpurdie at openedhand.com>
Date:   Tue Jan 8 12:12:06 2008 +0100

    [Kdrive] make XCalibrate 'orientation aware'

diff --git a/Xext/xcalibrate.c b/Xext/xcalibrate.c
index 97ef3dc..3fe2bdc 100644
--- a/Xext/xcalibrate.c
+++ b/Xext/xcalibrate.c
@@ -164,7 +164,6 @@ ProcXCalibrateSetRawMode (ClientPtr client)
   return (client->noClientException);
 }
 
-
 static int
 SProcXCalibrateSetRawMode (ClientPtr client)
 {
@@ -178,6 +177,47 @@ SProcXCalibrateSetRawMode (ClientPtr client)
   return ProcXCalibrateSetRawMode(client);
 }
 
+static int
+ProcXCalibrateScreenToCoord (ClientPtr client)
+{
+  REQUEST(xXCalibrateScreenToCoordReq);
+  xXCalibrateScreenToCoordReply rep;
+
+  REQUEST_SIZE_MATCH (xXCalibrateScreenToCoordReq);
+
+  memset (&rep, 0, sizeof (rep));
+  rep.type = X_Reply;
+  rep.sequenceNumber = client->sequence;
+  rep.x = stuff->x;
+  rep.y = stuff->y;
+
+  KdScreenToPointerCoords(&rep.x, &rep.y);
+
+  if (client->swapped)
+    {
+      int n;
+
+      swaps (&rep.x, n);
+      swaps (&rep.y, n);
+    }
+  WriteToClient(client, sizeof (rep), (char *) &rep);
+  return (client->noClientException);
+}
+
+static int
+SProcXCalibrateScreenToCoord (ClientPtr client)
+{
+  REQUEST(xXCalibrateScreenToCoordReq);
+  int n;
+
+  REQUEST_SIZE_MATCH (xXCalibrateScreenToCoordReq);
+
+  swaps(&stuff->x, n);
+  swaps(&stuff->y, n);
+
+  return ProcXCalibrateScreenToCoord(client);
+}
+
 static void
 XCalibrateResetProc (ExtensionEntry *extEntry) 
 { 
@@ -192,6 +232,9 @@ ProcXCalibrateDispatch (ClientPtr client)
         return ProcXCalibrateQueryVersion(client);
     case X_XCalibrateRawMode:
         return ProcXCalibrateSetRawMode(client);
+    case X_XCalibrateScreenToCoord:
+        return ProcXCalibrateScreenToCoord(client);
+
     default: break;
     }
 
@@ -211,6 +254,8 @@ SProcXCalibrateDispatch (ClientPtr client)
         return SProcXCalibrateQueryVersion(client);
     case X_XCalibrateRawMode:
         return SProcXCalibrateSetRawMode(client);
+    case X_XCalibrateScreenToCoord:
+        return SProcXCalibrateScreenToCoord(client);
 
     default: break;
     }
diff --git a/hw/kdrive/src/kdrive.h b/hw/kdrive/src/kdrive.h
index 8722ba3..4e04b59 100644
--- a/hw/kdrive/src/kdrive.h
+++ b/hw/kdrive/src/kdrive.h
@@ -832,7 +832,10 @@ KdSetPointerMatrix (KdPointerMatrix *pointer);
 
 void
 KdComputePointerMatrix (KdPointerMatrix *pointer, Rotation randr, int width, int height);
-    
+
+void
+KdScreenToPointerCoords (int *x, int *y);
+
 void
 KdBlockHandler (int		screen,
 		pointer		blockData,
diff --git a/hw/kdrive/src/kinput.c b/hw/kdrive/src/kinput.c
index 6c247c1..df73942 100644
--- a/hw/kdrive/src/kinput.c
+++ b/hw/kdrive/src/kinput.c
@@ -631,6 +631,18 @@ KdComputePointerMatrix (KdPointerMatrix *m, Rotation randr, int width,
     }
 }
 
+void
+KdScreenToPointerCoords (int *x, int *y)
+{
+    int	(*m)[3] = kdPointerMatrix.matrix;
+    int div = m[0][1] * m[1][0] - m[1][1] * m[0][0];
+    int sx = *x;
+    int sy = *y;
+
+    *x = (m[0][1] * sy - m[0][1] * m[1][2] + m[1][1] * m[0][2] - m[1][1] * sx) / div;
+    *y = (m[1][0] * sx + m[0][0] * m[1][2] - m[1][0] * m[0][2] - m[0][0] * sy) / div;
+}
+
 static void
 KdKbdCtrl (DeviceIntPtr pDevice, KeybdCtrl *ctrl)
 {
commit 30375cd6d1439a3390b41714fe116aecc94743ca
Author: David Nusinow <dnusinow at debian.org>
Date:   Mon Jan 7 20:57:30 2008 -0500

    Don't log DPMS enabling as being from xorg.conf if it's not

diff --git a/hw/xfree86/common/xf86DPMS.c b/hw/xfree86/common/xf86DPMS.c
index a23d81d..4fb901a 100644
--- a/hw/xfree86/common/xf86DPMS.c
+++ b/hw/xfree86/common/xf86DPMS.c
@@ -60,6 +60,7 @@ xf86DPMSInit(ScreenPtr pScreen, DPMSSetProcPtr set, int flags)
     ScrnInfoPtr pScrn = xf86Screens[pScreen->myNum];
     DPMSPtr pDPMS;
     pointer DPMSOpt;
+    MessageType enabled_from = X_INFO;
 
     DPMSKey = &DPMSKey;
 
@@ -78,6 +79,7 @@ xf86DPMSInit(ScreenPtr pScreen, DPMSSetProcPtr set, int flags)
 	    = xf86SetBoolOption(pScrn->options, "dpms", FALSE))
 	    && !DPMSDisabledSwitch)
 	    DPMSEnabled = TRUE;
+            enabled_from = X_CONFIG;
 	xf86MarkOptionUsed(DPMSOpt);
     } else if (DPMSEnabledSwitch) {
 	if (!DPMSDisabledSwitch)
@@ -88,7 +90,7 @@ xf86DPMSInit(ScreenPtr pScreen, DPMSSetProcPtr set, int flags)
 	pDPMS->Enabled = defaultDPMSEnabled;
     }
     if (pDPMS->Enabled)
-	xf86DrvMsg(pScreen->myNum, X_CONFIG, "DPMS enabled\n");
+	xf86DrvMsg(pScreen->myNum, enabled_from, "DPMS enabled\n");
     pDPMS->CloseScreen = pScreen->CloseScreen;
     pScreen->CloseScreen = DPMSClose;
     DPMSCount++;
commit 981bb9f1e33e4564d1b59c00c808cc43a2e9497b
Author: Peter Hutterer <peter at cs.unisa.edu.au>
Date:   Tue Dec 18 13:57:07 2007 +1030

    dix: set the correct number of valuators in valuator events.
    
    (first_valuator + num_valuators) must never be larger than the number of axes,
    otherwise DIX freaks out. And from looking at libXI, anything larger than 6 is
    wrong too.
    (cherry picked from commit 9f6ae61ad12cc2813d04405458e1ca5aed8a539e)

diff --git a/dix/getevents.c b/dix/getevents.c
index 40fc7f2..12cb950 100644
--- a/dix/getevents.c
+++ b/dix/getevents.c
@@ -346,7 +346,7 @@ getValuatorEvents(xEvent *events, DeviceIntPtr pDev, int first_valuator,
     for (i = first_valuator; i < final_valuator; i += 6, xv++, events++) {
         xv->type = DeviceValuator;
         xv->first_valuator = i;
-        xv->num_valuators = num_valuators;
+        xv->num_valuators = ((num_valuators - i) > 6) ? 6 : (num_valuators - i);
         xv->deviceid = pDev->id;
         switch (final_valuator - i) {
         case 6:
commit 260505e3c5a18044e97d31ea3bcc0955e46335c8
Author: David Nusinow <dnusinow at debian.org>
Date:   Sun Jan 6 16:37:13 2008 -0500

    Log enabling of DPMS even when it's not set in xorg.conf

diff --git a/hw/xfree86/common/xf86DPMS.c b/hw/xfree86/common/xf86DPMS.c
index 43efb8e..a23d81d 100644
--- a/hw/xfree86/common/xf86DPMS.c
+++ b/hw/xfree86/common/xf86DPMS.c
@@ -79,7 +79,6 @@ xf86DPMSInit(ScreenPtr pScreen, DPMSSetProcPtr set, int flags)
 	    && !DPMSDisabledSwitch)
 	    DPMSEnabled = TRUE;
 	xf86MarkOptionUsed(DPMSOpt);
-	xf86DrvMsg(pScreen->myNum, X_CONFIG, "DPMS enabled\n");
     } else if (DPMSEnabledSwitch) {
 	if (!DPMSDisabledSwitch)
 	    DPMSEnabled = TRUE;
@@ -88,6 +87,8 @@ xf86DPMSInit(ScreenPtr pScreen, DPMSSetProcPtr set, int flags)
     else {
 	pDPMS->Enabled = defaultDPMSEnabled;
     }
+    if (pDPMS->Enabled)
+	xf86DrvMsg(pScreen->myNum, X_CONFIG, "DPMS enabled\n");
     pDPMS->CloseScreen = pScreen->CloseScreen;
     pScreen->CloseScreen = DPMSClose;
     DPMSCount++;
commit 7e7622165940934e56ae96ae785a8f88eec1a5cf
Author: Julien Cristau <jcristau at debian.org>
Date:   Sun Jan 6 18:23:09 2008 +0100

    Fix the name of the XFree86-Misc extension in the xorg.conf manpage.

diff --git a/hw/xfree86/doc/man/xorg.conf.man.pre b/hw/xfree86/doc/man/xorg.conf.man.pre
index 9a08111..7eaf5d5 100644
--- a/hw/xfree86/doc/man/xorg.conf.man.pre
+++ b/hw/xfree86/doc/man/xorg.conf.man.pre
@@ -493,7 +493,7 @@ extension) to connect from another host.
 Default: off.
 .TP 7
 .BI "Option \*qDisableModInDev\*q  \*q" boolean \*q
-This disables the parts of the __xservername__\-Misc extension that can be used to
+This disables the parts of the XFree86\-Misc extension that can be used to
 modify the input device settings dynamically.
 Default: that functionality is enabled.
 .TP 7
commit 59df687835c68eda147de47edfe9bc415c0efb4f
Author: Julien Cristau <jcristau at debian.org>
Date:   Sun Jan 6 16:57:45 2008 +0100

    Document the AllowEmptyInput, AutoAddDevices and AutoEnableDevices flags
    
    Add documentation for the new AllowEmptyInput, AutoAddDevices and
    AutoEnableDevices server flags in the xorg.conf manpage.

diff --git a/hw/xfree86/doc/man/xorg.conf.man.pre b/hw/xfree86/doc/man/xorg.conf.man.pre
index 77439a5..9a08111 100644
--- a/hw/xfree86/doc/man/xorg.conf.man.pre
+++ b/hw/xfree86/doc/man/xorg.conf.man.pre
@@ -704,6 +704,20 @@ default.
 .BI "Option \*qIgnoreABI\*q \*q" boolean \*q
 Allow modules built for a different, potentially incompatible version of
 the X server to load. Disabled by default.
+.TP 7
+.BI "Option \*qAllowEmptyInput\*q \*q" boolean \*q
+If enabled, don't add the standard keyboard and mouse drivers, if there are no
+input devices in the config file.  Disabled by default.
+.TP 7
+.BI "Option \*qAutoAddDevices\*q \*q" boolean \*q
+If this option is disabled, then no devices will be added from HAL events.
+Enabled by default.
+.TP 7
+.BI "Option \*qAutoEnableDevices\*q \*q" boolean \*q
+If this option is disabled, then the devices will be added (and the
+DevicePresenceNotify event sent), but not enabled, thus leaving policy up
+to the client.
+Enabled by default.
 .SH "MODULE SECTION"
 The
 .B Module
commit 7d226d6a251cb90765be2b50a1973986c5b7605b
Author: Jeremy Huddleston <jeremy at yuffie.local>
Date:   Sat Jan 5 03:14:07 2008 -0800

    XQuartz: Cleanup for strict-prototyping
    Also fixed DarwinEQEnqueue to match changes to the callback
    And also use dpmsstubs.c rather than copying the code into darwin.c
    (cherry picked from commit 4c5c30a4beb7a427b00b18097f548876ad3c11d7)

diff --git a/hw/xquartz/Makefile.am b/hw/xquartz/Makefile.am
index 9ac6e0a..99d23eb 100644
--- a/hw/xquartz/Makefile.am
+++ b/hw/xquartz/Makefile.am
@@ -19,6 +19,7 @@ DIST_SUBDIRS = xpr bundle
 libXquartz_la_SOURCES = \
 	$(top_srcdir)/fb/fbcmap_mi.c \
 	$(top_srcdir)/mi/miinitext.c \
+	$(top_srcdir)/Xext/dpmsstubs.c \
 	X11Application.m \
 	X11Controller.m \
 	applewm.c \
diff --git a/hw/xquartz/X11Application.m b/hw/xquartz/X11Application.m
index 56db2c4..72537bb 100644
--- a/hw/xquartz/X11Application.m
+++ b/hw/xquartz/X11Application.m
@@ -855,7 +855,7 @@ static void send_nsevent (NSEventType type, NSEvent *e) {
     NSWindow *window;
     int pointer_x, pointer_y, ev_button, ev_type; 
     //    int num_events=0, i=0, state;
-    xEvent xe;
+    // xEvent xe;
 	
     /* convert location to global top-left coordinates */
     location = [e locationInWindow];
diff --git a/hw/xquartz/applewm.c b/hw/xquartz/applewm.c
index 72dca28..c460ec6 100644
--- a/hw/xquartz/applewm.c
+++ b/hw/xquartz/applewm.c
@@ -264,8 +264,7 @@ WMFreeEvents (data, id)
 }
 
 static int
-ProcAppleWMSelectInput (client)
-    register ClientPtr  client;
+ProcAppleWMSelectInput (register ClientPtr client)
 {
     REQUEST(xAppleWMSelectInputReq);
     WMEventPtr      pEvent, pNewEvent, *pHead;
@@ -479,13 +478,11 @@ ProcAppleWMSetFrontProcess(
 }
 
 static int
-ProcAppleWMSetWindowLevel(
-    register ClientPtr client
-)
+ProcAppleWMSetWindowLevel(register ClientPtr client)
 {
     REQUEST(xAppleWMSetWindowLevelReq);
     WindowPtr pWin;
-    int errno;
+    int err;
 
     REQUEST_SIZE_MATCH(xAppleWMSetWindowLevelReq);
 
@@ -497,9 +494,9 @@ ProcAppleWMSetWindowLevel(
         return BadValue;
     }
 
-     errno = appleWMProcs->SetWindowLevel(pWin, stuff->level);
-     if (errno != Success) {
-        return errno;
+     err = appleWMProcs->SetWindowLevel(pWin, stuff->level);
+     if (err != Success) {
+        return err;
     }
 
     return (client->noClientException);
diff --git a/hw/xquartz/darwin.c b/hw/xquartz/darwin.c
index 3ad9e14..20bcee5 100644
--- a/hw/xquartz/darwin.c
+++ b/hw/xquartz/darwin.c
@@ -879,24 +879,6 @@ void AbortDDX( void )
     ddxGiveUp();
 }
 
-
-/*
- * DPMS extension stubs
- */
-Bool DPMSSupported(void)
-{
-    return FALSE;
-}
-
-void DPMSSet(int level)
-{
-}
-
-int DPMSGet(int *level)
-{
-    return -1;
-}
-
 #include "mivalidate.h" // for union _Validate used by windowstr.h
 #include "windowstr.h"  // for struct _Window
 #include "scrnintstr.h" // for struct _Screen
diff --git a/hw/xquartz/darwinEvents.c b/hw/xquartz/darwinEvents.c
index 1760792..827fd81 100644
--- a/hw/xquartz/darwinEvents.c
+++ b/hw/xquartz/darwinEvents.c
@@ -45,6 +45,7 @@ in this Software without prior written authorization from The Open Group.
 #include "darwin.h"
 #include "quartz.h"
 #include "darwinKeyboard.h"
+#include "darwinEvents.h"
 
 #include <sys/types.h>
 #include <sys/uio.h>
@@ -213,9 +214,8 @@ Bool DarwinEQInit(DevicePtr pKbd, DevicePtr pPtr) {
  * 
  * This should be deprecated in favor of miEQEnqueue -- BB
  */
-void DarwinEQEnqueue(const xEvent *e) {
+void DarwinEQEnqueue(const xEventPtr e) {
     HWEventQueueType oldtail, newtail;
-    char byte = 0;
 
     oldtail = darwinEventQueue.tail;
 
@@ -253,7 +253,7 @@ void DarwinEQEnqueue(const xEvent *e) {
  * DarwinEQPointerPost
  *  Post a pointer event. Used by the mipointer.c routines.
  */
-void DarwinEQPointerPost(xEvent *e) {
+void DarwinEQPointerPost(DeviceIntPtr pdev, xEventPtr e) {
     (*darwinEventQueue.pPtr->processInputProc)
             (e, (DeviceIntPtr)darwinEventQueue.pPtr, 1);
 }
@@ -274,7 +274,6 @@ void ProcessInputEvents(void) {
     EventRec *e;
     int     x, y;
     xEvent  xe;
-    static int  old_flags = 0;  // last known modifier state
     // button number and modifier mask of currently pressed fake button
     input_check_flag=0;
 
diff --git a/hw/xquartz/darwinEvents.h b/hw/xquartz/darwinEvents.h
index d6cab2e..82cc26b 100644
--- a/hw/xquartz/darwinEvents.h
+++ b/hw/xquartz/darwinEvents.h
@@ -28,12 +28,13 @@
 #define _DARWIN_EVENTS_H
 
 Bool DarwinEQInit(DevicePtr pKbd, DevicePtr pPtr);
-void DarwinEQEnqueue(const xEvent *e);
-void DarwinEQPointerPost(xEvent *e);
+void DarwinEQEnqueue(const xEventPtr e);
+void DarwinEQPointerPost(DeviceIntPtr pDev, xEventPtr e);
 void DarwinEQSwitchScreen(ScreenPtr pScreen, Bool fromDIX);
 void DarwinPokeEQ(void);
 void DarwinSendPointerEvents(int ev_type, int ev_button, int pointer_x, int pointer_y);
 void DarwinSendKeyboardEvents(int ev_type, int keycode);
 void DarwinSendScrollEvents(float count, int pointer_x, int pointer_y);
+void DarwinUpdateModKeys(int flags);
 
 #endif  /* _DARWIN_EVENTS_H */
diff --git a/hw/xquartz/darwinKeyboard.c b/hw/xquartz/darwinKeyboard.c
index f1b90b7..b368fe9 100644
--- a/hw/xquartz/darwinKeyboard.c
+++ b/hw/xquartz/darwinKeyboard.c
@@ -330,7 +330,7 @@ static void parse_next_char_code(DataStream *s, KeySym *k) {
  * DarwinReadKeymapFile
  *      Read the appropriate keymapping from a keymapping file.
  */
-Bool DarwinReadKeymapFile(NXKeyMapping *keyMap) {
+static Bool DarwinReadKeymapFile(NXKeyMapping *keyMap) {
     struct stat         st;
     NXEventSystemDevice info[20];
     int                 interface = 0, handler_id = 0;
@@ -439,7 +439,7 @@ Bool DarwinReadKeymapFile(NXKeyMapping *keyMap) {
 /*
  * DarwinParseNXKeyMapping
  */
-Bool DarwinParseNXKeyMapping(darwinKeyboardInfo  *info) {
+static Bool DarwinParseNXKeyMapping(darwinKeyboardInfo  *info) {
     KeySym              *k;
     int                 i;
     short               numMods, numKeys, numPadKeys = 0;
@@ -933,7 +933,7 @@ int DarwinModifierNXMaskToNXKey(int mask) {
     return -1;
 }
 
-const char *DarwinModifierNXMaskTostring(int mask) {
+static const char *DarwinModifierNXMaskTostring(int mask) {
     switch (mask) {
         case NX_ALPHASHIFTMASK:      return "NX_ALPHASHIFTMASK";
         case NX_SHIFTMASK:           return "NX_SHIFTMASK";
diff --git a/hw/xquartz/darwinXinput.c b/hw/xquartz/darwinXinput.c
index ee456a4..e62ec0a 100644
--- a/hw/xquartz/darwinXinput.c
+++ b/hw/xquartz/darwinXinput.c
@@ -63,6 +63,7 @@ SOFTWARE.
 #include <X11/extensions/XI.h>
 #include <X11/extensions/XIproto.h>
 #include "XIstubs.h"
+#include "chgkbd.h"
 
 /***********************************************************************
  *
@@ -88,16 +89,12 @@ SOFTWARE.
  *
  */
 
-int
-ChangeKeyboardDevice (old_dev, new_dev)
-    DeviceIntPtr	old_dev;
-    DeviceIntPtr	new_dev;
-    {
+int ChangeKeyboardDevice (DeviceIntPtr old_dev, DeviceIntPtr new_dev) {
     /***********************************************************************
      DeleteFocusClassDeviceStruct(old_dev);	 * defined in xchgptr.c *
     **********************************************************************/
     return BadMatch;
-    }
+}
 
 
 /***********************************************************************
diff --git a/hw/xquartz/quartzAudio.c b/hw/xquartz/quartzAudio.c
index 86bb200..5dee32f 100644
--- a/hw/xquartz/quartzAudio.c
+++ b/hw/xquartz/quartzAudio.c
@@ -50,7 +50,7 @@
 #include <X11/extensions/XI.h>
 #include <assert.h>
 
-void NSBeep();
+void NSBeep(void);
 
 typedef struct QuartzAudioRec {
     double frequency;
diff --git a/hw/xquartz/quartzCocoa.m b/hw/xquartz/quartzCocoa.m
index 0086c5c..53e3f08 100644
--- a/hw/xquartz/quartzCocoa.m
+++ b/hw/xquartz/quartzCocoa.m
@@ -37,6 +37,7 @@
 #endif
 
 #include "quartzCommon.h"
+#include "quartzPasteboard.h"
 
 #define BOOL xBOOL
 #include "darwin.h"
diff --git a/hw/xquartz/quartzForeground.c b/hw/xquartz/quartzForeground.c
index bfea642..0e724de 100644
--- a/hw/xquartz/quartzForeground.c
+++ b/hw/xquartz/quartzForeground.c
@@ -32,6 +32,8 @@
 #include <ApplicationServices/ApplicationServices.h>
 #include <stdio.h>
 
+#include "quartzForeground.h"
+
 int QuartzMoveToForeground() {
    ProcessSerialNumber psn = { 0, kCurrentProcess };
    OSStatus returnCode = TransformProcessType(& psn, kProcessTransformToForegroundApplication);
diff --git a/hw/xquartz/quartzForeground.h b/hw/xquartz/quartzForeground.h
index 4fc21c7..b5422ff 100644
--- a/hw/xquartz/quartzForeground.h
+++ b/hw/xquartz/quartzForeground.h
@@ -32,6 +32,6 @@
 #ifndef _QUARTZ_FOREGROUND_H_
 #define _QUARTZ_FOREGROUND_H_
 
-int QuartzMoveToForeground();
+int QuartzMoveToForeground(void);
 
 #endif /* _QUARTZ_FOREGROUND_H_ */
diff --git a/hw/xquartz/quartzPasteboard.h b/hw/xquartz/quartzPasteboard.h
index afcb6e5..d6a8ee8 100644
--- a/hw/xquartz/quartzPasteboard.h
+++ b/hw/xquartz/quartzPasteboard.h
@@ -34,11 +34,11 @@
 #define _QUARTZPASTEBOARD_H
 
 // Aqua->X 
-void QuartzReadPasteboard();
+void QuartzReadPasteboard(void);
 char * QuartzReadCocoaPasteboard(void);	// caller must free string
 
 // X->Aqua
-void QuartzWritePasteboard();
+void QuartzWritePasteboard(void);
 void QuartzWriteCocoaPasteboard(char *text);
 
 #endif	/* _QUARTZPASTEBOARD_H */
diff --git a/hw/xquartz/quartzStartup.c b/hw/xquartz/quartzStartup.c
index 1b2a226..e25e155 100644
--- a/hw/xquartz/quartzStartup.c
+++ b/hw/xquartz/quartzStartup.c
@@ -52,8 +52,11 @@
 char **envpGlobal;      // argcGlobal and argvGlobal
                         // are from dix/globals.c
 
+int main(int argc, char **argv, char **envp);
+void _InitHLTB(void);
+void DarwinHandleGUI(int argc, char **argv, char **envp);
+
 static void server_thread (void *arg) {
-  extern int main(int argc, char **argv, char **envp);
   exit (main (argcGlobal, argvGlobal, envpGlobal));
 }
 
@@ -103,8 +106,6 @@ void DarwinHandleGUI(int argc, char **argv, char **envp) {
        before the main thread when we're _not_ prebound, things fail,
        so initialize by hand. */
 
-    extern void _InitHLTB(void);
-    
     _InitHLTB();    
     X11ControllerMain(argc, (const char **)argv, server_thread, NULL);
     exit(0);
diff --git a/hw/xquartz/xpr/appledri.c b/hw/xquartz/xpr/appledri.c
index 95a4439..b4a4725 100644
--- a/hw/xquartz/xpr/appledri.c
+++ b/hw/xquartz/xpr/appledri.c
@@ -55,6 +55,7 @@ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 #include "swaprep.h"
 #include "dri.h"
 #include "dristruct.h"
+#include "xpr.h"
 
 static int DRIErrorBase = 0;
 
commit 11967dce11cd953d123d53bb3389aa257c5158e8
Author: Jeremy Huddleston <jeremy at yuffie.local>
Date:   Fri Jan 4 22:54:26 2008 -0800

    XQuartz: Fixed copyright in About box for 2008.  Happy New Year!

diff --git a/hw/xquartz/Makefile.am b/hw/xquartz/Makefile.am
index 831ba49..9ac6e0a 100644
--- a/hw/xquartz/Makefile.am
+++ b/hw/xquartz/Makefile.am
@@ -1,7 +1,9 @@
 noinst_LTLIBRARIES = libXquartz.la
 AM_CFLAGS = $(XSERVER_CFLAGS) $(DIX_CFLAGS)
+AM_OBJCFLAGS = $(XSERVER_CFLAGS) $(DIX_CFLAGS)
 AM_CPPFLAGS = \
 	-DBUILD_DATE=\"$(BUILD_DATE)\" \
+	-DXSERVER_VERSION=\"$(VERSION)\" \
 	-DINXQUARTZ \
 	-DUSE_NEW_CLUT \
 	-DXFree86Server \
@@ -15,7 +17,7 @@ SUBDIRS = . xpr $(X11APP_SUBDIRS)
 DIST_SUBDIRS = xpr bundle
 
 libXquartz_la_SOURCES = \
-	$(top_srcdir)/fb/fbcmap.c \
+	$(top_srcdir)/fb/fbcmap_mi.c \
 	$(top_srcdir)/mi/miinitext.c \
 	X11Application.m \
 	X11Controller.m \
diff --git a/hw/xquartz/bundle/Info.plist b/hw/xquartz/bundle/Info.plist
index fce8c96..5babdfe 100644
--- a/hw/xquartz/bundle/Info.plist
+++ b/hw/xquartz/bundle/Info.plist
@@ -25,9 +25,9 @@
 	<key>CSResourcesFileMapped</key>
 		<true/>
 	<key>NSHumanReadableCopyright</key>
-		<string>Copyright © 2003-2007, Apple Inc.
+		<string>Copyright © 2003-2008, Apple Inc.
 Copyright © 2003, XFree86 Project, Inc.
-Copyright © 2003-2007, X.org Project, Inc.
+Copyright © 2003-2008, X.org Project, Inc.
 </string>
 	<key>NSMainNibFile</key>
 		<string>main</string>
commit aca75f389e2b08096c3cacec03b12a58075cf12c
Author: Jeremy Huddleston <jeremy at yuffie.local>
Date:   Fri Jan 4 12:23:09 2008 -0800

    XQuartz: Flush the debug log for easier debugging
    Also cleaned up formatting in xpr's eventHandler
    (cherry picked from commit 16861d6d4239c7f3918332ef07752f1e211afb23)

diff --git a/hw/xquartz/darwin.h b/hw/xquartz/darwin.h
index 1925424..c5e2ed8 100644
--- a/hw/xquartz/darwin.h
+++ b/hw/xquartz/darwin.h
@@ -124,7 +124,7 @@ enum {
 #ifdef ENABLE_DEBUG_LOG
 extern FILE *debug_log_fp;
 #define DEBUG_LOG_NAME "x11-debug.txt"
-#define DEBUG_LOG(msg, args...) if (debug_log_fp) fprintf(debug_log_fp, "%s:%d: " msg, __FUNCTION__, __LINE__, ##args )
+#define DEBUG_LOG(msg, args...) if (debug_log_fp) fprintf(debug_log_fp, "%s:%s:%d " msg, __FILE__, __FUNCTION__, __LINE__, ##args ); fflush(debug_log_fp);
 #else
 #define DEBUG_LOG(msg, args...) 
 #endif
diff --git a/hw/xquartz/xpr/xprScreen.c b/hw/xquartz/xpr/xprScreen.c
index 29179e5..e4e1fda 100644
--- a/hw/xquartz/xpr/xprScreen.c
+++ b/hw/xquartz/xpr/xprScreen.c
@@ -62,53 +62,52 @@ static const char *xprOpenGLBundle = "glxCGL.bundle";
  * eventHandler
  *  Callback handler for Xplugin events.
  */
-static void
-eventHandler(unsigned int type, const void *arg,
-             unsigned int arg_size, void *data)
-{
+static void eventHandler(unsigned int type, const void *arg,
+                         unsigned int arg_size, void *data) {
     switch (type) {
-    case XP_EVENT_DISPLAY_CHANGED:
-      DEBUG_LOG("XP_EVENT_DISPLAY_CHANGED\n");
-      QuartzMessageServerThread(kXDarwinDisplayChanged, 0);
-      break;
-
-    case XP_EVENT_WINDOW_STATE_CHANGED:
-      DEBUG_LOG("XP_EVENT_WINDOW_STATE_CHANGED\n");
-      if (arg_size >= sizeof(xp_window_state_event)) {
-	const xp_window_state_event *ws_arg = arg;
-	
-	QuartzMessageServerThread(kXDarwinWindowState, 2,
-				  ws_arg->id, ws_arg->state);
-      }
-      break;
-
-    case XP_EVENT_WINDOW_MOVED:
-      DEBUG_LOG("XP_EVENT_WINDOW_MOVED\n");
-      if (arg_size == sizeof(xp_window_id))  {
-	xp_window_id id = * (xp_window_id *) arg;
-	WindowPtr pWin = xprGetXWindow(id);
-	QuartzMessageServerThread(kXDarwinWindowMoved, 1, pWin);
-      }
-      break;
-      
-    case XP_EVENT_SURFACE_DESTROYED:
-      DEBUG_LOG("XP_EVENT_SURFACE_DESTROYED\n");
-    case XP_EVENT_SURFACE_CHANGED:
-      DEBUG_LOG("XP_EVENT_SURFACE_CHANGED\n");
-        if (arg_size == sizeof(xp_surface_id)) {
-	  int kind;
-	  
-	  if (type == XP_EVENT_SURFACE_DESTROYED)
-	    kind = AppleDRISurfaceNotifyDestroyed;
-	  else
-	    kind = AppleDRISurfaceNotifyChanged;
-	  
-	  DRISurfaceNotify(*(xp_surface_id *) arg, kind);
-        }
-        break;
-    default:
-      ErrorF("Unknown XP_EVENT type (%d) in xprScreen:eventHandler\n",
-	     type);
+        case XP_EVENT_DISPLAY_CHANGED:
+            DEBUG_LOG("XP_EVENT_DISPLAY_CHANGED\n");
+            QuartzMessageServerThread(kXDarwinDisplayChanged, 0);
+            break;
+            
+        case XP_EVENT_WINDOW_STATE_CHANGED:
+            if (arg_size >= sizeof(xp_window_state_event)) {
+                const xp_window_state_event *ws_arg = arg;
+                
+                DEBUG_LOG("XP_EVENT_WINDOW_STATE_CHANGED: id=%d, state=%d\n", ws_arg->id, ws_arg->state);
+                QuartzMessageServerThread(kXDarwinWindowState, 2,
+                                          ws_arg->id, ws_arg->state);
+            } else {
+                DEBUG_LOG("XP_EVENT_WINDOW_STATE_CHANGED: ignored\n");
+            }
+            break;
+            
+        case XP_EVENT_WINDOW_MOVED:
+            DEBUG_LOG("XP_EVENT_WINDOW_MOVED\n");
+            if (arg_size == sizeof(xp_window_id))  {
+                xp_window_id id = * (xp_window_id *) arg;
+                WindowPtr pWin = xprGetXWindow(id);
+                QuartzMessageServerThread(kXDarwinWindowMoved, 1, pWin);
+            }
+            break;
+            
+        case XP_EVENT_SURFACE_DESTROYED:
+            DEBUG_LOG("XP_EVENT_SURFACE_DESTROYED\n");
+        case XP_EVENT_SURFACE_CHANGED:
+            DEBUG_LOG("XP_EVENT_SURFACE_CHANGED\n");
+            if (arg_size == sizeof(xp_surface_id)) {
+                int kind;
+                
+                if (type == XP_EVENT_SURFACE_DESTROYED)
+                    kind = AppleDRISurfaceNotifyDestroyed;
+                else
+                    kind = AppleDRISurfaceNotifyChanged;
+                
+                DRISurfaceNotify(*(xp_surface_id *) arg, kind);
+            }
+            break;
+        default:
+            ErrorF("Unknown XP_EVENT type (%d) in xprScreen:eventHandler\n", type);
     }
 }
 
commit 57468a696e1259c1e1c185fc60230e1d195defb7
Author: Alan Hourihane <alanh at tungstengraphics.com>
Date:   Fri Jan 4 12:37:55 2008 +0000

    Fix Line drawing with CapNotLast set in PolySegment.

diff --git a/exa/exa_accel.c b/exa/exa_accel.c
index ae951ed..c2bfdee 100644
--- a/exa/exa_accel.c
+++ b/exa/exa_accel.c
@@ -739,6 +739,14 @@ exaPolySegment (DrawablePtr pDrawable, GCPtr pGC, int nseg,
 	    prect[i].y = pSeg[i].y2;
 	    prect[i].height = pSeg[i].y1 - pSeg[i].y2 + 1;
 	}
+
+	/* don't paint last pixel */
+	if (pGC->capStyle == CapNotLast) {
+	    if (prect[i].width == 1)
+		prect[i].height--;
+	    else
+		prect[i].width--;
+	}
     }
     pGC->ops->PolyFillRect(pDrawable, pGC, nseg, prect);
     xfree(prect);
commit 39cb782f28be4efb2621fd8c614f2367eb834412
Author: Eamon Walsh <ewalsh at tycho.nsa.gov>
Date:   Thu Jan 3 23:16:06 2008 -0500

    XACE: DeleteCallbackList zeroes out its argument so don't do it twice.

diff --git a/Xext/xace.c b/Xext/xace.c
index 6a7df31..e85a517 100644
--- a/Xext/xace.c
+++ b/Xext/xace.c
@@ -262,10 +262,7 @@ XaceResetProc(ExtensionEntry *extEntry)
     int i;
 
     for (i=0; i<XACE_NUM_HOOKS; i++)
-    {
 	DeleteCallbackList(&XaceHooks[i]);
-	XaceHooks[i] = NULL;
-    }
 } /* XaceResetProc */
 
 
commit 7f376f23db463a65176de632ca6094acb55db951
Author: Eamon Walsh <ewalsh at tycho.nsa.gov>
Date:   Thu Jan 3 23:08:49 2008 -0500

    devPrivates rework: Free callback lists after use.

diff --git a/dix/privates.c b/dix/privates.c
index e04da41..47a0e1a 100644
--- a/dix/privates.c
+++ b/dix/privates.c
@@ -232,6 +232,8 @@ dixResetPrivates(void)
     /* reset internal structures */
     while (items) {
 	next = items->next;
+	DeleteCallbackList(&items->initfuncs);
+	DeleteCallbackList(&items->deletefuncs);
 	xfree(items);
 	items = next;
     }
commit de18703d2a25999e391d11b4c82ee018fb87372d
Author: Eamon Walsh <ewalsh at tycho.nsa.gov>
Date:   Thu Jan 3 23:07:24 2008 -0500

    dix: Fix bug+leak in callback manager DeleteCallbackList function.

diff --git a/dix/dixutils.c b/dix/dixutils.c
index 786f4e3..dd485d5 100644
--- a/dix/dixutils.c
+++ b/dix/dixutils.c
@@ -800,7 +800,7 @@ _DeleteCallbackList(
 
     for (i = 0; i < numCallbackListsToCleanup; i++)
     {
-	if ((listsToCleanup[i] = pcbl) != 0)
+	if (listsToCleanup[i] == pcbl)
 	{
 	    listsToCleanup[i] = NULL;
 	    break;
commit 20eb26f9d149993ae360a2cbd1b536b68c9f4069
Author: Alex Deucher <alex at samba.(none)>
Date:   Thu Jan 3 22:53:36 2008 -0500

    Fix potential crasher in xf86CrtcRotate()
    
    xf86CrtcRotate() is called by randr 1.2 drivers via xf86CrtcSetMode() or xf86SetDesiredModes()
    during ScreenInit() at which point pScrn->pScreen is not set. If a user specifies a rotation
    in their config file pScrn->pScreen is dereferenced and boom.

diff --git a/hw/xfree86/modes/xf86Rotate.c b/hw/xfree86/modes/xf86Rotate.c
index 380478f..c129d9b 100644
--- a/hw/xfree86/modes/xf86Rotate.c
+++ b/hw/xfree86/modes/xf86Rotate.c
@@ -494,7 +494,8 @@ xf86CrtcRotate (xf86CrtcPtr crtc, DisplayModePtr mode, Rotation rotation)
 {
     ScrnInfoPtr		pScrn = crtc->scrn;
     xf86CrtcConfigPtr   xf86_config = XF86_CRTC_CONFIG_PTR(pScrn);
-    ScreenPtr		pScreen = pScrn->pScreen;
+    /* if this is called during ScreenInit() we don't have pScrn->pScreen yet */
+    ScreenPtr		pScreen = screenInfo.screens[pScrn->scrnIndex];
     PictTransform	crtc_to_fb, fb_to_crtc;
     
     PictureTransformIdentity (&crtc_to_fb);
commit cd0603c2dc5ee000ebce66056bc1a72f99bfb617
Author: Eamon Walsh <ewalsh at tycho.nsa.gov>
Date:   Thu Jan 3 21:41:02 2008 -0500

    Bug #13765: Heap corruption in XC-SECURITY extension code.

diff --git a/Xext/xace.c b/Xext/xace.c
index 9f8a8cc..6a7df31 100644
--- a/Xext/xace.c
+++ b/Xext/xace.c
@@ -448,7 +448,7 @@ XaceCensorImage(client, pVisibleRegion, widthBytesLine, pDraw, x, y, w, h,
 
 	/* convert region to list-of-rectangles for PolyFillRect */
 
-	pRects = (xRectangle *)xalloc(nRects * sizeof(xRectangle *));
+	pRects = (xRectangle *)xalloc(nRects * sizeof(xRectangle));
 	if (!pRects)
 	{
 	    failed = TRUE;
commit e46d559739e020dc7f6fcbdc6d1fb39c57aab4b1
Author: Jeremy Huddleston <jeremy at yuffie.local>
Date:   Sat Dec 22 15:09:12 2007 -0800

    XQuartz: Cleaned up color map configuration.
    8 bit color still doesn't work, but the -depth command line argument now works properly.
    (cherry picked from commit 6765949c27c053d22882f54337cfd09203aa5383)

diff --git a/hw/xquartz/darwin.c b/hw/xquartz/darwin.c
index 4630734..3ad9e14 100644
--- a/hw/xquartz/darwin.c
+++ b/hw/xquartz/darwin.c
@@ -78,7 +78,7 @@
 #include "darwinEvents.h"
 #include "darwinKeyboard.h"
 #include "quartz.h"
-#include "darwinClut8.h"
+//#include "darwinClut8.h"
 
 #ifdef ENABLE_DEBUG_LOG
 FILE *debug_log_fp = NULL;
@@ -176,17 +176,10 @@ static Bool DarwinSaveScreen(ScreenPtr pScreen, int on)
  *  This is a callback from dix during AddScreen() from InitOutput().
  *  Initialize the screen and communicate information about it back to dix.
  */
-static Bool DarwinAddScreen(
-    int         index,
-    ScreenPtr   pScreen,
-    int         argc,
-    char        **argv )
-{
-    int         bitsPerRGB, i, dpi;
+static Bool DarwinAddScreen(int index, ScreenPtr pScreen, int argc, char **argv) {
+    int         dpi;
     static int  foundIndex = 0;
     Bool        ret;
-    VisualPtr   visual;
-    ColormapPtr pmap;
     DarwinFramebufferPtr dfb;
 
     // reset index of found screens for each server generation
@@ -204,28 +197,13 @@ static Bool DarwinAddScreen(
     if (! ret)
         return FALSE;
 
-    bitsPerRGB = dfb->bitsPerComponent;
-
     // reset the visual list
     miClearVisualTypes();
 
     // setup a single visual appropriate for our pixel type
-    if (dfb->colorType == TrueColor) {
-        if (!miSetVisualTypes( dfb->colorBitsPerPixel, TrueColorMask,
-                               bitsPerRGB, TrueColor )) {
-            return FALSE;
-        }
-    } else if (dfb->colorType == PseudoColor) {
-        if (!miSetVisualTypes( dfb->colorBitsPerPixel, PseudoColorMask,
-                               bitsPerRGB, PseudoColor )) {
-            return FALSE;
-        }
-    } else if (dfb->colorType == StaticColor) {
-        if (!miSetVisualTypes( dfb->colorBitsPerPixel, StaticColorMask,
-                               bitsPerRGB, StaticColor )) {
-            return FALSE;
-        }
-    } else {
+    if(!miSetVisualTypesAndMasks(dfb->depth, dfb->visuals, dfb->bitsPerRGB,
+                                 dfb->preferredCVC, dfb->redMask,
+                                 dfb->greenMask, dfb->blueMask)) {
         return FALSE;
     }
 
@@ -249,20 +227,28 @@ static Bool DarwinAddScreen(
         return FALSE;
     }
 
+//    ErrorF("Screen type: %d, %d=%d, %d=%d, %d=%d, %x=%x=%x, %x=%x=%x, %x=%x=%x\n", pScreen->visuals->class,
+//           pScreen->visuals->offsetRed, dfb->bitsPerRGB * 2,
+//           pScreen->visuals->offsetGreen, dfb->bitsPerRGB,
+//           pScreen->visuals->offsetBlue, 0,
+//           pScreen->visuals->redMask, dfb->redMask, ((1<<dfb->bitsPerRGB)-1) << pScreen->visuals->offsetRed,
+//           pScreen->visuals->greenMask, dfb->greenMask, ((1<<dfb->bitsPerRGB)-1) << pScreen->visuals->offsetGreen,
+//           pScreen->visuals->blueMask, dfb->blueMask, ((1<<dfb->bitsPerRGB)-1) << pScreen->visuals->offsetBlue);
+
     // set the RGB order correctly for TrueColor
-    if (dfb->bitsPerPixel > 8) {
-        for (i = 0, visual = pScreen->visuals;  // someday we may have more than 1
-            i < pScreen->numVisuals; i++, visual++) {
-            if (visual->class == TrueColor) {
-                visual->offsetRed = bitsPerRGB * 2;
-                visual->offsetGreen = bitsPerRGB;
-                visual->offsetBlue = 0;
-                visual->redMask = ((1<<bitsPerRGB)-1) << visual->offsetRed;
-                visual->greenMask = ((1<<bitsPerRGB)-1) << visual->offsetGreen;
-                visual->blueMask = ((1<<bitsPerRGB)-1) << visual->offsetBlue;
-            }
-        }
-    }
+//    if (dfb->bitsPerPixel > 8) {
+//        for (i = 0, visual = pScreen->visuals;  // someday we may have more than 1
+//            i < pScreen->numVisuals; i++, visual++) {
+//            if (visual->class == TrueColor) {
+//                visual->offsetRed = bitsPerRGB * 2;
+//                visual->offsetGreen = bitsPerRGB;
+//                visual->offsetBlue = 0;
+//                visual->redMask = ((1<<bitsPerRGB)-1) << visual->offsetRed;
+//                visual->greenMask = ((1<<bitsPerRGB)-1) << visual->offsetGreen;
+//                visual->blueMask = ((1<<bitsPerRGB)-1) << visual->offsetBlue;
+//            }
+//        }
+//    }
 
 #ifdef RENDER
     if (! fbPictureInit(pScreen, 0, 0)) {
@@ -292,17 +278,16 @@ static Bool DarwinAddScreen(
      * mode and we're using a fixed color map.  Essentially this translates
      * to Darwin/x86 in 8-bit mode.
      */
-    if( (dfb->colorBitsPerPixel == 8) &&
-                (dfb->colorType == StaticColor) )
-    {
-        pmap = miInstalledMaps[pScreen->myNum];
-        visual = pmap->pVisual;
-        for( i = 0; i < visual->ColormapEntries; i++ ) {
-            pmap->red[i].co.local.red   = darwinClut8[i].red;
-            pmap->red[i].co.local.green = darwinClut8[i].green;
-            pmap->red[i].co.local.blue  = darwinClut8[i].blue;
-        }
-    }
+//    if(dfb->depth == 8) {
+//        ColormapPtr map = RootlessGetColormap (pScreen);
+//        for( i = 0; i < map->pVisual->ColormapEntries; i++ ) {
+//            Entry *ent = map->red + i;
+//            ErrorF("Setting lo %d -> r: %04x g: %04x b: %04x\n", i, darwinClut8[i].red, darwinClut8[i].green, darwinClut8[i].blue);
+//            ent->co.local.red   = darwinClut8[i].red;
+//            ent->co.local.green = darwinClut8[i].green;
+//            ent->co.local.blue  = darwinClut8[i].blue;
+//        }
+//    }
 
     dixScreenOrigins[index].x = dfb->x;
     dixScreenOrigins[index].y = dfb->y;
@@ -793,24 +778,21 @@ int ddxProcessArgument( int argc, char *argv[], int i )
     }
 
     if ( !strcmp( argv[i], "-depth" ) ) {
-        int     bitDepth;
-
         if ( i == argc-1 ) {
             FatalError( "-depth must be followed by a number\n" );
         }
 #ifdef OLD_POWERBOOK_G3
         ErrorF( "Ignoring unsupported -depth option on old PowerBook G3\n");
 #else
-        bitDepth = atoi( argv[i+1] );
-        if (bitDepth == 8)
-            darwinDesiredDepth = 0;
-        else if (bitDepth == 15)
-            darwinDesiredDepth = 1;
-        else if (bitDepth == 24)
-            darwinDesiredDepth = 2;
-        else
+        darwinDesiredDepth = atoi( argv[i+1] );
+        if(darwinDesiredDepth != -1 &&
+           darwinDesiredDepth != 8 &&
+           darwinDesiredDepth != 15 &&
+           darwinDesiredDepth != 24) {
             FatalError( "Unsupported pixel depth. Use 8, 15, or 24 bits\n" );
-        ErrorF( "Attempting to use pixel depth of %i\n", bitDepth );
+        }
+
+        ErrorF( "Attempting to use pixel depth of %i\n", darwinDesiredDepth );
 #endif
         return 2;
     }
diff --git a/hw/xquartz/darwin.h b/hw/xquartz/darwin.h
index c569d66..1925424 100644
--- a/hw/xquartz/darwin.h
+++ b/hw/xquartz/darwin.h
@@ -40,10 +40,14 @@ typedef struct {
     int                 width;
     int                 height;
     int                 pitch;
-    int                 colorType;
+    int                 depth;
+    int                 visuals;
+    int                 bitsPerRGB;
     int                 bitsPerPixel;
-    int                 colorBitsPerPixel;
-    int                 bitsPerComponent;
+    int                 preferredCVC;
+    Pixel               redMask;
+    Pixel               greenMask;
+    Pixel               blueMask;
 } DarwinFramebufferRec, *DarwinFramebufferPtr;
 
 // From darwin.c
diff --git a/hw/xquartz/xpr/xprScreen.c b/hw/xquartz/xpr/xprScreen.c
index 068b7b1..29179e5 100644
--- a/hw/xquartz/xpr/xprScreen.c
+++ b/hw/xquartz/xpr/xprScreen.c
@@ -42,6 +42,7 @@
 #include "globals.h"
 #include "Xplugin.h"
 #include "applewmExt.h"
+#include "micmap.h"
 
 // From xprFrame.c
 WindowPtr xprGetXWindow(xp_window_id wid);
@@ -249,35 +250,59 @@ static Bool
 xprAddScreen(int index, ScreenPtr pScreen)
 {
     DarwinFramebufferPtr dfb = SCREEN_PRIV(pScreen);
-
-    /* If no specific depth chosen, look for the depth of the main display.
-       Else if 16bpp specified, use that. Else use 32bpp. */
-
-    dfb->colorType = TrueColor;
-    dfb->bitsPerComponent = 8;
-    dfb->bitsPerPixel = 32;
-    dfb->colorBitsPerPixel = 24;
-
-    if (darwinDesiredDepth == -1)
-    {
-        dfb->bitsPerComponent = CGDisplayBitsPerSample(kCGDirectMainDisplay);
-        dfb->bitsPerPixel = CGDisplayBitsPerPixel(kCGDirectMainDisplay);
-        dfb->colorBitsPerPixel =
-                CGDisplaySamplesPerPixel(kCGDirectMainDisplay) *
-                dfb->bitsPerComponent;
+    int depth = darwinDesiredDepth;
+    
+    if(depth == -1) {
+        depth = CGDisplaySamplesPerPixel(kCGDirectMainDisplay) * CGDisplayBitsPerSample(kCGDirectMainDisplay);
+        //dfb->depth = CGDisplaySamplesPerPixel(kCGDirectMainDisplay) * CGDisplayBitsPerSample(kCGDirectMainDisplay);
+        //dfb->bitsPerRGB = CGDisplayBitsPerSample(kCGDirectMainDisplay);
+        //dfb->bitsPerPixel = CGDisplayBitsPerPixel(kCGDirectMainDisplay);
     }
-    else if (darwinDesiredDepth == 15)
-    {
-        dfb->bitsPerComponent = 5;
-        dfb->bitsPerPixel = 16;
-        dfb->colorBitsPerPixel = 15;
-    }
-    else if (darwinDesiredDepth == 8)
-    {
-        dfb->colorType = PseudoColor;
-        dfb->bitsPerComponent = 8;
-        dfb->bitsPerPixel = 8;
-        dfb->colorBitsPerPixel = 8;
+    
+    switch(depth) {
+        case -8: // broken
+            FatalError("Unsupported color depth %d\n", darwinDesiredDepth);
+            dfb->visuals = (1 << StaticGray) | (1 << GrayScale);
+            dfb->preferredCVC = GrayScale;
+            dfb->depth = 8;
+            dfb->bitsPerRGB = 8;
+            dfb->bitsPerPixel = 8;
+            dfb->redMask = 0;
+            dfb->greenMask = 0;
+            dfb->blueMask = 0;
+            break;
+        case 8: // broken
+            dfb->visuals = PseudoColorMask;
+            dfb->preferredCVC = PseudoColor;
+            dfb->depth = 8;
+            dfb->bitsPerRGB = 8;
+            dfb->bitsPerPixel = 8;
+            dfb->redMask = 0;
+            dfb->greenMask = 0;
+            dfb->blueMask = 0;
+            break;
+        case 15:
+            dfb->visuals = LARGE_VISUALS;
+            dfb->preferredCVC = TrueColor;
+            dfb->depth = 15;
+            dfb->bitsPerRGB = 5;
+            dfb->bitsPerPixel = 16;
+            dfb->redMask   = 0x7c00;
+            dfb->greenMask = 0x03e0;
+            dfb->blueMask  = 0x001f;
+            break;
+        case 24:
+            dfb->visuals = LARGE_VISUALS;
+            dfb->preferredCVC = TrueColor;
+            dfb->depth = 24;
+            dfb->bitsPerRGB = 8;
+            dfb->bitsPerPixel = 32;
+            dfb->redMask   = 0x00ff0000;
+            dfb->greenMask = 0x0000ff00;
+            dfb->blueMask  = 0x000000ff;
+            break;
+        default:
+            FatalError("Unsupported color depth %d\n", darwinDesiredDepth);
     }
 
     if (noPseudoramiXExtension)
commit 17a9714a6789a389d52dbb40fd1eed1e24c04d64
Author: Eamon Walsh <ewalsh at tycho.nsa.gov>
Date:   Thu Jan 3 14:46:54 2008 -0500

    Bug #13794: Update MBE extension devPrivates to new interface.

diff --git a/Xext/mbuf.c b/Xext/mbuf.c
index 35c8c89..0b5b91e 100644
--- a/Xext/mbuf.c
+++ b/Xext/mbuf.c
@@ -61,8 +61,8 @@ in this Software without prior written authorization from The Open Group.
 
 static int		MultibufferEventBase;
 static int		MultibufferErrorBase;
-int			MultibufferScreenIndex = -1;
-int			MultibufferWindowIndex = -1;
+static DevPrivateKey MultibufferScreenPrivKey = &MultibufferScreenPrivKey;
+static DevPrivateKey MultibufferWindowPrivKey = &MultibufferWindowPrivKey;
 
 static void		PerformDisplayRequest (
 				MultibuffersPtr * /* ppMultibuffers */,
@@ -200,27 +200,16 @@ MultibufferExtensionInit()
     ScreenPtr		    pScreen;
     MultibufferScreenPtr    pMultibufferScreen;
 
-    /*
-     * allocate private pointers in windows and screens.  Allocating
-     * window privates may seem like an unnecessary expense, but every
-     * PositionWindow call must check to see if the window is
-     * multi-buffered; a resource lookup is too expensive.
-     */
-    MultibufferScreenIndex = AllocateScreenPrivateIndex ();
-    if (MultibufferScreenIndex < 0)
-	return;
-    MultibufferWindowIndex = AllocateWindowPrivateIndex ();
     for (i = 0; i < screenInfo.numScreens; i++)
     {
 	pScreen = screenInfo.screens[i];
-	if (!AllocateWindowPrivate (pScreen, MultibufferWindowIndex, 0) ||
-	    !(pMultibufferScreen = (MultibufferScreenPtr) xalloc (sizeof (MultibufferScreenRec))))
+	if (!(pMultibufferScreen = (MultibufferScreenPtr) xalloc (sizeof (MultibufferScreenRec))))
 	{
 	    for (j = 0; j < i; j++)
-		xfree (screenInfo.screens[j]->devPrivates[MultibufferScreenIndex].ptr);
+		xfree (dixLookupPrivate(&screenInfo.screens[j]->devPrivates, MultibufferScreenPrivKey));
 	    return;
 	}
-	pScreen->devPrivates[MultibufferScreenIndex].ptr = (pointer) pMultibufferScreen;
+	dixSetPrivate(&pScreen->devPrivates, MultibufferScreenPrivKey, pMultibufferScreen);
 	/*
  	 * wrap PositionWindow to resize the pixmap when the window
 	 * changes size
@@ -260,14 +249,11 @@ ExtensionEntry	*extEntry;
     ScreenPtr		    pScreen;
     MultibufferScreenPtr    pMultibufferScreen;
     
-    if (MultibufferScreenIndex < 0)
-	return;
     for (i = 0; i < screenInfo.numScreens; i++)
     {
 	pScreen = screenInfo.screens[i];
-	if (pScreen->devPrivates[MultibufferScreenIndex].ptr)
+	if ((pMultibufferScreen = (MultibufferScreenPtr)dixLookupPrivate(&pScreen->devPrivates, MultibufferScreenPrivKey)))
 	{
-	    pMultibufferScreen = (MultibufferScreenPtr) pScreen->devPrivates[MultibufferScreenIndex].ptr;
 	    pScreen->PositionWindow = pMultibufferScreen->PositionWindow;
 	    xfree (pMultibufferScreen);
 	}
@@ -427,7 +413,7 @@ CreateImageBuffers (pWin, nbuf, ids, action, hint)
     pMultibuffers->lastUpdate.milliseconds = 0;
     pMultibuffers->width = width;
     pMultibuffers->height = height;
-    pWin->devPrivates[MultibufferWindowIndex].ptr = (pointer) pMultibuffers;
+    dixSetPrivate(&pWin->devPrivates, MultibufferWindowPrivKey, pMultibuffers);
     if (pClearGC) FreeScratchGC(pClearGC);
     return Success;
 }
@@ -487,7 +473,7 @@ ProcCreateImageBuffers (client)
     rep.type = X_Reply;
     rep.length = 0;
     rep.sequenceNumber = client->sequence;
-    rep.numberBuffer = ((MultibuffersPtr) (pWin->devPrivates[MultibufferWindowIndex].ptr))->numMultibuffer;
+    rep.numberBuffer = ((MultibuffersPtr) (dixLookupPrivate(&pWin->devPrivates, MultibufferWindowPrivKey)))->numMultibuffer;
     if (client->swapped)
     {
     	swaps(&rep.sequenceNumber, n);
@@ -1236,7 +1222,7 @@ GetBufferPointer (pWin, i)
 {
     MultibuffersPtr pMultibuffers;
 
-    if (!(pMultibuffers = (MultibuffersPtr) pWin->devPrivates[MultibufferWindowIndex].ptr))
+    if (!(pMultibuffers = (MultibuffersPtr) dixLookupPrivate(&pWin->devPrivates, MultibufferWindowPrivKey)))
 	return NULL;
     return (DrawablePtr) pMultibuffers->buffers[i].pPixmap;
 }
@@ -1475,7 +1461,7 @@ DestroyImageBuffers (pWin)
 {
     FreeResourceByType (pWin->drawable.id, MultibuffersResType, FALSE);
     /* Zero out the window's pointer to the buffers so they won't be reused */
-    pWin->devPrivates[MultibufferWindowIndex].ptr = NULL;
+    dixSetPrivate(&pWin->devPrivates, MultibufferWindowPrivKey, NULL);
 }
 
 /*
@@ -1503,11 +1489,11 @@ MultibufferPositionWindow (pWin, x, y)
     Bool	    clear;
 
     pScreen = pWin->drawable.pScreen;
-    pMultibufferScreen = (MultibufferScreenPtr) pScreen->devPrivates[MultibufferScreenIndex].ptr;
+    pMultibufferScreen = (MultibufferScreenPtr) dixLookupPrivate(&pScreen->devPrivates, MultibufferScreenPrivKey);
     (*pMultibufferScreen->PositionWindow) (pWin, x, y);
 
     /* if this window is not multibuffered, we're done */
-    if (!(pMultibuffers = (MultibuffersPtr) pWin->devPrivates[MultibufferWindowIndex].ptr))
+    if (!(pMultibuffers = (MultibuffersPtr) dixLookupPrivate(&pWin->devPrivates, MultibufferWindowPrivKey)))
 	return TRUE;
 
     /* if new size is same as old, we're done */
@@ -1620,7 +1606,7 @@ MultibufferDrawableDelete (value, id)
     if (pDrawable->type == DRAWABLE_WINDOW)
     {
 	pWin = (WindowPtr) pDrawable;
-	pMultibuffers = (MultibuffersPtr) pWin->devPrivates[MultibufferWindowIndex].ptr;
+	pMultibuffers = (MultibuffersPtr) dixLookupPrivate(&pWin->devPrivates, MultibufferWindowPrivKey);
 	pPixmap = pMultibuffers->buffers[pMultibuffers->displayedMultibuffer].pPixmap;
     }
     else
commit ccf6636d2ca8acdaaeb8da34db507a10a082b0de
Author: Alan Coopersmith <alan.coopersmith at sun.com>
Date:   Wed Jan 2 19:28:33 2008 -0800

    Kill xf86getpagesize even harder (dummylib & ioport)

diff --git a/hw/xfree86/dummylib/Makefile.am b/hw/xfree86/dummylib/Makefile.am
index 2ab0a77..ad3f1ea 100644
--- a/hw/xfree86/dummylib/Makefile.am
+++ b/hw/xfree86/dummylib/Makefile.am
@@ -25,7 +25,6 @@ libdummy_nonserver_a_SOURCES = \
 	xf86drvmsgverb.c \
 	xf86errorf.c \
 	xf86errorfverb.c \
-	xf86getpagesize.c \
 	xf86getverb.c \
 	xf86info.c \
 	xf86msg.c \
diff --git a/hw/xfree86/dummylib/xf86getpagesize.c b/hw/xfree86/dummylib/xf86getpagesize.c
deleted file mode 100644
index 8859c76..0000000
--- a/hw/xfree86/dummylib/xf86getpagesize.c
+++ /dev/null
@@ -1,21 +0,0 @@
-#ifdef HAVE_XORG_CONFIG_H
-#include <xorg-config.h>
-#endif
-
-#include <X11/X.h>
-#include "os.h"
-#include "xf86.h"
-#include "xf86Priv.h"
-
-/*
- * Utility functions required by libxf86_os. 
- */
-
-int xf86getpagesize(void);
-
-_X_EXPORT int
-xf86getpagesize(void)
-{
-    return 4096;	/* not used */
-}
-
diff --git a/hw/xfree86/utils/ioport/ioport.c b/hw/xfree86/utils/ioport/ioport.c
index 3221364..7370434 100644
--- a/hw/xfree86/utils/ioport/ioport.c
+++ b/hw/xfree86/utils/ioport/ioport.c
@@ -489,4 +489,3 @@ main(argc, argv)
 	return (0);
 }
 
-#include "xf86getpagesize.c"
commit dfd682b582636a36345144bcf835e3ee46718d90
Author: Alan Coopersmith <alan.coopersmith at sun.com>
Date:   Wed Jan 2 19:27:22 2008 -0800

    X.Org bug 4947/Sun bug 6646626: Xv extension not byte-swapping properly
    
    X.Org Bugzilla #4947 <https://bugs.freedesktop.org/show_bug.cgi?id=4947>
    Sun bug 6646626 <http://bugs.opensolaris.org/bugdatabase/view_bug.do?bug_id=6646626>
    
    Don't use swapped data after swapping it.   When done swapping data,
    send the swapped data, not the address of the pointer to it, to the client.

diff --git a/Xext/xvdisp.c b/Xext/xvdisp.c
index 8096c8c..17ff1d7 100644
--- a/Xext/xvdisp.c
+++ b/Xext/xvdisp.c
@@ -67,7 +67,7 @@ SWriteQueryExtensionReply(
   swaps(&rep->version, n);
   swaps(&rep->revision, n);
   
-  (void)WriteToClient(client, sz_xvQueryExtensionReply, (char *)&rep);
+  (void)WriteToClient(client, sz_xvQueryExtensionReply, (char *)rep);
 
   return Success;
 }
@@ -83,7 +83,7 @@ SWriteQueryAdaptorsReply(
   swapl(&rep->length, n);
   swaps(&rep->num_adaptors, n);
   
-  (void)WriteToClient(client, sz_xvQueryAdaptorsReply, (char *)&rep);
+  (void)WriteToClient(client, sz_xvQueryAdaptorsReply, (char *)rep);
 
   return Success;
 }
@@ -99,7 +99,7 @@ SWriteQueryEncodingsReply(
   swapl(&rep->length, n);
   swaps(&rep->num_encodings, n);
   
-  (void)WriteToClient(client, sz_xvQueryEncodingsReply, (char *)&rep);
+  (void)WriteToClient(client, sz_xvQueryEncodingsReply, (char *)rep);
 
   return Success;
 }
@@ -204,7 +204,7 @@ SWriteGrabPortReply(
   swaps(&rep->sequenceNumber, n);
   swapl(&rep->length, n);
 
-  (void)WriteToClient(client, sz_xvGrabPortReply, (char *)&rep);
+  (void)WriteToClient(client, sz_xvGrabPortReply, (char *)rep);
 
   return Success;
 }
@@ -220,7 +220,7 @@ SWriteGetPortAttributeReply(
   swapl(&rep->length, n);
   swapl(&rep->value, n);
 
-  (void)WriteToClient(client, sz_xvGetPortAttributeReply, (char *)&rep);
+  (void)WriteToClient(client, sz_xvGetPortAttributeReply, (char *)rep);
 
   return Success;
 }
@@ -237,7 +237,7 @@ SWriteQueryBestSizeReply(
   swaps(&rep->actual_width, n);
   swaps(&rep->actual_height, n);
 
-  (void)WriteToClient(client, sz_xvQueryBestSizeReply, (char *)&rep);
+  (void)WriteToClient(client, sz_xvQueryBestSizeReply, (char *)rep);
 
   return Success;
 }
@@ -254,7 +254,7 @@ SWriteQueryPortAttributesReply(
   swapl(&rep->num_attributes, n);
   swapl(&rep->text_size, n);
 
-  (void)WriteToClient(client, sz_xvQueryPortAttributesReply, (char *)&rep);
+  (void)WriteToClient(client, sz_xvQueryPortAttributesReply, (char *)rep);
 
   return Success;
 }
@@ -273,7 +273,7 @@ SWriteQueryImageAttributesReply(
   swaps(&rep->width, n);
   swaps(&rep->height, n);
 
-  (void)WriteToClient(client, sz_xvQueryImageAttributesReply, (char *)&rep);
+  (void)WriteToClient(client, sz_xvQueryImageAttributesReply, (char *)rep);
 
   return Success;
 }
@@ -289,7 +289,7 @@ SWriteListImageFormatsReply(
   swapl(&rep->length, n);
   swapl(&rep->num_formats, n);
 
-  (void)WriteToClient(client, sz_xvListImageFormatsReply, (char *)&rep);
+  (void)WriteToClient(client, sz_xvListImageFormatsReply, (char *)rep);
 
   return Success;
 }
@@ -378,6 +378,7 @@ ProcXvQueryAdaptors(ClientPtr client)
   xvAdaptorInfo ainfo;
   xvQueryAdaptorsReply rep;
   int totalSize, na, nf, rc;
+  int nameSize;
   XvAdaptorPtr pa;
   XvFormatPtr pf;
   WindowPtr pWin;
@@ -439,12 +440,12 @@ ProcXvQueryAdaptors(ClientPtr client)
       ainfo.base_id = pa->base_id;
       ainfo.num_ports = pa->nPorts;
       ainfo.type = pa->type;
-      ainfo.name_size = strlen(pa->name);
+      ainfo.name_size = nameSize = strlen(pa->name);
       ainfo.num_formats = pa->nFormats;
 
       _WriteAdaptorInfo(client, &ainfo);
 
-      WriteToClient(client, ainfo.name_size, pa->name);
+      WriteToClient(client, nameSize, pa->name);
 
       nf = pa->nFormats;
       pf = pa->pFormats;
@@ -469,6 +470,7 @@ ProcXvQueryEncodings(ClientPtr client)
   xvEncodingInfo einfo;
   xvQueryEncodingsReply rep;
   int totalSize;
+  int nameSize;
   XvPortPtr pPort;
   int ne;
   XvEncodingPtr pe;
@@ -513,13 +515,13 @@ ProcXvQueryEncodings(ClientPtr client)
   while (ne--) 
     {
       einfo.encoding = pe->id;
-      einfo.name_size = strlen(pe->name);
+      einfo.name_size = nameSize = strlen(pe->name);
       einfo.width = pe->width;
       einfo.height = pe->height;
       einfo.rate.numerator = pe->rate.numerator;
       einfo.rate.denominator = pe->rate.denominator;
       _WriteEncodingInfo(client, &einfo);
-      WriteToClient(client, einfo.name_size, pe->name);
+      WriteToClient(client, nameSize, pe->name);
       pe++;
     }
 
@@ -984,18 +986,19 @@ ProcXvQueryPortAttributes(ClientPtr client)
   rep.text_size = 0;
 
   for(i = 0, pAtt = pPort->pAdaptor->pAttributes; 
-      i < rep.num_attributes; i++, pAtt++) 
+      i < pPort->pAdaptor->nAttributes; i++, pAtt++) 
   {    
       rep.text_size += (strlen(pAtt->name) + 1 + 3) & ~3L;
   }
 
-  rep.length = (rep.num_attributes * sz_xvAttributeInfo) + rep.text_size;
+  rep.length = (pPort->pAdaptor->nAttributes * sz_xvAttributeInfo)
+      + rep.text_size;
   rep.length >>= 2;
 
   _WriteQueryPortAttributesReply(client, &rep);
 
   for(i = 0, pAtt = pPort->pAdaptor->pAttributes; 
-      i < rep.num_attributes; i++, pAtt++) 
+      i < pPort->pAdaptor->nAttributes; i++, pAtt++) 
   {
       size = strlen(pAtt->name) + 1;  /* pass the NULL */
       Info.flags = pAtt->flags;
@@ -1211,6 +1214,7 @@ ProcXvQueryImageAttributes(ClientPtr client)
   XvPortPtr pPort;
   int *offsets;
   int *pitches;
+  int planeLength;
   REQUEST(xvQueryImageAttributesReq);
 
   REQUEST_SIZE_MATCH(xvQueryImageAttributesReq);
@@ -1250,7 +1254,7 @@ ProcXvQueryImageAttributes(ClientPtr client)
 
   rep.type = X_Reply;
   rep.sequenceNumber = client->sequence;
-  rep.length = num_planes << 1;
+  rep.length = planeLength = num_planes << 1;
   rep.num_planes = num_planes;
   rep.width = width;
   rep.height = height;
@@ -1258,8 +1262,8 @@ ProcXvQueryImageAttributes(ClientPtr client)
  
   _WriteQueryImageAttributesReply(client, &rep);
   if(client->swapped)
-    SwapLongs((CARD32*)offsets, rep.length);
-  WriteToClient(client, rep.length << 2, (char*)offsets);
+    SwapLongs((CARD32*)offsets, planeLength);
+  WriteToClient(client, planeLength << 2, (char*)offsets);
 
   xfree(offsets);
 
@@ -1287,13 +1291,13 @@ ProcXvListImageFormats(ClientPtr client)
   rep.type = X_Reply;
   rep.sequenceNumber = client->sequence;
   rep.num_formats = pPort->pAdaptor->nImages;
-  rep.length = rep.num_formats * sz_xvImageFormatInfo >> 2;
+  rep.length = pPort->pAdaptor->nImages * sz_xvImageFormatInfo >> 2;
 
   _WriteListImageFormatsReply(client, &rep);
 
   pImage = pPort->pAdaptor->pImages;
   
-  for(i = 0; i < rep.num_formats; i++, pImage++) {
+  for(i = 0; i < pPort->pAdaptor->nImages; i++, pImage++) {
      info.id = pImage->id; 	
      info.type = pImage->type; 	
      info.byte_order = pImage->byte_order; 
commit f6666dcc3b1ac60f850ea53c357a9ef61672a52a
Author: Alan Coopersmith <alan.coopersmith at sun.com>
Date:   Wed Jan 2 19:19:55 2008 -0800

    Add dixAllocatePrivate stub to dummylib for utils
    
    Normally not necessary, except when building non-optimized/debug causes
    the inline functions from private.h to appear in os-support/libxorgos.la

diff --git a/hw/xfree86/dummylib/Makefile.am b/hw/xfree86/dummylib/Makefile.am
index 3e70d25..2ab0a77 100644
--- a/hw/xfree86/dummylib/Makefile.am
+++ b/hw/xfree86/dummylib/Makefile.am
@@ -13,6 +13,7 @@ STRL_SRCS = $(top_srcdir)/os/strlcat.c $(top_srcdir)/os/strlcpy.c
 endif
 
 libdummy_nonserver_a_SOURCES = \
+	dixprivates.c \
 	fatalerror.c \
 	logvwrite.c \
 	$(STRL_SRCS) \
diff --git a/hw/xfree86/dummylib/dixprivates.c b/hw/xfree86/dummylib/dixprivates.c
new file mode 100644
index 0000000..40c173a
--- /dev/null
+++ b/hw/xfree86/dummylib/dixprivates.c
@@ -0,0 +1,19 @@
+#ifdef HAVE_XORG_CONFIG_H
+#include <xorg-config.h>
+#endif
+
+#include <X11/X.h>
+#include "os.h"
+#include "xf86.h"
+#include "xf86Priv.h"
+
+/*
+ * Utility functions required by libxf86_os. 
+ */
+
+_X_EXPORT pointer *
+dixAllocatePrivate(PrivateRec **privates, const DevPrivateKey key)
+{
+    return NULL;	/* not used */
+}
+
commit 73f422996016107d5f53492e4197bb05ed9c4bb9
Author: Alan Coopersmith <alan.coopersmith at sun.com>
Date:   Wed Jan 2 19:17:54 2008 -0800

    Fix names/types of new vuidMouse{Get,Set}ScreenPrivates macros

diff --git a/hw/xfree86/os-support/solaris/sun_mouse.c b/hw/xfree86/os-support/solaris/sun_mouse.c
index b1b7797..a5955ef 100644
--- a/hw/xfree86/os-support/solaris/sun_mouse.c
+++ b/hw/xfree86/os-support/solaris/sun_mouse.c
@@ -122,10 +122,10 @@ static void vuidMouseAdjustFrame(int index, int x, int y, int flags);
 
 static int vuidMouseGeneration = 0;
 static DevPrivateKey vuidMouseScreenKey = &vuidMouseScreenKey;
-#define vuidGetMouseScreenPrivate(s) ((VuidMsePtr) \
+#define vuidMouseGetScreenPrivate(s) ( \
     dixLookupPrivate(&(s)->devPrivates, vuidMouseScreenKey))
-#define vuidSetMouseScreenPrivate(s,p) \
-    dixSetPrivate(&(s)->devPrivates, vuidMouseScreenKey, p)
+#define vuidMouseSetScreenPrivate(s,p) \
+    dixSetPrivate(&(s)->devPrivates, vuidMouseScreenKey, (void *) p)
 #endif /* HAVE_ABSOLUTE_MOUSE_SCALING */
 
 static inline
commit 895073f6b41d9313cfe748232c492c5e9f76b443
Author: Alan Coopersmith <alan.coopersmith at sun.com>
Date:   Wed Jan 2 18:09:26 2008 -0800

    Restore include & typedef needed by dtrace
    
    996b621bec1bbc4fb21970c75eaec62053bc6ccb deleted a couple lines too many

diff --git a/dix/dispatch.c b/dix/dispatch.c
index 577e17c..004509c 100644
--- a/dix/dispatch.c
+++ b/dix/dispatch.c
@@ -149,6 +149,8 @@ int ProcInitialConnection();
 
 #ifdef XSERVER_DTRACE
 #include "registry.h"
+#include <sys/types.h>
+typedef const char *string;
 #include "Xserver-dtrace.h"
 #endif
 
commit 306fde4082044dfecbedd9af41e660bafb3ce438
Author: Brian <brian at i915.localnet.net>
Date:   Tue Jan 1 09:27:44 2008 -0700

    regenerated to add framebuffer object tokens (bug 13800)

diff --git a/GL/glx/indirect_size_get.c b/GL/glx/indirect_size_get.c
index 1a1b123..e7eaf97 100644
--- a/GL/glx/indirect_size_get.c
+++ b/GL/glx/indirect_size_get.c
@@ -613,6 +613,7 @@ __glGetBooleanv_size(GLenum e)
 /*      case GL_CLIENT_ACTIVE_TEXTURE_ARB:*/
     case GL_MAX_TEXTURE_UNITS:
 /*      case GL_MAX_TEXTURE_UNITS_ARB:*/
+    case GL_MAX_RENDERBUFFER_SIZE_EXT:
     case GL_TEXTURE_COMPRESSION_HINT:
 /*      case GL_TEXTURE_COMPRESSION_HINT_ARB:*/
     case GL_TEXTURE_RECTANGLE_ARB:
@@ -715,6 +716,10 @@ __glGetBooleanv_size(GLenum e)
     case GL_ACTIVE_STENCIL_FACE_EXT:
     case GL_TEXTURE_BINDING_1D_ARRAY_EXT:
     case GL_TEXTURE_BINDING_2D_ARRAY_EXT:
+    case GL_DRAW_FRAMEBUFFER_BINDING_EXT:
+    case GL_RENDERBUFFER_BINDING_EXT:
+    case GL_READ_FRAMEBUFFER_BINDING_EXT:
+    case GL_MAX_COLOR_ATTACHMENTS_EXT:
     case GL_RASTER_POSITION_UNCLIPPED_IBM:
         return 1;
     case GL_SMOOTH_POINT_SIZE_RANGE:
commit 5c362c2eb2cfdf1f6d667a3e64a0a7bc4942c950
Author: Brian <brian at i915.localnet.net>
Date:   Tue Jan 1 09:07:48 2008 -0700

    regenerated, adds GL_MAX_3D_TEXTURE_SIZE (see bug 13811)

diff --git a/GL/glx/indirect_size_get.c b/GL/glx/indirect_size_get.c
index f64fb7e..1a1b123 100644
--- a/GL/glx/indirect_size_get.c
+++ b/GL/glx/indirect_size_get.c
@@ -538,6 +538,7 @@ __glGetBooleanv_size(GLenum e)
     case GL_UNPACK_SKIP_IMAGES:
     case GL_UNPACK_IMAGE_HEIGHT:
     case GL_TEXTURE_3D:
+    case GL_MAX_3D_TEXTURE_SIZE:
     case GL_VERTEX_ARRAY:
     case GL_NORMAL_ARRAY:
     case GL_COLOR_ARRAY:
commit 85365ddf16e2b954d8249b380df53337420ed684
Author: Adam Jackson <ajax at redhat.com>
Date:   Fri Dec 28 17:35:54 2007 -0500

    EDID 1.4: If given a native pixel format, use it when inferring virtual.

diff --git a/hw/xfree86/common/xf86Mode.c b/hw/xfree86/common/xf86Mode.c
index 782f08b..fb899a1 100644
--- a/hw/xfree86/common/xf86Mode.c
+++ b/hw/xfree86/common/xf86Mode.c
@@ -1215,20 +1215,40 @@ inferVirtualSize(ScrnInfoPtr scrp, DisplayModePtr modes, int *vx, int *vy)
 {
     float aspect = 0.0;
     MonPtr mon = scrp->monitor;
+    xf86MonPtr DDC;
     int x = 0, y = 0;
     DisplayModePtr mode;
 
     if (!mon) return 0;
+    DDC = mon->DDC;
+
+    if (DDC && DDC->ver.revision >= 4) {
+	/* For 1.4, we might actually get native pixel format.  How novel. */
+	if (PREFERRED_TIMING_MODE(DDC->features.msc)) {
+		for (mode = modes; mode; mode = mode->next) {
+		    if (mode->type & (M_T_DRIVER | M_T_PREFERRED)) {
+			x = mode->HDisplay;
+			y = mode->VDisplay;
+			goto found;
+		    }
+		}
+	}
+	/*
+	 * Even if we don't, we might get aspect ratio from extra CVT info
+	 * or from the monitor size fields.  TODO.
+	 */
+    }
 
     /*
-     * technically this triggers if _either_ is zero, which is not what EDID
-     * says, but if only one is zero this is best effort.  also we don't
-     * know that all projectors are 4:3, but we certainly suspect it.
+     * Technically this triggers if either is zero.  That wasn't legal
+     * before EDID 1.4, but right now we'll get that wrong. TODO.
      */
-    if (!mon->widthmm || !mon->heightmm)
-	aspect = 4.0/3.0;
-    else
-	aspect = (float)mon->widthmm / (float)mon->heightmm;
+    if (!aspect) {
+	if (!mon->widthmm || !mon->heightmm)
+	    aspect = 4.0/3.0;
+	else
+	    aspect = (float)mon->widthmm / (float)mon->heightmm;
+    }
 
     /* find the largest M_T_DRIVER mode with that aspect ratio */
     for (mode = modes; mode; mode = mode->next) {
@@ -1252,6 +1272,7 @@ inferVirtualSize(ScrnInfoPtr scrp, DisplayModePtr modes, int *vx, int *vy)
 	return 0;
     }
 
+found:
     *vx = x;
     *vy = y;
 
commit 312b30cb03e439644ea10e08fa93268116333f0d
Author: Adam Jackson <ajax at redhat.com>
Date:   Fri Dec 28 17:18:30 2007 -0500

    EDID 1.4: First detailed mode is always preferred.
    
    ... so act like it in the modelist generator, not just the parser.

diff --git a/hw/xfree86/modes/xf86EdidModes.c b/hw/xfree86/modes/xf86EdidModes.c
index d8c6161..87a8127 100644
--- a/hw/xfree86/modes/xf86EdidModes.c
+++ b/hw/xfree86/modes/xf86EdidModes.c
@@ -534,6 +534,8 @@ xf86DDCGetModes(int scrnIndex, xf86MonPtr DDC)
     quirks = xf86DDCDetectQuirks(scrnIndex, DDC, TRUE);
 
     preferred = PREFERRED_TIMING_MODE(DDC->features.msc);
+    if (DDC->ver.revision >= 4)
+	preferred = TRUE;
     if (quirks & DDC_QUIRK_FIRST_DETAILED_PREFERRED)
 	preferred = TRUE;
     if (quirks & (DDC_QUIRK_PREFER_LARGE_60 | DDC_QUIRK_PREFER_LARGE_75))
commit 9dbb73033ae60e7ab85f1469a696e2a52f0cb0fe
Author: Colin Harrison <colin.harrison at virgin.net>
Date:   Sat Dec 29 00:02:16 2007 +0200

    Rootless: Fix lvalue error from devPrivates change
    
    Instead of trying to use an invalid expression as an lvalue, use the function
    call instead.

diff --git a/miext/rootless/accel/rlAccel.c b/miext/rootless/accel/rlAccel.c
index a144124..f3cb215 100644
--- a/miext/rootless/accel/rlAccel.c
+++ b/miext/rootless/accel/rlAccel.c
@@ -51,6 +51,9 @@ static DevPrivateKey rlAccelScreenPrivateKey = &rlAccelScreenPrivateKey;
 #define RLACCELREC(pScreen) ((rlAccelScreenRec *) \
     dixLookupPrivate(&(pScreen)->devPrivates, rlAccelScreenPrivateKey))
 
+#define SETRLACCELREC(pScreen, v) \
+    dixSetPrivate(&(pScreen)->devPrivates, rlAccelScreenPrivateKey, v)
+
 /* This is mostly identical to fbGCOps. */
 static GCOps rlAccelOps = {
     rlFillSpans,
@@ -132,7 +135,7 @@ RootlessAccelInit(ScreenPtr pScreen)
 
     s = xalloc(sizeof(rlAccelScreenRec));
     if (!s) return FALSE;
-    RLACCELREC(pScreen) = s;
+    SETRLACCELREC(pScreen, s);
 
     // Wrap the screen functions we need
     s->CreateGC = pScreen->CreateGC;
commit 36ff05771b0699aa80ad718e24097bc25cb4fb00
Author: Jurij Smakov <jurij at wooyd.org>
Date:   Fri Dec 28 23:59:53 2007 +0200

    GL: Add GLX compile flags lost in modular X server changes
    
    RISC chips that trap on unaligned loads and stores need to
    define __GLX_ALIGN64.  This used to get added to the cflags
    in the old *.cf files but it no longer does in the modular
    X server.
    
    Also, Alpha needs to pass -mieee to the compiler as well.
    
    This is a simple backport of a patch that debian, and probably other
    distributions, have been applying forever.  To the best of my
    knowledge the patch was written by Jurij Smakov.  See Debian bug
    number #388125.
    
    I just checked and this has been rotting for more than a year in
    freedesktop bugzilla as #8392.
    
    Signed-off-by: David S. Miller <davem at davemloft.net>

diff --git a/GL/glx/Makefile.am b/GL/glx/Makefile.am
index 8eda153..4cf56e8 100644
--- a/GL/glx/Makefile.am
+++ b/GL/glx/Makefile.am
@@ -14,7 +14,8 @@ AM_CFLAGS = \
 	-I at MESA_SOURCE@/src/mesa/glapi \
 	-I at MESA_SOURCE@/src/mesa/main \
 	-DXFree86Server \
-	@GLX_DEFINES@
+	@GLX_DEFINES@ \
+	@GLX_ARCH_DEFINES@
 
 # none yet
 #sdk_HEADERS =
diff --git a/configure.ac b/configure.ac
index 0b718c9..0742040 100644
--- a/configure.ac
+++ b/configure.ac
@@ -304,6 +304,7 @@ case $host_cpu in
 	        *freebsd*)	SYS_LIBS=-lio ;;
 		*netbsd*)	AC_DEFINE(USE_ALPHA_PIO, 1, [NetBSD PIO alpha IO]) ;;
 	esac
+	GLX_ARCH_DEFINES="-D__GLX_ALIGN64 -mieee"
 	;;
   arm*)
 	ARM_VIDEO=yes
@@ -333,6 +334,7 @@ case $host_cpu in
 	xorg_loader_sparcmuldiv="yes"
 	SPARC64_VIDEO=yes
 	BSD_ARCH_SOURCES="sparc64_video.c ioperm_noop.c"
+	GLX_ARCH_DEFINES="-D__GLX_ALIGN64"
 	;;
   x86_64*|amd64*)
   	use_x86_asm="yes"
@@ -347,8 +349,16 @@ case $host_cpu in
 				SYS_LIBS=-lamd64
 				;;
 	esac
+	GLX_ARCH_DEFINES="-D__GLX_ALIGN64"
+	;;
+  ia64*)
+  	GLX_ARCH_DEFINES="-D__GLX_ALIGN64"
+	;;
+  s390*)
+  	GLX_ARCH_DEFINES="-D__GLX_ALIGN64"
 	;;
 esac
+AC_SUBST(GLX_ARCH_DEFINES)
 
 dnl BSD *_video.c selection
 AM_CONDITIONAL(ALPHA_VIDEO, [test "x$ALPHA_VIDEO" = xyes])
diff --git a/hw/dmx/glxProxy/Makefile.am b/hw/dmx/glxProxy/Makefile.am
index 1fbc8d7..f995498 100644
--- a/hw/dmx/glxProxy/Makefile.am
+++ b/hw/dmx/glxProxy/Makefile.am
@@ -32,6 +32,7 @@ libglxproxy_a_SOURCES = compsize.c \
                         unpack.h
 
 AM_CFLAGS = \
+            @GLX_ARCH_DEFINES@ \
             $(DIX_CFLAGS) \
             -I$(top_srcdir)/hw/dmx \
             -I$(top_srcdir)/include \
commit bae459cfc4f17a5ec5f2810e9f913e3ad2d8b8d4
Author: Adam Jackson <ajax at redhat.com>
Date:   Fri Dec 28 16:50:18 2007 -0500

    Don't carp on EDID 1.4 blocks anymore.
    
    Also whine more loudly when we get something other than 1.x.

diff --git a/hw/xfree86/ddc/interpret_edid.c b/hw/xfree86/ddc/interpret_edid.c
index 045c12d..14b0fd7 100644
--- a/hw/xfree86/ddc/interpret_edid.c
+++ b/hw/xfree86/ddc/interpret_edid.c
@@ -369,13 +369,16 @@ get_detailed_timing_section(Uchar *c, struct detailed_timings *r)
   r->misc = MISC;
 }
 
-#define MAX_EDID_MINOR 3
+#define MAX_EDID_MINOR 4
 
 static Bool
 validate_version(int scrnIndex, struct edid_version *r)
 {
-    if (r->version != 1)
+    if (r->version != 1) {
+	xf86DrvMsg(scrnIndex, X_ERROR, "Unknown EDID version %d\n",
+		   r->version);
 	return FALSE;
+    }
 
     if (r->revision > MAX_EDID_MINOR)
 	xf86DrvMsg(scrnIndex, X_WARNING,
commit 70b2d6cfeb3bcb7b862a2ae29f6ef7cb84d69486
Author: Adam Jackson <ajax at redhat.com>
Date:   Fri Dec 28 16:39:00 2007 -0500

    Check the gamma value, not its address.

diff --git a/hw/xfree86/ddc/print_edid.c b/hw/xfree86/ddc/print_edid.c
index a55c465..d9f18fa 100644
--- a/hw/xfree86/ddc/print_edid.c
+++ b/hw/xfree86/ddc/print_edid.c
@@ -211,7 +211,7 @@ print_display(int scrnIndex, struct disp_features *disp,
 	xf86DrvMsg(scrnIndex, X_INFO, "Indeterminate output size\n");
     }
 
-    if (!gamma && v->revision >= 1.4)
+    if (!disp->gamma && v->revision >= 1.4)
 	xf86DrvMsg(scrnIndex, X_INFO, "Gamma defined in extension block\n");
     else
 	xf86DrvMsg(scrnIndex, X_INFO, "Gamma: %.2f\n", disp->gamma);
commit 592d814ee09e86e283116a7a1052762c8398e8e5
Author: Adam Jackson <ajax at redhat.com>
Date:   Fri Dec 28 16:37:23 2007 -0500

    EDID 1.4: Additional semantics for display feature bits.
    
    First mode is _always_ preferred in 1.4; the bit that used to mean this
    now means that the preferred mode is also the native pixel format.  The
    old "is GTF" bit now means "is continuous-frequency" instead.
    
    Section 3.6.4, Table 3.14: Feature Support, Notes 4 and 5.

diff --git a/hw/xfree86/ddc/print_edid.c b/hw/xfree86/ddc/print_edid.c
index 30cd175..a55c465 100644
--- a/hw/xfree86/ddc/print_edid.c
+++ b/hw/xfree86/ddc/print_edid.c
@@ -154,16 +154,27 @@ print_dpms_features(int scrnIndex, struct disp_features *c,
     if (STD_COLOR_SPACE(c->msc))
 	xf86DrvMsg(scrnIndex,X_INFO,
 		   "Default color space is primary color space\n"); 
-    if (PREFERRED_TIMING_MODE(c->msc))
-	xf86DrvMsg(scrnIndex,X_INFO,
+
+    if (PREFERRED_TIMING_MODE(c->msc) || v->revision >= 4) {
+	xf86DrvMsg(scrnIndex, X_INFO,
 		   "First detailed timing is preferred mode\n"); 
-    else if (v->version == 1 && v->revision >= 3)
+	if (v->revision >= 4)
+	    xf86DrvMsg(scrnIndex, X_INFO,
+		"Preferred mode is native pixel format and refresh rate\n");
+    } else if (v->revision == 3) {
 	xf86DrvMsg(scrnIndex,X_INFO,
 		   "First detailed timing not preferred "
 		   "mode in violation of standard!");
-    if (GFT_SUPPORTED(c->msc))
-	xf86DrvMsg(scrnIndex,X_INFO,
-		   "GTF timings supported\n"); 
+    }
+
+    if (v->revision >= 4) {
+	if (GFT_SUPPORTED(c->msc)) {
+	    xf86DrvMsg(scrnIndex, X_INFO, "Display is continuous-frequency\n");
+	}
+    } else {
+	if (GFT_SUPPORTED(c->msc))
+	    xf86DrvMsg(scrnIndex, X_INFO, "GTF timings supported\n"); 
+    }
 }
   
 static void 
commit 322d0103aee317500057c80d542d7270d69a5731
Author: Adam Jackson <ajax at redhat.com>
Date:   Fri Dec 28 16:28:44 2007 -0500

    EDID 1.4: Alternate color encodings for digital inputs.
    
    Section 3.6.4, Table 3.14: Feature support.

diff --git a/hw/xfree86/ddc/edid.h b/hw/xfree86/ddc/edid.h
index 198794e..2496e19 100644
--- a/hw/xfree86/ddc/edid.h
+++ b/hw/xfree86/ddc/edid.h
@@ -326,11 +326,15 @@
 #define DPMS_SUSPEND(x) (x & 0x02)
 #define DPMS_OFF(x) (x & 0x01)
 
-/* display type */
+/* display type, analog */
 #define DISP_MONO 0
 #define DISP_RGB 1
 #define DISP_MULTCOLOR 2
 
+/* display color encodings, digital */
+#define DISP_YCRCB444 0x01
+#define DISP_YCRCB422 0x02
+
 /* Msc stuff EDID Ver > 1.1 */
 #define STD_COLOR_SPACE(x) (x & 0x4)
 #define PREFERRED_TIMING_MODE(x) (x & 0x2)
diff --git a/hw/xfree86/ddc/print_edid.c b/hw/xfree86/ddc/print_edid.c
index 880ca07..30cd175 100644
--- a/hw/xfree86/ddc/print_edid.c
+++ b/hw/xfree86/ddc/print_edid.c
@@ -128,20 +128,29 @@ print_dpms_features(int scrnIndex, struct disp_features *c,
 	 if (DPMS_OFF(c->dpms)) xf86ErrorF(" Off");
      } else 
 	 xf86DrvMsg(scrnIndex,X_INFO,"No DPMS capabilities specified");
-    switch (c->display_type){
-    case DISP_MONO:
-	xf86ErrorF("; Monochorome/GrayScale Display\n");
-	break;
-    case DISP_RGB:
-	xf86ErrorF("; RGB/Color Display\n");
-	break;
-    case DISP_MULTCOLOR:
-	xf86ErrorF("; Non RGB Multicolor Display\n");
-	break;
-    default:
-	xf86ErrorF("\n");
-	break;
+    if (!c->input_type) { /* analog */
+	switch (c->display_type){
+	    case DISP_MONO:
+		xf86ErrorF("; Monochorome/GrayScale Display\n");
+		break;
+	    case DISP_RGB:
+		xf86ErrorF("; RGB/Color Display\n");
+		break;
+	    case DISP_MULTCOLOR:
+		xf86ErrorF("; Non RGB Multicolor Display\n");
+		break;
+	    default:
+		xf86ErrorF("\n");
+		break;
+	}
+    } else {
+	int enc = c->display_type;
+	xf86DrvMsg(scrnIndex, X_INFO, "\nSupported color encodings: "
+		   "RGB 4:4:4 %s%s\n",
+		   enc & DISP_YCRCB444 ? "YCrCb 4:4:4 " : "",
+		   enc & DISP_YCRCB422 ? "YCrCb 4:2:2" : "");
     }
+
     if (STD_COLOR_SPACE(c->msc))
 	xf86DrvMsg(scrnIndex,X_INFO,
 		   "Default color space is primary color space\n"); 
commit f1f43caf7e26a84dbacd4e5d7d47c8b4e4982836
Author: Adam Jackson <ajax at redhat.com>
Date:   Fri Dec 28 16:12:11 2007 -0500

    EDID 1.4: Allow for gamma definition in extension blocks.
    
    Section 3.6.3, Table 3.13: Display Transfer Characteristics (Gamma)

diff --git a/hw/xfree86/ddc/edid.h b/hw/xfree86/ddc/edid.h
index 25163a6..198794e 100644
--- a/hw/xfree86/ddc/edid.h
+++ b/hw/xfree86/ddc/edid.h
@@ -129,7 +129,7 @@
 #define BPC _BPC(GET(D_INPUT))
 #define _DIGITAL_INTERFACE(x) (x & 0x0F)
 #define DIGITAL_INTERFACE _DIGITAL_INTERFACE(GET(D_INPUT))
-#define _GAMMA(x) (x == 0xff ? 1.0 : ((x + 100.0)/100.0))
+#define _GAMMA(x) (x == 0xff ? 0.0 : ((x + 100.0)/100.0))
 #define GAMMA _GAMMA(GET(D_GAMMA))
 #define HSIZE_MAX GET(D_HSIZE)
 #define VSIZE_MAX GET(D_VSIZE)
diff --git a/hw/xfree86/ddc/print_edid.c b/hw/xfree86/ddc/print_edid.c
index 59d414f..880ca07 100644
--- a/hw/xfree86/ddc/print_edid.c
+++ b/hw/xfree86/ddc/print_edid.c
@@ -191,7 +191,11 @@ print_display(int scrnIndex, struct disp_features *disp,
 	xf86DrvMsg(scrnIndex, X_INFO, "Indeterminate output size\n");
     }
 
-    xf86DrvMsg(scrnIndex, X_INFO, "Gamma: %.2f\n", disp->gamma);
+    if (!gamma && v->revision >= 1.4)
+	xf86DrvMsg(scrnIndex, X_INFO, "Gamma defined in extension block\n");
+    else
+	xf86DrvMsg(scrnIndex, X_INFO, "Gamma: %.2f\n", disp->gamma);
+
     print_dpms_features(scrnIndex, disp, v);
     print_whitepoint(scrnIndex, disp);
 }
commit 861ee38817523a647e6be10d7e8fe26f66054217
Author: Adam Jackson <ajax at redhat.com>
Date:   Fri Dec 28 16:06:45 2007 -0500

    EDID 1.4: Additional aspect ratio semantics for screen size fields.
    
    Section 3.6.2, Table 3.12: Horizontal and Vertical Screen Size or
    Aspect Ratio.

diff --git a/hw/xfree86/ddc/print_edid.c b/hw/xfree86/ddc/print_edid.c
index 9bd7ebc..59d414f 100644
--- a/hw/xfree86/ddc/print_edid.c
+++ b/hw/xfree86/ddc/print_edid.c
@@ -172,21 +172,28 @@ print_whitepoint(int scrnIndex, struct disp_features *disp)
 
 static void
 print_display(int scrnIndex, struct disp_features *disp,
-	      struct edid_version *version)
+	      struct edid_version *v)
 {
-    print_input_features(scrnIndex, disp, version);
-    xf86DrvMsg(scrnIndex,X_INFO,"Max H-Image Size [cm]: ");
-    if (disp->hsize)
-	xf86ErrorF("horiz.: %i  ",disp->hsize);
-    else
-	xf86ErrorF("H-Size may change,  ");
-    if (disp->vsize)
-	xf86ErrorF("vert.: %i\n",disp->vsize);
-      else
-	xf86ErrorF("V-Size may change\n");
-    xf86DrvMsg(scrnIndex,X_INFO,"Gamma: %.2f\n", disp->gamma);
-    print_dpms_features(scrnIndex,disp,version);
-    print_whitepoint(scrnIndex,disp);
+    print_input_features(scrnIndex, disp, v);
+    if (disp->hsize && disp->vsize) {
+	xf86DrvMsg(scrnIndex, X_INFO, "Max Image Size [cm]: ");
+	xf86ErrorF("horiz.: %i  ", disp->hsize);
+	xf86ErrorF("vert.: %i\n", disp->vsize);
+    } else if (v->revision >= 4 && (disp->hsize || disp->vsize)) {
+	if (disp->hsize)
+	    xf86DrvMsg(scrnIndex, X_INFO, "Aspect ratio: %.2f (landscape)\n",
+		       (disp->hsize + 99) / 100.0);
+	if (disp->vsize)
+	    xf86DrvMsg(scrnIndex, X_INFO, "Aspect ratio: %.2f (portrait)\n",
+		       100.0 / (float)(disp->vsize + 99));
+
+    } else {
+	xf86DrvMsg(scrnIndex, X_INFO, "Indeterminate output size\n");
+    }
+
+    xf86DrvMsg(scrnIndex, X_INFO, "Gamma: %.2f\n", disp->gamma);
+    print_dpms_features(scrnIndex, disp, v);
+    print_whitepoint(scrnIndex, disp);
 }
 
 static void 
commit 14b5c8a447db0395fb14b2d404eafb1d8e4fb817
Author: Adam Jackson <ajax at redhat.com>
Date:   Fri Dec 28 15:52:42 2007 -0500

    EDID 1.4: Extended support for digital interfaces.
    
    Section 3.6.1, Table 3.11: Video Input Definition.

diff --git a/hw/xfree86/ddc/edid.h b/hw/xfree86/ddc/edid.h
index 6708eaa..25163a6 100644
--- a/hw/xfree86/ddc/edid.h
+++ b/hw/xfree86/ddc/edid.h
@@ -125,6 +125,10 @@
 #define SYNC _SYNC(GET(D_INPUT))
 #define _DFP(x) (x & 0x01)
 #define DFP _DFP(GET(D_INPUT))
+#define _BPC(x) ((x & 0x70) >> 4)
+#define BPC _BPC(GET(D_INPUT))
+#define _DIGITAL_INTERFACE(x) (x & 0x0F)
+#define DIGITAL_INTERFACE _DIGITAL_INTERFACE(GET(D_INPUT))
 #define _GAMMA(x) (x == 0xff ? 1.0 : ((x + 100.0)/100.0))
 #define GAMMA _GAMMA(GET(D_GAMMA))
 #define HSIZE_MAX GET(D_HSIZE)
@@ -364,6 +368,9 @@ struct disp_features {
   unsigned int input_setup:1;
   unsigned int input_sync:5;
   unsigned int input_dfp:1;
+  unsigned int input_bpc:3;
+  unsigned int input_interface:4;
+  /* 15 bit hole */
   int hsize;
   int vsize;
   float gamma;
diff --git a/hw/xfree86/ddc/interpret_edid.c b/hw/xfree86/ddc/interpret_edid.c
index 982a502..045c12d 100644
--- a/hw/xfree86/ddc/interpret_edid.c
+++ b/hw/xfree86/ddc/interpret_edid.c
@@ -148,8 +148,12 @@ get_display_section(Uchar *c, struct disp_features *r,
 	r->input_voltage = INPUT_VOLTAGE;
 	r->input_setup = SETUP;
 	r->input_sync = SYNC;
-    } else if (v->version > 1 || v->revision > 2)
+    } else if (v->revision == 2 || v->revision == 3) {
 	r->input_dfp = DFP;
+    } else if (v->revision >= 4) {
+	r->input_bpc = BPC;
+	r->input_interface = DIGITAL_INTERFACE;
+    }
     r->hsize = HSIZE_MAX;
     r->vsize = VSIZE_MAX;
     r->gamma = GAMMA;
diff --git a/hw/xfree86/ddc/print_edid.c b/hw/xfree86/ddc/print_edid.c
index 5aebc6e..9bd7ebc 100644
--- a/hw/xfree86/ddc/print_edid.c
+++ b/hw/xfree86/ddc/print_edid.c
@@ -1,8 +1,28 @@
-
-/* print_edid.c: print out all information retrieved from display device 
- * 
+/*
  * Copyright 1998 by Egbert Eich <Egbert.Eich at Physik.TU-Darmstadt.DE>
+ * Copyright 2007 Red Hat, Inc.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software")
+ * to deal in the software without restriction, including without limitation
+ * on the rights to use, copy, modify, merge, publish, distribute, sub
+ * license, and/or sell copies of the Software, and to permit persons to whom
+ * them Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the next
+ * paragraph) shall be included in all copies or substantial portions of the
+ * Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTIBILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.  IN NO EVENT SHALL
+ * THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES, OR OTHER LIABILITY, WHETHER
+ * IN AN ACTION OF CONTRACT, TORT, OR OTHERWISE, ARISING FROM, OUT OF OR IN
+ * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ *
+ * print_edid.c: print out all information retrieved from display device  
  */
+
 #ifdef HAVE_XORG_CONFIG_H
 #include <xorg-config.h>
 #endif
@@ -11,53 +31,9 @@
 #include "xf86.h"
 #include "xf86_OSproc.h"
 #include "xf86DDC.h"
+#include "edid.h"
   
-static void print_vendor(int scrnIndex, struct vendor *);
-static void print_version(int scrnIndex, struct edid_version *);
-static void print_display(int scrnIndex, struct disp_features *,
-			  struct edid_version *);
-static void print_established_timings(int scrnIndex,
-				      struct established_timings *);
-static void print_std_timings(int scrnIndex, struct std_timings *);
-static void print_detailed_monitor_section(int scrnIndex,
-					   struct detailed_monitor_section *);
-static void print_detailed_timings(int scrnIndex, struct detailed_timings *);
-
-static void print_input_features(int scrnIndex, struct disp_features *);
-static void print_dpms_features(int scrnIndex, struct disp_features *,
-				struct edid_version *v);
-static void print_whitepoint(int scrnIndex, struct disp_features *);
-static void print_number_sections(int scrnIndex, int);
-
 #define EDID_WIDTH	16
-
-xf86MonPtr
-xf86PrintEDID(xf86MonPtr m)
-{
-    CARD16 i, j;
-    char buf[EDID_WIDTH * 2 + 1];
-
-    if (!(m)) return NULL;
-
-    print_vendor(m->scrnIndex,&m->vendor);
-    print_version(m->scrnIndex,&m->ver);
-    print_display(m->scrnIndex,&m->features, &m->ver);
-    print_established_timings(m->scrnIndex,&m->timings1);
-    print_std_timings(m->scrnIndex,m->timings2);
-    print_detailed_monitor_section(m->scrnIndex,m->det_mon);
-    print_number_sections(m->scrnIndex,m->no_sections);
-
-    xf86DrvMsg(m->scrnIndex, X_INFO, "EDID (in hex):\n");
- 
-    for (i = 0; i < 128; i += j) {
-	for (j = 0; j < EDID_WIDTH; ++j) {
-	    sprintf(&buf[j * 2], "%02x", m->rawData[i + j]);
-	}
-	xf86DrvMsg(m->scrnIndex, X_INFO, "\t%s\n", buf);
-    }
-    
-    return m;
-}
   
 static void
 print_vendor(int scrnIndex, struct vendor *c)
@@ -66,7 +42,7 @@ print_vendor(int scrnIndex, struct vendor *c)
 	(char *)&c->name, c->prod_id, c->serial);
     xf86DrvMsg(scrnIndex, X_INFO, "Year: %u  Week: %u\n", c->year, c->week);
 }
-  
+
 static void
 print_version(int scrnIndex, struct edid_version *c)
 {
@@ -74,32 +50,38 @@ print_version(int scrnIndex, struct edid_version *c)
 	       c->revision);  
 }
   
-static void
-print_display(int scrnIndex, struct disp_features *disp,
-	      struct edid_version *version)
-{
-    print_input_features(scrnIndex,disp);
-    xf86DrvMsg(scrnIndex,X_INFO,"Max H-Image Size [cm]: ");
-    if (disp->hsize)
-	xf86ErrorF("horiz.: %i  ",disp->hsize);
-    else
-	xf86ErrorF("H-Size may change,  ");
-    if (disp->vsize)
-	xf86ErrorF("vert.: %i\n",disp->vsize);
-      else
-	xf86ErrorF("V-Size may change\n");
-    xf86DrvMsg(scrnIndex,X_INFO,"Gamma: %.2f\n", disp->gamma);
-    print_dpms_features(scrnIndex,disp,version);
-    print_whitepoint(scrnIndex,disp);
-}
-  
+static const char *digital_interfaces[] = {
+    "undefined",
+    "DVI",
+    "HDMI-a",
+    "HDMI-b",
+    "MDDI",
+    "DisplayPort",
+    "unknown"
+};
+
 static void 
-print_input_features(int scrnIndex, struct disp_features *c)
+print_input_features(int scrnIndex, struct disp_features *c,
+		     struct edid_version *v)
 {
     if (DIGITAL(c->input_type)) {
-	xf86DrvMsg(scrnIndex,X_INFO,"Digital Display Input\n");
-	if (DFP1(c->input_dfp))
-	    xf86DrvMsg(scrnIndex,X_INFO,"DFP 1.x compatible TMDS\n");
+	xf86DrvMsg(scrnIndex, X_INFO, "Digital Display Input\n");
+	if (v->revision == 2 || v->revision == 3) {
+	    if (DFP1(c->input_dfp))
+		xf86DrvMsg(scrnIndex, X_INFO, "DFP 1.x compatible TMDS\n");
+	} else if (v->revision >= 4) {
+	    int interface = c->input_interface;
+	    int bpc = c->input_bpc;
+	    if (interface > 6)
+		interface = 6; /* unknown */
+	    if (bpc == 0 || bpc == 7)
+		xf86DrvMsg(scrnIndex, X_INFO, "Undefined color depth\n");
+	    else
+		xf86DrvMsg(scrnIndex, X_INFO, "%d bits per channel\n",
+			   bpc * 2 + 4);
+	    xf86DrvMsg(scrnIndex, X_INFO, "Digital interface is %s\n",
+		       digital_interfaces[interface]);
+	}
     } else {
 	xf86DrvMsg(scrnIndex,X_INFO,"Analog Display Input,  ");
 	xf86ErrorF("Input Voltage Level: ");
@@ -187,7 +169,26 @@ print_whitepoint(int scrnIndex, struct disp_features *disp)
     xf86ErrorF("whiteX: %.3f whiteY: %.3f\n",
 	       disp->whitex,disp->whitey);
 }
-  
+
+static void
+print_display(int scrnIndex, struct disp_features *disp,
+	      struct edid_version *version)
+{
+    print_input_features(scrnIndex, disp, version);
+    xf86DrvMsg(scrnIndex,X_INFO,"Max H-Image Size [cm]: ");
+    if (disp->hsize)
+	xf86ErrorF("horiz.: %i  ",disp->hsize);
+    else
+	xf86ErrorF("H-Size may change,  ");
+    if (disp->vsize)
+	xf86ErrorF("vert.: %i\n",disp->vsize);
+      else
+	xf86ErrorF("V-Size may change\n");
+    xf86DrvMsg(scrnIndex,X_INFO,"Gamma: %.2f\n", disp->gamma);
+    print_dpms_features(scrnIndex,disp,version);
+    print_whitepoint(scrnIndex,disp);
+}
+
 static void 
 print_established_timings(int scrnIndex, struct established_timings *t)
 {
@@ -253,7 +254,50 @@ print_cvt_timings(int si, struct cvt_timings *t)
 	} else break;
     }
 }
-  
+
+static void
+print_detailed_timings(int scrnIndex, struct detailed_timings *t)
+{
+
+    if (t->clock > 15000000) {  /* sanity check */
+	xf86DrvMsg(scrnIndex,X_INFO,"Supported additional Video Mode:\n");
+	xf86DrvMsg(scrnIndex,X_INFO,"clock: %.1f MHz   ",t->clock/1000000.0);
+	xf86ErrorF("Image Size:  %i x %i mm\n",t->h_size,t->v_size); 
+	xf86DrvMsg(scrnIndex,X_INFO,
+		   "h_active: %i  h_sync: %i  h_sync_end %i h_blank_end %i ",
+		   t->h_active, t->h_sync_off + t->h_active,
+		   t->h_sync_off + t->h_sync_width + t->h_active,
+		   t->h_active + t->h_blanking);
+	xf86ErrorF("h_border: %i\n",t->h_border);
+	xf86DrvMsg(scrnIndex,X_INFO,
+		   "v_active: %i  v_sync: %i  v_sync_end %i v_blanking: %i ",
+		   t->v_active, t->v_sync_off + t->v_active,
+		   t->v_sync_off + t->v_sync_width + t->v_active,
+		   t->v_active + t->v_blanking);
+	xf86ErrorF("v_border: %i\n",t->v_border);
+	if (IS_STEREO(t->stereo)) {
+	    xf86DrvMsg(scrnIndex,X_INFO,"Stereo: ");
+	    if (IS_RIGHT_STEREO(t->stereo)) {
+		if (!t->stereo_1)
+		    xf86ErrorF("right channel on sync\n");
+		else
+		    xf86ErrorF("left channel on sync\n");
+	    } else if (IS_LEFT_STEREO(t->stereo)) {
+		if (!t->stereo_1)
+		    xf86ErrorF("right channel on even line\n");
+		else 
+		    xf86ErrorF("left channel on evel line\n");
+	    }
+	    if (IS_4WAY_STEREO(t->stereo)) {
+		if (!t->stereo_1)
+		    xf86ErrorF("4-way interleaved\n");
+		else
+		    xf86ErrorF("side-by-side interleaved");
+	    }
+	}
+    }
+}
+
 static void
 print_detailed_monitor_section(int scrnIndex,
 			       struct detailed_monitor_section *m)
@@ -334,49 +378,6 @@ print_detailed_monitor_section(int scrnIndex,
 }
   
 static void
-print_detailed_timings(int scrnIndex, struct detailed_timings *t)
-{
-
-    if (t->clock > 15000000) {  /* sanity check */
-	xf86DrvMsg(scrnIndex,X_INFO,"Supported additional Video Mode:\n");
-	xf86DrvMsg(scrnIndex,X_INFO,"clock: %.1f MHz   ",t->clock/1000000.0);
-	xf86ErrorF("Image Size:  %i x %i mm\n",t->h_size,t->v_size); 
-	xf86DrvMsg(scrnIndex,X_INFO,
-		   "h_active: %i  h_sync: %i  h_sync_end %i h_blank_end %i ",
-		   t->h_active, t->h_sync_off + t->h_active,
-		   t->h_sync_off + t->h_sync_width + t->h_active,
-		   t->h_active + t->h_blanking);
-	xf86ErrorF("h_border: %i\n",t->h_border);
-	xf86DrvMsg(scrnIndex,X_INFO,
-		   "v_active: %i  v_sync: %i  v_sync_end %i v_blanking: %i ",
-		   t->v_active, t->v_sync_off + t->v_active,
-		   t->v_sync_off + t->v_sync_width + t->v_active,
-		   t->v_active + t->v_blanking);
-	xf86ErrorF("v_border: %i\n",t->v_border);
-	if (IS_STEREO(t->stereo)) {
-	    xf86DrvMsg(scrnIndex,X_INFO,"Stereo: ");
-	    if (IS_RIGHT_STEREO(t->stereo)) {
-		if (!t->stereo_1)
-		    xf86ErrorF("right channel on sync\n");
-		else
-		    xf86ErrorF("left channel on sync\n");
-	    } else if (IS_LEFT_STEREO(t->stereo)) {
-		if (!t->stereo_1)
-		    xf86ErrorF("right channel on even line\n");
-		else 
-		    xf86ErrorF("left channel on evel line\n");
-	    }
-	    if (IS_4WAY_STEREO(t->stereo)) {
-		if (!t->stereo_1)
-		    xf86ErrorF("4-way interleaved\n");
-		else
-		    xf86ErrorF("side-by-side interleaved");
-	    }
-	}
-    }
-}
-
-static void
 print_number_sections(int scrnIndex, int num)
 {
     if (num)
@@ -384,3 +385,30 @@ print_number_sections(int scrnIndex, int num)
 		   num);
 }
 
+xf86MonPtr
+xf86PrintEDID(xf86MonPtr m)
+{
+    CARD16 i, j;
+    char buf[EDID_WIDTH * 2 + 1];
+
+    if (!(m)) return NULL;
+
+    print_vendor(m->scrnIndex,&m->vendor);
+    print_version(m->scrnIndex,&m->ver);
+    print_display(m->scrnIndex,&m->features, &m->ver);
+    print_established_timings(m->scrnIndex,&m->timings1);
+    print_std_timings(m->scrnIndex,m->timings2);
+    print_detailed_monitor_section(m->scrnIndex,m->det_mon);
+    print_number_sections(m->scrnIndex,m->no_sections);
+
+    xf86DrvMsg(m->scrnIndex, X_INFO, "EDID (in hex):\n");
+ 
+    for (i = 0; i < 128; i += j) {
+	for (j = 0; j < EDID_WIDTH; ++j) {
+	    sprintf(&buf[j * 2], "%02x", m->rawData[i + j]);
+	}
+	xf86DrvMsg(m->scrnIndex, X_INFO, "\t%s\n", buf);
+    }
+    
+    return m;
+}
commit a948216dccb5ee577a50a42035dc9bc49d0a00c6
Author: Adam Jackson <ajax at redhat.com>
Date:   Fri Dec 28 15:00:41 2007 -0500

    EDID 1.4: Decode CVT 3-byte codes and add them to the mode pool.
    
    Section 3.10.3.8: CVT 3 Byte Code Descriptor Definition.

diff --git a/hw/xfree86/ddc/edid.h b/hw/xfree86/ddc/edid.h
index 2e3e7df..6708eaa 100644
--- a/hw/xfree86/ddc/edid.h
+++ b/hw/xfree86/ddc/edid.h
@@ -449,17 +449,33 @@ struct whitePoints{
   float white_gamma;
 };
 
+struct cvt_timings {
+    int width;
+    int height;
+    int rate;
+    int rates;
+};
+
+/*
+ * Be careful when adding new sections; this structure can't grow, it's
+ * embedded in the middle of xf86Monitor which is ABI.  Sizes below are
+ * in bytes, for ILP32 systems.  If all else fails just copy the section
+ * literally like serial and friends.
+ */
 struct detailed_monitor_section {
   int type;
   union {
-    struct detailed_timings d_timings;
+    struct detailed_timings d_timings;	/* 56 */
     Uchar serial[13];
     Uchar ascii_data[13];
     Uchar name[13];
-    struct monitor_ranges ranges;
-    struct std_timings std_t[5];
-    struct whitePoints wp[2];
-  } section;
+    struct monitor_ranges ranges;	/* 40 */
+    struct std_timings std_t[5];	/* 80 */
+    struct whitePoints wp[2];		/* 32 */
+    /* color management data */
+    struct cvt_timings cvt[4];		/* 64 */
+    /* established timings III */
+  } section;				/* max: 80 */
 };
 
 typedef struct {
diff --git a/hw/xfree86/ddc/interpret_edid.c b/hw/xfree86/ddc/interpret_edid.c
index ecec2b0..982a502 100644
--- a/hw/xfree86/ddc/interpret_edid.c
+++ b/hw/xfree86/ddc/interpret_edid.c
@@ -175,6 +175,34 @@ get_established_timing_section(Uchar *c, struct established_timings *r)
 }
 
 static void
+get_cvt_timing_section(Uchar *c, struct cvt_timings *r)
+{
+    int i;
+
+    for (i = 0; i < 4; i++) {
+	if (c[0] && c[1] && c[2]) {
+	    r[i].height = (c[0] + ((c[1] & 0xF0) << 8) + 1) * 2;
+	    switch (c[1] & 0xc0) {
+		case 0x00: r[i].width = r[i].height * 4 / 3; break;
+		case 0x40: r[i].width = r[i].height * 16 / 9; break;
+		case 0x80: r[i].width = r[i].height * 16 / 10; break;
+		case 0xc0: r[i].width = r[i].height * 15 / 9; break;
+	    }
+	    switch (c[2] & 0x60) {
+		case 0x00: r[i].rate = 50; break;
+		case 0x20: r[i].rate = 60; break;
+		case 0x40: r[i].rate = 75; break;
+		case 0x60: r[i].rate = 85; break;
+	    }
+	    r[i].rates = c[2] & 0x1f;
+	} else {
+	    return;
+	}
+	c += 3;
+    }
+}
+
+static void
 get_std_timing_section(Uchar *c, struct std_timings *r,
 		       struct edid_version *v)
 {
@@ -232,6 +260,7 @@ get_dt_md_section(Uchar *c, struct edid_version *ver,
 	break;
       case CVT_3BYTE_DATA:
 	det_mon[i].type = DS_CVT;
+	get_cvt_timing_section(c, det_mon[i].section.cvt);
 	break;
       case ADD_EST_TIMINGS:
 	det_mon[i].type = DS_EST_III;
diff --git a/hw/xfree86/ddc/print_edid.c b/hw/xfree86/ddc/print_edid.c
index 17e21ac..5aebc6e 100644
--- a/hw/xfree86/ddc/print_edid.c
+++ b/hw/xfree86/ddc/print_edid.c
@@ -235,6 +235,24 @@ print_std_timings(int scrnIndex, struct std_timings *t)
 	}
     }
 }
+
+static void
+print_cvt_timings(int si, struct cvt_timings *t)
+{
+    int i;
+
+    for (i = 0; i < 4; i++) {
+	if (t[i].height) {
+	    xf86DrvMsg(si, X_INFO, "%dx%d @ %s%s%s%s%s Hz\n",
+		    t[i].width, t[i].height,
+		    t[i].rates & 0x10 ? "50," : "",
+		    t[i].rates & 0x08 ? "60," : "",
+		    t[i].rates & 0x04 ? "75," : "",
+		    t[i].rates & 0x02 ? "85," : "",
+		    t[i].rates & 0x01 ? "60RB" : "");
+	} else break;
+    }
+}
   
 static void
 print_detailed_monitor_section(int scrnIndex,
@@ -296,7 +314,8 @@ print_detailed_monitor_section(int scrnIndex,
 	    break;
 	case DS_CVT:
 	    xf86DrvMsg(scrnIndex, X_INFO,
-		       "CVT 3-byte-code modes: (not decoded)\n");
+		       "CVT 3-byte-code modes:\n");
+	    print_cvt_timings(scrnIndex, m[i].section.cvt);
 	    break;
 	case DS_EST_III:
 	    xf86DrvMsg(scrnIndex, X_INFO,
diff --git a/hw/xfree86/modes/xf86EdidModes.c b/hw/xfree86/modes/xf86EdidModes.c
index a125d8c..d8c6161 100644
--- a/hw/xfree86/modes/xf86EdidModes.c
+++ b/hw/xfree86/modes/xf86EdidModes.c
@@ -354,6 +354,36 @@ DDCModeFromDetailedTiming(int scrnIndex, struct detailed_timings *timing,
     return Mode;
 }
 
+static DisplayModePtr
+DDCModesFromCVT(int scrnIndex, struct cvt_timings *t)
+{
+    DisplayModePtr modes = NULL;
+    int i;
+
+    for (i = 0; i < 4; i++) {
+	if (t[i].height) {
+	    if (t[i].rates & 0x10)
+		modes = xf86ModesAdd(modes,
+			xf86CVTMode(t[i].width, t[i].height, 50, 0, 0));
+	    if (t[i].rates & 0x08)
+		modes = xf86ModesAdd(modes,
+			xf86CVTMode(t[i].width, t[i].height, 60, 0, 0));
+	    if (t[i].rates & 0x04)
+		modes = xf86ModesAdd(modes,
+			xf86CVTMode(t[i].width, t[i].height, 75, 0, 0));
+	    if (t[i].rates & 0x02)
+		modes = xf86ModesAdd(modes,
+			xf86CVTMode(t[i].width, t[i].height, 85, 0, 0));
+	    if (t[i].rates & 0x01)
+		modes = xf86ModesAdd(modes,
+			xf86CVTMode(t[i].width, t[i].height, 60, 1, 0));
+	} else break;
+    }
+
+    return modes;
+}
+
+
 /*
  *
  */
@@ -527,6 +557,10 @@ xf86DDCGetModes(int scrnIndex, xf86MonPtr DDC)
 					      quirks);
             Modes = xf86ModesAdd(Modes, Mode);
             break;
+	case DS_CVT:
+	    Mode = DDCModesFromCVT(scrnIndex, det_mon->section.cvt);
+	    Modes = xf86ModesAdd(Modes, Mode);
+	    break;
         default:
             break;
         }
commit f6df66cc89bcd0a0be2e7bca05839fdd428c1d4c
Author: Adam Jackson <ajax at redhat.com>
Date:   Fri Dec 28 13:55:39 2007 -0500

    EDID 1.4: Trivial support for new detailed sections.
    
    Nothing actually decoded yet, but at least we print what they are.
    
    New in EDID 1.4:
    - Color Management Data (0xF9), Section 3.10.3.7
    - CVT 3 Byte Code Descriptor (0xF8), Section 3.10.3.8
    - Established Timings III Descriptor (0xF7), section 3.10.3.9
    - Manufacturer-specified data tag (0x00 - 0x0F), section 3.10.3.12

diff --git a/hw/xfree86/ddc/edid.h b/hw/xfree86/ddc/edid.h
index 02f5d09..2e3e7df 100644
--- a/hw/xfree86/ddc/edid.h
+++ b/hw/xfree86/ddc/edid.h
@@ -286,6 +286,9 @@
 #define _WHITE_GAMMA2(x) _GAMMA(x[14])
 #define WHITE_GAMMA2 _WHITE_GAMMA2(c)
 #define ADD_STD_TIMINGS 0xFA
+#define COLOR_MANAGEMENT_DATA 0xF9
+#define CVT_3BYTE_DATA 0xF8
+#define ADD_EST_TIMINGS 0xF7
 #define ADD_DUMMY 0x10
 
 #define _NEXT_DT_MD_SECTION(x) (x = (x + DET_TIMING_INFO_LEN))
@@ -418,8 +421,13 @@ struct detailed_timings {
 #define DS_RANGES 0xFD
 #define DS_WHITE_P 0xFB
 #define DS_STD_TIMINGS 0xFA
+#define DS_CMD 0xF9
+#define DS_CVT 0xF8
+#define DS_EST_III 0xF7
 #define DS_DUMMY 0x10
 #define DS_UNKOWN 0x100 /* type is an int */
+#define DS_VENDOR 0x101
+#define DS_VENDOR_MAX 0x110
 
 struct monitor_ranges {
   int min_v;
diff --git a/hw/xfree86/ddc/interpret_edid.c b/hw/xfree86/ddc/interpret_edid.c
index 7b4b2b9..ecec2b0 100644
--- a/hw/xfree86/ddc/interpret_edid.c
+++ b/hw/xfree86/ddc/interpret_edid.c
@@ -1,8 +1,28 @@
-
-/* interpret_edid.c: interpret a primary EDID block
- * 
+/*
  * Copyright 1998 by Egbert Eich <Egbert.Eich at Physik.TU-Darmstadt.DE>
+ * Copyright 2007 Red Hat, Inc.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software")
+ * to deal in the software without restriction, including without limitation
+ * on the rights to use, copy, modify, merge, publish, distribute, sub
+ * license, and/or sell copies of the Software, and to permit persons to whom
+ * them Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the next
+ * paragraph) shall be included in all copies or substantial portions of the
+ * Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTIBILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.  IN NO EVENT SHALL
+ * THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES, OR OTHER LIABILITY, WHETHER
+ * IN AN ACTION OF CONTRACT, TORT, OR OTHERWISE, ARISING FROM, OUT OF OR IN
+ * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ *
+ * interpret_edid.c: interpret a primary EDID block
  */
+
 #ifdef HAVE_XORG_CONFIG_H
 #include <xorg-config.h>
 #endif
@@ -207,6 +227,15 @@ get_dt_md_section(Uchar *c, struct edid_version *ver,
 	det_mon[i].type = DS_STD_TIMINGS;
 	get_dst_timing_section(c,det_mon[i].section.std_t, ver);
 	break;
+      case COLOR_MANAGEMENT_DATA:
+	det_mon[i].type = DS_CMD;
+	break;
+      case CVT_3BYTE_DATA:
+	det_mon[i].type = DS_CVT;
+	break;
+      case ADD_EST_TIMINGS:
+	det_mon[i].type = DS_EST_III;
+	break;
       case ADD_DUMMY:
 	det_mon[i].type = DS_DUMMY;
         break;
@@ -214,6 +243,9 @@ get_dt_md_section(Uchar *c, struct edid_version *ver,
         det_mon[i].type = DS_UNKOWN;
         break;
       }
+      if (c[3] <= 0x0F) {
+	det_mon[i].type = DS_VENDOR + c[3];
+      }
     } else { 
       det_mon[i].type = DT;
       get_detailed_timing_section(c,&det_mon[i].section.d_timings);
diff --git a/hw/xfree86/ddc/print_edid.c b/hw/xfree86/ddc/print_edid.c
index 30b607d..17e21ac 100644
--- a/hw/xfree86/ddc/print_edid.c
+++ b/hw/xfree86/ddc/print_edid.c
@@ -290,10 +290,27 @@ print_detailed_monitor_section(int scrnIndex,
 			       m[i].section.wp[j].white_y,
 			       m[i].section.wp[j].white_gamma);
 	    break;
+	case DS_CMD:
+	    xf86DrvMsg(scrnIndex, X_INFO,
+		       "Color management data: (not decoded)\n");
+	    break;
+	case DS_CVT:
+	    xf86DrvMsg(scrnIndex, X_INFO,
+		       "CVT 3-byte-code modes: (not decoded)\n");
+	    break;
+	case DS_EST_III:
+	    xf86DrvMsg(scrnIndex, X_INFO,
+		       "Established timings III: (not decoded)\n");
+	    break;
 	case DS_DUMMY:
 	default:
 	    break;
 	}
+	if (m[i].type >= DS_VENDOR && m[i].type <= DS_VENDOR_MAX) {
+	    xf86DrvMsg(scrnIndex, X_WARNING,
+		       "Unknown vendor-specific block %hx\n",
+		       m[i].type - DS_VENDOR);
+	}
     }
 }
   
commit bac3ecde39cc914ab515991234b7dc2138005b84
Author: Adam Jackson <ajax at redhat.com>
Date:   Fri Dec 28 13:33:39 2007 -0500

    EDID 1.4: Allow for sync range offsets.
    
    Table 3.26: Display Range Limits & Timing Descriptor Block Definition

diff --git a/hw/xfree86/ddc/edid.h b/hw/xfree86/ddc/edid.h
index 4487273..02f5d09 100644
--- a/hw/xfree86/ddc/edid.h
+++ b/hw/xfree86/ddc/edid.h
@@ -1,5 +1,5 @@
-
-/* edid.h: defines to parse an EDID block 
+/*
+ * edid.h: defines to parse an EDID block 
  *
  * This file contains all information to interpret a standard EDIC block 
  * transmitted by a display device via DDC (Display Data Channel). So far 
@@ -241,14 +241,18 @@
 #define SERIAL_NUMBER 0xFF
 #define ASCII_STR 0xFE
 #define MONITOR_RANGES 0xFD
+#define _MIN_V_OFFSET(x) ((!!(x[4] & 0x01)) * 255)
+#define _MAX_V_OFFSET(x) ((!!(x[4] & 0x02)) * 255)
+#define _MIN_H_OFFSET(x) ((!!(x[4] & 0x04)) * 255)
+#define _MAX_H_OFFSET(x) ((!!(x[4] & 0x08)) * 255)
 #define _MIN_V(x) x[5]
-#define MIN_V _MIN_V(c) 
+#define MIN_V (_MIN_V(c) + _MIN_V_OFFSET(c))
 #define _MAX_V(x) x[6]
-#define MAX_V _MAX_V(c) 
+#define MAX_V (_MAX_V(c) + _MAX_V_OFFSET(c))
 #define _MIN_H(x) x[7]
-#define MIN_H _MIN_H(c) 
+#define MIN_H (_MIN_H(c) + _MIN_H_OFFSET(c))
 #define _MAX_H(x) x[8]
-#define MAX_H _MAX_H(c) 
+#define MAX_H (_MAX_H(c) + _MAX_H_OFFSET(c))
 #define _MAX_CLOCK(x) x[9]
 #define MAX_CLOCK _MAX_CLOCK(c) 
 #define _HAVE_2ND_GTF(x) (x[10] == 0x02)
commit 3b23dd9fd43a28033d0af7b02088b0c6ca433158
Author: Eamon Walsh <ewalsh at tycho.nsa.gov>
Date:   Fri Dec 28 13:29:45 2007 -0500

    xselinux: Fix whitespace warnings.

diff --git a/Xext/xselinux.c b/Xext/xselinux.c
index 6550c7f..4629e90 100644
--- a/Xext/xselinux.c
+++ b/Xext/xselinux.c
@@ -1145,31 +1145,31 @@ ProcSELinuxDispatch(ClientPtr client)
     REQUEST(xReq);
     switch (stuff->data) {
     case X_SELinuxQueryVersion:
-        return ProcSELinuxQueryVersion(client);
+	return ProcSELinuxQueryVersion(client);
     case X_SELinuxSetSelectionManager:
 	return ProcSELinuxSetSelectionManager(client);
     case X_SELinuxGetSelectionManager:
-    	return ProcSELinuxGetSelectionManager(client);
+	return ProcSELinuxGetSelectionManager(client);
     case X_SELinuxSetDeviceCreateContext:
-    	return ProcSELinuxSetDeviceCreateContext(client);
+	return ProcSELinuxSetDeviceCreateContext(client);
     case X_SELinuxGetDeviceCreateContext:
-    	return ProcSELinuxGetDeviceCreateContext(client);
+	return ProcSELinuxGetDeviceCreateContext(client);
     case X_SELinuxSetDeviceContext:
-    	return ProcSELinuxSetDeviceContext(client);
+	return ProcSELinuxSetDeviceContext(client);
     case X_SELinuxGetDeviceContext:
-    	return ProcSELinuxGetDeviceContext(client);
+	return ProcSELinuxGetDeviceContext(client);
     case X_SELinuxSetPropertyCreateContext:
-    	return ProcSELinuxSetPropertyCreateContext(client);
+	return ProcSELinuxSetPropertyCreateContext(client);
     case X_SELinuxGetPropertyCreateContext:
-    	return ProcSELinuxGetPropertyCreateContext(client);
+	return ProcSELinuxGetPropertyCreateContext(client);
     case X_SELinuxGetPropertyContext:
-    	return ProcSELinuxGetPropertyContext(client);
+	return ProcSELinuxGetPropertyContext(client);
     case X_SELinuxSetWindowCreateContext:
-    	return ProcSELinuxSetWindowCreateContext(client);
+	return ProcSELinuxSetWindowCreateContext(client);
     case X_SELinuxGetWindowCreateContext:
-    	return ProcSELinuxGetWindowCreateContext(client);
+	return ProcSELinuxGetWindowCreateContext(client);
     case X_SELinuxGetWindowContext:
-    	return ProcSELinuxGetWindowContext(client);
+	return ProcSELinuxGetWindowContext(client);
     default:
 	return BadRequest;
     }
commit 643c52be32c187a0fdb9a031b1e31d97cd551339
Author: Eamon Walsh <ewalsh at tycho.nsa.gov>
Date:   Fri Dec 28 13:26:26 2007 -0500

    xselinux: Remove "X" prefix on remaining functions and strings.
    
    Should be evident from the context.

diff --git a/Xext/xselinux.c b/Xext/xselinux.c
index f3a8457..6550c7f 100644
--- a/Xext/xselinux.c
+++ b/Xext/xselinux.c
@@ -175,12 +175,12 @@ SELinuxSelectionToSID(Atom selection, SELinuxStateRec *sid_return)
 	security_id_t sid;
 
 	if (selabel_lookup(label_hnd, &con, name, SELABEL_X_SELN) < 0) {
-	    ErrorF("XSELinux: a selection label lookup failed!\n");
+	    ErrorF("SELinux: a selection label lookup failed!\n");
 	    return BadValue;
 	}
 	/* Get a SID for context */
 	if (avc_context_to_sid(con, &sid) < 0) {
-	    ErrorF("XSELinux: a context_to_SID call failed!\n");
+	    ErrorF("SELinux: a context_to_SID call failed!\n");
 	    return BadAlloc;
 	}
 	freecon(con);
@@ -216,12 +216,12 @@ SELinuxEventToSID(unsigned type, security_id_t sid_of_window,
     if (!knownEvents[type]) {
 	/* Look in the mappings of event names to contexts */
 	if (selabel_lookup(label_hnd, &con, name, SELABEL_X_EVENT) < 0) {
-	    ErrorF("XSELinux: an event label lookup failed!\n");
+	    ErrorF("SELinux: an event label lookup failed!\n");
 	    return BadValue;
 	}
 	/* Get a SID for context */
 	if (avc_context_to_sid(con, knownEvents + type) < 0) {
-	    ErrorF("XSELinux: a context_to_SID call failed!\n");
+	    ErrorF("SELinux: a context_to_SID call failed!\n");
 	    return BadAlloc;
 	}
 	freecon(con);
@@ -230,7 +230,7 @@ SELinuxEventToSID(unsigned type, security_id_t sid_of_window,
     /* Perform a transition to obtain the final SID */
     if (avc_compute_create(sid_of_window, knownEvents[type], SECCLASS_X_EVENT,
 			   &sid_return->sid) < 0) {
-	ErrorF("XSELinux: a compute_create call failed!\n");
+	ErrorF("SELinux: a compute_create call failed!\n");
 	return BadValue;
     }
 
@@ -607,13 +607,13 @@ SELinuxExtension(CallbackListPtr *pcbl, pointer unused, pointer calldata)
 
 	/* Look in the mappings of property names to contexts */
 	if (selabel_lookup(label_hnd, &con, name, SELABEL_X_EXT) < 0) {
-	    ErrorF("XSELinux: a property label lookup failed!\n");
+	    ErrorF("SELinux: a property label lookup failed!\n");
 	    rec->status = BadValue;
 	    return;
 	}
 	/* Get a SID for context */
 	if (avc_context_to_sid(con, &sid) < 0) {
-	    ErrorF("XSELinux: a context_to_SID call failed!\n");
+	    ErrorF("SELinux: a context_to_SID call failed!\n");
 	    rec->status = BadAlloc;
 	    return;
 	}
@@ -623,7 +623,7 @@ SELinuxExtension(CallbackListPtr *pcbl, pointer unused, pointer calldata)
 	/* Perform a transition to obtain the final SID */
 	if (avc_compute_create(serv->sid, sid, SECCLASS_X_EXTENSION,
 			       &obj->sid) < 0) {
-	    ErrorF("XSELinux: a SID transition call failed!\n");
+	    ErrorF("SELinux: a SID transition call failed!\n");
 	    freecon(con);
 	    rec->status = BadValue;
 	    return;
@@ -658,13 +658,13 @@ SELinuxProperty(CallbackListPtr *pcbl, pointer unused, pointer calldata)
 
 	/* Look in the mappings of property names to contexts */
 	if (selabel_lookup(label_hnd, &con, name, SELABEL_X_PROP) < 0) {
-	    ErrorF("XSELinux: a property label lookup failed!\n");
+	    ErrorF("SELinux: a property label lookup failed!\n");
 	    rec->status = BadValue;
 	    return;
 	}
 	/* Get a SID for context */
 	if (avc_context_to_sid(con, &sid) < 0) {
-	    ErrorF("XSELinux: a context_to_SID call failed!\n");
+	    ErrorF("SELinux: a context_to_SID call failed!\n");
 	    rec->status = BadAlloc;
 	    return;
 	}
@@ -674,7 +674,7 @@ SELinuxProperty(CallbackListPtr *pcbl, pointer unused, pointer calldata)
 	/* Perform a transition to obtain the final SID */
 	if (avc_compute_create(subj->sid, sid, SECCLASS_X_PROPERTY,
 			       &obj->sid) < 0) {
-	    ErrorF("XSELinux: a SID transition call failed!\n");
+	    ErrorF("SELinux: a SID transition call failed!\n");
 	    freecon(con);
 	    rec->status = BadValue;
 	    return;
@@ -732,7 +732,7 @@ SELinuxResource(CallbackListPtr *pcbl, pointer unused, pointer calldata)
 
 	/* Perform a transition to obtain the final SID */
 	if (avc_compute_create(subj->sid, pobj->sid, class, &obj->sid) < 0) {
-	    ErrorF("XSELinux: a compute_create call failed!\n");
+	    ErrorF("SELinux: a compute_create call failed!\n");
 	    rec->status = BadValue;
 	    return;
 	}
@@ -766,7 +766,7 @@ SELinuxScreen(CallbackListPtr *pcbl, pointer is_saver, pointer calldata)
 	/* Perform a transition to obtain the final SID */
 	if (avc_compute_create(subj->sid, subj->sid, SECCLASS_X_SCREEN,
 			       &obj->sid) < 0) {
-	    ErrorF("XSELinux: a compute_create call failed!\n");
+	    ErrorF("SELinux: a compute_create call failed!\n");
 	    rec->status = BadValue;
 	    return;
 	}
@@ -883,16 +883,16 @@ SELinuxResourceState(CallbackListPtr *pcbl, pointer unused, pointer calldata)
 	security_context_t ctx;
 	int rc = avc_sid_to_context(state->sid, &ctx);
 	if (rc < 0)
-	    FatalError("XSELinux: Failed to get security context!\n");
+	    FatalError("SELinux: Failed to get security context!\n");
 	rc = dixChangeWindowProperty(serverClient,
 				     pWin, atom_client_ctx, XA_STRING, 8,
 				     PropModeReplace, strlen(ctx), ctx, FALSE);
 	if (rc != Success)
-	    FatalError("XSELinux: Failed to set label property on window!\n");
+	    FatalError("SELinux: Failed to set label property on window!\n");
 	freecon(ctx);
     }
     else
-	FatalError("XSELinux: Unexpected unlabeled client found\n");
+	FatalError("SELinux: Unexpected unlabeled client found\n");
 
     state = dixLookupPrivate(&pWin->devPrivates, stateKey);
 
@@ -900,16 +900,16 @@ SELinuxResourceState(CallbackListPtr *pcbl, pointer unused, pointer calldata)
 	security_context_t ctx;
 	int rc = avc_sid_to_context(state->sid, &ctx);
 	if (rc < 0)
-	    FatalError("XSELinux: Failed to get security context!\n");
+	    FatalError("SELinux: Failed to get security context!\n");
 	rc = dixChangeWindowProperty(serverClient,
 				     pWin, atom_ctx, XA_STRING, 8,
 				     PropModeReplace, strlen(ctx), ctx, FALSE);
 	if (rc != Success)
-	    FatalError("XSELinux: Failed to set label property on window!\n");
+	    FatalError("SELinux: Failed to set label property on window!\n");
 	freecon(ctx);
     }
     else
-	FatalError("XSELinux: Unexpected unlabeled window found\n");
+	FatalError("SELinux: Unexpected unlabeled window found\n");
 }
 
 static void
@@ -931,7 +931,7 @@ SELinuxSelectionState(CallbackListPtr *pcbl, pointer unused, pointer calldata)
 
 	if (avc_compute_create(subj->sid, subj->sid, SECCLASS_X_SELECTION,
 			       &obj->sid) < 0) {
-	    ErrorF("XSELinux: a compute_create call failed!\n");
+	    ErrorF("SELinux: a compute_create call failed!\n");
 	    obj->sid = unlabeled_sid;
 	}
 	break;
@@ -998,8 +998,8 @@ ProcSELinuxQueryVersion(ClientPtr client)
     rep.type = X_Reply;
     rep.length = 0;
     rep.sequenceNumber = client->sequence;
-    rep.server_major = XSELINUX_MAJOR_VERSION;
-    rep.server_minor = XSELINUX_MINOR_VERSION;
+    rep.server_major = SELINUX_MAJOR_VERSION;
+    rep.server_minor = SELINUX_MINOR_VERSION;
     if (client->swapped) {
 	int n;
 	swaps(&rep.sequenceNumber, n);
@@ -1367,7 +1367,7 @@ SELinuxResetProc(ExtensionEntry *extEntry)
 }
 
 void
-XSELinuxExtensionInit(INITARGS)
+SELinuxExtensionInit(INITARGS)
 {
     ExtensionEntry *extEntry;
     struct selinux_opt options[] = { { SELABEL_OPT_VALIDATE, (char *)1 } };
@@ -1376,7 +1376,7 @@ XSELinuxExtensionInit(INITARGS)
 
     /* Setup SELinux stuff */
     if (!is_selinux_enabled()) {
-        ErrorF("XSELinux: SELinux not enabled, disabling SELinux support.\n");
+        ErrorF("SELinux: SELinux not enabled, disabling SELinux support.\n");
         return;
     }
 
@@ -1385,42 +1385,42 @@ XSELinuxExtensionInit(INITARGS)
 
     if (selinux_set_mapping(map) < 0) {
 	if (errno == EINVAL) {
-	    ErrorF("XSELinux: Invalid object class mapping, disabling SELinux support.\n");
+	    ErrorF("SELinux: Invalid object class mapping, disabling SELinux support.\n");
 	    return;
 	}
-	FatalError("XSELinux: Failed to set up security class mapping\n");
+	FatalError("SELinux: Failed to set up security class mapping\n");
     }
 
     if (avc_open(NULL, 0) < 0)
-	FatalError("XSELinux: Couldn't initialize SELinux userspace AVC\n");
+	FatalError("SELinux: Couldn't initialize SELinux userspace AVC\n");
     avc_active = 1;
 
     label_hnd = selabel_open(SELABEL_CTX_X, options, 1);
     if (!label_hnd)
-	FatalError("XSELinux: Failed to open x_contexts mapping in policy\n");
+	FatalError("SELinux: Failed to open x_contexts mapping in policy\n");
 
     if (security_get_initial_context("unlabeled", &con) < 0)
-	FatalError("XSELinux: Failed to look up unlabeled context\n");
+	FatalError("SELinux: Failed to look up unlabeled context\n");
     if (avc_context_to_sid(con, &unlabeled_sid) < 0)
-	FatalError("XSELinux: a context_to_SID call failed!\n");
+	FatalError("SELinux: a context_to_SID call failed!\n");
     freecon(con);
 
     /* Prepare for auditing */
     audit_fd = audit_open();
     if (audit_fd < 0)
-        FatalError("XSELinux: Failed to open the system audit log\n");
+        FatalError("SELinux: Failed to open the system audit log\n");
 
     /* Allocate private storage */
     if (!dixRequestPrivate(stateKey, sizeof(SELinuxStateRec)))
-	FatalError("XSELinux: Failed to allocate private storage.\n");
+	FatalError("SELinux: Failed to allocate private storage.\n");
 
     /* Create atoms for doing window labeling */
     atom_ctx = MakeAtom("_SELINUX_CONTEXT", 16, TRUE);
     if (atom_ctx == BAD_RESOURCE)
-	FatalError("XSELinux: Failed to create atom\n");
+	FatalError("SELinux: Failed to create atom\n");
     atom_client_ctx = MakeAtom("_SELINUX_CLIENT_CONTEXT", 23, TRUE);
     if (atom_client_ctx == BAD_RESOURCE)
-	FatalError("XSELinux: Failed to create atom\n");
+	FatalError("SELinux: Failed to create atom\n");
 
     /* Register callbacks */
     ret &= dixRegisterPrivateInitFunc(stateKey, SELinuxStateInit, NULL);
@@ -1443,11 +1443,11 @@ XSELinuxExtensionInit(INITARGS)
     ret &= XaceRegisterCallback(XACE_SCREEN_ACCESS, SELinuxScreen, NULL);
     ret &= XaceRegisterCallback(XACE_SCREENSAVER_ACCESS, SELinuxScreen, truep);
     if (!ret)
-	FatalError("XSELinux: Failed to register one or more callbacks\n");
+	FatalError("SELinux: Failed to register one or more callbacks\n");
 
     /* Add extension to server */
-    extEntry = AddExtension(XSELINUX_EXTENSION_NAME,
-			    XSELinuxNumberEvents, XSELinuxNumberErrors,
+    extEntry = AddExtension(SELINUX_EXTENSION_NAME,
+			    SELinuxNumberEvents, SELinuxNumberErrors,
 			    ProcSELinuxDispatch, SProcSELinuxDispatch,
 			    SELinuxResetProc, StandardMinorOpcode);
 
diff --git a/Xext/xselinux.h b/Xext/xselinux.h
index 9800d5a..ba1380b 100644
--- a/Xext/xselinux.h
+++ b/Xext/xselinux.h
@@ -23,11 +23,11 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 #include "dixaccess.h"
 
 /* Extension info */
-#define XSELINUX_EXTENSION_NAME		"SELinux"
-#define XSELINUX_MAJOR_VERSION		1
-#define XSELINUX_MINOR_VERSION		0
-#define XSELinuxNumberEvents		0
-#define XSELinuxNumberErrors		0
+#define SELINUX_EXTENSION_NAME		"SELinux"
+#define SELINUX_MAJOR_VERSION		1
+#define SELINUX_MINOR_VERSION		0
+#define SELinuxNumberEvents		0
+#define SELinuxNumberErrors		0
 
 /* Extension protocol */
 #define X_SELinuxQueryVersion			0
diff --git a/hw/xfree86/dixmods/extmod/modinit.h b/hw/xfree86/dixmods/extmod/modinit.h
index 191b3ef..99d714c 100644
--- a/hw/xfree86/dixmods/extmod/modinit.h
+++ b/hw/xfree86/dixmods/extmod/modinit.h
@@ -130,7 +130,7 @@ extern void XaceExtensionInit(INITARGS);
 #endif
 
 #ifdef XSELINUX
-extern void XSELinuxExtensionInit(INITARGS);
+extern void SELinuxExtensionInit(INITARGS);
 #endif
 
 #if 1
diff --git a/mi/miinitext.c b/mi/miinitext.c
index 319d2ce..b146907 100644
--- a/mi/miinitext.c
+++ b/mi/miinitext.c
@@ -330,7 +330,7 @@ extern void XaceExtensionInit(INITARGS);
 extern void SecurityExtensionInit(INITARGS);
 #endif
 #ifdef XSELINUX
-extern void XSELinuxExtensionInit(INITARGS);
+extern void SELinuxExtensionInit(INITARGS);
 #endif
 #ifdef XPRINT
 extern void XpExtensionInit(INITARGS);
@@ -606,7 +606,7 @@ InitExtensions(argc, argv)
     if (!noSecurityExtension) SecurityExtensionInit();
 #endif
 #ifdef XSELINUX
-    XSELinuxExtensionInit();
+    SELinuxExtensionInit();
 #endif
 #ifdef XPRINT
     XpExtensionInit(); /* server-specific extension, cannot be disabled */
@@ -703,7 +703,7 @@ static ExtensionModule staticExtensions[] = {
     { SecurityExtensionInit, SECURITY_EXTENSION_NAME, &noSecurityExtension, NULL, NULL },
 #endif
 #ifdef XSELINUX
-    { XSELinuxExtensionInit, XSELINUX_EXTENSION_NAME, NULL, NULL, NULL },
+    { SELinuxExtensionInit, SELINUX_EXTENSION_NAME, NULL, NULL, NULL },
 #endif
 #ifdef XPRINT
     { XpExtensionInit, XP_PRINTNAME, NULL, NULL, NULL },
commit f4bc333fc1e8d9fa9911771d2072df4df741c553
Author: Eamon Walsh <ewalsh at tycho.nsa.gov>
Date:   Fri Dec 28 11:56:54 2007 -0500

    xselinux: don't FatalError on an invalid class mapping, just disable support.

diff --git a/Xext/xselinux.c b/Xext/xselinux.c
index d7c7322..f3a8457 100644
--- a/Xext/xselinux.c
+++ b/Xext/xselinux.c
@@ -1376,15 +1376,20 @@ XSELinuxExtensionInit(INITARGS)
 
     /* Setup SELinux stuff */
     if (!is_selinux_enabled()) {
-        ErrorF("XSELinux: Extension failed to load: SELinux not enabled\n");
+        ErrorF("XSELinux: SELinux not enabled, disabling SELinux support.\n");
         return;
     }
 
     selinux_set_callback(SELINUX_CB_LOG, (union selinux_callback)SELinuxLog);
     selinux_set_callback(SELINUX_CB_AUDIT, (union selinux_callback)SELinuxAudit);
 
-    if (selinux_set_mapping(map) < 0)
+    if (selinux_set_mapping(map) < 0) {
+	if (errno == EINVAL) {
+	    ErrorF("XSELinux: Invalid object class mapping, disabling SELinux support.\n");
+	    return;
+	}
 	FatalError("XSELinux: Failed to set up security class mapping\n");
+    }
 
     if (avc_open(NULL, 0) < 0)
 	FatalError("XSELinux: Couldn't initialize SELinux userspace AVC\n");
commit f3780ece528ed3ead809ba6a388fa0f8aab2a775
Author: Eamon Walsh <ewalsh at tycho.nsa.gov>
Date:   Thu Dec 20 20:32:07 2007 -0500

    xselinux: Implement swapped protocol request logic.

diff --git a/Xext/xselinux.c b/Xext/xselinux.c
index bbd8d1a..d7c7322 100644
--- a/Xext/xselinux.c
+++ b/Xext/xselinux.c
@@ -1199,68 +1199,81 @@ SProcSELinuxSetSelectionManager(ClientPtr client)
 }
 
 static int
-SProcSELinuxGetSelectionManager(ClientPtr client)
-{
-    return ProcSELinuxGetSelectionManager(client);
-}
-
-static int
 SProcSELinuxSetDeviceCreateContext(ClientPtr client)
 {
-    return ProcSELinuxSetDeviceCreateContext(client);
-}
+    REQUEST(SELinuxSetCreateContextReq);
+    int n;
 
-static int
-SProcSELinuxGetDeviceCreateContext(ClientPtr client)
-{
-    return ProcSELinuxGetDeviceCreateContext(client);
+    REQUEST_AT_LEAST_SIZE(SELinuxSetCreateContextReq);
+    swaps(&stuff->context_len,n);
+    return ProcSELinuxSetDeviceCreateContext(client);
 }
 
 static int
 SProcSELinuxSetDeviceContext(ClientPtr client)
 {
+    REQUEST(SELinuxSetContextReq);
+    int n;
+
+    REQUEST_AT_LEAST_SIZE(SELinuxSetContextReq);
+    swapl(&stuff->id,n);
+    swaps(&stuff->context_len,n);
     return ProcSELinuxSetDeviceContext(client);
 }
 
 static int
 SProcSELinuxGetDeviceContext(ClientPtr client)
 {
+    REQUEST(SELinuxGetContextReq);
+    int n;
+
+    REQUEST_SIZE_MATCH(SELinuxGetContextReq);
+    swapl(&stuff->id,n);
     return ProcSELinuxGetDeviceContext(client);
 }
 
 static int
 SProcSELinuxSetPropertyCreateContext(ClientPtr client)
 {
-    return ProcSELinuxSetPropertyCreateContext(client);
-}
+    REQUEST(SELinuxSetCreateContextReq);
+    int n;
 
-static int
-SProcSELinuxGetPropertyCreateContext(ClientPtr client)
-{
-    return ProcSELinuxGetPropertyCreateContext(client);
+    REQUEST_AT_LEAST_SIZE(SELinuxSetCreateContextReq);
+    swaps(&stuff->context_len,n);
+    return ProcSELinuxSetPropertyCreateContext(client);
 }
 
 static int
 SProcSELinuxGetPropertyContext(ClientPtr client)
 {
+    REQUEST(SELinuxGetPropertyContextReq);
+    int n;
+
+    REQUEST_SIZE_MATCH(SELinuxGetPropertyContextReq);
+    swapl(&stuff->window,n);
+    swapl(&stuff->property,n);
     return ProcSELinuxGetPropertyContext(client);
 }
 
 static int
 SProcSELinuxSetWindowCreateContext(ClientPtr client)
 {
-    return ProcSELinuxSetWindowCreateContext(client);
-}
+    REQUEST(SELinuxSetCreateContextReq);
+    int n;
 
-static int
-SProcSELinuxGetWindowCreateContext(ClientPtr client)
-{
-    return ProcSELinuxGetWindowCreateContext(client);
+    REQUEST_AT_LEAST_SIZE(SELinuxSetCreateContextReq);
+    swaps(&stuff->context_len,n);
+    return ProcSELinuxSetWindowCreateContext(client);
 }
 
 static int
 SProcSELinuxGetWindowContext(ClientPtr client)
 {
+    REQUEST(SELinuxGetContextReq);
+    int n;
+
+    REQUEST_SIZE_MATCH(SELinuxGetContextReq);
+    swapl(&stuff->id,n);
     return ProcSELinuxGetWindowContext(client);
 }
 
@@ -1278,11 +1291,11 @@ SProcSELinuxDispatch(ClientPtr client)
     case X_SELinuxSetSelectionManager:
 	return SProcSELinuxSetSelectionManager(client);
     case X_SELinuxGetSelectionManager:
-    	return SProcSELinuxGetSelectionManager(client);
+    	return ProcSELinuxGetSelectionManager(client);
     case X_SELinuxSetDeviceCreateContext:
     	return SProcSELinuxSetDeviceCreateContext(client);
     case X_SELinuxGetDeviceCreateContext:
-    	return SProcSELinuxGetDeviceCreateContext(client);
+    	return ProcSELinuxGetDeviceCreateContext(client);
     case X_SELinuxSetDeviceContext:
     	return SProcSELinuxSetDeviceContext(client);
     case X_SELinuxGetDeviceContext:
@@ -1290,13 +1303,13 @@ SProcSELinuxDispatch(ClientPtr client)
     case X_SELinuxSetPropertyCreateContext:
     	return SProcSELinuxSetPropertyCreateContext(client);
     case X_SELinuxGetPropertyCreateContext:
-    	return SProcSELinuxGetPropertyCreateContext(client);
+    	return ProcSELinuxGetPropertyCreateContext(client);
     case X_SELinuxGetPropertyContext:
     	return SProcSELinuxGetPropertyContext(client);
     case X_SELinuxSetWindowCreateContext:
     	return SProcSELinuxSetWindowCreateContext(client);
     case X_SELinuxGetWindowCreateContext:
-    	return SProcSELinuxGetWindowCreateContext(client);
+    	return ProcSELinuxGetWindowCreateContext(client);
     case X_SELinuxGetWindowContext:
     	return SProcSELinuxGetWindowContext(client);
     default:
commit 1bbf64ab115e2a1121d6f9c0830b1b977f025178
Author: Eamon Walsh <ewalsh at tycho.nsa.gov>
Date:   Thu Dec 20 20:31:34 2007 -0500

    xselinux: Remove unnecessary structure definition.

diff --git a/Xext/xselinux.h b/Xext/xselinux.h
index ebcc4aa..9800d5a 100644
--- a/Xext/xselinux.h
+++ b/Xext/xselinux.h
@@ -139,20 +139,6 @@ typedef struct {
 } SELinuxGetContextReq;
 
 typedef struct {
-    CARD8   type;
-    CARD8   pad1;
-    CARD16  sequenceNumber;
-    CARD32  length;
-    CARD16  context_len;
-    CARD16  pad2;
-    CARD32  pad3;
-    CARD32  pad4;
-    CARD32  pad5;
-    CARD32  pad6;
-    CARD32  pad7;
-} SELinuxGetContextReply;
-
-typedef struct {
     CARD8   reqType;
     CARD8   SELinuxReqType;
     CARD16  length;
@@ -172,7 +158,7 @@ typedef struct {
     CARD32  pad5;
     CARD32  pad6;
     CARD32  pad7;
-} SELinuxGetPropertyContextReply;
+} SELinuxGetContextReply;
 
 
 /* Private Flask definitions */
commit 938da5ee389975f910721f1c2cebc2dcec793117
Author: Adam Jackson <ajax at redhat.com>
Date:   Fri Dec 28 12:23:44 2007 -0500

    Add HDMI and DisplayPort connector types.

diff --git a/hw/xfree86/modes/xf86Crtc.c b/hw/xfree86/modes/xf86Crtc.c
index e00fdf3..10db862 100644
--- a/hw/xfree86/modes/xf86Crtc.c
+++ b/hw/xfree86/modes/xf86Crtc.c
@@ -2192,9 +2192,12 @@ xf86OutputGetEDID (xf86OutputPtr output, I2CBusPtr pDDCBus)
     return mon;
 }
 
-static char *_xf86ConnectorNames[] = { "None", "VGA", "DVI-I", "DVI-D",
-				      "DVI-A", "Composite", "S-Video",
-				      "Component", "LFP", "Proprietary" };
+static char *_xf86ConnectorNames[] = {
+					"None", "VGA", "DVI-I", "DVI-D",
+					"DVI-A", "Composite", "S-Video",
+					"Component", "LFP", "Proprietary",
+					"HDMI", "DisplayPort",
+				     };
 _X_EXPORT char *
 xf86ConnectorGetName(xf86ConnectorType connector)
 {
diff --git a/hw/xfree86/modes/xf86Crtc.h b/hw/xfree86/modes/xf86Crtc.h
index f312b30..62d85bb 100644
--- a/hw/xfree86/modes/xf86Crtc.h
+++ b/hw/xfree86/modes/xf86Crtc.h
@@ -61,7 +61,9 @@ typedef enum _xf86ConnectorType {
    XF86ConnectorSvideo,
    XF86ConnectorComponent,
    XF86ConnectorLFP,
-   XF86ConnectorProprietary
+   XF86ConnectorProprietary,
+   XF86ConnectorHDMI,
+   XF86ConnectorDisplayPort,
 } xf86ConnectorType;
 
 typedef enum _xf86OutputStatus {
commit 24105cf6582201a94bc39aeac5a795297018aeb5
Author: Daniel Stone <daniel at fooishbar.org>
Date:   Fri Dec 28 15:49:50 2007 +0200

    Input: Don't reinit devices
    
    If a device is already initialised (i.e. the virtual core devices) during
    IASD, don't init them again.  This fixes a leak.

diff --git a/dix/devices.c b/dix/devices.c
index adf2fba..534a0b9 100644
--- a/dix/devices.c
+++ b/dix/devices.c
@@ -469,7 +469,8 @@ InitAndStartDevices(void)
 
     for (dev = inputInfo.off_devices; dev; dev = dev->next) {
         DebugF("(dix) initialising device %d\n", dev->id);
-	ActivateDevice(dev);
+        if (!dev->inited)
+            ActivateDevice(dev);
     }
     for (dev = inputInfo.off_devices; dev; dev = next)
     {
commit 941058f8da0d725f909dc97f68c32ce244a9dc0a
Author: Daniel Stone <daniel at fooishbar.org>
Date:   Fri Dec 28 15:48:57 2007 +0200

    KDrive: Xephyr: Don't leak screen damage structure

diff --git a/hw/kdrive/ephyr/ephyr.c b/hw/kdrive/ephyr/ephyr.c
index a4d995c..2a762a2 100644
--- a/hw/kdrive/ephyr/ephyr.c
+++ b/hw/kdrive/ephyr/ephyr.c
@@ -402,6 +402,7 @@ ephyrUnsetInternalDamage (ScreenPtr pScreen)
   
   pPixmap = (*pScreen->GetScreenPixmap) (pScreen);
   DamageUnregister (&pPixmap->drawable, scrpriv->pDamage);
+  DamageDestroy (scrpriv->pDamage);
   
   RemoveBlockAndWakeupHandlers (ephyrInternalDamageBlockHandler,
 				ephyrInternalDamageWakeupHandler,
commit b2f6cd290c43b88f0d08fb29f8657618a067d2a0
Author: Daniel Stone <daniel at fooishbar.org>
Date:   Fri Dec 28 15:48:25 2007 +0200

    OS: Don't leak connection translation table on regeneration

diff --git a/os/connection.c b/os/connection.c
index 3b5742c..8b6541c 100644
--- a/os/connection.c
+++ b/os/connection.c
@@ -353,7 +353,8 @@ InitConnectionLimits(void)
 #endif
 
 #if !defined(WIN32)
-    ConnectionTranslation = (int *)xnfalloc(sizeof(int)*(lastfdesc + 1));
+    if (!ConnectionTranslation)
+        ConnectionTranslation = (int *)xnfalloc(sizeof(int)*(lastfdesc + 1));
 #else
     InitConnectionTranslation();
 #endif
commit 190a0506243b39cd8dfc0e12068e3a3f416330f1
Author: Daniel Stone <daniel at fooishbar.org>
Date:   Fri Dec 28 15:47:57 2007 +0200

    Config: HAL: Don't leak options on failure to add device
    
    This showed up in Xephyr in particular, which denies new device requests.

diff --git a/config/hal.c b/config/hal.c
index af96fc2..4ab2961 100644
--- a/config/hal.c
+++ b/config/hal.c
@@ -92,6 +92,8 @@ add_option(InputOption **options, const char *key, const char *value)
     for (; *options; options = &(*options)->next)
         ;
     *options = xcalloc(sizeof(**options), 1);
+    if (!*options) /* Yeesh. */
+        return;
     (*options)->key = xstrdup(key);
     (*options)->value = xstrdup(value);
     (*options)->next = NULL;
@@ -156,7 +158,7 @@ device_added(LibHalContext *hal_ctx, const char *udi)
     char *path = NULL, *driver = NULL, *name = NULL, *xkb_rules = NULL;
     char *xkb_model = NULL, *xkb_layout = NULL, *xkb_variant = NULL;
     char *xkb_options = NULL, *config_info = NULL;
-    InputOption *options = NULL;
+    InputOption *options = NULL, *tmpo = NULL;
     DeviceIntPtr dev;
     DBusError error;
     int type = TYPE_NONE;
@@ -234,6 +236,7 @@ device_added(LibHalContext *hal_ctx, const char *udi)
 
     if (NewInputDeviceRequest(options, &dev) != Success) {
         DebugF("[config/hal] NewInputDeviceRequest failed\n");
+        dev = NULL;
         goto unwind;
     }
 
@@ -259,6 +262,12 @@ unwind:
         xfree(xkb_options);
     if (config_info)
         xfree(config_info);
+    while (!dev && (tmpo = options)) {
+        options = tmpo->next;
+        xfree(tmpo->key);
+        xfree(tmpo->value);
+        xfree(tmpo);
+    }
 
 out_error:
     dbus_error_free(&error);
commit f44fd3f9e41bf467360ace93ef5b532d8f61fb2c
Author: Daniel Stone <daniel at fooishbar.org>
Date:   Fri Dec 28 15:47:21 2007 +0200

    Config: D-Bus: Don't leak timers
    
    TimerCancel doesn't free the timer: you need TimerFree for that.

diff --git a/config/dbus-core.c b/config/dbus-core.c
index eab72a5..9cf1530 100644
--- a/config/dbus-core.c
+++ b/config/dbus-core.c
@@ -76,7 +76,7 @@ teardown(void)
     struct config_dbus_core_hook *hook;
 
     if (bus_info.timer) {
-        TimerCancel(bus_info.timer);
+        TimerFree(bus_info.timer);
         bus_info.timer = NULL;
     }
 
@@ -116,6 +116,8 @@ message_filter(DBusConnection *connection, DBusMessage *message, void *data)
         bus_info.connection = NULL;
         teardown();
 
+        if (bus_info.timer)
+            TimerFree(bus_info.timer);
         bus_info.timer = TimerSet(NULL, 0, 1, reconnect_timer, NULL);
 
         return DBUS_HANDLER_RESULT_HANDLED;
@@ -186,6 +188,7 @@ static CARD32
 reconnect_timer(OsTimerPtr timer, CARD32 time, pointer arg)
 {
     if (connect_to_bus()) {
+        TimerFree(bus_info.timer);
         bus_info.timer = NULL;
         return 0;
     }
commit ae869fc7669764729e13fdd70149ed636753f2a3
Author: David S. Miller <davem at davemloft.net>
Date:   Tue Dec 25 22:42:50 2007 -0800

    [SBUS]: Fix build, use getpagesize() instead of xf86getpagesize().
    
    xf86getpagesize() was removed, but this one call site was
    not fixed up.
    
    Signed-off-by: David S. Miller <davem at davemloft.net>

diff --git a/hw/xfree86/os-support/bus/Sbus.c b/hw/xfree86/os-support/bus/Sbus.c
index 2f0043f..ff257a8 100644
--- a/hw/xfree86/os-support/bus/Sbus.c
+++ b/hw/xfree86/os-support/bus/Sbus.c
@@ -585,7 +585,7 @@ xf86MapSbusMem(sbusDevicePtr psdp, unsigned long offset, unsigned long size)
 _X_EXPORT void
 xf86UnmapSbusMem(sbusDevicePtr psdp, pointer addr, unsigned long size)
 {
-    unsigned long mask = xf86getpagesize() - 1;
+    unsigned long mask = getpagesize() - 1;
     unsigned long base = (unsigned long)addr & ~mask;
     unsigned long len = (((unsigned long)addr + size + mask) & ~mask) - base;
 
commit 009f1e4e55200425de2fe0dbc1f0ac0f431fb4cf
Author: Fatih Aşıcı <fatih at pardus.org.tr>
Date:   Tue Dec 25 23:09:49 2007 +0200

    Config: Don't forget to add xkb_rules option

diff --git a/config/hal.c b/config/hal.c
index 45238c0..af96fc2 100644
--- a/config/hal.c
+++ b/config/hal.c
@@ -221,6 +221,8 @@ device_added(LibHalContext *hal_ctx, const char *udi)
         goto unwind;
     sprintf(config_info, "hal:%s", udi);
 
+    if (xkb_rules)
+        add_option(&options, "xkb_rules", xkb_rules);
     if (xkb_model)
         add_option(&options, "xkb_model", xkb_model);
     if (xkb_layout)
commit 389e8917f66a489455f1d5c70f44c262717538ad
Author: Fatih Aşıcı <fatih at pardus.org.tr>
Date:   Tue Dec 25 22:59:24 2007 +0200

    Config: Fix a memory leak

diff --git a/config/hal.c b/config/hal.c
index 4427deb..45238c0 100644
--- a/config/hal.c
+++ b/config/hal.c
@@ -251,6 +251,8 @@ unwind:
         xfree(xkb_model);
     if (xkb_layout)
         xfree(xkb_layout);
+    if (xkb_variant)
+        xfree(xkb_variant);
     if (xkb_options)
         xfree(xkb_options);
     if (config_info)
commit 743008a4812d6b046211ebcf4eab202687b458d5
Author: Adam Jackson <ajax at redhat.com>
Date:   Sun Dec 23 14:27:14 2007 -0500

    Report serverClient resources in the X-Resource extension.

diff --git a/Xext/xres.c b/Xext/xres.c
index feadad2..9bd70c6 100644
--- a/Xext/xres.c
+++ b/Xext/xres.c
@@ -67,7 +67,7 @@ ProcXResQueryClients (ClientPtr client)
     current_clients = xalloc((currentMaxClients - 1) * sizeof(int));
 
     num_clients = 0;
-    for(i = 1; i < currentMaxClients; i++) {
+    for(i = 0; i < currentMaxClients; i++) {
        if(clients[i]) {
            current_clients[num_clients] = i;
            num_clients++;   
@@ -128,9 +128,7 @@ ProcXResQueryClientResources (ClientPtr client)
 
     clientID = CLIENT_ID(stuff->xid);
 
-    /* we could remove the (clientID == 0) check if we wanted to allow
-       probing the X-server's resource usage */
-    if(!clientID || (clientID >= currentMaxClients) || !clients[clientID]) {
+    if((clientID >= currentMaxClients) || !clients[clientID]) {
         client->errorValue = stuff->xid;
         return BadValue;
     }
@@ -254,9 +252,7 @@ ProcXResQueryClientPixmapBytes (ClientPtr client)
 
     clientID = CLIENT_ID(stuff->xid);
 
-    /* we could remove the (clientID == 0) check if we wanted to allow
-       probing the X-server's resource usage */
-    if(!clientID || (clientID >= currentMaxClients) || !clients[clientID]) {
+    if((clientID >= currentMaxClients) || !clients[clientID]) {
         client->errorValue = stuff->xid;
         return BadValue;
     }
commit beb29c605b8c66e1a18b89668aa421c1519645f6
Author: Jeremy Huddleston <jeremy at yuffie.local>
Date:   Fri Dec 21 02:09:01 2007 -0800

    XQuartz: *REALLY* use CFStringCreateWithCString
    I need sleep!  Why am I making these stupid mistakes... sorry for pointless commit spam.  ugg.
    (cherry picked from commit b16351fc6457aabead328472d16dc25789032940)

diff --git a/hw/xquartz/bundle/bundle-main.c b/hw/xquartz/bundle/bundle-main.c
index c668567..df78d7f 100644
--- a/hw/xquartz/bundle/bundle-main.c
+++ b/hw/xquartz/bundle/bundle-main.c
@@ -104,7 +104,7 @@ static char *command_from_prefs(const char *key, const char *default_value) {
     CFPropertyListRef PlistRef = CFPreferencesCopyAppValue(cfKey, kCFPreferencesCurrentApplication);
     
     if ((PlistRef == NULL) || (CFGetTypeID(PlistRef) != CFStringGetTypeID())) {
-        CFStringRef cfDefaultValue = CFStringCreateWithPascalString(NULL, default_value, kCFStringEncodingASCII);
+        CFStringRef cfDefaultValue = CFStringCreateWithCString(NULL, default_value, kCFStringEncodingASCII);
 
         CFPreferencesSetAppValue(cfKey, cfDefaultValue, kCFPreferencesCurrentApplication);
         CFPreferencesAppSynchronize(kCFPreferencesCurrentApplication);
commit 5dd895efa305954e2695aa22a9e49acfb65b4d5e
Author: Jeremy Huddleston <jeremy at yuffie.local>
Date:   Fri Dec 21 02:06:47 2007 -0800

    XQuartz: Use CFStringCreateWithCString
    (cherry picked from commit 79782b0e14761dcf5d6635b8eec161b74f06763a)

diff --git a/hw/xquartz/bundle/bundle-main.c b/hw/xquartz/bundle/bundle-main.c
index a7b00d6..c668567 100644
--- a/hw/xquartz/bundle/bundle-main.c
+++ b/hw/xquartz/bundle/bundle-main.c
@@ -100,7 +100,7 @@ static int execute(const char *command) {
 static char *command_from_prefs(const char *key, const char *default_value) {
     char *command = NULL;
     
-    CFStringRef cfKey = CFStringCreateWithPascalString(NULL, key, kCFStringEncodingASCII);
+    CFStringRef cfKey = CFStringCreateWithCString(NULL, key, kCFStringEncodingASCII);
     CFPropertyListRef PlistRef = CFPreferencesCopyAppValue(cfKey, kCFPreferencesCurrentApplication);
     
     if ((PlistRef == NULL) || (CFGetTypeID(PlistRef) != CFStringGetTypeID())) {
commit 2c24231fc2027cf5034bb1b6636332687f586726
Author: Jeremy Huddleston <jeremy at yuffie.local>
Date:   Fri Dec 21 01:57:43 2007 -0800

    XQuartz: Reduce code duplication in X11.app
    (cherry picked from commit b81809cd91a9f90b7f2de77b1dcf514cee87c32d)

diff --git a/hw/xquartz/bundle/bundle-main.c b/hw/xquartz/bundle/bundle-main.c
index cd74cea..a7b00d6 100644
--- a/hw/xquartz/bundle/bundle-main.c
+++ b/hw/xquartz/bundle/bundle-main.c
@@ -39,8 +39,8 @@
 #define DEFAULT_CLIENT "/usr/X11/bin/xterm"
 #define DEFAULT_STARTX "/usr/X11/bin/startx"
 
-static int launcher_main(int argc, char **argv);
-static int server_main(int argc, char **argv);
+static int execute(const char *command);
+static char *command_from_prefs(const char *key, const char *default_value);
 
 int main(int argc, char **argv) {
     Display *display;
@@ -50,7 +50,7 @@ int main(int argc, char **argv) {
     for(i=0; i < argc; i++) {
         fprintf(stderr, "\targv[%u] = %s\n", (unsigned)i, argv[i]);
     }
-    
+
     /* If we have a process serial number and it's our only arg, act as if
      * the user double clicked the app bundle: launch app_to_run if possible
      */
@@ -61,32 +61,32 @@ int main(int argc, char **argv) {
             fprintf(stderr, "X11.app: Closing the display and sleeping for 2s to allow the X server to start up.\n");
             /* Could open the display, start the launcher */
             XCloseDisplay(display);
-            
+
             /* Give 2 seconds for the server to start... 
              * TODO: *Really* fix this race condition
              */
             usleep(2000);
-            return launcher_main(argc, argv);
+            return execute(command_from_prefs("app_to_run", DEFAULT_CLIENT));
         }
     }
-    
+
     /* Start the server */
     fprintf(stderr, "X11.app: Could not connect to server.  Starting X server.");
-    return server_main(argc, argv);
+    return execute(command_from_prefs("startx_script", DEFAULT_STARTX));
 }
 
-static int myexecvp(const char *command) {
+static int execute(const char *command) {
     const char *newargv[7];
     const char **s;
 
-	newargv[0] = "/usr/bin/login";
-	newargv[1] = "-fp";
-	newargv[2] = getlogin();
-	newargv[3] = "/bin/sh";
-	newargv[4] = "-c";
-	newargv[5] = command;
-	newargv[6] = NULL;
-
+    newargv[0] = "/usr/bin/login";
+    newargv[1] = "-fp";
+    newargv[2] = getlogin();
+    newargv[3] = "/bin/sh";
+    newargv[4] = "-c";
+    newargv[5] = command;
+    newargv[6] = NULL;
+    
     fprintf(stderr, "X11.app: Launching %s:\n", command);
     for(s=newargv; *s; s++) {
         fprintf(stderr, "\targv[%d] = %s\n", s - newargv, *s);
@@ -97,42 +97,33 @@ static int myexecvp(const char *command) {
     return(1);
 }
 
-int launcher_main (int argc, char **argv) {
-    char *command = DEFAULT_CLIENT;
+static char *command_from_prefs(const char *key, const char *default_value) {
+    char *command = NULL;
     
-	CFPropertyListRef PlistRef = CFPreferencesCopyAppValue(CFSTR("app_to_run"), kCFPreferencesCurrentApplication);
-	
-	if ((PlistRef == NULL) || (CFGetTypeID(PlistRef) != CFStringGetTypeID())) {
-		CFPreferencesSetAppValue(CFSTR("app_to_run"), CFSTR(DEFAULT_CLIENT), kCFPreferencesCurrentApplication);
-		CFPreferencesAppSynchronize(kCFPreferencesCurrentApplication);
-	} else {
-        int len = CFStringGetLength((CFStringRef)PlistRef)+1;
-		command = (char *)malloc(len);
-		CFStringGetCString((CFStringRef)PlistRef, command, len,  kCFStringEncodingASCII);
-	}
-
-	if (PlistRef)
-        CFRelease(PlistRef);
-
-    return myexecvp(command);
-}
-
-int server_main (int argc, char **argv) {
-    char *command = DEFAULT_STARTX;
+    CFStringRef cfKey = CFStringCreateWithPascalString(NULL, key, kCFStringEncodingASCII);
+    CFPropertyListRef PlistRef = CFPreferencesCopyAppValue(cfKey, kCFPreferencesCurrentApplication);
+    
+    if ((PlistRef == NULL) || (CFGetTypeID(PlistRef) != CFStringGetTypeID())) {
+        CFStringRef cfDefaultValue = CFStringCreateWithPascalString(NULL, default_value, kCFStringEncodingASCII);
 
-	CFPropertyListRef PlistRef = CFPreferencesCopyAppValue(CFSTR("startx_script"), kCFPreferencesCurrentApplication);
-	
-	if ((PlistRef == NULL) || (CFGetTypeID(PlistRef) != CFStringGetTypeID())) {
-		CFPreferencesSetAppValue(CFSTR("startx_script"), CFSTR(DEFAULT_STARTX), kCFPreferencesCurrentApplication);
-		CFPreferencesAppSynchronize(kCFPreferencesCurrentApplication);
-	} else {
-        int len = CFStringGetLength((CFStringRef)PlistRef)+1;
-		command = (char *)malloc(len);
-		CFStringGetCString((CFStringRef)PlistRef, command, len,  kCFStringEncodingASCII);
+        CFPreferencesSetAppValue(cfKey, cfDefaultValue, kCFPreferencesCurrentApplication);
+        CFPreferencesAppSynchronize(kCFPreferencesCurrentApplication);
+        
+        int len = strlen(default_value) + 1;
+        command = (char *)malloc(len * sizeof(char));
+        if(!command)
+            return NULL;
+        strcpy(command, default_value);
+    } else {
+        int len = CFStringGetLength((CFStringRef)PlistRef) + 1;
+        command = (char *)malloc(len * sizeof(char));
+        if(!command)
+            return NULL;
+        CFStringGetCString((CFStringRef)PlistRef, command, len,  kCFStringEncodingASCII);
 	}
     
-	if (PlistRef)
+    if (PlistRef)
         CFRelease(PlistRef);
     
-    return myexecvp(command);
+    return command;
 }
commit f3042a63be0748bb60567144276d2c61b75ba0b7
Author: Jeremy Huddleston <jeremy at yuffie.local>
Date:   Fri Dec 21 01:24:06 2007 -0800

    XQuartz: Handle Pseudorami init in miinitext
    (cherry picked from commit a585c94fedd4ecbc87524703c01bb128fc2aa951)

diff --git a/hw/xquartz/pseudoramiX.c b/hw/xquartz/pseudoramiX.c
index b19c605..4a9d8e1 100644
--- a/hw/xquartz/pseudoramiX.c
+++ b/hw/xquartz/pseudoramiX.c
@@ -44,7 +44,7 @@ Equipment Corporation.
 #include <X11/extensions/panoramiXproto.h>
 #include "globals.h"
 
-extern int noPseudoramiXExtension;
+Bool noPseudoramiXExtension = FALSE;
 extern int noPanoramiXExtension;
 
 extern int ProcPanoramiXQueryVersion (ClientPtr client);
diff --git a/hw/xquartz/quartz.c b/hw/xquartz/quartz.c
index 75f4e5e..6f42c53 100644
--- a/hw/xquartz/quartz.c
+++ b/hw/xquartz/quartz.c
@@ -39,11 +39,13 @@
 #include "quartzAudio.h"
 #include "pseudoramiX.h"
 #define _APPLEWM_SERVER_
-#include "X11/extensions/applewm.h"
 #include "applewmExt.h"
 
 #include "X11Application.h"
 
+#include <X11/extensions/applewm.h>
+#include <X11/extensions/randr.h>
+
 // X headers
 #include "scrnintstr.h"
 #include "windowstr.h"
@@ -69,7 +71,6 @@ int                     quartzServerVisible = TRUE;
 int                     quartzServerQuitting = FALSE;
 DevPrivateKey           quartzScreenKey = &quartzScreenKey;
 int                     aquaMenuBarHeight = 0;
-int                     noPseudoramiXExtension = FALSE;
 QuartzModeProcsPtr      quartzProcs = NULL;
 const char             *quartzOpenGLBundle = NULL;
 
@@ -165,13 +166,6 @@ void QuartzInitOutput(
 
     // Do display mode specific initialization
     quartzProcs->DisplayInit();
-
-    // Init PseudoramiX implementation of Xinerama.
-    // This should be in InitExtensions, but that causes link errors
-    // for servers that don't link in pseudoramiX.c.
-    if (!noPseudoramiXExtension) {
-        PseudoramiXExtensionInit(argc, argv);
-    }
 }
 
 
diff --git a/hw/xquartz/quartzStartup.c b/hw/xquartz/quartzStartup.c
index 8600ec8..1b2a226 100644
--- a/hw/xquartz/quartzStartup.c
+++ b/hw/xquartz/quartzStartup.c
@@ -106,6 +106,6 @@ void DarwinHandleGUI(int argc, char **argv, char **envp) {
     extern void _InitHLTB(void);
     
     _InitHLTB();    
-    X11ControllerMain(argc, argv, server_thread, NULL);
+    X11ControllerMain(argc, (const char **)argv, server_thread, NULL);
     exit(0);
 }
diff --git a/mi/miinitext.c b/mi/miinitext.c
index d06ab8a..319d2ce 100644
--- a/mi/miinitext.c
+++ b/mi/miinitext.c
@@ -206,6 +206,9 @@ extern Bool noXkbExtension;
 #ifdef PANORAMIX
 extern Bool noPanoramiXExtension;
 #endif
+#ifdef INXQUARTZ
+extern Bool noPseudoramiXExtension;
+#endif
 #ifdef XINPUT
 extern Bool noXInputExtension;
 #endif
@@ -274,6 +277,9 @@ extern void MultibufferExtensionInit(INITARGS);
 #ifdef PANORAMIX
 extern void PanoramiXExtensionInit(INITARGS);
 #endif
+#ifdef INXQUARTZ
+extern void PseudoramiXExtensionInit(INITARGS);
+#endif
 #ifdef XINPUT
 extern void XInputExtensionInit(INITARGS);
 #endif
@@ -533,6 +539,9 @@ InitExtensions(argc, argv)
   if (!noPanoramiXExtension) PanoramiXExtensionInit();
 # endif
 #endif
+#ifdef INXQUARTZ
+    if(!noPseudoramiXExtension) PseudoramiXExtensionInit();
+#endif
 #ifdef SHAPE
     if (!noShapeExtension) ShapeExtensionInit();
 #endif
commit fa9680a7305d7f906da1bdeb40a0863ef66316e6
Author: Jeremy Huddleston <jeremy at yuffie.local>
Date:   Thu Dec 20 19:38:20 2007 -0800

    XQuartz: Added localization.
    (cherry picked from commit 7a5cc7bfbb296a2c41a580b063324c448f7131db)

diff --git a/hw/xquartz/bundle/Dutch.lproj/InfoPlist.strings b/hw/xquartz/bundle/Dutch.lproj/InfoPlist.strings
new file mode 100644
index 0000000..8f978d6
Binary files /dev/null and b/hw/xquartz/bundle/Dutch.lproj/InfoPlist.strings differ
diff --git a/hw/xquartz/bundle/Dutch.lproj/Localizable.strings b/hw/xquartz/bundle/Dutch.lproj/Localizable.strings
new file mode 100644
index 0000000..1ff39fe
Binary files /dev/null and b/hw/xquartz/bundle/Dutch.lproj/Localizable.strings differ
diff --git a/hw/xquartz/bundle/Dutch.lproj/main.nib/keyedobjects.nib b/hw/xquartz/bundle/Dutch.lproj/main.nib/keyedobjects.nib
new file mode 100644
index 0000000..95c26d7
Binary files /dev/null and b/hw/xquartz/bundle/Dutch.lproj/main.nib/keyedobjects.nib differ
diff --git a/hw/xquartz/bundle/French.lproj/InfoPlist.strings b/hw/xquartz/bundle/French.lproj/InfoPlist.strings
new file mode 100644
index 0000000..88e1f04
Binary files /dev/null and b/hw/xquartz/bundle/French.lproj/InfoPlist.strings differ
diff --git a/hw/xquartz/bundle/French.lproj/Localizable.strings b/hw/xquartz/bundle/French.lproj/Localizable.strings
new file mode 100644
index 0000000..2770dfb
Binary files /dev/null and b/hw/xquartz/bundle/French.lproj/Localizable.strings differ
diff --git a/hw/xquartz/bundle/French.lproj/main.nib/keyedobjects.nib b/hw/xquartz/bundle/French.lproj/main.nib/keyedobjects.nib
new file mode 100644
index 0000000..9f9a7da
Binary files /dev/null and b/hw/xquartz/bundle/French.lproj/main.nib/keyedobjects.nib differ
diff --git a/hw/xquartz/bundle/German.lproj/InfoPlist.strings b/hw/xquartz/bundle/German.lproj/InfoPlist.strings
new file mode 100644
index 0000000..aa37e75
Binary files /dev/null and b/hw/xquartz/bundle/German.lproj/InfoPlist.strings differ
diff --git a/hw/xquartz/bundle/German.lproj/Localizable.strings b/hw/xquartz/bundle/German.lproj/Localizable.strings
new file mode 100644
index 0000000..a5489ab
Binary files /dev/null and b/hw/xquartz/bundle/German.lproj/Localizable.strings differ
diff --git a/hw/xquartz/bundle/German.lproj/main.nib/keyedobjects.nib b/hw/xquartz/bundle/German.lproj/main.nib/keyedobjects.nib
new file mode 100644
index 0000000..19532a9
Binary files /dev/null and b/hw/xquartz/bundle/German.lproj/main.nib/keyedobjects.nib differ
diff --git a/hw/xquartz/bundle/Italian.lproj/InfoPlist.strings b/hw/xquartz/bundle/Italian.lproj/InfoPlist.strings
new file mode 100644
index 0000000..4121698
Binary files /dev/null and b/hw/xquartz/bundle/Italian.lproj/InfoPlist.strings differ
diff --git a/hw/xquartz/bundle/Italian.lproj/Localizable.strings b/hw/xquartz/bundle/Italian.lproj/Localizable.strings
new file mode 100644
index 0000000..d05d73d
Binary files /dev/null and b/hw/xquartz/bundle/Italian.lproj/Localizable.strings differ
diff --git a/hw/xquartz/bundle/Italian.lproj/main.nib/keyedobjects.nib b/hw/xquartz/bundle/Italian.lproj/main.nib/keyedobjects.nib
new file mode 100644
index 0000000..b6e2e1b
Binary files /dev/null and b/hw/xquartz/bundle/Italian.lproj/main.nib/keyedobjects.nib differ
diff --git a/hw/xquartz/bundle/Japanese.lproj/InfoPlist.strings b/hw/xquartz/bundle/Japanese.lproj/InfoPlist.strings
new file mode 100644
index 0000000..2d6330f
Binary files /dev/null and b/hw/xquartz/bundle/Japanese.lproj/InfoPlist.strings differ
diff --git a/hw/xquartz/bundle/Japanese.lproj/Localizable.strings b/hw/xquartz/bundle/Japanese.lproj/Localizable.strings
new file mode 100644
index 0000000..99821ea
Binary files /dev/null and b/hw/xquartz/bundle/Japanese.lproj/Localizable.strings differ
diff --git a/hw/xquartz/bundle/Japanese.lproj/main.nib/keyedobjects.nib b/hw/xquartz/bundle/Japanese.lproj/main.nib/keyedobjects.nib
new file mode 100644
index 0000000..523fd08
Binary files /dev/null and b/hw/xquartz/bundle/Japanese.lproj/main.nib/keyedobjects.nib differ
diff --git a/hw/xquartz/bundle/Spanish.lproj/InfoPlist.strings b/hw/xquartz/bundle/Spanish.lproj/InfoPlist.strings
new file mode 100644
index 0000000..0e4287d
Binary files /dev/null and b/hw/xquartz/bundle/Spanish.lproj/InfoPlist.strings differ
diff --git a/hw/xquartz/bundle/Spanish.lproj/Localizable.strings b/hw/xquartz/bundle/Spanish.lproj/Localizable.strings
new file mode 100644
index 0000000..652f432
Binary files /dev/null and b/hw/xquartz/bundle/Spanish.lproj/Localizable.strings differ
diff --git a/hw/xquartz/bundle/Spanish.lproj/main.nib/keyedobjects.nib b/hw/xquartz/bundle/Spanish.lproj/main.nib/keyedobjects.nib
new file mode 100644
index 0000000..029349d
Binary files /dev/null and b/hw/xquartz/bundle/Spanish.lproj/main.nib/keyedobjects.nib differ
diff --git a/hw/xquartz/bundle/X11.xcodeproj/project.pbxproj b/hw/xquartz/bundle/X11.xcodeproj/project.pbxproj
index ddb6f83..ae8ec07 100644
--- a/hw/xquartz/bundle/X11.xcodeproj/project.pbxproj
+++ b/hw/xquartz/bundle/X11.xcodeproj/project.pbxproj
@@ -20,6 +20,57 @@
 /* Begin PBXFileReference section */
 		0867D6ABFE840B52C02AAC07 /* English */ = {isa = PBXFileReference; fileEncoding = 10; lastKnownFileType = text.plist.strings; name = English; path = English.lproj/InfoPlist.strings; sourceTree = "<group>"; };
 		1870340FFE93FCAF11CA0CD7 /* English */ = {isa = PBXFileReference; lastKnownFileType = wrapper.nib; name = English; path = English.lproj/main.nib; sourceTree = "<group>"; };
+		3FB03E460D1B6C05005958A5 /* da */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = da; path = da.lproj/Localizable.strings; sourceTree = "<group>"; };
+		3FB03E470D1B6C05005958A5 /* Dutch */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = Dutch; path = Dutch.lproj/Localizable.strings; sourceTree = "<group>"; };
+		3FB03E480D1B6C05005958A5 /* fi */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = fi; path = fi.lproj/Localizable.strings; sourceTree = "<group>"; };
+		3FB03E490D1B6C05005958A5 /* French */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = French; path = French.lproj/Localizable.strings; sourceTree = "<group>"; };
+		3FB03E4A0D1B6C05005958A5 /* German */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = German; path = German.lproj/Localizable.strings; sourceTree = "<group>"; };
+		3FB03E4B0D1B6C05005958A5 /* Italian */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = Italian; path = Italian.lproj/Localizable.strings; sourceTree = "<group>"; };
+		3FB03E4C0D1B6C05005958A5 /* Japanese */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = Japanese; path = Japanese.lproj/Localizable.strings; sourceTree = "<group>"; };
+		3FB03E4D0D1B6C05005958A5 /* ko */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = ko; path = ko.lproj/Localizable.strings; sourceTree = "<group>"; };
+		3FB03E4E0D1B6C05005958A5 /* no */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = no; path = no.lproj/Localizable.strings; sourceTree = "<group>"; };
+		3FB03E4F0D1B6C05005958A5 /* pl */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = pl; path = pl.lproj/Localizable.strings; sourceTree = "<group>"; };
+		3FB03E500D1B6C05005958A5 /* pt */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = pt; path = pt.lproj/Localizable.strings; sourceTree = "<group>"; };
+		3FB03E510D1B6C05005958A5 /* pt_PT */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = pt_PT; path = pt_PT.lproj/Localizable.strings; sourceTree = "<group>"; };
+		3FB03E520D1B6C05005958A5 /* ru */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = ru; path = ru.lproj/Localizable.strings; sourceTree = "<group>"; };
+		3FB03E530D1B6C05005958A5 /* Spanish */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = Spanish; path = Spanish.lproj/Localizable.strings; sourceTree = "<group>"; };
+		3FB03E540D1B6C05005958A5 /* sv */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = sv; path = sv.lproj/Localizable.strings; sourceTree = "<group>"; };
+		3FB03E550D1B6C05005958A5 /* zh_CN */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = zh_CN; path = zh_CN.lproj/Localizable.strings; sourceTree = "<group>"; };
+		3FB03E560D1B6C05005958A5 /* zh_TW */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = zh_TW; path = zh_TW.lproj/Localizable.strings; sourceTree = "<group>"; };
+		3FB03E570D1B6C17005958A5 /* da */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = da; path = da.lproj/InfoPlist.strings; sourceTree = "<group>"; };
+		3FB03E580D1B6C17005958A5 /* Dutch */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = Dutch; path = Dutch.lproj/InfoPlist.strings; sourceTree = "<group>"; };
+		3FB03E590D1B6C17005958A5 /* fi */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = fi; path = fi.lproj/InfoPlist.strings; sourceTree = "<group>"; };
+		3FB03E5A0D1B6C17005958A5 /* French */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = French; path = French.lproj/InfoPlist.strings; sourceTree = "<group>"; };
+		3FB03E5B0D1B6C17005958A5 /* German */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = German; path = German.lproj/InfoPlist.strings; sourceTree = "<group>"; };
+		3FB03E5C0D1B6C17005958A5 /* Italian */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = Italian; path = Italian.lproj/InfoPlist.strings; sourceTree = "<group>"; };
+		3FB03E5D0D1B6C17005958A5 /* Japanese */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = Japanese; path = Japanese.lproj/InfoPlist.strings; sourceTree = "<group>"; };
+		3FB03E5E0D1B6C17005958A5 /* ko */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = ko; path = ko.lproj/InfoPlist.strings; sourceTree = "<group>"; };
+		3FB03E5F0D1B6C17005958A5 /* no */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = no; path = no.lproj/InfoPlist.strings; sourceTree = "<group>"; };
+		3FB03E600D1B6C17005958A5 /* pl */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = pl; path = pl.lproj/InfoPlist.strings; sourceTree = "<group>"; };
+		3FB03E610D1B6C17005958A5 /* pt */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = pt; path = pt.lproj/InfoPlist.strings; sourceTree = "<group>"; };
+		3FB03E620D1B6C17005958A5 /* pt_PT */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = pt_PT; path = pt_PT.lproj/InfoPlist.strings; sourceTree = "<group>"; };
+		3FB03E630D1B6C17005958A5 /* ru */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = ru; path = ru.lproj/InfoPlist.strings; sourceTree = "<group>"; };
+		3FB03E640D1B6C17005958A5 /* Spanish */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = Spanish; path = Spanish.lproj/InfoPlist.strings; sourceTree = "<group>"; };
+		3FB03E650D1B6C17005958A5 /* sv */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = sv; path = sv.lproj/InfoPlist.strings; sourceTree = "<group>"; };
+		3FB03E660D1B6C17005958A5 /* zh_CN */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = zh_CN; path = zh_CN.lproj/InfoPlist.strings; sourceTree = "<group>"; };
+		3FB03E670D1B6C17005958A5 /* zh_TW */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = zh_TW; path = zh_TW.lproj/InfoPlist.strings; sourceTree = "<group>"; };
+		3FB03E680D1B6C34005958A5 /* da */ = {isa = PBXFileReference; lastKnownFileType = wrapper.nib; name = da; path = da.lproj/main.nib; sourceTree = "<group>"; };
+		3FB03E690D1B6C34005958A5 /* Dutch */ = {isa = PBXFileReference; lastKnownFileType = wrapper.nib; name = Dutch; path = Dutch.lproj/main.nib; sourceTree = "<group>"; };
+		3FB03E6A0D1B6C34005958A5 /* fi */ = {isa = PBXFileReference; lastKnownFileType = wrapper.nib; name = fi; path = fi.lproj/main.nib; sourceTree = "<group>"; };
+		3FB03E6B0D1B6C34005958A5 /* French */ = {isa = PBXFileReference; lastKnownFileType = wrapper.nib; name = French; path = French.lproj/main.nib; sourceTree = "<group>"; };
+		3FB03E6C0D1B6C34005958A5 /* German */ = {isa = PBXFileReference; lastKnownFileType = wrapper.nib; name = German; path = German.lproj/main.nib; sourceTree = "<group>"; };
+		3FB03E6D0D1B6C34005958A5 /* Italian */ = {isa = PBXFileReference; lastKnownFileType = wrapper.nib; name = Italian; path = Italian.lproj/main.nib; sourceTree = "<group>"; };
+		3FB03E6E0D1B6C34005958A5 /* Japanese */ = {isa = PBXFileReference; lastKnownFileType = wrapper.nib; name = Japanese; path = Japanese.lproj/main.nib; sourceTree = "<group>"; };
+		3FB03E6F0D1B6C34005958A5 /* ko */ = {isa = PBXFileReference; lastKnownFileType = wrapper.nib; name = ko; path = ko.lproj/main.nib; sourceTree = "<group>"; };
+		3FB03E700D1B6C34005958A5 /* no */ = {isa = PBXFileReference; lastKnownFileType = wrapper.nib; name = no; path = no.lproj/main.nib; sourceTree = "<group>"; };
+		3FB03E710D1B6C34005958A5 /* pl */ = {isa = PBXFileReference; lastKnownFileType = wrapper.nib; name = pl; path = pl.lproj/main.nib; sourceTree = "<group>"; };
+		3FB03E720D1B6C34005958A5 /* pt */ = {isa = PBXFileReference; lastKnownFileType = wrapper.nib; name = pt; path = pt.lproj/main.nib; sourceTree = "<group>"; };
+		3FB03E730D1B6C34005958A5 /* pt_PT */ = {isa = PBXFileReference; lastKnownFileType = wrapper.nib; name = pt_PT; path = pt_PT.lproj/main.nib; sourceTree = "<group>"; };
+		3FB03E740D1B6C34005958A5 /* ru */ = {isa = PBXFileReference; lastKnownFileType = wrapper.nib; name = ru; path = ru.lproj/main.nib; sourceTree = "<group>"; };
+		3FB03E750D1B6C34005958A5 /* Spanish */ = {isa = PBXFileReference; lastKnownFileType = wrapper.nib; name = Spanish; path = Spanish.lproj/main.nib; sourceTree = "<group>"; };
+		3FB03E760D1B6C34005958A5 /* sv */ = {isa = PBXFileReference; lastKnownFileType = wrapper.nib; name = sv; path = sv.lproj/main.nib; sourceTree = "<group>"; };
+		3FB03E770D1B6C34005958A5 /* zh_CN */ = {isa = PBXFileReference; lastKnownFileType = wrapper.nib; name = zh_CN; path = zh_CN.lproj/main.nib; sourceTree = "<group>"; };
+		3FB03E780D1B6C34005958A5 /* zh_TW */ = {isa = PBXFileReference; lastKnownFileType = wrapper.nib; name = zh_TW; path = zh_TW.lproj/main.nib; sourceTree = "<group>"; };
 		50459C5F038587C60ECA21EC /* X11.icns */ = {isa = PBXFileReference; lastKnownFileType = image.icns; path = X11.icns; sourceTree = "<group>"; };
 		50EE2AB703849F0B0ECA21EC /* bundle-main.c */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.c; path = "bundle-main.c"; sourceTree = "<group>"; };
 		50F4F0A7039D6ACA0E82C0CB /* CoreFoundation.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = CoreFoundation.framework; path = /System/Library/Frameworks/CoreFoundation.framework; sourceTree = "<absolute>"; };
@@ -130,6 +181,26 @@
 			buildConfigurationList = 527F24080B5D8FFC007840A7 /* Build configuration list for PBXProject "X11" */;
 			compatibilityVersion = "Xcode 2.4";
 			hasScannedForEncodings = 1;
+			knownRegions = (
+				English,
+				Japanese,
+				French,
+				German,
+				da,
+				Dutch,
+				fi,
+				Italian,
+				ko,
+				no,
+				pl,
+				pt,
+				pt_PT,
+				ru,
+				Spanish,
+				sv,
+				zh_CN,
+				zh_TW,
+			);
 			mainGroup = 20286C29FDCF999611CA2CEA /* X11 */;
 			projectDirPath = "";
 			projectRoot = "";
@@ -180,6 +251,23 @@
 			isa = PBXVariantGroup;
 			children = (
 				1870340FFE93FCAF11CA0CD7 /* English */,
+				3FB03E680D1B6C34005958A5 /* da */,
+				3FB03E690D1B6C34005958A5 /* Dutch */,
+				3FB03E6A0D1B6C34005958A5 /* fi */,
+				3FB03E6B0D1B6C34005958A5 /* French */,
+				3FB03E6C0D1B6C34005958A5 /* German */,
+				3FB03E6D0D1B6C34005958A5 /* Italian */,
+				3FB03E6E0D1B6C34005958A5 /* Japanese */,
+				3FB03E6F0D1B6C34005958A5 /* ko */,
+				3FB03E700D1B6C34005958A5 /* no */,
+				3FB03E710D1B6C34005958A5 /* pl */,
+				3FB03E720D1B6C34005958A5 /* pt */,
+				3FB03E730D1B6C34005958A5 /* pt_PT */,
+				3FB03E740D1B6C34005958A5 /* ru */,
+				3FB03E750D1B6C34005958A5 /* Spanish */,
+				3FB03E760D1B6C34005958A5 /* sv */,
+				3FB03E770D1B6C34005958A5 /* zh_CN */,
+				3FB03E780D1B6C34005958A5 /* zh_TW */,
 			);
 			name = main.nib;
 			sourceTree = "<group>";
@@ -188,6 +276,23 @@
 			isa = PBXVariantGroup;
 			children = (
 				0867D6ABFE840B52C02AAC07 /* English */,
+				3FB03E570D1B6C17005958A5 /* da */,
+				3FB03E580D1B6C17005958A5 /* Dutch */,
+				3FB03E590D1B6C17005958A5 /* fi */,
+				3FB03E5A0D1B6C17005958A5 /* French */,
+				3FB03E5B0D1B6C17005958A5 /* German */,
+				3FB03E5C0D1B6C17005958A5 /* Italian */,
+				3FB03E5D0D1B6C17005958A5 /* Japanese */,
+				3FB03E5E0D1B6C17005958A5 /* ko */,
+				3FB03E5F0D1B6C17005958A5 /* no */,
+				3FB03E600D1B6C17005958A5 /* pl */,
+				3FB03E610D1B6C17005958A5 /* pt */,
+				3FB03E620D1B6C17005958A5 /* pt_PT */,
+				3FB03E630D1B6C17005958A5 /* ru */,
+				3FB03E640D1B6C17005958A5 /* Spanish */,
+				3FB03E650D1B6C17005958A5 /* sv */,
+				3FB03E660D1B6C17005958A5 /* zh_CN */,
+				3FB03E670D1B6C17005958A5 /* zh_TW */,
 			);
 			name = InfoPlist.strings;
 			sourceTree = "<group>";
@@ -196,6 +301,23 @@
 			isa = PBXVariantGroup;
 			children = (
 				52D9C0EC0BCDDF6B00CD2AFC /* English */,
+				3FB03E460D1B6C05005958A5 /* da */,
+				3FB03E470D1B6C05005958A5 /* Dutch */,
+				3FB03E480D1B6C05005958A5 /* fi */,
+				3FB03E490D1B6C05005958A5 /* French */,
+				3FB03E4A0D1B6C05005958A5 /* German */,
+				3FB03E4B0D1B6C05005958A5 /* Italian */,
+				3FB03E4C0D1B6C05005958A5 /* Japanese */,
+				3FB03E4D0D1B6C05005958A5 /* ko */,
+				3FB03E4E0D1B6C05005958A5 /* no */,
+				3FB03E4F0D1B6C05005958A5 /* pl */,
+				3FB03E500D1B6C05005958A5 /* pt */,
+				3FB03E510D1B6C05005958A5 /* pt_PT */,
+				3FB03E520D1B6C05005958A5 /* ru */,
+				3FB03E530D1B6C05005958A5 /* Spanish */,
+				3FB03E540D1B6C05005958A5 /* sv */,
+				3FB03E550D1B6C05005958A5 /* zh_CN */,
+				3FB03E560D1B6C05005958A5 /* zh_TW */,
 			);
 			name = Localizable.strings;
 			sourceTree = "<group>";
diff --git a/hw/xquartz/bundle/da.lproj/InfoPlist.strings b/hw/xquartz/bundle/da.lproj/InfoPlist.strings
new file mode 100644
index 0000000..88e1f04
Binary files /dev/null and b/hw/xquartz/bundle/da.lproj/InfoPlist.strings differ
diff --git a/hw/xquartz/bundle/da.lproj/Localizable.strings b/hw/xquartz/bundle/da.lproj/Localizable.strings
new file mode 100644
index 0000000..9608a2e
Binary files /dev/null and b/hw/xquartz/bundle/da.lproj/Localizable.strings differ
diff --git a/hw/xquartz/bundle/da.lproj/main.nib/keyedobjects.nib b/hw/xquartz/bundle/da.lproj/main.nib/keyedobjects.nib
new file mode 100644
index 0000000..4a2bd4b
Binary files /dev/null and b/hw/xquartz/bundle/da.lproj/main.nib/keyedobjects.nib differ
diff --git a/hw/xquartz/bundle/fi.lproj/InfoPlist.strings b/hw/xquartz/bundle/fi.lproj/InfoPlist.strings
new file mode 100644
index 0000000..8e4f647
Binary files /dev/null and b/hw/xquartz/bundle/fi.lproj/InfoPlist.strings differ
diff --git a/hw/xquartz/bundle/fi.lproj/Localizable.strings b/hw/xquartz/bundle/fi.lproj/Localizable.strings
new file mode 100644
index 0000000..e8420fb
Binary files /dev/null and b/hw/xquartz/bundle/fi.lproj/Localizable.strings differ
diff --git a/hw/xquartz/bundle/fi.lproj/main.nib/keyedobjects.nib b/hw/xquartz/bundle/fi.lproj/main.nib/keyedobjects.nib
new file mode 100644
index 0000000..b5039fd
Binary files /dev/null and b/hw/xquartz/bundle/fi.lproj/main.nib/keyedobjects.nib differ
diff --git a/hw/xquartz/bundle/ko.lproj/InfoPlist.strings b/hw/xquartz/bundle/ko.lproj/InfoPlist.strings
new file mode 100644
index 0000000..4c738f8
Binary files /dev/null and b/hw/xquartz/bundle/ko.lproj/InfoPlist.strings differ
diff --git a/hw/xquartz/bundle/ko.lproj/Localizable.strings b/hw/xquartz/bundle/ko.lproj/Localizable.strings
new file mode 100644
index 0000000..56a3358
Binary files /dev/null and b/hw/xquartz/bundle/ko.lproj/Localizable.strings differ
diff --git a/hw/xquartz/bundle/ko.lproj/main.nib/keyedobjects.nib b/hw/xquartz/bundle/ko.lproj/main.nib/keyedobjects.nib
new file mode 100644
index 0000000..925945c
Binary files /dev/null and b/hw/xquartz/bundle/ko.lproj/main.nib/keyedobjects.nib differ
diff --git a/hw/xquartz/bundle/no.lproj/InfoPlist.strings b/hw/xquartz/bundle/no.lproj/InfoPlist.strings
new file mode 100644
index 0000000..eb1cfb0
Binary files /dev/null and b/hw/xquartz/bundle/no.lproj/InfoPlist.strings differ
diff --git a/hw/xquartz/bundle/no.lproj/Localizable.strings b/hw/xquartz/bundle/no.lproj/Localizable.strings
new file mode 100644
index 0000000..5157a67
Binary files /dev/null and b/hw/xquartz/bundle/no.lproj/Localizable.strings differ
diff --git a/hw/xquartz/bundle/no.lproj/main.nib/keyedobjects.nib b/hw/xquartz/bundle/no.lproj/main.nib/keyedobjects.nib
new file mode 100644
index 0000000..ca25327
Binary files /dev/null and b/hw/xquartz/bundle/no.lproj/main.nib/keyedobjects.nib differ
diff --git a/hw/xquartz/bundle/pl.lproj/InfoPlist.strings b/hw/xquartz/bundle/pl.lproj/InfoPlist.strings
new file mode 100644
index 0000000..b9c9502
Binary files /dev/null and b/hw/xquartz/bundle/pl.lproj/InfoPlist.strings differ
diff --git a/hw/xquartz/bundle/pl.lproj/Localizable.strings b/hw/xquartz/bundle/pl.lproj/Localizable.strings
new file mode 100644
index 0000000..4ae12d7
Binary files /dev/null and b/hw/xquartz/bundle/pl.lproj/Localizable.strings differ
diff --git a/hw/xquartz/bundle/pl.lproj/main.nib/keyedobjects.nib b/hw/xquartz/bundle/pl.lproj/main.nib/keyedobjects.nib
new file mode 100644
index 0000000..e9ca540
Binary files /dev/null and b/hw/xquartz/bundle/pl.lproj/main.nib/keyedobjects.nib differ
diff --git a/hw/xquartz/bundle/pt.lproj/InfoPlist.strings b/hw/xquartz/bundle/pt.lproj/InfoPlist.strings
new file mode 100644
index 0000000..33c6374
Binary files /dev/null and b/hw/xquartz/bundle/pt.lproj/InfoPlist.strings differ
diff --git a/hw/xquartz/bundle/pt.lproj/Localizable.strings b/hw/xquartz/bundle/pt.lproj/Localizable.strings
new file mode 100644
index 0000000..23ea968
Binary files /dev/null and b/hw/xquartz/bundle/pt.lproj/Localizable.strings differ
diff --git a/hw/xquartz/bundle/pt.lproj/main.nib/keyedobjects.nib b/hw/xquartz/bundle/pt.lproj/main.nib/keyedobjects.nib
new file mode 100644
index 0000000..e88cccd
Binary files /dev/null and b/hw/xquartz/bundle/pt.lproj/main.nib/keyedobjects.nib differ
diff --git a/hw/xquartz/bundle/pt_PT.lproj/InfoPlist.strings b/hw/xquartz/bundle/pt_PT.lproj/InfoPlist.strings
new file mode 100644
index 0000000..33c6374
Binary files /dev/null and b/hw/xquartz/bundle/pt_PT.lproj/InfoPlist.strings differ
diff --git a/hw/xquartz/bundle/pt_PT.lproj/Localizable.strings b/hw/xquartz/bundle/pt_PT.lproj/Localizable.strings
new file mode 100644
index 0000000..71c33ad
Binary files /dev/null and b/hw/xquartz/bundle/pt_PT.lproj/Localizable.strings differ
diff --git a/hw/xquartz/bundle/pt_PT.lproj/main.nib/keyedobjects.nib b/hw/xquartz/bundle/pt_PT.lproj/main.nib/keyedobjects.nib
new file mode 100644
index 0000000..a619334
Binary files /dev/null and b/hw/xquartz/bundle/pt_PT.lproj/main.nib/keyedobjects.nib differ
diff --git a/hw/xquartz/bundle/ru.lproj/InfoPlist.strings b/hw/xquartz/bundle/ru.lproj/InfoPlist.strings
new file mode 100644
index 0000000..7f722e4
Binary files /dev/null and b/hw/xquartz/bundle/ru.lproj/InfoPlist.strings differ
diff --git a/hw/xquartz/bundle/ru.lproj/Localizable.strings b/hw/xquartz/bundle/ru.lproj/Localizable.strings
new file mode 100644
index 0000000..3b38112
Binary files /dev/null and b/hw/xquartz/bundle/ru.lproj/Localizable.strings differ
diff --git a/hw/xquartz/bundle/ru.lproj/main.nib/keyedobjects.nib b/hw/xquartz/bundle/ru.lproj/main.nib/keyedobjects.nib
new file mode 100644
index 0000000..9354e02
Binary files /dev/null and b/hw/xquartz/bundle/ru.lproj/main.nib/keyedobjects.nib differ
diff --git a/hw/xquartz/bundle/sv.lproj/InfoPlist.strings b/hw/xquartz/bundle/sv.lproj/InfoPlist.strings
new file mode 100644
index 0000000..655d5ff
Binary files /dev/null and b/hw/xquartz/bundle/sv.lproj/InfoPlist.strings differ
diff --git a/hw/xquartz/bundle/sv.lproj/Localizable.strings b/hw/xquartz/bundle/sv.lproj/Localizable.strings
new file mode 100644
index 0000000..796f06c
Binary files /dev/null and b/hw/xquartz/bundle/sv.lproj/Localizable.strings differ
diff --git a/hw/xquartz/bundle/sv.lproj/main.nib/keyedobjects.nib b/hw/xquartz/bundle/sv.lproj/main.nib/keyedobjects.nib
new file mode 100644
index 0000000..bd01c2d
Binary files /dev/null and b/hw/xquartz/bundle/sv.lproj/main.nib/keyedobjects.nib differ
diff --git a/hw/xquartz/bundle/zh_CN.lproj/InfoPlist.strings b/hw/xquartz/bundle/zh_CN.lproj/InfoPlist.strings
new file mode 100644
index 0000000..b5df368
Binary files /dev/null and b/hw/xquartz/bundle/zh_CN.lproj/InfoPlist.strings differ
diff --git a/hw/xquartz/bundle/zh_CN.lproj/Localizable.strings b/hw/xquartz/bundle/zh_CN.lproj/Localizable.strings
new file mode 100644
index 0000000..f88a6da
Binary files /dev/null and b/hw/xquartz/bundle/zh_CN.lproj/Localizable.strings differ
diff --git a/hw/xquartz/bundle/zh_CN.lproj/main.nib/keyedobjects.nib b/hw/xquartz/bundle/zh_CN.lproj/main.nib/keyedobjects.nib
new file mode 100644
index 0000000..e36c15f
Binary files /dev/null and b/hw/xquartz/bundle/zh_CN.lproj/main.nib/keyedobjects.nib differ
diff --git a/hw/xquartz/bundle/zh_TW.lproj/InfoPlist.strings b/hw/xquartz/bundle/zh_TW.lproj/InfoPlist.strings
new file mode 100644
index 0000000..92d5473
Binary files /dev/null and b/hw/xquartz/bundle/zh_TW.lproj/InfoPlist.strings differ
diff --git a/hw/xquartz/bundle/zh_TW.lproj/Localizable.strings b/hw/xquartz/bundle/zh_TW.lproj/Localizable.strings
new file mode 100644
index 0000000..f009302
Binary files /dev/null and b/hw/xquartz/bundle/zh_TW.lproj/Localizable.strings differ
diff --git a/hw/xquartz/bundle/zh_TW.lproj/main.nib/keyedobjects.nib b/hw/xquartz/bundle/zh_TW.lproj/main.nib/keyedobjects.nib
new file mode 100644
index 0000000..36602c5
Binary files /dev/null and b/hw/xquartz/bundle/zh_TW.lproj/main.nib/keyedobjects.nib differ
commit 603a8b73d46d59e5f9f0be39be8317f3fadfe7e6
Author: Jeremy Huddleston <jeremy at yuffie.local>
Date:   Thu Dec 20 18:29:57 2007 -0800

    XQuartz: Cleaned up command line arguments.

diff --git a/hw/xquartz/darwin.c b/hw/xquartz/darwin.c
index d6eb100..4630734 100644
--- a/hw/xquartz/darwin.c
+++ b/hw/xquartz/darwin.c
@@ -701,20 +701,15 @@ void ddxInitGlobals(void)
  */
 int ddxProcessArgument( int argc, char *argv[], int i )
 {
-    if( !strcmp( argv[i], "-launchd" ) ) {
-        ErrorF( "Launchd command line argument noticed.\n" );
-        return 1;
-    }
-
-    if ( !strcmp( argv[i], "-fullscreen" ) ) {
-        ErrorF( "Running full screen in parallel with Mac OS X Quartz window server.\n" );
-        return 1;
-    }
+//    if ( !strcmp( argv[i], "-fullscreen" ) ) {
+//        ErrorF( "Running full screen in parallel with Mac OS X Quartz window server.\n" );
+//        return 1;
+//    }
 
-    if ( !strcmp( argv[i], "-rootless" ) ) {
-        ErrorF( "Running rootless inside Mac OS X window server.\n" );
-        return 1;
-    }
+//    if ( !strcmp( argv[i], "-rootless" ) ) {
+//        ErrorF( "Running rootless inside Mac OS X window server.\n" );
+//        return 1;
+//    }
 
     // This command line arg is passed when launched from the Aqua GUI.
     if ( !strncmp( argv[i], "-psn_", 5 ) ) {
@@ -838,12 +833,6 @@ int ddxProcessArgument( int argc, char *argv[], int i )
         exit(0);
     }
 
-    // XDarwinStartup uses this argument to indicate the IOKit X server
-    // should be started. Ignore it here.
-    if ( !strcmp( argv[i], "-iokit" ) ) {
-        return 1;
-    }
-
     return 0;
 }
 
commit 4cf3002b6020024f2fc2ed0cc40a872a066e482d
Author: Jeremy Huddleston <jeremy at yuffie.local>
Date:   Thu Dec 20 18:08:40 2007 -0800

    XQuartz: Kill off server-main.c and launcher-main.c
    Now using xinit
    (cherry picked from commit 5d6ae3d299f72df714117948b3d31dcbddf6c0bc)

diff --git a/hw/xquartz/bundle/X11.xcodeproj/project.pbxproj b/hw/xquartz/bundle/X11.xcodeproj/project.pbxproj
index 9d5c5d6..ddb6f83 100644
--- a/hw/xquartz/bundle/X11.xcodeproj/project.pbxproj
+++ b/hw/xquartz/bundle/X11.xcodeproj/project.pbxproj
@@ -7,7 +7,6 @@
 	objects = {
 
 /* Begin PBXBuildFile section */
-		3F5E1BE10D04BF110020CA24 /* server-main.c in Sources */ = {isa = PBXBuildFile; fileRef = 3F5E1BDF0D04BF110020CA24 /* server-main.c */; };
 		527F24190B5D938C007840A7 /* InfoPlist.strings in Resources */ = {isa = PBXBuildFile; fileRef = 0867D6AAFE840B52C02AAC07 /* InfoPlist.strings */; };
 		527F241A0B5D938C007840A7 /* main.nib in Resources */ = {isa = PBXBuildFile; fileRef = 02345980000FD03B11CA0E72 /* main.nib */; };
 		527F241B0B5D938C007840A7 /* X11.icns in Resources */ = {isa = PBXBuildFile; fileRef = 50459C5F038587C60ECA21EC /* X11.icns */; };
@@ -21,7 +20,6 @@
 /* Begin PBXFileReference section */
 		0867D6ABFE840B52C02AAC07 /* English */ = {isa = PBXFileReference; fileEncoding = 10; lastKnownFileType = text.plist.strings; name = English; path = English.lproj/InfoPlist.strings; sourceTree = "<group>"; };
 		1870340FFE93FCAF11CA0CD7 /* English */ = {isa = PBXFileReference; lastKnownFileType = wrapper.nib; name = English; path = English.lproj/main.nib; sourceTree = "<group>"; };
-		3F5E1BDF0D04BF110020CA24 /* server-main.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = "server-main.c"; sourceTree = "<group>"; };
 		50459C5F038587C60ECA21EC /* X11.icns */ = {isa = PBXFileReference; lastKnownFileType = image.icns; path = X11.icns; sourceTree = "<group>"; };
 		50EE2AB703849F0B0ECA21EC /* bundle-main.c */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.c; path = "bundle-main.c"; sourceTree = "<group>"; };
 		50F4F0A7039D6ACA0E82C0CB /* CoreFoundation.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = CoreFoundation.framework; path = /System/Library/Frameworks/CoreFoundation.framework; sourceTree = "<absolute>"; };
@@ -67,7 +65,6 @@
 		20286C2AFDCF999611CA2CEA /* Sources */ = {
 			isa = PBXGroup;
 			children = (
-				3F5E1BDF0D04BF110020CA24 /* server-main.c */,
 				50EE2AB703849F0B0ECA21EC /* bundle-main.c */,
 			);
 			name = Sources;
@@ -173,7 +170,6 @@
 			buildActionMask = 2147483647;
 			files = (
 				527F241D0B5D938C007840A7 /* bundle-main.c in Sources */,
-				3F5E1BE10D04BF110020CA24 /* server-main.c in Sources */,
 			);
 			runOnlyForDeploymentPostprocessing = 0;
 		};
diff --git a/hw/xquartz/bundle/bundle-main.c b/hw/xquartz/bundle/bundle-main.c
index ed41e68..cd74cea 100644
--- a/hw/xquartz/bundle/bundle-main.c
+++ b/hw/xquartz/bundle/bundle-main.c
@@ -36,10 +36,11 @@
 
 #include <CoreFoundation/CoreFoundation.h>
 
-#define DEFAULT_APP "/usr/X11/bin/xterm"
+#define DEFAULT_CLIENT "/usr/X11/bin/xterm"
+#define DEFAULT_STARTX "/usr/X11/bin/startx"
 
 static int launcher_main(int argc, char **argv);
-int server_main(int argc, char **argv);
+static int server_main(int argc, char **argv);
 
 int main(int argc, char **argv) {
     Display *display;
@@ -57,7 +58,7 @@ int main(int argc, char **argv) {
         /* Now, try to open a display, if so, run the launcher */
         display = XOpenDisplay(NULL);
         if(display) {
-            fprintf(stderr, "X11.app: closing the display and sleeping for 2s to allow the X server to start up.\n");
+            fprintf(stderr, "X11.app: Closing the display and sleeping for 2s to allow the X server to start up.\n");
             /* Could open the display, start the launcher */
             XCloseDisplay(display);
             
@@ -70,29 +71,13 @@ int main(int argc, char **argv) {
     }
     
     /* Start the server */
-    fprintf(stderr, "X11.app: main(): running server_main()");
+    fprintf(stderr, "X11.app: Could not connect to server.  Starting X server.");
     return server_main(argc, argv);
 }
 
-int launcher_main (int argc, char **argv) {
-    char *command = DEFAULT_APP;
+static int myexecvp(const char *command) {
     const char *newargv[7];
-    int child;
     const char **s;
-    
-	CFPropertyListRef PlistRef = CFPreferencesCopyAppValue(CFSTR("app_to_run"), kCFPreferencesCurrentApplication);
-	
-	if ((PlistRef == NULL) || (CFGetTypeID(PlistRef) != CFStringGetTypeID())) {
-		CFPreferencesSetAppValue(CFSTR("app_to_run"), CFSTR(DEFAULT_APP), kCFPreferencesCurrentApplication);
-		CFPreferencesAppSynchronize(kCFPreferencesCurrentApplication);
-	} else {
-		int len = CFStringGetLength((CFStringRef)PlistRef)+1;
-		command = (char *)malloc(len);
-		CFStringGetCString((CFStringRef)PlistRef, command, len,  kCFStringEncodingASCII);
-		fprintf(stderr, "command=%s\n", command);
-	}
-
-	if (PlistRef) CFRelease(PlistRef);
 
 	newargv[0] = "/usr/bin/login";
 	newargv[1] = "-fp";
@@ -102,7 +87,7 @@ int launcher_main (int argc, char **argv) {
 	newargv[5] = command;
 	newargv[6] = NULL;
 
-    fprintf(stderr, "X11.app: Launching X11 Application:\n");
+    fprintf(stderr, "X11.app: Launching %s:\n", command);
     for(s=newargv; *s; s++) {
         fprintf(stderr, "\targv[%d] = %s\n", s - newargv, *s);
     }
@@ -111,3 +96,43 @@ int launcher_main (int argc, char **argv) {
     perror ("X11.app: Couldn't exec.");
     return(1);
 }
+
+int launcher_main (int argc, char **argv) {
+    char *command = DEFAULT_CLIENT;
+    
+	CFPropertyListRef PlistRef = CFPreferencesCopyAppValue(CFSTR("app_to_run"), kCFPreferencesCurrentApplication);
+	
+	if ((PlistRef == NULL) || (CFGetTypeID(PlistRef) != CFStringGetTypeID())) {
+		CFPreferencesSetAppValue(CFSTR("app_to_run"), CFSTR(DEFAULT_CLIENT), kCFPreferencesCurrentApplication);
+		CFPreferencesAppSynchronize(kCFPreferencesCurrentApplication);
+	} else {
+        int len = CFStringGetLength((CFStringRef)PlistRef)+1;
+		command = (char *)malloc(len);
+		CFStringGetCString((CFStringRef)PlistRef, command, len,  kCFStringEncodingASCII);
+	}
+
+	if (PlistRef)
+        CFRelease(PlistRef);
+
+    return myexecvp(command);
+}
+
+int server_main (int argc, char **argv) {
+    char *command = DEFAULT_STARTX;
+
+	CFPropertyListRef PlistRef = CFPreferencesCopyAppValue(CFSTR("startx_script"), kCFPreferencesCurrentApplication);
+	
+	if ((PlistRef == NULL) || (CFGetTypeID(PlistRef) != CFStringGetTypeID())) {
+		CFPreferencesSetAppValue(CFSTR("startx_script"), CFSTR(DEFAULT_STARTX), kCFPreferencesCurrentApplication);
+		CFPreferencesAppSynchronize(kCFPreferencesCurrentApplication);
+	} else {
+        int len = CFStringGetLength((CFStringRef)PlistRef)+1;
+		command = (char *)malloc(len);
+		CFStringGetCString((CFStringRef)PlistRef, command, len,  kCFStringEncodingASCII);
+	}
+    
+	if (PlistRef)
+        CFRelease(PlistRef);
+    
+    return myexecvp(command);
+}
diff --git a/hw/xquartz/bundle/launcher-main.c b/hw/xquartz/bundle/launcher-main.c
deleted file mode 100644
index 60a1624..0000000
--- a/hw/xquartz/bundle/launcher-main.c
+++ /dev/null
@@ -1,81 +0,0 @@
-/* main.c -- X application launcher
- 
- Copyright (c) 2007 Apple Inc.
- 
- Permission is hereby granted, free of charge, to any person
- obtaining a copy of this software and associated documentation files
- (the "Software"), to deal in the Software without restriction,
- including without limitation the rights to use, copy, modify, merge,
- publish, distribute, sublicense, and/or sell copies of the Software,
- and to permit persons to whom the Software is furnished to do so,
- subject to the following conditions:
- 
- The above copyright notice and this permission notice shall be
- included in all copies or substantial portions of the Software.
- 
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
- EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
- MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
- NONINFRINGEMENT.  IN NO EVENT SHALL THE ABOVE LISTED COPYRIGHT
- HOLDER(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
- WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
- DEALINGS IN THE SOFTWARE.
- 
- Except as contained in this notice, the name(s) of the above
- copyright holders shall not be used in advertising or otherwise to
- promote the sale, use or other dealings in this Software without
- prior written authorization. */
-
-#include <stdio.h>
-#include <unistd.h>
-#include <stdlib.h>
-
-#include <CoreFoundation/CoreFoundation.h>
-
-#define DEFAULT_APP "/usr/X11/bin/xterm"
-
-int launcher_main (int argc, char **argv) {
-  char *command = DEFAULT_APP;
-  const char *newargv[7];
-  int child;
-  
-
-	CFPropertyListRef PlistRef = CFPreferencesCopyAppValue(CFSTR("app_to_run"),
-									kCFPreferencesCurrentApplication);
-	
-	if ((PlistRef == NULL) || (CFGetTypeID(PlistRef) != CFStringGetTypeID())) {
-		CFPreferencesSetAppValue(CFSTR("app_to_run"), CFSTR(DEFAULT_APP), 
-								 kCFPreferencesCurrentApplication);
-		CFPreferencesAppSynchronize(kCFPreferencesCurrentApplication);
-	} else {
-		int len = CFStringGetLength((CFStringRef)PlistRef)+1;
-		command = (char *) malloc(len);
-		CFStringGetCString((CFStringRef)PlistRef, command, len,  kCFStringEncodingASCII);
-		fprintf(stderr, "command=%s\n", command);
-	}
-	
-	if (PlistRef) CFRelease(PlistRef);
-	
-	newargv[0] = "/usr/bin/login";
-	newargv[1] = "-fp";
-	newargv[2] = getlogin();
-	newargv[3] = "/bin/sh";
-	newargv[4] = "-c";
-	newargv[5] = command;
-	newargv[6] = NULL;
-
-    child = fork();
-	
-    switch (child) {
-    case -1:				/* error */
-      perror ("fork");
-      return EXIT_FAILURE;		
-    case 0:				    /* child */
-      execvp (newargv[0], (char **const) newargv);
-      perror ("Couldn't exec");
-      _exit (1);
-   }
-	
-    return 0;
-}
diff --git a/hw/xquartz/bundle/server-main.c b/hw/xquartz/bundle/server-main.c
deleted file mode 100644
index 7e1bd70..0000000
--- a/hw/xquartz/bundle/server-main.c
+++ /dev/null
@@ -1,903 +0,0 @@
-/* bundle-main.c -- X server launcher
- 
- Copyright (c) 2002-2007 Apple Inc. All rights reserved.
- 
- Permission is hereby granted, free of charge, to any person
- obtaining a copy of this software and associated documentation files
- (the "Software"), to deal in the Software without restriction,
- including without limitation the rights to use, copy, modify, merge,
- publish, distribute, sublicense, and/or sell copies of the Software,
- and to permit persons to whom the Software is furnished to do so,
- subject to the following conditions:
- 
- The above copyright notice and this permission notice shall be
- included in all copies or substantial portions of the Software.
- 
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
- EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
- MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
- NONINFRINGEMENT.  IN NO EVENT SHALL THE ABOVE LISTED COPYRIGHT
- HOLDER(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
- WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
- DEALINGS IN THE SOFTWARE.
- 
- Except as contained in this notice, the name(s) of the above
- copyright holders shall not be used in advertising or otherwise to
- promote the sale, use or other dealings in this Software without
- prior written authorization.
- 
- Parts of this file are derived from xdm, which has this copyright:
- 
- Copyright 1988, 1998  The Open Group
- 
- Permission to use, copy, modify, distribute, and sell this software
- and its documentation for any purpose is hereby granted without fee,
- provided that the above copyright notice appear in all copies and
- that both that copyright notice and this permission notice appear in
- supporting documentation.
- 
- The above copyright notice and this permission notice shall be
- included in all copies or substantial portions of the Software.
- 
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
- EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
- MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
- NONINFRINGEMENT. IN NO EVENT SHALL THE OPEN GROUP BE LIABLE FOR ANY
- CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
- TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
- SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
- 
- Except as contained in this notice, the name of The Open Group shall
- not be used in advertising or otherwise to promote the sale, use or
- other dealings in this Software without prior written authorization
- from The Open Group. */
-
-#include <stdio.h>
-#include <unistd.h>
-#include <stdlib.h>
-#include <fcntl.h>
-#include <errno.h>
-#include <sys/socket.h>
-#include <sys/utsname.h>
-#include <ifaddrs.h>
-#include <netdb.h>
-#include <netinet/in.h>
-#include <time.h>
-#include <sys/wait.h>
-#include <setjmp.h>
-#include <sys/ioctl.h>
-
-#include <X11/Xlib.h>
-#include <X11/Xauth.h>
-#include <xcb/xcb.h>
-
-#include <CoreFoundation/CoreFoundation.h>
-#include <SystemConfiguration/SystemConfiguration.h>
-
-#define X_SERVER "/usr/X11/bin/Xquartz"
-#define XTERM_PATH "/usr/X11/bin/xterm"
-#define WM_PATH "/usr/bin/quartz-wm"
-#define DEFAULT_XINITRC "/usr/X11/lib/X11/xinit/xinitrc"
-#define DEFAULT_PATH "/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/X11/bin"
-
-/* what xinit does */
-#ifndef SHELL
-# define SHELL "sh"
-#endif
-
-#undef FALSE
-#define FALSE 0
-#undef TRUE
-#define TRUE 1
-
-#define MAX_DISPLAYS 64
-
-static int server_pid = -1, client_pid = -1;
-static int xinit_kills_server = FALSE;
-static jmp_buf exit_continuation;
-static const char *server_name = NULL;
-static Display *server_dpy;
-
-static char *auth_file;
-
-typedef struct addr_list_struct addr_list;
-
-struct addr_list_struct {
-    addr_list *next;
-    Xauth auth;
-};
-
-static addr_list *addresses;
-
-
-/* Utility functions. */
-
-/* Return the current host name. Matches what Xlib does. */
-static char *
-host_name (void)
-{
-#ifdef NEED_UTSNAME
-    static struct utsname name;
-	
-    uname(&name);
-	
-    return name.nodename;
-#else
-    static char buf[100];
-	
-    gethostname(buf, sizeof(buf));
-	
-    return buf;
-#endif
-}
-
-static int
-read_boolean_pref (CFStringRef name, int default_)
-{
-    int value;
-    Boolean ok;
-	
-    value = CFPreferencesGetAppBooleanValue (name, CFSTR ("org.x.X11"), &ok);
-    return ok ? value : default_;
-}
-
-static inline int
-binary_equal (const void *a, const void *b, int length)
-{
-    return memcmp (a, b, length) == 0;
-}
-
-static inline void *
-binary_dup (const void *a, int length)
-{
-    void *b = malloc (length);
-    if (b != NULL)
-		memcpy (b, a, length);
-    return b;
-}
-
-static inline void
-binary_free (void *data, int length)
-{
-    if (data != NULL)
-		free (data);
-}
-
-
-/* Functions for managing the authentication entries. */
-
-/* Returns true if something matching AUTH is in our list of auth items */
-static int
-check_auth_item (Xauth *auth)
-{
-    addr_list *a;
-	
-    for (a = addresses; a != NULL; a = a->next)
-    {
-		if (a->auth.family == auth->family
-			&& a->auth.address_length == auth->address_length
-			&& binary_equal (a->auth.address, auth->address, auth->address_length)
-			&& a->auth.number_length == auth->number_length
-			&& binary_equal (a->auth.number, auth->number, auth->number_length)
-			&& a->auth.name_length == auth->name_length
-			&& binary_equal (a->auth.name, auth->name, auth->name_length))
-		{
-			return TRUE;
-		}
-    }
-	
-    return FALSE;
-}
-
-/* Add one item to our list of auth items. */
-static void
-add_auth_item (Xauth *auth)
-{
-    addr_list *a = malloc (sizeof (addr_list));
-	
-    a->auth.family = auth->family;
-    a->auth.address_length = auth->address_length;
-    a->auth.address = binary_dup (auth->address, auth->address_length);
-    a->auth.number_length = auth->number_length;
-    a->auth.number = binary_dup (auth->number, auth->number_length);
-    a->auth.name_length = auth->name_length;
-    a->auth.name = binary_dup (auth->name, auth->name_length);
-    a->auth.data_length = auth->data_length;
-    a->auth.data = binary_dup (auth->data, auth->data_length);
-	
-    a->next = addresses;
-    addresses = a;
-}
-
-/* Free all allocated auth items. */
-static void
-free_auth_items (void)
-{
-    addr_list *a;
-	
-    while ((a = addresses) != NULL)
-    {
-		addresses = a->next;
-		
-		binary_free (a->auth.address, a->auth.address_length);
-		binary_free (a->auth.number, a->auth.number_length);
-		binary_free (a->auth.name, a->auth.name_length);
-		binary_free (a->auth.data, a->auth.data_length);
-		free (a);
-    }
-}
-
-/* Add the unix domain auth item. */
-static void
-define_local (Xauth *auth)
-{
-    char *host = host_name ();
-	
-#ifdef DEBUG
-    fprintf (stderr, "x11: hostname is %s\n", host);
-#endif
-	
-    auth->family = FamilyLocal;
-    auth->address_length = strlen (host);
-    auth->address = host;
-	
-    add_auth_item (auth);
-}
-
-/* Add the tcp auth item. */
-static void
-define_named (Xauth *auth, const char *name)
-{
-    struct ifaddrs *addrs, *ptr;
-	
-    if (getifaddrs (&addrs) != 0)
-		return;
-	
-    for (ptr = addrs; ptr != NULL; ptr = ptr->ifa_next)
-    {
-		if (ptr->ifa_addr->sa_family != AF_INET)
-			continue;
-		
-		auth->family = FamilyInternet;
-		auth->address_length = sizeof (struct in_addr);
-		auth->address = (char *) &(((struct sockaddr_in *) ptr->ifa_addr)->sin_addr);
-		
-#ifdef DEBUG
-		fprintf (stderr, "x11: ipaddr is %d.%d.%d.%d\n",
-				 (unsigned char) auth->address[0],
-				 (unsigned char) auth->address[1],
-				 (unsigned char) auth->address[2],
-				 (unsigned char) auth->address[3]);
-#endif
-		
-		add_auth_item (auth);
-    }
-	
-    freeifaddrs (addrs);
-}
-
-/* Parse the display number from NAME and add it to AUTH. */
-static void
-set_auth_number (Xauth *auth, const char *name)
-{
-    char *colon;
-    char *dot, *number;
-	
-    colon = strrchr(name, ':');
-    if (colon != NULL)
-    {
-		colon++;
-		dot = strchr(colon, '.');
-		
-		if (dot != NULL)
-			auth->number_length = dot - colon;
-		else
-			auth->number_length = strlen (colon);
-		
-		number = malloc (auth->number_length + 1);
-		if (number != NULL)
-		{
-			strncpy (number, colon, auth->number_length);
-			number[auth->number_length] = '\0';
-		}
-		else
-		{
-			auth->number_length = 0;
-		}
-		
-		auth->number = number;
-    }
-}
-
-/* Put 128 bits of random data into DATA. If possible, it will be "high
- quality" */
-static int
-generate_mit_magic_cookie (char data[16])
-{
-    int fd, ret, i;
-    long *ldata = (long *) data;
-	
-    fd = open ("/dev/random", O_RDONLY);
-    if (fd > 0) {
-		ret = read (fd, data, 16);
-		close (fd);
-		if (ret == 16) return TRUE;
-    }
-	
-    /* fall back to the usual crappy rng */
-	
-    srand48 (getpid () ^ time (NULL));
-	
-    for (i = 0; i < 4; i++)
-		ldata[i] = lrand48 ();
-	
-    return TRUE;
-}
-
-/* Create the keys we'll be using for the display named NAME. */
-static int
-make_auth_keys (const char *name)
-{
-    Xauth auth;
-    char key[16];
-	
-    if (auth_file == NULL)
-		return FALSE;
-	
-    auth.name = "MIT-MAGIC-COOKIE-1";
-    auth.name_length = strlen (auth.name);
-	
-    if (!generate_mit_magic_cookie (key))
-    {
-		auth_file = NULL;
-		return FALSE;
-    }
-	
-    auth.data = key;
-    auth.data_length = 16;
-	
-    set_auth_number (&auth, name);
-	
-    define_named (&auth, host_name ());
-    define_local (&auth);
-	
-    free (auth.number);
-	
-    return TRUE;
-}
-
-/* If ADD-ENTRIES is true, merge our auth entries into the existing
- Xauthority file. If ADD-ENTRIES is false, remove our entries. */
-static int
-write_auth_file (int add_entries)
-{
-    char *home, newname[1024];
-    int fd, ret;
-    FILE *new_fh, *old_fh;
-    addr_list *addr;
-    Xauth *auth;
-	
-    if (auth_file == NULL)
-		return FALSE;
-	
-    home = getenv ("HOME");
-    if (home == NULL)
-    {
-		auth_file = NULL;
-		return FALSE;
-    }
-	
-    snprintf (newname, sizeof (newname), "%s/.XauthorityXXXXXX", home);
-    mktemp (newname);
-	
-    if (XauLockAuth (auth_file, 1, 2, 10) != LOCK_SUCCESS)
-    {
-		/* FIXME: do something here? */
-		
-		auth_file = NULL;
-		return FALSE;
-    }
-	
-    fd = open (newname, O_WRONLY | O_CREAT | O_TRUNC, 0600);
-    if (fd >= 0)
-    {
-		new_fh = fdopen (fd, "w");
-		if (new_fh != NULL)
-		{
-			if (add_entries)
-			{
-				for (addr = addresses; addr != NULL; addr = addr->next)
-				{
-					XauWriteAuth (new_fh, &addr->auth);
-				}
-			}
-			
-			old_fh = fopen (auth_file, "r");
-			if (old_fh != NULL)
-			{
-				while ((auth = XauReadAuth (old_fh)) != NULL)
-				{
-					if (!check_auth_item (auth))
-						XauWriteAuth (new_fh, auth);
-					XauDisposeAuth (auth);
-				}
-				fclose (old_fh);
-			}
-			
-			fclose (new_fh);
-			unlink (auth_file);
-			
-			ret = rename (newname, auth_file);
-			
-			if (ret != 0)
-				auth_file = NULL;
-			
-			XauUnlockAuth (auth_file);
-			return ret == 0;
-		}
-		
-		close (fd);
-    }
-	
-    XauUnlockAuth (auth_file);
-    auth_file = NULL;
-    return FALSE;
-}
-
-
-/* Subprocess management functions. */
-
-static int
-start_server (char **xargv)
-{
-    int child;
-	
-    child = fork ();
-	
-    switch (child)
-    {
-    case -1:				/* error */
-		perror ("fork");
-		return FALSE;
-		
-    case 0:				/* child */
-		execv (X_SERVER, xargv);
-		perror ("Couldn't exec " X_SERVER);
-		_exit (1);
-		
-    default:				/* parent */
-		server_pid = child;
-		return TRUE;
-    }
-}
-
-static int
-wait_for_server (void)
-{
-    int count = 100;
-	
-    while (count-- > 0)
-    {
-		int status;
-		
-		server_dpy = XOpenDisplay (server_name);
-		if (server_dpy != NULL)
-			return TRUE;
-		
-		if (waitpid (server_pid, &status, WNOHANG) == server_pid)
-			return FALSE;
-		
-		sleep (1);
-    }
-	
-    return FALSE;
-}
-
-static int
-start_client (void)
-{
-    int child;
-	
-    child = fork();
-	
-    switch (child) {
-		char *temp, buf[1024];		
-
-	case -1:				/* error */
-		perror("fork");
-		return FALSE;
-
-	case 0:					/* child */
-		/* Setup environment */
-		temp = getenv("DISPLAY");
-//		if (temp == NULL && temp[0] != 0)
-			setenv("DISPLAY", server_name, TRUE);
-
-		temp = getenv("PATH");
-		if (temp == NULL || temp[0] == 0) 
-			setenv ("PATH", DEFAULT_PATH, TRUE);
-		else if (strnstr(temp, "/usr/X11/bin", sizeof(temp)) == NULL) {
-			snprintf(buf, sizeof(buf), "%s:/usr/X11/bin", temp);		
-			setenv("PATH", buf, TRUE);	
-		}
-		
-		/* First try value of $XINITRC, if set. */
-		temp = getenv("XINITRC");
-		if (temp != NULL && temp[0] != 0 && access(temp, R_OK) == 0)
-			execlp (SHELL, SHELL, temp, NULL);
-
-		/* Then look for .xinitrc in user's home directory. */
-		temp = getenv("HOME");
-		if (temp != NULL && temp[0] != 0) {
-			chdir(temp);
-			snprintf (buf, sizeof (buf), "%s/.xinitrc", temp);
-			if (access(buf, R_OK) == 0)
-				execlp(SHELL, SHELL, buf, NULL);
-		}
-		
-		/* Then try the default xinitrc in the lib directory. */
-		
-		if (access(DEFAULT_XINITRC, R_OK) == 0)
-			execlp(SHELL, SHELL, DEFAULT_XINITRC, NULL);
-		
-		/* Then fallback to hardcoding an xterm and the window manager. */
-		
-		//		system(XTERM_PATH " &");
-		execl(WM_PATH, WM_PATH, NULL);
-		
-		perror("exec");
-		_exit(1);
-		
-    default:				/* parent */
-		client_pid = child;
-		return TRUE;
-    }
-}
-
-static void
-sigchld_handler (int sig)
-{
-    int pid, status;
-	
-	again:
-    pid = waitpid (WAIT_ANY, &status, WNOHANG);
-	
-    if (pid > 0)
-    {
-		if (pid == server_pid)
-		{
-			server_pid = -1;
-			
-			if (client_pid >= 0)
-				kill (client_pid, SIGTERM);
-		}
-		else if (pid == client_pid)
-		{
-			client_pid = -1;
-			
-			if (server_pid >= 0 && xinit_kills_server)
-				kill (server_pid, SIGTERM);
-		}
-		goto again;
-    }
-	
-    if (server_pid == -1 && client_pid == -1)
-		longjmp (exit_continuation, 1);
-	
-    signal (SIGCHLD, sigchld_handler);
-}
-
-
-/* Server utilities. */
-
-static Boolean
-display_exists_p (int number)
-{
-    char buf[64];
-    xcb_connection_t *conn;
-    char *fullname = NULL;
-    int idisplay, iscreen;
-    char *conn_auth_name, *conn_auth_data;
-    int conn_auth_namelen, conn_auth_datalen;
-    
-    //    extern void *_X11TransConnectDisplay ();
-    //    extern void _XDisconnectDisplay ();
-	
-    /* Since connecting to the display waits for a few seconds if the
-	 display doesn't exist, check for trivial non-existence - if the
-	 socket in /tmp exists or not.. (note: if the socket exists, the
-	 server may still not, so we need to try to connect in that case..) */
-	
-    sprintf (buf, "/tmp/.X11-unix/X%d", number);
-    if (access (buf, F_OK) != 0)
-		return FALSE;
-    
-    sprintf (buf, ":%d", number);
-    conn = xcb_connect(buf, NULL);
-    if (xcb_connection_has_error(conn)) return FALSE;
-	
-    xcb_disconnect(conn);
-    return TRUE;
-}
-
-
-/* Monitoring when the system's ip addresses change. */
-
-static Boolean pending_timer;
-
-static void
-timer_callback (CFRunLoopTimerRef timer, void *info)
-{
-    pending_timer = FALSE;
-	
-    /* Update authentication names. Need to write .Xauthority file first
-	 without the existing entries, then again with the new entries.. */
-	
-    write_auth_file (FALSE);
-	
-    free_auth_items ();
-    make_auth_keys (server_name);
-	
-    write_auth_file (TRUE);
-}
-
-/* This function is called when the system's ip addresses may have changed. */
-static void
-ipaddr_callback (SCDynamicStoreRef store, CFArrayRef changed_keys, void *info)
-{
-#if DEBUG
-    if (changed_keys != NULL) {
-		fprintf (stderr, "x11: changed sc keys: ");
-		CFShow (changed_keys);
-    }
-#endif
-
-    if (auth_file != NULL && !pending_timer)
-    {
-		CFRunLoopTimerRef timer;
-		
-		timer = CFRunLoopTimerCreate (NULL, CFAbsoluteTimeGetCurrent () + 1.0,
-									  0.0, 0, 0, timer_callback, NULL);
-		CFRunLoopAddTimer (CFRunLoopGetCurrent (), timer,
-						   kCFRunLoopDefaultMode);
-		CFRelease (timer);
-		
-		pending_timer = TRUE;
-    }
-}
-
-/* This code adapted from "Living in a Dynamic TCP/IP Environment" technote. */
-static Boolean
-install_ipaddr_source (void)
-{
-    CFRunLoopSourceRef source = NULL;
-	
-    SCDynamicStoreContext context = {0};
-    SCDynamicStoreRef ref;
-	
-    ref = SCDynamicStoreCreate (NULL,
-								CFSTR ("AddIPAddressListChangeCallbackSCF"),
-								ipaddr_callback, &context);
-	
-    if (ref != NULL)
-    {
-		const void *keys[4], *patterns[2];
-		int i;
-		
-		keys[0] = SCDynamicStoreKeyCreateNetworkGlobalEntity (NULL, kSCDynamicStoreDomainState, kSCEntNetIPv4);
-		keys[1] = SCDynamicStoreKeyCreateNetworkGlobalEntity (NULL, kSCDynamicStoreDomainState, kSCEntNetIPv6);
-		keys[2] = SCDynamicStoreKeyCreateComputerName (NULL);
-		keys[3] = SCDynamicStoreKeyCreateHostNames (NULL);
-		
-		patterns[0] = SCDynamicStoreKeyCreateNetworkInterfaceEntity (NULL, kSCDynamicStoreDomainState, kSCCompAnyRegex, kSCEntNetIPv4);
-		patterns[1] = SCDynamicStoreKeyCreateNetworkInterfaceEntity (NULL, kSCDynamicStoreDomainState, kSCCompAnyRegex, kSCEntNetIPv6);
-		
-		if (keys[0] != NULL && keys[1] != NULL && keys[2] != NULL
-			&& keys[3] != NULL && patterns[0] != NULL && patterns[1] != NULL)
-		{
-			CFArrayRef key_array, pattern_array;
-			
-			key_array = CFArrayCreate (NULL, keys, 4, &kCFTypeArrayCallBacks);
-			pattern_array = CFArrayCreate (NULL, patterns, 2, &kCFTypeArrayCallBacks);
-			
-			if (key_array != NULL || pattern_array != NULL)
-			{
-				SCDynamicStoreSetNotificationKeys (ref, key_array, pattern_array);
-				source = SCDynamicStoreCreateRunLoopSource (NULL, ref, 0);
-			}
-			
-			if (key_array != NULL)
-				CFRelease (key_array);
-			if (pattern_array != NULL)
-				CFRelease (pattern_array);
-		}
-		
-		
-		for (i = 0; i < 4; i++)
-			if (keys[i] != NULL)
-			CFRelease (keys[i]);
-		for (i = 0; i < 2; i++)
-			if (patterns[i] != NULL)
-			CFRelease (patterns[i]);
-		
-		CFRelease (ref); 
-    }
-	
-    if (source != NULL)
-    {
-		CFRunLoopAddSource (CFRunLoopGetCurrent (),
-							source, kCFRunLoopDefaultMode);
-		CFRelease (source);
-    }
-	
-    return source != NULL;
-}
-
-
-/* Entrypoint. */
-
-void
-termination_signal_handler (int unused_sig)
-{
-    signal (SIGTERM, SIG_DFL);
-    signal (SIGHUP, SIG_DFL);
-    signal (SIGINT, SIG_DFL);
-    signal (SIGQUIT, SIG_DFL);
-
-    longjmp (exit_continuation, 1);
-}
-
-int
-server_main (int argc, char **argv)
-{
-    char **xargv;
-    int i, j;
-    int fd;
-	
-    xargv = alloca (sizeof (char *) * (argc + 32));
-	
-    if (!read_boolean_pref (CFSTR ("no_auth"), FALSE))
-		auth_file = XauFileName ();
-	
-    /* The standard X11 behaviour is for the server to quit when the first
-	 client exits. But it can be useful for debugging (and to mimic our
-	 behaviour in the beta releases) to not do that. */
-	
-    xinit_kills_server = read_boolean_pref (CFSTR ("xinit_kills_server"), TRUE);
-	
-    for (i = 1; i < argc; i++)
-    {
-		if (argv[i][0] == ':')
-			server_name = argv[i];
-    }
-	
-    if (server_name == NULL)
-    {
-		static char name[8];
-		
-		/* No display number specified, so search for the first unused.
-		 
-		 There's a big old race condition here if two servers start at
-		 the same time, but that's fairly unlikely. We could create
-		 lockfiles or something, but that's seems more likely to cause
-		 problems than the race condition itself.. */
-		
-		for (i = 0; i < MAX_DISPLAYS; i++)
-		{
-			if (!display_exists_p (i))
-				break;
-		}
-		
-		if (i == MAX_DISPLAYS)
-		{
-			fprintf (stderr, "%s: couldn't allocate a display number", argv[0]);
-			exit (1);
-		}
-		
-		sprintf (name, ":%d", i);
-		server_name = name;
-    }
-	
-    if (auth_file != NULL)
-    {
-		/* Create new Xauth keys and add them to the .Xauthority file */
-		
-		make_auth_keys (server_name);
-		write_auth_file (TRUE);
-    }
-	
-    /* Construct our new argv */
-	
-    i = j = 0;
-	
-    xargv[i++] = argv[j++];
-	
-    if (auth_file != NULL)
-    {
-		xargv[i++] = "-auth";
-		xargv[i++] = auth_file;
-    }
-	
-    /* By default, don't listen on tcp sockets if Xauth is disabled. */
-	
-    if (read_boolean_pref (CFSTR ("nolisten_tcp"), auth_file == NULL))
-    {
-		xargv[i++] = "-nolisten";
-		xargv[i++] = "tcp";
-    }
-	
-    while (j < argc)
-    {
-		if (argv[j++][0] != ':')
-			xargv[i++] = argv[j-1];
-    }
-	
-    xargv[i++] = (char *) server_name;
-    xargv[i++] = NULL;
-	
-    /* Detach from any controlling terminal and connect stdin to /dev/null */
-	
-#ifdef TIOCNOTTY
-    fd = open ("/dev/tty", O_RDONLY);
-    if (fd != -1)
-    {
-		ioctl (fd, TIOCNOTTY, 0);
-		close (fd);
-    }
-#endif
-	
-    fd = open ("/dev/null", O_RDWR, 0);
-    if (fd >= 0)
-    {
-		dup2 (fd, 0);
-		if (fd > 0)
-			close (fd);
-    }
-	
-    if (!start_server (xargv))
-		return 1;
-	
-    if (!wait_for_server ())
-    {
-		kill (server_pid, SIGTERM);
-		return 1;
-    }
-	
-    if (!start_client ())
-    {
-		kill (server_pid, SIGTERM);
-		return 1;
-    }
-	
-    signal (SIGCHLD, sigchld_handler);
-	
-    signal (SIGTERM, termination_signal_handler);
-    signal (SIGHUP, termination_signal_handler);
-    signal (SIGINT, termination_signal_handler);
-    signal (SIGQUIT, termination_signal_handler);
-
-    if (setjmp (exit_continuation) == 0)
-    {
-		if (install_ipaddr_source ())
-			CFRunLoopRun ();
-		else
-			while (1) pause ();
-    }
-	
-    signal (SIGCHLD, SIG_IGN);
-
-    if (client_pid >= 0) kill (client_pid, SIGTERM);
-    if (server_pid >= 0) kill (server_pid, SIGTERM);
-	
-    if (auth_file != NULL)
-    {
-		/* Remove our Xauth keys */
-		
-		write_auth_file (FALSE);
-    }
-	
-    free_auth_items ();
-	
-    return 0;
-}
commit 1f74bef1ad1399323fc0d2e309b808bf32c622e4
Author: Jeremy Huddleston <jeremy at yuffie.local>
Date:   Thu Dec 20 17:33:38 2007 -0800

    XQuartz: Don't fork to exec app_to_run.
    Plus other housecleaning...
    (cherry picked from commit ae302db472f127be082d05b418ede332fae8ccc5)

diff --git a/hw/xquartz/X11Application.m b/hw/xquartz/X11Application.m
index 828cd30..56db2c4 100644
--- a/hw/xquartz/X11Application.m
+++ b/hw/xquartz/X11Application.m
@@ -153,7 +153,7 @@ static void message_kit_thread (SEL selector, NSObject *arg) {
 	
     tem = [infoDict objectForKey:@"CFBundleShortVersionString"];
 	
-    [dict setObject:[NSString stringWithFormat:@"X11.app %@ - X.org X11R7.3", tem] 
+    [dict setObject:[NSString stringWithFormat:@"XQuartz %@ - (xorg-server %s)", tem, XSERVER_VERSION] 
 	  forKey:@"ApplicationVersion"];
 	
     [self orderFrontStandardAboutPanelWithOptions: dict];
diff --git a/hw/xquartz/bundle/X11.xcodeproj/project.pbxproj b/hw/xquartz/bundle/X11.xcodeproj/project.pbxproj
index 225f371..9d5c5d6 100644
--- a/hw/xquartz/bundle/X11.xcodeproj/project.pbxproj
+++ b/hw/xquartz/bundle/X11.xcodeproj/project.pbxproj
@@ -7,7 +7,6 @@
 	objects = {
 
 /* Begin PBXBuildFile section */
-		3F5E1BE00D04BF110020CA24 /* launcher-main.c in Sources */ = {isa = PBXBuildFile; fileRef = 3F5E1BDE0D04BF110020CA24 /* launcher-main.c */; };
 		3F5E1BE10D04BF110020CA24 /* server-main.c in Sources */ = {isa = PBXBuildFile; fileRef = 3F5E1BDF0D04BF110020CA24 /* server-main.c */; };
 		527F24190B5D938C007840A7 /* InfoPlist.strings in Resources */ = {isa = PBXBuildFile; fileRef = 0867D6AAFE840B52C02AAC07 /* InfoPlist.strings */; };
 		527F241A0B5D938C007840A7 /* main.nib in Resources */ = {isa = PBXBuildFile; fileRef = 02345980000FD03B11CA0E72 /* main.nib */; };
@@ -22,7 +21,6 @@
 /* Begin PBXFileReference section */
 		0867D6ABFE840B52C02AAC07 /* English */ = {isa = PBXFileReference; fileEncoding = 10; lastKnownFileType = text.plist.strings; name = English; path = English.lproj/InfoPlist.strings; sourceTree = "<group>"; };
 		1870340FFE93FCAF11CA0CD7 /* English */ = {isa = PBXFileReference; lastKnownFileType = wrapper.nib; name = English; path = English.lproj/main.nib; sourceTree = "<group>"; };
-		3F5E1BDE0D04BF110020CA24 /* launcher-main.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = "launcher-main.c"; sourceTree = "<group>"; };
 		3F5E1BDF0D04BF110020CA24 /* server-main.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = "server-main.c"; sourceTree = "<group>"; };
 		50459C5F038587C60ECA21EC /* X11.icns */ = {isa = PBXFileReference; lastKnownFileType = image.icns; path = X11.icns; sourceTree = "<group>"; };
 		50EE2AB703849F0B0ECA21EC /* bundle-main.c */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.c; path = "bundle-main.c"; sourceTree = "<group>"; };
@@ -69,7 +67,6 @@
 		20286C2AFDCF999611CA2CEA /* Sources */ = {
 			isa = PBXGroup;
 			children = (
-				3F5E1BDE0D04BF110020CA24 /* launcher-main.c */,
 				3F5E1BDF0D04BF110020CA24 /* server-main.c */,
 				50EE2AB703849F0B0ECA21EC /* bundle-main.c */,
 			);
@@ -176,7 +173,6 @@
 			buildActionMask = 2147483647;
 			files = (
 				527F241D0B5D938C007840A7 /* bundle-main.c in Sources */,
-				3F5E1BE00D04BF110020CA24 /* launcher-main.c in Sources */,
 				3F5E1BE10D04BF110020CA24 /* server-main.c in Sources */,
 			);
 			runOnlyForDeploymentPostprocessing = 0;
diff --git a/hw/xquartz/bundle/bundle-main.c b/hw/xquartz/bundle/bundle-main.c
index 681e1a8..ed41e68 100644
--- a/hw/xquartz/bundle/bundle-main.c
+++ b/hw/xquartz/bundle/bundle-main.c
@@ -32,18 +32,23 @@
 #include <unistd.h>
 #include <stdio.h>
 #include <string.h>
+#include <stdlib.h>
 
-int launcher_main(int argc, char **argv);
+#include <CoreFoundation/CoreFoundation.h>
+
+#define DEFAULT_APP "/usr/X11/bin/xterm"
+
+static int launcher_main(int argc, char **argv);
 int server_main(int argc, char **argv);
 
 int main(int argc, char **argv) {
     Display *display;
 
-    //size_t i;
-    //fprintf(stderr, "X11.app: main(): argc=%d\n", argc);
-    //for(i=0; i < argc; i++) {
-    //    fprintf(stderr, "\targv[%u] = %s\n", (unsigned)i, argv[i]);
-    //}
+    size_t i;
+    fprintf(stderr, "X11.app: main(): argc=%d\n", argc);
+    for(i=0; i < argc; i++) {
+        fprintf(stderr, "\targv[%u] = %s\n", (unsigned)i, argv[i]);
+    }
     
     /* If we have a process serial number and it's our only arg, act as if
      * the user double clicked the app bundle: launch app_to_run if possible
@@ -52,7 +57,7 @@ int main(int argc, char **argv) {
         /* Now, try to open a display, if so, run the launcher */
         display = XOpenDisplay(NULL);
         if(display) {
-            fprintf(stderr, "X11.app: main(): closing the display and sleeping");
+            fprintf(stderr, "X11.app: closing the display and sleeping for 2s to allow the X server to start up.\n");
             /* Could open the display, start the launcher */
             XCloseDisplay(display);
             
@@ -60,13 +65,49 @@ int main(int argc, char **argv) {
              * TODO: *Really* fix this race condition
              */
             usleep(2000);
-            //fprintf(stderr, "X11.app: main(): running launcher_main()");
             return launcher_main(argc, argv);
         }
     }
     
     /* Start the server */
-    //fprintf(stderr, "X11.app: main(): running server_main()");
+    fprintf(stderr, "X11.app: main(): running server_main()");
     return server_main(argc, argv);
 }
 
+int launcher_main (int argc, char **argv) {
+    char *command = DEFAULT_APP;
+    const char *newargv[7];
+    int child;
+    const char **s;
+    
+	CFPropertyListRef PlistRef = CFPreferencesCopyAppValue(CFSTR("app_to_run"), kCFPreferencesCurrentApplication);
+	
+	if ((PlistRef == NULL) || (CFGetTypeID(PlistRef) != CFStringGetTypeID())) {
+		CFPreferencesSetAppValue(CFSTR("app_to_run"), CFSTR(DEFAULT_APP), kCFPreferencesCurrentApplication);
+		CFPreferencesAppSynchronize(kCFPreferencesCurrentApplication);
+	} else {
+		int len = CFStringGetLength((CFStringRef)PlistRef)+1;
+		command = (char *)malloc(len);
+		CFStringGetCString((CFStringRef)PlistRef, command, len,  kCFStringEncodingASCII);
+		fprintf(stderr, "command=%s\n", command);
+	}
+
+	if (PlistRef) CFRelease(PlistRef);
+
+	newargv[0] = "/usr/bin/login";
+	newargv[1] = "-fp";
+	newargv[2] = getlogin();
+	newargv[3] = "/bin/sh";
+	newargv[4] = "-c";
+	newargv[5] = command;
+	newargv[6] = NULL;
+
+    fprintf(stderr, "X11.app: Launching X11 Application:\n");
+    for(s=newargv; *s; s++) {
+        fprintf(stderr, "\targv[%d] = %s\n", s - newargv, *s);
+    }
+
+    execvp (newargv[0], (const char **) newargv);
+    perror ("X11.app: Couldn't exec.");
+    return(1);
+}
diff --git a/hw/xquartz/darwin.c b/hw/xquartz/darwin.c
index 06e88bd..d6eb100 100644
--- a/hw/xquartz/darwin.c
+++ b/hw/xquartz/darwin.c
@@ -150,8 +150,9 @@ void
 DarwinPrintBanner(void)
 { 
   // this should change depending on which specific server we are building
-  ErrorF("X11.app starting:\n");
-  ErrorF("Xquartz server based on X.org %s, built on %s\n", XORG_RELEASE, BUILD_DATE );
+  ErrorF("XQuartz starting:\n");
+  ErrorF("X.org Release 7.2\n"); // This is here to help fink until they fix their packages.
+  ErrorF("X.Org X Server %s\nBuild Date: %s\n", XSERVER_VERSION, BUILD_DATE );
 }
 
 
commit 2d15d439f844d4016f169664a338595c11b91b77
Author: Jeremy Huddleston <jeremy at yuffie.local>
Date:   Thu Dec 20 15:46:40 2007 -0800

    Xquartz: Use X11ControllerMain()
    (cherry picked from commit a9ac932543374aa2540f5a12cc85ef82c85b0e0c)

diff --git a/hw/xquartz/X11Application.h b/hw/xquartz/X11Application.h
index c42e6a5..a1be751 100644
--- a/hw/xquartz/X11Application.h
+++ b/hw/xquartz/X11Application.h
@@ -72,7 +72,7 @@ void X11ApplicationSetCanQuit (int state);
 void X11ApplicationServerReady (void);
 void X11ApplicationShowHideMenubar (int state);
 
-void X11ApplicationMain(int argc, char **argv, void (*server_thread) (void *), void *server_arg);
+void X11ApplicationMain(int argc, const char **argv, void (*server_thread) (void *), void *server_arg);
 
 extern int X11EnableKeyEquivalents;
 extern int quartzHasRoot, quartzEnableRootless;
diff --git a/hw/xquartz/X11Application.m b/hw/xquartz/X11Application.m
index 92a503b..828cd30 100644
--- a/hw/xquartz/X11Application.m
+++ b/hw/xquartz/X11Application.m
@@ -790,7 +790,7 @@ environment?", @"Startup xinitrc dialog");
     [X11App prefs_synchronize];
 }
 
-void X11ApplicationMain (int argc, char **argv, void (*server_thread) (void *), void *server_arg) {
+void X11ApplicationMain (int argc, const char **argv, void (*server_thread) (void *), void *server_arg) {
     NSAutoreleasePool *pool;
 
 #ifdef DEBUG
diff --git a/hw/xquartz/X11Controller.h b/hw/xquartz/X11Controller.h
index bfbb04f..47f5220 100644
--- a/hw/xquartz/X11Controller.h
+++ b/hw/xquartz/X11Controller.h
@@ -78,4 +78,6 @@
 
 #endif /* __OBJC__ */
 
+void X11ControllerMain(int argc, const char **argv, void (*server_thread) (void *), void *server_arg);
+
 #endif /* X11CONTROLLER_H */
diff --git a/hw/xquartz/X11Controller.m b/hw/xquartz/X11Controller.m
index ecd88ab..6b7c351 100644
--- a/hw/xquartz/X11Controller.m
+++ b/hw/xquartz/X11Controller.m
@@ -741,3 +741,7 @@ objectValueForTableColumn:(NSTableColumn *)tableColumn row:(int)row
 }
 
 @end
+
+void X11ControllerMain(int argc, const char **argv, void (*server_thread) (void *), void *server_arg) {
+    X11ApplicationMain (argc, argv, server_thread, server_arg);
+}
diff --git a/hw/xquartz/quartzStartup.c b/hw/xquartz/quartzStartup.c
index 50ce2a6..8600ec8 100644
--- a/hw/xquartz/quartzStartup.c
+++ b/hw/xquartz/quartzStartup.c
@@ -35,7 +35,7 @@
 #include <unistd.h>
 #include <CoreFoundation/CoreFoundation.h>
 #include "quartzCommon.h"
-#include "X11Application.h"
+#include "X11Controller.h"
 #include "darwin.h"
 #include "quartz.h"
 #include "opaque.h"
@@ -106,6 +106,6 @@ void DarwinHandleGUI(int argc, char **argv, char **envp) {
     extern void _InitHLTB(void);
     
     _InitHLTB();    
-    X11ApplicationMain(argc, argv, server_thread, NULL);
+    X11ControllerMain(argc, argv, server_thread, NULL);
     exit(0);
 }
commit 1393a97ea97b5f7d7b90e3e8c58b5996b600e0c6
Author: Eamon Walsh <ewalsh at tycho.nsa.gov>
Date:   Thu Dec 20 16:23:35 2007 -0500

    xselinux: Send AVC messages to audit system instead of log file/stderr.

diff --git a/Xext/xselinux.c b/Xext/xselinux.c
index bbae483..bbd8d1a 100644
--- a/Xext/xselinux.c
+++ b/Xext/xselinux.c
@@ -462,8 +462,12 @@ static int
 SELinuxLog(int type, const char *fmt, ...)
 {
     va_list ap;
+    char buf[MAX_AUDIT_MESSAGE_LENGTH];
+    int rc, aut = AUDIT_USER_AVC;
+
     va_start(ap, fmt);
-    VErrorF(fmt, ap);
+    vsnprintf(buf, MAX_AUDIT_MESSAGE_LENGTH, fmt, ap);
+    rc = audit_log_user_avc_message(audit_fd, aut, buf, NULL, NULL, NULL, 0);
     va_end(ap);
     return 0;
 }
commit 42802a8e6b3d3795acc4f8b7597ea5a48619b5cd
Author: Jeremy Huddleston <jeremy at yuffie.local>
Date:   Thu Dec 20 13:17:30 2007 -0800

    Xquartz: General Cleanup
    General code cleanup, whitespace, dead code removal, added missing prototypes.
    Made Xquartz come to foreground later in startup, so it doesn't appear for Xquartz -version
    (cherry picked from commit 36922e8ff4316c93843aa3fe959cf8df3c7d5892)

diff --git a/dix/main.c b/dix/main.c
index 532b325..9114f00 100644
--- a/dix/main.c
+++ b/dix/main.c
@@ -238,6 +238,10 @@ static int indexForScanlinePad[ 65 ] = {
 #define MIN(a,b) (((a) < (b)) ? (a) : (b))
 #endif
 
+#ifdef __APPLE__
+void DarwinHandleGUI(int argc, char **argv, char **envp);
+#endif
+
 int
 main(int argc, char *argv[], char *envp[])
 {
diff --git a/hw/xquartz/X11Application.h b/hw/xquartz/X11Application.h
index 8615657..c42e6a5 100644
--- a/hw/xquartz/X11Application.h
+++ b/hw/xquartz/X11Application.h
@@ -64,40 +64,38 @@ extern X11Application *X11App;
 
 #endif /* __OBJC__ */
 
-extern void X11ApplicationSetWindowMenu (int nitems, const char **items,
+void X11ApplicationSetWindowMenu (int nitems, const char **items,
 					 const char *shortcuts);
-extern void X11ApplicationSetWindowMenuCheck (int idx);
-extern void X11ApplicationSetFrontProcess (void);
-extern void X11ApplicationSetCanQuit (int state);
-extern void X11ApplicationServerReady (void);
-extern void X11ApplicationShowHideMenubar (int state);
+void X11ApplicationSetWindowMenuCheck (int idx);
+void X11ApplicationSetFrontProcess (void);
+void X11ApplicationSetCanQuit (int state);
+void X11ApplicationServerReady (void);
+void X11ApplicationShowHideMenubar (int state);
 
-extern void X11ApplicationMain (int argc, const char *argv[],
-				void (*server_thread) (void *),
-				void *server_arg);
+void X11ApplicationMain(int argc, char **argv, void (*server_thread) (void *), void *server_arg);
 
 extern int X11EnableKeyEquivalents;
 extern int quartzHasRoot, quartzEnableRootless;
 
 #define APP_PREFS "org.x.X11"
 
-#define PREFS_APPSMENU		"apps_menu"
-#define PREFS_FAKEBUTTONS	"enable_fake_buttons"
-#define PREFS_SYSBEEP		"enable_system_beep"
-#define PREFS_KEYEQUIVS		"enable_key_equivalents"
-#define PREFS_KEYMAP_FILE	"keymap_file"
-#define PREFS_SYNC_KEYMAP	"sync_keymap"
-#define PREFS_DEPTH		"depth"
-#define PREFS_NO_AUTH		"no_auth"
-#define PREFS_NO_TCP		"nolisten_tcp"
-#define PREFS_DONE_XINIT_CHECK	"done_xinit_check"
-#define PREFS_NO_QUIT_ALERT	"no_quit_alert"
-#define PREFS_FAKE_BUTTON2	"fake_button2"
-#define PREFS_FAKE_BUTTON3	"fake_button3"
-#define PREFS_ROOTLESS		"rootless"
-#define PREFS_FULLSCREEN_HOTKEYS "fullscreen_hotkeys"
-#define PREFS_SWAP_ALT_META	"swap_alt_meta"
-#define PREFS_XP_OPTIONS	"xp_options"
-#define PREFS_ENABLE_STEREO	"enable_stereo"
+#define PREFS_APPSMENU              "apps_menu"
+#define PREFS_FAKEBUTTONS           "enable_fake_buttons"
+#define PREFS_SYSBEEP               "enable_system_beep"
+#define PREFS_KEYEQUIVS             "enable_key_equivalents"
+#define PREFS_KEYMAP_FILE           "keymap_file"
+#define PREFS_SYNC_KEYMAP           "sync_keymap"
+#define PREFS_DEPTH                 "depth"
+#define PREFS_NO_AUTH               "no_auth"
+#define PREFS_NO_TCP                "nolisten_tcp"
+#define PREFS_DONE_XINIT_CHECK      "done_xinit_check"
+#define PREFS_NO_QUIT_ALERT         "no_quit_alert"
+#define PREFS_FAKE_BUTTON2          "fake_button2"
+#define PREFS_FAKE_BUTTON3          "fake_button3"
+#define PREFS_ROOTLESS              "rootless"
+#define PREFS_FULLSCREEN_HOTKEYS    "fullscreen_hotkeys"
+#define PREFS_SWAP_ALT_META         "swap_alt_meta"
+#define PREFS_XP_OPTIONS            "xp_options"
+#define PREFS_ENABLE_STEREO         "enable_stereo"
 
 #endif /* X11APPLICATION_H */
diff --git a/hw/xquartz/X11Application.m b/hw/xquartz/X11Application.m
index 8d4076a..92a503b 100644
--- a/hw/xquartz/X11Application.m
+++ b/hw/xquartz/X11Application.m
@@ -32,6 +32,7 @@
 #endif
 
 #include "quartzCommon.h"
+#include "quartzForeground.h"
 
 #import "X11Application.h"
 #include <Carbon/Carbon.h>
@@ -82,8 +83,8 @@ static mach_port_t _port;
 static void send_nsevent (NSEventType type, NSEvent *e);
 
 /* Quartz mode initialization routine. This is often dynamically loaded
- but is statically linked into this X server. */
-extern Bool QuartzModeBundleInit(void);
+   but is statically linked into this X server. */
+Bool QuartzModeBundleInit(void);
 
 static void init_ports (void) {
     kern_return_t r;
@@ -789,44 +790,43 @@ environment?", @"Startup xinitrc dialog");
     [X11App prefs_synchronize];
 }
 
-void X11ApplicationMain (int argc, const char *argv[],
-			 void (*server_thread) (void *), void *server_arg) {
-  NSAutoreleasePool *pool;
-  
+void X11ApplicationMain (int argc, char **argv, void (*server_thread) (void *), void *server_arg) {
+    NSAutoreleasePool *pool;
+
 #ifdef DEBUG
-  while (access ("/tmp/x11-block", F_OK) == 0) sleep (1);
+    while (access ("/tmp/x11-block", F_OK) == 0) sleep (1);
 #endif
   
-  pool = [[NSAutoreleasePool alloc] init];
-  X11App = (X11Application *) [X11Application sharedApplication];
-  init_ports ();
-  [NSApp read_defaults];
-  [NSBundle loadNibNamed:@"main" owner:NSApp];
-  [[NSNotificationCenter defaultCenter] addObserver:NSApp
+    pool = [[NSAutoreleasePool alloc] init];
+    X11App = (X11Application *) [X11Application sharedApplication];
+    init_ports ();
+    [NSApp read_defaults];
+    [NSBundle loadNibNamed:@"main" owner:NSApp];
+    [[NSNotificationCenter defaultCenter] addObserver:NSApp
 					selector:@selector (became_key:)
 					name:NSWindowDidBecomeKeyNotification object:nil];
-  check_xinitrc ();
-	
-  /*
-   * The xpr Quartz mode is statically linked into this server.
-   * Initialize all the Quartz functions.
-   */
-  QuartzModeBundleInit();
-  
-  /* Calculate the height of the menubar so we can avoid it. */
-  aquaMenuBarHeight = NSHeight([[NSScreen mainScreen] frame]) -
+    check_xinitrc ();
+
+    /*
+     * The xpr Quartz mode is statically linked into this server.
+     * Initialize all the Quartz functions.
+     */
+    QuartzModeBundleInit();
+
+    /* Calculate the height of the menubar so we can avoid it. */
+    aquaMenuBarHeight = NSHeight([[NSScreen mainScreen] frame]) -
     NSMaxY([[NSScreen mainScreen] visibleFrame]);
   
-  if (!create_thread (server_thread, server_arg)) {
-    ErrorF("can't create secondary thread\n");
-    exit (1);
-  }
-  
-  [NSApp run];
-  
-  /* not reached */
-}
+    if (!create_thread (server_thread, server_arg)) {
+        ErrorF("can't create secondary thread\n");
+        exit (1);
+    }
+
+    QuartzMoveToForeground();
 
+    [NSApp run];
+    /* not reached */
+}
 
 /* event conversion */
 
diff --git a/hw/xquartz/X11Controller.h b/hw/xquartz/X11Controller.h
index f1399dc..bfbb04f 100644
--- a/hw/xquartz/X11Controller.h
+++ b/hw/xquartz/X11Controller.h
@@ -78,8 +78,4 @@
 
 #endif /* __OBJC__ */
 
-extern void X11ControllerMain (int argc, const char *argv[],
-			       void (*server_thread) (void *),
-			       void *server_arg);
-
 #endif /* X11CONTROLLER_H */
diff --git a/hw/xquartz/X11Controller.m b/hw/xquartz/X11Controller.m
index 0f64e45..ecd88ab 100644
--- a/hw/xquartz/X11Controller.m
+++ b/hw/xquartz/X11Controller.m
@@ -337,7 +337,7 @@
       /* Setup environment */
       temp = getenv("DISPLAY");
       if (temp == NULL || temp[0] == 0) {
-	snprintf(buf, sizeof(buf), ":%s", display);
+    snprintf(buf, sizeof(buf), ":%s", display);
 	setenv("DISPLAY", buf, TRUE);
       }
 	
@@ -741,9 +741,3 @@ objectValueForTableColumn:(NSTableColumn *)tableColumn row:(int)row
 }
 
 @end
-
-void X11ControllerMain (int argc, const char *argv[],
-			void (*server_thread) (void *), void *server_arg)
-{
-  X11ApplicationMain (argc, argv, server_thread, server_arg);
-}
diff --git a/hw/xquartz/darwin.c b/hw/xquartz/darwin.c
index d932bcd..06e88bd 100644
--- a/hw/xquartz/darwin.c
+++ b/hw/xquartz/darwin.c
@@ -715,16 +715,6 @@ int ddxProcessArgument( int argc, char *argv[], int i )
         return 1;
     }
 
-    if ( !strcmp( argv[i], "-quartz" ) ) {
-        ErrorF( "Running in parallel with Mac OS X Quartz window server.\n" );
-        return 1;
-    }
-
-    // The Mac OS X front end uses this argument, which we just ignore here.
-    if ( !strcmp( argv[i], "-nostartx" ) ) {
-        return 1;
-    }
-
     // This command line arg is passed when launched from the Aqua GUI.
     if ( !strncmp( argv[i], "-psn_", 5 ) ) {
         return 1;
@@ -876,9 +866,9 @@ void ddxUseMsg( void )
     ErrorF("-keymap <file> : read the keymapping from a file instead of the kernel.\n");
     ErrorF("-version : show the server version.\n");
     ErrorF("\n");
-    ErrorF("Quartz modes (Experimental / In Development):\n");
-    ErrorF("-fullscreen : run full screen in parallel with Mac OS X window server.\n");
-    ErrorF("-rootless : run rootless inside Mac OS X window server.\n");
+//    ErrorF("Quartz modes (Experimental / In Development):\n");
+//    ErrorF("-fullscreen : run full screen in parallel with Mac OS X window server.\n");
+//    ErrorF("-rootless : run rootless inside Mac OS X window server.\n");
     ErrorF("\n");
     ErrorF("Options ignored in rootless mode:\n");
     ErrorF("-size <height> <width> : use a screen resolution of <height> x <width>.\n");
@@ -896,7 +886,8 @@ void ddxGiveUp( void )
 {
     ErrorF( "Quitting XQuartz...\n" );
 
-    QuartzGiveUp();
+    //if (!quartzRootless)
+    //    quartzProcs->ReleaseScreens();
 }
 
 
diff --git a/hw/xquartz/quartz.c b/hw/xquartz/quartz.c
index 2063300..75f4e5e 100644
--- a/hw/xquartz/quartz.c
+++ b/hw/xquartz/quartz.c
@@ -61,7 +61,6 @@
 
 // Shared global variables for Quartz modes
 int                     quartzEventWriteFD = -1;
-int                     quartzStartClients = 1;
 int                     quartzRootless = -1;
 int                     quartzUseSysBeep = 0;
 int                     quartzUseAGL = 1;
@@ -408,12 +407,10 @@ QuartzMessageServerThread(
  * QuartzProcessEvent
  *  Process Quartz specific events.
  */
-void QuartzProcessEvent(
-    xEvent *xe)
-{
+void QuartzProcessEvent(xEvent *xe) {
     switch (xe->u.u.type) {
         case kXDarwinControllerNotify:
-	  DEBUG_LOG("kXDarwinControllerNotify\n");
+            DEBUG_LOG("kXDarwinControllerNotify\n");
             AppleWMSendEvent(AppleWMControllerNotify,
                              AppleWMControllerNotifyMask,
                              xe->u.clientMessage.u.l.longs0,
@@ -421,7 +418,7 @@ void QuartzProcessEvent(
             break;
 
         case kXDarwinPasteboardNotify:
-	  DEBUG_LOG("kXDarwinPasteboardNotify\n");
+            DEBUG_LOG("kXDarwinPasteboardNotify\n");
             AppleWMSendEvent(AppleWMPasteboardNotify,
                              AppleWMPasteboardNotifyMask,
                              xe->u.clientMessage.u.l.longs0,
@@ -429,7 +426,7 @@ void QuartzProcessEvent(
             break;
 
         case kXDarwinActivate:
-	  DEBUG_LOG("kXDarwinActivate\n");
+            DEBUG_LOG("kXDarwinActivate\n");
             QuartzShow(xe->u.keyButtonPointer.rootX,
                        xe->u.keyButtonPointer.rootY);
             AppleWMSendEvent(AppleWMActivationNotify,
@@ -438,7 +435,7 @@ void QuartzProcessEvent(
             break;
 
         case kXDarwinDeactivate:
-  	  DEBUG_LOG("kXDarwinDeactivate\n");
+            DEBUG_LOG("kXDarwinDeactivate\n");
             AppleWMSendEvent(AppleWMActivationNotify,
                              AppleWMActivationNotifyMask,
                              AppleWMIsInactive, 0);
@@ -446,23 +443,23 @@ void QuartzProcessEvent(
             break;
 
         case kXDarwinDisplayChanged:
-	    DEBUG_LOG("kXDarwinDisplayChanged\n");
+            DEBUG_LOG("kXDarwinDisplayChanged\n");
             QuartzUpdateScreens();
             break;
 
         case kXDarwinWindowState:
-	  DEBUG_LOG("kXDarwinWindowState\n");
+            DEBUG_LOG("kXDarwinWindowState\n");
             RootlessNativeWindowStateChanged(xe->u.clientMessage.u.l.longs0,
 		  			     xe->u.clientMessage.u.l.longs1);
 	    break;
 	  
         case kXDarwinWindowMoved:
-	  DEBUG_LOG("kXDarwinWindowMoved\n");
-	  RootlessNativeWindowMoved ((WindowPtr)xe->u.clientMessage.u.l.longs0);
+            DEBUG_LOG("kXDarwinWindowMoved\n");
+            RootlessNativeWindowMoved ((WindowPtr)xe->u.clientMessage.u.l.longs0);
 	    break;
 
         case kXDarwinToggleFullscreen:
-	  DEBUG_LOG("kXDarwinToggleFullscreen\n");
+            DEBUG_LOG("kXDarwinToggleFullscreen\n");
 #ifdef DARWIN_DDX_MISSING
             if (quartzEnableRootless) QuartzSetFullscreen(!quartzHasRoot);
             else if (quartzHasRoot) QuartzHide();
@@ -473,6 +470,7 @@ void QuartzProcessEvent(
             break;
 
         case kXDarwinSetRootless:
+            DEBUG_LOG("kXDarwinSetRootless\n");
 #ifdef DARWIN_DDX_MISSING
             QuartzSetRootless(xe->u.clientMessage.u.l.longs0);
             if (!quartzEnableRootless && !quartzHasRoot) QuartzHide();
@@ -498,34 +496,11 @@ void QuartzProcessEvent(
             break;
 
         case kXDarwinBringAllToFront:
-  	  DEBUG_LOG("kXDarwinBringAllToFront\n");
-	    RootlessOrderAllWindows();
+            DEBUG_LOG("kXDarwinBringAllToFront\n");
+            RootlessOrderAllWindows();
             break;
 
         default:
             ErrorF("Unknown application defined event type %d.\n", xe->u.u.type);
     }
 }
-
-
-/*
- * QuartzGiveUp
- *  Cleanup before X server shutdown
- *  Release the screen and restore the Aqua cursor.
- */
-void QuartzGiveUp(void)
-{
-#if 0
-// Trying to switch cursors when quitting causes deadlock
-    int i;
-
-    for (i = 0; i < screenInfo.numScreens; i++) {
-        if (screenInfo.screens[i]) {
-            QuartzSuspendXCursor(screenInfo.screens[i]);
-        }
-    }
-#endif
-
-    if (!quartzRootless)
-        quartzProcs->ReleaseScreens();
-}
diff --git a/hw/xquartz/quartzCommon.h b/hw/xquartz/quartzCommon.h
index 50b50f6..a0d4673 100644
--- a/hw/xquartz/quartzCommon.h
+++ b/hw/xquartz/quartzCommon.h
@@ -64,7 +64,6 @@ typedef struct {
 
 // Data stored at startup for Cocoa front end
 extern int              quartzEventWriteFD;
-extern int              quartzStartClients;
 
 // User preferences used by Quartz modes
 extern int              quartzRootless;
diff --git a/hw/xquartz/quartzStartup.c b/hw/xquartz/quartzStartup.c
index 87bcada..50ce2a6 100644
--- a/hw/xquartz/quartzStartup.c
+++ b/hw/xquartz/quartzStartup.c
@@ -34,8 +34,8 @@
 #include <fcntl.h>
 #include <unistd.h>
 #include <CoreFoundation/CoreFoundation.h>
-#include "quartzForeground.h"
 #include "quartzCommon.h"
+#include "X11Application.h"
 #include "darwin.h"
 #include "quartz.h"
 #include "opaque.h"
@@ -52,9 +52,6 @@
 char **envpGlobal;      // argcGlobal and argvGlobal
                         // are from dix/globals.c
 
-
-void X11ControllerMain(int argc, char *argv[], void (*server_thread) (void *), void *server_arg);
-
 static void server_thread (void *arg) {
   extern int main(int argc, char **argv, char **envp);
   exit (main (argcGlobal, argvGlobal, envpGlobal));
@@ -68,22 +65,16 @@ static void server_thread (void *arg) {
  *  server. On the second call this function loads the user
  *  preferences set by the Mac OS X front end.
  */
-void DarwinHandleGUI(
-    int         argc,
-    char        *argv[],
-    char        *envp[] )
-{
+void DarwinHandleGUI(int argc, char **argv, char **envp) {
     static Bool been_here = FALSE;
     int         i;
     int         fd[2];
 
-    QuartzMoveToForeground();
-    
     if (been_here) {
         return;
     }
     been_here = TRUE;
-
+    
     // Make a pipe to pass events
     assert( pipe(fd) == 0 );
     darwinEventReadFD = fd[0];
@@ -95,26 +86,14 @@ void DarwinHandleGUI(
     argvGlobal = argv;
     envpGlobal = envp;
 
-    quartzStartClients = 1;
     for (i = 1; i < argc; i++) {
         // Display version info without starting Mac OS X UI if requested
         if (!strcmp( argv[i], "-showconfig" ) || !strcmp( argv[i], "-version" )) {
             DarwinPrintBanner();
             exit(0);
         }
-
-        // Determine if we need to start X clients
-        // and what display mode to use
-        if (!strcmp(argv[i], "-nostartx")) {
-            quartzStartClients = 0;    
-        } else if (!strcmp( argv[i], "-fullscreen")) {
-            quartzRootless = 0;
-        } else if (!strcmp( argv[i], "-rootless")) {
-            quartzRootless = 1;
-        }
     }
 
-
     /* Initially I ran the X server on the main thread, and received
        events on the second thread. But now we may be using Carbon,
        that needs to run on the main thread. (Otherwise, when it's
@@ -127,6 +106,6 @@ void DarwinHandleGUI(
     extern void _InitHLTB(void);
     
     _InitHLTB();    
-    X11ControllerMain(argc, argv, server_thread, NULL);
+    X11ApplicationMain(argc, argv, server_thread, NULL);
     exit(0);
 }
diff --git a/hw/xquartz/xpr/xpr.h b/hw/xquartz/xpr/xpr.h
index ddc6d0c..b8c69df 100644
--- a/hw/xquartz/xpr/xpr.h
+++ b/hw/xquartz/xpr/xpr.h
@@ -31,7 +31,7 @@
 
 #include "screenint.h"
 
-extern Bool QuartzModeBundleInit(void);
+Bool QuartzModeBundleInit(void);
 
 void AppleDRIExtensionInit(void);
 void xprAppleWMInit(void);
commit 7ef7727b800fa4715b80a82850d65b88fde5fe6c
Author: Dave Airlie <airlied at clockmaker.usersys.redhat.com>
Date:   Thu Dec 20 10:11:26 2007 +1000

    entity sharing: make !shareable entity non-fatal.
    
    Just because the entity isn't shareable, we should bring down the server.
    Just ignore the extra screen and keep going.

diff --git a/hw/xfree86/common/xf86Bus.c b/hw/xfree86/common/xf86Bus.c
index 599f7a4..f7ffac8 100644
--- a/hw/xfree86/common/xf86Bus.c
+++ b/hw/xfree86/common/xf86Bus.c
@@ -290,8 +290,10 @@ xf86AddEntityToScreen(ScrnInfoPtr pScrn, int entityIndex)
     if (entityIndex == -1)
 	return;
     if (xf86Entities[entityIndex]->inUse &&
-	!(xf86Entities[entityIndex]->entityProp & IS_SHARED_ACCEL))
-	FatalError("Requested Entity already in use!\n");
+	!(xf86Entities[entityIndex]->entityProp & IS_SHARED_ACCEL)) {
+	ErrorF("Requested Entity already in use!\n");
+	return;
+    }
 
     pScrn->numEntities++;
     pScrn->entityList = xnfrealloc(pScrn->entityList,
commit 50e80c39870adfdc84fdbc00dddf1362117ad443
Author: Peter Hutterer <peter at cs.unisa.edu.au>
Date:   Wed Dec 19 16:20:36 2007 +1030

    include: never overwrite realInputProc with enqueueInputProc. Bug #13511
    
    In some cases (triggered by a key repeat during a sync grab) XKB unwrapping
    can overwrite the device's realInputProc with the enqueueInputProc. When the
    grab is released and the events are replayed, we end up in an infinite loop.
    Each event is replayed and in replaying pushed to the end of the queue again.
    
    This fix is a hack only. It ensures that the realInputProc is never
    overwritten with the enqueueInputProc.
    
    This fixes Bug #13511 (https://bugs.freedesktop.org/show_bug.cgi?id=13511)
    (cherry picked from commit eace88989c3b65d5c20e9f37ea9b23c7c8e19335)

diff --git a/include/xkbsrv.h b/include/xkbsrv.h
index 6425e37..bf386e7 100644
--- a/include/xkbsrv.h
+++ b/include/xkbsrv.h
@@ -258,7 +258,8 @@ typedef struct
 	    device->public.processInputProc = proc; \
 	oldprocs->processInputProc = \
 	oldprocs->realInputProc = device->public.realInputProc; \
-	device->public.realInputProc = proc; \
+	if (proc != device->public.enqueueInputProc) \
+		device->public.realInputProc = proc; \
 	oldprocs->unwrapProc = device->unwrapProc; \
 	device->unwrapProc = unwrapproc;
 
commit d0308b64655360517d83e07e866d103c3f2b389d
Author: Peter Hutterer <peter at cs.unisa.edu.au>
Date:   Wed Dec 19 18:18:10 2007 +1030

    Xi: specify correct struct when calculating size of GetDeviceControl reply.
    
    This doesn't change much, as the struct previously given has the same size as
    the ones now anyway. Still, we should be pendantic.
    
    Thanks to Simon Thum for reporting.

diff --git a/Xi/getdctl.c b/Xi/getdctl.c
index 6e1e3ef..c979959 100644
--- a/Xi/getdctl.c
+++ b/Xi/getdctl.c
@@ -265,19 +265,19 @@ ProcXGetDeviceControl(ClientPtr client)
         if (!dev->absolute)
 	    return BadMatch;
 
-        total_length = sizeof(xDeviceAbsCalibCtl);
+        total_length = sizeof(xDeviceAbsCalibState);
         break;
     case DEVICE_ABS_AREA:
         if (!dev->absolute)
 	    return BadMatch;
 
-        total_length = sizeof(xDeviceAbsAreaCtl);
+        total_length = sizeof(xDeviceAbsAreaState);
         break;
     case DEVICE_CORE:
-        total_length = sizeof(xDeviceCoreCtl);
+        total_length = sizeof(xDeviceCoreState);
         break;
     case DEVICE_ENABLE:
-        total_length = sizeof(xDeviceEnableCtl);
+        total_length = sizeof(xDeviceEnableState);
         break;
     default:
 	return BadValue;
commit 66b00029e587cec628d0041179a301e888277f8e
Author: Peter Hutterer <peter at cs.unisa.edu.au>
Date:   Wed Dec 19 18:10:50 2007 +1030

    Xext: remove redefinition of Bool.
    
    Thanks to Simon Thum.

diff --git a/Xext/dpmsstubs.c b/Xext/dpmsstubs.c
index fad07bd..0f59d51 100644
--- a/Xext/dpmsstubs.c
+++ b/Xext/dpmsstubs.c
@@ -26,8 +26,6 @@ Equipment Corporation.
 
 ******************************************************************/
 
-typedef int Bool;
-
 #ifdef HAVE_DIX_CONFIG_H
 #include <dix-config.h>
 #endif
commit bcad2a5a24f30cfdf9eca31915ed5a55ed094285
Author: Eamon Walsh <ewalsh at tycho.nsa.gov>
Date:   Tue Dec 18 20:19:26 2007 -0500

    XACE: Too many arguments to selection access hook.

diff --git a/xfixes/select.c b/xfixes/select.c
index 2321212..415257e 100755
--- a/xfixes/select.c
+++ b/xfixes/select.c
@@ -135,8 +135,7 @@ XFixesSelectSelectionInput (ClientPtr	pClient,
     int rc;
     SelectionEventPtr	*prev, e;
 
-    rc = XaceHook(XACE_SELECTION_ACCESS, pClient, selection, NULL,
-		  DixGetAttrAccess);
+    rc = XaceHook(XACE_SELECTION_ACCESS, pClient, selection, DixGetAttrAccess);
     if (rc != Success)
 	return rc;
 
commit 7721d3e9217b41aab3a0ee5eaa52f5b53cbb07db
Author: Adam Jackson <ajax at redhat.com>
Date:   Tue Dec 18 19:14:26 2007 -0500

    Reference cvt and gtf in the xorg.conf man page.

diff --git a/hw/xfree86/doc/man/xorg.conf.man.pre b/hw/xfree86/doc/man/xorg.conf.man.pre
index 3c657d0..77439a5 100644
--- a/hw/xfree86/doc/man/xorg.conf.man.pre
+++ b/hw/xfree86/doc/man/xorg.conf.man.pre
@@ -2144,7 +2144,9 @@ The data therein is not used in this release.
 General:
 .BR X (__miscmansuffix__),
 .BR Xserver (__appmansuffix__),
-.BR __xservername__ (__appmansuffix__).
+.BR __xservername__ (__appmansuffix__),
+.BR cvt (__appmansuffix__),
+.BR gtf (__appmansuffix__).
 .PP
 .B Not all modules or interfaces are available on all platforms.
 .PP
commit 51fab1eb30691c503f1b4dc98b465f2bc2e1394e
Author: Sam Lau <sam.lau at sun.com>
Date:   Tue Dec 18 11:38:47 2007 -0800

    Sun bug 6278039: Xevie checking wrong size in swapped XevieSelectInput requests
    
    <http://bugs.opensolaris.org/bugdatabase/view_bug.do?bug_id=6278039>

diff --git a/Xext/xevie.c b/Xext/xevie.c
index 7dd67bb..ea409f1 100644
--- a/Xext/xevie.c
+++ b/Xext/xevie.c
@@ -368,7 +368,7 @@ int SProcSelectInput (ClientPtr client)
 
     REQUEST (xXevieSelectInputReq);
     swaps (&stuff->length, n);
-    REQUEST_AT_LEAST_SIZE (xXevieSendReq);
+    REQUEST_AT_LEAST_SIZE (xXevieSelectInputReq);
     swapl(&stuff->event_mask, n);
     return ProcSelectInput (client);
 }
commit 97c82ce0510808ea9d8a37a0a121e750f6dd8158
Author: Eamon Walsh <ewalsh at tycho.nsa.gov>
Date:   Mon Dec 17 23:11:29 2007 -0500

    XACE: Restore the old background None behavior in response to bug #13683.
    
    From the X11 protocol spec:
    
    "If background None is specified, the window has no defined background."
    
    This means that toolkits and apps cannot rely on the "transparent" nature
    of the current implementation!  At some point before the next release,
    XACE will switch back to a solid background as the default.

diff --git a/Xext/xace.h b/Xext/xace.h
index de0e8fe..6f92290 100644
--- a/Xext/xace.h
+++ b/Xext/xace.h
@@ -32,6 +32,9 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 #define XaceNumberEvents		0
 #define XaceNumberErrors		0
 
+/* Default window background */
+#define XaceBackgroundNoneState		None
+
 /* security hooks */
 /* Constants used to identify the available security hooks
  */
@@ -94,6 +97,9 @@ extern void XaceCensorImage(
 
 #else /* XACE */
 
+/* Default window background */
+#define XaceBackgroundNoneState		None
+
 /* Define calls away when XACE is not being built. */
 
 #ifdef __GNUC__
diff --git a/dix/window.c b/dix/window.c
index 0404655..33cf76b 100644
--- a/dix/window.c
+++ b/dix/window.c
@@ -704,7 +704,7 @@ CreateWindow(Window wid, WindowPtr pParent, int x, int y, unsigned w,
 	return NullWindow;
     }
 
-    pWin->backgroundState = BackgroundPixel;
+    pWin->backgroundState = XaceBackgroundNoneState;
     pWin->background.pixel = 0;
 
     pWin->borderIsPixel = pParent->borderIsPixel;
@@ -1016,7 +1016,7 @@ ChangeWindowAttributes(WindowPtr pWin, Mask vmask, XID *vlist, ClientPtr client)
 		if (!pWin->parent)
 		    MakeRootTile(pWin);
 		else {
-		    pWin->backgroundState = BackgroundPixel;
+		    pWin->backgroundState = XaceBackgroundNoneState;
 		    pWin->background.pixel = 0;
 		}
 	    }
commit 6a5c3e04fa43b98ccffd69ad86dd781602f88d0b
Author: Dave Airlie <airlied at redhat.com>
Date:   Mon Dec 17 14:59:12 2007 +1000

    mi: set the private key to a unique non-zero value

diff --git a/mi/miscrinit.c b/mi/miscrinit.c
index a1fb2e2..7ca5f5d 100644
--- a/mi/miscrinit.c
+++ b/mi/miscrinit.c
@@ -301,7 +301,7 @@ miAllocateGCPrivateIndex()
     return privateKey;
 }
 
-_X_EXPORT DevPrivateKey miZeroLineScreenKey;
+_X_EXPORT DevPrivateKey miZeroLineScreenKey = &miZeroLineScreenKey;
 
 _X_EXPORT void
 miSetZeroLineBias(pScreen, bias)
commit a18d28a5efbe6021d6c800506cece28a73545aad
Author: Dave Airlie <airlied at redhat.com>
Date:   Mon Dec 17 13:49:16 2007 +1000

    damn then my cut-n-paste ate my end of lines...

diff --git a/configure.ac b/configure.ac
index 082ab86..0b718c9 100644
--- a/configure.ac
+++ b/configure.ac
@@ -1779,7 +1779,7 @@ fi
 AM_CONDITIONAL(LAUNCHD, [test "x$LAUNCHD" = "xyes"])
 
 AC_MSG_CHECKING([whether to build Xdmx DDX])
-PKG_CHECK_MODULES([DMXMODULES], [xmuu xext x11 xrender xfixes xfont xi dmxproto
+PKG_CHECK_MODULES([DMXMODULES], [xmuu xext x11 xrender xfixes xfont xi dmxproto xau $XDMCP_MODULES], [have_dmx=yes], [have_dmx=no])
 if test "x$DMX" = xauto; then
        DMX="$have_dmx"
 fi
@@ -1793,7 +1793,7 @@ if test "x$DMX" = xyes; then
        fi
        DMX_INCLUDES="$XEXT_INC $RENDER_INC $XTRAP_INC $RECORD_INC"
        XDMX_CFLAGS="$DMXMODULES_CFLAGS"
-       XDMX_LIBS="$XEXT_LIB $FB_LIB $CONFIG_LIB $RENDER_LIB $XTRAP_LIB $RECORD_
+       XDMX_LIBS="$XEXT_LIB $FB_LIB $CONFIG_LIB $RENDER_LIB $XTRAP_LIB $RECORD_LIB $XI_LIB $XKB_LIB $XKB_STUB_LIB $MIEXT_SHADOW_LIB $MIEXT_DAMAGE_LIB"
        XDMX_SYS_LIBS="$DMXMODULES_LIBS"
        AC_SUBST([XDMX_CFLAGS])
        AC_SUBST([XDMX_LIBS])
commit d096bbd01bf7c7e15b5a2c582718f3333e063ddc
Author: Dave Airlie <airlied at redhat.com>
Date:   Mon Dec 17 13:45:15 2007 +1000

    Xquartz ate my DMX - thanks

diff --git a/configure.ac b/configure.ac
index 86338e0..082ab86 100644
--- a/configure.ac
+++ b/configure.ac
@@ -1778,9 +1778,55 @@ if test "x$LAUNCHD" = "xyes" ; then
 fi
 AM_CONDITIONAL(LAUNCHD, [test "x$LAUNCHD" = "xyes"])
 
+AC_MSG_CHECKING([whether to build Xdmx DDX])
+PKG_CHECK_MODULES([DMXMODULES], [xmuu xext x11 xrender xfixes xfont xi dmxproto
+if test "x$DMX" = xauto; then
+       DMX="$have_dmx"
+fi
 AC_MSG_RESULT([$DMX])
 AM_CONDITIONAL(DMX, [test "x$DMX" = xyes])
 
+if test "x$DMX" = xyes; then
+       if test "x$have_dmx" = xno; then
+               AC_MSG_ERROR([Xdmx build explicitly requested, but required
+                             modules not found.])
+       fi
+       DMX_INCLUDES="$XEXT_INC $RENDER_INC $XTRAP_INC $RECORD_INC"
+       XDMX_CFLAGS="$DMXMODULES_CFLAGS"
+       XDMX_LIBS="$XEXT_LIB $FB_LIB $CONFIG_LIB $RENDER_LIB $XTRAP_LIB $RECORD_
+       XDMX_SYS_LIBS="$DMXMODULES_LIBS"
+       AC_SUBST([XDMX_CFLAGS])
+       AC_SUBST([XDMX_LIBS])
+       AC_SUBST([XDMX_SYS_LIBS])
+
+dnl USB sources in DMX require <linux/input.h>
+       AC_CHECK_HEADER([linux/input.h], DMX_BUILD_USB="yes",
+                       DMX_BUILD_USB="no")
+dnl Linux sources in DMX require <linux/keyboard.h>
+       AC_CHECK_HEADER([linux/keyboard.h], DMX_BUILD_LNX="yes",
+                       DMX_BUILD_LNX="no")
+       if test "x$GLX" = xyes; then
+               PKG_CHECK_MODULES([GL], [glproto])
+       fi
+       PKG_CHECK_MODULES([XDMXCONFIG_DEP], [xaw7 xmu xt xpm x11])
+       AC_SUBST(XDMXCONFIG_DEP_CFLAGS)
+       AC_SUBST(XDMXCONFIG_DEP_LIBS)
+       PKG_CHECK_MODULES([DMXEXAMPLES_DEP], [dmx xext x11])
+       AC_SUBST(DMXEXAMPLES_DEP_LIBS)
+       PKG_CHECK_MODULES([DMXXMUEXAMPLES_DEP], [dmx xmu xext x11])
+       AC_SUBST(DMXXMUEXAMPLES_DEP_LIBS)
+       PKG_CHECK_MODULES([DMXXIEXAMPLES_DEP], [dmx xi xext x11])
+       AC_SUBST(DMXXIEXAMPLES_DEP_LIBS)
+       PKG_CHECK_MODULES([XTSTEXAMPLES_DEP], [xtst xext x11])
+       AC_SUBST(XTSTEXAMPLES_DEP_LIBS)
+       PKG_CHECK_MODULES([XRESEXAMPLES_DEP], [xres xext x11])
+       AC_SUBST(XRESEXAMPLES_DEP_LIBS)
+       PKG_CHECK_MODULES([X11EXAMPLES_DEP], [xext x11])
+       AC_SUBST(X11EXAMPLES_DEP_LIBS)
+fi
+AM_CONDITIONAL([DMX_BUILD_LNX], [test "x$DMX_BUILD_LNX" = xyes])
+AM_CONDITIONAL([DMX_BUILD_USB], [test "x$DMX_BUILD_USB" = xyes])
+
 dnl kdrive DDX
 
 XEPHYR_LIBS=
commit bf20c4374aeb5160a0dc372df9b49f1bbc05f078
Author: Jeremy Huddleston <jeremy at yuffie.local>
Date:   Sun Dec 16 01:14:32 2007 -0800

    Xquartz: Removed launchd plist and x11-exec.  The relevant code is now in xinit.
    (cherry picked from commit 767b4c9d9daa5d0ea59ac1f0d70146798da631cb)

diff --git a/hw/xquartz/Makefile.am b/hw/xquartz/Makefile.am
index 0326f78..831ba49 100644
--- a/hw/xquartz/Makefile.am
+++ b/hw/xquartz/Makefile.am
@@ -9,12 +9,6 @@ AM_CPPFLAGS = \
 
 if X11APP
 X11APP_SUBDIRS = bundle
-
-if LAUNCHD
-libexec_PROGRAMS = x11-exec
-x11_exec_LDFLAGS = -framework CoreServices
-endif
-
 endif
 
 SUBDIRS = . xpr $(X11APP_SUBDIRS)
diff --git a/hw/xquartz/bundle/Makefile.am b/hw/xquartz/bundle/Makefile.am
index da297e9..9511670 100644
--- a/hw/xquartz/bundle/Makefile.am
+++ b/hw/xquartz/bundle/Makefile.am
@@ -8,17 +8,6 @@ x11app:
 install-data-hook:
 	xcodebuild install DSTROOT="/$(DESTDIR)" INSTALL_PATH="$(APPLE_APPLICATIONS_DIR)" DEPLOYMENT_LOCATION=YES SKIP_INSTALL=NO ARCHS="$(X11APP_ARCHS)"
 
-if LAUNCHD
-launchagents_PRE = org.x.X11.plist.pre
-launchagents_DATA = $(launchagents_PRE:plist.pre=plist)
-
-CPP_FILES_FLAGS = -D__libexecdir__="${libexecdir}"
-
-CLEANFILES = $(launchagents_DATA)
-endif
-
-include $(top_srcdir)/cpprules.in
-
 clean-local:
 	rm -rf build
 
@@ -26,7 +15,6 @@ resourcedir=$(libdir)/X11/xserver
 resource_DATA = Xquartz.plist
 
 EXTRA_DIST = \
-	org.x.X11.plist \
 	Info.plist \
 	X11.icns \
 	bundle-main.c \
diff --git a/hw/xquartz/bundle/org.x.X11.plist.pre b/hw/xquartz/bundle/org.x.X11.plist.pre
deleted file mode 100644
index 83d8b2f..0000000
--- a/hw/xquartz/bundle/org.x.X11.plist.pre
+++ /dev/null
@@ -1,23 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
-<plist version="1.0">
-<dict>
-	<key>Label</key>
-		<string>org.x.X11</string>
-	<key>ProgramArguments</key>
-		<array>
-		<string>__libexecdir__/x11-exec</string>
-		<string>-launchd</string>
-		</array>
-	<key>Sockets</key>
-		<dict>
-		<key>:0</key>
-			<dict>
-			<key>SecureSocketWithKey</key>
-				<string>DISPLAY</string>
-			</dict>
-		</dict>
-	<key>ServiceIPC</key>
-		<true/>
-</dict>
-</plist>
diff --git a/hw/xquartz/x11-exec.c b/hw/xquartz/x11-exec.c
deleted file mode 100644
index 105fd72..0000000
--- a/hw/xquartz/x11-exec.c
+++ /dev/null
@@ -1,84 +0,0 @@
-/* x11-exec.c -- Find X11.app by bundle-id and exec it.  This is so launchd
-   can correctly find X11.app, even if the user moved it.
-
- Copyright (c) 2007 Apple, Inc.
- 
- Permission is hereby granted, free of charge, to any person
- obtaining a copy of this software and associated documentation files
- (the "Software"), to deal in the Software without restriction,
- including without limitation the rights to use, copy, modify, merge,
- publish, distribute, sublicense, and/or sell copies of the Software,
- and to permit persons to whom the Software is furnished to do so,
- subject to the following conditions:
- 
- The above copyright notice and this permission notice shall be
- included in all copies or substantial portions of the Software.
- 
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
- EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
- MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
- NONINFRINGEMENT.  IN NO EVENT SHALL THE ABOVE LISTED COPYRIGHT
- HOLDER(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
- WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
- DEALINGS IN THE SOFTWARE.
- 
- Except as contained in this notice, the name(s) of the above
- copyright holders shall not be used in advertising or otherwise to
- promote the sale, use or other dealings in this Software without
- prior written authorization. */
-
-#include <CoreServices/CoreServices.h>
-#include <stdio.h>
-
-#define kX11AppBundleId "org.x.X11"
-#define kX11AppBundlePath "/Contents/MacOS/X11"
-
-int main(int argc, char **argv) {
-  char x11_path[PATH_MAX];
-  char** args = NULL;
-  CFURLRef appURL = NULL;
-  OSStatus osstatus = LSFindApplicationForInfo(kLSUnknownCreator, CFSTR(kX11AppBundleId), 
-					       nil, nil, &appURL);
-  
-  switch (osstatus) {
-  case noErr:
-    if (appURL == NULL) {
-      fprintf(stderr, "%s: Invalid response from LSFindApplicationForInfo(%s)\n", 
-	      argv[0], kX11AppBundleId);
-      exit(1);
-    }
-    if (!CFURLGetFileSystemRepresentation(appURL, true, (unsigned char *)x11_path, sizeof(x11_path))) {
-      fprintf(stderr, "%s: Error resolving URL for %s\n", argv[0], kX11AppBundleId);
-      exit(2);
-    }
-    
-    args = (char**)malloc(sizeof (char*) * (argc + 1));
-    strlcat(x11_path, kX11AppBundlePath, sizeof(x11_path));
-    if (args) {
-      int i;
-      args[0] = x11_path;
-      for (i = 1; i < argc; ++i) {
-        args[i] = argv[i];
-      }
-      args[i] = NULL;
-    }
-    
-    fprintf(stderr, "X11.app = %s\n", x11_path);
-    execv(x11_path, args);
-    fprintf(stderr, "Error executing X11.app (%s):", x11_path);
-    perror(NULL);
-    exit(3);
-    break;
-  case kLSApplicationNotFoundErr:
-    fprintf(stderr, "%s: Unable to find application for %s\n", argv[0], kX11AppBundleId);
-    exit(4);
-  default:
-    fprintf(stderr, "%s: Unable to find application for %s, error code = %d\n", 
-	    argv[0], kX11AppBundleId, osstatus);
-    exit(5);
-  }
-  /* not reached */
-}
-
-    
commit 58c2898b62fbf0d8e0f175de7cc208dc29d93788
Author: Samuel Thibault <samuel.thibault at ens-lyon.org>
Date:   Sun Dec 16 01:21:45 2007 +0100

    xfree86: permit access to io port 0xffff on the hurd

diff --git a/hw/xfree86/os-support/hurd/hurd_video.c b/hw/xfree86/os-support/hurd/hurd_video.c
index 8e6ae8d..04763ad 100644
--- a/hw/xfree86/os-support/hurd/hurd_video.c
+++ b/hw/xfree86/os-support/hurd/hurd_video.c
@@ -126,7 +126,7 @@ extern int ioperm(unsigned long __from, unsigned long __num, int __turn_on);
 Bool
 xf86EnableIO()
 {
-    if (ioperm(0, 0xffff, 1)) {
+    if (ioperm(0, 0x10000, 1)) {
 	FatalError("xf86EnableIO: ioperm() failed (%s)\n", strerror(errno));
 	return FALSE;
     }
@@ -138,7 +138,7 @@ xf86EnableIO()
 void
 xf86DisableIO()
 {
-    ioperm(0,0xffff,0);
+    ioperm(0,0x10000,0);
     return;
 }
 
commit b4ef8885e1697b83a0dcc9f7fe79155f19241798
Author: Jeremy Huddleston <jeremy at yuffie.local>
Date:   Sat Dec 15 14:00:19 2007 -0800

    Xquartz: Fixed launchd detection

diff --git a/configure.ac b/configure.ac
index 1d8aa60..86338e0 100644
--- a/configure.ac
+++ b/configure.ac
@@ -1120,10 +1120,6 @@ XSERVER_SYS_LIBS="${XSERVERLIBS_LIBS} ${SYS_LIBS} ${LIBS} ${LIBCRYPTO}"
 AC_SUBST([XSERVER_LIBS])
 AC_SUBST([XSERVER_SYS_LIBS])
 
-if test "x$HAVE_LAUNCHD" = xyes; then
-   XSERVER_CFLAGS="$XSERVER_CFLAGS -DHAVE_LAUNCHD"
-fi
-
 # The Xorg binary needs to export symbols so that they can be used from modules
 # Some platforms require extra flags to do this.   gcc should set these flags
 # when -rdynamic is passed to it, other compilers/linkers may need to be added
@@ -1772,17 +1768,19 @@ if test "x$LAUNCHD" = "xauto"; then
 	if test "x$XQUARTZ" = "xyes" ; then
 		LAUNCHD=yes
 	else
+		unset LAUNCHD
 		AC_CHECK_PROG(LAUNCHD, [launchd], [yes], [no])
 	fi
 fi
-AC_MSG_RESULT([$DMX])
-AM_CONDITIONAL(DMX, [test "x$DMX" = xyes])
 
 if test "x$LAUNCHD" = "xyes" ; then
 	AC_DEFINE(HAVE_LAUNCHD, 1, [launchd support available])
 fi
 AM_CONDITIONAL(LAUNCHD, [test "x$LAUNCHD" = "xyes"])
 
+AC_MSG_RESULT([$DMX])
+AM_CONDITIONAL(DMX, [test "x$DMX" = xyes])
+
 dnl kdrive DDX
 
 XEPHYR_LIBS=
commit ff5abc72fcc459d7eac663e5f8e4d40b28749841
Author: Otavio Salvador <otavio at ossystems.com.br>
Date:   Fri Dec 14 17:59:29 2007 -0200

    registry: XREGISTRY_UNKNOWN needs to be defined even if XREGISTRY isn't enabled
    
    In case XREGISTRY isn't enabled, XREGISTRY_UNKNOWN is used but it's
    not being available. It's now always available.

diff --git a/include/registry.h b/include/registry.h
index edd6ef9..29e5fdf 100644
--- a/include/registry.h
+++ b/include/registry.h
@@ -12,6 +12,11 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 #ifndef DIX_REGISTRY_H
 #define DIX_REGISTRY_H
 
+/*
+ * Result returned from any unsuccessful lookup
+ */
+#define XREGISTRY_UNKNOWN "<unknown>"
+
 #ifdef XREGISTRY
 
 #include "resource.h"
@@ -36,11 +41,6 @@ const char *LookupErrorName(int error);
 const char *LookupResourceName(RESTYPE rtype);
 
 /*
- * Result returned from any unsuccessful lookup
- */
-#define XREGISTRY_UNKNOWN "<unknown>"
-
-/*
  * Setup and teardown
  */
 void dixResetRegistry(void);
commit a3f7f7b60e391e6106f5db40b3fe5fbc67ccd836
Author: Ben Byer <bbyer at bbyer.apple.com>
Date:   Thu Dec 13 20:45:14 2007 -0800

    clarified debug message to indicate that we're sleeping
    (in case we get reports about slow launch times, this will
    help clarify what's happening)
    (cherry picked from commit 2eea3483cf893f8f81bacd434b31408dfb38cb06)

diff --git a/hw/xquartz/bundle/bundle-main.c b/hw/xquartz/bundle/bundle-main.c
index 53f60a3..681e1a8 100644
--- a/hw/xquartz/bundle/bundle-main.c
+++ b/hw/xquartz/bundle/bundle-main.c
@@ -52,7 +52,7 @@ int main(int argc, char **argv) {
         /* Now, try to open a display, if so, run the launcher */
         display = XOpenDisplay(NULL);
         if(display) {
-            fprintf(stderr, "X11.app: main(): closing the display");
+            fprintf(stderr, "X11.app: main(): closing the display and sleeping");
             /* Could open the display, start the launcher */
             XCloseDisplay(display);
             
commit e0e59b3bbc4d8e7ac3934a6f6a9e4a15b328c475
Author: Ben Byer <bbyer at bbyer.apple.com>
Date:   Thu Dec 13 20:44:33 2007 -0800

    we need to link against CoreServices, not ApplicationServices
    (cherry picked from commit ba4d2096e7953ef5b971682f0e28535da968acb1)

diff --git a/hw/xquartz/Makefile.am b/hw/xquartz/Makefile.am
index 97b8c94..0326f78 100644
--- a/hw/xquartz/Makefile.am
+++ b/hw/xquartz/Makefile.am
@@ -12,7 +12,7 @@ X11APP_SUBDIRS = bundle
 
 if LAUNCHD
 libexec_PROGRAMS = x11-exec
-x11_exec_LDFLAGS = -framework ApplicationServices
+x11_exec_LDFLAGS = -framework CoreServices
 endif
 
 endif
commit 062d9234e233fc4c1c617f59093da973c9d3e2ce
Author: Ben Byer <bbyer at bbyer.apple.com>
Date:   Thu Dec 13 20:40:27 2007 -0800

    fixed bug in x11-exec that prevent icon from showing up
    (cherry picked from commit e1f4a0c20d3a52d98954c4b28d0ec4d44564bc32)

diff --git a/hw/xquartz/x11-exec.c b/hw/xquartz/x11-exec.c
index d0b5c49..105fd72 100644
--- a/hw/xquartz/x11-exec.c
+++ b/hw/xquartz/x11-exec.c
@@ -28,7 +28,7 @@
  promote the sale, use or other dealings in this Software without
  prior written authorization. */
 
-#include <ApplicationServices/ApplicationServices.h>
+#include <CoreServices/CoreServices.h>
 #include <stdio.h>
 
 #define kX11AppBundleId "org.x.X11"
@@ -36,10 +36,10 @@
 
 int main(int argc, char **argv) {
   char x11_path[PATH_MAX];
+  char** args = NULL;
   CFURLRef appURL = NULL;
-  OSStatus osstatus = 
-    LSFindApplicationForInfo(kLSUnknownCreator, CFSTR(kX11AppBundleId), 
-			     nil, nil, &appURL);
+  OSStatus osstatus = LSFindApplicationForInfo(kLSUnknownCreator, CFSTR(kX11AppBundleId), 
+					       nil, nil, &appURL);
   
   switch (osstatus) {
   case noErr:
@@ -52,10 +52,20 @@ int main(int argc, char **argv) {
       fprintf(stderr, "%s: Error resolving URL for %s\n", argv[0], kX11AppBundleId);
       exit(2);
     }
-    strlcpy(argv[0], "X11", strlen(argv[0])+1);
+    
+    args = (char**)malloc(sizeof (char*) * (argc + 1));
     strlcat(x11_path, kX11AppBundlePath, sizeof(x11_path));
-//  fprintf(stderr, "X11.app = %s\n", x11_path);
-    execv(x11_path, argv);
+    if (args) {
+      int i;
+      args[0] = x11_path;
+      for (i = 1; i < argc; ++i) {
+        args[i] = argv[i];
+      }
+      args[i] = NULL;
+    }
+    
+    fprintf(stderr, "X11.app = %s\n", x11_path);
+    execv(x11_path, args);
     fprintf(stderr, "Error executing X11.app (%s):", x11_path);
     perror(NULL);
     exit(3);
commit 95c02adea80a14e18bb51876bc1418eccdade31d
Author: Jeremy Huddleston <jeremy at yuffie.local>
Date:   Fri Dec 14 15:21:40 2007 -0800

    Xquartz: Fixed cpprules include

diff --git a/hw/xquartz/bundle/Makefile.am b/hw/xquartz/bundle/Makefile.am
index 775e1aa..da297e9 100644
--- a/hw/xquartz/bundle/Makefile.am
+++ b/hw/xquartz/bundle/Makefile.am
@@ -15,9 +15,9 @@ launchagents_DATA = $(launchagents_PRE:plist.pre=plist)
 CPP_FILES_FLAGS = -D__libexecdir__="${libexecdir}"
 
 CLEANFILES = $(launchagents_DATA)
+endif
 
 include $(top_srcdir)/cpprules.in
-endif
 
 clean-local:
 	rm -rf build
commit 86730337001ba4db6d77fe42406695e32784b157
Author: Otavio Salvador <otavio at ossystems.com.br>
Date:   Fri Dec 14 08:46:35 2007 -0200

    kdrive/ati: use operating system input devices

diff --git a/hw/kdrive/ati/ati_stub.c b/hw/kdrive/ati/ati_stub.c
index 3669fd7..f881b7f 100644
--- a/hw/kdrive/ati/ati_stub.c
+++ b/hw/kdrive/ati/ati_stub.c
@@ -50,14 +50,7 @@ InitOutput(ScreenInfo *pScreenInfo, int argc, char **argv)
 void
 InitInput(int argc, char **argv)
 {
-        KdKeyboardInfo *ki = NULL;
-        
-        KdAddPointerDriver(&LinuxMouseDriver);
-        ki = KdNewKeyboard();
-        if (ki) {
-            ki->driver = &LinuxKeyboardDriver;
-            KdAddKeyboard(ki);
-        }
+	KdOsAddInputDrivers();
 	KdInitInput();
 }
 
commit e110255501e2f699709e6978f5e52d3be96333c8
Author: Otavio Salvador <otavio at ossystems.com.br>
Date:   Fri Dec 14 08:45:09 2007 -0200

    kdrive/vesa: use operating system input devices

diff --git a/hw/kdrive/vesa/vesainit.c b/hw/kdrive/vesa/vesainit.c
index 90b1681..a5e216c 100644
--- a/hw/kdrive/vesa/vesainit.c
+++ b/hw/kdrive/vesa/vesainit.c
@@ -70,15 +70,7 @@ InitOutput (ScreenInfo *pScreenInfo, int argc, char **argv)
 void
 InitInput (int argc, char **argv)
 {
-    KdKeyboardInfo *ki = NULL;
-        
-    KdAddPointerDriver(&LinuxMouseDriver);
-    KdAddKeyboardDriver(&LinuxKeyboardDriver);
-    ki = KdNewKeyboard();
-    if (ki) {
-        ki->driver = &LinuxKeyboardDriver;
-        KdAddKeyboard(ki);
-    }
+    KdOsAddInputDrivers();
     KdInitInput();
 }
 
commit 863ba390e9fdf0d37cdf03bf5eebe7fdfe6288f5
Author: Otavio Salvador <otavio at ossystems.com.br>
Date:   Fri Dec 14 00:03:13 2007 -0200

    kdrive/fbdev: use operating system input devices

diff --git a/hw/kdrive/fbdev/fbinit.c b/hw/kdrive/fbdev/fbinit.c
index 5e1c88b..de80c79 100644
--- a/hw/kdrive/fbdev/fbinit.c
+++ b/hw/kdrive/fbdev/fbinit.c
@@ -42,17 +42,7 @@ InitOutput (ScreenInfo *pScreenInfo, int argc, char **argv)
 void
 InitInput (int argc, char **argv)
 {
-    KdKeyboardInfo *ki;
-
-    KdAddKeyboardDriver (&LinuxKeyboardDriver);
-    KdAddPointerDriver (&LinuxMouseDriver);
-#ifdef TSLIB
-    KdAddPointerDriver (&TsDriver);
-#endif
-
-    ki = KdParseKeyboard ("keybd");
-    KdAddKeyboard(ki);
-
+    KdOsAddInputDrivers ();
     KdInitInput ();
 }
 
commit ca59d3f7bdb5f3724ff45ea57912c0b1098a73d6
Author: Arkadiusz Miskiewicz <arekm at maven.pl>
Date:   Thu Dec 13 00:09:08 2007 +0200

    Xprint: Clean up generated files
    
    Remember to clean generated wrapper files.

diff --git a/hw/xprint/Makefile.am b/hw/xprint/Makefile.am
index c440473..1b80048 100644
--- a/hw/xprint/Makefile.am
+++ b/hw/xprint/Makefile.am
@@ -53,3 +53,5 @@ Xprt_SOURCES =			\
         $(top_srcdir)/fb/fbcmap_mi.c
 
 EXTRA_DIST = ValTree.c
+
+CLEANFILES = miinitext-wrapper.c dpmsstubs-wrapper.c
commit 5b02a6ca5b31db69d08f2f452494c0f93a6260d9
Author: Bartosz Fabianowski <freebsd at chillt.de>
Date:   Fri Dec 7 02:38:14 2007 +0000

    Input: Fix proximity events with valuators
    
    Initialise num_events to 1, so we always send a proximity event, and then
    optionally valuator events.  Also make sure mieq can deal with valuator
    events sent after proximity events.

diff --git a/dix/getevents.c b/dix/getevents.c
index 08744ae..40fc7f2 100644
--- a/dix/getevents.c
+++ b/dix/getevents.c
@@ -707,7 +707,7 @@ _X_EXPORT int
 GetProximityEvents(xEvent *events, DeviceIntPtr pDev, int type,
                    int first_valuator, int num_valuators, int *valuators)
 {
-    int num_events = 0;
+    int num_events = 1;
     deviceKeyButtonPointer *kbp = (deviceKeyButtonPointer *) events;
 
     /* Sanity checks. */
diff --git a/mi/mieq.c b/mi/mieq.c
index d946e7d..c2f687a 100644
--- a/mi/mieq.c
+++ b/mi/mieq.c
@@ -128,7 +128,9 @@ mieqEnqueue(DeviceIntPtr pDev, xEvent *e)
         if (oldtail == miEventQueue.head ||
             !(lastkbp->type == DeviceMotionNotify ||
               lastkbp->type == DeviceButtonPress ||
-              lastkbp->type == DeviceButtonRelease) ||
+              lastkbp->type == DeviceButtonRelease ||
+              lastkbp->type == ProximityIn ||
+              lastkbp->type == ProximityOut) ||
             ((lastkbp->deviceid & DEVICE_BITS) !=
              (v->deviceid & DEVICE_BITS))) {
             ErrorF("mieqEnequeue: out-of-order valuator event; dropping.\n");
commit a14a143832be844b4b890b0160ccb9fc8293c28c
Author: Eamon Walsh <ewalsh at tycho.nsa.gov>
Date:   Fri Dec 14 00:57:16 2007 -0500

    Bump server version for devPrivates rework / XACE.

diff --git a/configure.ac b/configure.ac
index 49d57d7..1d8aa60 100644
--- a/configure.ac
+++ b/configure.ac
@@ -26,7 +26,7 @@ dnl
 dnl Process this file with autoconf to create configure.
 
 AC_PREREQ(2.57)
-AC_INIT([xorg-server], 1.4.99.1, [https://bugs.freedesktop.org/enter_bug.cgi?product=xorg], xorg-server)
+AC_INIT([xorg-server], 1.4.99.2, [https://bugs.freedesktop.org/enter_bug.cgi?product=xorg], xorg-server)
 AC_CONFIG_SRCDIR([Makefile.am])
 AM_INIT_AUTOMAKE([dist-bzip2 foreign])
 AM_MAINTAINER_MODE
commit a2df51f8e95a814c54b806814020155ac8bd177d
Author: Eamon Walsh <ewalsh at tycho.nsa.gov>
Date:   Fri Dec 14 00:53:54 2007 -0500

    Bump video driver ABI and extension ABI for devPrivates rework.

diff --git a/hw/xfree86/common/xf86Module.h b/hw/xfree86/common/xf86Module.h
index 852e51f..240155c 100644
--- a/hw/xfree86/common/xf86Module.h
+++ b/hw/xfree86/common/xf86Module.h
@@ -83,9 +83,9 @@ typedef enum {
  * mask is 0xFFFF0000.
  */
 #define ABI_ANSIC_VERSION	SET_ABI_VERSION(0, 3)
-#define ABI_VIDEODRV_VERSION	SET_ABI_VERSION(3, 0)
+#define ABI_VIDEODRV_VERSION	SET_ABI_VERSION(4, 0)
 #define ABI_XINPUT_VERSION	SET_ABI_VERSION(2, 0)
-#define ABI_EXTENSION_VERSION	SET_ABI_VERSION(0, 3)
+#define ABI_EXTENSION_VERSION	SET_ABI_VERSION(1, 0)
 #define ABI_FONT_VERSION	SET_ABI_VERSION(0, 5)
 
 #define MODINFOSTRING1	0xef23fdc5


More information about the xorg-commit mailing list