summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--dix/extension.c38
-rw-r--r--dix/main.c1
-rw-r--r--dix/privates.c58
-rw-r--r--include/extension.h2
-rw-r--r--include/extnsionst.h2
5 files changed, 99 insertions, 2 deletions
diff --git a/dix/extension.c b/dix/extension.c
index bb20ade96..40e1373b6 100644
--- a/dix/extension.c
+++ b/dix/extension.c
@@ -78,6 +78,40 @@ int lastEvent = EXTENSION_EVENT_BASE;
static int lastError = FirstExtensionError;
static unsigned int NumExtensions = 0;
+extern int extensionPrivateLen;
+extern unsigned *extensionPrivateSizes;
+extern unsigned totalExtensionSize;
+
+static int
+InitExtensionPrivates(ExtensionEntry *ext)
+{
+ register char *ptr;
+ DevUnion *ppriv;
+ register unsigned *sizes;
+ register unsigned size;
+ register int i;
+
+ if (totalExtensionSize == sizeof(ExtensionEntry))
+ ppriv = (DevUnion *)NULL;
+ else
+ ppriv = (DevUnion *)(ext + 1);
+
+ ext->devPrivates = ppriv;
+ sizes = extensionPrivateSizes;
+ ptr = (char *)(ppriv + extensionPrivateLen);
+ for (i = extensionPrivateLen; --i >= 0; ppriv++, sizes++)
+ {
+ if ( (size = *sizes) )
+ {
+ ppriv->ptr = (pointer)ptr;
+ ptr += size;
+ }
+ else
+ ppriv->ptr = (pointer)NULL;
+ }
+ return 1;
+}
+
_X_EXPORT ExtensionEntry *
AddExtension(char *name, int NumEvents, int NumErrors,
int (*MainProc)(ClientPtr c1),
@@ -94,8 +128,8 @@ AddExtension(char *name, int NumEvents, int NumErrors,
(unsigned)(lastError + NumErrors > LAST_ERROR))
return((ExtensionEntry *) NULL);
- ext = (ExtensionEntry *) xalloc(sizeof(ExtensionEntry));
- if (!ext)
+ ext = (ExtensionEntry *) xalloc(totalExtensionSize);
+ if (!ext || !InitExtensionPrivates(ext))
return((ExtensionEntry *) NULL);
ext->name = (char *)xalloc(strlen(name) + 1);
ext->num_aliases = 0;
diff --git a/dix/main.c b/dix/main.c
index 9d66a4fa8..e8039e9c3 100644
--- a/dix/main.c
+++ b/dix/main.c
@@ -357,6 +357,7 @@ main(int argc, char *argv[], char *envp[])
InitAtoms();
InitEvents();
InitGlyphCaching();
+ ResetExtensionPrivates();
ResetClientPrivates();
ResetScreenPrivates();
ResetWindowPrivates();
diff --git a/dix/privates.c b/dix/privates.c
index 0c94ff54d..f2ceaf8c6 100644
--- a/dix/privates.c
+++ b/dix/privates.c
@@ -45,6 +45,7 @@ from The Open Group.
#include "servermd.h"
#include "site.h"
#include "inputstr.h"
+#include "extnsionst.h"
/*
* See the Wrappers and devPrivates section in "Definition of the
@@ -53,6 +54,63 @@ from The Open Group.
*/
/*
+ * extension private machinery
+ */
+
+static int extensionPrivateCount;
+int extensionPrivateLen;
+unsigned *extensionPrivateSizes;
+unsigned totalExtensionSize;
+
+void
+ResetExtensionPrivates()
+{
+ extensionPrivateCount = 0;
+ extensionPrivateLen = 0;
+ xfree(extensionPrivateSizes);
+ extensionPrivateSizes = (unsigned *)NULL;
+ totalExtensionSize =
+ ((sizeof(ExtensionEntry) + sizeof(long) - 1) / sizeof(long)) * sizeof(long);
+}
+
+_X_EXPORT int
+AllocateExtensionPrivateIndex()
+{
+ return extensionPrivateCount++;
+}
+
+_X_EXPORT Bool
+AllocateExtensionPrivate(int index2, unsigned amount)
+{
+ unsigned oldamount;
+
+ /* Round up sizes for proper alignment */
+ amount = ((amount + (sizeof(long) - 1)) / sizeof(long)) * sizeof(long);
+
+ if (index2 >= extensionPrivateLen)
+ {
+ unsigned *nsizes;
+ nsizes = (unsigned *)xrealloc(extensionPrivateSizes,
+ (index2 + 1) * sizeof(unsigned));
+ if (!nsizes)
+ return FALSE;
+ while (extensionPrivateLen <= index2)
+ {
+ nsizes[extensionPrivateLen++] = 0;
+ totalExtensionSize += sizeof(DevUnion);
+ }
+ extensionPrivateSizes = nsizes;
+ }
+ oldamount = extensionPrivateSizes[index2];
+ if (amount > oldamount)
+ {
+ extensionPrivateSizes[index2] = amount;
+ totalExtensionSize += (amount - oldamount);
+ }
+ return TRUE;
+}
+
+/*
* client private machinery
*/
diff --git a/include/extension.h b/include/extension.h
index 613076dea..c3d7c2183 100644
--- a/include/extension.h
+++ b/include/extension.h
@@ -60,6 +60,8 @@ extern Bool EnableDisableExtension(char *name, Bool enable);
extern void EnableDisableExtensionError(char *name, Bool enable);
+extern void ResetExtensionPrivates(void);
+
extern void InitExtensions(int argc, char **argv);
extern void InitVisualWrap(void);
diff --git a/include/extnsionst.h b/include/extnsionst.h
index a86e52cbf..35aa97e1a 100644
--- a/include/extnsionst.h
+++ b/include/extnsionst.h
@@ -50,6 +50,7 @@ SOFTWARE.
#ifndef EXTENSIONSTRUCT_H
#define EXTENSIONSTRUCT_H
+#include "dix.h"
#include "misc.h"
#include "screenint.h"
#include "extension.h"
@@ -70,6 +71,7 @@ typedef struct _ExtensionEntry {
pointer extPrivate;
unsigned short (* MinorOpcode)( /* called for errors */
ClientPtr /* client */);
+ DevUnion *devPrivates;
#ifdef XACE
pointer securityState[4]; /* 4 slots for use */
#endif