diff options
Diffstat (limited to 'render/picture.c')
-rw-r--r-- | render/picture.c | 149 |
1 files changed, 27 insertions, 122 deletions
diff --git a/render/picture.c b/render/picture.c index a7e40f994..35e2a28b3 100644 --- a/render/picture.c +++ b/render/picture.c @@ -40,66 +40,17 @@ #include "gcstruct.h" #include "servermd.h" #include "picturestr.h" +#include "xace.h" +#include "registry.h" -_X_EXPORT int PictureScreenPrivateIndex = -1; -int PictureWindowPrivateIndex; +_X_EXPORT DevPrivateKey PictureScreenPrivateKey = &PictureScreenPrivateKey; +DevPrivateKey PictureWindowPrivateKey = &PictureWindowPrivateKey; static int PictureGeneration; RESTYPE PictureType; RESTYPE PictFormatType; RESTYPE GlyphSetType; int PictureCmapPolicy = PictureCmapPolicyDefault; -/* Picture Private machinery */ - -static int picturePrivateCount; - -void -ResetPicturePrivateIndex (void) -{ - picturePrivateCount = 0; -} - -int -AllocatePicturePrivateIndex (void) -{ - return picturePrivateCount++; -} - -Bool -AllocatePicturePrivate (ScreenPtr pScreen, int index2, unsigned int amount) -{ - PictureScreenPtr ps = GetPictureScreen(pScreen); - unsigned int oldamount; - - /* Round up sizes for proper alignment */ - amount = ((amount + (sizeof(long) - 1)) / sizeof(long)) * sizeof(long); - - if (index2 >= ps->PicturePrivateLen) - { - unsigned int *nsizes; - - nsizes = (unsigned int *)xrealloc(ps->PicturePrivateSizes, - (index2 + 1) * sizeof(unsigned int)); - if (!nsizes) - return FALSE; - while (ps->PicturePrivateLen <= index2) - { - nsizes[ps->PicturePrivateLen++] = 0; - ps->totalPictureSize += sizeof(DevUnion); - } - ps->PicturePrivateSizes = nsizes; - } - oldamount = ps->PicturePrivateSizes[index2]; - if (amount > oldamount) - { - ps->PicturePrivateSizes[index2] = amount; - ps->totalPictureSize += (amount - oldamount); - } - - return TRUE; -} - - Bool PictureDestroyWindow (WindowPtr pWindow) { @@ -137,8 +88,6 @@ PictureCloseScreen (int index, ScreenPtr pScreen) (*ps->CloseIndexed) (pScreen, &ps->formats[n]); GlyphUninit (pScreen); SetPictureScreen(pScreen, 0); - if (ps->PicturePrivateSizes) - xfree (ps->PicturePrivateSizes); xfree (ps->formats); xfree (ps); return ret; @@ -497,8 +446,6 @@ PictureFinishInit (void) for (s = 0; s < screenInfo.numScreens; s++) { - if (!GlyphFinishInit (screenInfo.screens[s])) - return FALSE; if (!PictureInitIndexedFormats (screenInfo.screens[s])) return FALSE; (void) AnimCurInit (screenInfo.screens[s]); @@ -637,20 +584,11 @@ PictureInit (ScreenPtr pScreen, PictFormatPtr formats, int nformats) GlyphSetType = CreateNewResourceType (FreeGlyphSet); if (!GlyphSetType) return FALSE; - PictureScreenPrivateIndex = AllocateScreenPrivateIndex(); - if (PictureScreenPrivateIndex < 0) - return FALSE; - PictureWindowPrivateIndex = AllocateWindowPrivateIndex(); PictureGeneration = serverGeneration; -#ifdef XResExtension RegisterResourceName (PictureType, "PICTURE"); RegisterResourceName (PictFormatType, "PICTFORMAT"); RegisterResourceName (GlyphSetType, "GLYPHSET"); -#endif } - if (!AllocateWindowPrivate (pScreen, PictureWindowPrivateIndex, 0)) - return FALSE; - if (!formats) { formats = PictureCreateDefaultFormats (pScreen, &nformats); @@ -697,18 +635,7 @@ PictureInit (ScreenPtr pScreen, PictFormatPtr formats, int nformats) return FALSE; } SetPictureScreen(pScreen, ps); - if (!GlyphInit (pScreen)) - { - SetPictureScreen(pScreen, 0); - xfree (formats); - xfree (ps); - return FALSE; - } - ps->totalPictureSize = sizeof (PictureRec); - ps->PicturePrivateSizes = 0; - ps->PicturePrivateLen = 0; - ps->formats = formats; ps->fallback = formats; ps->nformats = nformats; @@ -774,37 +701,6 @@ SetPictureToDefaults (PicturePtr pPicture) } PicturePtr -AllocatePicture (ScreenPtr pScreen) -{ - PictureScreenPtr ps = GetPictureScreen(pScreen); - PicturePtr pPicture; - char *ptr; - DevUnion *ppriv; - unsigned int *sizes; - unsigned int size; - int i; - - pPicture = (PicturePtr) xalloc (ps->totalPictureSize); - if (!pPicture) - return 0; - ppriv = (DevUnion *)(pPicture + 1); - pPicture->devPrivates = ppriv; - sizes = ps->PicturePrivateSizes; - ptr = (char *)(ppriv + ps->PicturePrivateLen); - for (i = ps->PicturePrivateLen; --i >= 0; ppriv++, sizes++) - { - if ( (size = *sizes) ) - { - ppriv->ptr = (pointer)ptr; - ptr += size; - } - else - ppriv->ptr = (pointer)NULL; - } - return pPicture; -} - -PicturePtr CreatePicture (Picture pid, DrawablePtr pDrawable, PictFormatPtr pFormat, @@ -816,7 +712,7 @@ CreatePicture (Picture pid, PicturePtr pPicture; PictureScreenPtr ps = GetPictureScreen(pDrawable->pScreen); - pPicture = AllocatePicture (pDrawable->pScreen); + pPicture = (PicturePtr)xalloc(sizeof(PictureRec)); if (!pPicture) { *error = BadAlloc; @@ -827,6 +723,14 @@ 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, + RT_PIXMAP, pDrawable, DixCreateAccess|DixSetAttrAccess); + if (*error != Success) + goto out; + if (pDrawable->type == DRAWABLE_PIXMAP) { ++((PixmapPtr)pDrawable)->refcnt; @@ -846,6 +750,7 @@ CreatePicture (Picture pid, *error = Success; if (*error == Success) *error = (*ps->CreatePicture) (pPicture); +out: if (*error != Success) { FreePicture (pPicture, (XID) 0); @@ -1163,14 +1068,13 @@ ChangePicture (PicturePtr pPicture, pAlpha = 0; else { - pAlpha = (PicturePtr) SecurityLookupIDByType(client, - pid, - PictureType, - DixWriteAccess|DixReadAccess); - if (!pAlpha) + error = dixLookupResource((pointer *)&pAlpha, pid, + PictureType, client, + DixReadAccess); + if (error != Success) { client->errorValue = pid; - error = BadPixmap; + error = (error == BadValue) ? BadPixmap : error; break; } if (pAlpha->pDrawable == NULL || @@ -1225,14 +1129,13 @@ ChangePicture (PicturePtr pPicture, else { clipType = CT_PIXMAP; - pPixmap = (PixmapPtr)SecurityLookupIDByType(client, - pid, - RT_PIXMAP, - DixReadAccess); - if (!pPixmap) + error = dixLookupResource((pointer *)&pPixmap, pid, + RT_PIXMAP, client, + DixReadAccess); + if (error != Success) { client->errorValue = pid; - error = BadPixmap; + error = (error == BadValue) ? BadPixmap : error; break; } } @@ -1607,7 +1510,8 @@ FreePicture (pointer value, WindowPtr pWindow = (WindowPtr) pPicture->pDrawable; PicturePtr *pPrev; - for (pPrev = (PicturePtr *) &((pWindow)->devPrivates[PictureWindowPrivateIndex].ptr); + for (pPrev = (PicturePtr *)dixLookupPrivateAddr + (&pWindow->devPrivates, PictureWindowPrivateKey); *pPrev; pPrev = &(*pPrev)->pNext) { @@ -1623,6 +1527,7 @@ FreePicture (pointer value, (*pScreen->DestroyPixmap) ((PixmapPtr)pPicture->pDrawable); } } + dixFreePrivates(pPicture->devPrivates); xfree (pPicture); } return Success; |