From faeebead7bfcc78535757ca7acc1faf7554c03b7 Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Mon, 26 Apr 2010 17:22:21 -0700 Subject: [PATCH] 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 Tested-by: Tiago Vignatti --- 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 | 71 +++++++--- dix/property.c | 15 +- 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 | 196 ++++++++++++++++++-------- include/xkbsrv.h | 4 +- mi/micmap.c | 6 +- mi/micmap.h | 4 +- mi/midispcur.c | 22 ++- 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 +- 139 files changed, 1108 insertions(+), 714 deletions(-) diff --git a/Xext/geext.c b/Xext/geext.c index b7f32c079..e61989caa 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 10a33cea3..3e2b8e187 100644 --- a/Xext/geint.h +++ b/Xext/geint.h @@ -37,7 +37,8 @@ #include "extnsionst.h" #include -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 c6254387e..1cb58b59f 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 696c4aa22..6d91ddf5e 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 e58ba10f8..12210f8bc 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 322709c17..dfd8723e3 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 13e5243c2..560e1e9bf 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 e5dbe11f1..011a10370 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 263d0c16a..0a6b1c531 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 9a367bd4c..0c34b1611 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 755038631..982fad13f 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 2d2d25c0b..f7557079e 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 f9d8dc8e7..eda4efb50 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 d37d52a18..30d9dc2b6 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 b4deaf5e8..1b2cd8ff6 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 93da4dfa2..9c1ffd501 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 7717a40f7..926504e87 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 9b5474c81..ef4b596c4 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 ba6b56d79..9c383cef8 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 49689c529..03e8e2e1b 100644 --- a/dbe/midbe.c +++ b/dbe/midbe.c @@ -58,14 +58,8 @@ #include -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 007f2e37b..cff36d038 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 12197acde..eb6c491c1 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 7ff0a932e..67592c578 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 998d22a4b..427264d46 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 859b93e43..ffb376470 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 d3d4db042..f422ea3a0 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 48a507daa..6d022f1e6 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 82a85c28e..b12856994 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 982fedd6b..0f499dd0f 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; idevPrivates, 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 a4ad2557b..cbb5e7f99 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 9ec6c46be..87831c237 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 03b70efc6..65231079a 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 f52638c3a..bae3a3092 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 a98437b43..7caa1ccd7 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 4e1ffd699..bbe93f6df 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 7ab4adf69..4fde42647 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 569391b93..efeb26880 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 ce6fcd53d..02b72683d 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 392e27f39..cda7fc793 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 625ce715b..15eedcdb9 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 9b789b0a8..f4311aedf 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 73ee510b9..433f286e0 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 b234afcd0..4d02b4778 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 ffe70c31c..a5b61df9f 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 fbb8b96ed..4532960b5 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 f968f8622..75e0650ce 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 3e75de75e..829200e6a 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 2da3ba85e..4ff3cd800 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 164214500..915e7678a 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 a81eb7d37..3c8a09ce4 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 a64cbd0a4..a058ae285 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 64418340c..59da788b3 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 068e80908..6d2f2d3f5 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 a4642350c..9c9fbc59d 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 28212a330..44848281f 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 8bd1f74bd..f93121ea2 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 23c20321f..4041bf5fa 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 27596e467..06c3661da 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 35ce03660..3ca98146b 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 99ab2d824..24ae89eac 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 0f0edb2a9..2f4195582 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 d8629a84d..886c25b13 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 a51a754e4..82fb52a05 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 cd33e75e7..cd025dca4 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 8b483f35c..43665d1b6 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 db88f706d..18df8c943 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 77053b8c2..d7ffff4ca 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 4a736fc7a..a58d21a2d 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 e704f5a46..1788fa192 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 f59ffcb70..f26c22c59 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 f15844e59..649f07808 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 d883ab36a..e60e5c405 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 36e325f6a..a979dd3eb 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 99d6695b8..e6464a582 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 906f4d5fc..203fccf16 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 448762879..b02fdafa2 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 63c77ded6..db4cd7b00 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 3c8d3a82d..baa6706d6 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 315ba4af9..83f72b5e1 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 8d598d6e7..bb4d75e2f 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 2bbcb9cb1..e16b510ff 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 32be9c2f3..d22d88d8b 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 a0e4b9e36..2066f7631 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 0ccdae59d..d0a66b8d8 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 61adec62b..ca22368f4 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 0e86e67e4..189441d0d 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 2491492f5..e91bac062 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 b3f0fc488..6399e3470 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 2cd555c58..2761583ec 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 bf0648088..a0968b94d 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 0a05ac8da..957fe4cdb 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 fab2f3981..659b13537 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 ab2c3b1e6..d3b18bd3a 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 19535fe3a..9f1045611 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 614827587..aa671ed1f 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 92a190208..f4d8fc7d6 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 1d99d36bf..a99c0f155 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 8fa48bfeb..350eadeb6 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 bb37e4abe..2828c57ed 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 8ab70f22a..c038ed026 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 d9b2e0338..72a7ecfc8 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 -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 f1a5c83f5..efbae3caf 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 fdb85630d..c268c2c87 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 49b73d746..05913d700 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 21ccd9b3b..6ecbff6d3 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 2ef8a36ee..2cc53f2d2 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 dadedfd1d..59978d4ca 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 3ff56e2bf..6a4d0db52 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 55a9c818a..5cf42d1fb 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 72f4d4028..9412fd613 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 +#include +#include +#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'. + * Let drivers know how to initialize private keys + */ + +#define HAS_DEVPRIVATEKEYREC 1 +#define HAS_DIXREGISTERPRIVATEKEY 1 + +/* + * Register a new private index for the private type. * - * 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. + * 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 is not called with a nonzero size for 'key', then the - * module responsible for 'key' must manage the associated pointer itself with - * dixSetPrivate. + * You may call dixRegisterPrivate more than once on the same key, but the + * size and type must match or the server will abort. * - * dixRequestPrivate returns FALSE if it cannot store the requested size. + * dixRegisterPrivateIndex returns FALSE if it fails to allocate memory + * during its operation. + */ +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; +} + +/* + * 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 -dixRequestPrivate(const DevPrivateKey key, unsigned size); +dixSetPrivate(PrivatePtr *privates, const DevPrivateKey key, pointer val); + +#include "dix.h" +#include "resource.h" /* - * Allocates space for an association of 'key' with a value in 'privates'. + * Lookup a pointer to the private record. * - * 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. - * - * If dixRequestPrivate was never called with a nonzero size, then - * dixAllocatePrivate associates NULL with 'key' in 'privates'. - * - * dixAllocatePrivate returns a pointer to the value associated with 'key' in - * 'privates', unless a memory allocation fails, in which case it returns NULL. - */ -extern _X_EXPORT pointer * -dixAllocatePrivate(PrivateRec **privates, const DevPrivateKey key); - -/* - * Look up a private pointer. - * - * If no value is currently associated with 'key' in 'privates', then - * dixLookupPrivate calls dixAllocatePrivate and returns the resulting - * associated value. - * - * 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 b3a831919..7c92f6491 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 dac700dc5..3effe6c76 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 8ad94b9dd..c67710c46 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 a8aef926c..b41247764 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 b5f706dbf..ae9d113d1 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 d8eb64278..aa00e234c 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 296c57f5d..33bb40b89 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 22575ea21..de58c07f4 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 1b88ecbb1..ea2a0c1cd 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 b2cf5f0be..38a6b939a 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 563831a49..7623de75e 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 79051dfa2..31eb9e57c 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 935b1c048..e8a119127 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 8a4b81321..6faf1febd 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 24dcfe80a..43b9cbb53 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 893014bf4..111f46a60 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 ffb34d6a9..f52a46ac8 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 a18c834e9..aad126f80 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 46231c913..82d5f9f1e 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 ad126fb48..2160f5043 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 e5b8f8633..948a20a9a 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 ca5e18e74..f6e3a9e08 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 8bd38b98e..e5f0d78f6 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 a4011082b..da69ff601 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 78ecf43b7..40401a4f5 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 5f08db7a5..a9f089f28 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 2f64a04f7..215909df1 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 5a425bd73..0dab69468 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 0a1a873d1..3f0b766db 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);