summaryrefslogtreecommitdiff
path: root/dix
diff options
context:
space:
mode:
authorOlivier Fourdan <ofourdan@redhat.com>2015-07-07 18:19:50 +0200
committerKeith Packard <keithp@keithp.com>2015-08-24 00:00:18 -0700
commitd206c240c0b85c4da44f073d6e9a692afb6b96d2 (patch)
tree31eebed4e7b51c3e83c243046f707982f9c88ae5 /dix
parent7ecdfbf0af3547295b245efa754123db65cabb43 (diff)
configurable maximum number of clients
Make the maximum number of clients user configurable, either from the command line or from xorg.conf This patch works by using the MAXCLIENTS (raised to 512) as the maximum allowed number of clients, but allowing the actual limit to be set by the user to a lower value (keeping the default of 256). There is a limit size of 29 bits to be used to store both the client ID and the X resources ID, so by reducing the number of clients allowed to connect to the X server, the user can increase the number of X resources per client or vice-versa. Parts of this patch are based on a similar patch from Adam Jackson <ajax@redhat.com> This now requires at least xproto 7.0.28 Signed-off-by: Adam Jackson <ajax@redhat.com> Signed-off-by: Olivier Fourdan <ofourdan@redhat.com> Reviewed-by: Adam Jackson <ajax@redhat.com> Signed-off-by: Keith Packard <keithp@keithp.com>
Diffstat (limited to 'dix')
-rw-r--r--dix/colormap.c28
-rw-r--r--dix/dispatch.c4
-rw-r--r--dix/main.c2
-rw-r--r--dix/resource.c33
4 files changed, 45 insertions, 22 deletions
diff --git a/dix/colormap.c b/dix/colormap.c
index 89a17c43b..12a85b256 100644
--- a/dix/colormap.c
+++ b/dix/colormap.c
@@ -252,7 +252,7 @@ CreateColormap(Colormap mid, ScreenPtr pScreen, VisualPtr pVisual,
size = pVisual->ColormapEntries;
sizebytes = (size * sizeof(Entry)) +
- (MAXCLIENTS * sizeof(Pixel *)) + (MAXCLIENTS * sizeof(int));
+ (LimitClients * sizeof(Pixel *)) + (LimitClients * sizeof(int));
if ((class | DynamicClass) == DirectColor)
sizebytes *= 3;
sizebytes += sizeof(ColormapRec);
@@ -277,7 +277,7 @@ CreateColormap(Colormap mid, ScreenPtr pScreen, VisualPtr pVisual,
sizebytes = size * sizeof(Entry);
pmap->clientPixelsRed = (Pixel **) ((char *) pmap->red + sizebytes);
pmap->numPixelsRed = (int *) ((char *) pmap->clientPixelsRed +
- (MAXCLIENTS * sizeof(Pixel *)));
+ (LimitClients * sizeof(Pixel *)));
pmap->mid = mid;
pmap->flags = 0; /* start out with all flags clear */
if (mid == pScreen->defColormap)
@@ -289,8 +289,8 @@ CreateColormap(Colormap mid, ScreenPtr pScreen, VisualPtr pVisual,
size = NUMRED(pVisual);
pmap->freeRed = size;
memset((char *) pmap->red, 0, (int) sizebytes);
- memset((char *) pmap->numPixelsRed, 0, MAXCLIENTS * sizeof(int));
- for (pptr = &pmap->clientPixelsRed[MAXCLIENTS];
+ memset((char *) pmap->numPixelsRed, 0, LimitClients * sizeof(int));
+ for (pptr = &pmap->clientPixelsRed[LimitClients];
--pptr >= pmap->clientPixelsRed;)
*pptr = (Pixel *) NULL;
if (alloc == AllocAll) {
@@ -313,26 +313,26 @@ CreateColormap(Colormap mid, ScreenPtr pScreen, VisualPtr pVisual,
if ((class | DynamicClass) == DirectColor) {
pmap->freeGreen = NUMGREEN(pVisual);
pmap->green = (EntryPtr) ((char *) pmap->numPixelsRed +
- (MAXCLIENTS * sizeof(int)));
+ (LimitClients * sizeof(int)));
pmap->clientPixelsGreen = (Pixel **) ((char *) pmap->green + sizebytes);
pmap->numPixelsGreen = (int *) ((char *) pmap->clientPixelsGreen +
- (MAXCLIENTS * sizeof(Pixel *)));
+ (LimitClients * sizeof(Pixel *)));
pmap->freeBlue = NUMBLUE(pVisual);
pmap->blue = (EntryPtr) ((char *) pmap->numPixelsGreen +
- (MAXCLIENTS * sizeof(int)));
+ (LimitClients * sizeof(int)));
pmap->clientPixelsBlue = (Pixel **) ((char *) pmap->blue + sizebytes);
pmap->numPixelsBlue = (int *) ((char *) pmap->clientPixelsBlue +
- (MAXCLIENTS * sizeof(Pixel *)));
+ (LimitClients * sizeof(Pixel *)));
memset((char *) pmap->green, 0, (int) sizebytes);
memset((char *) pmap->blue, 0, (int) sizebytes);
memmove((char *) pmap->clientPixelsGreen,
- (char *) pmap->clientPixelsRed, MAXCLIENTS * sizeof(Pixel *));
+ (char *) pmap->clientPixelsRed, LimitClients * sizeof(Pixel *));
memmove((char *) pmap->clientPixelsBlue,
- (char *) pmap->clientPixelsRed, MAXCLIENTS * sizeof(Pixel *));
- memset((char *) pmap->numPixelsGreen, 0, MAXCLIENTS * sizeof(int));
- memset((char *) pmap->numPixelsBlue, 0, MAXCLIENTS * sizeof(int));
+ (char *) pmap->clientPixelsRed, LimitClients * sizeof(Pixel *));
+ memset((char *) pmap->numPixelsGreen, 0, LimitClients * sizeof(int));
+ memset((char *) pmap->numPixelsBlue, 0, LimitClients * sizeof(int));
/* If every cell is allocated, mark its refcnt */
if (alloc == AllocAll) {
@@ -416,7 +416,7 @@ FreeColormap(void *value, XID mid)
(*pmap->pScreen->DestroyColormap) (pmap);
if (pmap->clientPixelsRed) {
- for (i = 0; i < MAXCLIENTS; i++)
+ for (i = 0; i < LimitClients; i++)
free(pmap->clientPixelsRed[i]);
}
@@ -434,7 +434,7 @@ FreeColormap(void *value, XID mid)
}
}
if ((pmap->class | DynamicClass) == DirectColor) {
- for (i = 0; i < MAXCLIENTS; i++) {
+ for (i = 0; i < LimitClients; i++) {
free(pmap->clientPixelsGreen[i]);
free(pmap->clientPixelsBlue[i]);
}
diff --git a/dix/dispatch.c b/dix/dispatch.c
index dbbac8bd6..2c201245a 100644
--- a/dix/dispatch.c
+++ b/dix/dispatch.c
@@ -3484,7 +3484,7 @@ NextAvailableClient(void *ospriv)
xReq data;
i = nextFreeClientID;
- if (i == MAXCLIENTS)
+ if (i == LimitClients)
return (ClientPtr) NULL;
clients[i] = client =
dixAllocateObjectWithPrivates(ClientRec, PRIVATE_CLIENT);
@@ -3504,7 +3504,7 @@ NextAvailableClient(void *ospriv)
}
if (i == currentMaxClients)
currentMaxClients++;
- while ((nextFreeClientID < MAXCLIENTS) && clients[nextFreeClientID])
+ while ((nextFreeClientID < LimitClients) && clients[nextFreeClientID])
nextFreeClientID++;
/* Enable client ID tracking. This must be done before
diff --git a/dix/main.c b/dix/main.c
index db3b9c0a9..d7a9cdaae 100644
--- a/dix/main.c
+++ b/dix/main.c
@@ -165,7 +165,7 @@ dix_main(int argc, char *argv[], char *envp[])
OsInit();
if (serverGeneration == 1) {
CreateWellKnownSockets();
- for (i = 1; i < MAXCLIENTS; i++)
+ for (i = 1; i < LimitClients; i++)
clients[i] = NullClient;
serverClient = calloc(sizeof(ClientRec), 1);
if (!serverClient)
diff --git a/dix/resource.c b/dix/resource.c
index af8e162bb..ad71b2437 100644
--- a/dix/resource.c
+++ b/dix/resource.c
@@ -600,6 +600,29 @@ CreateNewResourceClass(void)
static ClientResourceRec clientTable[MAXCLIENTS];
+static unsigned int
+ilog2(int val)
+{
+ int bits;
+
+ if (val <= 0)
+ return 0;
+ for (bits = 0; val != 0; bits++)
+ val >>= 1;
+ return bits - 1;
+}
+
+/*****************
+ * ResourceClientBits
+ * Returns the client bit offset in the client + resources ID field
+ *****************/
+
+unsigned int
+ResourceClientBits(void)
+{
+ return (ilog2(LimitClients));
+}
+
/*****************
* InitClientResources
* When a new client is created, call this to allocate space
@@ -883,7 +906,7 @@ FreeResource(XID id, RESTYPE skipDeleteFuncType)
int *eltptr;
int elements;
- if (((cid = CLIENT_ID(id)) < MAXCLIENTS) && clientTable[cid].buckets) {
+ if (((cid = CLIENT_ID(id)) < LimitClients) && clientTable[cid].buckets) {
head = &clientTable[cid].resources[HashResourceID(id, clientTable[cid].hashsize)];
eltptr = &clientTable[cid].elements;
@@ -917,7 +940,7 @@ FreeResourceByType(XID id, RESTYPE type, Bool skipFree)
ResourcePtr res;
ResourcePtr *prev, *head;
- if (((cid = CLIENT_ID(id)) < MAXCLIENTS) && clientTable[cid].buckets) {
+ if (((cid = CLIENT_ID(id)) < LimitClients) && clientTable[cid].buckets) {
head = &clientTable[cid].resources[HashResourceID(id, clientTable[cid].hashsize)];
prev = head;
@@ -952,7 +975,7 @@ ChangeResourceValue(XID id, RESTYPE rtype, void *value)
int cid;
ResourcePtr res;
- if (((cid = CLIENT_ID(id)) < MAXCLIENTS) && clientTable[cid].buckets) {
+ if (((cid = CLIENT_ID(id)) < LimitClients) && clientTable[cid].buckets) {
res = clientTable[cid].resources[HashResourceID(id, clientTable[cid].hashsize)];
for (; res; res = res->next)
@@ -1190,7 +1213,7 @@ dixLookupResourceByType(void **result, XID id, RESTYPE rtype,
if ((rtype & TypeMask) > lastResourceType)
return BadImplementation;
- if ((cid < MAXCLIENTS) && clientTable[cid].buckets) {
+ if ((cid < LimitClients) && clientTable[cid].buckets) {
res = clientTable[cid].resources[HashResourceID(id, clientTable[cid].hashsize)];
for (; res; res = res->next)
@@ -1223,7 +1246,7 @@ dixLookupResourceByClass(void **result, XID id, RESTYPE rclass,
*result = NULL;
- if ((cid < MAXCLIENTS) && clientTable[cid].buckets) {
+ if ((cid < LimitClients) && clientTable[cid].buckets) {
res = clientTable[cid].resources[HashResourceID(id, clientTable[cid].hashsize)];
for (; res; res = res->next)