xserver: Branch 'master' - 6 commits

Keith Packard keithp at kemper.freedesktop.org
Sat Jun 5 19:45:08 PDT 2010


 Xext/geext.c                          |    6 
 Xext/geint.h                          |    3 
 Xext/panoramiX.c                      |   23 -
 Xext/saver.c                          |    7 
 Xext/security.c                       |    6 
 Xext/shm.c                            |   29 +
 Xext/xselinux_hooks.c                 |   15 
 Xext/xselinuxint.h                    |    9 
 Xext/xtest.c                          |    7 
 Xext/xvmain.c                         |   11 
 Xext/xvmc.c                           |   14 
 Xi/exglobals.h                        |    4 
 Xi/extinit.c                          |    6 
 composite/compext.c                   |    8 
 composite/compinit.c                  |   17 -
 composite/compint.h                   |   11 
 damageext/damageext.c                 |    7 
 dbe/dbe.c                             |   33 --
 dbe/dbestruct.h                       |    8 
 dbe/midbe.c                           |   22 -
 dbe/midbe.h                           |   11 
 dix/colormap.c                        |   25 +
 dix/cursor.c                          |   35 +-
 dix/devices.c                         |    7 
 dix/dispatch.c                        |   22 -
 dix/extension.c                       |   11 
 dix/gc.c                              |    9 
 dix/globals.c                         |    2 
 dix/main.c                            |   21 -
 dix/pixmap.c                          |   17 +
 dix/privates.c                        |  537 +++++++++++++++++++++++-----------
 dix/property.c                        |   15 
 dix/resource.c                        |    2 
 dix/selection.c                       |    3 
 dix/window.c                          |   21 -
 exa/exa.c                             |   24 -
 fb/fb.h                               |   19 -
 fb/fballpriv.c                        |   44 +-
 fb/fbcmap.c                           |    4 
 fb/fboverlay.c                        |    8 
 fb/fbpixmap.c                         |    4 
 fb/fbscreen.c                         |    3 
 fb/wfbrename.h                        |    8 
 glx/glxext.c                          |    6 
 glx/glxscreens.c                      |    7 
 hw/dmx/dmx.h                          |   23 +
 hw/dmx/dmxcmap.h                      |    3 
 hw/dmx/dmxgc.c                        |    2 
 hw/dmx/dmxgc.h                        |    3 
 hw/dmx/dmxpict.c                      |    2 
 hw/dmx/dmxpict.h                      |    4 
 hw/dmx/dmxpixmap.c                    |    5 
 hw/dmx/dmxpixmap.h                    |    3 
 hw/dmx/dmxscrinit.c                   |   28 -
 hw/dmx/dmxscrinit.h                   |    3 
 hw/dmx/dmxwindow.c                    |    2 
 hw/dmx/dmxwindow.h                    |    3 
 hw/kdrive/ephyr/ephyrdriext.c         |    8 
 hw/kdrive/src/kdrive.c                |    6 
 hw/kdrive/src/kdrive.h                |    4 
 hw/kdrive/src/kxv.c                   |   14 
 hw/vfb/InitOutput.c                   |    7 
 hw/xfree86/common/xf86.h              |   13 
 hw/xfree86/common/xf86DGA.c           |   35 +-
 hw/xfree86/common/xf86DPMS.c          |    9 
 hw/xfree86/common/xf86Globals.c       |   12 
 hw/xfree86/common/xf86Init.c          |   10 
 hw/xfree86/common/xf86RandR.c         |    7 
 hw/xfree86/common/xf86VGAarbiter.c    |   13 
 hw/xfree86/common/xf86VidMode.c       |   16 -
 hw/xfree86/common/xf86cmap.c          |   33 +-
 hw/xfree86/common/xf86cmap.h          |    4 
 hw/xfree86/common/xf86fbman.c         |   18 -
 hw/xfree86/common/xf86xv.c            |   21 -
 hw/xfree86/common/xf86xvmc.c          |    7 
 hw/xfree86/dixmods/extmod/xf86dga2.c  |   19 -
 hw/xfree86/dixmods/extmod/xf86vmode.c |   18 -
 hw/xfree86/dri/dri.c                  |   15 
 hw/xfree86/dri2/dri2.c                |   24 +
 hw/xfree86/exa/examodule.c            |    7 
 hw/xfree86/modes/xf86RandR12.c        |    6 
 hw/xfree86/ramdac/xf86Cursor.c        |    6 
 hw/xfree86/ramdac/xf86CursorPriv.h    |    3 
 hw/xfree86/shadowfb/shadow.c          |   13 
 hw/xfree86/xaa/xaaInit.c              |   19 -
 hw/xfree86/xaa/xaaOverlayDF.c         |    7 
 hw/xfree86/xaa/xaaStateChange.c       |    5 
 hw/xfree86/xaa/xaaWrapper.c           |   13 
 hw/xnest/Color.c                      |    4 
 hw/xnest/GC.c                         |    3 
 hw/xnest/Pixmap.c                     |   10 
 hw/xnest/Screen.c                     |   15 
 hw/xnest/Window.c                     |    3 
 hw/xnest/XNCursor.h                   |    3 
 hw/xnest/XNGC.h                       |    3 
 hw/xnest/XNPixmap.h                   |    3 
 hw/xnest/XNWindow.h                   |    3 
 hw/xquartz/darwin.c                   |    6 
 hw/xquartz/darwin.h                   |    3 
 hw/xquartz/quartz.c                   |    6 
 hw/xquartz/quartzCommon.h             |    3 
 hw/xquartz/xpr/dri.c                  |   25 +
 hw/xquartz/xpr/driWrap.c              |   12 
 hw/xquartz/xpr/xprCursor.c            |    8 
 hw/xwin/win.h                         |   16 -
 hw/xwin/winallpriv.c                  |    6 
 hw/xwin/winglobals.c                  |   22 -
 include/cursor.h                      |    3 
 include/cursorstr.h                   |    4 
 include/pixmap.h                      |    3 
 include/privates.h                    |  268 ++++++++++++----
 include/xkbsrv.h                      |    4 
 mi/micmap.c                           |    6 
 mi/micmap.h                           |    4 
 mi/midispcur.c                        |   57 ++-
 mi/miline.h                           |    3 
 mi/mioverlay.c                        |   13 
 mi/mipointer.c                        |   12 
 mi/mipointer.h                        |    6 
 mi/miscrinit.c                        |   12 
 mi/misprite.c                         |   14 
 miext/cw/cw.c                         |   24 -
 miext/cw/cw.h                         |   13 
 miext/damage/damage.c                 |   34 +-
 miext/rootless/rootlessCommon.h       |   15 
 miext/rootless/rootlessScreen.c       |   22 -
 miext/shadow/shadow.c                 |    7 
 randr/randr.c                         |   15 
 randr/randrstr.h                      |    6 
 record/record.c                       |    4 
 render/animcur.c                      |   19 -
 render/glyph.c                        |   36 --
 render/picture.c                      |   21 -
 render/picture.h                      |    1 
 render/picturestr.h                   |    8 
 render/render.c                       |    6 
 xfixes/cursor.c                       |    7 
 xfixes/xfixes.c                       |    6 
 xkb/xkb.c                             |    3 
 xkb/xkbActions.c                      |    3 
 140 files changed, 1506 insertions(+), 891 deletions(-)

New commits:
commit ab07e2b8ededaa2193fc199a8c09623d84032280
Author: Keith Packard <keithp at keithp.com>
Date:   Fri Apr 30 19:38:48 2010 -0700

    Allocate per-screen device/cursor-bits private keys in midispcur
    
    midispcur was abusing the CursorScreenKey to index the cursor_bits
    privates, it also had a MAXSCREENS array of keys to index device
    privates. Switch both of these to the new dixCreatePrivateKey API and
    store a pointer to that in the screen private.
    
    Signed-off-by: Keith Packard <keithp at keithp.com>
    Reviewed-by: Jamey Sharp <jamey at minilop.net>

diff --git a/mi/midispcur.c b/mi/midispcur.c
index b412477..323ee02 100644
--- a/mi/midispcur.c
+++ b/mi/midispcur.c
@@ -59,14 +59,7 @@ static DevPrivateKeyRec miDCScreenKeyRec;
 
 static Bool	miDCCloseScreen(int index, ScreenPtr pScreen);
 
-/* per bits per-screen private data */
-static DevPrivateKeyRec miDCCursorBitsKeyRec[MAXSCREENS];
-#define miDCCursorBitsKey(screen)	(&miDCCursorBitsKeyRec[(screen)->myNum])
-
-/* per device per-screen private data */
-static DevPrivateKeyRec miDCDeviceKeyRec[MAXSCREENS];
-#define miDCDeviceKey(screen)		(&miDCDeviceKeyRec[(screen)->myNum])
-
+/* per device private data */
 typedef struct {
     GCPtr	    pSourceGC, pMaskGC;
     GCPtr	    pSaveGC, pRestoreGC;
@@ -86,9 +79,15 @@ typedef struct {
  * in the pCursorBuffers array. 
  */
 typedef struct {
-    CloseScreenProcPtr CloseScreen;
+    CloseScreenProcPtr	CloseScreen;
+    DevPrivateKey	device_key;
+    DevPrivateKey	cursor_bits_key;
 } miDCScreenRec, *miDCScreenPtr;
 
+#define miGetDCScreen(s)	((miDCScreenPtr)(dixLookupPrivate(&(s)->devPrivates, miDCScreenKey)))
+#define miDCDeviceKey(s) 	(miGetDCScreen(s)->device_key)
+#define miDCCursorBitsKey(s)	(miGetDCScreen(s)->cursor_bits_key)
+
 /* per-cursor per-screen private data */
 typedef struct {
     PixmapPtr		sourceBits;	    /* source bits */
@@ -106,16 +105,16 @@ miDCInitialize (ScreenPtr pScreen, miPointerScreenFuncPtr screenFuncs)
     if (!dixRegisterPrivateKey(&miDCScreenKeyRec, PRIVATE_SCREEN, 0))
 	return FALSE;
 
-    if (!dixRegisterPrivateKey(&miDCDeviceKeyRec[pScreen->myNum], PRIVATE_DEVICE, 0))
-	return FALSE;
-
-    if (!dixRegisterPrivateKey(&miDCCursorBitsKeyRec[pScreen->myNum], PRIVATE_CURSOR_BITS, 0))
-	return FALSE;
-
     pScreenPriv = malloc(sizeof (miDCScreenRec));
     if (!pScreenPriv)
 	return FALSE;
 
+    pScreenPriv->cursor_bits_key = dixCreatePrivateKey(PRIVATE_CURSOR_BITS, 0);
+    pScreenPriv->device_key = dixCreatePrivateKey(PRIVATE_DEVICE, 0);
+    if (!pScreenPriv->cursor_bits_key || !pScreenPriv->device_key) {
+	free(pScreenPriv);
+	return FALSE;
+    }
     pScreenPriv->CloseScreen = pScreen->CloseScreen;
     pScreen->CloseScreen = miDCCloseScreen;
 
commit 34db537907c6cb2635dbefdce7dcfcae90f7c902
Author: Keith Packard <keithp at keithp.com>
Date:   Fri Apr 30 19:36:33 2010 -0700

    Add dixCreatePrivateKey API
    
    Keys need to persist through server reset so that the private system
    can be cleaned up in dixResetPrivates. In particular, this means that
    keys cannot live in objects freed at reset time. This API provides
    suitable object lifetime by having the privates code free the key in
    the reset path.
    
    Signed-off-by: Keith Packard <keithp at keithp.com>
    Reviewed-by: Jamey Sharp <jamey at minilop.net>

diff --git a/dix/privates.c b/dix/privates.c
index 736e950..ec818d4 100644
--- a/dix/privates.c
+++ b/dix/privates.c
@@ -229,6 +229,7 @@ dixRegisterPrivateKey(DevPrivateKey key, DevPrivateType type, unsigned size)
     key->size = size;
     key->initialized = TRUE;
     key->type = type;
+    key->allocated = FALSE;
     key->next = keys[type].key;
     keys[type].key = key;
 
@@ -236,6 +237,30 @@ dixRegisterPrivateKey(DevPrivateKey key, DevPrivateType type, unsigned size)
 }
 
 /*
+ * Allocate a new private key.
+ *
+ * This manages the storage of the key object itself, freeing it when the
+ * privates system is restarted at server reset time. All other keys
+ * are expected to be statically allocated as the privates must be
+ * reset after all objects have been freed
+ */
+DevPrivateKey
+dixCreatePrivateKey(DevPrivateType type, unsigned size)
+{
+    DevPrivateKey	key;
+
+    key = calloc(sizeof (DevPrivateKeyRec), 1);
+    if (!key)
+	return NULL;
+    if (!dixRegisterPrivateKey(key, type, size)) {
+	free(key);
+	return NULL;
+    }
+    key->allocated = TRUE;
+    return key;
+}
+
+/*
  * Initialize privates by zeroing them
  */
 void
@@ -444,13 +469,16 @@ dixResetPrivates(void)
     DevPrivateType	t;
 
     for (t = PRIVATE_XSELINUX; t < PRIVATE_LAST; t++) {
-	DevPrivateKey	key;
+	DevPrivateKey	key, next;
 
-	for (key = keys[t].key; key; key = key->next) {
+	for (key = keys[t].key; key; key = next) {
+	    next = key->next;
 	    key->offset = 0;
 	    key->initialized = FALSE;
 	    key->size = 0;
 	    key->type = 0;
+	    if (key->allocated)
+		free(key);
 	}
 	if (keys[t].created) {
 	    ErrorF("%d %ss still allocated at reset\n",
diff --git a/include/privates.h b/include/privates.h
index e2bdafd..4fed7d0 100644
--- a/include/privates.h
+++ b/include/privates.h
@@ -60,6 +60,7 @@ typedef struct _DevPrivateKeyRec {
     int			offset;
     int			size;
     Bool		initialized;
+    Bool		allocated;
     DevPrivateType	type;
     struct _DevPrivateKeyRec	*next;
 } DevPrivateKeyRec, *DevPrivateKey;
@@ -99,6 +100,17 @@ dixPrivateKeyRegistered(DevPrivateKey key)
 }
 
 /*
+ * Allocate a new private key.
+ *
+ * This manages the storage of the key object itself, freeing it when the
+ * privates system is restarted at server reset time. All other keys
+ * are expected to be statically allocated as the privates must be
+ * reset after all objects have been freed
+ */
+extern _X_EXPORT DevPrivateKey
+dixCreatePrivateKey(DevPrivateType type, unsigned size);
+
+/*
  * Get the address of the private storage.
  *
  * For keys with pre-defined storage, this gets the base of that storage
commit 495fc3eb2d6c98bde82ae1278f89fcf131fd9bf8
Author: Keith Packard <keithp at keithp.com>
Date:   Fri Apr 30 19:38:38 2010 -0700

    Change devPrivates implementation.
    
    Each key now declares which object type it belongs to, this permits
    keys for different types to share the same offset within the allocated
    privates. As a special case for XSELinux, a key may be allocated as
    PRIVATE_XSELINUX which will allow it to continue to be used across the
    relevant object types.
    
    Signed-off-by: Keith Packard <keithp at keithp.com>
    Reviewed-by: Jamey Sharp <jamey at minilop.net>

diff --git a/dix/privates.c b/dix/privates.c
index 87831c2..736e950 100644
--- a/dix/privates.c
+++ b/dix/privates.c
@@ -25,6 +25,28 @@ other dealings in this Software without prior written authorization
 from The Open Group.
 
 */
+/*
+ * Copyright © 2010, Keith Packard
+ * Copyright © 2010, Jamey Sharp
+ *
+ * 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, and
+ * that the name of the copyright holders not be used in advertising or
+ * publicity pertaining to distribution of the software without specific,
+ * written prior permission.  The copyright holders make no representations
+ * about the suitability of this software for any purpose.  It is provided "as
+ * is" without express or implied warranty.
+ *
+ * THE COPYRIGHT HOLDERS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
+ * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
+ * EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY SPECIAL, INDIRECT OR
+ * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
+ * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
+ * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
+ * OF THIS SOFTWARE.
+ */
 
 #ifdef HAVE_DIX_CONFIG_H
 #include <dix-config.h>
@@ -38,192 +60,300 @@ from The Open Group.
 #include "cursorstr.h"
 #include "colormapst.h"
 #include "inputstr.h"
-
-struct _Private {
-    int state;
-    pointer value;
+#include "scrnintstr.h"
+#include "extnsionst.h"
+
+static struct {
+    DevPrivateKey	key;
+    unsigned		offset;
+    int			created;
+    int			allocated;
+} keys[PRIVATE_LAST];
+
+static const Bool xselinux_private[PRIVATE_LAST] = {
+    [PRIVATE_CLIENT] = TRUE,
+    [PRIVATE_WINDOW] = TRUE,
+    [PRIVATE_PIXMAP] = TRUE,
+    [PRIVATE_GC] = TRUE,
+    [PRIVATE_CURSOR] = TRUE,
+    [PRIVATE_COLORMAP] = TRUE,
+    [PRIVATE_DEVICE] = TRUE,
+    [PRIVATE_EXTENSION] = TRUE,
+    [PRIVATE_SELECTION] = TRUE,
+    [PRIVATE_PROPERTY] = TRUE,
+    [PRIVATE_PICTURE] = TRUE,
+    [PRIVATE_GLYPHSET] = TRUE,
 };
 
-typedef struct _PrivateDesc {
-    DevPrivateKey key;
-    unsigned size;
-} PrivateDescRec;
+typedef Bool (*FixupFunc)(PrivatePtr *privates, int offset, unsigned bytes);
 
-#define PRIV_MAX 256
-#define PRIV_STEP 16
-
-static int number_privates_allocated;
-static int number_private_ptrs_allocated;
-static int bytes_private_data_allocated;
+static Bool
+dixReallocPrivates(PrivatePtr *privates, int old_offset, unsigned bytes)
+{
+    void	*new_privates;
 
-/* list of all allocated privates */
-static PrivateDescRec items[PRIV_MAX];
-static int nextPriv;
+    new_privates = realloc(*privates, old_offset + bytes);
+    if (!new_privates)
+	return FALSE;
+    memset((char *) new_privates + old_offset, '\0', bytes);
+    *privates = new_privates;
+    return TRUE;
+}
 
-static PrivateDescRec *
-findItem(const DevPrivateKey key)
+static Bool
+dixMovePrivates(PrivatePtr *privates, int new_offset, unsigned bytes)
 {
-    if (!key->key) {
-	if (nextPriv >= PRIV_MAX)
-	    return NULL;
+    memmove((char *) *privates + bytes, *privates, new_offset - bytes);
+    memset(*privates, '\0', bytes);
+    return TRUE;
+}
 
-	items[nextPriv].key = key;
-	key->key = nextPriv;
-	nextPriv++;
-    }
+static Bool
+fixupScreens(FixupFunc fixup, unsigned bytes)
+{
+    int s;
+    for (s = 0; s < screenInfo.numScreens; s++)
+	if (!fixup(&screenInfo.screens[s]->devPrivates, keys[PRIVATE_SCREEN].offset, bytes))
+	    return FALSE;
+    return TRUE;
+}
 
-    return items + key->key;
+static Bool
+fixupServerClient(FixupFunc fixup, unsigned bytes)
+{
+    if (serverClient)
+	return fixup(&serverClient->devPrivates, keys[PRIVATE_CLIENT].offset, bytes);
+    return TRUE;
 }
 
-static _X_INLINE int
-privateExists(PrivateRec **privates, const DevPrivateKey key)
+static Bool
+fixupExtensions(FixupFunc fixup, unsigned bytes)
 {
-    return key->key && *privates &&
-	(*privates)[0].state > key->key &&
-	(*privates)[key->key].state;
+    unsigned char 	major;
+    ExtensionEntry	*extension;
+    for (major = EXTENSION_BASE; (extension = GetExtensionEntry(major)); major++)
+	if (!fixup(&extension->devPrivates, keys[PRIVATE_EXTENSION].offset, bytes))
+	    return FALSE;
+    return TRUE;
 }
 
-/*
- * Request pre-allocated space.
- */
-int
-dixRegisterPrivateKey(const DevPrivateKey key, DevPrivateType type, unsigned size)
+static Bool
+fixupDefaultColormaps(FixupFunc fixup, unsigned bytes)
 {
-    PrivateDescRec *item = findItem(key);
-    if (!item)
-	return FALSE;
-    if (size > item->size)
-	item->size = size;
+    int s;
+    for (s = 0; s < screenInfo.numScreens; s++) {
+	ColormapPtr cmap;
+	dixLookupResourceByType((pointer *) &cmap, screenInfo.screens[s]->defColormap,
+	                        RT_COLORMAP, serverClient, DixCreateAccess);
+	if (cmap && !fixup(&cmap->devPrivates, keys[PRIVATE_COLORMAP].offset, bytes))
+	    return FALSE;
+    }
     return TRUE;
 }
 
+static Bool (* const allocated_early[PRIVATE_LAST])(FixupFunc, unsigned) = {
+    [PRIVATE_SCREEN] = fixupScreens,
+    [PRIVATE_CLIENT] = fixupServerClient,
+    [PRIVATE_EXTENSION] = fixupExtensions,
+    [PRIVATE_COLORMAP] = fixupDefaultColormaps,
+};
+
 /*
- * Allocate a private and attach it to an existing object.
+ * Register a private key. This takes the type of object the key will
+ * be used with, which may be PRIVATE_ALL indicating that this key
+ * will be used with all of the private objects. If 'size' is
+ * non-zero, then the specified amount of space will be allocated in
+ * the private storage. Otherwise, space for a single pointer will
+ * be allocated which can be set with dixSetPrivate
  */
-static pointer *
-dixAllocatePrivate(PrivateRec **privates, const DevPrivateKey key)
+Bool
+dixRegisterPrivateKey(DevPrivateKey key, DevPrivateType type, unsigned size)
 {
-    PrivateDescRec *item = findItem(key);
-    PrivateRec *ptr;
-    pointer value;
-    int oldsize, newsize;
+    DevPrivateType	t;
+    int			offset;
+    unsigned		bytes;
 
-    newsize = (key->key / PRIV_STEP + 1) * PRIV_STEP;
-
-    /* resize or init privates array */
-    if (!item)
-	return NULL;
-
-    /* initialize privates array if necessary */
-    if (!*privates) {
-	++number_privates_allocated;
-	number_private_ptrs_allocated += newsize;
-	ptr = calloc(newsize, sizeof(*ptr));
-	if (!ptr)
-	    return NULL;
-	*privates = ptr;
-	(*privates)[0].state = newsize;
+    if (key->initialized) {
+	assert (size == key->size);
+	return TRUE;
     }
 
-    oldsize = (*privates)[0].state;
-
-    /* resize privates array if necessary */
-    if (key->key >= oldsize) {
-	ptr = realloc(*privates, newsize * sizeof(*ptr));
-	if (!ptr)
-	    return NULL;
-	memset(ptr + oldsize, 0, (newsize - oldsize) * sizeof(*ptr));
-	*privates = ptr;
-	(*privates)[0].state = newsize;
-	number_private_ptrs_allocated -= oldsize;
-	number_private_ptrs_allocated += newsize;
-    }
+    /* Compute required space */
+    bytes = size;
+    if (size == 0)
+	bytes = sizeof (void *);
+
+    /* align to void * size */
+    bytes = (bytes + sizeof (void *) - 1) & ~(sizeof (void *) - 1);
+
+    /* Update offsets for all affected keys */
+    if (type == PRIVATE_XSELINUX) {
+	DevPrivateKey	k;
+
+	/* Resize if we can, or make sure nothing's allocated if we can't
+	 */
+	for (t = PRIVATE_XSELINUX; t < PRIVATE_LAST; t++)
+	    if (xselinux_private[t]) {
+		if (!allocated_early[t])
+		    assert (!keys[t].created);
+		else if (!allocated_early[t](dixReallocPrivates, bytes))
+		    return FALSE;
+	    }
 
-    /* initialize slot */
-    ptr = *privates + key->key;
-    ptr->state = 1;
-    if (item->size) {
-	value = calloc(item->size, 1);
-	if (!value)
-	    return NULL;
-	bytes_private_data_allocated += item->size;
-	ptr->value = value;
+	/* Move all existing keys up in the privates space to make
+	 * room for this new global key
+	 */
+	for (t = PRIVATE_XSELINUX; t < PRIVATE_LAST; t++) {
+	    if (xselinux_private[t]) {
+		for (k = keys[t].key; k; k = k->next)
+		    k->offset += bytes;
+		keys[t].offset += bytes;
+		if (allocated_early[t])
+		    allocated_early[t](dixMovePrivates, bytes);
+	    }
+	}
+
+	offset = 0;
+    } else {
+	/* Resize if we can, or make sure nothing's allocated if we can't */
+	if (!allocated_early[type])
+	    assert(!keys[type].created);
+	else if (!allocated_early[type](dixReallocPrivates, bytes))
+	    return FALSE;
+	offset = keys[type].offset;
+	keys[type].offset += bytes;
     }
 
-    return &ptr->value;
+    /* Setup this key */
+    key->offset = offset;
+    key->size = size;
+    key->initialized = TRUE;
+    key->type = type;
+    key->next = keys[type].key;
+    keys[type].key = key;
+
+    return TRUE;
 }
 
 /*
- * Look up a private pointer.
+ * Initialize privates by zeroing them
  */
-pointer
-dixLookupPrivate(PrivateRec **privates, const DevPrivateKey key)
+void
+_dixInitPrivates(PrivatePtr *privates, void *addr, DevPrivateType type)
 {
-    pointer *ptr;
-
-    assert (key->key != 0);
-    if (privateExists(privates, key))
-	return (*privates)[key->key].value;
+    keys[type].created++;
+    if (xselinux_private[type])
+	keys[PRIVATE_XSELINUX].created++;
+    if (keys[type].offset == 0)
+	addr = 0;
+    *privates = addr;
+    memset(addr, '\0', keys[type].offset);
+}
 
-    ptr = dixAllocatePrivate(privates, key);
-    return ptr ? *ptr : NULL;
+/*
+ * Clean up privates
+ */
+void
+_dixFiniPrivates(PrivatePtr privates, DevPrivateType type)
+{
+    keys[type].created--;
+    if (xselinux_private[type])
+	keys[PRIVATE_XSELINUX].created--;
 }
 
 /*
- * Look up the address of a private pointer.
+ * Allocate new object with privates.
+ *
+ * This is expected to be invoked from the
+ * dixAllocateObjectWithPrivates macro
  */
-pointer *
-dixLookupPrivateAddr(PrivateRec **privates, const DevPrivateKey key)
+void *
+_dixAllocateObjectWithPrivates(unsigned baseSize, unsigned clear, unsigned offset, DevPrivateType type)
 {
-    assert (key->key != 0);
+    unsigned		totalSize;
+    void		*object;
+    PrivatePtr		privates;
+    PrivatePtr		*devPrivates;
+
+    assert (type > PRIVATE_SCREEN && type < PRIVATE_LAST);
+
+    /* round up so that void * is aligned */
+    baseSize = (baseSize + sizeof (void *) - 1) & ~(sizeof (void *) - 1);
+    totalSize = baseSize + keys[type].offset;
+    object = malloc(totalSize);
+    if (!object)
+	return NULL;
 
-    if (privateExists(privates, key))
-	return &(*privates)[key->key].value;
+    memset(object, '\0', clear);
+    privates = (PrivatePtr) (((char *) object) + baseSize);
+    devPrivates = (PrivatePtr *) ((char *) object + offset);
 
-    return dixAllocatePrivate(privates, key);
+    _dixInitPrivates(devPrivates, privates, type);
+
+    return object;
 }
 
 /*
- * Set a private pointer.
+ * Allocate privates separately from containing object.
+ * Used for clients and screens.
  */
-int
-dixSetPrivate(PrivateRec **privates, const DevPrivateKey key, pointer val)
+Bool
+dixAllocatePrivates(PrivatePtr *privates, DevPrivateType type)
 {
-    assert (key->key != 0);
- top:
-    if (privateExists(privates, key)) {
-	(*privates)[key->key].value = val;
-	return TRUE;
+    unsigned 	size;
+    PrivatePtr	p;
+
+    assert (type > PRIVATE_XSELINUX && type < PRIVATE_LAST);
+
+    size = keys[type].offset;
+    if (!size) {
+	p = NULL;
+    } else {
+	if (!(p = malloc(size)))
+	    return FALSE;
     }
 
-    if (!dixAllocatePrivate(privates, key))
-	return FALSE;
-    goto top;
+    _dixInitPrivates(privates, p, type);
+    ++keys[type].allocated;
+
+    return TRUE;
 }
 
 /*
- * Called to free privates at object deletion time.
+ * Free an object that has privates
+ *
+ * This is expected to be invoked from the
+ * dixFreeObjectWithPrivates macro
  */
 void
-dixFreePrivates(PrivateRec *privates, DevPrivateType type)
+_dixFreeObjectWithPrivates(void *object, PrivatePtr privates, DevPrivateType type)
 {
-    int i;
-
-    if (privates) {
-	number_private_ptrs_allocated -= privates->state;
-	number_privates_allocated--;
-	for (i = 1; i < privates->state; i++)
-	    if (privates[i].state) {
-		/* free pre-allocated memory */
-		if (items[i].size)
-		    free(privates[i].value);
-		bytes_private_data_allocated -= items[i].size;
-	    }
-    }
+    _dixFiniPrivates(privates, type);
+    free(object);
+}
 
+/*
+ * Called to free screen or client privates
+ */
+void
+dixFreePrivates(PrivatePtr privates, DevPrivateType type)
+{
+    _dixFiniPrivates(privates, type);
+    --keys[type].allocated;
     free(privates);
 }
 
+/*
+ * Return size of privates for the specified type
+ */
+extern _X_EXPORT int
+dixPrivatesSize(DevPrivateType type)
+{
+    assert (type >= PRIVATE_SCREEN && type < PRIVATE_LAST);
+
+    return keys[type].offset;
+}
+
 /* Table of devPrivates offsets */
 static const int offsets[] = {
     -1,					/* RT_NONE */
@@ -256,32 +386,80 @@ dixLookupPrivateOffset(RESTYPE type)
     return -1;
 }
 
+static const char *key_names[PRIVATE_LAST] = {
+    /* XSELinux uses the same private keys for numerous objects */
+    [PRIVATE_XSELINUX] = "XSELINUX",
+
+    /* Otherwise, you get a private in just the requested structure
+     */
+    /* These can have objects created before all of the keys are registered */
+    [PRIVATE_SCREEN] = "SCREEN",
+    [PRIVATE_EXTENSION] = "EXTENSION",
+    [PRIVATE_COLORMAP] = "COLORMAP",
+
+    /* These cannot have any objects before all relevant keys are registered */
+    [PRIVATE_DEVICE] = "DEVICE",
+    [PRIVATE_CLIENT] = "CLIENT",
+    [PRIVATE_PROPERTY] = "PROPERTY",
+    [PRIVATE_SELECTION] = "SELECTION",
+    [PRIVATE_WINDOW] = "WINDOW",
+    [PRIVATE_PIXMAP] = "PIXMAP",
+    [PRIVATE_GC] = "GC",
+    [PRIVATE_CURSOR] = "CURSOR",
+    [PRIVATE_CURSOR_BITS] = "CURSOR_BITS",
+
+    /* extension privates */
+    [PRIVATE_DBE_WINDOW] = "DBE_WINDOW",
+    [PRIVATE_DAMAGE] = "DAMAGE",
+    [PRIVATE_GLYPH] = "GLYPH",
+    [PRIVATE_GLYPHSET] = "GLYPHSET",
+    [PRIVATE_PICTURE] = "PICTURE",
+};
+
 void
 dixPrivateUsage(void)
 {
-    ErrorF("number of private structures: %d\n",
-	   number_privates_allocated);
-    ErrorF("total number of private pointers: %d (%zd bytes)\n",
-	   number_private_ptrs_allocated,
-	   number_private_ptrs_allocated * sizeof (struct _Private));
-    ErrorF("bytes of extra private data: %d\n",
-	   bytes_private_data_allocated);
-    ErrorF("Total privates memory usage: %zd\n",
-	   bytes_private_data_allocated +
-	   number_private_ptrs_allocated * sizeof (struct _Private));
+    int objects = 0;
+    int	bytes = 0;
+    int alloc = 0;
+    DevPrivateType t;
+
+    for (t = PRIVATE_XSELINUX + 1; t < PRIVATE_LAST; t++) {
+	if (keys[t].offset) {
+	    ErrorF("%s: %d objects of %d bytes = %d total bytes %d private allocs\n",
+		   key_names[t], keys[t].created, keys[t].offset, keys[t].created * keys[t].offset,
+		   keys[t].allocated);
+	    bytes += keys[t].created * keys[t].offset;
+	    objects += keys[t].created;
+	    alloc += keys[t].allocated;
+	}
+    }
+    ErrorF("TOTAL: %d objects, %d bytes, %d allocs\n",
+	   objects, bytes, alloc);
 }
 
 void
 dixResetPrivates(void)
 {
-    int i;
-
-    /* reset private descriptors */
-    for (i = 1; i < nextPriv; i++) {
-	items[i].key->key = 0;
-	items[i].size = 0;
+    DevPrivateType	t;
+
+    for (t = PRIVATE_XSELINUX; t < PRIVATE_LAST; t++) {
+	DevPrivateKey	key;
+
+	for (key = keys[t].key; key; key = key->next) {
+	    key->offset = 0;
+	    key->initialized = FALSE;
+	    key->size = 0;
+	    key->type = 0;
+	}
+	if (keys[t].created) {
+	    ErrorF("%d %ss still allocated at reset\n",
+		   keys[t].created, key_names[t]);
+	    dixPrivateUsage();
+	}
+	keys[t].key = NULL;
+	keys[t].offset = 0;
+	keys[t].created = 0;
+	keys[t].allocated = 0;
     }
-    nextPriv = 1;
-    if (number_privates_allocated)
-	dixPrivateUsage();
 }
diff --git a/include/privates.h b/include/privates.h
index 9412fd6..e2bdafd 100644
--- a/include/privates.h
+++ b/include/privates.h
@@ -57,7 +57,11 @@ typedef enum {
 } DevPrivateType;
 
 typedef struct _DevPrivateKeyRec {
-    int			key;
+    int			offset;
+    int			size;
+    Bool		initialized;
+    DevPrivateType	type;
+    struct _DevPrivateKeyRec	*next;
 } DevPrivateKeyRec, *DevPrivateKey;
 
 /*
@@ -91,17 +95,46 @@ dixRegisterPrivateKey(DevPrivateKey key, DevPrivateType type, unsigned size);
 static inline Bool
 dixPrivateKeyRegistered(DevPrivateKey key)
 {
-    return key->key != 0;
+    return key->initialized;
+}
+
+/*
+ * Get the address of the private storage.
+ *
+ * For keys with pre-defined storage, this gets the base of that storage
+ * Otherwise, it returns the place where the private pointer is stored.
+ */
+static inline void *
+dixGetPrivateAddr(PrivatePtr *privates, const DevPrivateKey key)
+{
+    assert(key->initialized);
+    return (char *) (*privates) + key->offset;
+}
+
+/*
+ * Fetch a private pointer stored in the object
+ *
+ * Returns the pointer stored with dixSetPrivate.
+ * This must only be used with keys that have
+ * no pre-defined storage
+ */
+static inline void *
+dixGetPrivate(PrivatePtr *privates, const DevPrivateKey key)
+{
+    assert (key->size == 0);
+    return *(void **) dixGetPrivateAddr(privates, key);
 }
 
 /*
  * Associate 'val' with 'key' in 'privates' so that later calls to
  * dixLookupPrivate(privates, key) will return 'val'.
- *
- * dixSetPrivate returns FALSE if a memory allocation fails.
  */
-extern _X_EXPORT int
-dixSetPrivate(PrivatePtr *privates, const DevPrivateKey key, pointer val);
+static inline void
+dixSetPrivate(PrivatePtr *privates, const DevPrivateKey key, pointer val)
+{
+    assert (key->size == 0);
+    *(pointer *) dixGetPrivateAddr(privates, key) = val;
+}
 
 #include "dix.h"
 #include "resource.h"
@@ -113,28 +146,42 @@ dixSetPrivate(PrivatePtr *privates, const DevPrivateKey key, pointer val);
  * storage. For privates without defined storage, return the pointer
  * contents
  */
-extern _X_EXPORT pointer
-dixLookupPrivate(PrivatePtr *privates, const DevPrivateKey key);
+static inline pointer
+dixLookupPrivate(PrivatePtr *privates, const DevPrivateKey key)
+{
+    if (key->size)
+	return dixGetPrivateAddr(privates, key);
+    else
+	return dixGetPrivate(privates, key);
+}
 
 /*
- * Look up the address of a private pointer.  If 'key' is not associated with a
- * value in 'privates', then dixLookupPrivateAddr calls dixAllocatePrivate and
- * returns a pointer to the resulting associated value.
+ * Look up the address of the pointer to the storage
  *
- * dixLookupPrivateAddr returns NULL if 'key' was not previously associated in
- * 'privates' and a memory allocation fails.
+ * This returns the place where the private pointer is stored,
+ * which is only valid for privates without predefined storage.
  */
-extern _X_EXPORT pointer *
-dixLookupPrivateAddr(PrivatePtr *privates, const DevPrivateKey key);
+static inline pointer *
+dixLookupPrivateAddr(PrivatePtr *privates, const DevPrivateKey key)
+{
+    assert (key->size == 0);
+    return dixGetPrivateAddr(privates, key);
+}
 
 /*
- * Allocates private data separately from main object (clients and colormaps)
+ * Allocates private data separately from main object.
+ *
+ * For objects created during server initialization, this allows those
+ * privates to be re-allocated as new private keys are registered.
+ *
+ * This includes screens, the serverClient, default colormaps and
+ * extensions entries.
  */
-static inline Bool
-dixAllocatePrivates(PrivatePtr *privates, DevPrivateType type) { *privates = NULL; return TRUE; }
+extern _X_EXPORT Bool
+dixAllocatePrivates(PrivatePtr *privates, DevPrivateType type);
 
 /*
- * Frees separately allocated private data (screens and clients)
+ * Frees separately allocated private data
  */
 extern _X_EXPORT void
 dixFreePrivates(PrivatePtr privates, DevPrivateType type);
@@ -142,48 +189,44 @@ dixFreePrivates(PrivatePtr privates, DevPrivateType type);
 /*
  * Initialize privates by zeroing them
  */
-static inline void
-_dixInitPrivates(PrivatePtr *privates, void *addr, DevPrivateType type) { *privates = NULL; }
+extern _X_EXPORT void
+_dixInitPrivates(PrivatePtr *privates, void *addr, DevPrivateType type);
 
 #define dixInitPrivates(o, v, type) _dixInitPrivates(&(o)->devPrivates, (v), type);
 
 /*
  * Clean up privates
  */
-static inline void
-_dixFiniPrivates(PrivatePtr privates, DevPrivateType type) { dixFreePrivates(privates, type); }
+extern _X_EXPORT void
+_dixFiniPrivates(PrivatePtr privates, DevPrivateType type);
 
 #define dixFiniPrivates(o,t)	_dixFiniPrivates((o)->devPrivates,t)
 
 /*
  * Allocates private data at object creation time. Required
- * for all objects other than ScreenRecs.
+ * for almost all objects, except for the list described
+ * above for dixAllocatePrivates.
  */
-static inline void *
-_dixAllocateObjectWithPrivates(unsigned size, unsigned clear, unsigned offset, DevPrivateType type) {
-    return calloc(size, 1);
-}
+extern _X_EXPORT void *
+_dixAllocateObjectWithPrivates(unsigned size, unsigned clear, unsigned offset, DevPrivateType type);
 
 #define dixAllocateObjectWithPrivates(t, type) (t *) _dixAllocateObjectWithPrivates(sizeof(t), sizeof(t), offsetof(t, devPrivates), type)
 
-static inline void
-_dixFreeObjectWithPrivates(void *object, PrivatePtr privates, DevPrivateType type) {
-    dixFreePrivates(privates, type);
-    free(object);
-}
+extern _X_EXPORT void
+_dixFreeObjectWithPrivates(void *object, PrivatePtr privates, DevPrivateType type);
 
 #define dixFreeObjectWithPrivates(o,t) _dixFreeObjectWithPrivates(o, (o)->devPrivates, t)
 
 /*
  * Return size of privates for the specified type
  */
-static inline int
-dixPrivatesSize(DevPrivateType type) { return 0; }
+extern _X_EXPORT int
+dixPrivatesSize(DevPrivateType type);
 
 /*
  * Dump out private stats to ErrorF
  */
-void
+extern void
 dixPrivateUsage(void);
 
 /*
@@ -195,6 +238,7 @@ dixResetPrivates(void);
 
 /*
  * Looks up the offset where the devPrivates field is located.
+ *
  * Returns -1 if the specified resource has no dev privates.
  * The position of the devPrivates field varies by structure
  * and calling code might only know the resource type, not the
commit faeebead7bfcc78535757ca7acc1faf7554c03b7
Author: Keith Packard <keithp at keithp.com>
Date:   Mon Apr 26 17:22:21 2010 -0700

    Change the devPrivates API to require dixRegisterPrivateKey
    
    This patch only changes the API, not the implementation of the
    devPrivates infrastructure. This will permit a new devPrivates
    implementation to be layed into the server without requiring
    simultaneous changes in every devPrivates user.
    
    Signed-off-by: Keith Packard <keithp at keithp.com>
    Tested-by: Tiago Vignatti <tiago.vignatti at nokia.com>

diff --git a/Xext/geext.c b/Xext/geext.c
index b7f32c0..e61989c 100644
--- a/Xext/geext.c
+++ b/Xext/geext.c
@@ -36,12 +36,10 @@
 
 #define rClient(obj) (clients[CLIENT_ID((obj)->resource)])
 
-static int GEClientPrivateKeyIndex;
-DevPrivateKey GEClientPrivateKey = &GEClientPrivateKeyIndex;
+DevPrivateKeyRec GEClientPrivateKeyRec;
 
 int RT_GECLIENT  = 0;
 
-
 GEExtension GEExtensions[MAXEXTENSIONS];
 
 /* Major available requests */
@@ -209,7 +207,7 @@ GEExtensionInit(void)
 {
     ExtensionEntry *extEntry;
 
-    if (!dixRequestPrivate(GEClientPrivateKey, sizeof(GEClientInfoRec)))
+    if (!dixRegisterPrivateKey(&GEClientPrivateKeyRec, PRIVATE_CLIENT, sizeof(GEClientInfoRec)))
         FatalError("GEExtensionInit: GE private request failed.\n");
 
     if(!AddCallback(&ClientStateCallback, GEClientCallback, 0))
diff --git a/Xext/geint.h b/Xext/geint.h
index 10a33ce..3e2b8e1 100644
--- a/Xext/geint.h
+++ b/Xext/geint.h
@@ -37,7 +37,8 @@
 #include "extnsionst.h"
 #include <X11/extensions/geproto.h>
 
-extern _X_EXPORT DevPrivateKey GEClientPrivateKey;
+extern _X_EXPORT DevPrivateKeyRec GEClientPrivateKeyRec;
+#define GEClientPrivateKey (&GEClientPrivateKeyRec)
 
 typedef struct _GEClientInfo {
     CARD32  major_version;
diff --git a/Xext/panoramiX.c b/Xext/panoramiX.c
index c625438..1cb58b5 100644
--- a/Xext/panoramiX.c
+++ b/Xext/panoramiX.c
@@ -103,10 +103,10 @@ static void PanoramiXResetProc(ExtensionEntry*);
 
 int (* SavedProcVector[256]) (ClientPtr client) = { NULL, };
 
-static int PanoramiXGCKeyIndex;
-static DevPrivateKey PanoramiXGCKey = &PanoramiXGCKeyIndex;
-static int PanoramiXScreenKeyIndex;
-static DevPrivateKey PanoramiXScreenKey = &PanoramiXScreenKeyIndex;
+static DevPrivateKeyRec PanoramiXGCKeyRec;
+#define PanoramiXGCKey (&PanoramiXGCKeyRec)
+static DevPrivateKeyRec PanoramiXScreenKeyRec;
+#define PanoramiXScreenKey (&PanoramiXScreenKeyRec)
 
 typedef struct {
   DDXPointRec clipOrg;
@@ -443,6 +443,16 @@ void PanoramiXExtensionInit(int argc, char *argv[])
     if (noPanoramiXExtension) 
 	return;
 
+    if (!dixRegisterPrivateKey(&PanoramiXScreenKeyRec, PRIVATE_SCREEN, 0)) {
+	noPanoramiXExtension = TRUE;
+	return;
+    }
+
+    if (!dixRegisterPrivateKey(&PanoramiXGCKeyRec, PRIVATE_GC, sizeof(PanoramiXGCRec))) {
+	noPanoramiXExtension = TRUE;
+	return;
+    }
+
     PanoramiXNumScreens = screenInfo.numScreens;
     if (PanoramiXNumScreens == 1) {		/* Only 1 screen 	*/
 	noPanoramiXExtension = TRUE;
@@ -462,11 +472,6 @@ void PanoramiXExtensionInit(int argc, char *argv[])
 	 *	run in non-PanoramiXeen mode.
 	 */
 
-	if (!dixRequestPrivate(PanoramiXGCKey, sizeof(PanoramiXGCRec))) {
-		noPanoramiXExtension = TRUE;
-		return;
-	}
-	
 	for (i = 0; i < PanoramiXNumScreens; i++) {
 	   pScreen = screenInfo.screens[i];
 	   pScreenPriv = malloc(sizeof(PanoramiXScreenRec));
diff --git a/Xext/saver.c b/Xext/saver.c
index 696c4aa..6d91ddf 100644
--- a/Xext/saver.c
+++ b/Xext/saver.c
@@ -226,8 +226,8 @@ MakeScreenPrivate (
 	ScreenPtr /* pScreen */
 	);
 
-static int ScreenPrivateKeyIndex;
-static DevPrivateKey ScreenPrivateKey = &ScreenPrivateKeyIndex;
+static DevPrivateKeyRec ScreenPrivateKeyRec;
+#define ScreenPrivateKey (&ScreenPrivateKeyRec)
 
 #define GetScreenPrivate(s) ((ScreenSaverScreenPrivatePtr) \
     dixLookupPrivate(&(s)->devPrivates, ScreenPrivateKey))
@@ -252,6 +252,9 @@ ScreenSaverExtensionInit(INITARGS)
     int		    i;
     ScreenPtr	    pScreen;
 
+    if (!dixRegisterPrivateKey(&ScreenPrivateKeyRec, PRIVATE_SCREEN, 0))
+	return;
+
     AttrType = CreateNewResourceType(ScreenSaverFreeAttr, "SaverAttr");
     SaverEventType = CreateNewResourceType(ScreenSaverFreeEvents,
 					   "SaverEvent");
diff --git a/Xext/security.c b/Xext/security.c
index e58ba10..12210f8 100644
--- a/Xext/security.c
+++ b/Xext/security.c
@@ -51,8 +51,8 @@ static RESTYPE RTEventClient;
 static CallbackListPtr SecurityValidateGroupCallback = NULL;
 
 /* Private state record */
-static int stateKeyIndex;
-static DevPrivateKey stateKey = &stateKeyIndex;
+static DevPrivateKeyRec stateKeyRec;
+#define stateKey (&stateKeyRec)
 
 /* This is what we store as client security state */
 typedef struct {
@@ -1108,7 +1108,7 @@ SecurityExtensionInit(INITARGS)
     RTEventClient |= RC_NEVERRETAIN;
 
     /* Allocate the private storage */
-    if (!dixRequestPrivate(stateKey, sizeof(SecurityStateRec)))
+    if (!dixRegisterPrivateKey(stateKey, PRIVATE_CLIENT, sizeof(SecurityStateRec)))
 	FatalError("SecurityExtensionSetup: Can't allocate client private.\n");
 
     /* Register callbacks */
diff --git a/Xext/shm.c b/Xext/shm.c
index 322709c..dfd8723 100644
--- a/Xext/shm.c
+++ b/Xext/shm.c
@@ -141,10 +141,10 @@ int BadShmSegCode;
 RESTYPE ShmSegType;
 static ShmDescPtr Shmsegs;
 static Bool sharedPixmaps;
-static int shmScrPrivateKeyIndex;
-static DevPrivateKey shmScrPrivateKey = &shmScrPrivateKeyIndex;
-static int shmPixmapPrivateIndex;
-static DevPrivateKey shmPixmapPrivate = &shmPixmapPrivateIndex;
+static DevPrivateKeyRec shmScrPrivateKeyRec;
+#define shmScrPrivateKey (&shmScrPrivateKeyRec)
+static DevPrivateKeyRec shmPixmapPrivateKeyRec;
+#define shmPixmapPrivateKey (&shmPixmapPrivateKeyRec)
 static ShmFuncs miFuncs = {NULL, NULL};
 static ShmFuncs fbFuncs = {fbShmCreatePixmap, NULL};
 
@@ -244,6 +244,16 @@ ShmInitScreenPriv(ScreenPtr pScreen)
     return screen_priv;
 }
 
+static Bool
+ShmRegisterPrivates(void)
+{
+    if (!dixRegisterPrivateKey(&shmScrPrivateKeyRec, PRIVATE_SCREEN, 0))
+	return FALSE;
+    if (!dixRegisterPrivateKey(&shmPixmapPrivateKeyRec, PRIVATE_PIXMAP, 0))
+	return FALSE;
+    return TRUE;
+}
+
 void
 ShmExtensionInit(INITARGS)
 {
@@ -258,6 +268,9 @@ ShmExtensionInit(INITARGS)
     }
 #endif
 
+    if (!ShmRegisterPrivates())
+	return;
+
     sharedPixmaps = xFalse;
     {
       sharedPixmaps = xTrue;
@@ -303,6 +316,8 @@ ShmResetProc(ExtensionEntry *extEntry)
 void
 ShmRegisterFuncs(ScreenPtr pScreen, ShmFuncsPtr funcs)
 {
+    if (!ShmRegisterPrivates())
+	return;
     ShmInitScreenPriv(pScreen)->shmFuncs = funcs;
 }
 
@@ -316,7 +331,7 @@ ShmDestroyPixmap (PixmapPtr pPixmap)
     {
 	ShmDescPtr  shmdesc;
 	shmdesc = (ShmDescPtr)dixLookupPrivate(&pPixmap->devPrivates,
-					       shmPixmapPrivate);
+					       shmPixmapPrivateKey);
 	if (shmdesc)
 	    ShmDetachSegment ((pointer) shmdesc, pPixmap->drawable.id);
     }
@@ -817,7 +832,7 @@ CreatePmap:
 				shmdesc->addr + stuff->offset);
 
 	if (pMap) {
-	    dixSetPrivate(&pMap->devPrivates, shmPixmapPrivate, shmdesc);
+	    dixSetPrivate(&pMap->devPrivates, shmPixmapPrivateKey, shmdesc);
             shmdesc->refcnt++;
 	    pMap->drawable.serialNumber = NEXT_SERIAL_NUMBER;
 	    pMap->drawable.id = newPix->info[j].id;
@@ -1156,7 +1171,7 @@ CreatePmap:
 	    pDraw->pScreen->DestroyPixmap(pMap);
 	    return rc;
 	}
-	dixSetPrivate(&pMap->devPrivates, shmPixmapPrivate, shmdesc);
+	dixSetPrivate(&pMap->devPrivates, shmPixmapPrivateKey, shmdesc);
 	shmdesc->refcnt++;
 	pMap->drawable.serialNumber = NEXT_SERIAL_NUMBER;
 	pMap->drawable.id = stuff->pid;
diff --git a/Xext/xselinux_hooks.c b/Xext/xselinux_hooks.c
index 13e5243..560e1e9 100644
--- a/Xext/xselinux_hooks.c
+++ b/Xext/xselinux_hooks.c
@@ -59,12 +59,9 @@ typedef struct {
 } SELinuxAuditRec;
 
 /* private state keys */
-static int subjectKeyIndex;
-DevPrivateKey subjectKey = &subjectKeyIndex;
-static int objectKeyIndex;
-DevPrivateKey objectKey = &objectKeyIndex;
-static int dataKeyIndex;
-DevPrivateKey dataKey = &dataKeyIndex;
+DevPrivateKeyRec subjectKeyRec;
+DevPrivateKeyRec objectKeyRec;
+DevPrivateKeyRec dataKeyRec;
 
 /* audit file descriptor */
 static int audit_fd;
@@ -896,9 +893,9 @@ SELinuxFlaskInit(void)
 	FatalError("SELinux: Failed to open the system audit log\n");
 
     /* Allocate private storage */
-    if (!dixRequestPrivate(subjectKey, sizeof(SELinuxSubjectRec)) ||
-	!dixRequestPrivate(objectKey, sizeof(SELinuxObjectRec)) ||
-	!dixRequestPrivate(dataKey, sizeof(SELinuxObjectRec)))
+    if (!dixRegisterPrivateKey(subjectKey, PRIVATE_XSELINUX, sizeof(SELinuxSubjectRec)) ||
+	!dixRegisterPrivateKey(objectKey, PRIVATE_XSELINUX, sizeof(SELinuxObjectRec)) ||
+	!dixRegisterPrivateKey(dataKey, PRIVATE_XSELINUX, sizeof(SELinuxObjectRec)))
 	FatalError("SELinux: Failed to allocate private storage.\n");
 
     /* Create atoms for doing window labeling */
diff --git a/Xext/xselinuxint.h b/Xext/xselinuxint.h
index e5dbe11..011a103 100644
--- a/Xext/xselinuxint.h
+++ b/Xext/xselinuxint.h
@@ -62,9 +62,12 @@ typedef struct {
  * Globals
  */
 
-extern DevPrivateKey subjectKey;
-extern DevPrivateKey objectKey;
-extern DevPrivateKey dataKey;
+extern DevPrivateKeyRec subjectKeyRec;
+#define subjectKey (&subjectKeyRec)
+extern DevPrivateKeyRec objectKeyRec;
+#define objectKey (&objectKeyRec)
+extern DevPrivateKeyRec dataKeyRec;
+#define dataKey (&dataKeyRec)
 
 /*
  * Label functions
diff --git a/Xext/xtest.c b/Xext/xtest.c
index 263d0c1..0a6b1c5 100644
--- a/Xext/xtest.c
+++ b/Xext/xtest.c
@@ -63,8 +63,8 @@ extern int DeviceValuator;
 static EventListPtr xtest_evlist;
 
 /* Used to store if a device is an XTest Virtual device */
-static int XTestDevicePrivateKeyIndex;
-DevPrivateKey XTestDevicePrivateKey = &XTestDevicePrivateKeyIndex;
+static DevPrivateKeyRec XTestDevicePrivateKeyRec;
+#define XTestDevicePrivateKey (&XTestDevicePrivateKeyRec)
 
 /**
  * xtestpointer
@@ -102,6 +102,9 @@ static DISPATCH_PROC(SProcXTestGrabControl);
 void
 XTestExtensionInit(INITARGS)
 {
+    if (!dixRegisterPrivateKey(&XTestDevicePrivateKeyRec, PRIVATE_DEVICE, 0))
+	return;
+
     AddExtension(XTestExtensionName, 0, 0,
             ProcXTestDispatch, SProcXTestDispatch,
             NULL, StandardMinorOpcode);
diff --git a/Xext/xvmain.c b/Xext/xvmain.c
index 9a367bd..0c34b16 100644
--- a/Xext/xvmain.c
+++ b/Xext/xvmain.c
@@ -105,8 +105,8 @@ SOFTWARE.
 #endif
 #include "xvdisp.h"
 
-static int XvScreenKeyIndex;
-static DevPrivateKey XvScreenKey = &XvScreenKeyIndex;
+static DevPrivateKeyRec XvScreenKeyRec;
+#define XvScreenKey (&XvScreenKeyRec)
 unsigned long XvExtensionGeneration = 0;
 unsigned long XvScreenGeneration = 0;
 unsigned long XvResourceGeneration = 0;
@@ -156,6 +156,9 @@ XvExtensionInit(void)
 {
   ExtensionEntry *extEntry;
 
+  if (!dixRegisterPrivateKey(&XvScreenKeyRec, PRIVATE_SCREEN, 0))
+      return;
+
   /* LOOK TO SEE IF ANY SCREENS WERE INITIALIZED; IF NOT THEN
      INIT GLOBAL VARIABLES SO THE EXTENSION CAN FUNCTION */
   if (XvScreenGeneration != serverGeneration)
@@ -269,6 +272,9 @@ XvScreenInit(ScreenPtr pScreen)
       XvScreenGeneration = serverGeneration; 
     }
 
+  if (!dixRegisterPrivateKey(&XvScreenKeyRec, PRIVATE_SCREEN, 0))
+      return BadAlloc;
+
   if (dixLookupPrivate(&pScreen->devPrivates, XvScreenKey))
     {
       ErrorF("XvScreenInit: screen devPrivates ptr non-NULL before init\n");
@@ -284,7 +290,6 @@ XvScreenInit(ScreenPtr pScreen)
     }
 
   dixSetPrivate(&pScreen->devPrivates, XvScreenKey, pxvs);
-
   
   pxvs->DestroyPixmap = pScreen->DestroyPixmap;
   pxvs->DestroyWindow = pScreen->DestroyWindow;
diff --git a/Xext/xvmc.c b/Xext/xvmc.c
index 7550386..982fad1 100644
--- a/Xext/xvmc.c
+++ b/Xext/xvmc.c
@@ -33,8 +33,9 @@
 #define DR_CLIENT_DRIVER_NAME_SIZE 48
 #define DR_BUSID_SIZE 48
 
-static int XvMCScreenKeyIndex;
-static DevPrivateKey XvMCScreenKey;
+static DevPrivateKeyRec XvMCScreenKeyRec;
+#define XvMCScreenKey (&XvMCScreenKeyRec)
+static Bool XvMCInUse;
 
 unsigned long XvMCGeneration = 0;
 
@@ -138,7 +139,7 @@ ProcXvMCListSurfaceTypes(ClientPtr client)
 
     VALIDATE_XV_PORT(stuff->port, pPort, DixReadAccess);
 
-    if(XvMCScreenKey) { /* any adaptors at all */
+    if(XvMCInUse) { /* any adaptors at all */
        ScreenPtr pScreen = pPort->pAdaptor->pScreen;
        if((pScreenPriv = XVMC_GET_PRIVATE(pScreen))) {  /* any this screen */
           for(i = 0; i < pScreenPriv->num_adaptors; i++) {
@@ -193,7 +194,7 @@ ProcXvMCCreateContext(ClientPtr client)
 
     pScreen = pPort->pAdaptor->pScreen;
 
-    if(XvMCScreenKey == NULL) /* no XvMC adaptors */
+    if(!XvMCInUse) /* no XvMC adaptors */
        return BadMatch;
  
     if(!(pScreenPriv = XVMC_GET_PRIVATE(pScreen))) /* none this screen */
@@ -716,7 +717,8 @@ XvMCScreenInit(ScreenPtr pScreen, int num, XvMCAdaptorPtr pAdapt)
 {
    XvMCScreenPtr pScreenPriv;
 
-   XvMCScreenKey = &XvMCScreenKeyIndex;
+   if (!dixRegisterPrivateKey(&XvMCScreenKeyRec, PRIVATE_SCREEN, 0))
+       return BadAlloc;
 
    if(!(pScreenPriv = malloc(sizeof(XvMCScreenRec))))
 	return BadAlloc;
@@ -734,6 +736,8 @@ XvMCScreenInit(ScreenPtr pScreen, int num, XvMCAdaptorPtr pAdapt)
    pScreenPriv->minor = 0;
    pScreenPriv->patchLevel = 0;
 
+   XvMCInUse = TRUE;
+
    return Success;
 }
 
diff --git a/Xi/exglobals.h b/Xi/exglobals.h
index 2d2d25c..f755707 100644
--- a/Xi/exglobals.h
+++ b/Xi/exglobals.h
@@ -78,5 +78,7 @@ extern int DevicePropertyNotify;
 
 extern int RT_INPUTCLIENT;
 
-extern DevPrivateKey XIClientPrivateKey;
+extern DevPrivateKeyRec XIClientPrivateKeyRec;
+#define XIClientPrivateKey (&XIClientPrivateKeyRec)
+
 #endif /* EXGLOBALS_H */
diff --git a/Xi/extinit.c b/Xi/extinit.c
index f9d8dc8..eda4efb 100644
--- a/Xi/extinit.c
+++ b/Xi/extinit.c
@@ -377,9 +377,7 @@ Mask PropagateMask[MAXDEVICES];
  *
  */
 
-static int XIClientPrivateKeyIndex;
-DevPrivateKey XIClientPrivateKey = &XIClientPrivateKeyIndex;
-
+DevPrivateKeyRec XIClientPrivateKeyRec;
 
 /*****************************************************************
  *
@@ -1256,7 +1254,7 @@ XInputExtensionInit(void)
         SERVER_XI_MINOR_VERSION,
     };
 
-    if (!dixRequestPrivate(XIClientPrivateKey, sizeof(XIClientRec)))
+    if (!dixRegisterPrivateKey(&XIClientPrivateKeyRec, PRIVATE_CLIENT, sizeof(XIClientRec)))
         FatalError("Cannot request private for XI.\n");
 
     if (!AddCallback(&ClientStateCallback, XIClientCallback, 0))
diff --git a/composite/compext.c b/composite/compext.c
index d37d52a..30d9dc2 100644
--- a/composite/compext.c
+++ b/composite/compext.c
@@ -50,8 +50,8 @@
 #include "protocol-versions.h"
 
 static CARD8	CompositeReqCode;
-static int CompositeClientPrivateKeyIndex;
-static DevPrivateKey CompositeClientPrivateKey = &CompositeClientPrivateKeyIndex;
+static DevPrivateKeyRec CompositeClientPrivateKeyRec;
+#define CompositeClientPrivateKey (&CompositeClientPrivateKeyRec)
 RESTYPE		CompositeClientWindowType;
 RESTYPE		CompositeClientSubwindowsType;
 RESTYPE		CompositeClientOverlayType;
@@ -558,8 +558,8 @@ CompositeExtensionInit (void)
     if (!CompositeClientOverlayType)
 	return;
 
-    if (!dixRequestPrivate(CompositeClientPrivateKey,
-			   sizeof(CompositeClientRec)))
+    if (!dixRegisterPrivateKey(&CompositeClientPrivateKeyRec, PRIVATE_CLIENT,
+			       sizeof(CompositeClientRec)))
 	return;
 
     if (!AddCallback (&ClientStateCallback, CompositeClientCallback, 0))
diff --git a/composite/compinit.c b/composite/compinit.c
index b4deaf5..1b2cd8f 100644
--- a/composite/compinit.c
+++ b/composite/compinit.c
@@ -48,13 +48,9 @@
 #include "compint.h"
 #include "compositeext.h"
 
-static int CompScreenPrivateKeyIndex;
-DevPrivateKey CompScreenPrivateKey = &CompScreenPrivateKeyIndex;
-static int CompWindowPrivateKeyIndex;
-DevPrivateKey CompWindowPrivateKey = &CompWindowPrivateKeyIndex;
-static int CompSubwindowsPrivateKeyIndex;
-DevPrivateKey CompSubwindowsPrivateKey = &CompSubwindowsPrivateKeyIndex;
-
+DevPrivateKeyRec CompScreenPrivateKeyRec;
+DevPrivateKeyRec CompWindowPrivateKeyRec;
+DevPrivateKeyRec CompSubwindowsPrivateKeyRec;
 
 static Bool
 compCloseScreen (int index, ScreenPtr pScreen)
@@ -319,6 +315,13 @@ compScreenInit (ScreenPtr pScreen)
 {
     CompScreenPtr   cs;
 
+    if (!dixRegisterPrivateKey(&CompScreenPrivateKeyRec, PRIVATE_SCREEN, 0))
+	return FALSE;
+    if (!dixRegisterPrivateKey(&CompWindowPrivateKeyRec, PRIVATE_WINDOW, 0))
+	return FALSE;
+    if (!dixRegisterPrivateKey(&CompSubwindowsPrivateKeyRec, PRIVATE_WINDOW, 0))
+	return FALSE;
+
     if (GetCompScreen (pScreen))
 	return TRUE;
     cs = (CompScreenPtr) malloc(sizeof (CompScreenRec));
diff --git a/composite/compint.h b/composite/compint.h
index 93da4df..9c1ffd5 100644
--- a/composite/compint.h
+++ b/composite/compint.h
@@ -157,9 +157,14 @@ typedef struct _CompScreen {
     
 } CompScreenRec, *CompScreenPtr;
 
-extern DevPrivateKey CompScreenPrivateKey;
-extern DevPrivateKey CompWindowPrivateKey;
-extern DevPrivateKey CompSubwindowsPrivateKey;
+extern DevPrivateKeyRec CompScreenPrivateKeyRec;
+#define CompScreenPrivateKey (&CompScreenPrivateKeyRec)
+
+extern DevPrivateKeyRec CompWindowPrivateKeyRec;
+#define CompWindowPrivateKey (&CompWindowPrivateKeyRec)
+
+extern DevPrivateKeyRec CompSubwindowsPrivateKeyRec;
+#define CompSubwindowsPrivateKey (&CompSubwindowsPrivateKeyRec)
 
 #define GetCompScreen(s) ((CompScreenPtr) \
     dixLookupPrivate(&(s)->devPrivates, CompScreenPrivateKey))
diff --git a/damageext/damageext.c b/damageext/damageext.c
index 7717a40..926504e 100644
--- a/damageext/damageext.c
+++ b/damageext/damageext.c
@@ -32,8 +32,8 @@ static int		DamageEventBase;
 static RESTYPE		DamageExtType;
 static RESTYPE		DamageExtWinType;
 
-static int DamageClientPrivateKeyIndex;
-static DevPrivateKey DamageClientPrivateKey = &DamageClientPrivateKeyIndex;
+static DevPrivateKeyRec DamageClientPrivateKeyRec;
+#define DamageClientPrivateKey (&DamageClientPrivateKeyRec)
 
 #define prScreen	screenInfo.screens[0]
 
@@ -502,8 +502,9 @@ DamageExtensionInit(void)
     if (!DamageExtWinType)
 	return;
 
-    if (!dixRequestPrivate(DamageClientPrivateKey, sizeof (DamageClientRec)))
+    if (!dixRegisterPrivateKey(&DamageClientPrivateKeyRec, PRIVATE_CLIENT, sizeof (DamageClientRec)))
 	return;
+
     if (!AddCallback (&ClientStateCallback, DamageClientCallback, 0))
 	return;
 
diff --git a/dbe/dbe.c b/dbe/dbe.c
index 9b5474c..ef4b596 100644
--- a/dbe/dbe.c
+++ b/dbe/dbe.c
@@ -57,15 +57,13 @@
 
 /* GLOBALS */
 
-/* These are static globals copied to DBE's screen private for use by DDX */
-static int dbeScreenPrivKeyIndex;
-static DevPrivateKey dbeScreenPrivKey = &dbeScreenPrivKeyIndex;
-static int dbeWindowPrivKeyIndex;
-static DevPrivateKey dbeWindowPrivKey = &dbeWindowPrivKeyIndex;
+/* These are globals for use by DDX */
+DevPrivateKeyRec dbeScreenPrivKeyRec;
+DevPrivateKeyRec dbeWindowPrivKeyRec;
 
-/* These are static globals copied to DBE's screen private for use by DDX */
-static RESTYPE	dbeDrawableResType;
-static RESTYPE	dbeWindowPrivResType;
+/* These are globals for use by DDX */
+RESTYPE	dbeDrawableResType;
+RESTYPE	dbeWindowPrivResType;
 
 /* Used to generate DBE's BadBuffer error. */
 static int	dbeErrorBase;
@@ -254,7 +252,7 @@ ProcDbeAllocateBackBufferName(ClientPtr client)
          * Allocate a window priv.
          */
 
-        pDbeWindowPriv = calloc(1, sizeof(DbeWindowPrivRec));
+        pDbeWindowPriv = dixAllocateObjectWithPrivates(DbeWindowPrivRec, PRIVATE_DBE_WINDOW);
 	if (!pDbeWindowPriv)
             return(BadAlloc);
 
@@ -1410,8 +1408,7 @@ DbeWindowPrivDelete(pointer pDbeWinPriv, XID id)
 		      NULL);
 
         /* We are done with the window priv. */
-	dixFreePrivates(pDbeWindowPriv->devPrivates);
-        free(pDbeWindowPriv);
+	dixFreeObjectWithPrivates(pDbeWindowPriv, PRIVATE_DBE_WINDOW);
     }
 
     return(Success);
@@ -1576,6 +1573,12 @@ DbeExtensionInit(void)
     if (!dbeWindowPrivResType)
 	return;
 
+    if (!dixRegisterPrivateKey(&dbeScreenPrivKeyRec, PRIVATE_SCREEN, 0))
+	return;
+
+    if (!dixRegisterPrivateKey(&dbeWindowPrivKeyRec, PRIVATE_WINDOW, 0))
+	return;
+
     for (i = 0; i < screenInfo.numScreens; i++)
     {
         /* For each screen, set up DBE screen privates and init DIX and DDX
@@ -1602,14 +1605,6 @@ DbeExtensionInit(void)
 
 	dixSetPrivate(&pScreen->devPrivates, dbeScreenPrivKey, pDbeScreenPriv);
 
-        /* Copy the resource types */
-        pDbeScreenPriv->dbeDrawableResType   = dbeDrawableResType;
-        pDbeScreenPriv->dbeWindowPrivResType = dbeWindowPrivResType;
-
-        /* Copy the private indices */
-        pDbeScreenPriv->dbeScreenPrivKey = dbeScreenPrivKey;
-        pDbeScreenPriv->dbeWindowPrivKey = dbeWindowPrivKey;
-
         {
             /* We don't have DDX support for DBE anymore */
 
diff --git a/dbe/dbestruct.h b/dbe/dbestruct.h
index ba6b56d..9c383ce 100644
--- a/dbe/dbestruct.h
+++ b/dbe/dbestruct.h
@@ -167,14 +167,6 @@ typedef struct _DbeWindowPrivRec
 
 typedef struct _DbeScreenPrivRec
 {
-    /* Resources created by DIX to be used by DDX */
-    RESTYPE	dbeDrawableResType;
-    RESTYPE	dbeWindowPrivResType;
-
-    /* Private indices created by DIX to be used by DDX */
-    DevPrivateKey dbeScreenPrivKey;
-    DevPrivateKey dbeWindowPrivKey;
-
     /* Wrapped functions
      * It is the responsibilty of the DDX layer to wrap PositionWindow().
      * DbeExtensionInit wraps DestroyWindow().
diff --git a/dbe/midbe.c b/dbe/midbe.c
index 49689c5..03e8e2e 100644
--- a/dbe/midbe.c
+++ b/dbe/midbe.c
@@ -58,14 +58,8 @@
 
 #include <stdio.h>
 
-static int miDbeWindowPrivPrivKeyIndex;
-static DevPrivateKey miDbeWindowPrivPrivKey = &miDbeWindowPrivPrivKeyIndex;
-static RESTYPE	dbeDrawableResType;
-static RESTYPE	dbeWindowPrivResType;
-static int dbeScreenPrivKeyIndex;
-static DevPrivateKey dbeScreenPrivKey = &dbeScreenPrivKeyIndex;
-static int dbeWindowPrivKeyIndex;
-static DevPrivateKey dbeWindowPrivKey = &dbeWindowPrivKeyIndex;
+static DevPrivateKeyRec miDbeWindowPrivPrivKeyRec;
+#define miDbeWindowPrivPrivKey (&miDbeWindowPrivPrivKeyRec)
 
 
 /******************************************************************************
@@ -787,16 +781,8 @@ miDbeResetProc(ScreenPtr pScreen)
 Bool
 miDbeInit(ScreenPtr pScreen, DbeScreenPrivPtr pDbeScreenPriv)
 {
-    /* Copy resource types created by DIX */
-    dbeDrawableResType   = pDbeScreenPriv->dbeDrawableResType;
-    dbeWindowPrivResType = pDbeScreenPriv->dbeWindowPrivResType;
-
-    /* Copy private indices created by DIX */
-    dbeScreenPrivKey = pDbeScreenPriv->dbeScreenPrivKey;
-    dbeWindowPrivKey = pDbeScreenPriv->dbeWindowPrivKey;
-
-    if (!dixRequestPrivate(miDbeWindowPrivPrivKey,
-			   sizeof(MiDbeWindowPrivPrivRec)))
+    if (!dixRegisterPrivateKey(&miDbeWindowPrivPrivKeyRec, PRIVATE_DBE_WINDOW,
+			       sizeof(MiDbeWindowPrivPrivRec)))
         return(FALSE);
 
     /* Wrap functions. */
diff --git a/dbe/midbe.h b/dbe/midbe.h
index 007f2e3..cff36d0 100644
--- a/dbe/midbe.h
+++ b/dbe/midbe.h
@@ -36,6 +36,8 @@
 #ifndef MIDBE_H
 #define MIDBE_H
 
+#include "privates.h"
+
 /* EXTERNS */
 
 extern Bool miDbeInit(
@@ -43,5 +45,14 @@ extern Bool miDbeInit(
     DbeScreenPrivPtr    pDbeScreenPriv
 );
 
+extern DevPrivateKeyRec dbeScreenPrivKeyRec;
+#define dbeScreenPrivKey (&dbeScreenPrivKeyRec)
+
+extern DevPrivateKeyRec dbeWindowPrivKeyRec;
+#define dbeWindowPrivKey (&dbeWindowPrivKeyRec)
+
+extern RESTYPE	dbeDrawableResType;
+extern RESTYPE	dbeWindowPrivResType;
+
 #endif /* MIDBE_H */
 
diff --git a/dix/colormap.c b/dix/colormap.c
index 12197ac..eb6c491 100644
--- a/dix/colormap.c
+++ b/dix/colormap.c
@@ -273,9 +273,20 @@ CreateColormap (Colormap mid, ScreenPtr pScreen, VisualPtr pVisual,
     if ((class | DynamicClass) == DirectColor)
 	sizebytes *= 3;
     sizebytes += sizeof(ColormapRec);
-    pmap = malloc(sizebytes);
-    if (!pmap)
-	return (BadAlloc);
+    if (mid == pScreen->defColormap) {
+	pmap = malloc(sizebytes);
+	if (!pmap)
+	    return (BadAlloc);
+	if (!dixAllocatePrivates(&pmap->devPrivates, PRIVATE_COLORMAP)) {
+	    free (pmap);
+	    return (BadAlloc);
+	}
+    } else {
+	pmap = _dixAllocateObjectWithPrivates(sizebytes, sizebytes,
+					      offsetof(ColormapRec, devPrivates), PRIVATE_COLORMAP);
+	if (!pmap)
+	    return (BadAlloc);
+    }
 #if defined(_XSERVER64)
     pmap->pad0 = 0;
     pmap->pad1 = 0;
@@ -385,7 +396,6 @@ CreateColormap (Colormap mid, ScreenPtr pScreen, VisualPtr pVisual,
 	    pmap->numPixelsBlue[client] = size;
 	}
     }
-    pmap->devPrivates = NULL;
     pmap->flags |= BeingCreated;
 
     if (!AddResource(mid, RT_COLORMAP, (pointer)pmap))
@@ -467,8 +477,11 @@ FreeColormap (pointer value, XID mid)
         }
     }
 
-    dixFreePrivates(pmap->devPrivates);
-    free(pmap);
+    if (pmap->flags & IsDefault) {
+	dixFreePrivates(pmap->devPrivates, PRIVATE_COLORMAP);
+	free(pmap);
+    } else
+	dixFreeObjectWithPrivates(pmap, PRIVATE_COLORMAP);
     return(Success);
 }
 
diff --git a/dix/cursor.c b/dix/cursor.c
index 7ff0a93..67592c5 100644
--- a/dix/cursor.c
+++ b/dix/cursor.c
@@ -72,6 +72,8 @@ typedef struct _GlyphShare {
 
 static GlyphSharePtr sharedGlyphs = (GlyphSharePtr)NULL;
 
+DevPrivateKeyRec cursorScreenDevPriv[MAXSCREENS];
+
 #ifdef XFIXES
 static CARD32	cursorSerial;
 #endif
@@ -86,8 +88,7 @@ FreeCursorBits(CursorBitsPtr bits)
 #ifdef ARGB_CURSOR
     free(bits->argb);
 #endif
-    dixFreePrivates(bits->devPrivates);
-    bits->devPrivates = NULL;
+    dixFiniPrivates(bits, PRIVATE_CURSOR_BITS);
     if (bits->refcnt == 0)
     {
 	GlyphSharePtr *prev, this;
@@ -128,8 +129,8 @@ FreeCursor(pointer value, XID cid)
 	pscr = screenInfo.screens[nscr];
         (void)( *pscr->UnrealizeCursor)(pDev, pscr, pCurs);
     }
-    dixFreePrivates(pCurs->devPrivates);
     FreeCursorBits(pCurs->bits);
+    dixFiniPrivates(pCurs, PRIVATE_CURSOR);
     free( pCurs);
     return(Success);
 }
@@ -217,6 +218,7 @@ RealizeCursorAllScreens(CursorPtr pCurs)
     return Success;
 }
 
+
 /**
  * does nothing about the resource table, just creates the data structure.
  * does not copy the src and mask bits
@@ -237,14 +239,16 @@ AllocARGBCursor(unsigned char *psrcbits, unsigned char *pmaskbits,
     int rc;
 
     *ppCurs = NULL;
-    pCurs = (CursorPtr)calloc(sizeof(CursorRec) + sizeof(CursorBits), 1);
+    pCurs = (CursorPtr)calloc(CURSOR_REC_SIZE + CURSOR_BITS_SIZE, 1);
     if (!pCurs)
     {
 	free(psrcbits);
 	free(pmaskbits);
 	return BadAlloc;
     }
-    bits = (CursorBitsPtr)((char *)pCurs + sizeof(CursorRec));
+    bits = (CursorBitsPtr)((char *)pCurs + CURSOR_REC_SIZE);
+    dixInitPrivates(pCurs, pCurs + 1, PRIVATE_CURSOR);
+    dixInitPrivates(bits, bits + 1, PRIVATE_CURSOR_BITS)
     bits->source = psrcbits;
     bits->mask = pmaskbits;
 #ifdef ARGB_CURSOR
@@ -255,7 +259,6 @@ AllocARGBCursor(unsigned char *psrcbits, unsigned char *pmaskbits,
     bits->xhot = cm->xhot;
     bits->yhot = cm->yhot;
     pCurs->refcnt = 1;		
-    bits->devPrivates = NULL;
     bits->refcnt = -1;
     CheckForEmptyMask(bits);
     pCurs->bits = bits;
@@ -273,7 +276,6 @@ AllocARGBCursor(unsigned char *psrcbits, unsigned char *pmaskbits,
     pCurs->backBlue = backBlue;
 
     pCurs->id = cid;
-    pCurs->devPrivates = NULL;
 
     /* security creation/labeling check */
     rc = XaceHook(XACE_RESOURCE_ACCESS, client, cid, RT_CURSOR,
@@ -289,8 +291,8 @@ AllocARGBCursor(unsigned char *psrcbits, unsigned char *pmaskbits,
     return Success;
 
 error:
-    dixFreePrivates(pCurs->devPrivates);
     FreeCursorBits(bits);
+    dixFiniPrivates(pCurs, PRIVATE_CURSOR);
     free(pCurs);
 
     return rc;
@@ -339,9 +341,10 @@ AllocGlyphCursor(Font source, unsigned sourceChar, Font mask, unsigned maskChar,
     }
     if (pShare)
     {
-	pCurs = (CursorPtr)calloc(sizeof(CursorRec), 1);
+	pCurs = (CursorPtr)calloc(CURSOR_REC_SIZE, 1);
 	if (!pCurs)
 	    return BadAlloc;
+	dixInitPrivates(pCurs, pCurs + 1, PRIVATE_CURSOR);
 	bits = pShare->bits;
 	bits->refcnt++;
     }
@@ -382,17 +385,17 @@ AllocGlyphCursor(Font source, unsigned sourceChar, Font mask, unsigned maskChar,
 	if (sourcefont != maskfont)
 	{
 	    pCurs = 
-                (CursorPtr)calloc(sizeof(CursorRec) + sizeof(CursorBits), 1);
+                (CursorPtr)calloc(CURSOR_REC_SIZE + CURSOR_BITS_SIZE, 1);
 	    if (pCurs)
-		bits = (CursorBitsPtr)((char *)pCurs + sizeof(CursorRec));
+		bits = (CursorBitsPtr)((char *)pCurs + CURSOR_REC_SIZE);
 	    else
 		bits = (CursorBitsPtr)NULL;
 	}
 	else
 	{
-	    pCurs = (CursorPtr)calloc(sizeof(CursorRec), 1);
+	    pCurs = (CursorPtr)calloc(CURSOR_REC_SIZE, 1);
 	    if (pCurs)
-		bits = (CursorBitsPtr)calloc(sizeof(CursorBits), 1);
+		bits = (CursorBitsPtr)calloc(CURSOR_BITS_SIZE, 1);
 	    else
 		bits = (CursorBitsPtr)NULL;
 	}
@@ -403,6 +406,8 @@ AllocGlyphCursor(Font source, unsigned sourceChar, Font mask, unsigned maskChar,
 	    free(srcbits);
 	    return BadAlloc;
 	}
+	dixInitPrivates(pCurs, pCurs + 1, PRIVATE_CURSOR);
+	dixInitPrivates(bits, bits + 1, PRIVATE_CURSOR_BITS);
 	bits->source = srcbits;
 	bits->mask = mskbits;
 #ifdef ARGB_CURSOR
@@ -412,7 +417,6 @@ AllocGlyphCursor(Font source, unsigned sourceChar, Font mask, unsigned maskChar,
 	bits->height = cm.height;
 	bits->xhot = cm.xhot;
 	bits->yhot = cm.yhot;
-	bits->devPrivates = NULL;
 	if (sourcefont != maskfont)
 	    bits->refcnt = -1;
 	else
@@ -451,7 +455,6 @@ AllocGlyphCursor(Font source, unsigned sourceChar, Font mask, unsigned maskChar,
     pCurs->backBlue = backBlue;
 
     pCurs->id = cid;
-    pCurs->devPrivates = NULL;
 
     /* security creation/labeling check */
     rc = XaceHook(XACE_RESOURCE_ACCESS, client, cid, RT_CURSOR,
@@ -467,8 +470,8 @@ AllocGlyphCursor(Font source, unsigned sourceChar, Font mask, unsigned maskChar,
     return Success;
 
 error:
-    dixFreePrivates(pCurs->devPrivates);
     FreeCursorBits(bits);
+    dixFiniPrivates(pCurs, PRIVATE_CURSOR);
     free(pCurs);
 
     return rc;
diff --git a/dix/devices.c b/dix/devices.c
index 998d22a..427264d 100644
--- a/dix/devices.c
+++ b/dix/devices.c
@@ -255,7 +255,9 @@ AddInputDevice(ClientPtr client, DeviceProc deviceProc, Bool autoStart)
 
     if (devid >= MAXDEVICES)
 	return (DeviceIntPtr)NULL;
-    dev =  calloc(sizeof(DeviceIntRec) + sizeof(SpriteInfoRec), 1);
+    dev =  _dixAllocateObjectWithPrivates(sizeof(DeviceIntRec) + sizeof(SpriteInfoRec),
+					  sizeof(DeviceIntRec) + sizeof(SpriteInfoRec),
+					  offsetof(DeviceIntRec, devPrivates), PRIVATE_DEVICE);
     if (!dev)
 	return (DeviceIntPtr)NULL;
     dev->id = devid;
@@ -936,8 +938,7 @@ CloseDevice(DeviceIntPtr dev)
     }
 
     free(dev->deviceGrab.sync.event);
-    dixFreePrivates(dev->devPrivates);
-    free(dev);
+    dixFreeObjectWithPrivates(dev, PRIVATE_DEVICE);
 }
 
 /**
diff --git a/dix/dispatch.c b/dix/dispatch.c
index 859b93e..ffb3764 100644
--- a/dix/dispatch.c
+++ b/dix/dispatch.c
@@ -3498,8 +3498,7 @@ CloseDownClient(ClientPtr client)
 	    nextFreeClientID = client->index;
 	clients[client->index] = NullClient;
 	SmartLastClient = NullClient;
-	dixFreePrivates(client->devPrivates);
-	free(client);
+	dixFreeObjectWithPrivates(client, PRIVATE_CLIENT);
 
 	while (!clients[currentMaxClients-1])
 	    currentMaxClients--;
@@ -3520,7 +3519,6 @@ KillAllClients(void)
 
 void InitClient(ClientPtr client, int i, pointer ospriv)
 {
-    memset(client, 0, sizeof(*client));
     client->index = i;
     client->clientAsMask = ((Mask)i) << CLIENTOFFSET;
     client->closeDownMode = i ? DestroyAll : RetainPermanent;
@@ -3548,13 +3546,13 @@ ClientPtr NextAvailableClient(pointer ospriv)
     i = nextFreeClientID;
     if (i == MAXCLIENTS)
 	return (ClientPtr)NULL;
-    clients[i] = client = malloc(sizeof(ClientRec));
+    clients[i] = client = dixAllocateObjectWithPrivates(ClientRec, PRIVATE_CLIENT);
     if (!client)
 	return (ClientPtr)NULL;
     InitClient(client, i, ospriv);
     if (!InitClientResources(client))
     {
-	free(client);
+	dixFreeObjectWithPrivates(client, PRIVATE_CLIENT);
 	return (ClientPtr)NULL;
     }
     data.reqType = 1;
@@ -3562,7 +3560,7 @@ ClientPtr NextAvailableClient(pointer ospriv)
     if (!InsertFakeRequest(client, (char *)&data, sz_xReq))
     {
 	FreeClientResources(client);
-	free(client);
+	dixFreeObjectWithPrivates(client, PRIVATE_CLIENT);
 	return (ClientPtr)NULL;
     }
     if (i == currentMaxClients)
@@ -3868,9 +3866,12 @@ AddScreen(
     if (!pScreen)
 	return -1;
 
-    pScreen->devPrivates = NULL;
+    if (!dixAllocatePrivates(&pScreen->devPrivates, PRIVATE_SCREEN)) {
+	free (pScreen);
+	return -1;
+    }
     pScreen->myNum = i;
-    pScreen->totalPixmapSize = BitmapBytePad(sizeof(PixmapRec)*8);
+    pScreen->totalPixmapSize = 0;	/* computed in CreateScratchPixmapForScreen */
     pScreen->ClipNotify = 0;	/* for R4 ddx compatibility */
     pScreen->CreateScreenResources = 0;
 
@@ -3920,10 +3921,13 @@ AddScreen(
     screenInfo.numScreens++;
     if (!(*pfnInit)(i, pScreen, argc, argv))
     {
-	dixFreePrivates(pScreen->devPrivates);
+	dixFreePrivates(pScreen->devPrivates, PRIVATE_SCREEN);
 	free(pScreen);
 	screenInfo.numScreens--;
 	return -1;
     }
+
+    dixRegisterPrivateKey(&cursorScreenDevPriv[i], PRIVATE_CURSOR, 0);
+
     return i;
 }
diff --git a/dix/extension.c b/dix/extension.c
index d3d4db0..f422ea3 100644
--- a/dix/extension.c
+++ b/dix/extension.c
@@ -89,15 +89,19 @@ AddExtension(char *name, int NumEvents, int NumErrors,
         return((ExtensionEntry *) NULL);
     }
 
-    ext = malloc(sizeof(ExtensionEntry));
+    ext = calloc(sizeof (ExtensionEntry), 1);
     if (!ext)
 	return(NULL);
+    if (!dixAllocatePrivates(&ext->devPrivates, PRIVATE_EXTENSION)) {
+	free(ext);
+	return(NULL);
+    }
     ext->name = malloc(strlen(name) + 1);
     ext->num_aliases = 0;
     ext->aliases = (char **)NULL;
-    ext->devPrivates = NULL;
     if (!ext->name)
     {
+	dixFreePrivates(ext->devPrivates, PRIVATE_EXTENSION);
 	free(ext);
 	return((ExtensionEntry *) NULL);
     }
@@ -108,6 +112,7 @@ AddExtension(char *name, int NumEvents, int NumErrors,
     if (!newexts)
     {
 	free(ext->name);
+	dixFreePrivates(ext->devPrivates, PRIVATE_EXTENSION);
 	free(ext);
 	return((ExtensionEntry *) NULL);
     }
@@ -253,7 +258,7 @@ CloseDownExtensions(void)
 	for (j = extensions[i]->num_aliases; --j >= 0;)
 	    free(extensions[i]->aliases[j]);
 	free(extensions[i]->aliases);
-	dixFreePrivates(extensions[i]->devPrivates);
+	dixFreePrivates(extensions[i]->devPrivates, PRIVATE_EXTENSION);
 	free(extensions[i]);
     }
     free(extensions);
diff --git a/dix/gc.c b/dix/gc.c
index 48a507d..6d022f1 100644
--- a/dix/gc.c
+++ b/dix/gc.c
@@ -479,7 +479,7 @@ CreateGC(DrawablePtr pDrawable, BITS32 mask, XID *pval, int *pStatus,
 {
     GCPtr pGC;
 
-    pGC = malloc(sizeof(GC));
+    pGC = dixAllocateObjectWithPrivates(GC, PRIVATE_GC);
     if (!pGC)
     {
 	*pStatus = BadAlloc;
@@ -492,7 +492,6 @@ CreateGC(DrawablePtr pDrawable, BITS32 mask, XID *pval, int *pStatus,
     pGC->planemask = ~0;
     pGC->serialNumber = GC_CHANGE_SERIAL_BIT;
     pGC->funcs = 0;
-    pGC->devPrivates = NULL;
     pGC->fgPixel = 0;
     pGC->bgPixel = 1;
     pGC->lineWidth = 0;
@@ -785,8 +784,7 @@ FreeGC(pointer value, XID gid)
     (*pGC->funcs->DestroyGC) (pGC);
     if (pGC->dash != DefaultDash)
 	free(pGC->dash);
-    dixFreePrivates(pGC->devPrivates);
-    free(pGC);
+    dixFreeObjectWithPrivates(pGC, PRIVATE_GC);
     return(Success);
 }
 
@@ -808,7 +806,7 @@ CreateScratchGC(ScreenPtr pScreen, unsigned depth)
 {
     GCPtr pGC;
 
-    pGC = malloc(sizeof(GC));
+    pGC = dixAllocateObjectWithPrivates(GC, PRIVATE_GC);
     if (!pGC)
 	return (GCPtr)NULL;
 
@@ -817,7 +815,6 @@ CreateScratchGC(ScreenPtr pScreen, unsigned depth)
     pGC->alu = GXcopy; /* dst <- src */
     pGC->planemask = ~0;
     pGC->serialNumber = 0;
-    pGC->devPrivates = NULL;
     pGC->fgPixel = 0;
     pGC->bgPixel = 1;
     pGC->lineWidth = 0;
diff --git a/dix/globals.c b/dix/globals.c
index 82a85c2..b128569 100644
--- a/dix/globals.c
+++ b/dix/globals.c
@@ -123,8 +123,6 @@ CursorPtr rootCursor;
 Bool party_like_its_1989 = FALSE;
 Bool whiteRoot = FALSE;
 
-int cursorScreenDevPriv[MAXSCREENS];
-
 TimeStamp currentTime;
 TimeStamp lastDeviceEventTime;
 
diff --git a/dix/main.c b/dix/main.c
index 982fedd..0f499dd 100644
--- a/dix/main.c
+++ b/dix/main.c
@@ -174,7 +174,7 @@ int main(int argc, char *argv[], char *envp[])
 	    InitProcVectors();
 	    for (i=1; i<MAXCLIENTS; i++)
 		clients[i] = NullClient;
-	    serverClient = malloc(sizeof(ClientRec));
+	    serverClient = calloc(sizeof(ClientRec), 1);
 	    if (!serverClient)
 		FatalError("couldn't create server client");
 	    InitClient(serverClient, 0, (pointer)NULL);
@@ -184,6 +184,12 @@ int main(int argc, char *argv[], char *envp[])
 	clients[0] = serverClient;
 	currentMaxClients = 1;
 
+	/* Initialize server client devPrivates, to be reallocated as
+	 * more client privates are registered
+	 */
+	if (!dixAllocatePrivates(&serverClient->devPrivates, PRIVATE_CLIENT))
+	    FatalError("failed to create server client privates");
+
 	if (!InitClientResources(serverClient))      /* for root resources */
 	    FatalError("couldn't init server resources");
 
@@ -194,8 +200,7 @@ int main(int argc, char *argv[], char *envp[])
 	InitEvents();
 	InitSelections();
 	InitGlyphCaching();
-	if (!dixResetPrivates())
-	    FatalError("couldn't init private data storage");
+	dixResetPrivates();
 	dixResetRegistry();
 	ResetFontPrivateIndex();
 	InitCallbackManager();
@@ -204,6 +209,7 @@ int main(int argc, char *argv[], char *envp[])
 	if (screenInfo.numScreens < 1)
 	    FatalError("no screens found");
 	InitExtensions(argc, argv);
+
 	for (i = 0; i < screenInfo.numScreens; i++)
 	{
 	    ScreenPtr pScreen = screenInfo.screens[i];
@@ -314,17 +320,18 @@ int main(int argc, char *argv[], char *envp[])
 	    FreeGCperDepth(i);
 	    FreeDefaultStipple(i);
 	    (* screenInfo.screens[i]->CloseScreen)(i, screenInfo.screens[i]);
-	    dixFreePrivates(screenInfo.screens[i]->devPrivates);
+	    dixFreePrivates(screenInfo.screens[i]->devPrivates, PRIVATE_SCREEN);
 	    free(screenInfo.screens[i]);
 	    screenInfo.numScreens = i;
 	}
+
+	dixFreePrivates(serverClient->devPrivates, PRIVATE_CLIENT);
+	serverClient->devPrivates = NULL;
+
 	FreeFonts();
 
 	FreeAuditTimer();
 
-	dixFreePrivates(serverClient->devPrivates);
-	serverClient->devPrivates = NULL;
-
 	if (dispatchException & DE_TERMINATE)
 	{
 	    CloseWellKnownConnections();
diff --git a/dix/pixmap.c b/dix/pixmap.c
index a4ad255..cbb5e7f 100644
--- a/dix/pixmap.c
+++ b/dix/pixmap.c
@@ -91,6 +91,11 @@ FreeScratchPixmapHeader(PixmapPtr pPixmap)
 Bool
 CreateScratchPixmapsForScreen(int scrnum)
 {
+    unsigned int	pixmap_size;
+
+    pixmap_size = sizeof(PixmapRec) + dixPrivatesSize(PRIVATE_PIXMAP);
+    screenInfo.screens[scrnum]->totalPixmapSize = BitmapBytePad(pixmap_size * 8);
+
     /* let it be created on first use */
     screenInfo.screens[scrnum]->pScratchPixmap = NULL;
     return TRUE;
@@ -110,6 +115,8 @@ AllocatePixmap(ScreenPtr pScreen, int pixDataSize)
 {
     PixmapPtr pPixmap;
 
+    assert(pScreen->totalPixmapSize > 0);
+
     if (pScreen->totalPixmapSize > ((size_t)-1) - pixDataSize)
 	return NullPixmap;
     
@@ -117,6 +124,14 @@ AllocatePixmap(ScreenPtr pScreen, int pixDataSize)
     if (!pPixmap)
 	return NullPixmap;
 
-    pPixmap->devPrivates = NULL;
+    dixInitPrivates(pPixmap, pPixmap + 1, PRIVATE_PIXMAP);
     return pPixmap;
 }
+
+/* callable by ddx */
+void
+FreePixmap(PixmapPtr pPixmap)
+{
+    dixFiniPrivates(pPixmap, PRIVATE_PIXMAP);
+    free(pPixmap);
+}
diff --git a/dix/privates.c b/dix/privates.c
index 9ec6c46..87831c2 100644
--- a/dix/privates.c
+++ b/dix/privates.c
@@ -52,6 +52,10 @@ typedef struct _PrivateDesc {
 #define PRIV_MAX 256
 #define PRIV_STEP 16
 
+static int number_privates_allocated;
+static int number_private_ptrs_allocated;
+static int bytes_private_data_allocated;
+
 /* list of all allocated privates */
 static PrivateDescRec items[PRIV_MAX];
 static int nextPriv;
@@ -59,31 +63,31 @@ static int nextPriv;
 static PrivateDescRec *
 findItem(const DevPrivateKey key)
 {
-    if (!*key) {
+    if (!key->key) {
 	if (nextPriv >= PRIV_MAX)
 	    return NULL;
 
 	items[nextPriv].key = key;
-	*key = nextPriv;
+	key->key = nextPriv;
 	nextPriv++;
     }
 
-    return items + *key;
+    return items + key->key;
 }
 
 static _X_INLINE int
 privateExists(PrivateRec **privates, const DevPrivateKey key)
 {
-    return *key && *privates &&
-	(*privates)[0].state > *key &&
-	(*privates)[*key].state;
+    return key->key && *privates &&
+	(*privates)[0].state > key->key &&
+	(*privates)[key->key].state;
 }
 
 /*
  * Request pre-allocated space.
  */
 int
-dixRequestPrivate(const DevPrivateKey key, unsigned size)
+dixRegisterPrivateKey(const DevPrivateKey key, DevPrivateType type, unsigned size)
 {
     PrivateDescRec *item = findItem(key);
     if (!item)
@@ -96,7 +100,7 @@ dixRequestPrivate(const DevPrivateKey key, unsigned size)
 /*
  * Allocate a private and attach it to an existing object.
  */
-pointer *
+static pointer *
 dixAllocatePrivate(PrivateRec **privates, const DevPrivateKey key)
 {
     PrivateDescRec *item = findItem(key);
@@ -104,7 +108,7 @@ dixAllocatePrivate(PrivateRec **privates, const DevPrivateKey key)
     pointer value;
     int oldsize, newsize;
 
-    newsize = (*key / PRIV_STEP + 1) * PRIV_STEP;
+    newsize = (key->key / PRIV_STEP + 1) * PRIV_STEP;
 
     /* resize or init privates array */
     if (!item)
@@ -112,6 +116,8 @@ dixAllocatePrivate(PrivateRec **privates, const DevPrivateKey key)
 
     /* initialize privates array if necessary */
     if (!*privates) {
+	++number_privates_allocated;
+	number_private_ptrs_allocated += newsize;
 	ptr = calloc(newsize, sizeof(*ptr));
 	if (!ptr)
 	    return NULL;
@@ -122,22 +128,25 @@ dixAllocatePrivate(PrivateRec **privates, const DevPrivateKey key)
     oldsize = (*privates)[0].state;
 
     /* resize privates array if necessary */
-    if (*key >= oldsize) {
+    if (key->key >= oldsize) {
 	ptr = realloc(*privates, newsize * sizeof(*ptr));
 	if (!ptr)
 	    return NULL;
 	memset(ptr + oldsize, 0, (newsize - oldsize) * sizeof(*ptr));
 	*privates = ptr;
 	(*privates)[0].state = newsize;
+	number_private_ptrs_allocated -= oldsize;
+	number_private_ptrs_allocated += newsize;
     }
 
     /* initialize slot */
-    ptr = *privates + *key;
+    ptr = *privates + key->key;
     ptr->state = 1;
     if (item->size) {
 	value = calloc(item->size, 1);
 	if (!value)
 	    return NULL;
+	bytes_private_data_allocated += item->size;
 	ptr->value = value;
     }
 
@@ -152,8 +161,9 @@ dixLookupPrivate(PrivateRec **privates, const DevPrivateKey key)
 {
     pointer *ptr;
 
+    assert (key->key != 0);
     if (privateExists(privates, key))
-	return (*privates)[*key].value;
+	return (*privates)[key->key].value;
 
     ptr = dixAllocatePrivate(privates, key);
     return ptr ? *ptr : NULL;
@@ -165,8 +175,10 @@ dixLookupPrivate(PrivateRec **privates, const DevPrivateKey key)
 pointer *
 dixLookupPrivateAddr(PrivateRec **privates, const DevPrivateKey key)
 {
+    assert (key->key != 0);
+
     if (privateExists(privates, key))
-	return &(*privates)[*key].value;
+	return &(*privates)[key->key].value;
 
     return dixAllocatePrivate(privates, key);
 }
@@ -177,9 +189,10 @@ dixLookupPrivateAddr(PrivateRec **privates, const DevPrivateKey key)
 int
 dixSetPrivate(PrivateRec **privates, const DevPrivateKey key, pointer val)
 {
+    assert (key->key != 0);
  top:
     if (privateExists(privates, key)) {
-	(*privates)[*key].value = val;
+	(*privates)[key->key].value = val;
 	return TRUE;
     }
 
@@ -192,17 +205,21 @@ dixSetPrivate(PrivateRec **privates, const DevPrivateKey key, pointer val)
  * Called to free privates at object deletion time.
  */
 void
-dixFreePrivates(PrivateRec *privates)
+dixFreePrivates(PrivateRec *privates, DevPrivateType type)
 {
     int i;
 
-    if (privates)
+    if (privates) {
+	number_private_ptrs_allocated -= privates->state;
+	number_privates_allocated--;
 	for (i = 1; i < privates->state; i++)
 	    if (privates[i].state) {
 		/* free pre-allocated memory */
 		if (items[i].size)
 		    free(privates[i].value);
+		bytes_private_data_allocated -= items[i].size;
 	    }
+    }
 
     free(privates);
 }
@@ -239,16 +256,32 @@ dixLookupPrivateOffset(RESTYPE type)
     return -1;
 }
 
-int
+void
+dixPrivateUsage(void)
+{
+    ErrorF("number of private structures: %d\n",
+	   number_privates_allocated);
+    ErrorF("total number of private pointers: %d (%zd bytes)\n",
+	   number_private_ptrs_allocated,
+	   number_private_ptrs_allocated * sizeof (struct _Private));
+    ErrorF("bytes of extra private data: %d\n",
+	   bytes_private_data_allocated);
+    ErrorF("Total privates memory usage: %zd\n",
+	   bytes_private_data_allocated +
+	   number_private_ptrs_allocated * sizeof (struct _Private));
+}
+
+void
 dixResetPrivates(void)
 {
     int i;
 
     /* reset private descriptors */
     for (i = 1; i < nextPriv; i++) {
-	*items[i].key = 0;
+	items[i].key->key = 0;
 	items[i].size = 0;
     }
     nextPriv = 1;
-    return TRUE;
+    if (number_privates_allocated)
+	dixPrivateUsage();
 }
diff --git a/dix/property.c b/dix/property.c
index 03b70ef..6523107 100644
--- a/dix/property.c
+++ b/dix/property.c
@@ -269,13 +269,13 @@ dixChangeWindowProperty(ClientPtr pClient, WindowPtr pWin, Atom property,
     {
 	if (!pWin->optional && !MakeWindowOptional (pWin))
 	    return(BadAlloc);
-        pProp = malloc(sizeof(PropertyRec));
+	pProp = dixAllocateObjectWithPrivates(PropertyRec, PRIVATE_PROPERTY);
 	if (!pProp)
 	    return(BadAlloc);
         data = malloc(totalSize);
 	if (!data && len)
 	{
-	    free(pProp);
+	    dixFreeObjectWithPrivates(pProp, PRIVATE_PROPERTY);
 	    return(BadAlloc);
 	}
         memcpy(data, value, totalSize);
@@ -289,7 +289,7 @@ dixChangeWindowProperty(ClientPtr pClient, WindowPtr pWin, Atom property,
 				    DixCreateAccess|DixWriteAccess);
 	if (rc != Success) {
 	    free(data);
-	    free(pProp);
+	    dixFreeObjectWithPrivates(pProp, PRIVATE_PROPERTY);
 	    pClient->errorValue = property;
 	    return rc;
 	}
@@ -405,9 +405,8 @@ DeleteProperty(ClientPtr client, WindowPtr pWin, Atom propName)
 	}
 
 	deliverPropertyNotifyEvent(pWin, PropertyDelete, pProp->propertyName);
-	dixFreePrivates(pProp->devPrivates);
 	free(pProp->data);
-        free(pProp);
+	dixFreeObjectWithPrivates(pProp, PRIVATE_PROPERTY);
     }
     return rc;
 }
@@ -422,9 +421,8 @@ DeleteAllWindowProperties(WindowPtr pWin)
     {
 	deliverPropertyNotifyEvent(pWin, PropertyDelete, pProp->propertyName);
 	pNextProp = pProp->next;
-	dixFreePrivates(pProp->devPrivates);
         free(pProp->data);
-        free(pProp);
+	dixFreeObjectWithPrivates(pProp, PRIVATE_PROPERTY);
 	pProp = pNextProp;
     }
 }
@@ -570,9 +568,8 @@ ProcGetProperty(ClientPtr client)
 	    prevProp->next = pProp->next;
 	}
 
-	dixFreePrivates(pProp->devPrivates);
 	free(pProp->data);
-	free(pProp);
+	dixFreeObjectWithPrivates(pProp, PRIVATE_PROPERTY);
     }
     return Success;
 }
diff --git a/dix/selection.c b/dix/selection.c
index f52638c..bae3a30 100644
--- a/dix/selection.c
+++ b/dix/selection.c
@@ -94,8 +94,7 @@ InitSelections(void)
     pSel = CurrentSelections;
     while (pSel) {
 	pNextSel = pSel->next;
-	dixFreePrivates(pSel->devPrivates);
-	free(pSel);
+	dixFreeObjectWithPrivates(pSel, PRIVATE_SELECTION);
 	pSel = pNextSel;
     }
 
diff --git a/dix/window.c b/dix/window.c
index a98437b..7caa1cc 100644
--- a/dix/window.c
+++ b/dix/window.c
@@ -151,12 +151,8 @@ WindowSeekDeviceCursor(WindowPtr pWin,
 
 int screenIsSaved = SCREEN_SAVER_OFF;
 
-static int FocusPrivatesKeyIndex;
-DevPrivateKey FocusPrivatesKey = &FocusPrivatesKeyIndex;
-
 static Bool TileScreenSaver(ScreenPtr pScreen, int kind);
 
-
 #define INPUTONLY_LEGAL_MASK (CWWinGravity | CWEventMask | \
 			      CWDontPropagate | CWOverrideRedirect | CWCursor )
 
@@ -357,7 +353,7 @@ CreateRootWindow(ScreenPtr pScreen)
     BoxRec	box;
     PixmapFormatRec *format;
 
-    pWin = malloc(sizeof(WindowRec));
+    pWin = dixAllocateObjectWithPrivates(WindowRec, PRIVATE_WINDOW);
     if (!pWin)
 	return FALSE;
 
@@ -370,7 +366,6 @@ CreateRootWindow(ScreenPtr pScreen)
 
     pWin->drawable.pScreen = pScreen;
     pWin->drawable.type = DRAWABLE_WINDOW;
-    pWin->devPrivates = NULL;
 
     pWin->drawable.depth = pScreen->rootDepth;
     for (format = screenInfo.formats;
@@ -637,14 +632,13 @@ CreateWindow(Window wid, WindowPtr pParent, int x, int y, unsigned w,
 	return NullWindow;
     }
 
-    pWin = malloc(sizeof(WindowRec));
+    pWin = dixAllocateObjectWithPrivates(WindowRec, PRIVATE_WINDOW);
     if (!pWin)
     {
 	*error = BadAlloc;
 	return NullWindow;
     }
     pWin->drawable = pParent->drawable;
-    pWin->devPrivates = NULL;
     pWin->drawable.depth = depth;
     if (depth == pParent->drawable.depth)
 	pWin->drawable.bitsPerPixel = pParent->drawable.bitsPerPixel;
@@ -668,7 +662,7 @@ CreateWindow(Window wid, WindowPtr pParent, int x, int y, unsigned w,
     {
 	if (!MakeWindowOptional (pWin))
 	{
-	    free(pWin);
+	    dixFreeObjectWithPrivates(pWin, PRIVATE_WINDOW);
 	    *error = BadAlloc;
 	    return NullWindow;
 	}
@@ -683,7 +677,7 @@ CreateWindow(Window wid, WindowPtr pParent, int x, int y, unsigned w,
     *error = XaceHook(XACE_RESOURCE_ACCESS, client, wid, RT_WINDOW, pWin,
 		RT_WINDOW, pWin->parent, DixCreateAccess|DixSetAttrAccess);
     if (*error != Success) {
-	free(pWin);
+	dixFreeObjectWithPrivates(pWin, PRIVATE_WINDOW);
 	return NullWindow;
     }
 
@@ -881,8 +875,7 @@ CrushTree(WindowPtr pWin)
 		(*UnrealizeWindow)(pChild);
 	    }
 	    FreeWindowResources(pChild);
-	    dixFreePrivates(pChild->devPrivates);
-	    free(pChild);
+	    dixFreeObjectWithPrivates(pChild, PRIVATE_WINDOW);
 	    if ( (pChild = pSib) )
 		break;
 	    pChild = pParent;
@@ -932,9 +925,7 @@ DeleteWindow(pointer value, XID wid)
 	if (pWin->prevSib)
 	    pWin->prevSib->nextSib = pWin->nextSib;
     }
-    free(dixLookupPrivate(&pWin->devPrivates, FocusPrivatesKey));
-    dixFreePrivates(pWin->devPrivates);
-    free(pWin);
+    dixFreeObjectWithPrivates(pWin, PRIVATE_WINDOW);
     return Success;
 }
 
diff --git a/exa/exa.c b/exa/exa.c
index 4e1ffd6..bbe93f6 100644
--- a/exa/exa.c
+++ b/exa/exa.c
@@ -37,12 +37,12 @@
 #include "exa_priv.h"
 #include "exa.h"
 
-static int exaScreenPrivateKeyIndex;
-DevPrivateKey exaScreenPrivateKey = &exaScreenPrivateKeyIndex;
-static int exaPixmapPrivateKeyIndex;
-DevPrivateKey exaPixmapPrivateKey = &exaPixmapPrivateKeyIndex;
-static int exaGCPrivateKeyIndex;
-DevPrivateKey exaGCPrivateKey = &exaGCPrivateKeyIndex;
+static DevPrivateKeyRec exaScreenPrivateKeyRec;
+#define exaScreenPrivateKey (&exaScreenPrivateKeyRec)
+static DevPrivateKeyRec exaPixmapPrivateKeyRec;
+#define exaPixmapPrivateKey (&exaPixmapPrivateKeyRec)
+static DevPrivateKeyRec exaGCPrivateKeyRec;
+#define exaGCPrivateKey (&exaGCPrivateKeyRec)
 
 #ifdef MITSHM
 static ShmFuncs exaShmFuncs = { NULL, NULL };
@@ -889,7 +889,13 @@ exaDriverInit (ScreenPtr		pScreen,
 
     ps = GetPictureScreenIfSet(pScreen);
 
-    pExaScr = calloc(sizeof (ExaScreenPrivRec), 1);
+    if (!dixRegisterPrivateKey(&exaScreenPrivateKeyRec, PRIVATE_SCREEN, 0)) {
+        LogMessage(X_WARNING, "EXA(%d): Failed to register screen private\n",
+		   pScreen->myNum);
+	return FALSE;
+    }
+
+    pExaScr = calloc (sizeof (ExaScreenPrivRec), 1);
     if (!pExaScr) {
         LogMessage(X_WARNING, "EXA(%d): Failed to allocate screen private\n",
 		   pScreen->myNum);
@@ -904,7 +910,7 @@ exaDriverInit (ScreenPtr		pScreen,
 
     exaDDXDriverInit(pScreen);
 
-    if (!dixRequestPrivate(exaGCPrivateKey, sizeof(ExaGCPrivRec))) {
+    if (!dixRegisterPrivateKey(&exaGCPrivateKeyRec, PRIVATE_GC, sizeof(ExaGCPrivRec))) {
 	LogMessage(X_WARNING,
 	       "EXA(%d): Failed to allocate GC private\n",
 	       pScreen->myNum);
@@ -953,7 +959,7 @@ exaDriverInit (ScreenPtr		pScreen,
      */
     if (pExaScr->info->flags & EXA_OFFSCREEN_PIXMAPS)
     {
-	if (!dixRequestPrivate(exaPixmapPrivateKey, sizeof(ExaPixmapPrivRec))) {
+	if (!dixRegisterPrivateKey(&exaPixmapPrivateKeyRec, PRIVATE_PIXMAP, sizeof(ExaPixmapPrivRec))) {
             LogMessage(X_WARNING,
 		       "EXA(%d): Failed to allocate pixmap private\n",
 		       pScreen->myNum);
diff --git a/fb/fb.h b/fb/fb.h
index 7ab4adf..4fde426 100644
--- a/fb/fb.h
+++ b/fb/fb.h
@@ -603,8 +603,12 @@ extern _X_EXPORT void fbSetBits (FbStip *bits, int stride, FbStip data);
     }							    \
 }
 
-extern _X_EXPORT DevPrivateKey fbGetGCPrivateKey(void);
-extern _X_EXPORT DevPrivateKey fbGetWinPrivateKey(void);
+extern _X_EXPORT DevPrivateKey
+fbGetGCPrivateKey (void);
+
+extern _X_EXPORT DevPrivateKey
+fbGetWinPrivateKey (void);
+
 extern _X_EXPORT const GCOps	fbGCOps;
 extern _X_EXPORT const GCFuncs	fbGCFuncs;
 
@@ -639,7 +643,8 @@ typedef void (*FinishWrapProcPtr)(DrawablePtr pDraw);
 
 
 #ifdef FB_SCREEN_PRIVATE
-extern _X_EXPORT DevPrivateKey fbGetScreenPrivateKey(void);
+extern _X_EXPORT DevPrivateKey
+fbGetScreenPrivateKey(void);
 
 /* private field of a screen */
 typedef struct {
@@ -652,7 +657,7 @@ typedef struct {
 } FbScreenPrivRec, *FbScreenPrivPtr;
 
 #define fbGetScreenPrivate(pScreen) ((FbScreenPrivPtr) \
-	dixLookupPrivate(&(pScreen)->devPrivates, fbGetScreenPrivateKey()))
+				     dixLookupPrivate(&(pScreen)->devPrivates, fbGetScreenPrivateKey()))
 #endif
 
 /* private field of GC */
@@ -667,7 +672,7 @@ typedef struct {
 } FbGCPrivRec, *FbGCPrivPtr;
 
 #define fbGetGCPrivate(pGC)	((FbGCPrivPtr)\
-	dixLookupPrivate(&(pGC)->devPrivates, fbGetGCPrivateKey()))
+				 dixLookupPrivate(&(pGC)->devPrivates, fbGetGCPrivateKey()))
 
 #define fbGetCompositeClip(pGC) ((pGC)->pCompositeClip)
 #define fbGetExpose(pGC)	((pGC)->fExpose)
@@ -676,7 +681,7 @@ typedef struct {
 
 #define fbGetScreenPixmap(s)	((PixmapPtr) (s)->devPrivate)
 #define fbGetWindowPixmap(pWin)	((PixmapPtr)\
-    dixLookupPrivate(&((WindowPtr)(pWin))->devPrivates, fbGetWinPrivateKey()))
+				 dixLookupPrivate(&((WindowPtr)(pWin))->devPrivates, fbGetWinPrivateKey()))
 
 #ifdef ROOTLESS
 #define __fbPixDrawableX(pPix)	((pPix)->drawable.x)
@@ -830,8 +835,6 @@ fb24_32ModifyPixmapHeader (PixmapPtr   pPixmap,
 /*
  * fballpriv.c
  */
-extern _X_EXPORT DevPrivateKey fbGetWinPrivateKey(void);
-
 extern _X_EXPORT Bool
 fbAllocatePrivates(ScreenPtr pScreen, DevPrivateKey *pGCIndex);
     
diff --git a/fb/fballpriv.c b/fb/fballpriv.c
index 569391b..efeb268 100644
--- a/fb/fballpriv.c
+++ b/fb/fballpriv.c
@@ -27,46 +27,34 @@
 #include "fb.h"
 
 #ifdef FB_SCREEN_PRIVATE
-static int fbScreenPrivateKeyIndex;
-static DevPrivateKey fbScreenPrivateKey = &fbScreenPrivateKeyIndex;
-DevPrivateKey fbGetScreenPrivateKey(void)
-{
-    return fbScreenPrivateKey;
-}
+static DevPrivateKeyRec fbScreenPrivateKeyRec;
+DevPrivateKey
+fbGetScreenPrivateKey(void) { return &fbScreenPrivateKeyRec; }
 #endif
 
-static int fbGCPrivateKeyIndex;
-static DevPrivateKey fbGCPrivateKey = &fbGCPrivateKeyIndex;
-DevPrivateKey fbGetGCPrivateKey(void)
-{
-    return fbGCPrivateKey;
-}
+static DevPrivateKeyRec fbGCPrivateKeyRec;
+DevPrivateKey
+fbGetGCPrivateKey (void) { return &fbGCPrivateKeyRec; }
 
-static int fbWinPrivateKeyIndex;
-static DevPrivateKey fbWinPrivateKey = &fbWinPrivateKeyIndex;
-DevPrivateKey fbGetWinPrivateKey(void)
-{
-    return fbWinPrivateKey;
-}
+static DevPrivateKeyRec fbWinPrivateKeyRec;
+DevPrivateKey
+fbGetWinPrivateKey (void) { return &fbWinPrivateKeyRec; }
 
 Bool
 fbAllocatePrivates(ScreenPtr pScreen, DevPrivateKey *pGCKey)
 {
     if (pGCKey)
-	*pGCKey = fbGCPrivateKey;
+	*pGCKey = &fbGCPrivateKeyRec;
     
-    if (!dixRequestPrivate(fbGCPrivateKey, sizeof(FbGCPrivRec)))
+    if (!dixRegisterPrivateKey(&fbGCPrivateKeyRec, PRIVATE_GC, sizeof(FbGCPrivRec)))
 	return FALSE;
 #ifdef FB_SCREEN_PRIVATE
-    {
-	FbScreenPrivPtr	pScreenPriv;
-
-	pScreenPriv = (FbScreenPrivPtr) malloc(sizeof (FbScreenPrivRec));
-	if (!pScreenPriv)
-	    return FALSE;
-	dixSetPrivate(&pScreen->devPrivates, fbScreenPrivateKey, pScreenPriv);
-    }
+    if (!dixRegisterPrivateKey(&fbScreenPrivateKeyRec, PRIVATE_SCREEN, sizeof (FbScreenPrivRec)))
+	return FALSE;
 #endif
+    if (!dixRegisterPrivateKey(&fbWinPrivateKeyRec, PRIVATE_WINDOW, 0))
+	return FALSE;
+
     return TRUE;
 }
 
diff --git a/fb/fbcmap.c b/fb/fbcmap.c
index ce6fcd5..02b7268 100644
--- a/fb/fbcmap.c
+++ b/fb/fbcmap.c
@@ -36,8 +36,8 @@
 #error "You should be compiling fbcmap_mi.c instead of fbcmap.c!"
 #endif
 
-static int cmapScrPrivateKeyIndex;
-static DevPrivateKey cmapScrPrivateKey = &cmapScrPrivateKeyIndex;
+static DevPrivateKeyRec cmapScrPrivateKeyRec;
+#define cmapScrPrivateKey (&cmapScrPrivateKeyRec)
 
 #define GetInstalledColormap(s) ((ColormapPtr) dixLookupPrivate(&(s)->devPrivates, cmapScrPrivateKey))
 #define SetInstalledColormap(s,c) (dixSetPrivate(&(s)->devPrivates, cmapScrPrivateKey, c))
diff --git a/fb/fboverlay.c b/fb/fboverlay.c
index 392e27f..cda7fc7 100644
--- a/fb/fboverlay.c
+++ b/fb/fboverlay.c
@@ -33,8 +33,8 @@
 #include "fboverlay.h"
 #include "shmint.h"
 
-static int fbOverlayScreenPrivateKeyIndex;
-static DevPrivateKey fbOverlayScreenPrivateKey = &fbOverlayScreenPrivateKeyIndex;
+static DevPrivateKeyRec fbOverlayScreenPrivateKeyRec;
+#define fbOverlayScreenPrivateKey (&fbOverlayScreenPrivateKeyRec)
 
 DevPrivateKey fbOverlayGetScreenPrivateKey(void)
 {
@@ -348,6 +348,9 @@ fbOverlayFinishScreenInit(ScreenPtr	pScreen,
     VisualID	defaultVisual;
     FbOverlayScrPrivPtr	pScrPriv;
 
+    if (!dixRegisterPrivateKey(&fbOverlayScreenPrivateKeyRec, PRIVATE_SCREEN, 0))
+	return FALSE;
+
     pScrPriv = malloc(sizeof (FbOverlayScrPrivRec));
     if (!pScrPriv)
 	return FALSE;
@@ -416,7 +419,6 @@ fbOverlayFinishScreenInit(ScreenPtr	pScreen,
     pScrPriv->layer[1].u.init.pbits = pbits2;
     pScrPriv->layer[1].u.init.width = width2;
     pScrPriv->layer[1].u.init.depth = depth2;
-    
     dixSetPrivate(&pScreen->devPrivates, fbOverlayScreenPrivateKey, pScrPriv);
     
     /* overwrite miCloseScreen with our own */
diff --git a/fb/fbpixmap.c b/fb/fbpixmap.c
index 625ce71..15eedcd 100644
--- a/fb/fbpixmap.c
+++ b/fb/fbpixmap.c
@@ -67,6 +67,7 @@ fbCreatePixmapBpp (ScreenPtr pScreen, int width, int height, int depth, int bpp,
     pPixmap->devKind = paddedWidth;
     pPixmap->refcnt = 1;
     pPixmap->devPrivate.ptr = (pointer) ((char *)pPixmap + base + adjust);
+
 #ifdef FB_DEBUG
     pPixmap->devPrivate.ptr = (void *) ((char *) pPixmap->devPrivate.ptr + paddedWidth);
     fbInitializeDrawable (&pPixmap->drawable);
@@ -100,8 +101,7 @@ fbDestroyPixmap (PixmapPtr pPixmap)
 {
     if(--pPixmap->refcnt)
 	return TRUE;
-    dixFreePrivates(pPixmap->devPrivates);
-    free(pPixmap);
+    FreePixmap(pPixmap);
     return TRUE;
 }
 
diff --git a/fb/fbscreen.c b/fb/fbscreen.c
index 9b789b0..f4311ae 100644
--- a/fb/fbscreen.c
+++ b/fb/fbscreen.c
@@ -37,9 +37,6 @@ fbCloseScreen (int index, ScreenPtr pScreen)
     free(depths);
     free(pScreen->visuals);
     free(pScreen->devPrivate);
-#ifdef FB_SCREEN_PRIVATE
-    free(dixLookupPrivate(&pScreen->devPrivates, fbGetScreenPrivateKey()));
-#endif
     return TRUE;
 }
 
diff --git a/fb/wfbrename.h b/fb/wfbrename.h
index 73ee510..433f286 100644
--- a/fb/wfbrename.h
+++ b/fb/wfbrename.h
@@ -83,13 +83,14 @@
 #define fbFixCoordModePrevious wfbFixCoordModePrevious
 #define fbGCFuncs wfbGCFuncs
 #define fbGCOps wfbGCOps
-#define fbGCPrivateKey wfbGCPrivateKey
+#define fbGCPrivateKeyRec wfbGCPrivateKeyRec
 #define fbGeneration wfbGeneration
 #define fbGetGCPrivateKey wfbGetGCPrivateKey
 #define fbGetImage wfbGetImage
 #define fbGetScreenPrivateKey wfbGetScreenPrivateKey
 #define fbGetSpans wfbGetSpans
 #define _fbGetWindowPixmap _wfbGetWindowPixmap
+#define fbWinPrivateKeyRec wfbWinPrivateKeyRec
 #define fbGetWinPrivateKey wfbGetWinPrivateKey
 #define fbGlyph16 wfbGlyph16
 #define fbGlyph24 wfbGlyph24
@@ -118,7 +119,6 @@
 #define fbOverlayGeneration wfbOverlayGeneration
 #define fbOverlayGetScreenPrivateKey wfbOverlayGetScreenPrivateKey
 #define fbOverlayPaintKey wfbOverlayPaintKey
-#define fbOverlayScreenPrivateKey wfbOverlayScreenPrivateKey
 #define fbOverlaySetupScreen wfbOverlaySetupScreen
 #define fbOverlayUpdateLayerRegion wfbOverlayUpdateLayerRegion
 #define fbOverlayWindowExposures wfbOverlayWindowExposures
@@ -157,7 +157,7 @@
 #define fbResolveColor wfbResolveColor
 #define fbRestoreAreas wfbRestoreAreas
 #define fbSaveAreas wfbSaveAreas
-#define fbScreenPrivateKey wfbScreenPrivateKey
+#define fbScreenPrivateKeyRec wfbScreenPrivateKeyRec
 #define fbSegment wfbSegment
 #define fbSelectBres wfbSelectBres
 #define fbSetSpans wfbSetSpans
@@ -182,7 +182,7 @@
 #define fbUnrealizeFont wfbUnrealizeFont
 #define fbValidateGC wfbValidateGC
 #define fbWalkCompositeRegion wfbWalkCompositeRegion
-#define fbWinPrivateKey wfbWinPrivateKey
+#define fbWinPrivateKeyRec wfbWinPrivateKeyRec
 #define fbZeroLine wfbZeroLine
 #define fbZeroSegment wfbZeroSegment
 #define free_pixman_pict wfb_free_pixman_pict
diff --git a/glx/glxext.c b/glx/glxext.c
index b234afc..4d02b47 100644
--- a/glx/glxext.c
+++ b/glx/glxext.c
@@ -65,8 +65,8 @@ RESTYPE __glXSwapBarrierRes;
 */
 xGLXSingleReply __glXReply;
 
-static int glxClientPrivateKeyIndex;
-static DevPrivateKey glxClientPrivateKey = &glxClientPrivateKeyIndex;
+static DevPrivateKeyRec glxClientPrivateKeyRec;
+#define glxClientPrivateKey (&glxClientPrivateKeyRec)
 
 /*
 ** Client that called into GLX dispatch.
@@ -364,7 +364,7 @@ void GlxExtensionInit(void)
     if (!__glXContextRes || !__glXDrawableRes || !__glXSwapBarrierRes)
 	return;
 
-    if (!dixRequestPrivate(glxClientPrivateKey, sizeof (__GLXclientState)))
+    if (!dixRegisterPrivateKey(&glxClientPrivateKeyRec, PRIVATE_CLIENT, sizeof (__GLXclientState)))
 	return;
     if (!AddCallback (&ClientStateCallback, glxClientCallback, 0))
 	return;
diff --git a/glx/glxscreens.c b/glx/glxscreens.c
index ffe70c3..a5b61df 100644
--- a/glx/glxscreens.c
+++ b/glx/glxscreens.c
@@ -44,8 +44,8 @@
 #include "glxext.h"
 #include "protocol-versions.h"
 
-static int glxScreenPrivateKeyIndex;
-static DevPrivateKey glxScreenPrivateKey = &glxScreenPrivateKeyIndex;
+static DevPrivateKeyRec glxScreenPrivateKeyRec;
+#define glxScreenPrivateKey (&glxScreenPrivateKeyRec)
 
 const char GLServerVersion[] = "1.4";
 static const char GLServerExtensions[] = 
@@ -352,6 +352,9 @@ void __glXScreenInit(__GLXscreen *pGlxScreen, ScreenPtr pScreen)
     __GLXconfig *config;
     int i;
 
+    if (!dixRegisterPrivateKey(&glxScreenPrivateKeyRec, PRIVATE_SCREEN, 0))
+	return;
+
     pGlxScreen->pScreen       = pScreen;
     pGlxScreen->GLextensions  = xstrdup(GLServerExtensions);
     pGlxScreen->GLXvendor     = xstrdup(GLXServerVendorName);
diff --git a/hw/dmx/dmx.h b/hw/dmx/dmx.h
index fbb8b96..4532960 100644
--- a/hw/dmx/dmx.h
+++ b/hw/dmx/dmx.h
@@ -364,4 +364,27 @@ do {									\
 #define MAXSCREENSCALLOC_FATAL(o,m)     _MAXSCREENSALLOCF(o,MAXSCREENS*(m),1)
 #endif
 
+extern DevPrivateKeyRec dmxGCPrivateKeyRec;
+#define dmxGCPrivateKey (&dmxGCPrivateKeyRec) /**< Private index for GCs       */
+
+extern DevPrivateKeyRec dmxWinPrivateKeyRec;
+#define dmxWinPrivateKey (&dmxWinPrivateKeyRec) /**< Private index for Windows   */
+
+extern DevPrivateKeyRec dmxPixPrivateKeyRec;
+#define dmxPixPrivateKey (&dmxPixPrivateKeyRec) /**< Private index for Pixmaps   */
+
+extern int dmxFontPrivateIndex;        /**< Private index for Fonts     */
+
+extern DevPrivateKeyRec dmxScreenPrivateKeyRec;
+#define dmxScreenPrivateKey (&dmxScreenPrivateKeyRec) /**< Private index for Screens   */
+
+extern DevPrivateKeyRec dmxColormapPrivateKeyRec;
+#define dmxColormapPrivateKey (&dmxColormapPrivateKeyRec) /**< Private index for Colormaps */
+
+extern DevPrivateKeyRec dmxPictPrivateKeyRec;
+#define dmxPictPrivateKey (&dmxPictPrivateKeyRec) /**< Private index for Picts     */
+
+extern DevPrivateKeyRec dmxGlyphSetPrivateKeyRec;
+#define dmxGlyphSetPrivateKey (&dmxGlyphSetPrivateKeyRec) /**< Private index for GlyphSets */
+
 #endif /* DMX_H */
diff --git a/hw/dmx/dmxcmap.h b/hw/dmx/dmxcmap.h
index f968f86..75e0650 100644
--- a/hw/dmx/dmxcmap.h
+++ b/hw/dmx/dmxcmap.h
@@ -55,9 +55,6 @@ extern Bool dmxCreateDefColormap(ScreenPtr pScreen);
 extern Bool dmxBECreateColormap(ColormapPtr pColormap);
 extern Bool dmxBEFreeColormap(ColormapPtr pColormap);
 
-/** Private index.  \see dmxcmap.c \see dmxscrinit.c \see dmxwindow.c */
-extern DevPrivateKey dmxColormapPrivateKey;
-
 /** Set colormap private structure. */
 #define DMX_SET_COLORMAP_PRIV(_pCMap, _pCMapPriv)			\
     dixSetPrivate(&(_pCMap)->devPrivates, dmxColormapPrivateKey, _pCMapPriv)
diff --git a/hw/dmx/dmxgc.c b/hw/dmx/dmxgc.c
index 3e75de7..829200e 100644
--- a/hw/dmx/dmxgc.c
+++ b/hw/dmx/dmxgc.c
@@ -85,7 +85,7 @@ static GCOps dmxGCOps = {
 /** Initialize the GC on \a pScreen */
 Bool dmxInitGC(ScreenPtr pScreen)
 {
-    if (!dixRequestPrivate(dmxGCPrivateKey, sizeof(dmxGCPrivRec)))
+    if (!dixRegisterPrivateKey(&dmxGCPrivateKeyRec, PRIVATE_GC, sizeof(dmxGCPrivRec)))
             return FALSE;
     return TRUE;
 }
diff --git a/hw/dmx/dmxgc.h b/hw/dmx/dmxgc.h
index 2da3ba8..4ff3cd8 100644
--- a/hw/dmx/dmxgc.h
+++ b/hw/dmx/dmxgc.h
@@ -63,9 +63,6 @@ extern void dmxCopyClip(GCPtr pGCDst, GCPtr pGCSrc);
 extern void dmxBECreateGC(ScreenPtr pScreen, GCPtr pGC);
 extern Bool dmxBEFreeGC(GCPtr pGC);
 
-/** Private index.  \see dmxgc.c \see dmxscrinit.c */
-extern DevPrivateKey dmxGCPrivateKey;
-
 /** Get private. */
 #define DMX_GET_GC_PRIV(_pGC)						\
     (dmxGCPrivPtr)dixLookupPrivate(&(_pGC)->devPrivates, dmxGCPrivateKey)
diff --git a/hw/dmx/dmxpict.c b/hw/dmx/dmxpict.c
index 1642145..915e767 100644
--- a/hw/dmx/dmxpict.c
+++ b/hw/dmx/dmxpict.c
@@ -145,7 +145,7 @@ Bool dmxPictureInit(ScreenPtr pScreen, PictFormatPtr formats, int nformats)
     if (!miPictureInit(pScreen, formats, nformats))
 	return FALSE;
 
-    if (!dixRequestPrivate(dmxPictPrivateKey, sizeof(dmxPictPrivRec)))
+    if (!dixRegisterPrivateKey(&dmxPictPrivateKeyRec, PRIVATE_PICTURE, sizeof(dmxPictPrivRec)))
 	return FALSE;
 
     ps = GetPictureScreen(pScreen);
diff --git a/hw/dmx/dmxpict.h b/hw/dmx/dmxpict.h
index a81eb7d..3c8a09c 100644
--- a/hw/dmx/dmxpict.h
+++ b/hw/dmx/dmxpict.h
@@ -116,10 +116,6 @@ extern Bool dmxBEFreeGlyphSet(ScreenPtr pScreen, GlyphSetPtr glyphSet);
 extern int dmxBECreatePicture(PicturePtr pPicture);
 extern Bool dmxBEFreePicture(PicturePtr pPicture);
 
-extern DevPrivateKey dmxPictPrivateKey;	/**< Index for picture private data */
-extern DevPrivateKey dmxGlyphSetPrivateKey; /**< Index for glyphset private data */
-
-
 /** Get the picture private data given a picture pointer */
 #define DMX_GET_PICT_PRIV(_pPict)					\
     (dmxPictPrivPtr)dixLookupPrivate(&(_pPict)->devPrivates, dmxPictPrivateKey)
diff --git a/hw/dmx/dmxpixmap.c b/hw/dmx/dmxpixmap.c
index a64cbd0..a058ae2 100644
--- a/hw/dmx/dmxpixmap.c
+++ b/hw/dmx/dmxpixmap.c
@@ -49,7 +49,7 @@
 /** Initialize a private area in \a pScreen for pixmap information. */
 Bool dmxInitPixmap(ScreenPtr pScreen)
 {
-    if (!dixRequestPrivate(dmxPixPrivateKey, sizeof(dmxPixPrivRec)))
+    if (!dixRegisterPrivateKey(&dmxPixPrivateKeyRec, PRIVATE_PIXMAP, sizeof(dmxPixPrivRec)))
 	return FALSE;
 
     return TRUE;
@@ -174,8 +174,7 @@ Bool dmxDestroyPixmap(PixmapPtr pPixmap)
 	    dmxSync(dmxScreen, FALSE);
 	}
     }
-    dixFreePrivates(pPixmap->devPrivates);
-    free(pPixmap);
+    FreePixmap(pPixmap);
 
 #if 0
     if (pScreen->DestroyPixmap)
diff --git a/hw/dmx/dmxpixmap.h b/hw/dmx/dmxpixmap.h
index 6441834..59da788 100644
--- a/hw/dmx/dmxpixmap.h
+++ b/hw/dmx/dmxpixmap.h
@@ -57,9 +57,6 @@ extern RegionPtr dmxBitmapToRegion(PixmapPtr pPixmap);
 extern void      dmxBECreatePixmap(PixmapPtr pPixmap);
 extern Bool      dmxBEFreePixmap(PixmapPtr pPixmap);
 
-/** Private index.  \see dmxpicmap.h \see dmxscrinit.c */
-extern DevPrivateKey dmxPixPrivateKey;
-
 /** Get pixmap private pointer. */
 #define DMX_GET_PIXMAP_PRIV(_pPix)					\
     (dmxPixPrivPtr)dixLookupPrivate(&(_pPix)->devPrivates, dmxPixPrivateKey)
diff --git a/hw/dmx/dmxscrinit.c b/hw/dmx/dmxscrinit.c
index 068e809..6d2f2d3 100644
--- a/hw/dmx/dmxscrinit.c
+++ b/hw/dmx/dmxscrinit.c
@@ -65,21 +65,14 @@ static Bool dmxSaveScreen(ScreenPtr pScreen, int what);
 static unsigned long dmxGeneration;
 static unsigned long *dmxCursorGeneration;
 
-static int dmxGCPrivateKeyIndex;
-DevPrivateKey dmxGCPrivateKey = &dmxGCPrivateKeyIndex; /**< Private index for GCs       */
-static int dmxWinPrivateKeyIndex;
-DevPrivateKey dmxWinPrivateKey = &dmxWinPrivateKeyIndex; /**< Private index for Windows   */
-static int dmxPixPrivateKeyIndex;
-DevPrivateKey dmxPixPrivateKey = &dmxPixPrivateKeyIndex; /**< Private index for Pixmaps   */
+DevPrivateKeyRec dmxGCPrivateKeyRec;
+DevPrivateKeyRec dmxWinPrivateKeyRec;
+DevPrivateKeyRec dmxPixPrivateKeyRec;
 int dmxFontPrivateIndex;        /**< Private index for Fonts     */
-static int dmxScreenPrivateKeyIndex;
-DevPrivateKey dmxScreenPrivateKey = &dmxScreenPrivateKeyIndex; /**< Private index for Screens   */
-static int dmxColormapPrivateKeyIndex;
-DevPrivateKey dmxColormapPrivateKey = &dmxColormapPrivateKeyIndex; /**< Private index for Colormaps */
-static int dmxPictPrivateKeyIndex;
-DevPrivateKey dmxPictPrivateKey = &dmxPictPrivateKeyIndex; /**< Private index for Picts     */
-static int dmxGlyphSetPrivateKeyIndex;
-DevPrivateKey dmxGlyphSetPrivateKey = &dmxGlyphSetPrivateKeyIndex; /**< Private index for GlyphSets */
+DevPrivateKeyRec dmxScreenPrivateKeyRec;
+DevPrivateKeyRec dmxColormapPrivateKeyRec;
+DevPrivateKeyRec dmxPictPrivateKeyRec;
+DevPrivateKeyRec dmxGlyphSetPrivateKeyRec;
 
 /** Initialize the parts of screen \a idx that require access to the
  *  back-end server. */
@@ -210,6 +203,13 @@ Bool dmxScreenInit(int idx, ScreenPtr pScreen, int argc, char *argv[])
     DMXScreenInfo        *dmxScreen = &dmxScreens[idx];
     int                   i, j;
 
+    if (!dixRegisterPrivateKey(&dmxScreenPrivateKeyRec, PRIVATE_SCREEN, 0))
+	return FALSE;
+    if (!dixRegisterPrivateKey(&dmxColormapPrivateKeyRec, PRIVATE_COLORMAP, 0))
+	return FALSE;
+    if (!dixRegisterPrivateKey(&dmxGlyphSetPrivateKeyRec, PRIVATE_GLYPHSET, 0))
+	return FALSE;
+
     if (dmxGeneration != serverGeneration) {
 	/* Allocate font private index */
 	dmxFontPrivateIndex = AllocateFontPrivateIndex();
diff --git a/hw/dmx/dmxscrinit.h b/hw/dmx/dmxscrinit.h
index a464235..9c9fbc5 100644
--- a/hw/dmx/dmxscrinit.h
+++ b/hw/dmx/dmxscrinit.h
@@ -40,9 +40,6 @@
 
 #include "scrnintstr.h"
 
-/** Private index.  \see dmxscrrinit.c \see input/dmxconcole.c */
-extern DevPrivateKey dmxScreenPrivateKey;
-
 extern Bool dmxScreenInit(int idx, ScreenPtr pScreen, int argc, char *argv[]);
 
 extern void dmxBEScreenInit(int idx, ScreenPtr pScreen);
diff --git a/hw/dmx/dmxwindow.c b/hw/dmx/dmxwindow.c
index 28212a3..4484828 100644
--- a/hw/dmx/dmxwindow.c
+++ b/hw/dmx/dmxwindow.c
@@ -60,7 +60,7 @@ static void dmxDoSetShape(WindowPtr pWindow);
 /** Initialize the private area for the window functions. */
 Bool dmxInitWindow(ScreenPtr pScreen)
 {
-    if (!dixRequestPrivate(dmxWinPrivateKey, sizeof(dmxWinPrivRec)))
+    if (!dixRegisterPrivateKey(&dmxWinPrivateKeyRec, PRIVATE_WINDOW, sizeof(dmxWinPrivRec)))
 	return FALSE;
 
     return TRUE;
diff --git a/hw/dmx/dmxwindow.h b/hw/dmx/dmxwindow.h
index 8bd1f74..f93121e 100644
--- a/hw/dmx/dmxwindow.h
+++ b/hw/dmx/dmxwindow.h
@@ -96,9 +96,6 @@ extern Bool dmxBEDestroyWindow(WindowPtr pWindow);
 /* Support for shape extension */
 extern void dmxSetShape(WindowPtr pWindow, int kind);
 
-/** Private index.  \see dmxwindow.c \see dmxscrinit.c */
-extern DevPrivateKey dmxWinPrivateKey;
-
 /** Get window private pointer. */
 #define DMX_GET_WINDOW_PRIV(_pWin) ((dmxWinPrivPtr) \
     dixLookupPrivate(&(_pWin)->devPrivates, dmxWinPrivateKey))
diff --git a/hw/kdrive/ephyr/ephyrdriext.c b/hw/kdrive/ephyr/ephyrdriext.c
index 23c2032..4041bf5 100644
--- a/hw/kdrive/ephyr/ephyrdriext.c
+++ b/hw/kdrive/ephyr/ephyrdriext.c
@@ -109,10 +109,10 @@ static Bool findWindowPairFromLocal (WindowPtr a_local,
 
 static unsigned char DRIReqCode = 0;
 
-static int ephyrDRIWindowKeyIndex;
-static DevPrivateKey ephyrDRIWindowKey = &ephyrDRIWindowKeyIndex;
-static int ephyrDRIScreenKeyIndex;
-static DevPrivateKey ephyrDRIScreenKey = &ephyrDRIScreenKeyIndex;
+static DevPrivateKeyRec ephyrDRIWindowKeyRec;
+#define ephyrDRIWindowKey (&ephyrDRIWindowKeyRec)
+static DevPrivateKeyRec ephyrDRIScreenKeyRec;
+#define ephyrDRIScreenKey (&ephyrDRIScreenKeyRec)
 
 #define GET_EPHYR_DRI_WINDOW_PRIV(win) ((EphyrDRIWindowPrivPtr) \
     dixLookupPrivate(&(win)->devPrivates, ephyrDRIWindowKey))
diff --git a/hw/kdrive/src/kdrive.c b/hw/kdrive/src/kdrive.c
index 27596e4..06c3661 100644
--- a/hw/kdrive/src/kdrive.c
+++ b/hw/kdrive/src/kdrive.c
@@ -64,8 +64,7 @@ KdDepths    kdDepths[] = {
 
 #define KD_DEFAULT_BUTTONS 5
 
-static int          kdScreenPrivateKeyIndex;
-DevPrivateKey       kdScreenPrivateKey = &kdScreenPrivateKeyIndex;
+DevPrivateKeyRec    kdScreenPrivateKeyRec;
 unsigned long	    kdGeneration;
 
 Bool                kdVideoTest;
@@ -699,6 +698,9 @@ KdAllocatePrivates (ScreenPtr pScreen)
     if (kdGeneration != serverGeneration)
 	kdGeneration = serverGeneration;
 
+    if (!dixRegisterPrivateKey(&kdScreenPrivateKeyRec, PRIVATE_SCREEN, 0))
+	return FALSE;
+
     pScreenPriv = calloc(1, sizeof (*pScreenPriv));
     if (!pScreenPriv)
 	return FALSE;
diff --git a/hw/kdrive/src/kdrive.h b/hw/kdrive/src/kdrive.h
index 35ce036..3ca9814 100644
--- a/hw/kdrive/src/kdrive.h
+++ b/hw/kdrive/src/kdrive.h
@@ -342,7 +342,9 @@ typedef struct _KdPointerMatrix {
     (PixmapWidthPaddingInfo[d].padRoundUp+1)))
 #endif
 
-extern DevPrivateKey	kdScreenPrivateKey;
+extern DevPrivateKeyRec	kdScreenPrivateKeyRec;
+#define kdScreenPrivateKey (&kdScreenPrivateKeyRec)
+
 extern unsigned long	kdGeneration;
 extern Bool		kdEnabled;
 extern Bool		kdSwitchPending;
diff --git a/hw/kdrive/src/kxv.c b/hw/kdrive/src/kxv.c
index 99ab2d8..24ae89e 100644
--- a/hw/kdrive/src/kxv.c
+++ b/hw/kdrive/src/kxv.c
@@ -103,10 +103,10 @@ static void KdXVClipNotify(WindowPtr pWin, int dx, int dy);
 /* misc */
 static Bool KdXVInitAdaptors(ScreenPtr, KdVideoAdaptorPtr*, int);
 
-static int KdXVWindowKeyIndex;
-DevPrivateKey KdXVWindowKey = &KdXVWindowKeyIndex;
-static int KdXvScreenKeyIndex;
-DevPrivateKey KdXvScreenKey = &KdXvScreenKeyIndex;
+static DevPrivateKeyRec KdXVWindowKeyRec;
+#define KdXVWindowKey (&KdXVWindowKeyRec)
+static DevPrivateKeyRec KdXvScreenKeyRec;
+#define KdXvScreenKey (&KdXvScreenKeyRec)
 static unsigned long KdXVGeneration = 0;
 static unsigned long PortResource = 0;
 
@@ -199,6 +199,12 @@ KdXVScreenInit(
   if(!XvGetScreenKeyProc || !XvGetRTPortProc || !XvScreenInitProc)
 	return FALSE;
 
+  if (!dixRegisterPrivateKey(&KdXVWindowKeyRec, PRIVATE_WINDOW, 0))
+      return FALSE;
+
+  if (!dixRegisterPrivateKey(&KdXVScreenKeyRec, PRIVATE_SCREEN, 0))
+      return FALSE;
+
   if(Success != (*XvScreenInitProc)(pScreen)) return FALSE;
 
   KdXvScreenKey = (*XvGetScreenKeyProc)();
diff --git a/hw/vfb/InitOutput.c b/hw/vfb/InitOutput.c
index 0f0edb2..2f41955 100644
--- a/hw/vfb/InitOutput.c
+++ b/hw/vfb/InitOutput.c
@@ -389,8 +389,8 @@ ddxProcessArgument(int argc, char *argv[], int i)
     return 0;
 }
 
-static int cmapScrPrivateKeyIndex;
-static DevPrivateKey cmapScrPrivateKey = &cmapScrPrivateKeyIndex;
+static DevPrivateKeyRec cmapScrPrivateKeyRec;
+#define cmapScrPrivateKey (&cmapScrPrivateKeyRec)
 
 #define GetInstalledColormap(s) ((ColormapPtr) dixLookupPrivate(&(s)->devPrivates, cmapScrPrivateKey))
 #define SetInstalledColormap(s,c) (dixSetPrivate(&(s)->devPrivates, cmapScrPrivateKey, c))
@@ -811,6 +811,9 @@ vfbScreenInit(int index, ScreenPtr pScreen, int argc, char **argv)
     int ret;
     char *pbits;
     
+    if (!dixRegisterPrivateKey(&cmapScrPrivateKeyRec, PRIVATE_SCREEN, 0))
+	return FALSE;
+
     if (dpix == 0)
       dpix = 100;
 
diff --git a/hw/xfree86/common/xf86.h b/hw/xfree86/common/xf86.h
index d8629a8..886c25b 100644
--- a/hw/xfree86/common/xf86.h
+++ b/hw/xfree86/common/xf86.h
@@ -55,9 +55,16 @@
 extern _X_EXPORT int xf86DoConfigure;
 extern _X_EXPORT int xf86DoShowOptions;
 extern _X_EXPORT Bool xf86DoConfigurePass1;
-extern _X_EXPORT DevPrivateKey xf86ScreenKey;
-extern _X_EXPORT DevPrivateKey xf86CreateRootWindowKey;
-extern _X_EXPORT DevPrivateKey xf86PixmapKey;
+
+extern _X_EXPORT DevPrivateKeyRec xf86ScreenKeyRec;
+#define xf86ScreenKey (&xf86ScreenKeyRec)
+
+extern _X_EXPORT DevPrivateKeyRec xf86CreateRootWindowKeyRec;
+#define xf86CreateRootWindowKey (&xf86CreateRootWindowKeyRec)
+
+extern _X_EXPORT DevPrivateKeyRec xf86PixmapKeyRec;
+#define xf86PixmapKey (&xf86PixmapKeyRec)
+
 extern _X_EXPORT ScrnInfoPtr *xf86Screens;	/* List of pointers to ScrnInfoRecs */
 extern _X_EXPORT const unsigned char byte_reversed[256];
 extern _X_EXPORT Bool fbSlotClaimed;
diff --git a/hw/xfree86/common/xf86DGA.c b/hw/xfree86/common/xf86DGA.c
index a51a754..82fb52a 100644
--- a/hw/xfree86/common/xf86DGA.c
+++ b/hw/xfree86/common/xf86DGA.c
@@ -51,8 +51,8 @@
 
 #include "mi.h"
 
-static int DGAScreenKeyIndex;
-static DevPrivateKey DGAScreenKey;
+static DevPrivateKeyRec DGAScreenKeyRec;
+#define DGAScreenKeyRegistered dixPrivateKeyRegistered(&DGAScreenKeyRec)
 static int mieq_installed = 0;
 
 static Bool DGACloseScreen(int i, ScreenPtr pScreen);
@@ -71,7 +71,7 @@ DGACopyModeInfo(
 int *XDGAEventBase = NULL;
 
 #define DGA_GET_SCREEN_PRIV(pScreen) ((DGAScreenPtr) \
-    dixLookupPrivate(&(pScreen)->devPrivates, DGAScreenKey))
+    dixLookupPrivate(&(pScreen)->devPrivates, &DGAScreenKeyRec))
 
 
 typedef struct _FakedVisualList{
@@ -118,7 +118,8 @@ DGAInit(
     if(!modes || num <= 0)
 	return FALSE;
 
-    DGAScreenKey = &DGAScreenKeyIndex;
+    if (!dixRegisterPrivateKey(&DGAScreenKeyRec, PRIVATE_SCREEN, 0))
+	return FALSE;
 
     pScreenPriv = DGA_GET_SCREEN_PRIV(pScreen);
 
@@ -126,7 +127,7 @@ DGAInit(
     {
 	if(!(pScreenPriv = (DGAScreenPtr)malloc(sizeof(DGAScreenRec))))
 	    return FALSE;
-	dixSetPrivate(&pScreen->devPrivates, DGAScreenKey, pScreenPriv);
+	dixSetPrivate(&pScreen->devPrivates, &DGAScreenKeyRec, pScreenPriv);
 	pScreenPriv->CloseScreen = pScreen->CloseScreen;
 	pScreen->CloseScreen = DGACloseScreen;
 	pScreenPriv->DestroyColormap = pScreen->DestroyColormap;
@@ -177,7 +178,7 @@ DGAReInitModes(
     int i;
 
     /* No DGA? Ignore call (but don't make it look like it failed) */
-    if(DGAScreenKey == NULL)
+    if(!DGAScreenKeyRegistered)
 	return TRUE;
 	
     pScreenPriv = DGA_GET_SCREEN_PRIV(pScreen);
@@ -347,7 +348,7 @@ xf86SetDGAMode(
    DGAModePtr pMode = NULL;
 
    /* First check if DGAInit was successful on this screen */
-   if (DGAScreenKey == NULL)
+   if (!DGAScreenKeyRegistered)
 	return BadValue;
    pScreenPriv = DGA_GET_SCREEN_PRIV(pScreen);
    if (!pScreenPriv)
@@ -478,7 +479,7 @@ DGAChangePixmapMode(int index, int *x, int *y, int mode)
    DGAModePtr   pMode;
    PixmapPtr    pPix;
 
-   if(DGAScreenKey == NULL)
+   if(!DGAScreenKeyRegistered)
 	return FALSE;
 
    pScreenPriv = DGA_GET_SCREEN_PRIV(screenInfo.screens[index]);
@@ -528,7 +529,7 @@ DGAChangePixmapMode(int index, int *x, int *y, int mode)
 Bool
 DGAAvailable(int index) 
 {
-   if(DGAScreenKey == NULL)
+   if(!DGAScreenKeyRegistered)
 	return FALSE;
    
    if(DGA_GET_SCREEN_PRIV(screenInfo.screens[index]))
@@ -542,7 +543,7 @@ DGAActive(int index)
 {
    DGAScreenPtr pScreenPriv;
 
-   if(DGAScreenKey == NULL)
+   if(!DGAScreenKeyRegistered)
 	return FALSE;
 
    pScreenPriv = DGA_GET_SCREEN_PRIV(screenInfo.screens[index]);
@@ -563,7 +564,7 @@ DGAShutdown(void)
     ScrnInfoPtr pScrn;
     int i;
 
-    if(DGAScreenKey == NULL)
+    if(!DGAScreenKeyRegistered)
 	return;
 
     for(i = 0; i < screenInfo.numScreens; i++) {
@@ -893,7 +894,7 @@ DGAVTSwitch(void)
 
        /* Alternatively, this could send events to DGA clients */
 
-       if(DGAScreenKey) {
+       if(DGAScreenKeyRegistered) {
 	   DGAScreenPtr pScreenPriv = DGA_GET_SCREEN_PRIV(pScreen);
 
 	   if(pScreenPriv && pScreenPriv->current)
@@ -910,7 +911,7 @@ DGAStealKeyEvent(DeviceIntPtr dev, int index, int key_code, int is_down)
    DGAScreenPtr pScreenPriv;
    DGAEvent     event;
 
-   if(DGAScreenKey == NULL) /* no DGA */
+   if(!DGAScreenKeyRegistered) /* no DGA */
         return FALSE;
 
    if (key_code < 8 || key_code > 255)
@@ -943,7 +944,7 @@ DGAStealMotionEvent(DeviceIntPtr dev, int index, int dx, int dy)
    DGAScreenPtr pScreenPriv;
    DGAEvent event;
 
-   if(DGAScreenKey == NULL) /* no DGA */
+   if(!DGAScreenKeyRegistered) /* no DGA */
         return FALSE;
     
    pScreenPriv = DGA_GET_SCREEN_PRIV(screenInfo.screens[index]);
@@ -981,7 +982,7 @@ DGAStealButtonEvent(DeviceIntPtr dev, int index, int button, int is_down)
     DGAScreenPtr pScreenPriv;
     DGAEvent event;
 
-    if (DGAScreenKey == NULL)
+    if(!DGAScreenKeyRegistered) /* no DGA */
         return FALSE;
     
     pScreenPriv = DGA_GET_SCREEN_PRIV(screenInfo.screens[index]);
@@ -1009,7 +1010,7 @@ Bool
 DGAIsDgaEvent (xEvent *e)
 {
     int	    coreEquiv;
-    if (DGAScreenKey == NULL || XDGAEventBase == 0)
+    if (!DGAScreenKeyRegistered || XDGAEventBase == 0)
 	return FALSE;
     coreEquiv = e->u.u.type - *XDGAEventBase;
     if (KeyPress <= coreEquiv && coreEquiv <= MotionNotify)
@@ -1203,7 +1204,7 @@ DGAHandleEvent(int screen_num, InternalEvent *ev, DeviceIntPtr device)
     DGAScreenPtr    pScreenPriv;
 
     /* no DGA */
-    if (DGAScreenKey == NULL || XDGAEventBase == 0)
+    if (!DGAScreenKeyRegistered || XDGAEventBase == 0)
 	return;
     pScreenPriv = DGA_GET_SCREEN_PRIV(pScreen);
 
diff --git a/hw/xfree86/common/xf86DPMS.c b/hw/xfree86/common/xf86DPMS.c
index cd33e75..cd025dc 100644
--- a/hw/xfree86/common/xf86DPMS.c
+++ b/hw/xfree86/common/xf86DPMS.c
@@ -46,7 +46,7 @@
 
 
 #ifdef DPMSExtension
-static int DPMSKeyIndex;
+static DevPrivateKeyRec DPMSKeyRec;
 static DevPrivateKey DPMSKey;
 static Bool DPMSClose(int i, ScreenPtr pScreen);
 static int DPMSCount = 0;
@@ -62,10 +62,9 @@ xf86DPMSInit(ScreenPtr pScreen, DPMSSetProcPtr set, int flags)
     pointer DPMSOpt;
     MessageType enabled_from;
 
-    DPMSKey = &DPMSKeyIndex;
+    DPMSKey = &DPMSKeyRec;
 
-    if (!dixSetPrivate(&pScreen->devPrivates, DPMSKey,
-		       calloc(sizeof(DPMSRec), 1)))
+    if (!dixRegisterPrivateKey(&DPMSKeyRec, PRIVATE_SCREEN, sizeof (DPMSRec)))
 	return FALSE;
 
     pDPMS = dixLookupPrivate(&pScreen->devPrivates, DPMSKey);
@@ -127,8 +126,6 @@ DPMSClose(int i, ScreenPtr pScreen)
  	xf86Screens[i]->DPMSSet(xf86Screens[i],DPMSModeOn,0);
     }
     
-    free(pDPMS);
-    dixSetPrivate(&pScreen->devPrivates, DPMSKey, NULL);
     if (--DPMSCount == 0)
 	DPMSKey = NULL;
     return pScreen->CloseScreen(i, pScreen);
diff --git a/hw/xfree86/common/xf86Globals.c b/hw/xfree86/common/xf86Globals.c
index 8b483f3..43665d1 100644
--- a/hw/xfree86/common/xf86Globals.c
+++ b/hw/xfree86/common/xf86Globals.c
@@ -47,14 +47,10 @@
 
 /* Globals that video drivers may access */
 
-/* Index into pScreen.devPrivates */
-static int xf86CreateRootWindowKeyIndex;
-DevPrivateKey xf86CreateRootWindowKey = &xf86CreateRootWindowKeyIndex;
-/* Index of ScrnInfo in pScreen.devPrivates */
-static int xf86ScreenKeyIndex;
-DevPrivateKey xf86ScreenKey = &xf86ScreenKeyIndex;
-static int xf86PixmapKeyIndex;
-DevPrivateKey xf86PixmapKey = &xf86PixmapKeyIndex;
+DevPrivateKeyRec xf86CreateRootWindowKeyRec;
+DevPrivateKeyRec xf86ScreenKeyRec;
+DevPrivateKeyRec xf86PixmapKeyRec;
+
 ScrnInfoPtr *xf86Screens = NULL;	/* List of ScrnInfos */
 const unsigned char byte_reversed[256] =
 {
diff --git a/hw/xfree86/common/xf86Init.c b/hw/xfree86/common/xf86Init.c
index db88f70..18df8c9 100644
--- a/hw/xfree86/common/xf86Init.c
+++ b/hw/xfree86/common/xf86Init.c
@@ -66,6 +66,7 @@
 #include "xf86Priv.h"
 #include "xf86Config.h"
 #include "xf86_OSlib.h"
+#include "xf86cmap.h"
 #include "xorgVersion.h"
 #include "xf86Build.h"
 #include "mipointer.h"
@@ -734,6 +735,15 @@ InitOutput(ScreenInfo *pScreenInfo, int argc, char **argv)
   }
 #endif /* SCO325 */
 
+  for (i = 0; i < xf86NumScreens; i++)
+      if (!xf86ColormapAllocatePrivates(xf86Screens[i]))
+	  FatalError("Cannot register DDX private keys");
+
+  if (!dixRegisterPrivateKey(&xf86ScreenKeyRec, PRIVATE_SCREEN, 0) ||
+      !dixRegisterPrivateKey(&xf86CreateRootWindowKeyRec, PRIVATE_SCREEN, 0) ||
+      !dixRegisterPrivateKey(&xf86PixmapKeyRec, PRIVATE_PIXMAP, 0))
+      FatalError("Cannot register DDX private keys");
+
   for (i = 0; i < xf86NumScreens; i++) {
 	xf86VGAarbiterLock(xf86Screens[i]);
 	/*
diff --git a/hw/xfree86/common/xf86RandR.c b/hw/xfree86/common/xf86RandR.c
index 77053b8..d7ffff4 100644
--- a/hw/xfree86/common/xf86RandR.c
+++ b/hw/xfree86/common/xf86RandR.c
@@ -46,7 +46,7 @@ typedef struct _xf86RandRInfo {
     Rotation			    rotation;
 } XF86RandRInfoRec, *XF86RandRInfoPtr;
 
-static int xf86RandRKeyIndex;
+static DevPrivateKeyRec xf86RandRKeyRec;
 static DevPrivateKey xf86RandRKey;
 
 #define XF86RANDRINFO(p) ((XF86RandRInfoPtr)dixLookupPrivate(&(p)->devPrivates, xf86RandRKey))
@@ -424,7 +424,10 @@ xf86RandRInit (ScreenPtr    pScreen)
 	return TRUE;
 #endif
 
-    xf86RandRKey = &xf86RandRKeyIndex;
+    xf86RandRKey = &xf86RandRKeyRec;
+
+    if (!dixRegisterPrivateKey(&xf86RandRKeyRec, PRIVATE_SCREEN, 0))
+	return FALSE;
 
     randrp = malloc(sizeof (XF86RandRInfoRec));
     if (!randrp)
diff --git a/hw/xfree86/common/xf86VGAarbiter.c b/hw/xfree86/common/xf86VGAarbiter.c
index 4a736fc..a58d21a 100644
--- a/hw/xfree86/common/xf86VGAarbiter.c
+++ b/hw/xfree86/common/xf86VGAarbiter.c
@@ -62,10 +62,10 @@ static miPointerSpriteFuncRec VGAarbiterSpriteFuncs = {
     VGAarbiterDeviceCursorInitialize, VGAarbiterDeviceCursorCleanup
 };
 
-static int VGAarbiterKeyIndex;
-static DevPrivateKey VGAarbiterScreenKey = &VGAarbiterKeyIndex;
-static int VGAarbiterGCIndex;
-static DevPrivateKey VGAarbiterGCKey = &VGAarbiterGCIndex;
+static DevPrivateKeyRec VGAarbiterScreenKeyRec;
+#define VGAarbiterScreenKey (&VGAarbiterScreenKeyRec)
+static DevPrivateKeyRec VGAarbiterGCKeyRec;
+#define VGAarbiterGCKey (&VGAarbiterGCKeyRec)
 
 static int vga_no_arb = 0;
 void
@@ -175,9 +175,12 @@ xf86VGAarbiterWrapFunctions(void)
         pScrn = xf86Screens[pScreen->myNum];
         PointPriv = dixLookupPrivate(&pScreen->devPrivates, miPointerScreenKey);
 
-        if (!dixRequestPrivate(VGAarbiterGCKey, sizeof(VGAarbiterGCRec)))
+        if (!dixRegisterPrivateKey(&VGAarbiterGCKeyRec, PRIVATE_GC, sizeof(VGAarbiterGCRec)))
             return FALSE;
 
+	if (!dixRegisterPrivateKey(&VGAarbiterScreenKeyRec, PRIVATE_SCREEN, 0))
+	    return FALSE;
+
         if (!(pScreenPriv = malloc(sizeof(VGAarbiterScreenRec))))
             return FALSE;
 
diff --git a/hw/xfree86/common/xf86VidMode.c b/hw/xfree86/common/xf86VidMode.c
index e704f5a..1788fa1 100644
--- a/hw/xfree86/common/xf86VidMode.c
+++ b/hw/xfree86/common/xf86VidMode.c
@@ -47,7 +47,7 @@
 #include "vidmodeproc.h"
 #include "xf86cmap.h"
 
-static int VidModeKeyIndex;
+static DevPrivateKeyRec VidModeKeyRec;
 static DevPrivateKey VidModeKey;
 static int VidModeCount = 0;
 static Bool VidModeClose(int i, ScreenPtr pScreen);
@@ -67,15 +67,17 @@ VidModeExtensionInit(ScreenPtr pScreen)
 	return FALSE;
     }
 
-    VidModeKey = &VidModeKeyIndex;
+    VidModeKey = &VidModeKeyRec;
 
-    if (!dixSetPrivate(&pScreen->devPrivates, VidModeKey,
-		       calloc(sizeof(VidModeRec), 1))) {
-	DebugF("xcalloc failed\n");
+    if (!dixRegisterPrivateKey(&VidModeKeyRec, PRIVATE_SCREEN, 0))
 	return FALSE;
-    }
 
-    pVidMode = VMPTR(pScreen);
+    pVidMode = calloc(sizeof(VidModeRec), 1);
+    if (!pVidMode)
+	return FALSE;
+
+    dixSetPrivate(&pScreen->devPrivates, VidModeKey, pVidMode);
+
     pVidMode->Flags = 0;
     pVidMode->Next = NULL;
     pVidMode->CloseScreen = pScreen->CloseScreen;
diff --git a/hw/xfree86/common/xf86cmap.c b/hw/xfree86/common/xf86cmap.c
index f59ffcb..f26c22c 100644
--- a/hw/xfree86/common/xf86cmap.c
+++ b/hw/xfree86/common/xf86cmap.c
@@ -102,10 +102,11 @@ typedef struct {
   int		overscan;
 } CMapColormapRec, *CMapColormapPtr;
 
-static int CMapScreenKeyIndex;
-static DevPrivateKey CMapScreenKey;
-static int CMapColormapKeyIndex;
-static DevPrivateKey CMapColormapKey = &CMapColormapKeyIndex;
+static DevPrivateKeyRec CMapScreenKeyRec;
+#define CMapScreenKeyRegistered dixPrivateKeyRegistered(&CMapScreenKeyRec)
+#define CMapScreenKey (&CMapScreenKeyRec)
+static DevPrivateKeyRec CMapColormapKeyRec;
+#define CMapColormapKey (&CMapColormapKeyRec)
 
 static void CMapInstallColormap(ColormapPtr);
 static void CMapStoreColors(ColormapPtr, int, xColorItem *);
@@ -128,6 +129,18 @@ static void CMapReinstallMap(ColormapPtr);
 static void CMapUnwrapScreen(ScreenPtr pScreen);
 
 
+Bool xf86ColormapAllocatePrivates(ScrnInfoPtr pScrn)
+{
+    /* If we support a better colormap system, then pretend we succeeded. */
+    if (xf86_crtc_supports_gamma(pScrn))
+	return TRUE;
+    if (!dixRegisterPrivateKey(&CMapScreenKeyRec, PRIVATE_SCREEN, 0))
+	return FALSE;
+
+    if (!dixRegisterPrivateKey(&CMapColormapKeyRec, PRIVATE_COLORMAP, 0))
+	return FALSE;
+    return TRUE;
+}
 
 Bool xf86HandleColormaps(
     ScreenPtr pScreen,
@@ -151,8 +164,6 @@ Bool xf86HandleColormaps(
     if(!maxColors || !sigRGBbits || !loadPalette)
 	return FALSE;
 
-    CMapScreenKey = &CMapScreenKeyIndex;
-
     elements = 1 << sigRGBbits;
 
     if(!(gamma = malloc(elements * sizeof(LOCO))))
@@ -169,7 +180,7 @@ Bool xf86HandleColormaps(
 	return FALSE;     
     }
 
-    dixSetPrivate(&pScreen->devPrivates, CMapScreenKey, pScreenPriv);
+    dixSetPrivate(&pScreen->devPrivates, &CMapScreenKeyRec, pScreenPriv);
      
     pScreenPriv->CloseScreen = pScreen->CloseScreen;
     pScreenPriv->CreateColormap = pScreen->CreateColormap;
@@ -900,7 +911,7 @@ CMapChangeGamma(
     CMapLinkPtr pLink;
         
     /* Is this sufficient checking ? */
-    if(CMapScreenKey == NULL)
+    if(!CMapScreenKeyRegistered)
 	return BadImplementation;
 
     pScreenPriv = (CMapScreenPtr)dixLookupPrivate(&pScreen->devPrivates,
@@ -1012,7 +1023,7 @@ xf86ChangeGammaRamp(
 	}
     }
 
-    if(CMapScreenKey == NULL)
+    if(!CMapScreenKeyRegistered)
         return BadImplementation;
 
     pScreenPriv = (CMapScreenPtr)dixLookupPrivate(&pScreen->devPrivates,
@@ -1080,7 +1091,7 @@ xf86GetGammaRampSize(ScreenPtr pScreen)
 	    return crtc->gammaSize;
     }
 
-    if(CMapScreenKey == NULL) return 0;
+    if(!CMapScreenKeyRegistered) return 0;
 
     pScreenPriv = (CMapScreenPtr)dixLookupPrivate(&pScreen->devPrivates,
 						  CMapScreenKey);
@@ -1120,7 +1131,7 @@ xf86GetGammaRamp(
 	}
     }
 
-    if(CMapScreenKey == NULL) 
+    if(!CMapScreenKeyRegistered)
 	return BadImplementation;
 
     pScreenPriv = (CMapScreenPtr)dixLookupPrivate(&pScreen->devPrivates,
diff --git a/hw/xfree86/common/xf86cmap.h b/hw/xfree86/common/xf86cmap.h
index f15844e..649f078 100644
--- a/hw/xfree86/common/xf86cmap.h
+++ b/hw/xfree86/common/xf86cmap.h
@@ -45,6 +45,10 @@ extern _X_EXPORT Bool xf86HandleColormaps(
     unsigned int flags
 );
 
+extern _X_EXPORT Bool xf86ColormapAllocatePrivates(
+    ScrnInfoPtr pScrn
+);
+
 extern _X_EXPORT int
 xf86ChangeGamma(
    ScreenPtr pScreen,
diff --git a/hw/xfree86/common/xf86fbman.c b/hw/xfree86/common/xf86fbman.c
index d883ab3..e60e5c4 100644
--- a/hw/xfree86/common/xf86fbman.c
+++ b/hw/xfree86/common/xf86fbman.c
@@ -42,7 +42,7 @@
 #define DEBUG
 */
 
-static int xf86FBManagerKeyIndex;
+static DevPrivateKeyRec xf86FBManagerKeyRec;
 static DevPrivateKey xf86FBManagerKey;
 
 Bool xf86RegisterOffscreenManager(
@@ -50,7 +50,11 @@ Bool xf86RegisterOffscreenManager(
     FBManagerFuncsPtr funcs
 ){
 
-   xf86FBManagerKey = &xf86FBManagerKeyIndex;
+   xf86FBManagerKey = &xf86FBManagerKeyRec;
+
+   if (!dixRegisterPrivateKey(&xf86FBManagerKeyRec, PRIVATE_SCREEN, 0))
+       return FALSE;
+
    dixSetPrivate(&pScreen->devPrivates, xf86FBManagerKey, funcs);
 
    return TRUE;
@@ -60,8 +64,9 @@ Bool xf86RegisterOffscreenManager(
 Bool
 xf86FBManagerRunning(ScreenPtr pScreen)
 {
-    if(xf86FBManagerKey == NULL) 
+    if (xf86FBManagerKey == NULL)
 	return FALSE;
+
     if(!dixLookupPrivate(&pScreen->devPrivates, xf86FBManagerKey))
 	return FALSE;
 
@@ -270,8 +275,8 @@ xf86PurgeUnlockedOffscreenAreas(ScreenPtr pScreen)
 
 \************************************************************/ 
 
-static int xf86FBScreenKeyIndex;
-static DevPrivateKey xf86FBScreenKey = &xf86FBScreenKeyIndex;
+static DevPrivateKeyRec xf86FBScreenKeyRec;
+#define xf86FBScreenKey (&xf86FBScreenKeyRec)
 
 typedef struct _FBLink {
   FBArea area;
@@ -1321,6 +1326,9 @@ xf86InitFBManagerRegion(
    if(RegionNil(FullRegion))
 	return FALSE;
 
+   if (!dixRegisterPrivateKey(&xf86FBScreenKeyRec, PRIVATE_SCREEN, 0))
+       return FALSE;
+
    if(!xf86RegisterOffscreenManager(pScreen, &xf86FBManFuncs))
 	return FALSE;
 
diff --git a/hw/xfree86/common/xf86xv.c b/hw/xfree86/common/xf86xv.c
index 36e325f..a979dd3 100644
--- a/hw/xfree86/common/xf86xv.c
+++ b/hw/xfree86/common/xf86xv.c
@@ -110,10 +110,11 @@ static void xf86XVAdjustFrame(int index, int x, int y, int flags);
 static Bool xf86XVInitAdaptors(ScreenPtr, XF86VideoAdaptorPtr*, int);
 
 
-static int XF86XVWindowKeyIndex;
-static DevPrivateKey XF86XVWindowKey = &XF86XVWindowKeyIndex;
-static int XF86XvScreenKeyIndex;
-DevPrivateKey XF86XvScreenKey = &XF86XvScreenKeyIndex;
+static DevPrivateKeyRec XF86XVWindowKeyRec;
+#define XF86XVWindowKey (&XF86XVWindowKeyRec)
+
+DevPrivateKey XF86XvScreenKey;
+
 static unsigned long PortResource = 0;
 
 DevPrivateKey (*XvGetScreenKeyProc)(void) = NULL;
@@ -186,8 +187,8 @@ typedef struct {
    int num;
 } OffscreenImageRec;
 
-static int OffscreenPrivateKeyIndex;
-static DevPrivateKey OffscreenPrivateKey = &OffscreenPrivateKeyIndex;
+static DevPrivateKeyRec OffscreenPrivateKeyRec;
+#define OffscreenPrivateKey (&OffscreenPrivateKeyRec)
 #define GetOffscreenImage(pScreen) ((OffscreenImageRec *) dixLookupPrivate(&(pScreen)->devPrivates, OffscreenPrivateKey))
 
 Bool
@@ -198,9 +199,9 @@ xf86XVRegisterOffscreenImages(
 ){
     OffscreenImageRec *OffscreenImage;
     /* This function may be called before xf86XVScreenInit, so there's
-     * no better place than this to call dixRequestPrivate to ensure we
+     * no better place than this to call dixRegisterPrivateKey to ensure we
      * have space reserved. After the first call it is a no-op. */
-    if(!dixRequestPrivate(OffscreenPrivateKey, sizeof(OffscreenImageRec)) ||
+    if(!dixRegisterPrivateKey(OffscreenPrivateKey, PRIVATE_SCREEN, sizeof(OffscreenImageRec)) ||
        !(OffscreenImage = GetOffscreenImage(pScreen)))
         /* Every X.org driver assumes this function always succeeds, so
          * just die on allocation failure. */
@@ -251,7 +252,11 @@ xf86XVScreenInit(
 
   if(Success != (*XvScreenInitProc)(pScreen)) return FALSE;
 
+  if (!dixRegisterPrivateKey(&XF86XVWindowKeyRec, PRIVATE_WINDOW, 0))
+      return FALSE;
+
   XF86XvScreenKey = (*XvGetScreenKeyProc)();
+
   PortResource = (*XvGetRTPortProc)();
 
   pxvs = GET_XV_SCREEN(pScreen);
diff --git a/hw/xfree86/common/xf86xvmc.c b/hw/xfree86/common/xf86xvmc.c
index 99d6695..e6464a5 100644
--- a/hw/xfree86/common/xf86xvmc.c
+++ b/hw/xfree86/common/xf86xvmc.c
@@ -55,8 +55,8 @@ typedef struct {
   XvMCAdaptorPtr dixinfo;
 } xf86XvMCScreenRec, *xf86XvMCScreenPtr;
 
-static int XF86XvMCScreenKeyIndex;
-static DevPrivateKey XF86XvMCScreenKey = &XF86XvMCScreenKeyIndex;
+static DevPrivateKeyRec XF86XvMCScreenKeyRec;
+#define XF86XvMCScreenKey (&XF86XvMCScreenKeyRec)
 
 #define XF86XVMC_GET_PRIVATE(pScreen) (xf86XvMCScreenPtr) \
     dixLookupPrivate(&(pScreen)->devPrivates, XF86XvMCScreenKey)
@@ -172,6 +172,9 @@ Bool xf86XvMCScreenInit(
    if(!(pAdapt = malloc(sizeof(XvMCAdaptorRec) * num_adaptors)))
 	return FALSE;
 
+   if (!dixRegisterPrivateKey(&XF86XvMCScreenKeyRec, PRIVATE_SCREEN, 0))
+       return FALSE;
+
    if(!(pScreenPriv = malloc(sizeof(xf86XvMCScreenRec)))) {
 	free(pAdapt);
 	return FALSE;
diff --git a/hw/xfree86/dixmods/extmod/xf86dga2.c b/hw/xfree86/dixmods/extmod/xf86dga2.c
index 906f4d5..203fccf 100644
--- a/hw/xfree86/dixmods/extmod/xf86dga2.c
+++ b/hw/xfree86/dixmods/extmod/xf86dga2.c
@@ -61,10 +61,11 @@ unsigned char DGAReqCode = 0;
 int DGAErrorBase;
 int DGAEventBase;
 
-static int DGAScreenPrivateKeyIndex;
-static DevPrivateKey DGAScreenPrivateKey = &DGAScreenPrivateKeyIndex;
-static int DGAClientPrivateKeyIndex;
-static DevPrivateKey DGAClientPrivateKey = &DGAClientPrivateKeyIndex;
+static DevPrivateKeyRec DGAScreenPrivateKeyRec;
+#define DGAScreenPrivateKey (&DGAScreenPrivateKeyRec)
+#define DGAScreenPrivateKeyRegistered (DGAScreenPrivateKeyRec.initialized)
+static DevPrivateKeyRec DGAClientPrivateKeyRec;
+#define DGAClientPrivateKey (&DGAClientPrivateKeyRec)
 static int DGACallbackRefCount = 0;
 
 /* This holds the client's version information */
@@ -89,6 +90,12 @@ XFree86DGAExtensionInit(INITARGS)
 {
     ExtensionEntry* extEntry;
 
+    if (!dixRegisterPrivateKey(&DGAClientPrivateKeyRec, PRIVATE_CLIENT, 0))
+	return;
+
+    if (!dixRegisterPrivateKey(&DGAScreenPrivateKeyRec, PRIVATE_SCREEN, 0))
+	return;
+
     if ((extEntry = AddExtension(XF86DGANAME,
 				XF86DGANumberEvents,
 				XF86DGANumberErrors,
@@ -717,13 +724,13 @@ ProcXF86DGADirectVideo(ClientPtr client)
 
     if (stuff->screen > screenInfo.numScreens)
 	return BadValue;
-    owner = DGA_GETCLIENT(stuff->screen);
-
     REQUEST_SIZE_MATCH(xXF86DGADirectVideoReq);
 
     if (!DGAAvailable(stuff->screen))
 	return DGAErrorBase + XF86DGANoDirectVideoMode;
 
+    owner = DGA_GETCLIENT(stuff->screen);
+
     if (owner && owner != client)
         return DGAErrorBase + XF86DGANoDirectVideoMode;
 
diff --git a/hw/xfree86/dixmods/extmod/xf86vmode.c b/hw/xfree86/dixmods/extmod/xf86vmode.c
index 4487628..b02fdaf 100644
--- a/hw/xfree86/dixmods/extmod/xf86vmode.c
+++ b/hw/xfree86/dixmods/extmod/xf86vmode.c
@@ -51,8 +51,8 @@ from Kaleb S. KEITHLEY
 #define DEFAULT_XF86VIDMODE_VERBOSITY	3
 
 static int VidModeErrorBase;
-static int VidModeClientPrivateKeyIndex;
-static DevPrivateKey VidModeClientPrivateKey = &VidModeClientPrivateKeyIndex;
+static DevPrivateKeyRec VidModeClientPrivateKeyRec;
+#define VidModeClientPrivateKey (&VidModeClientPrivateKeyRec)
 
 /* This holds the client's version information */
 typedef struct {
@@ -141,8 +141,8 @@ typedef struct _XF86VidModeScreenPrivate {
     Bool		hasWindow;
 } XF86VidModeScreenPrivateRec, *XF86VidModeScreenPrivatePtr;
 
-static int ScreenPrivateKeyIndex;
-static DevPrivateKey ScreenPrivateKey = &ScreenPrivateKeyIndex;
+static DevPrivateKeyRec ScreenPrivateKeyRec;
+#define ScreenPrivateKey (&ScreenPrivateKeyRec)
 
 #define GetScreenPrivate(s) ((ScreenSaverScreenPrivatePtr) \
     dixLookupPrivate(&(s)->devPrivates, ScreenPrivateKey))
@@ -169,6 +169,13 @@ XFree86VidModeExtensionInit(void)
 
     DEBUG_P("XFree86VidModeExtensionInit");
 
+    if (!dixRegisterPrivateKey(&VidModeClientPrivateKeyRec, PRIVATE_CLIENT, 0))
+	return;
+#ifdef XF86VIDMODE_EVENTS
+    if (!dixRegisterPrivateKey(&ScreenPrivateKeyRec, PRIVATE_SCREEN, 0))
+	return;
+#endif
+
 #ifdef XF86VIDMODE_EVENTS
     EventType = CreateNewResourceType(XF86VidModeFreeEvents, "VidModeEvent");
 #endif
@@ -177,9 +184,6 @@ XFree86VidModeExtensionInit(void)
         pScreen = screenInfo.screens[i];
 	if (VidModeExtensionInit(pScreen))
 	    enabled = TRUE;
-#ifdef XF86VIDMODE_EVENTS
-	SetScreenPrivate (pScreen, NULL);
-#endif
     }
     /* This means that the DDX doesn't want the vidmode extension enabled */
     if (!enabled)
diff --git a/hw/xfree86/dri/dri.c b/hw/xfree86/dri/dri.c
index 63c77de..db4cd7b 100644
--- a/hw/xfree86/dri/dri.c
+++ b/hw/xfree86/dri/dri.c
@@ -74,10 +74,10 @@ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 #define PCI_BUS_NO_DOMAIN(bus) ((bus) & 0xffu)
 
 static int DRIEntPrivIndex = -1;
-static int DRIScreenPrivKeyIndex;
-static DevPrivateKey DRIScreenPrivKey = &DRIScreenPrivKeyIndex;
-static int DRIWindowPrivKeyIndex;
-static DevPrivateKey DRIWindowPrivKey = &DRIWindowPrivKeyIndex;
+static DevPrivateKeyRec DRIScreenPrivKeyRec;
+#define DRIScreenPrivKey (&DRIScreenPrivKeyRec)
+static DevPrivateKeyRec DRIWindowPrivKeyRec;
+#define DRIWindowPrivKey (&DRIWindowPrivKeyRec)
 static unsigned long DRIGeneration = 0;
 static unsigned int DRIDrawableValidationStamp = 0;
 
@@ -357,6 +357,11 @@ DRIScreenInit(ScreenPtr pScreen, DRIInfoPtr pDRIInfo, int *pDRMFD)
     if (DRIGeneration != serverGeneration)
 	DRIGeneration = serverGeneration;
 
+    if (!dixRegisterPrivateKey(&DRIScreenPrivKeyRec, PRIVATE_SCREEN, 0))
+	return FALSE;
+    if (!dixRegisterPrivateKey(&DRIWindowPrivKeyRec, PRIVATE_WINDOW, 0))
+	return FALSE;
+
     pDRIPriv = (DRIScreenPrivPtr) calloc(1, sizeof(DRIScreenPrivRec));
     if (!pDRIPriv) {
 	dixSetPrivate(&pScreen->devPrivates, DRIScreenPrivKey, NULL);
@@ -785,7 +790,7 @@ drmServerInfo DRIDRMServerInfo =  {
 Bool
 DRIExtensionInit(void)
 {
-    if (!DRIScreenPrivKey || DRIGeneration != serverGeneration) {
+    if (DRIGeneration != serverGeneration) {
 	return FALSE;
     }
 
diff --git a/hw/xfree86/dri2/dri2.c b/hw/xfree86/dri2/dri2.c
index 3c8d3a8..baa6706 100644
--- a/hw/xfree86/dri2/dri2.c
+++ b/hw/xfree86/dri2/dri2.c
@@ -51,12 +51,15 @@
 CARD8 dri2_major; /* version of DRI2 supported by DDX */
 CARD8 dri2_minor;
 
-static int           dri2ScreenPrivateKeyIndex;
-static DevPrivateKey dri2ScreenPrivateKey = &dri2ScreenPrivateKeyIndex;
-static int dri2WindowPrivateKeyIndex;
-static DevPrivateKey dri2WindowPrivateKey = &dri2WindowPrivateKeyIndex;
-static int dri2PixmapPrivateKeyIndex;
-static DevPrivateKey dri2PixmapPrivateKey = &dri2PixmapPrivateKeyIndex;
+static DevPrivateKeyRec dri2ScreenPrivateKeyRec;
+#define dri2ScreenPrivateKey (&dri2ScreenPrivateKeyRec)
+
+static DevPrivateKeyRec dri2WindowPrivateKeyRec;
+#define dri2WindowPrivateKey (&dri2WindowPrivateKeyRec)
+
+static DevPrivateKeyRec dri2PixmapPrivateKeyRec;
+#define dri2PixmapPrivateKey (&dri2PixmapPrivateKeyRec)
+
 static RESTYPE       dri2DrawableRes;
 
 typedef struct _DRI2Screen *DRI2ScreenPtr;
@@ -1025,6 +1028,15 @@ DRI2ScreenInit(ScreenPtr pScreen, DRI2InfoPtr info)
         return FALSE;
     }
 
+    if (!dixRegisterPrivateKey(&dri2ScreenPrivateKeyRec, PRIVATE_SCREEN, 0))
+	return FALSE;
+
+    if (!dixRegisterPrivateKey(&dri2WindowPrivateKeyRec, PRIVATE_WINDOW, 0))
+	return FALSE;
+
+    if (!dixRegisterPrivateKey(&dri2PixmapPrivateKeyRec, PRIVATE_PIXMAP, 0))
+	return FALSE;
+
     ds = calloc(1, sizeof *ds);
     if (!ds)
 	return FALSE;
diff --git a/hw/xfree86/exa/examodule.c b/hw/xfree86/exa/examodule.c
index 315ba4a..83f72b5 100644
--- a/hw/xfree86/exa/examodule.c
+++ b/hw/xfree86/exa/examodule.c
@@ -42,8 +42,8 @@ typedef struct _ExaXorgScreenPrivRec {
     OptionInfoPtr		 options;
 } ExaXorgScreenPrivRec, *ExaXorgScreenPrivPtr;
 
-static int exaXorgScreenPrivateKeyIndex;
-static DevPrivateKey exaXorgScreenPrivateKey = &exaXorgScreenPrivateKeyIndex;
+static DevPrivateKeyRec exaXorgScreenPrivateKeyRec;
+#define exaXorgScreenPrivateKey (&exaXorgScreenPrivateKeyRec)
 
 typedef enum {
     EXAOPT_MIGRATION_HEURISTIC,
@@ -114,6 +114,9 @@ exaDDXDriverInit(ScreenPtr pScreen)
     ScrnInfoPtr pScrn = xf86Screens[pScreen->myNum];
     ExaXorgScreenPrivPtr pScreenPriv;
 
+    if (!dixRegisterPrivateKey(&exaXorgScreenPrivateKeyRec, PRIVATE_SCREEN, 0))
+	return;
+
     pScreenPriv = calloc(1, sizeof(ExaXorgScreenPrivRec));
     if (pScreenPriv == NULL)
 	return;
diff --git a/hw/xfree86/modes/xf86RandR12.c b/hw/xfree86/modes/xf86RandR12.c
index 8d598d6..bb4d75e 100644
--- a/hw/xfree86/modes/xf86RandR12.c
+++ b/hw/xfree86/modes/xf86RandR12.c
@@ -71,7 +71,7 @@ static Bool xf86RandR12CreateScreenResources12 (ScreenPtr pScreen);
 static int xf86RandR12Generation;
 #if XORG_VERSION_CURRENT < XORG_VERSION_NUMERIC(7,0,0,0,0)
 
-static int xf86RandR12KeyIndex;
+static DevPrivateKeyRec xf86RandR12KeyRec;
 static DevPrivateKey xf86RandR12Key;
 #define XF86RANDRINFO(p) ((XF86RandRInfoPtr) \
     dixLookupPrivate(&(p)->devPrivates, xf86RandR12Key))
@@ -883,7 +883,9 @@ xf86RandR12Init (ScreenPtr pScreen)
 	xf86RandR12Generation = serverGeneration;
 
 #if XORG_VERSION_CURRENT < XORG_VERSION_NUMERIC(7,0,0,0,0)
-    xf86RandR12Key = &xf86RandR12KeyIndex;
+    xf86RandR12Key = &xf86RandR12KeyRec;
+    if (!dixRegisterPrivateKey(&xf86RandR12KeyRec, PRIVATE_SCREEN, 0))
+	return FALSE;
 #else
     xf86RandR12Index = AllocateScreenPrivateIndex();
 #endif
diff --git a/hw/xfree86/ramdac/xf86Cursor.c b/hw/xfree86/ramdac/xf86Cursor.c
index 2bbcb9c..e16b510 100644
--- a/hw/xfree86/ramdac/xf86Cursor.c
+++ b/hw/xfree86/ramdac/xf86Cursor.c
@@ -18,8 +18,7 @@
 #include "inputstr.h"
 extern InputInfo inputInfo;
 
-static int xf86CursorScreenKeyIndex;
-DevPrivateKey xf86CursorScreenKey = &xf86CursorScreenKeyIndex;
+DevPrivateKeyRec xf86CursorScreenKeyRec;
 
 /* sprite functions */
 
@@ -65,6 +64,9 @@ xf86InitCursor(
     if (!xf86InitHardwareCursor(pScreen, infoPtr))
 	return FALSE;
 
+    if (!dixRegisterPrivateKey(&xf86CursorScreenKeyRec, PRIVATE_SCREEN, 0))
+	return FALSE;
+
     ScreenPriv = calloc(1, sizeof(xf86CursorScreenRec));
     if (!ScreenPriv)
 	return FALSE;
diff --git a/hw/xfree86/ramdac/xf86CursorPriv.h b/hw/xfree86/ramdac/xf86CursorPriv.h
index 32be9c2..d22d88d 100644
--- a/hw/xfree86/ramdac/xf86CursorPriv.h
+++ b/hw/xfree86/ramdac/xf86CursorPriv.h
@@ -45,6 +45,7 @@ Bool xf86InitHardwareCursor(ScreenPtr pScreen, xf86CursorInfoPtr infoPtr);
 
 CARD32 xf86ReverseBitOrder(CARD32 data);
 
-extern _X_EXPORT DevPrivateKey xf86CursorScreenKey;
+extern _X_EXPORT DevPrivateKeyRec xf86CursorScreenKeyRec;
+#define xf86CursorScreenKey (&xf86CursorScreenKeyRec)
 
 #endif /* _XF86CURSORPRIV_H */
diff --git a/hw/xfree86/shadowfb/shadow.c b/hw/xfree86/shadowfb/shadow.c
index a0e4b9e..2066f76 100644
--- a/hw/xfree86/shadowfb/shadow.c
+++ b/hw/xfree86/shadowfb/shadow.c
@@ -84,11 +84,11 @@ typedef struct {
    GCFuncs *funcs;
 } ShadowGCRec, *ShadowGCPtr;
 
+static DevPrivateKeyRec ShadowScreenKeyRec;
+#define ShadowScreenKey (&ShadowScreenKeyRec)
 
-static int ShadowScreenKeyIndex;
-static DevPrivateKey ShadowScreenKey = &ShadowScreenKeyIndex;
-static int ShadowGCKeyIndex;
-static DevPrivateKey ShadowGCKey = &ShadowGCKeyIndex;
+static DevPrivateKeyRec ShadowGCKeyRec;
+#define ShadowGCKey (&ShadowGCKeyRec)
 
 #define GET_SCREEN_PRIVATE(pScreen) \
     (ShadowScreenPtr)dixLookupPrivate(&(pScreen)->devPrivates, ShadowScreenKey)
@@ -162,7 +162,10 @@ ShadowFBInit2 (
 
     if(!preRefreshArea && !postRefreshArea) return FALSE;
     
-    if(!dixRequestPrivate(ShadowGCKey, sizeof(ShadowGCRec)))
+    if (!dixRegisterPrivateKey(&ShadowScreenKeyRec, PRIVATE_SCREEN, 0))
+	return FALSE;
+
+    if(!dixRegisterPrivateKey(&ShadowGCKeyRec, PRIVATE_GC, sizeof(ShadowGCRec)))
 	return FALSE;
 
     if(!(pPriv = (ShadowScreenPtr)malloc(sizeof(ShadowScreenRec))))
diff --git a/hw/xfree86/xaa/xaaInit.c b/hw/xfree86/xaa/xaaInit.c
index 0ccdae5..d0a66b8 100644
--- a/hw/xfree86/xaa/xaaInit.c
+++ b/hw/xfree86/xaa/xaaInit.c
@@ -42,12 +42,12 @@ static int  XAASetDGAMode(int index, int num, DGADevicePtr devRet);
 static void XAAEnableDisableFBAccess (int index, Bool enable);
 static Bool XAAChangeWindowAttributes (WindowPtr pWin, unsigned long mask);
 
-static int XAAScreenKeyIndex;
-static DevPrivateKey XAAScreenKey = &XAAScreenKeyIndex;
-static int XAAGCKeyIndex;
-static DevPrivateKey XAAGCKey = &XAAGCKeyIndex;
-static int XAAPixmapKeyIndex;
-static DevPrivateKey XAAPixmapKey = &XAAPixmapKeyIndex;
+static DevPrivateKeyRec XAAScreenKeyRec;
+#define XAAScreenKey (&XAAScreenKeyRec)
+static DevPrivateKeyRec XAAGCKeyRec;
+#define XAAGCKey (&XAAGCKeyRec)
+static DevPrivateKeyRec XAAPixmapKeyRec;
+#define XAAPixmapKey (&XAAPixmapKeyRec)
 
 DevPrivateKey XAAGetScreenKey(void) {
     return XAAScreenKey;
@@ -106,10 +106,13 @@ XAAInit(ScreenPtr pScreen, XAAInfoRecPtr infoRec)
     if (!infoRec)
 	return TRUE;
     
-    if (!dixRequestPrivate(XAAGCKey, sizeof(XAAGCRec)))
+    if (!dixRegisterPrivateKey(&XAAGCKeyRec, PRIVATE_GC, sizeof(XAAGCRec)))
 	return FALSE;
 
-    if (!dixRequestPrivate(XAAPixmapKey, sizeof(XAAPixmapRec)))
+    if (!dixRegisterPrivateKey(&XAAPixmapKeyRec, PRIVATE_PIXMAP, sizeof(XAAPixmapRec)))
+	return FALSE;
+
+    if (!dixRegisterPrivateKey(&XAAScreenKeyRec, PRIVATE_SCREEN, 0))
 	return FALSE;
 
     if (!(pScreenPriv = malloc(sizeof(XAAScreenRec))))
diff --git a/hw/xfree86/xaa/xaaOverlayDF.c b/hw/xfree86/xaa/xaaOverlayDF.c
index 61adec6..ca22368 100644
--- a/hw/xfree86/xaa/xaaOverlayDF.c
+++ b/hw/xfree86/xaa/xaaOverlayDF.c
@@ -151,8 +151,8 @@ typedef struct {
    int (*TiledFillChooser)(GCPtr);
 } XAAOverlayRec, *XAAOverlayPtr;
 
-static int XAAOverlayKeyIndex;
-static DevPrivateKey XAAOverlayKey = &XAAOverlayKeyIndex;
+static DevPrivateKeyRec XAAOverlayKeyRec;
+#define XAAOverlayKey (&XAAOverlayKeyRec)
 
 #define GET_OVERLAY_PRIV(pScreen) \
     (XAAOverlayPtr)dixLookupPrivate(&(pScreen)->devPrivates, XAAOverlayKey)
@@ -173,6 +173,9 @@ XAAInitDualFramebufferOverlay(
     XAAInfoRecPtr infoRec = GET_XAAINFORECPTR_FROM_SCREEN(pScreen);
     XAAOverlayPtr pOverPriv;
 
+    if (!dixRegisterPrivateKey(&XAAOverlayKeyRec, PRIVATE_SCREEN, 0))
+	return FALSE;
+
     if(!(pOverPriv = malloc(sizeof(XAAOverlayRec))))
 	return FALSE;
 
diff --git a/hw/xfree86/xaa/xaaStateChange.c b/hw/xfree86/xaa/xaaStateChange.c
index 0e86e67..189441d 100644
--- a/hw/xfree86/xaa/xaaStateChange.c
+++ b/hw/xfree86/xaa/xaaStateChange.c
@@ -272,8 +272,8 @@ typedef struct _XAAStateWrapRec {
                                       int width, int height, int flags);
 } XAAStateWrapRec, *XAAStateWrapPtr;
 
-static int XAAStateKeyIndex;
-static DevPrivateKey XAAStateKey = &XAAStateKeyIndex;
+static DevPrivateKeyRec XAAStateKeyRec;
+#define XAAStateKey (&XAAStateKeyRec)
 
 /* Wrap functions start here */
 #define GET_STATEPRIV_GC(pGC)   XAAStateWrapPtr pStatePriv =\
@@ -1500,6 +1500,7 @@ XAAInitStateWrap(ScreenPtr pScreen, XAAInfoRecPtr infoRec)
    XAAStateWrapPtr pStatePriv;
    int i = 0;
    
+   if (!dixRegisterPrivateKey(&XAAStateKeyRec, PRIVATE_SCREEN, 0)) return FALSE;
    if(!(pStatePriv = malloc(sizeof(XAAStateWrapRec)))) return FALSE;
    dixSetPrivate(&pScreen->devPrivates, XAAStateKey, pStatePriv);
    pStatePriv->RestoreAccelState = infoRec->RestoreAccelState;
diff --git a/hw/xfree86/xaa/xaaWrapper.c b/hw/xfree86/xaa/xaaWrapper.c
index 2491492..e91bac0 100644
--- a/hw/xfree86/xaa/xaaWrapper.c
+++ b/hw/xfree86/xaa/xaaWrapper.c
@@ -125,10 +125,10 @@ typedef struct _xaaWrapperGCPriv {
 #define xaaWrapperGCPriv(pGC)   xaaWrapperGCPrivPtr  pGCPriv = xaaWrapperGetGCPriv(pGC)
 
 
-static int xaaWrapperScrPrivateKeyIndex;
-static DevPrivateKey xaaWrapperScrPrivateKey = &xaaWrapperScrPrivateKeyIndex;
-static int xaaWrapperGCPrivateKeyIndex;
-static DevPrivateKey xaaWrapperGCPrivateKey = &xaaWrapperGCPrivateKeyIndex;
+static DevPrivateKeyRec xaaWrapperScrPrivateKeyRec;
+#define xaaWrapperScrPrivateKey (&xaaWrapperScrPrivateKeyRec)
+static DevPrivateKeyRec xaaWrapperGCPrivateKeyRec;
+#define xaaWrapperGCPrivateKey (&xaaWrapperGCPrivateKeyRec)
 
 static Bool
 xaaWrapperCreateScreenResources(ScreenPtr pScreen)
@@ -268,7 +268,10 @@ xaaSetupWrapper(ScreenPtr pScreen, XAAInfoRecPtr infoPtr, int depth, SyncFunc *f
     xaaWrapperScrPrivPtr pScrPriv;
     PictureScreenPtr	ps = GetPictureScreenIfSet(pScreen);
 
-    if (!dixRequestPrivate(xaaWrapperGCPrivateKey, sizeof(xaaWrapperGCPrivRec)))
+    if (!dixRegisterPrivateKey(&xaaWrapperGCPrivateKeyRec, PRIVATE_GC, sizeof(xaaWrapperGCPrivRec)))
+	return FALSE;
+
+    if (!dixRegisterPrivateKey(&xaaWrapperScrPrivateKeyRec, PRIVATE_SCREEN, 0))
 	return FALSE;
 
     pScrPriv = (xaaWrapperScrPrivPtr) malloc(sizeof (xaaWrapperScrPrivRec));
diff --git a/hw/xnest/Color.c b/hw/xnest/Color.c
index b3f0fc4..6399e34 100644
--- a/hw/xnest/Color.c
+++ b/hw/xnest/Color.c
@@ -34,8 +34,8 @@ is" without express or implied warranty.
 #include "XNWindow.h"
 #include "Args.h"
 
-static int cmapScrPrivateKeyIndex;
-static DevPrivateKey cmapScrPrivateKey = &cmapScrPrivateKeyIndex;
+static DevPrivateKeyRec cmapScrPrivateKeyRec;
+#define cmapScrPrivateKey (&cmapScrPrivateKeyRec)
 
 #define GetInstalledColormap(s) ((ColormapPtr) dixLookupPrivate(&(s)->devPrivates, cmapScrPrivateKey))
 #define SetInstalledColormap(s,c) (dixSetPrivate(&(s)->devPrivates, cmapScrPrivateKey, c))
diff --git a/hw/xnest/GC.c b/hw/xnest/GC.c
index 2cd555c..2761583 100644
--- a/hw/xnest/GC.c
+++ b/hw/xnest/GC.c
@@ -35,8 +35,7 @@ is" without express or implied warranty.
 #include "XNFont.h"
 #include "Color.h"
 
-static int xnestGCPrivateKeyIndex;
-DevPrivateKey xnestGCPrivateKey = &xnestGCPrivateKeyIndex;
+DevPrivateKeyRec xnestGCPrivateKeyRec;
 
 static GCFuncs xnestFuncs = {
   xnestValidateGC,
diff --git a/hw/xnest/Pixmap.c b/hw/xnest/Pixmap.c
index bf06480..a0968b9 100644
--- a/hw/xnest/Pixmap.c
+++ b/hw/xnest/Pixmap.c
@@ -33,8 +33,7 @@ is" without express or implied warranty.
 #include "Screen.h"
 #include "XNPixmap.h"
 
-static int xnestPixmapPrivateKeyIndex;
-DevPrivateKey xnestPixmapPrivateKey = &xnestPixmapPrivateKeyIndex;
+DevPrivateKeyRec xnestPixmapPrivateKeyRec;
 
 PixmapPtr
 xnestCreatePixmap(ScreenPtr pScreen, int width, int height, int depth,
@@ -42,7 +41,7 @@ xnestCreatePixmap(ScreenPtr pScreen, int width, int height, int depth,
 {
   PixmapPtr pPixmap;
 
-  pPixmap = AllocatePixmap(pScreen, sizeof(xnestPrivPixmap));
+  pPixmap = AllocatePixmap(pScreen, 0);
   if (!pPixmap)
     return NullPixmap;
   pPixmap->drawable.type = DRAWABLE_PIXMAP;
@@ -59,8 +58,6 @@ xnestCreatePixmap(ScreenPtr pScreen, int width, int height, int depth,
   pPixmap->refcnt = 1;
   pPixmap->devKind = PixmapBytePad(width, depth);
   pPixmap->usage_hint = usage_hint;
-  dixSetPrivate(&pPixmap->devPrivates, xnestPixmapPrivateKey,
-		(char *)pPixmap + pScreen->totalPixmapSize);
   if (width && height)
       xnestPixmapPriv(pPixmap)->pixmap = 
 	  XCreatePixmap(xnestDisplay, 
@@ -78,8 +75,7 @@ xnestDestroyPixmap(PixmapPtr pPixmap)
   if(--pPixmap->refcnt)
     return TRUE;
   XFreePixmap(xnestDisplay, xnestPixmap(pPixmap));
-  dixFreePrivates(pPixmap->devPrivates);
-  free(pPixmap);
+  FreePixmap(pPixmap);
   return TRUE;
 }
 
diff --git a/hw/xnest/Screen.c b/hw/xnest/Screen.c
index 0a05ac8..957fe4c 100644
--- a/hw/xnest/Screen.c
+++ b/hw/xnest/Screen.c
@@ -45,8 +45,7 @@ is" without express or implied warranty.
 
 Window xnestDefaultWindows[MAXSCREENS];
 Window xnestScreenSaverWindows[MAXSCREENS];
-static int xnestCursorScreenKeyIndex;
-DevPrivateKey xnestCursorScreenKey = &xnestCursorScreenKeyIndex;
+DevPrivateKeyRec xnestCursorScreenKeyRec;
 
 ScreenPtr
 xnestScreen(Window window)
@@ -146,10 +145,14 @@ xnestOpenScreen(int index, ScreenPtr pScreen, int argc, char *argv[])
   int rootDepth;
   miPointerScreenPtr PointPriv;
 
-  if (!dixRequestPrivate(xnestWindowPrivateKey, sizeof(xnestPrivWin)))
-      return False;
-  if (!dixRequestPrivate(xnestGCPrivateKey, sizeof(xnestPrivGC)))
-    return False;
+  if (!dixRegisterPrivateKey(&xnestWindowPrivateKeyRec, PRIVATE_WINDOW, sizeof(xnestPrivWin)))
+      return FALSE;
+  if (!dixRegisterPrivateKey(&xnestGCPrivateKeyRec, PRIVATE_GC, sizeof(xnestPrivGC)))
+    return FALSE;
+  if (!dixRegisterPrivateKey(&xnestPixmapPrivateKeyRec, PRIVATE_PIXMAP, sizeof (xnestPrivPixmap)))
+      return FALSE;
+  if (!dixRegisterPrivateKey(&xnestCursorScreenKeyRec, PRIVATE_SCREEN, 0))
+      return FALSE;
 
   visuals = (VisualPtr)malloc(xnestNumVisuals * sizeof(VisualRec));
   numVisuals = 0;
diff --git a/hw/xnest/Window.c b/hw/xnest/Window.c
index fab2f39..659b135 100644
--- a/hw/xnest/Window.c
+++ b/hw/xnest/Window.c
@@ -39,8 +39,7 @@ is" without express or implied warranty.
 #include "Events.h"
 #include "Args.h"
 
-static int xnestWindowPrivateKeyIndex;
-DevPrivateKey xnestWindowPrivateKey = &xnestWindowPrivateKeyIndex;
+DevPrivateKeyRec xnestWindowPrivateKeyRec;
 
 static int
 xnestFindWindowMatch(WindowPtr pWin, pointer ptr)
diff --git a/hw/xnest/XNCursor.h b/hw/xnest/XNCursor.h
index ab2c3b1..d3b18bd 100644
--- a/hw/xnest/XNCursor.h
+++ b/hw/xnest/XNCursor.h
@@ -21,7 +21,8 @@ typedef struct {
     miPointerSpriteFuncPtr spriteFuncs;
 } xnestCursorFuncRec, *xnestCursorFuncPtr;
 
-extern DevPrivateKey xnestCursorScreenKey;
+extern DevPrivateKeyRec xnestCursorScreenKeyRec;
+#define xnestCursorScreenKey (&xnestCursorScreenKeyRec)
 extern xnestCursorFuncRec xnestCursorFuncs;
 
 typedef struct {
diff --git a/hw/xnest/XNGC.h b/hw/xnest/XNGC.h
index 19535fe..9f10456 100644
--- a/hw/xnest/XNGC.h
+++ b/hw/xnest/XNGC.h
@@ -22,7 +22,8 @@ typedef struct {
   int nClipRects;
 } xnestPrivGC;
 
-extern DevPrivateKey xnestGCPrivateKey;
+extern DevPrivateKeyRec xnestGCPrivateKeyRec;
+#define xnestGCPrivateKey (&xnestGCPrivateKeyRec)
 
 #define xnestGCPriv(pGC) ((xnestPrivGC *) \
     dixLookupPrivate(&(pGC)->devPrivates, xnestGCPrivateKey))
diff --git a/hw/xnest/XNPixmap.h b/hw/xnest/XNPixmap.h
index 6148275..aa671ed 100644
--- a/hw/xnest/XNPixmap.h
+++ b/hw/xnest/XNPixmap.h
@@ -15,7 +15,8 @@ is" without express or implied warranty.
 #ifndef XNESTPIXMAP_H
 #define XNESTPIXMAP_H
 
-extern DevPrivateKey xnestPixmapPrivateKey;
+extern DevPrivateKeyRec xnestPixmapPrivateKeyRec;
+#define xnestPixmapPrivateKey (&xnestPixmapPrivateKeyRec)
 
 typedef struct {
   Pixmap pixmap;
diff --git a/hw/xnest/XNWindow.h b/hw/xnest/XNWindow.h
index 92a1902..f4d8fc7 100644
--- a/hw/xnest/XNWindow.h
+++ b/hw/xnest/XNWindow.h
@@ -33,7 +33,8 @@ typedef struct {
   Window window;
 } xnestWindowMatch;
 
-extern DevPrivateKey xnestWindowPrivateKey;
+extern DevPrivateKeyRec xnestWindowPrivateKeyRec;
+#define xnestWindowPrivateKey (&xnestWindowPrivateKeyRec)
 
 #define xnestWindowPriv(pWin) ((xnestPrivWin *) \
     dixLookupPrivate(&(pWin)->devPrivates, xnestWindowPrivateKey))
diff --git a/hw/xquartz/darwin.c b/hw/xquartz/darwin.c
index 1d99d36..a99c0f1 100644
--- a/hw/xquartz/darwin.c
+++ b/hw/xquartz/darwin.c
@@ -84,8 +84,7 @@ FILE *debug_log_fp = NULL;
  * X server shared global variables
  */
 int                     darwinScreensFound = 0;
-static int              darwinScreenKeyIndex;
-DevPrivateKey           darwinScreenKey = &darwinScreenKeyIndex;
+DevPrivateKeyRec        darwinScreenKeyRec;
 io_connect_t            darwinParamConnect = 0;
 int                     darwinEventReadFD = -1;
 int                     darwinEventWriteFD = -1;
@@ -185,6 +184,9 @@ static Bool DarwinScreenInit(int index, ScreenPtr pScreen, int argc, char **argv
     Bool        ret;
     DarwinFramebufferPtr dfb;
 
+    if (!dixRegisterPrivateKey(&darwinScreenKeyRec, PRIVATE_SCREEN, 0))
+	return FALSE;
+
     // reset index of found screens for each server generation
     if (index == 0) {
         foundIndex = 0;
diff --git a/hw/xquartz/darwin.h b/hw/xquartz/darwin.h
index 8fa48bf..350eade 100644
--- a/hw/xquartz/darwin.h
+++ b/hw/xquartz/darwin.h
@@ -50,7 +50,8 @@ void xf86SetRootClip (ScreenPtr pScreen, int enable);
 /*
  * Global variables from darwin.c
  */
-extern DevPrivateKey    darwinScreenKey; // index into pScreen.devPrivates
+extern DevPrivateKeyRec darwinScreenKeyRec;
+#define darwinScreenKey (&darwinScreenKeyRec)
 extern int              darwinScreensFound;
 extern io_connect_t     darwinParamConnect;
 extern int              darwinEventReadFD;
diff --git a/hw/xquartz/quartz.c b/hw/xquartz/quartz.c
index bb37e4a..2828c57 100644
--- a/hw/xquartz/quartz.c
+++ b/hw/xquartz/quartz.c
@@ -73,8 +73,7 @@ int                     quartzUseAGL = 1;
 int                     quartzEnableKeyEquivalents = 1;
 int                     quartzServerVisible = FALSE;
 int                     quartzServerQuitting = FALSE;
-static int              quartzScreenKeyIndex;
-DevPrivateKey           quartzScreenKey = &quartzScreenKeyIndex;
+DevPrivateKeyRec        quartzScreenKeyRec;
 int                     aquaMenuBarHeight = 0;
 QuartzModeProcsPtr      quartzProcs = NULL;
 const char             *quartzOpenGLBundle = NULL;
@@ -167,6 +166,9 @@ void QuartzInitOutput(
         FatalError("Could not register block and wakeup handlers.");
     }
 
+    if (!dixRegisterPrivateKey(&quartzScreenKeyRec, PRIVATE_SCREEN, 0))
+	FatalError("Failed to alloc quartz screen private.\n");
+
 #if defined(RANDR) && !defined(FAKE_RANDR)
     if(!QuartzRandRInit(pScreen))
         FatalError("Failed to init RandR extension.\n");
diff --git a/hw/xquartz/quartzCommon.h b/hw/xquartz/quartzCommon.h
index 8ab70f2..c038ed0 100644
--- a/hw/xquartz/quartzCommon.h
+++ b/hw/xquartz/quartzCommon.h
@@ -65,7 +65,8 @@ extern int              quartzOptionSendsAlt;
 // Other shared data
 extern int              quartzServerVisible;
 extern int              quartzServerQuitting;
-extern DevPrivateKey    quartzScreenKey;
+extern DevPrivateKeyRec quartzScreenKeyRec;
+#define quartzScreenKey (&quartzScreenKeyRec)
 extern int              aquaMenuBarHeight;
 
 // Name of GLX bundle for native OpenGL
diff --git a/hw/xquartz/xpr/dri.c b/hw/xquartz/xpr/dri.c
index d9b2e03..72a7ecf 100644
--- a/hw/xquartz/xpr/dri.c
+++ b/hw/xquartz/xpr/dri.c
@@ -74,14 +74,14 @@ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 
 #include <AvailabilityMacros.h>
 
-static int DRIScreenPrivKeyIndex;
-static DevPrivateKey DRIScreenPrivKey = &DRIScreenPrivKeyIndex;
-static int DRIWindowPrivKeyIndex;
-static DevPrivateKey DRIWindowPrivKey = &DRIWindowPrivKeyIndex;
-static int DRIPixmapPrivKeyIndex;
-static DevPrivateKey DRIPixmapPrivKey = &DRIPixmapPrivKeyIndex;
-static int DRIPixmapBufferPrivKeyIndex;
-static DevPrivateKey DRIPixmapBufferPrivKey = &DRIPixmapBufferPrivKeyIndex;
+static DevPrivateKeyRec DRIScreenPrivKeyRec;
+#define DRIScreenPrivKey (&DRIScreenPrivKeyRec)
+static DevPrivateKeyRec DRIWindowPrivKeyRec;
+#define DRIWindowPrivKey (&DRIWindowPrivKeyRec)
+static DevPrivateKeyRec DRIPixmapPrivKeyRec;
+#define DRIPixmapPrivKey (&DRIPixmapPrivKeyRec)
+static DevPrivateKeyRec DRIPixmapBufferPrivKeyRec;
+#define DRIPixmapBufferPrivKey (&DRIPixmapBufferPrivKeyRec)
 
 static RESTYPE DRIDrawablePrivResType;
 
@@ -205,6 +205,15 @@ DRIScreenInit(ScreenPtr pScreen)
     DRIScreenPrivPtr    pDRIPriv;
     int                 i;
 
+    if (!dixRegisterPrivateKey(&DRIScreenPrivateKeyRec, PRIVATE_SCREEN, 0))
+	return FALSE:
+    if (!dixRegisterPrivateKey(&DRIWindowPrivateKeyRec, PRIVATE_WINDOW, 0))
+	return FALSE:
+    if (!dixRegisterPrivateKey(&DRIPixmapPrivateKeyRec, PRIVATE_PIXMAP, 0))
+	return FALSE:
+    if (!dixRegisterPrivateKey(&DRIPixmapBufferPrivateKeyRec, PRIVATE_PIXMAP, 0))
+	return FALSE:
+
     pDRIPriv = (DRIScreenPrivPtr) calloc(1, sizeof(DRIScreenPrivRec));
     if (!pDRIPriv) {
 	dixSetPrivate(&pScreen->devPrivates, DRIScreenPrivKey, NULL);
diff --git a/hw/xquartz/xpr/driWrap.c b/hw/xquartz/xpr/driWrap.c
index f1a5c83..efbae3c 100644
--- a/hw/xquartz/xpr/driWrap.c
+++ b/hw/xquartz/xpr/driWrap.c
@@ -55,11 +55,11 @@ typedef struct {
     DevUnion devPrivate;
 } DRISavedDrawableState;
 
-static int driGCKeyIndex;
-static DevPrivateKey driGCKey = &driGCKeyIndex;
+static DevPrivateKeyRec driGCKeyRec;
+#define driGCKey (&driGCKeyRec)
 
-static int driWrapScreenKeyIndex;
-static DevPrivateKey driWrapScreenKey = &driWrapScreenKeyIndex;
+static DevPrivateKeyRec driWrapScreenKeyRec;
+#define driWrapScreenKey (&driWrapScreenKeyRec)
 
 static GCOps driGCOps;
 
@@ -527,10 +527,10 @@ Bool
 DRIWrapInit(ScreenPtr pScreen) {
     DRIWrapScreenRec *pScreenPriv;
 
-    if(!dixRequestPrivate(driGCKey, sizeof(DRIGCRec)))
+    if(!dixRegisterPrivateKey(&driGCKeyRec, PRIVATE_GC, sizeof(DRIGCRec)))
 	return FALSE;
 
-    if(!dixRequestPrivate(driWrapScreenKey, sizeof(DRIWrapScreenRec)))
+    if(!dixRegisterPrivateKey(&driWrapScreenKeyRec, PRIVATE_WINDOW, sizeof(DRIWrapScreenRec)))
 	return FALSE;
     
     pScreenPriv = malloc(sizeof(*pScreenPriv));
diff --git a/hw/xquartz/xpr/xprCursor.c b/hw/xquartz/xpr/xprCursor.c
index fdb8563..c268c2c 100644
--- a/hw/xquartz/xpr/xprCursor.c
+++ b/hw/xquartz/xpr/xprCursor.c
@@ -57,13 +57,12 @@ typedef struct {
     miPointerSpriteFuncPtr  spriteFuncs;
 } QuartzCursorScreenRec, *QuartzCursorScreenPtr;
 
-static int darwinCursorScreenKeyIndex;
-static DevPrivateKey darwinCursorScreenKey = &darwinCursorScreenKeyIndex;
+static DevPrivateKeyRec darwinCursorScreenKeyRec;
+#define darwinCursorScreenKey (&darwinCursorScreenKey)
 
 #define CURSOR_PRIV(pScreen) ((QuartzCursorScreenPtr) \
     dixLookupPrivate(&pScreen->devPrivates, darwinCursorScreenKey))
 
-
 static Bool
 load_cursor(CursorPtr src, int screen)
 {
@@ -360,6 +359,9 @@ QuartzInitCursor(ScreenPtr pScreen)
     if (!miDCInitialize(pScreen, &quartzScreenFuncsRec))
         return FALSE;
 
+    if (!dixRegisterPrivate(&darwinCursorScreenKeyRec, PRIVATE_SCREEN, 0))
+	return FALSE;
+
     ScreenPriv = calloc(1, sizeof(QuartzCursorScreenRec));
     if (ScreenPriv == NULL)
         return FALSE;
diff --git a/hw/xwin/win.h b/hw/xwin/win.h
index 49b73d7..05913d7 100644
--- a/hw/xwin/win.h
+++ b/hw/xwin/win.h
@@ -628,11 +628,17 @@ extern DWORD			g_dwEvents;
 #ifdef HAS_DEVWINDOWS
 extern int			g_fdMessageQueue;
 #endif
-extern DevPrivateKey		g_iScreenPrivateKey;
-extern DevPrivateKey		g_iCmapPrivateKey;
-extern DevPrivateKey		g_iGCPrivateKey;
-extern DevPrivateKey		g_iPixmapPrivateKey;
-extern DevPrivateKey		g_iWindowPrivateKey;
+extern DevPrivateKeyRec		g_iScreenPrivateKeyRec;
+#define g_iScreenPrivateKey  	(&g_iScreenPrivateKeyRec)
+extern DevPrivateKeyRec		g_iCmapPrivateKeyRec;
+#define g_iCmapPrivateKeyRec 	(&g_iCmapPrivateKeyRec)
+extern DevPrivateKeyRec		g_iGCPrivateKeyRec;
+#define g_iGCPrivateKey 	(&g_iGCPrivateKeyRec)
+extern DevPrivateKeyRec		g_iPixmapPrivateKeyRec;
+#define g_iPixmapPrivateKey 	(&g_iPixmapPrivateKeyRec)
+extern DevPrivateKeyRec		g_iWindowPrivateKeyRec;
+#define g_iWindowPrivateKey 	(&g_iWindowPrivateKeyRec)
+
 extern unsigned long		g_ulServerGeneration;
 extern DWORD			g_dwEnginesSupported;
 extern HINSTANCE		g_hInstance;
diff --git a/hw/xwin/winallpriv.c b/hw/xwin/winallpriv.c
index 21ccd9b..6ecbff6 100644
--- a/hw/xwin/winallpriv.c
+++ b/hw/xwin/winallpriv.c
@@ -78,21 +78,21 @@ winAllocatePrivates (ScreenPtr pScreen)
   winSetScreenPriv (pScreen, pScreenPriv);
 
   /* Reserve GC memory for our privates */
-  if (!dixRequestPrivate(g_iGCPrivateKey, sizeof (winPrivGCRec)))
+  if (!dixRequestPrivateKey(g_iGCPrivateKey, PRIVATE_GC, sizeof (winPrivGCRec)))
     {
       ErrorF ("winAllocatePrivates - AllocateGCPrivate () failed\n");
       return FALSE;
     }
 
   /* Reserve Pixmap memory for our privates */
-  if (!dixRequestPrivate(g_iPixmapPrivateKey, sizeof (winPrivPixmapRec)))
+  if (!dixRequestPrivateKey(g_iPixmapPrivateKey, PRIVATE_PIXMAP, sizeof (winPrivPixmapRec)))
     {
       ErrorF ("winAllocatePrivates - AllocatePixmapPrivates () failed\n");
       return FALSE;
     }
 
   /* Reserve Window memory for our privates */
-  if (!dixRequestPrivate(g_iWindowPrivateKey, sizeof (winPrivWinRec)))
+  if (!dixRequestPrivateKey(g_iWindowPrivateKey, PRIVATE_WINDOW, sizeof (winPrivWinRec)))
     {
       ErrorF ("winAllocatePrivates () - AllocateWindowPrivates () failed\n");
        return FALSE;
diff --git a/hw/xwin/winglobals.c b/hw/xwin/winglobals.c
index 2ef8a36..2cc53f2 100644
--- a/hw/xwin/winglobals.c
+++ b/hw/xwin/winglobals.c
@@ -45,16 +45,11 @@ winScreenInfo * g_ScreenInfo = 0;
 #ifdef HAS_DEVWINDOWS
 int		g_fdMessageQueue = WIN_FD_INVALID;
 #endif
-static int	g_iScreenPrivateKeyIndex;
-DevPrivateKey	g_iScreenPrivateKey = &g_iScreenPrivateKeyIndex;
-static int	g_iCmapPrivateKeyIndex;
-DevPrivateKey	g_iCmapPrivateKey = &g_iCmapPrivateKeyIndex;
-static int	g_iGCPrivateKeyIndex;
-DevPrivateKey	g_iGCPrivateKey = &g_iGCPrivateKeyIndex;
-static int	g_iPixmapPrivateKeyIndex;
-DevPrivateKey	g_iPixmapPrivateKey = &g_iPixmapPrivateKeyIndex;
-static int	g_iWindowPrivateKeyIndex;
-DevPrivateKey	g_iWindowPrivateKey = &g_iWindowPrivateKeyIndex;
+DevPrivateKeyRec g_iScreenPrivateKeyRec;
+DevPrivateKeyRec g_iCmapPrivateKeyRec;
+DevPrivateKeyRec g_iGCPrivateKeyRec;
+DevPrivateKeyRec g_iPixmapPrivateKeyRec;
+DevPrivateKeyRec g_iWindowPrivateKeyRec;
 unsigned long	g_ulServerGeneration = 0;
 DWORD		g_dwEnginesSupported = 0;
 HINSTANCE	g_hInstance = 0;
@@ -131,6 +126,13 @@ Atom			g_atomLastOwnedSelection = None;
 void
 winInitializeGlobals (void)
 {
+  if (!dixRegisterPrivateKey(&g_iScreenPrivateKeyRec, PRIVATE_SCREEN, 0) ||
+      !dixRegisterPrivateKey(&g_iCmapPrivateKeyRec, PRIVATE_COLORMAP, 0) ||
+      !dixRegisterPrivateKey(&g_iGCPrivateKeyRec, PRIVATE_GC, 0) ||
+      !dixRegisterPrivateKey(&g_iPixmapPrivateKeyRec, PRIVATE_PIXMAP, 0) ||
+      !dixRegisterPrivateKey(&g_iWindowPrivateKeyRec, PRIVATE_WINDOW, 0)) {
+      FatalError("cannot register private key");
+  }
   g_dwCurrentThreadID = GetCurrentThreadId ();
   g_hwndKeyboardFocus = NULL;
 #ifdef XWIN_CLIPBOARD
diff --git a/include/cursor.h b/include/cursor.h
index dadedfd..59978d4 100644
--- a/include/cursor.h
+++ b/include/cursor.h
@@ -51,6 +51,7 @@ SOFTWARE.
 #include "misc.h"
 #include "screenint.h"
 #include "window.h"
+#include "privates.h"
 
 #define NullCursor ((CursorPtr)NULL)
 
@@ -62,7 +63,7 @@ struct _DeviceIntRec;
 typedef struct _Cursor *CursorPtr;
 typedef struct _CursorMetric *CursorMetricPtr;
 
-extern _X_EXPORT int cursorScreenDevPriv[MAXSCREENS];
+extern _X_EXPORT DevPrivateKeyRec cursorScreenDevPriv[MAXSCREENS];
 #define CursorScreenKey(pScreen) (cursorScreenDevPriv + (pScreen)->myNum)
 
 extern _X_EXPORT CursorPtr rootCursor;
diff --git a/include/cursorstr.h b/include/cursorstr.h
index 3ff56e2..6a4d0db 100644
--- a/include/cursorstr.h
+++ b/include/cursorstr.h
@@ -70,6 +70,8 @@ typedef struct _CursorBits {
 #endif
 } CursorBits, *CursorBitsPtr;
 
+#define CURSOR_BITS_SIZE (sizeof(CursorBits) + dixPrivatesSize(PRIVATE_CURSOR_BITS))
+
 typedef struct _Cursor {
     CursorBitsPtr bits;
     unsigned short foreRed, foreGreen, foreBlue; /* device-independent color */
@@ -83,6 +85,8 @@ typedef struct _Cursor {
 #endif
 } CursorRec;
 
+#define CURSOR_REC_SIZE (sizeof(CursorRec) + dixPrivatesSize(PRIVATE_CURSOR))
+
 typedef struct _CursorMetric {
     unsigned short width, height, xhot, yhot;
 } CursorMetricRec;
diff --git a/include/pixmap.h b/include/pixmap.h
index 55a9c81..5cf42d1 100644
--- a/include/pixmap.h
+++ b/include/pixmap.h
@@ -115,4 +115,7 @@ extern _X_EXPORT PixmapPtr AllocatePixmap(
     ScreenPtr /*pScreen*/,
     int /*pixDataSize*/);
 
+extern _X_EXPORT void FreePixmap(
+    PixmapPtr /*pPixmap*/);
+
 #endif /* PIXMAP_H */
diff --git a/include/privates.h b/include/privates.h
index 72f4d40..9412fd6 100644
--- a/include/privates.h
+++ b/include/privates.h
@@ -12,66 +12,109 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 #ifndef PRIVATES_H
 #define PRIVATES_H 1
 
-#include "dix.h"
-#include "resource.h"
+#include <X11/Xdefs.h>
+#include <X11/Xosdefs.h>
+#include <X11/Xfuncproto.h>
+#include "misc.h"
 
 /*****************************************************************
  * STUFF FOR PRIVATES
  *****************************************************************/
 
-typedef int *DevPrivateKey;
-struct _Private;
-typedef struct _Private PrivateRec;
+typedef struct _Private PrivateRec, *PrivatePtr;
+
+typedef enum {
+    /* XSELinux uses the same private keys for numerous objects */
+    PRIVATE_XSELINUX,
+
+    /* Otherwise, you get a private in just the requested structure
+     */
+    /* These can have objects created before all of the keys are registered */
+    PRIVATE_SCREEN,
+    PRIVATE_EXTENSION,
+    PRIVATE_COLORMAP,
+
+    /* These cannot have any objects before all relevant keys are registered */
+    PRIVATE_DEVICE,
+    PRIVATE_CLIENT,
+    PRIVATE_PROPERTY,
+    PRIVATE_SELECTION,
+    PRIVATE_WINDOW,
+    PRIVATE_PIXMAP,
+    PRIVATE_GC,
+    PRIVATE_CURSOR,
+    PRIVATE_CURSOR_BITS,
+
+    /* extension privates */
+    PRIVATE_DBE_WINDOW,
+    PRIVATE_DAMAGE,
+    PRIVATE_GLYPH,
+    PRIVATE_GLYPHSET,
+    PRIVATE_PICTURE,
+
+    /* last private type */
+    PRIVATE_LAST,
+} DevPrivateType;
+
+typedef struct _DevPrivateKeyRec {
+    int			key;
+} DevPrivateKeyRec, *DevPrivateKey;
 
 /*
- * Request pre-allocated private space for your driver/module.  This function
- * increases the amount of space allocated automatically when dixLookupPrivate
- * is called on a PrivateRec that does not yet have a value associated with
- * 'key'.
- *
- * This function will only increase the reserved size: if a size was previously
- * requested, then dixRequestPrivate causes later calls to dixLookupPrivate to
- * allocate the maximum of the old size and 'size'.  Requested sizes are reset
- * to 0 by dixResetPrivates, which is called before each server generation.
- *
- * If dixRequestPrivate is not called with a nonzero size for 'key', then the
- * module responsible for 'key' must manage the associated pointer itself with
- * dixSetPrivate.
- *
- * dixRequestPrivate returns FALSE if it cannot store the requested size.
+ * Let drivers know how to initialize private keys
  */
-extern _X_EXPORT int
-dixRequestPrivate(const DevPrivateKey key, unsigned size);
+
+#define HAS_DEVPRIVATEKEYREC		1
+#define HAS_DIXREGISTERPRIVATEKEY	1
 
 /*
- * Allocates space for an association of 'key' with a value in 'privates'.
+ * Register a new private index for the private type.
  *
- * If a nonzero size was requested with dixRequestPrivate, then
- * dixAllocatePrivate also allocates the requested amount of memory and
- * associates the pointer to that memory with 'key' in 'privates'.  The
- * allocated memory is initialized to zero.  This memory can only be freed by
- * dixFreePrivates.
+ * This initializes the specified key and optionally requests pre-allocated
+ * private space for your driver/module. If you request no extra space, you
+ * may set and get a single pointer value using this private key. Otherwise,
+ * you can get the address of the extra space and store whatever data you like
+ * there.
  *
- * If dixRequestPrivate was never called with a nonzero size, then
- * dixAllocatePrivate associates NULL with 'key' in 'privates'.
+ * You may call dixRegisterPrivate more than once on the same key, but the
+ * size and type must match or the server will abort.
  *
- * dixAllocatePrivate returns a pointer to the value associated with 'key' in
- * 'privates', unless a memory allocation fails, in which case it returns NULL.
+ * dixRegisterPrivateIndex returns FALSE if it fails to allocate memory
+ * during its operation.
  */
-extern _X_EXPORT pointer *
-dixAllocatePrivate(PrivateRec **privates, const DevPrivateKey key);
+extern _X_EXPORT Bool
+dixRegisterPrivateKey(DevPrivateKey key, DevPrivateType type, unsigned size);
+
+/*
+ * Check whether a private key has been registered
+ */
+static inline Bool
+dixPrivateKeyRegistered(DevPrivateKey key)
+{
+    return key->key != 0;
+}
 
 /*
- * Look up a private pointer.
+ * Associate 'val' with 'key' in 'privates' so that later calls to
+ * dixLookupPrivate(privates, key) will return 'val'.
  *
- * If no value is currently associated with 'key' in 'privates', then
- * dixLookupPrivate calls dixAllocatePrivate and returns the resulting
- * associated value.
+ * dixSetPrivate returns FALSE if a memory allocation fails.
+ */
+extern _X_EXPORT int
+dixSetPrivate(PrivatePtr *privates, const DevPrivateKey key, pointer val);
+
+#include "dix.h"
+#include "resource.h"
+
+/*
+ * Lookup a pointer to the private record.
  *
- * dixLookupPrivate returns NULL if a memory allocation fails.
+ * For privates with defined storage, return the address of the
+ * storage. For privates without defined storage, return the pointer
+ * contents
  */
 extern _X_EXPORT pointer
-dixLookupPrivate(PrivateRec **privates, const DevPrivateKey key);
+dixLookupPrivate(PrivatePtr *privates, const DevPrivateKey key);
 
 /*
  * Look up the address of a private pointer.  If 'key' is not associated with a
@@ -82,29 +125,72 @@ dixLookupPrivate(PrivateRec **privates, const DevPrivateKey key);
  * 'privates' and a memory allocation fails.
  */
 extern _X_EXPORT pointer *
-dixLookupPrivateAddr(PrivateRec **privates, const DevPrivateKey key);
+dixLookupPrivateAddr(PrivatePtr *privates, const DevPrivateKey key);
 
 /*
- * Associate 'val' with 'key' in 'privates' so that later calls to
- * dixLookupPrivate(privates, key) will return 'val'.
- *
- * dixSetPrivate returns FALSE if a memory allocation fails.
+ * Allocates private data separately from main object (clients and colormaps)
  */
-extern _X_EXPORT int
-dixSetPrivate(PrivateRec **privates, const DevPrivateKey key, pointer val);
+static inline Bool
+dixAllocatePrivates(PrivatePtr *privates, DevPrivateType type) { *privates = NULL; return TRUE; }
 
 /*
- * Unassociates all keys from 'privates' and frees all private data automatically
- * allocated via dixRequestPrivate.
+ * Frees separately allocated private data (screens and clients)
  */
 extern _X_EXPORT void
-dixFreePrivates(PrivateRec *privates);
+dixFreePrivates(PrivatePtr privates, DevPrivateType type);
+
+/*
+ * Initialize privates by zeroing them
+ */
+static inline void
+_dixInitPrivates(PrivatePtr *privates, void *addr, DevPrivateType type) { *privates = NULL; }
+
+#define dixInitPrivates(o, v, type) _dixInitPrivates(&(o)->devPrivates, (v), type);
+
+/*
+ * Clean up privates
+ */
+static inline void
+_dixFiniPrivates(PrivatePtr privates, DevPrivateType type) { dixFreePrivates(privates, type); }
+
+#define dixFiniPrivates(o,t)	_dixFiniPrivates((o)->devPrivates,t)
+
+/*
+ * Allocates private data at object creation time. Required
+ * for all objects other than ScreenRecs.
+ */
+static inline void *
+_dixAllocateObjectWithPrivates(unsigned size, unsigned clear, unsigned offset, DevPrivateType type) {
+    return calloc(size, 1);
+}
+
+#define dixAllocateObjectWithPrivates(t, type) (t *) _dixAllocateObjectWithPrivates(sizeof(t), sizeof(t), offsetof(t, devPrivates), type)
+
+static inline void
+_dixFreeObjectWithPrivates(void *object, PrivatePtr privates, DevPrivateType type) {
+    dixFreePrivates(privates, type);
+    free(object);
+}
+
+#define dixFreeObjectWithPrivates(o,t) _dixFreeObjectWithPrivates(o, (o)->devPrivates, t)
+
+/*
+ * Return size of privates for the specified type
+ */
+static inline int
+dixPrivatesSize(DevPrivateType type) { return 0; }
+
+/*
+ * Dump out private stats to ErrorF
+ */
+void
+dixPrivateUsage(void);
 
 /*
  * Resets the privates subsystem.  dixResetPrivates is called from the main loop
  * before each server generation.  This function must only be called by main().
  */
-extern _X_EXPORT int
+extern _X_EXPORT void
 dixResetPrivates(void);
 
 /*
@@ -121,6 +207,6 @@ dixLookupPrivateOffset(RESTYPE type);
  * Convenience macro for adding an offset to an object pointer
  * when making a call to one of the devPrivates functions
  */
-#define DEVPRIV_AT(ptr, offset) ((PrivateRec **)((char *)ptr + offset))
+#define DEVPRIV_AT(ptr, offset) ((PrivatePtr *)((char *)(ptr) + offset))
 
 #endif /* PRIVATES_H */
diff --git a/include/xkbsrv.h b/include/xkbsrv.h
index b3a8319..7c92f64 100644
--- a/include/xkbsrv.h
+++ b/include/xkbsrv.h
@@ -275,7 +275,9 @@ typedef struct
 	device->public.realInputProc = oldprocs->realInputProc; \
 	device->unwrapProc = oldprocs->unwrapProc;
 
-extern DevPrivateKey xkbDevicePrivateKey;
+extern _X_EXPORT DevPrivateKeyRec xkbDevicePrivateKeyRec;
+#define xkbDevicePrivateKey (&xkbDevicePrivateKeyRec)
+
 #define XKBDEVICEINFO(dev) ((xkbDeviceInfoPtr)dixLookupPrivate(&(dev)->devPrivates, xkbDevicePrivateKey))
 
 extern void xkbUnwrapProc(DeviceIntPtr, DeviceHandleProc, pointer);
diff --git a/mi/micmap.c b/mi/micmap.c
index dac700d..3effe6c 100644
--- a/mi/micmap.c
+++ b/mi/micmap.c
@@ -40,8 +40,7 @@
 #include "globals.h"
 #include "micmap.h"
 
-static int micmapScrPrivateKeyIndex;
-DevPrivateKey micmapScrPrivateKey = &micmapScrPrivateKeyIndex;
+DevPrivateKeyRec micmapScrPrivateKeyRec;
 
 int
 miListInstalledColormaps(ScreenPtr pScreen, Colormap *pmaps)
@@ -300,6 +299,9 @@ miCreateDefColormap(ScreenPtr pScreen)
     ColormapPtr	cmap;
     int alloctype;
     
+    if (!dixRegisterPrivateKey(&micmapScrPrivateKeyRec, PRIVATE_SCREEN, 0))
+	return FALSE;
+
     for (pVisual = pScreen->visuals;
 	 pVisual->vid != pScreen->rootVisual;
 	 pVisual++)
diff --git a/mi/micmap.h b/mi/micmap.h
index 8ad94b9..c67710c 100644
--- a/mi/micmap.h
+++ b/mi/micmap.h
@@ -9,8 +9,8 @@
 #define SetInstalledmiColormap(s,c) \
     (dixSetPrivate(&(s)->devPrivates, micmapScrPrivateKey, c))
 
-extern _X_EXPORT DevPrivateKey micmapScrPrivateKey;
-
+extern _X_EXPORT DevPrivateKeyRec micmapScrPrivateKeyRec;
+#define micmapScrPrivateKey (&micmapScrPrivateKeyRec)
 
 typedef Bool (* miInitVisualsProcPtr)(VisualPtr *, DepthPtr *, int *, int *,
 					int *, VisualID *, unsigned long, int,
diff --git a/mi/midispcur.c b/mi/midispcur.c
index a8aef92..b412477 100644
--- a/mi/midispcur.c
+++ b/mi/midispcur.c
@@ -54,18 +54,18 @@ in this Software without prior written authorization from The Open Group.
 # include "inputstr.h"
 
 /* per-screen private data */
-static int miDCScreenKeyIndex;
-static DevPrivateKey miDCScreenKey = &miDCScreenKeyIndex;
+static DevPrivateKeyRec miDCScreenKeyRec;
+#define miDCScreenKey (&miDCScreenKeyRec)
 
 static Bool	miDCCloseScreen(int index, ScreenPtr pScreen);
 
 /* per bits per-screen private data */
-static int miDCCursorBitsKeyIndex[MAXSCREENS];
-#define miDCCursorBitsKey(screen)	(&miDCCursorBitsKeyIndex[(screen)->myNum])
+static DevPrivateKeyRec miDCCursorBitsKeyRec[MAXSCREENS];
+#define miDCCursorBitsKey(screen)	(&miDCCursorBitsKeyRec[(screen)->myNum])
 
 /* per device per-screen private data */
-static int miDCDeviceKeyIndex[MAXSCREENS];
-#define miDCDeviceKey(screen)		(&miDCDeviceKeyIndex[(screen)->myNum])
+static DevPrivateKeyRec miDCDeviceKeyRec[MAXSCREENS];
+#define miDCDeviceKey(screen)		(&miDCDeviceKeyRec[(screen)->myNum])
 
 typedef struct {
     GCPtr	    pSourceGC, pMaskGC;
@@ -103,11 +103,19 @@ miDCInitialize (ScreenPtr pScreen, miPointerScreenFuncPtr screenFuncs)
 {
     miDCScreenPtr   pScreenPriv;
 
+    if (!dixRegisterPrivateKey(&miDCScreenKeyRec, PRIVATE_SCREEN, 0))
+	return FALSE;
+
+    if (!dixRegisterPrivateKey(&miDCDeviceKeyRec[pScreen->myNum], PRIVATE_DEVICE, 0))
+	return FALSE;
+
+    if (!dixRegisterPrivateKey(&miDCCursorBitsKeyRec[pScreen->myNum], PRIVATE_CURSOR_BITS, 0))
+	return FALSE;
+
     pScreenPriv = malloc(sizeof (miDCScreenRec));
     if (!pScreenPriv)
 	return FALSE;
 
-
     pScreenPriv->CloseScreen = pScreen->CloseScreen;
     pScreen->CloseScreen = miDCCloseScreen;
 
diff --git a/mi/miline.h b/mi/miline.h
index b5f706d..ae9d113 100644
--- a/mi/miline.h
+++ b/mi/miline.h
@@ -148,7 +148,8 @@ extern _X_EXPORT void miSetZeroLineBias(
 #define IsXDecreasingOctant(_octant)	((_octant) & XDECREASING)
 #define IsYDecreasingOctant(_octant)	((_octant) & YDECREASING)
 
-extern _X_EXPORT DevPrivateKey miZeroLineScreenKey;
+extern _X_EXPORT DevPrivateKeyRec miZeroLineScreenKeyRec;
+#define miZeroLineScreenKey (&miZeroLineScreenKeyRec)
 
 extern _X_EXPORT int miZeroClipLine(
     int /*xmin*/,
diff --git a/mi/mioverlay.c b/mi/mioverlay.c
index d8eb642..aa00e23 100644
--- a/mi/mioverlay.c
+++ b/mi/mioverlay.c
@@ -55,10 +55,10 @@ typedef struct {
    Bool				copyUnderlay;
 } miOverlayScreenRec, *miOverlayScreenPtr;
 
-static int miOverlayWindowKeyKeyIndex;
-static DevPrivateKey miOverlayWindowKey = &miOverlayWindowKeyKeyIndex;
-static int miOverlayScreenKeyIndex;
-static DevPrivateKey miOverlayScreenKey = &miOverlayScreenKeyIndex;
+static DevPrivateKeyRec miOverlayWindowKeyRec;
+#define miOverlayWindowKey (&miOverlayWindowKeyRec)
+static DevPrivateKeyRec miOverlayScreenKeyRec;
+#define miOverlayScreenKey (&miOverlayScreenKeyRec)
 
 static void RebuildTree(WindowPtr);
 static Bool HasUnderlayChildren(WindowPtr);
@@ -113,7 +113,10 @@ miInitOverlay(
 
     if(!inOverlayFunc || !transFunc) return FALSE;
 
-    if(!dixRequestPrivate(miOverlayWindowKey, sizeof(miOverlayWindowRec)))
+    if(!dixRegisterPrivateKey(&miOverlayWindowKeyRec, PRIVATE_WINDOW, sizeof(miOverlayWindowRec)))
+	return FALSE;
+
+    if(!dixRegisterPrivateKey(&miOverlayScreenKeyRec, PRIVATE_SCREEN, 0))
 	return FALSE;
 
     if(!(pScreenPriv = malloc(sizeof(miOverlayScreenRec))))
diff --git a/mi/mipointer.c b/mi/mipointer.c
index 296c57f..33bb40b 100644
--- a/mi/mipointer.c
+++ b/mi/mipointer.c
@@ -40,15 +40,13 @@ in this Software without prior written authorization from The Open Group.
 # include   "dixstruct.h"
 # include   "inputstr.h"
 
-static int miPointerScreenKeyIndex;
-DevPrivateKey miPointerScreenKey = &miPointerScreenKeyIndex;
+DevPrivateKeyRec miPointerScreenKeyRec;
 
 #define GetScreenPrivate(s) ((miPointerScreenPtr) \
     dixLookupPrivate(&(s)->devPrivates, miPointerScreenKey))
 #define SetupScreen(s)	miPointerScreenPtr  pScreenPriv = GetScreenPrivate(s)
 
-static int miPointerPrivKeyIndex;
-static DevPrivateKey miPointerPrivKey = &miPointerPrivKeyIndex;
+DevPrivateKeyRec miPointerPrivKeyRec;
 
 #define MIPOINTER(dev) \
     ((!IsMaster(dev) && !dev->u.master) ? \
@@ -86,6 +84,12 @@ miPointerInitialize (ScreenPtr                  pScreen,
 {
     miPointerScreenPtr	pScreenPriv;
 
+    if (!dixRegisterPrivateKey(&miPointerScreenKeyRec, PRIVATE_SCREEN, 0))
+	return FALSE;
+
+    if (!dixRegisterPrivateKey(&miPointerPrivKeyRec, PRIVATE_DEVICE, 0))
+	return FALSE;
+
     pScreenPriv = malloc(sizeof (miPointerScreenRec));
     if (!pScreenPriv)
 	return FALSE;
diff --git a/mi/mipointer.h b/mi/mipointer.h
index 22575ea..de58c07 100644
--- a/mi/mipointer.h
+++ b/mi/mipointer.h
@@ -139,6 +139,10 @@ extern _X_EXPORT void miPointerSetPosition(
 extern _X_EXPORT void miPointerUpdateSprite(
     DeviceIntPtr pDev);
 
-extern _X_EXPORT DevPrivateKey miPointerScreenKey;
+extern _X_EXPORT DevPrivateKeyRec miPointerPrivKeyRec;
+#define miPointerPrivKey (&miPointerPrivKeyRec)
+
+extern _X_EXPORT DevPrivateKeyRec miPointerScreenKeyRec;
+#define miPointerScreenKey (&miPointerScreenKeyRec)
 
 #endif /* MIPOINTER_H */
diff --git a/mi/miscrinit.c b/mi/miscrinit.c
index 1b88ecb..ea2a0c1 100644
--- a/mi/miscrinit.c
+++ b/mi/miscrinit.c
@@ -292,21 +292,25 @@ miScreenInit(
     return miScreenDevPrivateInit(pScreen, width, pbits);
 }
 
-static int privateKeyIndex;
-static DevPrivateKey privateKey = &privateKeyIndex;
+static DevPrivateKeyRec privateKeyRec;
+#define privateKey (&privateKeyRec)
 
 DevPrivateKey
 miAllocateGCPrivateIndex(void)
 {
+    if (!dixRegisterPrivateKey(&privateKeyRec, PRIVATE_GC, 0))
+	return NULL;
     return privateKey;
 }
 
-static int miZeroLineScreenKeyIndex;
-DevPrivateKey miZeroLineScreenKey = &miZeroLineScreenKeyIndex;
+DevPrivateKeyRec miZeroLineScreenKeyRec;
 
 void
 miSetZeroLineBias(ScreenPtr pScreen, unsigned int bias)
 {
+    if (!dixRegisterPrivateKey(&miZeroLineScreenKeyRec, PRIVATE_SCREEN, 0))
+	return;
+
     dixSetPrivate(&pScreen->devPrivates, miZeroLineScreenKey, 
 					(unsigned long *)(unsigned long)bias);
 }
diff --git a/mi/misprite.c b/mi/misprite.c
index b2cf5f0..38a6b93 100644
--- a/mi/misprite.c
+++ b/mi/misprite.c
@@ -182,10 +182,10 @@ miSpriteIsDown(miCursorInfoPtr pDevCursor)
  * screen wrappers
  */
 
-static int miSpriteScreenKeyIndex;
-static DevPrivateKey miSpriteScreenKey = &miSpriteScreenKeyIndex;
-static int miSpriteDevPrivatesKeyIndex;
-static DevPrivateKey miSpriteDevPrivatesKey = &miSpriteDevPrivatesKeyIndex;
+static DevPrivateKeyRec miSpriteScreenKeyRec;
+#define miSpriteScreenKey (&miSpriteScreenKeyRec)
+static DevPrivateKeyRec miSpriteDevPrivatesKeyRec;
+#define miSpriteDevPrivatesKey (&miSpriteDevPrivatesKeyRec)
 
 static Bool	    miSpriteCloseScreen(int i, ScreenPtr pScreen);
 static void	    miSpriteGetImage(DrawablePtr pDrawable, int sx, int sy,
@@ -293,6 +293,12 @@ miSpriteInitialize (ScreenPtr               pScreen,
     if (!DamageSetup (pScreen))
 	return FALSE;
 
+    if (!dixRegisterPrivateKey(&miSpriteScreenKeyRec, PRIVATE_SCREEN, 0))
+	return FALSE;
+
+    if (!dixRegisterPrivateKey(&miSpriteDevPrivatesKeyRec, PRIVATE_DEVICE, 0))
+	return FALSE;
+
     pScreenPriv = malloc(sizeof (miSpriteScreenRec));
     if (!pScreenPriv)
 	return FALSE;
diff --git a/miext/cw/cw.c b/miext/cw/cw.c
index 563831a..7623de7 100644
--- a/miext/cw/cw.c
+++ b/miext/cw/cw.c
@@ -43,14 +43,11 @@
 #define CW_ASSERT(x) do {} while (0)
 #endif
 
-static int cwGCKeyIndex;
-DevPrivateKey cwGCKey = &cwGCKeyIndex;
-static int cwScreenKeyIndex;
-DevPrivateKey cwScreenKey = &cwScreenKeyIndex;
-static int cwWindowKeyIndex;
-DevPrivateKey cwWindowKey = &cwWindowKeyIndex;
-static int cwPictureKeyIndex;
-DevPrivateKey cwPictureKey = &cwPictureKeyIndex;
+DevPrivateKeyRec cwGCKeyRec;
+DevPrivateKeyRec cwScreenKeyRec;
+DevPrivateKeyRec cwWindowKeyRec;
+DevPrivateKeyRec cwPictureKeyRec;
+
 extern GCOps cwGCOps;
 
 static Bool
@@ -477,7 +474,16 @@ miInitializeCompositeWrapper(ScreenPtr pScreen)
     cwScreenPtr pScreenPriv;
     Bool has_render = GetPictureScreenIfSet(pScreen) != NULL;
 
-    if (!dixRequestPrivate(cwGCKey, sizeof(cwGCRec)))
+    if (!dixRegisterPrivateKey(&cwScreenKeyRec, PRIVATE_SCREEN, 0))
+	return;
+
+    if (!dixRegisterPrivateKey(&cwGCKeyRec, PRIVATE_GC, sizeof(cwGCRec)))
+	return;
+
+    if (!dixRegisterPrivateKey(&cwWindowKeyRec, PRIVATE_WINDOW, 0))
+	return;
+
+    if (!dixRegisterPrivateKey(&cwPictureKeyRec, PRIVATE_PICTURE, 0))
 	return;
 
     pScreenPriv = malloc(sizeof(cwScreenRec));
diff --git a/miext/cw/cw.h b/miext/cw/cw.h
index 79051df..31eb9e5 100644
--- a/miext/cw/cw.h
+++ b/miext/cw/cw.h
@@ -44,7 +44,8 @@ typedef struct {
     GCFuncs	    *wrapFuncs;	    /* wrapped funcs */
 } cwGCRec, *cwGCPtr;
 
-extern _X_EXPORT DevPrivateKey cwGCKey;
+extern _X_EXPORT DevPrivateKeyRec cwGCKeyRec;
+#define cwGCKey (&cwGCKeyRec)
 
 #define getCwGC(pGC) ((cwGCPtr)dixLookupPrivate(&(pGC)->devPrivates, cwGCKey))
 #define setCwGC(pGC,p) dixSetPrivate(&(pGC)->devPrivates, cwGCKey, p)
@@ -60,12 +61,15 @@ typedef struct {
     unsigned long   stateChanges;
 } cwPictureRec, *cwPicturePtr;
 
+extern _X_EXPORT DevPrivateKeyRec cwPictureKeyRec;
+#define cwPictureKey (&cwPictureKeyRec)
+
 #define getCwPicture(pPicture) (pPicture->pDrawable ? \
     (cwPicturePtr)dixLookupPrivate(&(pPicture)->devPrivates, cwPictureKey) : 0)
 #define setCwPicture(pPicture,p) dixSetPrivate(&(pPicture)->devPrivates, cwPictureKey, p)
 
-extern _X_EXPORT DevPrivateKey cwPictureKey;
-extern _X_EXPORT DevPrivateKey cwWindowKey;
+extern _X_EXPORT DevPrivateKeyRec cwWindowKeyRec;
+#define cwWindowKey (&cwWindowKeyRec)
 
 #define cwWindowPrivate(pWin) dixLookupPrivate(&(pWin)->devPrivates, cwWindowKey)
 #define getCwPixmap(pWindow)	    ((PixmapPtr) cwWindowPrivate(pWindow))
@@ -108,7 +112,8 @@ typedef struct {
     RasterizeTrapezoidProcPtr	RasterizeTrapezoid;
 } cwScreenRec, *cwScreenPtr;
 
-extern _X_EXPORT DevPrivateKey cwScreenKey;
+extern _X_EXPORT DevPrivateKeyRec cwScreenKeyRec;
+#define cwScreenKey (&cwScreenKeyRec)
 
 #define getCwScreen(pScreen) ((cwScreenPtr)dixLookupPrivate(&(pScreen)->devPrivates, cwScreenKey))
 #define setCwScreen(pScreen,p) dixSetPrivate(&(pScreen)->devPrivates, cwScreenKey, p)
diff --git a/miext/damage/damage.c b/miext/damage/damage.c
index 935b1c0..e8a1191 100644
--- a/miext/damage/damage.c
+++ b/miext/damage/damage.c
@@ -70,14 +70,14 @@
 
 #define pixmapDamage(pPixmap)		damagePixPriv(pPixmap)
 
-static int damageScrPrivateKeyIndex;
-static DevPrivateKey damageScrPrivateKey = &damageScrPrivateKeyIndex;
-static int damagePixPrivateKeyIndex;
-static DevPrivateKey damagePixPrivateKey = &damagePixPrivateKeyIndex;
-static int damageGCPrivateKeyIndex;
-static DevPrivateKey damageGCPrivateKey = &damageGCPrivateKeyIndex;
-static int damageWinPrivateKeyIndex;
-static DevPrivateKey damageWinPrivateKey = &damageWinPrivateKeyIndex;
+static DevPrivateKeyRec damageScrPrivateKeyRec;
+#define damageScrPrivateKey (&damageScrPrivateKeyRec)
+static DevPrivateKeyRec damagePixPrivateKeyRec;
+#define damagePixPrivateKey (&damagePixPrivateKeyRec)
+static DevPrivateKeyRec damageGCPrivateKeyRec;
+#define damageGCPrivateKey (&damageGCPrivateKeyRec)
+static DevPrivateKeyRec damageWinPrivateKeyRec;
+#define damageWinPrivateKey (&damageWinPrivateKeyRec)
 
 static DamagePtr *
 getDrawableDamageRef (DrawablePtr pDrawable)
@@ -1884,10 +1884,19 @@ DamageSetup (ScreenPtr pScreen)
 	miDamageCreate, miDamageRegister, miDamageUnregister, miDamageDestroy
     };
 
+    if (!dixRegisterPrivateKey(&damageScrPrivateKeyRec, PRIVATE_SCREEN, 0))
+	return FALSE;
+
     if (dixLookupPrivate(&pScreen->devPrivates, damageScrPrivateKey))
 	return TRUE;
 
-    if (!dixRequestPrivate(damageGCPrivateKey, sizeof(DamageGCPrivRec)))
+    if (!dixRegisterPrivateKey(&damageGCPrivateKeyRec, PRIVATE_GC, sizeof(DamageGCPrivRec)))
+	return FALSE;
+
+    if (!dixRegisterPrivateKey(&damagePixPrivateKeyRec, PRIVATE_PICTURE, 0))
+	return FALSE;
+
+    if (!dixRegisterPrivateKey(&damageWinPrivateKeyRec, PRIVATE_WINDOW, 0))
 	return FALSE;
 
     pScrPriv = malloc(sizeof (DamageScrPrivRec));
@@ -1926,7 +1935,7 @@ DamageCreate (DamageReportFunc  damageReport,
     damageScrPriv(pScreen);
     DamagePtr	pDamage;
 
-    pDamage = malloc(sizeof (DamageRec));
+    pDamage = dixAllocateObjectWithPrivates(DamageRec, PRIVATE_DAMAGE);
     if (!pDamage)
 	return 0;
     pDamage->pNext = 0;
@@ -1946,7 +1955,6 @@ DamageCreate (DamageReportFunc  damageReport,
     pDamage->damageDestroy = damageDestroy;
     pDamage->damageMarker = NULL;
     pDamage->pScreen = pScreen;
-    pDamage->devPrivates = NULL;
 
     (*pScrPriv->funcs.Create) (pDamage);
 
@@ -2050,11 +2058,9 @@ DamageDestroy (DamagePtr    pDamage)
     if (pDamage->damageDestroy)
 	(*pDamage->damageDestroy) (pDamage, pDamage->closure);
     (*pScrPriv->funcs.Destroy) (pDamage);
-    dixFreePrivates(pDamage->devPrivates);
-    pDamage->devPrivates = NULL;
     RegionUninit(&pDamage->damage);
     RegionUninit(&pDamage->pendingDamage);
-    free(pDamage);
+    dixFreeObjectWithPrivates(pDamage, PRIVATE_DAMAGE);
 }
 
 Bool
diff --git a/miext/rootless/rootlessCommon.h b/miext/rootless/rootlessCommon.h
index 8a4b813..6faf1fe 100644
--- a/miext/rootless/rootlessCommon.h
+++ b/miext/rootless/rootlessCommon.h
@@ -54,10 +54,17 @@
 
 
 // Global variables
-extern DevPrivateKey rootlessGCPrivateKey;
-extern DevPrivateKey rootlessScreenPrivateKey;
-extern DevPrivateKey rootlessWindowPrivateKey;
-extern DevPrivateKey rootlessWindowOldPixmapPrivateKey;
+extern DevPrivateKeyRec rootlessGCPrivateKeyRec;
+#define rootlessGCPrivateKey (&rootlessGCPrivateKeyRec)
+
+extern DevPrivateKeyRec rootlessScreenPrivateKeyRec;
+#define rootlessScreenPrivateKey (&rootlessScreenPrivateKeyRec)
+
+extern DevPrivateKeyRec rootlessWindowPrivateKeyRec;
+#define rootlessWindowPrivateKey (&rootlessWindowPrivateKeyRec)
+
+extern DevPrivateKeyRec rootlessWindowOldPixmapPrivateKeyRec;
+#define rootlessWindowOldPixmapPrivateKey (&rootlessWindowOldPixmapPrivateKeyRec)
 
 
 // RootlessGCRec: private per-gc data
diff --git a/miext/rootless/rootlessScreen.c b/miext/rootless/rootlessScreen.c
index 24dcfe8..43b9cbb 100644
--- a/miext/rootless/rootlessScreen.c
+++ b/miext/rootless/rootlessScreen.c
@@ -62,15 +62,10 @@ extern int RootlessMiValidateTree(WindowPtr pRoot, WindowPtr pChild,
 extern Bool RootlessCreateGC(GCPtr pGC);
 
 // Initialize globals
-static int rootlessGCPrivateKeyIndex;
-DevPrivateKey rootlessGCPrivateKey = &rootlessGCPrivateKeyIndex;
-static int rootlessScreenPrivateKeyIndex;
-DevPrivateKey rootlessScreenPrivateKey = &rootlessScreenPrivateKeyIndex;
-static int rootlessWindowPrivateKeyIndex;
-DevPrivateKey rootlessWindowPrivateKey = &rootlessWindowPrivateKeyIndex;
-static int rootlessWindowOldPixmapPrivateKeyIndex;
-DevPrivateKey rootlessWindowOldPixmapPrivateKey = &rootlessWindowOldPixmapPrivateKeyIndex;
-
+DevPrivateKeyRec rootlessGCPrivateKeyRec;
+DevPrivateKeyRec rootlessScreenPrivateKeyRec;
+DevPrivateKeyRec rootlessWindowPrivateKeyRec;
+DevPrivateKeyRec rootlessWindowOldPixmapPrivateKeyRec;
 
 /*
  * RootlessUpdateScreenPixmap
@@ -637,8 +632,13 @@ RootlessAllocatePrivates(ScreenPtr pScreen)
 {
     RootlessScreenRec *s;
 
-    // no allocation needed for screen privates
-    if (!dixRequestPrivate(rootlessGCPrivateKey, sizeof(RootlessGCRec)))
+    if (!dixRegisterPrivateKey(&rootlessGCPrivateKeyRec, PRIVATE_GC, sizeof(RootlessGCRec)))
+        return FALSE;
+    if (!dixRegisterPrivateKey(&rootlessScreenPrivateKeyRec, PRIVATE_SCREEN, 0))
+        return FALSE;
+    if (!dixRegisterPrivateKey(&rootlessWindowPrivateKeyRec, PRIVATE_WINDOW, 0))
+        return FALSE;
+    if (!dixRegisterPrivateKey(&rootlessWindowOldPixmapPrivateKeyRec, PRIVATE_WINDOW, 0))
         return FALSE;
 
     s = malloc(sizeof(RootlessScreenRec));
diff --git a/miext/shadow/shadow.c b/miext/shadow/shadow.c
index 893014b..111f46a 100644
--- a/miext/shadow/shadow.c
+++ b/miext/shadow/shadow.c
@@ -36,8 +36,8 @@
 #include    "gcstruct.h"
 #include    "shadow.h"
 
-static int shadowScrPrivateKeyIndex;
-DevPrivateKey shadowScrPrivateKey = &shadowScrPrivateKeyIndex;
+static DevPrivateKeyRec shadowScrPrivateKeyRec;
+#define shadowScrPrivateKey (&shadowScrPrivateKeyRec)
 
 #define wrap(priv, real, mem) {\
     priv->mem = real->mem; \
@@ -233,6 +233,9 @@ shadowInit(ScreenPtr pScreen, ShadowUpdateProc update, ShadowWindowProc window)
 {
     PixmapPtr pPixmap;
     
+    if (!dixRegisterPrivateKey(&shadowScrPrivateKeyRec, PRIVATE_SCREEN, 0))
+	return FALSE;
+
     pPixmap = pScreen->CreatePixmap(pScreen, pScreen->width, pScreen->height,
 				    pScreen->rootDepth, 0);
     if (!pPixmap)
diff --git a/randr/randr.c b/randr/randr.c
index ffb34d6..f52a46a 100644
--- a/randr/randr.c
+++ b/randr/randr.c
@@ -54,11 +54,9 @@ static int SProcRRDispatch (ClientPtr pClient);
 int	RREventBase;
 int	RRErrorBase;
 RESTYPE RRClientType, RREventType; /* resource types for event masks */
-static int RRClientPrivateKeyIndex;
-DevPrivateKey RRClientPrivateKey = &RRClientPrivateKeyIndex;
+DevPrivateKeyRec RRClientPrivateKeyRec;
 
-static int rrPrivKeyIndex;
-DevPrivateKey rrPrivKey = &rrPrivKeyIndex;
+DevPrivateKeyRec rrPrivKeyRec;
 
 static void
 RRClientCallback (CallbackListPtr	*list,
@@ -215,6 +213,9 @@ Bool RRInit (void)
 	    return FALSE;
 	RRGeneration = serverGeneration;
     }
+    if (!dixRegisterPrivateKey(&rrPrivKeyRec, PRIVATE_SCREEN, 0))
+	return FALSE;
+
     return TRUE;
 }
 
@@ -329,9 +330,9 @@ RRExtensionInit (void)
 
     if (RRNScreens == 0) return;
 
-    if (!dixRequestPrivate(RRClientPrivateKey,
-				sizeof (RRClientRec) +
-				screenInfo.numScreens * sizeof (RRTimesRec)))
+    if (!dixRegisterPrivateKey(&RRClientPrivateKeyRec, PRIVATE_CLIENT,
+			       sizeof (RRClientRec) +
+			       screenInfo.numScreens * sizeof (RRTimesRec)))
 	return;
     if (!AddCallback (&ClientStateCallback, RRClientCallback, 0))
 	return;
diff --git a/randr/randrstr.h b/randr/randrstr.h
index a18c834..aad126f 100644
--- a/randr/randrstr.h
+++ b/randr/randrstr.h
@@ -299,7 +299,8 @@ typedef struct _rrScrPriv {
 #endif
 } rrScrPrivRec, *rrScrPrivPtr;
 
-extern _X_EXPORT DevPrivateKey rrPrivKey;
+extern _X_EXPORT DevPrivateKeyRec rrPrivKeyRec;
+#define rrPrivKey (&rrPrivKeyRec)
 
 #define rrGetScrPriv(pScr)  ((rrScrPrivPtr)dixLookupPrivate(&(pScr)->devPrivates, rrPrivKey))
 #define rrScrPriv(pScr)	rrScrPrivPtr    pScrPriv = rrGetScrPriv(pScr)
@@ -335,7 +336,8 @@ typedef struct _RRClient {
 } RRClientRec, *RRClientPtr;
 
 extern _X_EXPORT RESTYPE RRClientType, RREventType; /* resource types for event masks */
-extern _X_EXPORT DevPrivateKey RRClientPrivateKey;
+extern _X_EXPORT DevPrivateKeyRec RRClientPrivateKeyRec;
+#define RRClientPrivateKey (&RRClientPrivateKeyRec)
 extern _X_EXPORT RESTYPE RRCrtcType, RRModeType, RROutputType;
 
 #define VERIFY_RR_OUTPUT(id, ptr, a)\
diff --git a/record/record.c b/record/record.c
index 46231c9..82d5f9f 100644
--- a/record/record.c
+++ b/record/record.c
@@ -167,8 +167,8 @@ typedef struct {
     ProcFunctionPtr recordVector[256]; 
 } RecordClientPrivateRec, *RecordClientPrivatePtr;
 
-static int RecordClientPrivateKeyIndex;
-static DevPrivateKey RecordClientPrivateKey = &RecordClientPrivateKeyIndex;
+static DevPrivateKeyRec RecordClientPrivateKeyRec;
+#define RecordClientPrivateKey (&RecordClientPrivateKeyRec)
 
 /*  RecordClientPrivatePtr RecordClientPrivate(ClientPtr)
  *  gets the client private of the given client.  Syntactic sugar.
diff --git a/render/animcur.c b/render/animcur.c
index ad126fb..2160f50 100644
--- a/render/animcur.c
+++ b/render/animcur.c
@@ -76,11 +76,11 @@ static CursorBits   animCursorBits = {
     empty, empty, 2, 1, 1, 0, 0, 1
 };
 
-static int AnimCurScreenPrivateKeyIndex;
-static DevPrivateKey AnimCurScreenPrivateKey = &AnimCurScreenPrivateKeyIndex;
+static DevPrivateKeyRec AnimCurScreenPrivateKeyRec;
+#define AnimCurScreenPrivateKey (&AnimCurScreenPrivateKeyRec)
 
 #define IsAnimCur(c)	    ((c) && ((c)->bits == &animCursorBits))
-#define GetAnimCur(c)	    ((AnimCurPtr) ((c) + 1))
+#define GetAnimCur(c)	    ((AnimCurPtr) ((((char *)(c) + CURSOR_REC_SIZE))))
 #define GetAnimCurScreen(s) ((AnimCurScreenPtr)dixLookupPrivate(&(s)->devPrivates, AnimCurScreenPrivateKey))
 #define SetAnimCurScreen(s,p) dixSetPrivate(&(s)->devPrivates, AnimCurScreenPrivateKey, p)
 
@@ -322,6 +322,9 @@ AnimCurInit (ScreenPtr pScreen)
 {
     AnimCurScreenPtr    as;
 
+    if (!dixRegisterPrivateKey(&AnimCurScreenPrivateKeyRec, PRIVATE_SCREEN, 0))
+	return FALSE;
+
     as = (AnimCurScreenPtr) malloc(sizeof (AnimCurScreenRec));
     if (!as)
 	return FALSE;
@@ -354,11 +357,12 @@ AnimCursorCreate (CursorPtr *cursors, CARD32 *deltas, int ncursor, CursorPtr *pp
 	if (IsAnimCur (cursors[i]))
 	    return BadMatch;
 	
-    pCursor = (CursorPtr) malloc(sizeof (CursorRec) +
-				  sizeof (AnimCurRec) +
-				  ncursor * sizeof (AnimCurElt));
+    pCursor = (CursorPtr) calloc(CURSOR_REC_SIZE +
+				 sizeof (AnimCurRec) +
+				 ncursor * sizeof (AnimCurElt), 1);
     if (!pCursor)
 	return BadAlloc;
+    dixInitPrivates(pCursor, pCursor + 1, PRIVATE_CURSOR);
     pCursor->bits = &animCursorBits;
     pCursor->refcnt = 1;
     
@@ -371,13 +375,12 @@ AnimCursorCreate (CursorPtr *cursors, CARD32 *deltas, int ncursor, CursorPtr *pp
     pCursor->backBlue = cursors[0]->backBlue;
 
     pCursor->id = cid;
-    pCursor->devPrivates = NULL;
 
     /* security creation/labeling check */
     rc = XaceHook(XACE_RESOURCE_ACCESS, client, cid, RT_CURSOR, pCursor,
 		  RT_NONE, NULL, DixCreateAccess);
     if (rc != Success) {
-	dixFreePrivates(pCursor->devPrivates);
+	dixFiniPrivates(pCursor, PRIVATE_CURSOR);
 	free(pCursor);
 	return rc;
     }
diff --git a/render/glyph.c b/render/glyph.c
index e5b8f86..948a20a 100644
--- a/render/glyph.c
+++ b/render/glyph.c
@@ -84,19 +84,13 @@ static const CARD8	glyphDepths[GlyphFormatNum] = { 1, 4, 8, 16, 32 };
 
 static GlyphHashRec	globalGlyphs[GlyphFormatNum];
 
-static void
-FreeGlyphPrivates (GlyphPtr glyph)
-{
-    dixFreePrivates(glyph->devPrivates);
-    glyph->devPrivates = NULL;
-}
-
 void
 GlyphUninit (ScreenPtr pScreen)
 {
     PictureScreenPtr ps = GetPictureScreen (pScreen);
     GlyphPtr	     glyph;
     int		     fdepth, i;
+    int		     scrno = pScreen->myNum;
 
     for (fdepth = 0; fdepth < GlyphFormatNum; fdepth++)
     {
@@ -108,8 +102,12 @@ GlyphUninit (ScreenPtr pScreen)
 	    glyph = globalGlyphs[fdepth].table[i].glyph;
 	    if (glyph && glyph != DeletedGlyph)
 	    {
+		if (GlyphPicture(glyph)[scrno])
+		{
+		    FreePicture ((pointer) GlyphPicture (glyph)[scrno], 0);
+		    GlyphPicture(glyph)[scrno] = NULL;
+		}
 		(*ps->UnrealizeGlyph) (pScreen, glyph);
-		FreeGlyphPrivates(glyph);
 	    }
 	}
     }
@@ -301,8 +299,7 @@ FreeGlyph (GlyphPtr glyph, int format)
 	}
 
 	FreeGlyphPicture(glyph);
-	FreeGlyphPrivates(glyph);
-	free(glyph);
+	dixFreeObjectWithPrivates(glyph, PRIVATE_GLYPH);
     }
 }
 
@@ -320,8 +317,7 @@ AddGlyph (GlyphSetPtr glyphSet, GlyphPtr glyph, Glyph id)
     if (gr->glyph && gr->glyph != DeletedGlyph && gr->glyph != glyph)
     {
 	FreeGlyphPicture(glyph);
-	FreeGlyphPrivates(glyph);
-	free(glyph);
+	dixFreeObjectWithPrivates(glyph, PRIVATE_GLYPH);
 	glyph = gr->glyph;
     }
     else if (gr->glyph != glyph)
@@ -372,6 +368,8 @@ FindGlyph (GlyphSetPtr glyphSet, Glyph id)
     return glyph;
 }
 
+#define GLYPH_SIZE	(sizeof (GlyphRec) + dixPrivatesSize(PRIVATE_GLYPH))
+
 GlyphPtr
 AllocateGlyph (xGlyphInfo *gi, int fdepth)
 {
@@ -381,13 +379,13 @@ AllocateGlyph (xGlyphInfo *gi, int fdepth)
     int		     i;
 
     size = screenInfo.numScreens * sizeof (PicturePtr);
-    glyph = (GlyphPtr) malloc(size + sizeof (GlyphRec));
+    glyph = (GlyphPtr) malloc (size + GLYPH_SIZE);
     if (!glyph)
 	return 0;
     glyph->refcnt = 0;
     glyph->size = size + sizeof (xGlyphInfo);
     glyph->info = *gi;
-    glyph->devPrivates = NULL;
+    dixInitPrivates(glyph, glyph + 1, PRIVATE_GLYPH);
 
     for (i = 0; i < screenInfo.numScreens; i++)
     {
@@ -411,8 +409,7 @@ bail:
 	    (*ps->UnrealizeGlyph) (screenInfo.screens[i], glyph);
     }
 
-    FreeGlyphPrivates(glyph);
-    free(glyph);
+    dixFreeObjectWithPrivates(glyph, PRIVATE_GLYPH);
     return 0;
 }
     
@@ -481,7 +478,6 @@ GlyphSetPtr
 AllocateGlyphSet (int fdepth, PictFormatPtr format)
 {
     GlyphSetPtr	glyphSet;
-    int size;
     
     if (!globalGlyphs[fdepth].hashSet)
     {
@@ -489,8 +485,7 @@ AllocateGlyphSet (int fdepth, PictFormatPtr format)
 	    return FALSE;
     }
 
-    size = sizeof (GlyphSetRec);
-    glyphSet = calloc(1, size);
+    glyphSet = dixAllocateObjectWithPrivates(GlyphSetRec, PRIVATE_GLYPHSET);
     if (!glyphSet)
 	return FALSE;
 
@@ -532,8 +527,7 @@ FreeGlyphSet (pointer	value,
 	else
 	    ResizeGlyphHash (&globalGlyphs[glyphSet->fdepth], 0, TRUE);
 	free(table);
-	dixFreePrivates(glyphSet->devPrivates);
-	free(glyphSet);
+	dixFreeObjectWithPrivates(glyphSet, PRIVATE_GLYPHSET);
     }
     return Success;
 }
diff --git a/render/picture.c b/render/picture.c
index ca5e18e..f6e3a9e 100644
--- a/render/picture.c
+++ b/render/picture.c
@@ -42,10 +42,8 @@
 #include "picturestr.h"
 #include "xace.h"
 
-static int PictureScreenPrivateKeyIndex;
-DevPrivateKey PictureScreenPrivateKey = &PictureScreenPrivateKeyIndex;
-static int PictureWindowPrivateKeyIndex;
-DevPrivateKey	PictureWindowPrivateKey = &PictureWindowPrivateKeyIndex;
+DevPrivateKeyRec PictureScreenPrivateKeyRec;
+DevPrivateKeyRec PictureWindowPrivateKeyRec;
 static int	PictureGeneration;
 RESTYPE		PictureType;
 RESTYPE		PictFormatType;
@@ -628,6 +626,12 @@ PictureInit (ScreenPtr pScreen, PictFormatPtr formats, int nformats)
 	    return FALSE;
 	PictureGeneration = serverGeneration;
     }
+    if (!dixRegisterPrivateKey(&PictureScreenPrivateKeyRec, PRIVATE_SCREEN, 0))
+	return FALSE;
+
+    if (!dixRegisterPrivateKey(&PictureWindowPrivateKeyRec, PRIVATE_WINDOW, 0))
+	return FALSE;
+
     if (!formats)
     {
 	formats = PictureCreateDefaultFormats (pScreen, &nformats);
@@ -753,7 +757,7 @@ CreatePicture (Picture		pid,
     PicturePtr		pPicture;
     PictureScreenPtr	ps = GetPictureScreen(pDrawable->pScreen);
 
-    pPicture = (PicturePtr)malloc(sizeof(PictureRec));
+    pPicture = dixAllocateObjectWithPrivates(PictureRec, PRIVATE_PICTURE);
     if (!pPicture)
     {
 	*error = BadAlloc;
@@ -764,7 +768,6 @@ CreatePicture (Picture		pid,
     pPicture->pDrawable = pDrawable;
     pPicture->pFormat = pFormat;
     pPicture->format = pFormat->format | (pDrawable->bitsPerPixel << 24);
-    pPicture->devPrivates = NULL;
 
     /* security creation/labeling check */
     *error = XaceHook(XACE_RESOURCE_ACCESS, client, pid, PictureType, pPicture,
@@ -896,12 +899,11 @@ static void initGradient(SourcePictPtr pGradient, int stopCount,
 static PicturePtr createSourcePicture(void)
 {
     PicturePtr pPicture;
-    pPicture = (PicturePtr) malloc(sizeof(PictureRec));
+    pPicture = dixAllocateObjectWithPrivates(PictureRec, PRIVATE_PICTURE);
     pPicture->pDrawable = 0;
     pPicture->pFormat = 0;
     pPicture->pNext = 0;
     pPicture->format = PICT_a8r8g8b8;
-    pPicture->devPrivates = 0;
 
     SetPictureToDefaults(pPicture);
     return pPicture;
@@ -1566,8 +1568,7 @@ FreePicture (pointer	value,
                 (*pScreen->DestroyPixmap) ((PixmapPtr)pPicture->pDrawable);
             }
         }
-	dixFreePrivates(pPicture->devPrivates);
-	free(pPicture);
+	dixFreeObjectWithPrivates(pPicture, PRIVATE_PICTURE);
     }
     return Success;
 }
diff --git a/render/picture.h b/render/picture.h
index 8bd38b9..e5f0d78 100644
--- a/render/picture.h
+++ b/render/picture.h
@@ -174,7 +174,6 @@ extern _X_EXPORT int PictureCmapPolicy;
 extern _X_EXPORT int PictureParseCmapPolicy (const char *name);
 
 extern _X_EXPORT int RenderErrBase;
-extern _X_EXPORT DevPrivateKey RenderClientPrivateKey;
 
 /* Fixed point updates from Carl Worth, USC, Information Sciences Institute */
 
diff --git a/render/picturestr.h b/render/picturestr.h
index a401108..da69ff6 100644
--- a/render/picturestr.h
+++ b/render/picturestr.h
@@ -396,8 +396,12 @@ typedef struct _PictureScreen {
 
 } PictureScreenRec, *PictureScreenPtr;
 
-extern _X_EXPORT DevPrivateKey	PictureScreenPrivateKey;
-extern _X_EXPORT DevPrivateKey	PictureWindowPrivateKey;
+extern _X_EXPORT DevPrivateKeyRec PictureScreenPrivateKeyRec;
+#define PictureScreenPrivateKey (&PictureScreenPrivateKeyRec)
+
+extern _X_EXPORT DevPrivateKeyRec PictureWindowPrivateKeyRec;
+#define	PictureWindowPrivateKey (&PictureWindowPrivateKeyRec)
+
 extern _X_EXPORT RESTYPE	PictureType;
 extern _X_EXPORT RESTYPE	PictFormatType;
 extern _X_EXPORT RESTYPE	GlyphSetType;
diff --git a/render/render.c b/render/render.c
index 78ecf43..40401a4 100644
--- a/render/render.c
+++ b/render/render.c
@@ -210,8 +210,8 @@ int	(*SProcRenderVector[RenderNumberRequests])(ClientPtr) = {
 };
 
 int	RenderErrBase;
-static int RenderClientPrivateKeyIndex;
-DevPrivateKey RenderClientPrivateKey = &RenderClientPrivateKeyIndex;
+static DevPrivateKeyRec RenderClientPrivateKeyRec;
+#define RenderClientPrivateKey (&RenderClientPrivateKeyRec )
 
 typedef struct _RenderClient {
     int	    major_version;
@@ -246,7 +246,7 @@ RenderExtensionInit (void)
 	return;
     if (!PictureFinishInit ())
 	return;
-    if (!dixRequestPrivate(RenderClientPrivateKey, sizeof(RenderClientRec)))
+    if (!dixRegisterPrivateKey(&RenderClientPrivateKeyRec, PRIVATE_CLIENT, sizeof(RenderClientRec)))
 	return;
     if (!AddCallback (&ClientStateCallback, RenderClientCallback, 0))
 	return;
diff --git a/xfixes/cursor.c b/xfixes/cursor.c
index 5f08db7..a9f089f 100644
--- a/xfixes/cursor.c
+++ b/xfixes/cursor.c
@@ -59,8 +59,8 @@ static RESTYPE		CursorHideCountType;
 static RESTYPE		CursorWindowType;
 static CursorPtr	CursorCurrent[MAXDEVICES];
 
-static int CursorScreenPrivateKeyIndex;
-static DevPrivateKey CursorScreenPrivateKey = &CursorScreenPrivateKeyIndex;
+static DevPrivateKeyRec CursorScreenPrivateKeyRec;
+#define CursorScreenPrivateKey (&CursorScreenPrivateKeyRec)
 
 static void deleteCursorHideCountsForScreen (ScreenPtr pScreen);
 
@@ -1037,6 +1037,9 @@ XFixesCursorInit (void)
     if (party_like_its_1989)
 	CursorVisible = EnableCursor;
     
+    if (!dixRegisterPrivateKey(&CursorScreenPrivateKeyRec, PRIVATE_SCREEN, 0))
+	return FALSE;
+
     for (i = 0; i < screenInfo.numScreens; i++)
     {
 	ScreenPtr	pScreen = screenInfo.screens[i];
diff --git a/xfixes/xfixes.c b/xfixes/xfixes.c
index 2f64a04..215909d 100644
--- a/xfixes/xfixes.c
+++ b/xfixes/xfixes.c
@@ -56,8 +56,8 @@ static unsigned char	XFixesReqCode;
 int		XFixesEventBase;
 int		XFixesErrorBase;
 
-static int XFixesClientPrivateKeyIndex;
-static DevPrivateKey XFixesClientPrivateKey = &XFixesClientPrivateKeyIndex;
+static DevPrivateKeyRec XFixesClientPrivateKeyRec;
+#define XFixesClientPrivateKey (&XFixesClientPrivateKeyRec)
 
 static int
 ProcXFixesQueryVersion(ClientPtr client)
@@ -241,7 +241,7 @@ XFixesExtensionInit(void)
 {
     ExtensionEntry *extEntry;
 
-    if (!dixRequestPrivate(XFixesClientPrivateKey, sizeof (XFixesClientRec)))
+    if (!dixRegisterPrivateKey(&XFixesClientPrivateKeyRec, PRIVATE_CLIENT, sizeof (XFixesClientRec)))
 	return;
     if (!AddCallback (&ClientStateCallback, XFixesClientCallback, 0))
 	return;
diff --git a/xkb/xkb.c b/xkb/xkb.c
index 5a425bd..0dab694 100644
--- a/xkb/xkb.c
+++ b/xkb/xkb.c
@@ -6707,6 +6707,9 @@ XkbExtensionInit(void)
     if (!RT_XKBCLIENT)
 	return;
 
+    if (!dixRegisterPrivateKey(&xkbDevicePrivateKeyRec, PRIVATE_DEVICE, 0))
+	return;
+
     if ((extEntry = AddExtension(XkbName, XkbNumberEvents, XkbNumberErrors,
 				 ProcXkbDispatch, SProcXkbDispatch,
 				 NULL, StandardMinorOpcode))) {
diff --git a/xkb/xkbActions.c b/xkb/xkbActions.c
index 0a1a873..3f0b766 100644
--- a/xkb/xkbActions.c
+++ b/xkb/xkbActions.c
@@ -43,8 +43,7 @@ THE USE OR PERFORMANCE OF THIS SOFTWARE.
 #include "mi.h"
 #define EXTENSION_EVENT_BASE 64
 
-static int xkbDevicePrivateKeyIndex;
-DevPrivateKey xkbDevicePrivateKey = &xkbDevicePrivateKeyIndex;
+DevPrivateKeyRec xkbDevicePrivateKeyRec;
 
 static void XkbFakeDeviceButton(DeviceIntPtr dev,Bool press,int button);
 static void XkbFakePointerMotion(DeviceIntPtr dev, unsigned flags,int x,int y);
commit c865a24401f06bcf1347d8b41f736a066ab25693
Author: Keith Packard <keithp at keithp.com>
Date:   Fri Apr 30 22:05:27 2010 -0700

    Create separate private key for midispcur cursor bits
    
    The CursorScreenKey array is supposed to be used by the DDX for cursor
    private data, but midispcur was abusing it to hold cursor bits private
    information. Create a separate set of privates for the dispcur cursor
    bits information.
    
    This also renames the device private index and macros to better
    reflect their usage:
    
    	miDCSpriteKey -> miDCDeviceKey
    	MIDCBUFFER -> miGetDCDevice
    
    Signed-off-by: Keith Packard <keithp at keithp.com>
    Reviewed-by: Jamey Sharp <jamey at minilop.net>

diff --git a/mi/midispcur.c b/mi/midispcur.c
index 87eb27d..a8aef92 100644
--- a/mi/midispcur.c
+++ b/mi/midispcur.c
@@ -59,9 +59,13 @@ static DevPrivateKey miDCScreenKey = &miDCScreenKeyIndex;
 
 static Bool	miDCCloseScreen(int index, ScreenPtr pScreen);
 
+/* per bits per-screen private data */
+static int miDCCursorBitsKeyIndex[MAXSCREENS];
+#define miDCCursorBitsKey(screen)	(&miDCCursorBitsKeyIndex[(screen)->myNum])
+
 /* per device per-screen private data */
-static int miDCSpriteKeyIndex[MAXSCREENS];
-static DevPrivateKey miDCSpriteKey = miDCSpriteKeyIndex;
+static int miDCDeviceKeyIndex[MAXSCREENS];
+#define miDCDeviceKey(screen)		(&miDCDeviceKeyIndex[(screen)->myNum])
 
 typedef struct {
     GCPtr	    pSourceGC, pMaskGC;
@@ -72,10 +76,10 @@ typedef struct {
 #endif
 } miDCBufferRec, *miDCBufferPtr;
 
-#define MIDCBUFFER(dev, screen) \
+#define miGetDCDevice(dev, screen) \
  ((DevHasCursor(dev)) ? \
-  (miDCBufferPtr)dixLookupPrivate(&dev->devPrivates, miDCSpriteKey + (screen)->myNum) : \
-  (miDCBufferPtr)dixLookupPrivate(&dev->u.master->devPrivates, miDCSpriteKey + (screen)->myNum))
+  (miDCBufferPtr)dixLookupPrivate(&dev->devPrivates, miDCDeviceKey(screen)) : \
+  (miDCBufferPtr)dixLookupPrivate(&dev->u.master->devPrivates, miDCDeviceKey(screen)))
 
 /* 
  * The core pointer buffer will point to the index of the virtual core pointer
@@ -133,7 +137,7 @@ Bool
 miDCRealizeCursor (ScreenPtr pScreen, CursorPtr pCursor)
 {
     if (pCursor->bits->refcnt <= 1)
-	dixSetPrivate(&pCursor->bits->devPrivates, CursorScreenKey(pScreen), NULL);
+	dixSetPrivate(&pCursor->bits->devPrivates, miDCCursorBitsKey(pScreen), NULL);
     return TRUE;
 }
 
@@ -232,7 +236,7 @@ miDCRealize (ScreenPtr pScreen, CursorPtr pCursor)
 	    free((pointer) pPriv);
 	    return NULL;
 	}
-	dixSetPrivate(&pCursor->bits->devPrivates, CursorScreenKey(pScreen), pPriv);
+	dixSetPrivate(&pCursor->bits->devPrivates, miDCCursorBitsKey(pScreen), pPriv);
 	return pPriv;
     }
     pPriv->pPicture = 0;
@@ -250,7 +254,7 @@ miDCRealize (ScreenPtr pScreen, CursorPtr pCursor)
 	free((pointer) pPriv);
 	return NULL;
     }
-    dixSetPrivate(&pCursor->bits->devPrivates, CursorScreenKey(pScreen), pPriv);
+    dixSetPrivate(&pCursor->bits->devPrivates, miDCCursorBitsKey(pScreen), pPriv);
 
     /* create the two sets of bits, clipping as appropriate */
 
@@ -295,7 +299,7 @@ miDCUnrealizeCursor (ScreenPtr pScreen, CursorPtr pCursor)
     miDCCursorPtr   pPriv;
 
     pPriv = (miDCCursorPtr)dixLookupPrivate(&pCursor->bits->devPrivates,
-					    CursorScreenKey(pScreen));
+					    miDCCursorBitsKey(pScreen));
     if (pPriv && (pCursor->bits->refcnt <= 1))
     {
 	if (pPriv->sourceBits)
@@ -307,7 +311,7 @@ miDCUnrealizeCursor (ScreenPtr pScreen, CursorPtr pCursor)
 	    FreePicture (pPriv->pPicture, 0);
 #endif
 	free((pointer) pPriv);
-	dixSetPrivate(&pCursor->bits->devPrivates, CursorScreenKey(pScreen), NULL);
+	dixSetPrivate(&pCursor->bits->devPrivates, miDCCursorBitsKey(pScreen), NULL);
     }
     return TRUE;
 }
@@ -396,7 +400,7 @@ miDCPutUpCursor (DeviceIntPtr pDev, ScreenPtr pScreen, CursorPtr pCursor,
     WindowPtr	    pWin;
 
     pPriv = (miDCCursorPtr)dixLookupPrivate(&pCursor->bits->devPrivates,
-					    CursorScreenKey(pScreen));
+					    miDCCursorBitsKey(pScreen));
     if (!pPriv)
     {
 	pPriv = miDCRealize(pScreen, pCursor);
@@ -406,7 +410,7 @@ miDCPutUpCursor (DeviceIntPtr pDev, ScreenPtr pScreen, CursorPtr pCursor,
     pScreenPriv = (miDCScreenPtr)dixLookupPrivate(&pScreen->devPrivates,
 						  miDCScreenKey);
     pWin = pScreen->root;
-    pBuffer = MIDCBUFFER(pDev, pScreen);
+    pBuffer = miGetDCDevice(pDev, pScreen);
 
 #ifdef ARGB_CURSOR
     if (pPriv->pPicture)
@@ -445,7 +449,7 @@ miDCSaveUnderCursor (DeviceIntPtr pDev, ScreenPtr pScreen,
 
     pScreenPriv = (miDCScreenPtr)dixLookupPrivate(&pScreen->devPrivates,
 						  miDCScreenKey);
-    pBuffer = MIDCBUFFER(pDev, pScreen);
+    pBuffer = miGetDCDevice(pDev, pScreen);
 
     pSave = pBuffer->pSave;
     pWin = pScreen->root;
@@ -479,7 +483,7 @@ miDCRestoreUnderCursor (DeviceIntPtr pDev, ScreenPtr pScreen,
 
     pScreenPriv = (miDCScreenPtr)dixLookupPrivate(&pScreen->devPrivates,
 						  miDCScreenKey);
-    pBuffer = MIDCBUFFER(pDev, pScreen);
+    pBuffer = miGetDCDevice(pDev, pScreen);
     pSave = pBuffer->pSave;
 
     pWin = pScreen->root;
@@ -512,7 +516,7 @@ miDCDeviceInitialize(DeviceIntPtr pDev, ScreenPtr pScreen)
         if (!pBuffer)
             goto failure;
 
-        dixSetPrivate(&pDev->devPrivates, miDCSpriteKey + pScreen->myNum, pBuffer);
+        dixSetPrivate(&pDev->devPrivates, miDCDeviceKey(pScreen), pBuffer);
         pWin = pScreen->root;
 
         pBuffer->pSourceGC = miDCMakeGC(pWin);
@@ -560,7 +564,7 @@ miDCDeviceCleanup(DeviceIntPtr pDev, ScreenPtr pScreen)
         {
             pScreen = screenInfo.screens[i];
 
-            pBuffer = MIDCBUFFER(pDev, pScreen);
+            pBuffer = miGetDCDevice(pDev, pScreen);
 
             if (pBuffer)
             {
@@ -578,7 +582,7 @@ miDCDeviceCleanup(DeviceIntPtr pDev, ScreenPtr pScreen)
                 if (pBuffer->pSave) (*pScreen->DestroyPixmap)(pBuffer->pSave);
 
                 free(pBuffer);
-                dixSetPrivate(&pDev->devPrivates, miDCSpriteKey + pScreen->myNum, NULL);
+                dixSetPrivate(&pDev->devPrivates, miDCDeviceKey(pScreen), NULL);
             }
         }
     }
commit 431781a921251d54782f0a4f194bbef1fabd1380
Author: Keith Packard <keithp at keithp.com>
Date:   Sat May 15 14:52:39 2010 -0700

    Remove dixRegisterPrivateOffset; hard-code devPrivates offsets instead
    
    For predefined resource types, the offset of the devPrivates field was
    already kept in a constant table. The only non-predefined type needing
    this treatment was dbeDrawableResType, which is just a magic alias for
    RT_PIXMAP.
    
    This patch special-cases looking up RC_DRAWABLE offsets and uses the
    table directly for everything else.
    
    Signed-off-by: Keith Packard <keithp at keithp.com>
    Reviewed-by: Jamey Sharp <jamey at minilop.net>

diff --git a/dbe/dbe.c b/dbe/dbe.c
index fba10d6..9b5474c 100644
--- a/dbe/dbe.c
+++ b/dbe/dbe.c
@@ -1576,10 +1576,6 @@ DbeExtensionInit(void)
     if (!dbeWindowPrivResType)
 	return;
 
-    if (!dixRegisterPrivateOffset(dbeDrawableResType,
-				  offsetof(PixmapRec, devPrivates)))
-	return;
-
     for (i = 0; i < screenInfo.numScreens; i++)
     {
         /* For each screen, set up DBE screen privates and init DIX and DDX
diff --git a/dix/privates.c b/dix/privates.c
index 4a8a186..9ec6c46 100644
--- a/dix/privates.c
+++ b/dix/privates.c
@@ -208,7 +208,7 @@ dixFreePrivates(PrivateRec *privates)
 }
 
 /* Table of devPrivates offsets */
-static const int offsetDefaults[] = {
+static const int offsets[] = {
     -1,					/* RT_NONE */
     offsetof(WindowRec, devPrivates),	/* RT_WINDOW */
     offsetof(PixmapRec, devPrivates),	/* RT_PIXMAP */
@@ -216,45 +216,27 @@ static const int offsetDefaults[] = {
     -1,		    			/* RT_FONT */
     offsetof(CursorRec, devPrivates),	/* RT_CURSOR */
     offsetof(ColormapRec, devPrivates),	/* RT_COLORMAP */
-    -1,			  		/* RT_CMAPENTRY */
-    -1,					/* RT_OTHERCLIENT */
-    -1					/* RT_PASSIVEGRAB */
 };
-    
-static int *offsets = NULL;
-static int offsetsSize = 0;
 
-/*
- * Specify where the devPrivates field is located in a structure type
- */
-int
-dixRegisterPrivateOffset(RESTYPE type, int offset)
-{
-    type = type & TypeMask;
-
-    /* resize offsets table if necessary */
-    while (type >= offsetsSize) {
-	unsigned i = offsetsSize * 2 * sizeof(int);
-	offsets = (int *)realloc(offsets, i);
-	if (!offsets) {
-	    offsetsSize = 0;
-	    return FALSE;
-	}
-	for (i=offsetsSize; i < 2*offsetsSize; i++)
-	    offsets[i] = -1;
-	offsetsSize *= 2;
-    }
-
-    offsets[type] = offset;
-    return TRUE;
-}
+#define NUM_OFFSETS	(sizeof (offsets) / sizeof (offsets[0]))
 
 int
 dixLookupPrivateOffset(RESTYPE type)
 {
+    /*
+     * Special kludge for DBE which registers a new resource type that
+     * points at pixmaps (thanks, DBE)
+     */
+    if (type & RC_DRAWABLE) {
+	if (type == RT_WINDOW)
+	    return offsets[RT_WINDOW & TypeMask];
+	else
+	    return offsets[RT_PIXMAP & TypeMask];
+    }
     type = type & TypeMask;
-    assert(type < offsetsSize);
-    return offsets[type];
+    if (type < NUM_OFFSETS)
+	return offsets[type];
+    return -1;
 }
 
 int
@@ -268,15 +250,5 @@ dixResetPrivates(void)
 	items[i].size = 0;
     }
     nextPriv = 1;
-
-    /* reset offsets */
-    if (offsets)
-	free(offsets);
-    offsetsSize = sizeof(offsetDefaults);
-    offsets = malloc(offsetsSize);
-    offsetsSize /= sizeof(int);
-    if (!offsets)
-	return FALSE;
-    memcpy(offsets, offsetDefaults, sizeof(offsetDefaults));
     return TRUE;
 }
diff --git a/dix/resource.c b/dix/resource.c
index a6d115f..ce025f9 100644
--- a/dix/resource.c
+++ b/dix/resource.c
@@ -254,8 +254,6 @@ CreateNewResourceType(DeleteType deleteFunc, char *name)
     types = realloc(resourceTypes, (next + 1) * sizeof(*resourceTypes));
     if (!types)
 	return 0;
-    if (!dixRegisterPrivateOffset(next, -1))
-	return 0;
 
     lastResourceType = next;
     resourceTypes = types;
diff --git a/include/privates.h b/include/privates.h
index 7850dea..72f4d40 100644
--- a/include/privates.h
+++ b/include/privates.h
@@ -108,26 +108,16 @@ extern _X_EXPORT int
 dixResetPrivates(void);
 
 /*
- * These next two functions are necessary because the position of
- * the devPrivates field varies by structure and calling code might
- * only know the resource type, not the structure definition.
- */
-
-/*
  * Looks up the offset where the devPrivates field is located.
- * Returns -1 if no offset has been registered for the resource type.
+ * Returns -1 if the specified resource has no dev privates.
+ * The position of the devPrivates field varies by structure
+ * and calling code might only know the resource type, not the
+ * structure definition.
  */
 extern _X_EXPORT int
 dixLookupPrivateOffset(RESTYPE type);
 
 /*
- * Specifies the offset where the devPrivates field is located.
- * A negative value indicates no devPrivates field is available.
- */
-extern _X_EXPORT int
-dixRegisterPrivateOffset(RESTYPE type, int offset);
-
-/*
  * Convenience macro for adding an offset to an object pointer
  * when making a call to one of the devPrivates functions
  */


More information about the xorg-commit mailing list