Index: xc/programs/Xserver/Xprint/ps/Ps.h =================================================================== RCS file: /cvs/xorg/xc/programs/Xserver/Xprint/ps/Ps.h,v retrieving revision 1.7 diff -u -2 -0 -r1.7 Ps.h --- xc/programs/Xserver/Xprint/ps/Ps.h 1 Apr 2005 21:45:20 -0000 1.7 +++ xc/programs/Xserver/Xprint/ps/Ps.h 17 Apr 2005 19:58:01 -0000 @@ -165,40 +165,41 @@ typedef struct { int x; int y; int count; unsigned short *string; } PsText16Rec; typedef struct { int depth; int x; int y; int w; int h; int leftPad; int format; int res; /* image resolution */ char *pData; + long pSize; /* bytes allocated for |pData| */ } PsImageRec; typedef struct { int x; int y; int w; int h; } PsFrameRec; typedef enum { PolyPointCmd, PolyLineCmd, PolySegmentCmd, PolyRectangleCmd, FillPolygonCmd, PolyFillRectCmd, PolyArcCmd, PolyFillArcCmd, Index: xc/programs/Xserver/Xprint/ps/PsArea.c =================================================================== RCS file: /cvs/xorg/xc/programs/Xserver/Xprint/ps/PsArea.c,v retrieving revision 1.4 diff -u -2 -0 -r1.4 PsArea.c --- xc/programs/Xserver/Xprint/ps/PsArea.c 1 Apr 2005 21:45:20 -0000 1.4 +++ xc/programs/Xserver/Xprint/ps/PsArea.c 17 Apr 2005 19:58:01 -0000 @@ -68,62 +68,63 @@ ** * ** * Created By: Roger Helmendach (Liberty Systems) ** * ** * Copyright: Copyright 1996 The Open Group, Inc. ** * ** ********************************************************* ** ********************************************************************/ #include "Ps.h" #include "gcstruct.h" #include "windowstr.h" void PsPutScaledImage(DrawablePtr pDrawable, GCPtr pGC, int depth, int x, int y, int w, int h, int leftPad, int format, int imageRes, char *pImage) { if( pDrawable->type==DRAWABLE_PIXMAP ) { - int size = PixmapBytePad(w, depth)*h; + long size = PixmapBytePad(w, depth)*h; DisplayElmPtr elm; PixmapPtr pix = (PixmapPtr)pDrawable; PsPixmapPrivPtr priv = (PsPixmapPrivPtr)pix->devPrivate.ptr; DisplayListPtr disp; GCPtr gc; if ((gc = PsCreateAndCopyGC(pDrawable, pGC)) == NULL) return; disp = PsGetFreeDisplayBlock(priv); elm = &disp->elms[disp->nelms]; elm->type = PutImageCmd; elm->gc = gc; elm->c.image.depth = depth; elm->c.image.x = x; elm->c.image.y = y; elm->c.image.w = w; elm->c.image.h = h; elm->c.image.leftPad = leftPad; elm->c.image.format = format; elm->c.image.res = imageRes; - elm->c.image.pData = (char *)xalloc(size); + elm->c.image.pData = MapAlloc(size, True); + elm->c.image.pSize = size; memcpy(elm->c.image.pData, pImage, size); disp->nelms += 1; } else { int i, j; int r, c; char *pt; PsOutPtr psOut; ColormapPtr cMap; int pageRes, sw, sh; if( PsUpdateDrawableGC(pGC, pDrawable, &psOut, &cMap)==FALSE ) return; if (!imageRes) { sw = w; sh = h; } else { pageRes = XpGetResolution(XpGetPrintContext(requestingClient)); sw = (float)w * (float)pageRes / (float)imageRes + 0.5; sh = (float)h * (float)pageRes / (float)imageRes + 0.5; @@ -180,62 +181,63 @@ #elif IMAGE_BYTE_ORDER == MSBFirst iv_ = iv; #else #error Unsupported byte order #endif c = iv_; PsOut_OutImageBytes(psOut, 1, &c); } } PsOut_EndImage(psOut); } } } void PsPutScaledImageIM(DrawablePtr pDrawable, GCPtr pGC, int depth, int x, int y, int w, int h, int leftPad, int format, int imageRes, char *pImage) { if( pDrawable->type==DRAWABLE_PIXMAP ) { - int size = PixmapBytePad(w, depth)*h; + long size = PixmapBytePad(w, depth)*h; DisplayElmPtr elm; PixmapPtr pix = (PixmapPtr)pDrawable; PsPixmapPrivPtr priv = (PsPixmapPrivPtr)pix->devPrivate.ptr; DisplayListPtr disp; GCPtr gc; if ((gc = PsCreateAndCopyGC(pDrawable, pGC)) == NULL) return; disp = PsGetFreeDisplayBlock(priv); elm = &disp->elms[disp->nelms]; elm->type = PutImageCmd; elm->gc = gc; elm->c.image.depth = depth; elm->c.image.x = x; elm->c.image.y = y; elm->c.image.w = w; elm->c.image.h = h; elm->c.image.leftPad = leftPad; elm->c.image.format = format; elm->c.image.res = imageRes; - elm->c.image.pData = (char *)xalloc(size); + elm->c.image.pData = MapAlloc(size, True); + elm->c.image.pSize = size; memcpy(elm->c.image.pData, pImage, size); disp->nelms += 1; } else { int i, j; int r, c; char *pt; PsOutPtr psOut; ColormapPtr cMap; int pageRes, sw, sh; #ifdef BM_CACHE long cache_id = 0; #endif if( PsUpdateDrawableGC(pGC, pDrawable, &psOut, &cMap)==FALSE ) return; if (!imageRes) { sw = w; sh = h; } else { Index: xc/programs/Xserver/Xprint/ps/PsPixmap.c =================================================================== RCS file: /cvs/xorg/xc/programs/Xserver/Xprint/ps/PsPixmap.c,v retrieving revision 1.5 diff -u -2 -0 -r1.5 PsPixmap.c --- xc/programs/Xserver/Xprint/ps/PsPixmap.c 25 Oct 2004 07:12:21 -0000 1.5 +++ xc/programs/Xserver/Xprint/ps/PsPixmap.c 17 Apr 2005 19:58:02 -0000 @@ -148,41 +148,41 @@ if( elm->c.polyPts.pPoints ) xfree(elm->c.polyPts.pPoints); break; case PolyFillRectCmd: if( elm->c.rects.pRects ) xfree(elm->c.rects.pRects); break; case PolyArcCmd: if( elm->c.arcs.pArcs ) xfree(elm->c.arcs.pArcs); break; case PolyFillArcCmd: if( elm->c.arcs.pArcs ) xfree(elm->c.arcs.pArcs); break; case Text8Cmd: case TextI8Cmd: if( elm->c.text8.string ) xfree(elm->c.text8.string); break; case Text16Cmd: case TextI16Cmd: if( elm->c.text16.string ) xfree(elm->c.text16.string); break; case PutImageCmd: - if( elm->c.image.pData ) xfree(elm->c.image.pData); + if( elm->c.image.pData ) MapFree(elm->c.image.pData, elm->c.image.pSize); break; case BeginFrameCmd: break; case EndFrameCmd: break; } if (elm->type != BeginFrameCmd && elm->type != EndFrameCmd) { (void) FreeGC(elm->gc, (GContext) 0); } } xfree(oldDisp); } priv->dispList = NULL; } Bool PsDestroyPixmap(PixmapPtr pPixmap) { @@ -299,41 +299,40 @@ void PsReplayPixmap(PixmapPtr pix, DrawablePtr pDrawable) { PsPixmapPrivPtr priv = (PsPixmapPrivPtr)pix->devPrivate.ptr; DisplayListPtr disp = priv->dispList; DisplayElmPtr elm; for(; disp ; disp=disp->next ) { int i; for( i=0,elm=disp->elms ; inelms ; i++,elm++ ) PsReplay(elm, pDrawable); } } int PsCloneDisplayElm(PixmapPtr dst, DisplayElmPtr elm, DisplayElmPtr newElm, int xoff, int yoff) { int i; - int size; int status = 0; *newElm = *elm; /* I think this is the correct return value */ if ((newElm->gc = PsCreateAndCopyGC(&dst->drawable, elm->gc)) == NULL) { return 1; } switch(elm->type) { case PolyPointCmd: case PolyLineCmd: newElm->c.polyPts.pPoints = (xPoint *)xalloc(elm->c.polyPts.nPoints*sizeof(xPoint)); for( i=0 ; ic.polyPts.nPoints ; i++ ) { newElm->c.polyPts.pPoints[i].x = elm->c.polyPts.pPoints[i].x+xoff; newElm->c.polyPts.pPoints[i].y = elm->c.polyPts.pPoints[i].y+yoff; } @@ -410,43 +409,43 @@ newElm->c.arcs.pArcs[i].angle2 = elm->c.arcs.pArcs[i].angle2; } break; case Text8Cmd: case TextI8Cmd: newElm->c.text8.string = (char *)xalloc(elm->c.text8.count); memcpy(newElm->c.text8.string, elm->c.text8.string, elm->c.text8.count); newElm->c.text8.x += xoff; newElm->c.text8.y += yoff; break; case Text16Cmd: case TextI16Cmd: newElm->c.text16.string = (unsigned short *)xalloc(elm->c.text16.count*sizeof(unsigned short)); memcpy(newElm->c.text16.string, elm->c.text16.string, elm->c.text16.count*sizeof(unsigned short)); newElm->c.text16.x += xoff; newElm->c.text16.y += yoff; break; case PutImageCmd: - size = PixmapBytePad(elm->c.image.w, elm->c.image.depth)*elm->c.image.h; - newElm->c.image.pData = (char *)xalloc(size); - memcpy(newElm->c.image.pData, elm->c.image.pData, size); + newElm->c.image.pData = MapAlloc(elm->c.image.pSize, True); + newElm->c.image.pSize = elm->c.image.pSize; + memcpy(newElm->c.image.pData, elm->c.image.pData, elm->c.image.pSize); newElm->c.image.x += xoff; newElm->c.image.y += yoff; break; case BeginFrameCmd: case EndFrameCmd: status = 1; break; } return(status); } void PsCopyDisplayList(PixmapPtr src, PixmapPtr dst, int xoff, int yoff, int x, int y, int w, int h) { PsPixmapPrivPtr sPriv = (PsPixmapPrivPtr)src->devPrivate.ptr; PsPixmapPrivPtr dPriv = (PsPixmapPrivPtr)dst->devPrivate.ptr; DisplayListPtr sDisp; DisplayListPtr dDisp = PsGetFreeDisplayBlock(dPriv); DisplayElmPtr elm = &dDisp->elms[dDisp->nelms]; Index: xc/programs/Xserver/hw/xfree86/loader/dixsym.c =================================================================== RCS file: /cvs/xorg/xc/programs/Xserver/hw/xfree86/loader/dixsym.c,v retrieving revision 1.8 diff -u -2 -0 -r1.8 dixsym.c --- xc/programs/Xserver/hw/xfree86/loader/dixsym.c 1 Apr 2005 20:05:11 -0000 1.8 +++ xc/programs/Xserver/hw/xfree86/loader/dixsym.c 17 Apr 2005 19:58:03 -0000 @@ -1,26 +1,28 @@ /* $XdotOrg: xc/programs/Xserver/hw/xfree86/loader/dixsym.c,v 1.8 2005/04/01 20:05:11 ajax Exp $ */ /* $XFree86: xc/programs/Xserver/hw/xfree86/loader/dixsym.c,v 1.63 2003/12/03 * 17:11:29 tsi Exp $ */ /* * Copyright 1995-1998 by Metro Link, Inc. + * Copyright 2005 Sun Microsystems, Inc. All rights reserved. + * Copyright 2005 Roland Mainz . All rights reserved. * * 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, and that the name of Metro Link, Inc. not be used in * advertising or publicity pertaining to distribution of the software without * specific, written prior permission. Metro Link, Inc. makes no * representations about the suitability of this software for any purpose. * It is provided "as is" without express or implied warranty. * * METRO LINK, INC. DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO * EVENT SHALL METRO LINK, INC. 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. */ /* @@ -308,40 +310,43 @@ SYMFUNC(ResizeChildrenWinSize) SYMFUNC(SaveScreens) SYMFUNC(SendVisibilityNotify) SYMFUNC(SetWinSize) SYMFUNC(SetBorderSize) SYMFUNC(TraverseTree) SYMFUNC(UnmapWindow) SYMFUNC(WalkTree) SYMFUNC(WindowsRestructured) SYMVAR(deltaSaveUndersViewable) SYMVAR(numSaveUndersViewable) SYMVAR(savedScreenInfo) SYMVAR(screenIsSaved) /*os/ */ /* access.c */ SYMFUNC(LocalClient) /* utils.c */ SYMFUNC(Xstrdup) SYMFUNC(XNFstrdup) + SYMFUNC(MapAlloc) + SYMFUNC(MapFree) + SYMVAR(mapallocMinSize) SYMVAR(Must_have_memory) SYMFUNC(AdjustWaitForDelay) SYMVAR(noTestExtensions) SYMFUNC(GiveUp) #ifdef BEZIER SYMVAR(noBezierExtension) #endif #ifdef BIGREQS SYMVAR(noBigReqExtension) #endif #ifdef COMPOSITE SYMVAR(noCompositeExtension) #endif #ifdef DAMAGE SYMVAR(noDamageExtension) #endif #ifdef DBE SYMVAR(noDbeExtension) #endif Index: xc/programs/Xserver/include/os.h =================================================================== RCS file: /cvs/xorg/xc/programs/Xserver/include/os.h,v retrieving revision 1.5 diff -u -2 -0 -r1.5 os.h --- xc/programs/Xserver/include/os.h 3 Dec 2004 11:57:42 -0000 1.5 +++ xc/programs/Xserver/include/os.h 17 Apr 2005 19:58:04 -0000 @@ -1,24 +1,26 @@ /* $XFree86: xc/programs/Xserver/include/os.h,v 3.54 2003/10/30 21:21:06 herrb Exp $ */ /*********************************************************** Copyright 1987, 1998 The Open Group +Copyright 2005 Sun Microsystems, Inc. All rights reserved. +Copyright 2005 Roland Mainz . All rights reserved. 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. @@ -244,40 +246,44 @@ #define _HAVE_XALLOC_DECLS extern pointer Xalloc(unsigned long /*amount*/); extern pointer Xcalloc(unsigned long /*amount*/); extern pointer Xrealloc(pointer /*ptr*/, unsigned long /*amount*/); extern void Xfree(pointer /*ptr*/); #endif extern pointer XNFalloc(unsigned long /*amount*/); extern pointer XNFcalloc(unsigned long /*amount*/); extern pointer XNFrealloc(pointer /*ptr*/, unsigned long /*amount*/); extern void OsInitAllocator(void); extern char *Xstrdup(const char *s); extern char *XNFstrdup(const char *s); extern char *Xprintf(const char *fmt, ...); extern char *Xvprintf(const char *fmt, va_list va); extern char *XNFprintf(const char *fmt, ...); extern char *XNFvprintf(const char *fmt, va_list va); +extern unsigned long mapallocMinSize; /* semi-private */ +extern void *MapAlloc(unsigned long size, Bool reserveswap); +extern void MapFree(void *ptr, unsigned long size); + typedef SIGVAL (*OsSigHandlerPtr)(int /* sig */); extern OsSigHandlerPtr OsSignal(int /* sig */, OsSigHandlerPtr /* handler */); extern int auditTrailLevel; #ifdef SERVER_LOCK extern void LockServer(void); extern void UnlockServer(void); #endif extern int OsLookupColor( int /*screen*/, char * /*name*/, unsigned /*len*/, unsigned short * /*pred*/, unsigned short * /*pgreen*/, unsigned short * /*pblue*/); extern void OsInit(void); Index: xc/programs/Xserver/os/Imakefile =================================================================== RCS file: /cvs/xorg/xc/programs/Xserver/os/Imakefile,v retrieving revision 1.8 diff -u -2 -0 -r1.8 Imakefile --- xc/programs/Xserver/os/Imakefile 23 Mar 2005 19:58:45 -0000 1.8 +++ xc/programs/Xserver/os/Imakefile 17 Apr 2005 19:58:05 -0000 @@ -52,40 +52,44 @@ 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 HasUsableFileMmap +MMAPDEFINES = -DUSE_MMAP +#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 @@ -111,41 +115,42 @@ 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) + $(RANDOM_DEFINES) $(BUGMSG) $(XTRANS_FAILDEFINES) \ + $(MMAPDEFINES) 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() NormalLibraryTarget(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 Index: xc/programs/Xserver/os/utils.c =================================================================== RCS file: /cvs/xorg/xc/programs/Xserver/os/utils.c,v retrieving revision 1.12 diff -u -2 -0 -r1.12 utils.c --- xc/programs/Xserver/os/utils.c 23 Mar 2005 19:58:45 -0000 1.12 +++ xc/programs/Xserver/os/utils.c 17 Apr 2005 19:58:06 -0000 @@ -1,25 +1,26 @@ /* $XdotOrg: xc/programs/Xserver/os/utils.c,v 1.12 2005/03/23 19:58:45 gisburn Exp $ */ /* $Xorg: utils.c,v 1.5 2001/02/09 02:05:24 xorgcvs Exp $ */ /* Copyright 1987, 1998 The Open Group +Copyright 2005 Sun Microsystems, Inc. All rights reserved. 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 @@ -82,40 +83,47 @@ #endif #endif #ifndef WIN32 #include #endif #if !defined(SYSV) && !defined(WIN32) && !defined(Lynx) && !defined(QNX4) #include #endif #include #include #include /* for isspace */ #include #if defined(DGUX) #include #include #endif #include /* for malloc() */ +#if defined(USE_MMAP) && (!(defined(MEMBUG) || defined(PURIFY))) +# define MAPALLOCMEM 1 +#endif +#ifdef MAPALLOCMEM +#include /* for |MapAlloc()| and |MapFree()| */ +#endif /* MAPALLOCMEM */ + #if defined(TCPCONN) || defined(STREAMSCONN) # ifndef WIN32 # include # endif #endif #include "opaque.h" #ifdef SMART_SCHEDULE #include "dixstruct.h" #endif #ifdef XKB #include "XKBsrv.h" #endif #ifdef XCSECURITY #define _SECURITY_SERVER #include "security.h" #endif @@ -581,40 +589,43 @@ else { olddelay = (*wt)->tv_sec * 1000 + (*wt)->tv_usec / 1000; if (newdelay < olddelay) { (*wt)->tv_sec = newdelay / 1000; (*wt)->tv_usec = 1000 * (newdelay % 1000); } } } void UseMsg(void) { #if !defined(AIXrt) && !defined(AIX386) ErrorF("use: X [:] [option]\n"); ErrorF("-a # mouse acceleration (pixels)\n"); ErrorF("-ac disable access control restrictions\n"); #ifdef MEMBUG ErrorF("-alloc int chance alloc should fail\n"); #endif +#ifdef MAPALLOCMEM + ErrorF("-mapallocmin int set minimum value for mmap()-based memory allocations\n"); +#endif /* MAPALLOCMEM */ ErrorF("-audit int set audit trail level\n"); ErrorF("-auth file select authorization file\n"); ErrorF("bc enable bug compatibility\n"); ErrorF("-br create root window with black background\n"); ErrorF("+bs enable any backing store support\n"); ErrorF("-bs disable any backing store support\n"); ErrorF("-c turns off key-click\n"); ErrorF("c # key-click volume (0-100)\n"); ErrorF("-cc int default color visual class\n"); ErrorF("-co file color database file\n"); #ifdef COMMANDLINE_CHALLENGED_OPERATING_SYSTEMS ErrorF("-config file read options from file\n"); #endif ErrorF("-core generate core dump on fatal error\n"); ErrorF("-dpi int screen resolution in dots per inch\n"); #ifdef DPMSExtension ErrorF("dpms enables VESA DPMS monitor control\n"); ErrorF("-dpms disables VESA DPMS monitor control\n"); #endif ErrorF("-deferglyphs [none|all|16] defer loading of [no|all|16-bit] glyphs\n"); @@ -755,40 +766,49 @@ else if ( strcmp( argv[i], "-a") == 0) { if(++i < argc) defaultPointerControl.num = atoi(argv[i]); else UseMsg(); } else if ( strcmp( argv[i], "-ac") == 0) { defeatAccessControl = TRUE; } #ifdef MEMBUG else if ( strcmp( argv[i], "-alloc") == 0) { if(++i < argc) Memory_fail = atoi(argv[i]); else UseMsg(); } #endif +#ifdef MAPALLOCMEM + else if ( strcmp( argv[i], "-mapallocmin") == 0) + { + if(++i < argc) + mapallocMinSize = atol(argv[i]); + else + UseMsg(); + } +#endif /* MAPALLOCMEM */ else if ( strcmp( argv[i], "-audit") == 0) { if(++i < argc) auditTrailLevel = atoi(argv[i]); else UseMsg(); } else if ( strcmp( argv[i], "-auth") == 0) { if(++i < argc) InitAuthorization (argv[i]); else UseMsg(); } else if ( strcmp( argv[i], "bc") == 0) permitOldBugs = TRUE; else if ( strcmp( argv[i], "-br") == 0) blackRoot = TRUE; else if ( strcmp( argv[i], "+bs") == 0) enableBackingStore = TRUE; @@ -1513,40 +1533,112 @@ sd = (char *)Xalloc(strlen(s) + 1); if (sd != NULL) strcpy(sd, s); return sd; } char * XNFstrdup(const char *s) { char *sd; if (s == NULL) return NULL; sd = (char *)XNFalloc(strlen(s) + 1); strcpy(sd, s); return sd; } +/* + * MapAlloc() and MapFree() form an alternate memory allocator scheme + * based on mapping /dev/zero. This interface is meant to be used for + * allocating large, relatively long-term memory such as pixmaps or + * image buffers (for Mesa/GL, Xprintor VectorMaps) that should have + * their memory resources returned back to the OS. + * Allocations smaller than |mapallocMinSize| are allocated using + * |xalloc()| to avoid wasted memory and mapping overhead. + * + * The default value for |mapallocMinSize| is set to 256KB which + * was chosen with TLB usage, page size and memory fragmentation + * in mind (the original size of 8KB was set when the common desktop + * was a Sparc 2 with 32MB and 1-bit or 8-bit pixmaps, the new value + * targets modern machines which have displays with 32-bit pixmaps + * (see SunSolve issue #4771300 ("threshold for mmap() allocations of + * pixmaps should be raised")). + * The value can be altered using the "-mapallocmin" tuneable. + * Setting this value to "-1" will effectively turn the usage of + * |mmap()| for this kind of memory allocations off. + */ +unsigned long mapallocMinSize = 256 * 1024; /* 256kb */ + +void * +MapAlloc(unsigned long size, Bool reserveswap) +{ + caddr_t ptr; + int flags; + +#ifdef MAPALLOCMEM_DEBUG + ErrorF("MapAlloc: size=%lu, reserveswap=%d\n", size, (int)reserveswap); +#endif + +#ifndef MAPALLOCMEM + ptr = (caddr_t)xalloc(size); +#else + if (size < mapallocMinSize) { + return (void *)xalloc(size); + } + + flags = reserveswap == FALSE ? MAP_PRIVATE|MAP_NORESERVE : MAP_PRIVATE; + flags |= MAP_ANON; + + ptr = mmap((caddr_t)0, (size_t)size, PROT_READ|PROT_WRITE, + flags, -1, (off_t)0); + if (ptr == MAP_FAILED) { + ptr = (caddr_t)0; + } +#endif /* MAPALLOCMEM */ + + return (void *)ptr; +} + +void +MapFree(void *ptr, unsigned long size) +{ +#ifdef MAPALLOCMEM_DEBUG + ErrorF("MapFree: ptr=%p, size=%lu\n", ptr, size); +#endif + +#ifndef MAPALLOCMEM + xfree(ptr); +#else + if (size < mapallocMinSize) { + xfree(ptr); + return; + } + if (munmap((caddr_t)ptr, (size_t)size) == -1) { + FatalError("MapFree: munmap error, ptr=%p, size=%lu\n", ptr, size); + } +#endif /* MAPALLOCMEM */ +} + #ifdef SMART_SCHEDULE unsigned long SmartScheduleIdleCount; Bool SmartScheduleIdle; Bool SmartScheduleTimerStopped; #ifdef SIGVTALRM #define SMART_SCHEDULE_POSSIBLE #endif #ifdef SMART_SCHEDULE_POSSIBLE #define SMART_SCHEDULE_SIGNAL SIGALRM #define SMART_SCHEDULE_TIMER ITIMER_REAL #endif static void SmartScheduleStopTimer (void) { #ifdef SMART_SCHEDULE_POSSIBLE struct itimerval timer;