6488392 PSARC 2006/609: Xserver provider for DTrace nv_53
authorAlan Coopersmith <Alan.Coopersmith@Sun.COM>
Tue, 07 Nov 2006 14:27:40 -0800
changeset 81 dc9eae1b23dd
parent 80 59eb925d41b1
child 82 096dcca64c6b
6488392 PSARC 2006/609: Xserver provider for DTrace
XORG_NV/sun-src/xc/config/cf/host.def
XORG_NV/sun-src/xc/programs/Xserver/Imakefile
XORG_NV/sun-src/xc/programs/Xserver/Xserver.d
XORG_NV/sun-src/xc/programs/Xserver/dix/Imakefile
XORG_NV/sun-src/xc/programs/Xserver/dix/dispatch.c
XORG_NV/sun-src/xc/programs/Xserver/dix/events.c
XORG_NV/sun-src/xc/programs/Xserver/dix/extension.c
XORG_NV/sun-src/xc/programs/Xserver/dix/localdefines
XORG_NV/sun-src/xc/programs/Xserver/dix/localmacros
XORG_NV/sun-src/xc/programs/Xserver/dix/resource.c
XORG_NV/sun-src/xc/programs/Xserver/os/Imakefile
XORG_NV/sun-src/xc/programs/Xserver/os/connection.c
XORG_NV/sun-src/xc/programs/Xserver/os/localdefines
--- a/XORG_NV/sun-src/xc/config/cf/host.def	Thu Nov 02 17:37:06 2006 -0800
+++ b/XORG_NV/sun-src/xc/config/cf/host.def	Tue Nov 07 14:27:40 2006 -0800
@@ -29,13 +29,14 @@
 XCOMM
 XCOMM #########################################################################
 XCOMM
-XCOMM ident	"@(#)host.def	1.47	06/10/25 SMI"
+XCOMM ident	"@(#)host.def	1.48	06/11/07 SMI"
 XCOMM
 
 /* Settings for official Solaris package builds */
 
 #define SunSolarisXorgBuilds	YES
 #define BuildLikeSun		YES
+#define BuildDTraceSupport	YES
 
 #ifndef LibManSuffix
 #define LibManSuffix		3
--- a/XORG_NV/sun-src/xc/programs/Xserver/Imakefile	Thu Nov 02 17:37:06 2006 -0800
+++ b/XORG_NV/sun-src/xc/programs/Xserver/Imakefile	Tue Nov 07 14:27:40 2006 -0800
@@ -10,13 +10,18 @@
 #endif
 #define InstallServerSetUID InstallXserverSetUID
 
+#if BuildDTraceSupport
+DTRACE_OBJ = Xserver-dtrace.o
+SITEEXTS = $(DTRACE_OBJ)
+#endif
+
 #include <Server.tmpl>
 
 /* On most systems the linker requires the libraries in dependency order. 
    But we have no real order because there are cycles. We fix this by adding
    some libraries twice on the commandline. dependLib will add the 
    dependency library to the commandline if the link order is important */ 
-#if 1 /* This is currently enabled for all systems */
+#if !defined(SunArchitecture) /* SUNSOFT: Disabled for Solaris builds */
 #define dependLib(x) x
 #else
 #define dependLib(x)
@@ -233,7 +238,11 @@
 #if BuildLBX || GzipFontCompression
            ZLIB = GzipLibrary
 #endif
+#if BuildDTraceSupport
+             OS = os/os.Osuf
+#else
              OS = os/LibraryTargetName(os)
+#endif
         BSDEMUL = $(DEPXBSDLIB)
 #if DoLoadableServer
             MFB = mfb/ModuleLibraryTargetName(mfb)
@@ -295,7 +304,11 @@
              MI = mi/LibraryTargetName(mi)
 #endif
    MIINITEXTOBJ = mi/miinitext.o
+#if BuildDTraceSupport
+            DIX = dix/dix.Osuf
+#else
             DIX = dix/LibraryTargetName(dix)
+#endif
        FONTBASE = $(FONTLIBSRC)/fontbase.o \
 		  $(FONTLIBSRC)/LibraryTargetName(fontbase)
 #if XserverStaticFontLib
@@ -1243,3 +1256,20 @@
                 MakeNamedTargetSubdir($$i,NullParameter,all) ; \
         done
 #endif
+
+#if BuildDTraceSupport
+XCOMM DTrace magic
+
+DTRACE_SRC = Xserver.d
+DTRACE_MODULES = $(DIX) $(OS)
+
+# if defined(Sparc64Architecture) || defined(AMD64Architecture)
+DTRACE_BITS = -64
+# else
+DTRACE_BITS = -32
+# endif
+
+$(DTRACE_OBJ): $(DTRACE_SRC) $(DTRACE_MODULES)
+	dtrace -G -C $(DTRACE_BITS) -s $(DTRACE_SRC) -o $(DTRACE_OBJ) $(DTRACE_MODULES)
+
+#endif
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/XORG_NV/sun-src/xc/programs/Xserver/Xserver.d	Tue Nov 07 14:27:40 2006 -0800
@@ -0,0 +1,59 @@
+/* Copyright 2005-2006 Sun Microsystems, Inc.  All rights reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the
+ * "Software"), to deal in the Software without restriction, including
+ * without limitation the rights to use, copy, modify, merge, publish,
+ * distribute, and/or sell copies of the Software, and to permit persons
+ * to whom the Software is furnished to do so, provided that the above
+ * copyright notice(s) and this permission notice appear in all copies of
+ * the Software and that both the above copyright notice(s) and this
+ * permission notice appear in supporting documentation.
+ * 
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+ * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT
+ * OF THIRD PARTY RIGHTS. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
+ * HOLDERS INCLUDED IN THIS NOTICE BE LIABLE FOR ANY CLAIM, OR ANY SPECIAL
+ * INDIRECT OR CONSEQUENTIAL DAMAGES, OR ANY DAMAGES WHATSOEVER RESULTING
+ * FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
+ * NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION
+ * WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ * 
+ * Except as contained in this notice, the name of a copyright holder
+ * shall not be used in advertising or otherwise to promote the sale, use
+ * or other dealings in this Software without prior written authorization
+ * of the copyright holder.
+ */
+
+/*
+ * Xserver dtrace provider definition
+ */
+
+#include <sys/types.h>
+
+provider Xserver {
+	/* reqType, data, length, client id, request buffer */
+	probe request__start(string, uint8_t, uint16_t, int, void *);
+	/* reqType, data, sequence, client id, result */
+	probe request__done(string, uint8_t, uint32_t, int, int);
+	/* client id, client fd */
+	probe client__connect(int, int);
+	/* client id, client address, client pid, client zone id */
+	probe client__auth(int, string, pid_t, zoneid_t);
+	/* client id */
+	probe client__disconnect(int);
+	/* resource id, resource type, value, resource type name */
+	probe resource__alloc(uint32_t, uint32_t, void *, string);
+	/* resource id, resource type, value, resource type name */
+	probe resource__free(uint32_t, uint32_t, void *, string);
+	/* client id, event type, event* */
+	probe send__event(int, uint8_t, void *);
+};
+
+#pragma D attributes Unstable/Unstable/Common provider Xserver provider
+#pragma D attributes Private/Private/Unknown  provider Xserver module
+#pragma D attributes Private/Private/Unknown  provider Xserver function
+#pragma D attributes Unstable/Unstable/Common provider Xserver name
+#pragma D attributes Unstable/Unstable/Common provider Xserver args
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/XORG_NV/sun-src/xc/programs/Xserver/dix/Imakefile	Tue Nov 07 14:27:40 2006 -0800
@@ -0,0 +1,101 @@
+XCOMM $Xorg: Imakefile,v 1.3 2000/08/17 19:48:16 cpqbld Exp $
+
+
+
+
+XCOMM $XFree86: xc/programs/Xserver/dix/Imakefile,v 3.17 2003/04/15 18:30:43 alanh Exp $
+
+#include <Server.tmpl>
+
+#if !BuildXprint || PrintOnlyServer
+XPSRC = xpstubs.c
+XPOBJ = xpstubs.o
+#endif
+
+#if !HasFfs
+FFS_SRC = ffs.c
+FFS_OBJ = ffs.o
+#endif
+
+SRCS = atom.c colormap.c cursor.c devices.c dispatch.c dixutils.c events.c \
+	extension.c gc.c globals.c glyphcurs.c grabs.c \
+	main.c property.c resource.c swaprep.c swapreq.c \
+	tables.c window.c initatoms.c dixfonts.c privates.c pixmap.c $(FFS_SRC)
+OBJS = atom.o colormap.o cursor.o devices.o dispatch.o dixutils.o events.o \
+	extension.o gc.o globals.o glyphcurs.o grabs.o \
+	main.o property.o resource.o swaprep.o swapreq.o \
+	tables.o window.o initatoms.o dixfonts.o privates.o pixmap.o $(FFS_OBJ)
+
+    INCLUDES = -I../include -I$(XINCLUDESRC) -I$(FONTINCSRC) -I$(EXTINCSRC) \
+	       -I$(SERVERSRC)/Xext -I$(SERVERSRC)/lbx -I../Xprint
+    LINTLIBS = ../os/llib-los.ln
+
+/*
+ * The following configuration parameters may be set in the appropriate
+ * .macros files or site.def in the directory util/imake.includes/:
+ *
+ *     DefaultFontPath                COMPILEDDEFAULTFONTPATH
+ *     DefaultRGBDatabase             RGB_DB
+ *
+ * The sample util/imake.includes/Imake.tmpl will provide generic defaults.
+ * The values in site.h are simply a last line of defense and should not be
+ * changed.
+ */
+
+#ifdef DefaultFontPath
+DEFAULTFONTPATH = DefaultFontPath
+SITE_FONT_PATH = -DCOMPILEDDEFAULTFONTPATH=\"$(DEFAULTFONTPATH)\"
+#endif
+
+#ifdef DefaultRGBDatabase
+DEFAULTRGBDATABASE = DefaultRGBDatabase
+   SITE_RGB_DB = -DRGB_DB=\"$(DEFAULTRGBDATABASE)\"
+#endif
+
+#ifdef DefaultDisplayClass
+DEFAULTDISPLAYCLASS = DefaultDisplayClass
+   SITE_DISPLAY_CLASS = -DCOMPILEDDISPLAYCLASS=\"$(DEFAULTDISPLAYCLASS)\"
+#endif
+
+#ifdef XVendorString
+VENDORSTRING = XVendorString
+   VENDOR_STRING = -DVENDOR_STRING=\"$(VENDORSTRING)\"
+#endif
+
+#ifdef XVendorRelease
+VENDORRELEASE = XVendorRelease
+   VENDOR_RELEASE = -DVENDOR_RELEASE="$(VENDORRELEASE)"
+#endif
+
+#if HasKrb5
+         K5DEFS = Krb5Defines
+#endif
+
+#ifdef DarwinArchitecture
+#if DarwinQuartzSupport
+    QUARTZ_DEFINES = -DDARWIN_WITH_QUARTZ
+#endif
+#endif
+
+SITE_DEFINES = $(SITE_FONT_PATH) $(SITE_RGB_DB) $(SITE_DISPLAY_CLASS)
+
+VENDOR_DEFINES = $(VENDOR_STRING) $(VENDOR_RELEASE) $(QUARTZ_DEFINES)
+
+NormalLibraryObjectRule()
+NormalRelocatableTarget(dix,$(OBJS))
+LintLibraryTarget(dix,$(SRCS) $(XPSRC))
+NormalLintTarget($(SRCS) $(XPSRC))
+
+SpecialCObjectRule(globals,$(ICONFIGFILES),$(SITE_DEFINES))
+SpecialCObjectRule(tables,$(ICONFIGFILES),$(K5DEFS))
+SpecialCObjectRule(dispatch,$(ICONFIGFILES),$(K5DEFS))
+SpecialCObjectRule(main,$(ICONFIGFILES),$(VENDOR_DEFINES))
+SpecialCObjectRule(pixmap,$(ICONFIGFILES),$(_NOOP_))
+SpecialCObjectRule(privates,$(ICONFIGFILES),$(_NOOP_))
+SpecialCObjectRule(window,$(ICONFIGFILES),$(QUARTZ_DEFINES))
+
+#if !BuildXprint || PrintOnlyServer
+NormalLibraryTarget(xpstubs,$(XPOBJ))
+#endif
+
+DependTarget()
--- a/XORG_NV/sun-src/xc/programs/Xserver/dix/dispatch.c	Thu Nov 02 17:37:06 2006 -0800
+++ b/XORG_NV/sun-src/xc/programs/Xserver/dix/dispatch.c	Tue Nov 07 14:27:40 2006 -0800
@@ -150,6 +150,17 @@
 #include "lbxserve.h"
 #endif
 
+#ifdef XSERVER_DTRACE
+#include <sys/types.h>
+typedef const char *string;
+#include "Xserver-dtrace.h"
+
+char *RequestNames[256];
+static void LoadRequestNames(void);
+static void FreeRequestNames(void);
+#define GetRequestName(i) (RequestNames[i])
+#endif
+
 #define mskcnt ((MAXCLIENTS + 31) / 32)
 #define BITMASK(i) (1U << ((i) & 31))
 #define MASKIDX(i) ((i) >> 5)
@@ -408,6 +419,10 @@
     if (!clientReady)
 	return;
 
+#ifdef XSERVER_DTRACE
+    LoadRequestNames();
+#endif
+
     while (!dispatchException)
     {
         if (*icheck[0] != *icheck[1])
@@ -484,6 +499,11 @@
 		client->requestLog[client->requestLogIndex] = MAJOROP;
 		client->requestLogIndex++;
 #endif
+#ifdef XSERVER_DTRACE
+		XSERVER_REQUEST_START(GetRequestName(MAJOROP), MAJOROP,
+			      ((xReq *)client->requestBuffer)->length,
+			      client->index, client->requestBuffer);
+#endif
 		if (result > (maxBigRequestSize << 2))
 		    result = BadLength;
 		else
@@ -498,6 +518,10 @@
 #else
                     result = (* client->requestVector[MAJOROP])(client);
 #endif /* TSOL */
+#ifdef XSERVER_DTRACE
+		XSERVER_REQUEST_DONE(GetRequestName(MAJOROP), MAJOROP,
+			      client->sequence, client->index, result);
+#endif
 
 		if (result != Success) 
 		{
@@ -529,6 +553,9 @@
     KillAllClients();
     DEALLOCATE_LOCAL(clientReady);
     dispatchException &= ~DE_RESET;
+#ifdef XSERVER_DTRACE
+    FreeRequestNames();
+#endif
 }
 
 #undef MAJOROP
@@ -3653,6 +3680,9 @@
 	    CallCallbacks((&ClientStateCallback), (pointer)&clientinfo);
 	} 	    
 	FreeClientResources(client);
+#ifdef XSERVER_DTRACE
+	XSERVER_CLIENT_DISCONNECT(client->index);
+#endif	
 	if (client->index < nextFreeClientID)
 	    nextFreeClientID = client->index;
 	clients[client->index] = NullClient;
@@ -4083,3 +4113,60 @@
 {
     client->noClientException = -1;
 }
+
+#ifdef XSERVER_DTRACE
+#include <ctype.h>
+
+/* Load table of request names for dtrace probes */
+static void LoadRequestNames(void)
+{
+    int i;
+    FILE *xedb;
+    extern void LoadExtensionNames(char **RequestNames);
+
+    bzero(RequestNames, 256 * sizeof(char *));
+
+    xedb = fopen(XERRORDB_PATH, "r");
+    if (xedb != NULL) {
+	char buf[256];
+	while (fgets(buf, sizeof(buf), xedb)) {
+	    if ((strncmp("XRequest.", buf, 9) == 0) && (isdigit(buf[9]))) {
+		char *name;
+		i = strtol(buf + 9, &name, 10);
+		if (RequestNames[i] == 0) {
+		    char *end = strchr(name, '\n');
+		    if (end) { *end = '\0'; }
+		    RequestNames[i] = strdup(name + 1);
+		}
+	    }
+	}
+	fclose(xedb);
+    }
+
+    LoadExtensionNames(RequestNames);
+
+    for (i = 0; i < 256; i++) {
+	if (RequestNames[i] == 0) {
+#define RN_SIZE 12 /* "Request#' + up to 3 digits + \0 */
+	    RequestNames[i] = xalloc(RN_SIZE);
+	    if (RequestNames[i]) {
+		snprintf(RequestNames[i], RN_SIZE, "Request#%d", i);
+	    }
+	}
+	/* fprintf(stderr, "%d: %s\n", i, RequestNames[i]); */
+    }
+}
+
+static void FreeRequestNames(void)
+{
+    int i;
+
+    for (i = 0; i < 256; i++) {
+	if (RequestNames[i] != 0) {
+	    free(RequestNames[i]);
+	    RequestNames[i] = 0;
+	}
+    }
+}
+
+#endif
--- a/XORG_NV/sun-src/xc/programs/Xserver/dix/events.c	Thu Nov 02 17:37:06 2006 -0800
+++ b/XORG_NV/sun-src/xc/programs/Xserver/dix/events.c	Tue Nov 07 14:27:40 2006 -0800
@@ -138,6 +138,12 @@
 #include <X11/extensions/security.h>
 #endif
 
+#ifdef XSERVER_DTRACE
+#include <sys/types.h>
+typedef const char *string;
+#include "Xserver-dtrace.h"
+#endif
+
 #ifdef XEVIE
 extern WindowPtr *WindowTable;
 extern int       xevieFlag;
@@ -4664,6 +4670,14 @@
 	eventinfo.count = count;
 	CallCallbacks(&EventCallback, (pointer)&eventinfo);
     }
+#ifdef XSERVER_DTRACE
+    if (XSERVER_SEND_EVENT_ENABLED()) {
+	for (i = 0; i < count; i++)
+	{
+	    XSERVER_SEND_EVENT(pClient->index, events[i].u.u.type, &events[i]);
+	}
+    }
+#endif	
     if(pClient->swapped)
     {
 	for(i = 0; i < count; i++)
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/XORG_NV/sun-src/xc/programs/Xserver/dix/extension.c	Tue Nov 07 14:27:40 2006 -0800
@@ -0,0 +1,488 @@
+/* $XFree86: xc/programs/Xserver/dix/extension.c,v 3.11 2001/12/14 19:59:31 dawes Exp $ */
+/***********************************************************
+
+Copyright 1987, 1998  The Open Group
+
+Permission to use, copy, modify, distribute, and sell this software and its
+documentation for any purpose is hereby granted without fee, provided that
+the above copyright notice appear in all copies and that both that
+copyright notice and this permission notice appear in supporting
+documentation.
+
+The above copyright notice and this permission notice shall be included in
+all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
+OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
+AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+
+Except as contained in this notice, the name of The Open Group shall not be
+used in advertising or otherwise to promote the sale, use or other dealings
+in this Software without prior written authorization from The Open Group.
+
+
+Copyright 1987 by Digital Equipment Corporation, Maynard, Massachusetts.
+
+                        All Rights Reserved
+
+Permission to use, copy, modify, and distribute this software and its 
+documentation for any purpose and without fee is hereby granted, 
+provided that the above copyright notice appear in all copies and that
+both that copyright notice and this permission notice appear in 
+supporting documentation, and that the name of Digital not be
+used in advertising or publicity pertaining to distribution of the
+software without specific, written prior permission.  
+
+DIGITAL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
+ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
+DIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
+ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
+WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
+ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
+SOFTWARE.
+
+******************************************************************/
+/* $Xorg: extension.c,v 1.4 2001/02/09 02:04:40 xorgcvs Exp $ */
+
+#ifdef HAVE_DIX_CONFIG_H
+#include <dix-config.h>
+#endif
+
+#include <X11/X.h>
+#define NEED_EVENTS
+#define NEED_REPLIES
+#include <X11/Xproto.h>
+#include "misc.h"
+#include "dixstruct.h"
+#include "extnsionst.h"
+#include "gcstruct.h"
+#include "scrnintstr.h"
+#include "dispatch.h"
+#ifdef XCSECURITY
+#define _SECURITY_SERVER
+#include <X11/extensions/security.h>
+#endif
+#ifdef LBX
+#include "lbxserve.h"
+#endif
+
+#define EXTENSION_BASE  128
+#define EXTENSION_EVENT_BASE  64
+#define LAST_EVENT  128
+#define LAST_ERROR 255
+
+ScreenProcEntry AuxillaryScreenProcs[MAXSCREENS];
+
+static ExtensionEntry **extensions = (ExtensionEntry **)NULL;
+
+int lastEvent = EXTENSION_EVENT_BASE;
+static int lastError = FirstExtensionError;
+static unsigned int NumExtensions = 0;
+
+ExtensionEntry *
+AddExtension(char *name, int NumEvents, int NumErrors, 
+	     int (*MainProc)(ClientPtr c1), 
+	     int (*SwappedMainProc)(ClientPtr c2), 
+	     void (*CloseDownProc)(ExtensionEntry *e), 
+	     unsigned short (*MinorOpcodeProc)(ClientPtr c3))
+{
+    int i;
+    register ExtensionEntry *ext, **newexts;
+
+    if (!MainProc || !SwappedMainProc || !CloseDownProc || !MinorOpcodeProc)
+        return((ExtensionEntry *) NULL);
+    if ((lastEvent + NumEvents > LAST_EVENT) || 
+	        (unsigned)(lastError + NumErrors > LAST_ERROR))
+        return((ExtensionEntry *) NULL);
+
+    ext = (ExtensionEntry *) xalloc(sizeof(ExtensionEntry));
+    if (!ext)
+	return((ExtensionEntry *) NULL);
+    ext->name = (char *)xalloc(strlen(name) + 1);
+    ext->num_aliases = 0;
+    ext->aliases = (char **)NULL;
+    if (!ext->name)
+    {
+	xfree(ext);
+	return((ExtensionEntry *) NULL);
+    }
+    strcpy(ext->name,  name);
+    i = NumExtensions;
+    newexts = (ExtensionEntry **) xrealloc(extensions,
+					   (i + 1) * sizeof(ExtensionEntry *));
+    if (!newexts)
+    {
+	xfree(ext->name);
+	xfree(ext);
+	return((ExtensionEntry *) NULL);
+    }
+    NumExtensions++;
+    extensions = newexts;
+    extensions[i] = ext;
+    ext->index = i;
+    ext->base = i + EXTENSION_BASE;
+    ext->CloseDown = CloseDownProc;
+    ext->MinorOpcode = MinorOpcodeProc;
+    ProcVector[i + EXTENSION_BASE] = MainProc;
+    SwappedProcVector[i + EXTENSION_BASE] = SwappedMainProc;
+    if (NumEvents)
+    {
+        ext->eventBase = lastEvent;
+	ext->eventLast = lastEvent + NumEvents;
+	lastEvent += NumEvents;
+    }
+    else
+    {
+        ext->eventBase = 0;
+        ext->eventLast = 0;
+    }
+    if (NumErrors)
+    {
+        ext->errorBase = lastError;
+	ext->errorLast = lastError + NumErrors;
+	lastError += NumErrors;
+    }
+    else
+    {
+        ext->errorBase = 0;
+        ext->errorLast = 0;
+    }
+#ifdef XCSECURITY
+    ext->secure = FALSE;
+#endif
+
+#ifdef LBX
+    (void) LbxAddExtension(name, ext->base, ext->eventBase, ext->errorBase);
+#endif
+    return(ext);
+}
+
+Bool AddExtensionAlias(char *alias, ExtensionEntry *ext)
+{
+    char *name;
+    char **aliases;
+
+    aliases = (char **)xrealloc(ext->aliases,
+				(ext->num_aliases + 1) * sizeof(char *));
+    if (!aliases)
+	return FALSE;
+    ext->aliases = aliases;
+    name = (char *)xalloc(strlen(alias) + 1);
+    if (!name)
+	return FALSE;
+    strcpy(name,  alias);
+    ext->aliases[ext->num_aliases] = name;
+    ext->num_aliases++;
+#ifdef LBX
+    return LbxAddExtensionAlias(ext->index, alias);
+#else
+    return TRUE;
+#endif
+}
+
+static int
+FindExtension(char *extname, int len)
+{
+    int i, j;
+
+    for (i=0; i<NumExtensions; i++)
+    {
+	if ((strlen(extensions[i]->name) == len) &&
+	    !strncmp(extname, extensions[i]->name, len))
+	    break;
+	for (j = extensions[i]->num_aliases; --j >= 0;)
+	{
+	    if ((strlen(extensions[i]->aliases[j]) == len) &&
+		!strncmp(extname, extensions[i]->aliases[j], len))
+		break;
+	}
+	if (j >= 0) break;
+    }
+    return ((i == NumExtensions) ? -1 : i);
+}
+
+/*
+ * CheckExtension returns the extensions[] entry for the requested
+ * extension name.  Maybe this could just return a Bool instead?
+ */
+ExtensionEntry *
+CheckExtension(const char *extname)
+{
+    int n;
+
+    n = FindExtension((char*)extname, strlen(extname));
+    if (n != -1)
+	return extensions[n];
+    else
+	return NULL;
+}
+
+void
+DeclareExtensionSecurity(char *extname, Bool secure)
+{
+#ifdef XCSECURITY
+    int i = FindExtension(extname, strlen(extname));
+    if (i >= 0)
+    {
+	int majorop = extensions[i]->base;
+	extensions[i]->secure = secure;
+	if (secure)
+	{
+	    UntrustedProcVector[majorop] = ProcVector[majorop];
+	    SwappedUntrustedProcVector[majorop] = SwappedProcVector[majorop];
+	}
+	else
+	{
+	    UntrustedProcVector[majorop]	= ProcBadRequest;
+	    SwappedUntrustedProcVector[majorop] = ProcBadRequest;
+	}
+    }
+#endif
+#ifdef LBX
+    LbxDeclareExtensionSecurity(extname, secure);
+#endif
+}
+
+unsigned short
+StandardMinorOpcode(ClientPtr client)
+{
+    return ((xReq *)client->requestBuffer)->data;
+}
+
+unsigned short
+MinorOpcodeOfRequest(ClientPtr client)
+{
+    unsigned char major;
+
+    major = ((xReq *)client->requestBuffer)->reqType;
+    if (major < EXTENSION_BASE)
+	return 0;
+    major -= EXTENSION_BASE;
+    if (major >= NumExtensions)
+	return 0;
+    return (*extensions[major]->MinorOpcode)(client);
+}
+
+void
+CloseDownExtensions()
+{
+    register int i,j;
+
+#ifdef LBX
+    LbxCloseDownExtensions();
+#endif
+
+    for (i = NumExtensions - 1; i >= 0; i--)
+    {
+	(* extensions[i]->CloseDown)(extensions[i]);
+	NumExtensions = i;
+	xfree(extensions[i]->name);
+	for (j = extensions[i]->num_aliases; --j >= 0;)
+	    xfree(extensions[i]->aliases[j]);
+	xfree(extensions[i]->aliases);
+	xfree(extensions[i]);
+    }
+    xfree(extensions);
+    extensions = (ExtensionEntry **)NULL;
+    lastEvent = EXTENSION_EVENT_BASE;
+    lastError = FirstExtensionError;
+    for (i=0; i<MAXSCREENS; i++)
+    {
+	register ScreenProcEntry *spentry = &AuxillaryScreenProcs[i];
+
+	while (spentry->num)
+	{
+	    spentry->num--;
+	    xfree(spentry->procList[spentry->num].name);
+	}
+	xfree(spentry->procList);
+	spentry->procList = (ProcEntryPtr)NULL;
+    }
+}
+
+
+int
+ProcQueryExtension(ClientPtr client)
+{
+    xQueryExtensionReply reply;
+    int i;
+    REQUEST(xQueryExtensionReq);
+
+    REQUEST_FIXED_SIZE(xQueryExtensionReq, stuff->nbytes);
+    
+    reply.type = X_Reply;
+    reply.length = 0;
+    reply.major_opcode = 0;
+    reply.sequenceNumber = client->sequence;
+
+    if ( ! NumExtensions )
+        reply.present = xFalse;
+    else
+    {
+	i = FindExtension((char *)&stuff[1], stuff->nbytes);
+        if (i < 0
+#ifdef XCSECURITY
+	    /* don't show insecure extensions to untrusted clients */
+	    || (client->trustLevel == XSecurityClientUntrusted &&
+		!extensions[i]->secure)
+#endif
+	    )
+            reply.present = xFalse;
+        else
+        {            
+            reply.present = xTrue;
+	    reply.major_opcode = extensions[i]->base;
+	    reply.first_event = extensions[i]->eventBase;
+	    reply.first_error = extensions[i]->errorBase;
+	}
+    }
+    WriteReplyToClient(client, sizeof(xQueryExtensionReply), &reply);
+    return(client->noClientException);
+}
+
+int
+ProcListExtensions(ClientPtr client)
+{
+    xListExtensionsReply reply;
+    char *bufptr, *buffer;
+    int total_length = 0;
+
+    REQUEST_SIZE_MATCH(xReq);
+
+    reply.type = X_Reply;
+    reply.nExtensions = 0;
+    reply.length = 0;
+    reply.sequenceNumber = client->sequence;
+    buffer = NULL;
+
+    if ( NumExtensions )
+    {
+        register int i, j;
+
+        for (i=0;  i<NumExtensions; i++)
+	{
+#ifdef XCSECURITY
+	    /* don't show insecure extensions to untrusted clients */
+	    if (client->trustLevel == XSecurityClientUntrusted &&
+		!extensions[i]->secure)
+		continue;
+#endif
+	    total_length += strlen(extensions[i]->name) + 1;
+	    reply.nExtensions += 1 + extensions[i]->num_aliases;
+	    for (j = extensions[i]->num_aliases; --j >= 0;)
+		total_length += strlen(extensions[i]->aliases[j]) + 1;
+	}
+        reply.length = (total_length + 3) >> 2;
+	buffer = bufptr = (char *)ALLOCATE_LOCAL(total_length);
+	if (!buffer)
+	    return(BadAlloc);
+        for (i=0;  i<NumExtensions; i++)
+        {
+	    int len;
+#ifdef XCSECURITY
+	    if (client->trustLevel == XSecurityClientUntrusted &&
+		!extensions[i]->secure)
+		continue;
+#endif
+            *bufptr++ = len = strlen(extensions[i]->name);
+	    memmove(bufptr, extensions[i]->name,  len);
+	    bufptr += len;
+	    for (j = extensions[i]->num_aliases; --j >= 0;)
+	    {
+		*bufptr++ = len = strlen(extensions[i]->aliases[j]);
+		memmove(bufptr, extensions[i]->aliases[j],  len);
+		bufptr += len;
+	    }
+	}
+    }
+    WriteReplyToClient(client, sizeof(xListExtensionsReply), &reply);
+    if (reply.length)
+    {
+        WriteToClient(client, total_length, buffer);
+    	DEALLOCATE_LOCAL(buffer);
+    }
+    return(client->noClientException);
+}
+
+
+ExtensionLookupProc 
+LookupProc(char *name, GCPtr pGC)
+{
+    register int i;
+    register ScreenProcEntry *spentry;
+    spentry  = &AuxillaryScreenProcs[pGC->pScreen->myNum];
+    if (spentry->num)    
+    {
+        for (i = 0; i < spentry->num; i++)
+            if (strcmp(name, spentry->procList[i].name) == 0)
+                return(spentry->procList[i].proc);
+    }
+    return (ExtensionLookupProc)NULL;
+}
+
+Bool
+RegisterProc(char *name, GC *pGC, ExtensionLookupProc proc)
+{
+    return RegisterScreenProc(name, pGC->pScreen, proc);
+}
+
+Bool
+RegisterScreenProc(char *name, ScreenPtr pScreen, ExtensionLookupProc proc)
+{
+    register ScreenProcEntry *spentry;
+    register ProcEntryPtr procEntry = (ProcEntryPtr)NULL;
+    char *newname;
+    int i;
+
+    spentry = &AuxillaryScreenProcs[pScreen->myNum];
+    /* first replace duplicates */
+    if (spentry->num)
+    {
+        for (i = 0; i < spentry->num; i++)
+            if (strcmp(name, spentry->procList[i].name) == 0)
+	    {
+                procEntry = &spentry->procList[i];
+		break;
+	    }
+    }
+    if (procEntry)
+        procEntry->proc = proc;
+    else
+    {
+	newname = (char *)xalloc(strlen(name)+1);
+	if (!newname)
+	    return FALSE;
+	procEntry = (ProcEntryPtr)
+			    xrealloc(spentry->procList,
+				     sizeof(ProcEntryRec) * (spentry->num+1));
+	if (!procEntry)
+	{
+	    xfree(newname);
+	    return FALSE;
+	}
+	spentry->procList = procEntry;
+        procEntry += spentry->num;
+        procEntry->name = newname;
+        strcpy(newname, name);
+        procEntry->proc = proc;
+        spentry->num++;        
+    }
+    return TRUE;
+}
+
+#ifdef XSERVER_DTRACE
+void LoadExtensionNames(char **RequestNames) {
+    int i;
+
+    for (i=0; i<NumExtensions; i++) {
+	int r = extensions[i]->base;
+
+	if (RequestNames[r] == NULL) {
+	    RequestNames[r] = strdup(extensions[i]->name);
+	}
+    }
+}
+#endif
--- a/XORG_NV/sun-src/xc/programs/Xserver/dix/localdefines	Thu Nov 02 17:37:06 2006 -0800
+++ b/XORG_NV/sun-src/xc/programs/Xserver/dix/localdefines	Tue Nov 07 14:27:40 2006 -0800
@@ -1,6 +1,6 @@
 XCOMM ########################################################################
 XCOMM
-XCOMM Copyright 2004 Sun Microsystems, Inc.  All rights reserved.
+XCOMM Copyright 2006 Sun Microsystems, Inc.  All rights reserved.
 XCOMM
 XCOMM Permission is hereby granted, free of charge, to any person obtaining a
 XCOMM copy of this software and associated documentation files (the
@@ -29,11 +29,14 @@
 XCOMM
 XCOMM ########################################################################
 XCOMM
-XCOMM ident "@(#)localdefines 1.2     05/11/08 SMI"
+XCOMM ident "@(#)localdefines 1.4     06/11/07 SMI"
 XCOMM
 
+DTRACE_DEFINES = -DXSERVER_DTRACE -DXERRORDB_PATH=\"$(LIBDIR)/XErrorDB\"
+
 XCOMM Default DPMS settings for Solaris
 EXTRA_DEFINES = -DDEFAULT_STANDBY_TIME=1440000 \
 		-DDEFAULT_SUSPEND_TIME=1620000 \
 		-DDEFAULT_OFF_TIME=1800000 \
-		-DDEFAULT_DPMS_ENABLED=TRUE
+		-DDEFAULT_DPMS_ENABLED=TRUE \
+		$(DTRACE_DEFINES)
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/XORG_NV/sun-src/xc/programs/Xserver/dix/localmacros	Tue Nov 07 14:27:40 2006 -0800
@@ -0,0 +1,47 @@
+XCOMM ########################################################################
+XCOMM
+XCOMM Copyright 2006 Sun Microsystems, Inc.  All rights reserved.
+XCOMM
+XCOMM Permission is hereby granted, free of charge, to any person obtaining a
+XCOMM copy of this software and associated documentation files (the
+XCOMM "Software"), to deal in the Software without restriction, including
+XCOMM without limitation the rights to use, copy, modify, merge, publish,
+XCOMM distribute, and/or sell copies of the Software, and to permit persons
+XCOMM to whom the Software is furnished to do so, provided that the above
+XCOMM copyright notice(s) and this permission notice appear in all copies of
+XCOMM the Software and that both the above copyright notice(s) and this
+XCOMM permission notice appear in supporting documentation.
+XCOMM
+XCOMM THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+XCOMM OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+XCOMM MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT
+XCOMM OF THIRD PARTY RIGHTS. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
+XCOMM HOLDERS INCLUDED IN THIS NOTICE BE LIABLE FOR ANY CLAIM, OR ANY SPECIAL
+XCOMM INDIRECT OR CONSEQUENTIAL DAMAGES, OR ANY DAMAGES WHATSOEVER RESULTING
+XCOMM FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
+XCOMM NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION
+XCOMM WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+XCOMM
+XCOMM Except as contained in this notice, the name of a copyright holder
+XCOMM shall not be used in advertising or otherwise to promote the sale, use
+XCOMM or other dealings in this Software without prior written authorization
+XCOMM of the copyright holder.
+XCOMM
+XCOMM ########################################################################
+XCOMM
+XCOMM ident "@(#)localmacros 1.1     06/11/07 SMI"
+XCOMM
+
+all:: Xserver-dtrace.h
+
+Xserver-dtrace.h: ../Xserver.d
+	dtrace -C -h -o $@ -s ../Xserver.d
+
+dispatch.o: Xserver-dtrace.h
+
+includes:: Xserver-dtrace.h
+
+depend::  Xserver-dtrace.h
+
+clean::
+        RemoveFiles(Xserver-dtrace.h)
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/XORG_NV/sun-src/xc/programs/Xserver/dix/resource.c	Tue Nov 07 14:27:40 2006 -0800
@@ -0,0 +1,1010 @@
+/************************************************************
+
+Copyright 1987, 1998  The Open Group
+
+Permission to use, copy, modify, distribute, and sell this software and its
+documentation for any purpose is hereby granted without fee, provided that
+the above copyright notice appear in all copies and that both that
+copyright notice and this permission notice appear in supporting
+documentation.
+
+The above copyright notice and this permission notice shall be included in
+all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
+OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
+AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+
+Except as contained in this notice, the name of The Open Group shall not be
+used in advertising or otherwise to promote the sale, use or other dealings
+in this Software without prior written authorization from The Open Group.
+
+
+Copyright 1987 by Digital Equipment Corporation, Maynard, Massachusetts.
+
+                        All Rights Reserved
+
+Permission to use, copy, modify, and distribute this software and its 
+documentation for any purpose and without fee is hereby granted, 
+provided that the above copyright notice appear in all copies and that
+both that copyright notice and this permission notice appear in 
+supporting documentation, and that the name of Digital not be
+used in advertising or publicity pertaining to distribution of the
+software without specific, written prior permission.  
+
+DIGITAL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
+ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
+DIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
+ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
+WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
+ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
+SOFTWARE.
+
+********************************************************/
+/* The panoramix components contained the following notice */
+/*****************************************************************
+
+Copyright (c) 1991, 1997 Digital Equipment Corporation, Maynard, Massachusetts.
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software.
+
+The above copyright notice and this permission notice shall be included in
+all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
+DIGITAL EQUIPMENT CORPORATION BE LIABLE FOR ANY CLAIM, DAMAGES, INCLUDING,
+BUT NOT LIMITED TO CONSEQUENTIAL OR INCIDENTAL DAMAGES, OR OTHER LIABILITY,
+WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR
+IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+
+Except as contained in this notice, the name of Digital Equipment Corporation
+shall not be used in advertising or otherwise to promote the sale, use or other
+dealings in this Software without prior written authorization from Digital
+Equipment Corporation.
+
+******************************************************************/
+/* XSERVER_DTRACE additions:
+ * Copyright 2005-2006 Sun Microsystems, Inc.  All rights reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the
+ * "Software"), to deal in the Software without restriction, including
+ * without limitation the rights to use, copy, modify, merge, publish,
+ * distribute, and/or sell copies of the Software, and to permit persons
+ * to whom the Software is furnished to do so, provided that the above
+ * copyright notice(s) and this permission notice appear in all copies of
+ * the Software and that both the above copyright notice(s) and this
+ * permission notice appear in supporting documentation.
+ * 
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+ * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT
+ * OF THIRD PARTY RIGHTS. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
+ * HOLDERS INCLUDED IN THIS NOTICE BE LIABLE FOR ANY CLAIM, OR ANY SPECIAL
+ * INDIRECT OR CONSEQUENTIAL DAMAGES, OR ANY DAMAGES WHATSOEVER RESULTING
+ * FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
+ * NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION
+ * WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ * 
+ * Except as contained in this notice, the name of a copyright holder
+ * shall not be used in advertising or otherwise to promote the sale, use
+ * or other dealings in this Software without prior written authorization
+ * of the copyright holder.
+ */
+
+/* $Xorg: resource.c,v 1.5 2001/02/09 02:04:40 xorgcvs Exp $ */
+/* $XdotOrg: xc/programs/Xserver/dix/resource.c,v 1.8 2005/07/03 08:53:38 daniels Exp $ */
+/* $TOG: resource.c /main/41 1998/02/09 14:20:31 kaleb $ */
+
+/*	Routines to manage various kinds of resources:
+ *
+ *	CreateNewResourceType, CreateNewResourceClass, InitClientResources,
+ *	FakeClientID, AddResource, FreeResource, FreeClientResources,
+ *	FreeAllResources, LookupIDByType, LookupIDByClass, GetXIDRange
+ */
+
+/* 
+ *      A resource ID is a 32 bit quantity, the upper 2 bits of which are
+ *	off-limits for client-visible resources.  The next 8 bits are
+ *      used as client ID, and the low 22 bits come from the client.
+ *	A resource ID is "hashed" by extracting and xoring subfields
+ *      (varying with the size of the hash table).
+ *
+ *      It is sometimes necessary for the server to create an ID that looks
+ *      like it belongs to a client.  This ID, however,  must not be one
+ *      the client actually can create, or we have the potential for conflict.
+ *      The 31st bit of the ID is reserved for the server's use for this
+ *      purpose.  By setting CLIENT_ID(id) to the client, the SERVER_BIT to
+ *      1, and an otherwise arbitrary ID in the low 22 bits, we can create a
+ *      resource "owned" by the client.
+ */
+/* $XFree86: xc/programs/Xserver/dix/resource.c,v 3.13 2003/09/24 02:43:13 dawes Exp $ */
+
+#define NEED_EVENTS
+#ifdef HAVE_DIX_CONFIG_H
+#include <dix-config.h>
+#endif
+
+#include <X11/X.h>
+#include "misc.h"
+#include "os.h"
+#include "resource.h"
+#include "dixstruct.h" 
+#include "opaque.h"
+#include "windowstr.h"
+#include "dixfont.h"
+#include "colormap.h"
+#include "inputstr.h"
+#include "dixevents.h"
+#include "dixgrabs.h"
+#include "cursor.h"
+#ifdef PANORAMIX
+#include "panoramiX.h"
+#include "panoramiXsrv.h"
+#endif
+#include <assert.h>
+
+#ifdef XSERVER_DTRACE
+#include <sys/types.h>
+typedef const char *string;
+#include "Xserver-dtrace.h"
+
+#define TypeNameString(t) NameForAtom(ResourceNames[t & TypeMask])
+#endif
+
+static void RebuildTable(
+    int /*client*/
+);
+
+#define SERVER_MINID 32
+
+#define INITBUCKETS 64
+#define INITHASHSIZE 6
+#define MAXHASHSIZE 11
+
+typedef struct _Resource {
+    struct _Resource	*next;
+    XID			id;
+    RESTYPE		type;
+    pointer		value;
+} ResourceRec, *ResourcePtr;
+#define NullResource ((ResourcePtr)NULL)
+
+typedef struct _ClientResource {
+    ResourcePtr *resources;
+    int		elements;
+    int		buckets;
+    int		hashsize;	/* log(2)(buckets) */
+    XID		fakeID;
+    XID		endFakeID;
+    XID		expectID;
+} ClientResourceRec;
+
+RESTYPE lastResourceType;
+static RESTYPE lastResourceClass;
+RESTYPE TypeMask;
+
+static DeleteType *DeleteFuncs = (DeleteType *)NULL;
+
+#ifdef XResExtension
+
+Atom * ResourceNames = NULL;
+
+void RegisterResourceName (RESTYPE type, char *name)
+{
+    ResourceNames[type & TypeMask] =  MakeAtom(name, strlen(name), TRUE);
+}
+
+#endif
+
+RESTYPE
+CreateNewResourceType(DeleteType deleteFunc)
+{
+    RESTYPE next = lastResourceType + 1;
+    DeleteType *funcs;
+
+    if (next & lastResourceClass)
+	return 0;
+    funcs = (DeleteType *)xrealloc(DeleteFuncs,
+				   (next + 1) * sizeof(DeleteType));
+    if (!funcs)
+	return 0;
+
+#ifdef XResExtension
+    {
+       Atom *newnames;
+       newnames = xrealloc(ResourceNames, (next + 1) * sizeof(Atom));
+       if(!newnames)
+           return 0;
+       ResourceNames = newnames;
+       ResourceNames[next] = 0;
+    }
+#endif
+
+    lastResourceType = next;
+    DeleteFuncs = funcs;
+    DeleteFuncs[next] = deleteFunc;
+    return next;
+}
+
+RESTYPE
+CreateNewResourceClass()
+{
+    RESTYPE next = lastResourceClass >> 1;
+
+    if (next & lastResourceType)
+	return 0;
+    lastResourceClass = next;
+    TypeMask = next - 1;
+    return next;
+}
+
+ClientResourceRec clientTable[MAXCLIENTS];
+
+/*****************
+ * InitClientResources
+ *    When a new client is created, call this to allocate space
+ *    in resource table
+ *****************/
+
+Bool
+InitClientResources(ClientPtr client)
+{
+    register int i, j;
+ 
+    if (client == serverClient)
+    {
+	lastResourceType = RT_LASTPREDEF;
+	lastResourceClass = RC_LASTPREDEF;
+	TypeMask = RC_LASTPREDEF - 1;
+	if (DeleteFuncs)
+	    xfree(DeleteFuncs);
+	DeleteFuncs = (DeleteType *)xalloc((lastResourceType + 1) *
+					   sizeof(DeleteType));
+	if (!DeleteFuncs)
+	    return FALSE;
+	DeleteFuncs[RT_NONE & TypeMask] = (DeleteType)NoopDDA;
+	DeleteFuncs[RT_WINDOW & TypeMask] = DeleteWindow;
+	DeleteFuncs[RT_PIXMAP & TypeMask] = dixDestroyPixmap;
+	DeleteFuncs[RT_GC & TypeMask] = FreeGC;
+	DeleteFuncs[RT_FONT & TypeMask] = CloseFont;
+	DeleteFuncs[RT_CURSOR & TypeMask] = FreeCursor;
+	DeleteFuncs[RT_COLORMAP & TypeMask] = FreeColormap;
+	DeleteFuncs[RT_CMAPENTRY & TypeMask] = FreeClientPixels;
+	DeleteFuncs[RT_OTHERCLIENT & TypeMask] = OtherClientGone;
+	DeleteFuncs[RT_PASSIVEGRAB & TypeMask] = DeletePassiveGrab;
+
+#ifdef XResExtension
+        if(ResourceNames)
+            xfree(ResourceNames);
+        ResourceNames = xalloc((lastResourceType + 1) * sizeof(Atom));
+        if(!ResourceNames)
+           return FALSE;
+#endif
+    }
+    clientTable[i = client->index].resources =
+	(ResourcePtr *)xalloc(INITBUCKETS*sizeof(ResourcePtr));
+    if (!clientTable[i].resources)
+	return FALSE;
+    clientTable[i].buckets = INITBUCKETS;
+    clientTable[i].elements = 0;
+    clientTable[i].hashsize = INITHASHSIZE;
+    /* Many IDs allocated from the server client are visible to clients,
+     * so we don't use the SERVER_BIT for them, but we have to start
+     * past the magic value constants used in the protocol.  For normal
+     * clients, we can start from zero, with SERVER_BIT set.
+     */
+    clientTable[i].fakeID = client->clientAsMask |
+			    (client->index ? SERVER_BIT : SERVER_MINID);
+    clientTable[i].endFakeID = (clientTable[i].fakeID | RESOURCE_ID_MASK) + 1;
+    clientTable[i].expectID = client->clientAsMask;
+    for (j=0; j<INITBUCKETS; j++) 
+    {
+        clientTable[i].resources[j] = NullResource;
+    }
+    return TRUE;
+}
+
+
+static int
+Hash(int client, register XID id)
+{
+    id &= RESOURCE_ID_MASK;
+    switch (clientTable[client].hashsize)
+    {
+	case 6:
+	    return ((int)(0x03F & (id ^ (id>>6) ^ (id>>12))));
+	case 7:
+	    return ((int)(0x07F & (id ^ (id>>7) ^ (id>>13))));
+	case 8:
+	    return ((int)(0x0FF & (id ^ (id>>8) ^ (id>>16))));
+	case 9:
+	    return ((int)(0x1FF & (id ^ (id>>9))));
+	case 10:
+	    return ((int)(0x3FF & (id ^ (id>>10))));
+	case 11:
+	    return ((int)(0x7FF & (id ^ (id>>11))));
+    }
+    return -1;
+}
+
+static XID
+AvailableID(
+    register int client,
+    register XID id,
+    register XID maxid,
+    register XID goodid)
+{
+    register ResourcePtr res;
+
+    if ((goodid >= id) && (goodid <= maxid))
+	return goodid;
+    for (; id <= maxid; id++)
+    {
+	res = clientTable[client].resources[Hash(client, id)];
+	while (res && (res->id != id))
+	    res = res->next;
+	if (!res)
+	    return id;
+    }
+    return 0;
+}
+
+void
+GetXIDRange(int client, Bool server, XID *minp, XID *maxp)
+{
+    register XID id, maxid;
+    register ResourcePtr *resp;
+    register ResourcePtr res;
+    register int i;
+    XID goodid;
+
+    id = (Mask)client << CLIENTOFFSET;
+    if (server)
+	id |= client ? SERVER_BIT : SERVER_MINID;
+    maxid = id | RESOURCE_ID_MASK;
+    goodid = 0;
+    for (resp = clientTable[client].resources, i = clientTable[client].buckets;
+	 --i >= 0;)
+    {
+	for (res = *resp++; res; res = res->next)
+	{
+	    if ((res->id < id) || (res->id > maxid))
+		continue;
+	    if (((res->id - id) >= (maxid - res->id)) ?
+		(goodid = AvailableID(client, id, res->id - 1, goodid)) :
+		!(goodid = AvailableID(client, res->id + 1, maxid, goodid)))
+		maxid = res->id - 1;
+	    else
+		id = res->id + 1;
+	}
+    }
+    if (id > maxid)
+	id = maxid = 0;
+    *minp = id;
+    *maxp = maxid;
+}
+
+/**
+ *  GetXIDList is called by the XC-MISC extension's MiscGetXIDList function.
+ *  This function tries to find count unused XIDs for the given client.  It 
+ *  puts the IDs in the array pids and returns the number found, which should
+ *  almost always be the number requested.
+ *
+ *  The circumstances that lead to a call to this function are very rare.
+ *  Xlib must run out of IDs while trying to generate a request that wants
+ *  multiple ID's, like the Multi-buffering CreateImageBuffers request.
+ *
+ *  No rocket science in the implementation; just iterate over all
+ *  possible IDs for the given client and pick the first count IDs
+ *  that aren't in use.  A more efficient algorithm could probably be
+ *  invented, but this will be used so rarely that this should suffice.
+ */
+
+unsigned int
+GetXIDList(ClientPtr pClient, unsigned count, XID *pids)
+{
+    unsigned int found = 0;
+    XID id = pClient->clientAsMask;
+    XID maxid;
+
+    maxid = id | RESOURCE_ID_MASK;
+    while ( (found < count) && (id <= maxid) )
+    {
+	if (!LookupIDByClass(id, RC_ANY))
+	{
+	    pids[found++] = id;
+	}
+	id++;
+    }
+    return found;
+}
+
+/*
+ * Return the next usable fake client ID.
+ *
+ * Normally this is just the next one in line, but if we've used the last
+ * in the range, we need to find a new range of safe IDs to avoid
+ * over-running another client.
+ */
+
+XID
+FakeClientID(register int client)
+{
+    XID id, maxid;
+
+    id = clientTable[client].fakeID++;
+    if (id != clientTable[client].endFakeID)
+	return id;
+    GetXIDRange(client, TRUE, &id, &maxid);
+    if (!id) {
+	if (!client)
+	    FatalError("FakeClientID: server internal ids exhausted\n");
+	MarkClientException(clients[client]);
+	id = ((Mask)client << CLIENTOFFSET) | (SERVER_BIT * 3);
+	maxid = id | RESOURCE_ID_MASK;
+    }
+    clientTable[client].fakeID = id + 1;
+    clientTable[client].endFakeID = maxid + 1;
+    return id;
+}
+
+Bool
+AddResource(XID id, RESTYPE type, pointer value)
+{
+    int client;
+    register ClientResourceRec *rrec;
+    register ResourcePtr res, *head;
+    	
+#ifdef XSERVER_DTRACE
+    XSERVER_RESOURCE_ALLOC(id, type, value, TypeNameString(type));
+#endif
+    client = CLIENT_ID(id);
+    rrec = &clientTable[client];
+    if (!rrec->buckets)
+    {
+	ErrorF("AddResource(%lx, %lx, %lx), client=%d \n",
+		(unsigned long)id, type, (unsigned long)value, client);
+        FatalError("client not in use\n");
+    }
+    if ((rrec->elements >= 4*rrec->buckets) &&
+	(rrec->hashsize < MAXHASHSIZE))
+	RebuildTable(client);
+    head = &rrec->resources[Hash(client, id)];
+    res = (ResourcePtr)xalloc(sizeof(ResourceRec));
+    if (!res)
+    {
+	(*DeleteFuncs[type & TypeMask])(value, id);
+	return FALSE;
+    }
+    res->next = *head;
+    res->id = id;
+    res->type = type;
+    res->value = value;
+    *head = res;
+    rrec->elements++;
+    if (!(id & SERVER_BIT) && (id >= rrec->expectID))
+	rrec->expectID = id + 1;
+    return TRUE;
+}
+
+static void
+RebuildTable(int client)
+{
+    register int j;
+    register ResourcePtr res, next;
+    ResourcePtr **tails, *resources;
+    register ResourcePtr **tptr, *rptr;
+
+    /*
+     * For now, preserve insertion order, since some ddx layers depend
+     * on resources being free in the opposite order they are added.
+     */
+
+    j = 2 * clientTable[client].buckets;
+    tails = (ResourcePtr **)ALLOCATE_LOCAL(j * sizeof(ResourcePtr *));
+    if (!tails)
+	return;
+    resources = (ResourcePtr *)xalloc(j * sizeof(ResourcePtr));
+    if (!resources)
+    {
+	DEALLOCATE_LOCAL(tails);
+	return;
+    }
+    for (rptr = resources, tptr = tails; --j >= 0; rptr++, tptr++)
+    {
+	*rptr = NullResource;
+	*tptr = rptr;
+    }
+    clientTable[client].hashsize++;
+    for (j = clientTable[client].buckets,
+	 rptr = clientTable[client].resources;
+	 --j >= 0;
+	 rptr++)
+    {
+	for (res = *rptr; res; res = next)
+	{
+	    next = res->next;
+	    res->next = NullResource;
+	    tptr = &tails[Hash(client, res->id)];
+	    **tptr = res;
+	    *tptr = &res->next;
+	}
+    }
+    DEALLOCATE_LOCAL(tails);
+    clientTable[client].buckets *= 2;
+    xfree(clientTable[client].resources);
+    clientTable[client].resources = resources;
+}
+
+void
+FreeResource(XID id, RESTYPE skipDeleteFuncType)
+{
+    int		cid;
+    register    ResourcePtr res;
+    register	ResourcePtr *prev, *head;
+    register	int *eltptr;
+    int		elements;
+    Bool	gotOne = FALSE;
+
+    if (((cid = CLIENT_ID(id)) < MAXCLIENTS) && clientTable[cid].buckets)
+    {
+	head = &clientTable[cid].resources[Hash(cid, id)];
+	eltptr = &clientTable[cid].elements;
+
+	prev = head;
+	while ( (res = *prev) )
+	{
+	    if (res->id == id)
+	    {
+		RESTYPE rtype = res->type;
+
+#ifdef XSERVER_DTRACE
+		XSERVER_RESOURCE_FREE(res->id, res->type,
+			      res->value, TypeNameString(res->type));
+#endif		    
+		*prev = res->next;
+		elements = --*eltptr;
+		if (rtype & RC_CACHED)
+		    FlushClientCaches(res->id);
+		if (rtype != skipDeleteFuncType)
+		    (*DeleteFuncs[rtype & TypeMask])(res->value, res->id);
+		xfree(res);
+		if (*eltptr != elements)
+		    prev = head; /* prev may no longer be valid */
+		gotOne = TRUE;
+	    }
+	    else
+		prev = &res->next;
+        }
+	if(clients[cid] && (id == clients[cid]->lastDrawableID))
+	{
+	    clients[cid]->lastDrawable = (DrawablePtr)WindowTable[0];
+	    clients[cid]->lastDrawableID = WindowTable[0]->drawable.id;
+	}
+    }
+    if (!gotOne)
+	ErrorF("Freeing resource id=%lX which isn't there.\n",
+		   (unsigned long)id);
+}
+
+
+void
+FreeResourceByType(XID id, RESTYPE type, Bool skipFree)
+{
+    int		cid;
+    register    ResourcePtr res;
+    register	ResourcePtr *prev, *head;
+    if (((cid = CLIENT_ID(id)) < MAXCLIENTS) && clientTable[cid].buckets)
+    {
+	head = &clientTable[cid].resources[Hash(cid, id)];
+
+	prev = head;
+	while ( (res = *prev) )
+	{
+	    if (res->id == id && res->type == type)
+	    {
+#ifdef XSERVER_DTRACE
+		XSERVER_RESOURCE_FREE(res->id, res->type,
+			      res->value, TypeNameString(res->type));
+#endif		    		    
+		*prev = res->next;
+		if (type & RC_CACHED)
+		    FlushClientCaches(res->id);
+		if (!skipFree)
+		    (*DeleteFuncs[type & TypeMask])(res->value, res->id);
+		xfree(res);
+		break;
+	    }
+	    else
+		prev = &res->next;
+        }
+	if(clients[cid] && (id == clients[cid]->lastDrawableID))
+	{
+	    clients[cid]->lastDrawable = (DrawablePtr)WindowTable[0];
+	    clients[cid]->lastDrawableID = WindowTable[0]->drawable.id;
+	}
+    }
+}
+
+/*
+ * Change the value associated with a resource id.  Caller
+ * is responsible for "doing the right thing" with the old
+ * data
+ */
+
+Bool
+ChangeResourceValue (XID id, RESTYPE rtype, pointer value)
+{
+    int    cid;
+    register    ResourcePtr res;
+
+    if (((cid = CLIENT_ID(id)) < MAXCLIENTS) && clientTable[cid].buckets)
+    {
+	res = clientTable[cid].resources[Hash(cid, id)];
+
+	for (; res; res = res->next)
+	    if ((res->id == id) && (res->type == rtype))
+	    {
+		if (rtype & RC_CACHED)
+		    FlushClientCaches(res->id);
+		res->value = value;
+		return TRUE;
+	    }
+    }
+    return FALSE;
+}
+
+/* Note: if func adds or deletes resources, then func can get called
+ * more than once for some resources.  If func adds new resources,
+ * func might or might not get called for them.  func cannot both
+ * add and delete an equal number of resources!
+ */
+
+void
+FindClientResourcesByType(
+    ClientPtr client,
+    RESTYPE type,
+    FindResType func,
+    pointer cdata
+){
+    register ResourcePtr *resources;
+    register ResourcePtr this, next;
+    int i, elements;
+    register int *eltptr;
+
+    if (!client)
+	client = serverClient;
+
+    resources = clientTable[client->index].resources;
+    eltptr = &clientTable[client->index].elements;
+    for (i = 0; i < clientTable[client->index].buckets; i++) 
+    {
+        for (this = resources[i]; this; this = next)
+	{
+	    next = this->next;
+	    if (!type || this->type == type) {
+		elements = *eltptr;
+		(*func)(this->value, this->id, cdata);
+		if (*eltptr != elements)
+		    next = resources[i]; /* start over */
+	    }
+	}
+    }
+}
+
+void
+FindAllClientResources(
+    ClientPtr client,
+    FindAllRes func,
+    pointer cdata
+){
+    register ResourcePtr *resources;
+    register ResourcePtr this, next;
+    int i, elements;
+    register int *eltptr;
+
+    if (!client)
+        client = serverClient;
+
+    resources = clientTable[client->index].resources;
+    eltptr = &clientTable[client->index].elements;
+    for (i = 0; i < clientTable[client->index].buckets; i++)
+    {
+        for (this = resources[i]; this; this = next)
+        {
+            next = this->next;
+            elements = *eltptr;
+            (*func)(this->value, this->id, this->type, cdata);
+            if (*eltptr != elements)
+                next = resources[i]; /* start over */
+        }
+    }
+}
+
+
+pointer
+LookupClientResourceComplex(
+    ClientPtr client,
+    RESTYPE type,
+    FindComplexResType func,
+    pointer cdata
+){
+    ResourcePtr *resources;
+    ResourcePtr this;
+    int i;
+
+    if (!client)
+	client = serverClient;
+
+    resources = clientTable[client->index].resources;
+    for (i = 0; i < clientTable[client->index].buckets; i++) {
+        for (this = resources[i]; this; this = this->next) {
+	    if (!type || this->type == type) {
+		if((*func)(this->value, this->id, cdata))
+		    return this->value;
+	    }
+	}
+    }
+    return NULL;
+}
+
+
+void
+FreeClientNeverRetainResources(ClientPtr client)
+{
+    ResourcePtr *resources;
+    ResourcePtr this;
+    ResourcePtr *prev;
+    int j;
+
+    if (!client)
+	return;
+
+    resources = clientTable[client->index].resources;
+    for (j=0; j < clientTable[client->index].buckets; j++) 
+    {
+	prev = &resources[j];
+        while ( (this = *prev) )
+	{
+	    RESTYPE rtype = this->type;
+	    if (rtype & RC_NEVERRETAIN)
+	    {
+#ifdef XSERVER_DTRACE
+		XSERVER_RESOURCE_FREE(this->id, this->type,
+			      this->value, TypeNameString(this->type));
+#endif		    
+		*prev = this->next;
+		if (rtype & RC_CACHED)
+		    FlushClientCaches(this->id);
+		(*DeleteFuncs[rtype & TypeMask])(this->value, this->id);
+		xfree(this);	    
+	    }
+	    else
+		prev = &this->next;
+	}
+    }
+}
+
+void
+FreeClientResources(ClientPtr client)
+{
+    register ResourcePtr *resources;
+    register ResourcePtr this;
+    int j;
+
+    /* This routine shouldn't be called with a null client, but just in
+	case ... */
+
+    if (!client)
+	return;
+
+    HandleSaveSet(client);
+
+    resources = clientTable[client->index].resources;
+    for (j=0; j < clientTable[client->index].buckets; j++) 
+    {
+        /* It may seem silly to update the head of this resource list as
+	we delete the members, since the entire list will be deleted any way, 
+	but there are some resource deletion functions "FreeClientPixels" for 
+	one which do a LookupID on another resource id (a Colormap id in this
+	case), so the resource list must be kept valid up to the point that
+	it is deleted, so every time we delete a resource, we must update the
+	head, just like in FreeResource. I hope that this doesn't slow down
+	mass deletion appreciably. PRH */
+
+	ResourcePtr *head;
+
+	head = &resources[j];
+
+        for (this = *head; this; this = *head)
+	{
+	    RESTYPE rtype = this->type;
+#ifdef XSERVER_DTRACE
+	    XSERVER_RESOURCE_FREE(this->id, this->type,
+			  this->value, TypeNameString(this->type));
+#endif		    
+	    *head = this->next;
+	    if (rtype & RC_CACHED)
+		FlushClientCaches(this->id);
+	    (*DeleteFuncs[rtype & TypeMask])(this->value, this->id);
+	    xfree(this);	    
+	}
+    }
+    xfree(clientTable[client->index].resources);
+    clientTable[client->index].resources = NULL;
+    clientTable[client->index].buckets = 0;
+}
+
+void
+FreeAllResources()
+{
+    int	i;
+
+    for (i = currentMaxClients; --i >= 0; ) 
+    {
+        if (clientTable[i].buckets) 
+	    FreeClientResources(clients[i]);
+    }
+}
+
+Bool
+LegalNewID(XID id, register ClientPtr client)
+{
+
+#ifdef PANORAMIX
+    XID 	minid, maxid;
+
+	if (!noPanoramiXExtension) { 
+	    minid = client->clientAsMask | (client->index ? 
+			                    SERVER_BIT : SERVER_MINID);
+	    maxid = (clientTable[client->index].fakeID | RESOURCE_ID_MASK) + 1;
+            if ((id >= minid) && (id <= maxid))
+	        return TRUE;
+	}
+#endif /* PANORAMIX */
+	return ((client->clientAsMask == (id & ~RESOURCE_ID_MASK)) &&
+	    ((clientTable[client->index].expectID <= id) ||
+	     !LookupIDByClass(id, RC_ANY)));
+}
+
+#ifdef XCSECURITY
+
+/* SecurityLookupIDByType and SecurityLookupIDByClass:
+ * These are the heart of the resource ID security system.  They take
+ * two additional arguments compared to the old LookupID functions:
+ * the client doing the lookup, and the access mode (see resource.h).
+ * The resource is returned if it exists and the client is allowed access,
+ * else NULL is returned.
+ */
+
+pointer
+SecurityLookupIDByType(ClientPtr client, XID id, RESTYPE rtype, Mask mode)
+{
+    int    cid;
+    register    ResourcePtr res;
+    pointer retval = NULL;
+
+    assert(client == NullClient ||
+     (client->index <= currentMaxClients && clients[client->index] == client));
+    assert( (rtype & TypeMask) <= lastResourceType);
+
+    if (((cid = CLIENT_ID(id)) < MAXCLIENTS) &&
+	clientTable[cid].buckets)
+    {
+	res = clientTable[cid].resources[Hash(cid, id)];
+
+	for (; res; res = res->next)
+	    if ((res->id == id) && (res->type == rtype))
+	    {
+		retval = res->value;
+		break;
+	    }
+    }
+    if (retval && client && client->CheckAccess)
+	retval = (* client->CheckAccess)(client, id, rtype, mode, retval);
+    return retval;
+}
+
+
+pointer
+SecurityLookupIDByClass(ClientPtr client, XID id, RESTYPE classes, Mask mode)
+{
+    int    cid;
+    register ResourcePtr res = NULL;
+    pointer retval = NULL;
+
+    assert(client == NullClient ||
+     (client->index <= currentMaxClients && clients[client->index] == client));
+    assert (classes >= lastResourceClass);
+
+    if (((cid = CLIENT_ID(id)) < MAXCLIENTS) &&
+	clientTable[cid].buckets)
+    {
+	res = clientTable[cid].resources[Hash(cid, id)];
+
+	for (; res; res = res->next)
+	    if ((res->id == id) && (res->type & classes))
+	    {
+		retval = res->value;
+		break;
+	    }
+    }
+    if (retval && client && client->CheckAccess)
+	retval = (* client->CheckAccess)(client, id, res->type, mode, retval);
+    return retval;
+}
+
+/* We can't replace the LookupIDByType and LookupIDByClass functions with
+ * macros because of compatibility with loadable servers.
+ */
+
+pointer
+LookupIDByType(XID id, RESTYPE rtype)
+{
+    return SecurityLookupIDByType(NullClient, id, rtype,
+				  SecurityUnknownAccess);
+}
+
+pointer
+LookupIDByClass(XID id, RESTYPE classes)
+{
+    return SecurityLookupIDByClass(NullClient, id, classes,
+				   SecurityUnknownAccess);
+}
+
+#else /* not XCSECURITY */
+
+/*
+ *  LookupIDByType returns the object with the given id and type, else NULL.
+ */ 
+pointer
+LookupIDByType(XID id, RESTYPE rtype)
+{
+    int    cid;
+    register    ResourcePtr res;
+
+    if (((cid = CLIENT_ID(id)) < MAXCLIENTS) &&
+	clientTable[cid].buckets)
+    {
+	res = clientTable[cid].resources[Hash(cid, id)];
+
+	for (; res; res = res->next)
+	    if ((res->id == id) && (res->type == rtype))
+		return res->value;
+    }
+    return (pointer)NULL;
+}
+
+/*
+ *  LookupIDByClass returns the object with the given id and any one of the
+ *  given classes, else NULL.
+ */ 
+pointer
+LookupIDByClass(XID id, RESTYPE classes)
+{
+    int    cid;
+    register    ResourcePtr res;
+
+    if (((cid = CLIENT_ID(id)) < MAXCLIENTS) &&
+	clientTable[cid].buckets)
+    {
+	res = clientTable[cid].resources[Hash(cid, id)];
+
+	for (; res; res = res->next)
+	    if ((res->id == id) && (res->type & classes))
+		return res->value;
+    }
+    return (pointer)NULL;
+}
+
+#endif /* XCSECURITY */
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/XORG_NV/sun-src/xc/programs/Xserver/os/Imakefile	Tue Nov 07 14:27:40 2006 -0800
@@ -0,0 +1,200 @@
+XCOMM $Xorg: Imakefile,v 1.3 2000/08/17 19:53:40 cpqbld Exp $
+
+
+
+
+XCOMM $XFree86: xc/programs/Xserver/os/Imakefile,v 3.40 2003/09/09 03:20:41 dawes Exp $
+
+#include <Server.tmpl>
+
+/*
+ * If you have any extra files to be put into the library, define them here.
+ */
+
+/*
+ * do not modify the following two definitions
+ */
+
+#ifndef OtherSources
+#define OtherSources
+#endif
+
+#ifndef OtherObjects
+#define OtherObjects
+#endif
+
+#if HasXdmAuth
+XDMAUTHDEFS = -DHASXDMAUTH
+XDMAUTHOBJS = xdmauth.o
+XDMAUTHSRCS = xdmauth.c
+#else
+XDMAUTHDEFS = 
+XDMAUTHOBJS =
+XDMAUTHSCRS =
+#endif
+
+#if HasSecureRPC
+RPCDEFS = -DSECURE_RPC
+RPCOBJS = rpcauth.o
+RPCSRCS = rpcauth.c
+#else
+RPCDEFS =
+RPCOBJS =
+RPCSRCS =
+#endif
+
+#if HasKrb5
+KRB5OBJS = k5auth.o k5encode.o
+KRB5SRCS = k5auth.c k5encode.c
+#endif
+
+#if HasBSD44Sockets
+   SOCK_DEFINES = -DBSD44SOCKETS
+#endif
+
+#if HasGetIfAddrs
+   IFADDRS_DEFINES = -DHAS_GETIFADDRS
+#endif
+
+#if BuildLBX
+   LBX_SRCS = lbxio.c
+   LBX_OBJS = lbxio.o
+#else
+   LBX_SRCS =
+   LBX_OBJS =
+#endif
+
+#if !defined(DDXOsColor)
+COLOR_SRCS=oscolor.c
+COLOR_OBJS=oscolor.o
+#endif
+
+#if UseInternalMalloc
+MALLOC_SRCS=xalloc.c
+MALLOC_OBJS=xalloc.o
+#endif
+
+#if !HasSnprintf
+SNPRINTF_SRCS = snprintf.c
+SNPRINTF_OBJS = snprintf.o
+#endif
+
+#if !HasStrlcat
+STRLCAT_SRCS = strlcat.c strlcpy.c
+STRLCAT_OBJS = strlcat.o strlcpy.o
+#endif
+
+#if HasGetpeerucred
+GETPEER_DEFINES = -DHAS_GETPEERUCRED
+#else
+# if HasGetpeereid
+GETPEER_DEFINES = -DHAS_GETPEEREID
+# endif
+#endif
+
+BOOTSTRAPCFLAGS = 
+           SRCS = WaitFor.c access.c connection.c io.c $(COLOR_SRCS) \
+                  osinit.c utils.c log.c auth.c mitauth.c secauth.c \
+                  $(XDMAUTHSRCS) $(RPCSRCS) $(KRB5SRCS) xdmcp.c OtherSources \
+                  transport.c $(SNPRINTF_SRCS) $(STRLCAT_SRCS) \
+		  $(MALLOC_SRCS) $(LBX_SRCS) xprintf.c
+           OBJS = WaitFor.o access.o connection.o io.o $(COLOR_OBJS) \
+                  osinit.o utils.o log.o auth.o mitauth.o secauth.o \
+                  $(XDMAUTHOBJS) $(RPCOBJS) $(KRB5OBJS) xdmcp.o OtherObjects \
+                  transport.o $(SNPRINTF_OBJS) $(STRLCAT_OBJS) \
+		  $(MALLOC_OBJS) $(LBX_OBJS) xprintf.o
+
+#if SpecialMalloc
+     MEM_DEFINES = -DSPECIAL_MALLOC
+#endif /* SpecialMalloc */
+#if UseInternalMalloc
+     MEM_DEFINES = -DINTERNAL_MALLOC
+#endif
+#if UseMemLeak
+     MEM_DEFINES = -DMEMBUG
+#endif
+#if UseRgbTxt
+    RGB_DEFINES = -DUSE_RGB_TXT
+#endif
+    DBM_DEFINES = NdbmDefines
+    ADM_DEFINES = -DADMPATH=\"$(ADMDIR)/X\%smsgs\"
+  XDMCP_DEFINES = ServerXdmcpDefines
+   KRB5_DEFINES = Krb5Defines
+ XALLOC_DEFINES = XallocDefines
+  ERROR_DEFINES = ServerErrorDefines
+#if HasPam && HasPamMisc
+    PAM_DEFINES = -DUSE_PAM
+#endif
+        DEFINES = -DXSERV_t -DTRANS_SERVER $(CONNECTION_FLAGS) $(MEM_DEFINES) \
+		  $(XDMAUTHDEFS) $(RPCDEFS) $(SIGNAL_DEFINES) $(OS_DEFINES) \
+		  $(KRB5_DEFINES) $(RGB_DEFINES) $(GETPEER_DEFINES) \
+		  $(RANDOM_DEFINES) $(BUGMSG) $(XTRANS_FAILDEFINES)
+       INCLUDES = -I. -I../include -I$(XINCLUDESRC) -I$(EXTINCSRC) \
+		  -I$(SERVERSRC)/Xext -I$(FONTINCSRC) -I$(SERVERSRC)/render \
+		  -I$(TOP)/lib/Xau -I../lbx -I../Xprint Krb5Includes
+ DEPEND_DEFINES = $(DBM_DEFINES) $(XDMCP_DEFINES) $(EXT_DEFINES) \
+		  $(TRANS_INCLUDES) $(CONNECTION_FLAGS) $(GETPEER_DEFINES) \
+		  DependDefines
+       LINTLIBS = ../dix/llib-ldix.ln
+
+#ifdef NEED_ALLOCA_FROM_LIBPW
+          PWLIB = /lib/libPW.a
+#endif /* NEED_ALLOCA_FROM_LIBPW */
+
+NormalLibraryObjectRule()
+NormalRelocatableTarget(os,$(OBJS))
+LintLibraryTarget(os,$(SRCS))
+NormalLintTarget($(SRCS))
+
+#ifdef NEED_ALLOCA_FROM_LIBPW
+XCOMM
+XCOMM And this one is to get the version of alloca that lives in /lib/libPW.a
+XCOMM without getting all of the rest of the stuff in there.
+XCOMM
+alloca.o:  $(PWLIB)
+	rm -f alloca.o
+	ar x $(PWLIB) alloca.o
+#endif /* NEED_ALLOCA_FROM_LIBPW */
+
+SpecialCObjectRule(access,$(ICONFIGFILES),$(XDMCP_DEFINES) $(SOCK_DEFINES) $(IFADDRS_DEFINES))
+SpecialCObjectRule(auth,$(ICONFIGFILES),$(XDMCP_DEFINES))
+SpecialCObjectRule(xdmauth,$(ICONFIGFILES),$(XDMCP_DEFINES))
+SpecialCObjectRule(xdmcp,$(ICONFIGFILES),$(SOCK_DEFINES) $(XDMCP_DEFINES))
+SpecialCObjectRule(connection,$(ICONFIGFILES),$(SOCK_DEFINES) $(XDMCP_DEFINES))
+SpecialCObjectRule(transport,$(ICONFIGFILES),$(TRANS_INCLUDES) $(CONN_DEFINES) $(SOCK_DEFINES))
+LinkSourceFile(transport.c,$(TRANSCOMMSRC))
+SpecialCObjectRule(osinit,$(ICONFIGFILES),$(ADM_DEFINES))
+SpecialCObjectRule(WaitFor,$(ICONFIGFILES),$(EXT_DEFINES))
+SpecialCObjectRule(io,$(ICONFIGFILES),$(EXT_DEFINES))
+#if BuildLBX
+SpecialCObjectRule(lbxio,$(ICONFIGFILES),$(EXT_DEFINES))
+#endif
+SpecialCObjectRule(utils,$(ICONFIGFILES),$(XDMCP_DEFINES) $(EXT_DEFINES) $(ERROR_DEFINES) $(PAM_DEFINES))
+SpecialCObjectRule(xalloc,$(ICONFIGFILES),$(XALLOC_DEFINES))
+#if defined(SparcArchitecture) && HasGcc && !HasGcc2
+oscolor.o: oscolor.c $(ICONFIGFILES)
+	$(RM) $@
+	cc -c $(DBM_DEFINES) $(CDEBUGFLAGS) $(ALLDEFINES) $*.c
+#else
+SpecialCObjectRule(oscolor,$(ICONFIGFILES),$(DBM_DEFINES))
+#endif
+
+#if HasKrb5
+LinkSourceFile(k5encode.c,$(XAUTHSRC))
+#endif
+
+#if !HasSnprintf
+LinkSourceFile(snprintf.c,$(LIBSRC)/misc)
+#endif
+
+#if !HasStrlcat
+LinkSourceFile(strlcat.c,$(LIBSRC)/misc)
+LinkSourceFile(strlcpy.c,$(LIBSRC)/misc)
+#endif
+
+#if DoLoadableServer
+AllTarget(libcwrapper.o)
+ObjectFromSpecialSource(libcwrapper,$(XF86OSSRC)/shared/libc_wrapper,-DSELF_CONTAINED_WRAPPER)
+#endif
+
+DependTarget()
--- a/XORG_NV/sun-src/xc/programs/Xserver/os/connection.c	Thu Nov 02 17:37:06 2006 -0800
+++ b/XORG_NV/sun-src/xc/programs/Xserver/os/connection.c	Tue Nov 07 14:27:40 2006 -0800
@@ -204,6 +204,18 @@
 extern void DtloginInit(void);
 #endif /* SUNSOFT */
 
+#ifdef HAS_GETPEERUCRED
+# include <ucred.h>
+# include <zone.h>
+#endif
+
+#ifdef XSERVER_DTRACE
+# include <sys/types.h>
+typedef const char *string;
+# include "../dix/Xserver-dtrace.h"
+# include <ucred.h>
+#endif
+
 int lastfdesc;			/* maximum file descriptor */
 
 fd_set WellKnownConnections;	/* Listener mask */
@@ -606,6 +618,13 @@
 {
     char addr[128];
     char *out = addr;
+    int client_uid;
+    char client_uid_string[64];
+#ifdef HAS_GETPEERUCRED
+    ucred_t *peercred = NULL;
+    pid_t client_pid = -1;
+    zoneid_t client_zid = -1;
+#endif
 
     if (!((OsCommPtr)client->osPrivate)->trans_conn) {
 	strcpy(addr, "LBX proxy at ");
@@ -646,14 +665,58 @@
 	default:
 	    strcpy(out, "unknown address");
 	}
+
+#ifdef HAS_GETPEERUCRED
+    if (getpeerucred(((OsCommPtr)client->osPrivate)->fd, &peercred) >= 0) {
+	client_uid = ucred_geteuid(peercred);
+	client_pid = ucred_getpid(peercred);
+	client_zid = ucred_getzoneid(peercred);
+
+	ucred_free(peercred);
+	snprintf(client_uid_string, sizeof(client_uid_string),
+		 " (uid %ld, pid %ld, zone %ld)",
+		 (long) client_uid, (long) client_pid, (long) client_zid);
+    }
+#else    
+    if (LocalClientCred(client, &client_uid, NULL) != -1) {
+	snprintf(client_uid_string, sizeof(client_uid_string),
+		 " (uid %d)", client_uid);
+    }
+#endif
+    else {
+	client_uid_string[0] = '\0';
+    }
+
+#ifdef XSERVER_DTRACE
+  if (auditTrailLevel > 1) {
+#endif
     
     if (proto_n)
-	AuditF("client %d %s from %s\n  Auth name: %.*s ID: %d\n", 
+	AuditF("client %d %s from %s%s\n  Auth name: %.*s ID: %d\n", 
+	       client->index, letin ? "connected" : "rejected", addr,
+	       client_uid_string, (int)proto_n, auth_proto, auth_id);
+    else 
+	AuditF("client %d %s from %s%s\n", 
 	       client->index, letin ? "connected" : "rejected", addr,
-	       (int)proto_n, auth_proto, auth_id);
-    else 
-	AuditF("client %d %s from %s\n", 
-	       client->index, letin ? "connected" : "rejected", addr);
+	       client_uid_string);
+#ifdef XSERVER_DTRACE
+  }
+  if (XSERVER_CLIENT_AUTH_ENABLED())
+  {
+      ucred_t *peercred = NULL;
+      pid_t pid = -1;
+      zoneid_t zid = -1;
+      
+      if (getpeerucred(((OsCommPtr)client->osPrivate)->fd, &peercred) >= 0) {
+	  pid = ucred_getpid(peercred);
+	  zid = ucred_getzoneid(peercred);
+	  ucred_free(peercred);
+      }
+    
+      XSERVER_CLIENT_AUTH(client->index, addr, pid, zid);
+  }
+#endif	
+
 }
 
 XID
@@ -782,7 +845,9 @@
 	    else
 	    {
 		auth_id = (XID) 0;
+#ifndef XSERVER_DTRACE
 		if (auditTrailLevel > 1)
+#endif
 		    AuthAudit(client, TRUE,
 			(struct sockaddr *) from, fromlen,
 			proto_n, auth_proto, auth_id);
@@ -806,7 +871,11 @@
 		return "Client is not authorized to connect to Server";
 	}
     }
+#ifdef XSERVER_DTRACE
+    else
+#else
     else if (auditTrailLevel > 1)
+#endif
     {
 	if (_XSERVTransGetPeerAddr (trans_conn,
 	    &family, &fromlen, &from) != -1)
@@ -914,6 +983,9 @@
     ErrorF("AllocNewConnection: client index = %d, socket fd = %d\n",
 	   client->index, fd);
 #endif
+#ifdef XSERVER_DTRACE
+    XSERVER_CLIENT_CONNECT(client->index, fd);
+#endif	
 
     return client;
 }
--- a/XORG_NV/sun-src/xc/programs/Xserver/os/localdefines	Thu Nov 02 17:37:06 2006 -0800
+++ b/XORG_NV/sun-src/xc/programs/Xserver/os/localdefines	Tue Nov 07 14:27:40 2006 -0800
@@ -29,11 +29,11 @@
 XCOMM
 XCOMM ########################################################################
 XCOMM
-XCOMM ident "@(#)localdefines 1.3     05/11/08 SMI"
+XCOMM ident "@(#)localdefines 1.4     06/11/03 SMI"
 XCOMM
 
 XCOMM Add VENDOR_DEFINES so we get -DSUNSOFT and other Sun-specific definitions
-    EXTRA_DEFINES = $(VENDOR_DEFINES)
+    EXTRA_DEFINES = $(VENDOR_DEFINES) -DXSERVER_DTRACE
 
 /* Add dtlogin.c for dtlogin authentication information pipe */
 #define OtherSources dtlogin.c