From 2646fc254e75c4a7fc10d03d1139d0bd708ceae9 Mon Sep 17 00:00:00 2001 From: Mike Gabriel Date: Sun, 26 Jun 2016 01:51:18 +0200 Subject: nx-X11/programs/Xserver: Drop {X,x}alloc() macros, use malloc() instead. --- nx-X11/programs/Xserver/os/Imakefile | 17 +- nx-X11/programs/Xserver/os/WaitFor.c | 2 +- nx-X11/programs/Xserver/os/access.c | 12 +- nx-X11/programs/Xserver/os/connection.c | 6 +- nx-X11/programs/Xserver/os/io.c | 8 +- nx-X11/programs/Xserver/os/log.c | 4 +- nx-X11/programs/Xserver/os/mitauth.c | 4 +- nx-X11/programs/Xserver/os/oscolor.c | 6 +- nx-X11/programs/Xserver/os/rpcauth.c | 4 +- nx-X11/programs/Xserver/os/utils.c | 18 +- nx-X11/programs/Xserver/os/xalloc.c | 817 -------------------------------- nx-X11/programs/Xserver/os/xdmauth.c | 8 +- nx-X11/programs/Xserver/os/xdmcp.c | 6 +- nx-X11/programs/Xserver/os/xprintf.c | 4 +- 14 files changed, 40 insertions(+), 876 deletions(-) delete mode 100644 nx-X11/programs/Xserver/os/xalloc.c (limited to 'nx-X11/programs/Xserver/os') diff --git a/nx-X11/programs/Xserver/os/Imakefile b/nx-X11/programs/Xserver/os/Imakefile index 00d28deb1..802725306 100644 --- a/nx-X11/programs/Xserver/os/Imakefile +++ b/nx-X11/programs/Xserver/os/Imakefile @@ -91,11 +91,6 @@ 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 @@ -119,19 +114,13 @@ BOOTSTRAPCFLAGS = osinit.c utils.c log.c auth.c mitauth.c secauth.c \ $(XDMAUTHSRCS) $(RPCSRCS) xdmcp.c OtherSources \ transport.c $(SNPRINTF_SRCS) $(STRLCAT_SRCS) \ - $(MALLOC_SRCS) xprintf.c + 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) xdmcp.o OtherObjects \ transport.o $(SNPRINTF_OBJS) $(STRLCAT_OBJS) \ - $(MALLOC_OBJS) xprintf.o + xprintf.o -#if SpecialMalloc - MEM_DEFINES = -DSPECIAL_MALLOC -#endif /* SpecialMalloc */ -#if UseInternalMalloc - MEM_DEFINES = -DINTERNAL_MALLOC -#endif #if UseMemLeak MEM_DEFINES = -DMEMBUG #endif @@ -141,7 +130,6 @@ BOOTSTRAPCFLAGS = DBM_DEFINES = NdbmDefines ADM_DEFINES = -DADMPATH=\"$(ADMDIR)/X\%smsgs\" XDMCP_DEFINES = ServerXdmcpDefines - XALLOC_DEFINES = XallocDefines ERROR_DEFINES = ServerErrorDefines #if HasPam && HasPamMisc PAM_DEFINES = -DUSE_PAM @@ -189,7 +177,6 @@ SpecialCObjectRule(osinit,$(ICONFIGFILES),$(ADM_DEFINES)) SpecialCObjectRule(WaitFor,$(ICONFIGFILES),$(EXT_DEFINES)) SpecialCObjectRule(io,$(ICONFIGFILES),$(EXT_DEFINES)) 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) $@ diff --git a/nx-X11/programs/Xserver/os/WaitFor.c b/nx-X11/programs/Xserver/os/WaitFor.c index f9037ed3b..0f23c9d4a 100644 --- a/nx-X11/programs/Xserver/os/WaitFor.c +++ b/nx-X11/programs/Xserver/os/WaitFor.c @@ -650,7 +650,7 @@ TimerSet(OsTimerPtr timer, int flags, CARD32 millis, if (!timer) { - timer = (OsTimerPtr)xalloc(sizeof(struct _OsTimerRec)); + timer = (OsTimerPtr)malloc(sizeof(struct _OsTimerRec)); if (!timer) return NULL; } diff --git a/nx-X11/programs/Xserver/os/access.c b/nx-X11/programs/Xserver/os/access.c index dcd2b52af..4090a9589 100644 --- a/nx-X11/programs/Xserver/os/access.c +++ b/nx-X11/programs/Xserver/os/access.c @@ -256,7 +256,7 @@ typedef struct _host { int requested; } HOST; -#define MakeHost(h,l) (h)=(HOST *) xalloc(sizeof *(h)+(l));\ +#define MakeHost(h,l) (h)=(HOST *) malloc(sizeof *(h)+(l));\ if (h) { \ (h)->addr=(unsigned char *) ((h) + 1);\ (h)->requested = FALSE; \ @@ -782,7 +782,7 @@ DefineSelf (int fd) Error ("Getting interface count"); if (len < (ifn.lifn_count * sizeof(struct lifreq))) { len = ifn.lifn_count * sizeof(struct lifreq); - bufptr = xalloc(len); + bufptr = malloc(len); } #endif @@ -1477,7 +1477,7 @@ LocalClientCredAndGroups(ClientPtr client, int *pUid, int *pGid, const gid_t *gids; *nSuppGids = ucred_getgroups(peercred, &gids); if (*nSuppGids > 0) { - *pSuppGids = xalloc(sizeof(int) * (*nSuppGids)); + *pSuppGids = malloc(sizeof(int) * (*nSuppGids)); if (*pSuppGids == NULL) { *nSuppGids = 0; } else { @@ -1691,7 +1691,7 @@ GetHosts ( } if (n) { - *data = ptr = (void *) xalloc (n); + *data = ptr = (void *) malloc (n); if (!ptr) { return(BadAlloc); @@ -1951,7 +1951,7 @@ siTypeAdd(const char *typeName, siAddrMatchFunc addrMatch, } } - s = (struct siType *) xalloc(sizeof(struct siType)); + s = (struct siType *) malloc(sizeof(struct siType)); if (s == NULL) return BadAlloc; @@ -2293,7 +2293,7 @@ static Bool siLocalCredGetId(const char *addr, int len, siLocalCredPrivPtr lcPriv, int *id) { Bool parsedOK = FALSE; - char *addrbuf = xalloc(len + 1); + char *addrbuf = malloc(len + 1); if (addrbuf == NULL) { return FALSE; diff --git a/nx-X11/programs/Xserver/os/connection.c b/nx-X11/programs/Xserver/os/connection.c index 4d5826888..15321458e 100644 --- a/nx-X11/programs/Xserver/os/connection.c +++ b/nx-X11/programs/Xserver/os/connection.c @@ -261,7 +261,7 @@ void SetConnectionTranslation(int conn, int client) } node = &((*node)->next); } - *node = (struct _ct_node*)xalloc(sizeof(struct _ct_node)); + *node = (struct _ct_node*)malloc(sizeof(struct _ct_node)); (*node)->next = NULL; (*node)->key = conn; (*node)->value = client; @@ -407,7 +407,7 @@ CreateWellKnownSockets(void) } else { - ListenTransFds = (int *) xalloc (ListenTransCount * sizeof (int)); + ListenTransFds = (int *) malloc (ListenTransCount * sizeof (int)); for (i = 0; i < ListenTransCount; i++) { @@ -764,7 +764,7 @@ AllocNewConnection (XtransConnInfo trans_conn, int fd, CARD32 conn_time) #endif ) return NullClient; - oc = (OsCommPtr)xalloc(sizeof(OsCommRec)); + oc = (OsCommPtr)malloc(sizeof(OsCommRec)); if (!oc) return NullClient; oc->trans_conn = trans_conn; diff --git a/nx-X11/programs/Xserver/os/io.c b/nx-X11/programs/Xserver/os/io.c index b8f05d939..3e9abb35c 100644 --- a/nx-X11/programs/Xserver/os/io.c +++ b/nx-X11/programs/Xserver/os/io.c @@ -1171,10 +1171,10 @@ AllocateInputBuffer(void) { ConnectionInputPtr oci; - oci = (ConnectionInputPtr)xalloc(sizeof(ConnectionInput)); + oci = (ConnectionInputPtr)malloc(sizeof(ConnectionInput)); if (!oci) return (ConnectionInputPtr)NULL; - oci->buffer = (char *)xalloc(BUFSIZE); + oci->buffer = (char *)malloc(BUFSIZE); if (!oci->buffer) { free(oci); @@ -1192,10 +1192,10 @@ AllocateOutputBuffer(void) { ConnectionOutputPtr oco; - oco = (ConnectionOutputPtr)xalloc(sizeof(ConnectionOutput)); + oco = (ConnectionOutputPtr)malloc(sizeof(ConnectionOutput)); if (!oco) return (ConnectionOutputPtr)NULL; - oco->buf = (unsigned char *) xalloc(BUFSIZE); + oco->buf = (unsigned char *) malloc(BUFSIZE); if (!oco->buf) { free(oco); diff --git a/nx-X11/programs/Xserver/os/log.c b/nx-X11/programs/Xserver/os/log.c index 12827cbe0..d97317819 100644 --- a/nx-X11/programs/Xserver/os/log.c +++ b/nx-X11/programs/Xserver/os/log.c @@ -186,7 +186,7 @@ LogInit(const char *fname, const char *backup) char *logFileName = NULL; if (fname && *fname) { - /* xalloc() can't be used yet. */ + /* malloc() can't be used yet. */ logFileName = malloc(strlen(fname) + strlen(display) + 1); if (!logFileName) FatalError("Cannot allocate space for the log file name\n"); @@ -333,7 +333,7 @@ LogVWrite(int verb, const char *f, va_list args) } else if (needBuffer) { /* * Note, this code is used before OsInit() has been called, so - * xalloc() and friends can't be used. + * malloc() and friends can't be used. */ if (len > bufferUnused) { bufferSize += 1024; diff --git a/nx-X11/programs/Xserver/os/mitauth.c b/nx-X11/programs/Xserver/os/mitauth.c index 4c1ae9cf6..2630a81ae 100644 --- a/nx-X11/programs/Xserver/os/mitauth.c +++ b/nx-X11/programs/Xserver/os/mitauth.c @@ -57,10 +57,10 @@ MitAddCookie ( { struct auth *new; - new = (struct auth *) xalloc (sizeof (struct auth)); + new = (struct auth *) malloc (sizeof (struct auth)); if (!new) return 0; - new->data = (char *) xalloc ((unsigned) data_length); + new->data = (char *) malloc ((unsigned) data_length); if (!new->data) { free(new); return 0; diff --git a/nx-X11/programs/Xserver/os/oscolor.c b/nx-X11/programs/Xserver/os/oscolor.c index 8f737eaba..2ea81060d 100644 --- a/nx-X11/programs/Xserver/os/oscolor.c +++ b/nx-X11/programs/Xserver/os/oscolor.c @@ -134,11 +134,11 @@ OsLookupColor(int screen, char *name, unsigned int len, if(!rgb_dbm) return(0); - /* we use xalloc here so that we can compile with cc without alloca + /* we use malloc here so that we can compile with cc without alloca * when otherwise using gcc */ if (len < sizeof(buf)) lowername = buf; - else if (!(lowername = (char *)xalloc(len + 1))) + else if (!(lowername = (char *)malloc(len + 1))) return(0); CopyISOLatin1Lowered ((unsigned char *) lowername, (unsigned char *) name, (int)len); @@ -372,7 +372,7 @@ lookup(char *name, int len, Bool create) else prev = &(hashTab[h]); - if (!entry && create && (entry = (dbEntryPtr)xalloc(sizeof(dbEntry) +len))) + if (!entry && create && (entry = (dbEntryPtr)malloc(sizeof(dbEntry) +len))) { *prev = entry; entry->link = NULL; diff --git a/nx-X11/programs/Xserver/os/rpcauth.c b/nx-X11/programs/Xserver/os/rpcauth.c index 1b3db1e0e..40ea7ad97 100644 --- a/nx-X11/programs/Xserver/os/rpcauth.c +++ b/nx-X11/programs/Xserver/os/rpcauth.c @@ -77,7 +77,7 @@ authdes_ezdecode(char *inmsg, int len) XDR xdr; SVCXPRT xprt; - temp_inmsg = (char *) xalloc(len); + temp_inmsg = (char *) malloc(len); if (temp_inmsg == NULL) { why = AUTH_FAILED; /* generic error, since there is no AUTH_BADALLOC */ return NULL; @@ -94,7 +94,7 @@ authdes_ezdecode(char *inmsg, int len) why = AUTH_FAILED; xdrmem_create(&xdr, temp_inmsg, len, XDR_DECODE); - if ((r.rq_clntcred = (caddr_t) xalloc(MAX_AUTH_BYTES)) == NULL) + if ((r.rq_clntcred = (caddr_t) malloc(MAX_AUTH_BYTES)) == NULL) goto bad1; r.rq_xprt = &xprt; diff --git a/nx-X11/programs/Xserver/os/utils.c b/nx-X11/programs/Xserver/os/utils.c index 03deb811a..98e3cab8b 100644 --- a/nx-X11/programs/Xserver/os/utils.c +++ b/nx-X11/programs/Xserver/os/utils.c @@ -261,12 +261,6 @@ int SyncOn = 0; extern int SelectWaitTime; #endif -#ifdef DEBUG -#ifndef SPECIAL_MALLOC -#define MEMBUG -#endif -#endif - #if defined(SVR4) || defined(__linux__) || defined(CSRG_BASED) #define HAS_SAVED_IDS_AND_SETEUID #endif @@ -1186,7 +1180,7 @@ InsertFileIntoCommandLine( fstat(fileno(f), &st); - buf = (char *) xalloc((unsigned) st.st_size + 1); + buf = (char *) malloc((unsigned) st.st_size + 1); if (!buf) FatalError("Out of Memory\n"); @@ -1231,7 +1225,7 @@ InsertFileIntoCommandLine( FatalError("Out of memory reallocing option buf\n"); *resargc = prefix_argc + insert_argc + suffix_argc; - *resargv = (char **) xalloc((*resargc + 1) * sizeof(char *)); + *resargv = (char **) malloc((*resargc + 1) * sizeof(char *)); if (!*resargv) FatalError("Out of Memory\n"); @@ -1316,7 +1310,7 @@ set_font_authorizations(char **authorizations, int *authlen, void * client) #endif len = strlen(hnameptr) + 1; - result = xalloc(len + sizeof(AUTHORIZATION_NAME) + 4); + result = malloc(len + sizeof(AUTHORIZATION_NAME) + 4); p = result; *p++ = sizeof(AUTHORIZATION_NAME) >> 8; @@ -1517,7 +1511,7 @@ Xstrdup(const char *s) if (s == NULL) return NULL; - sd = (char *)Xalloc(strlen(s) + 1); + sd = (char *)malloc(strlen(s) + 1); if (sd != NULL) strcpy(sd, s); return sd; @@ -1808,7 +1802,7 @@ Popen(char *command, char *type) if ((*type != 'r' && *type != 'w') || type[1]) return NULL; - if ((cur = (struct pid *)xalloc(sizeof(struct pid))) == NULL) + if ((cur = (struct pid *)malloc(sizeof(struct pid))) == NULL) return NULL; if (pipe(pdes) < 0) { @@ -1946,7 +1940,7 @@ Fopen(char *file, char *type) if ((*type != 'r' && *type != 'w') || type[1]) return NULL; - if ((cur = (struct pid *)xalloc(sizeof(struct pid))) == NULL) + if ((cur = (struct pid *)malloc(sizeof(struct pid))) == NULL) return NULL; if (pipe(pdes) < 0) { diff --git a/nx-X11/programs/Xserver/os/xalloc.c b/nx-X11/programs/Xserver/os/xalloc.c deleted file mode 100644 index 4d2d3f1ee..000000000 --- a/nx-X11/programs/Xserver/os/xalloc.c +++ /dev/null @@ -1,817 +0,0 @@ -#define FATALERRORS 1 -/* -Copyright (C) 1995 Pascal Haible. 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, sublicense, -and/or sell copies of the Software, and to permit persons to whom the -Software is furnished to do so, subject to the following conditions: - -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 -PASCAL HAIBLE 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 Pascal Haible shall -not be used in advertising or otherwise to promote the sale, use or other -dealings in this Software without prior written authorization from -Pascal Haible. -*/ - -/* $XFree86: xc/programs/Xserver/os/xalloc.c,v 3.35tsi Exp $ */ - -/* Only used if INTERNAL_MALLOC is defined - * - otherwise xalloc() in utils.c is used - */ -#ifdef HAVE_DIX_CONFIG_H -#include -#endif - -#ifdef INTERNAL_MALLOC - -#include /* for malloc() etc. */ - -#include -#include "misc.h" -#include - -#ifdef XALLOC_LOG -#include -#endif - -extern Bool Must_have_memory; - -/* - ***** New malloc approach for the X server ***** - * Pascal Haible 1995 - * - * Some statistics about memory allocation of the X server - * The test session included several clients of different size, including - * xv, emacs and xpaint with a new canvas of 3000x2000, zoom 5. - * All clients were running together. - * A protocolling version of Xalloc recorded 318917 allocating actions - * (191573 Xalloc, 85942 XNFalloc, 41438 Xrealloc, 279727 Xfree). - * Results grouped by size, excluding the next lower size - * (i.e. size=32 means 16=11k) are mmapped on xalloc, and unmapped on xfree, - * so we don't need any free lists etc. - * As this needs 2 system calls, we only do this for the quite - * infrequent large (>=11k) blocks. - * - instead of reinventing the wheel, we use system malloc for medium - * sized blocks (>256, <11k). - * - for small blocks (<=256) we use an other approach: - * As we need many small blocks, and most ones for a short time, - * we don't go through the system malloc: - * for each fixed sizes a seperate list of free blocks is kept. - * to KISS (Keep it Small and Simple), we don't free them - * (not freeing a block of 32 bytes won't be worse than having fragmented - * a larger area on allocation). - * This way, we (almost) allways have a fitting free block right at hand, - * and don't have to walk any lists. - */ - -/* - * structure layout of a allocated block - * unsigned long size: - * rounded up netto size for small and medium blocks - * brutto size == mmap'ed area for large blocks - * unsigned long DEBUG ? MAGIC : unused - * .... data - * ( unsigned long MAGIC2 ) only if SIZE_TAIL defined - * - */ - -/* use otherwise unused long in the header to store a magic */ -/* shouldn't this be removed for production release ? */ -#define XALLOC_DEBUG - -#ifdef XALLOC_DEBUG -/* Xfree fills the memory with a certain pattern (currently 0xF0) */ -/* this should really be removed for production release! */ -#define XFREE_ERASES -#endif - -/* this must be a multiple of SIZE_STEPS below */ -#define MAX_SMALL 264 /* quite many blocks of 264 */ - -#define MIN_LARGE (11*1024) -/* worst case is 25% loss with a page size of 4k */ - -/* SIZE_STEPS defines the granularity of size of small blocks - - * this makes blocks align to that, too! */ -#define SIZE_STEPS (sizeof(double)) -#define SIZE_HEADER (2*sizeof(long)) /* = sizeof(double) for 32bit */ -#ifdef XALLOC_DEBUG -#if defined(__sparc__) -#define SIZE_TAIL (2*sizeof(long)) /* = sizeof(double) for 32bit */ -#else -#define SIZE_TAIL (sizeof(long)) -#endif -#endif - -#undef TAIL_SIZE -#ifdef SIZE_TAIL -#define TAIL_SIZE SIZE_TAIL -#else -#define TAIL_SIZE 0 -#endif - -#if defined (_LP64) || \ - defined(__alpha__) || defined(__alpha) || \ - defined(__ia64__) || defined(ia64) || \ - defined(__sparc64__) || \ - defined(__s390x__) || \ - defined(__amd64__) || defined(amd64) || \ - defined(__powerpc64__) || \ - (defined(sgi) && _MIPS_SZLONG == 64)) -#define MAGIC 0x1404196414071968 -#define MAGIC_FREE 0x1506196615061966 -#define MAGIC2 0x2515207525182079 -#else -#define MAGIC 0x14071968 -#define MAGIC_FREE 0x15061966 -#define MAGIC2 0x25182079 -#endif - -/* To get some statistics about memory allocation */ - -#ifdef XALLOC_LOG -#define XALLOC_LOG_FILE "/tmp/Xalloc.log" /* unsecure... */ -#define LOG_BODY(_body) \ - { FILE *f; \ - f = fopen(XALLOC_LOG_FILE, "a"); \ - if (NULL!=f) { \ - _body; \ - fclose(f); \ - } \ - } -#if defined(linux) && defined(i386) -#define LOG_ALLOC(_fun, _size, _ret) \ - { unsigned long *from; \ - __asm__("movl %%ebp,%0" : /*OUT*/ "=r" (from) : /*IN*/ ); \ - LOG_BODY(fprintf(f, "%s\t%i\t%p\t[%lu]\n", _fun, _size, _ret, *(from+1))) \ - } -#else -#define LOG_ALLOC(_fun, _size, _ret) \ - LOG_BODY(fprintf(f, "%s\t%i\t%p\n", _fun, _size, _ret)) -#endif -#define LOG_REALLOC(_fun, _ptr, _size, _ret) \ - LOG_BODY(fprintf(f, "%s\t%p\t%i\t%p\n", _fun, _ptr, _size, _ret)) -#define LOG_FREE(_fun, _ptr) \ - LOG_BODY(fprintf(f, "%s\t%p\n", _fun, _ptr)) -#else -#define LOG_ALLOC(_fun, _size, _ret) -#define LOG_REALLOC(_fun, _ptr, _size, _ret) -#define LOG_FREE(_fun, _ptr) -#endif /* XALLOC_LOG */ - -static unsigned long *free_lists[MAX_SMALL/SIZE_STEPS]; - -/* - * systems that support it should define HAS_MMAP_ANON or MMAP_DEV_ZERO - * and include the appropriate header files for - * mmap(), munmap(), PROT_READ, PROT_WRITE, MAP_PRIVATE, - * PAGE_SIZE or _SC_PAGESIZE (and MAP_ANON for HAS_MMAP_ANON). - * - * systems that don't support MAP_ANON fall through to the 2 fold behaviour - */ - -#if defined(linux) -#define HAS_MMAP_ANON -#include -#include -#include /* PAGE_SIZE */ -#define HAS_SC_PAGESIZE /* _SC_PAGESIZE may be an enum for Linux */ -#define HAS_GETPAGESIZE -#endif /* linux */ - -#if defined(__GNU__) -#define HAS_MMAP_ANON -#include -#include -#include /* PAGE_SIZE */ -#define HAS_SC_PAGESIZE -#define HAS_GETPAGESIZE -#endif /* __GNU__ */ - -#if defined(CSRG_BASED) -#define HAS_MMAP_ANON -#define HAS_GETPAGESIZE -#include -#include -#endif /* CSRG_BASED */ - -#if defined(DGUX) -#define HAS_GETPAGESIZE -#define MMAP_DEV_ZERO -#include -#include -#include -#endif /* DGUX */ - -#if defined(SVR4) && !defined(DGUX) -#define MMAP_DEV_ZERO -#include -#include -#include -#endif /* SVR4 && !DGUX */ - -#if defined(sun) && !defined(SVR4) /* SunOS */ -#define MMAP_DEV_ZERO /* doesn't SunOS have MAP_ANON ?? */ -#define HAS_GETPAGESIZE -#include -#include -#endif /* sun && !SVR4 */ - -#ifdef XNO_SYSCONF -#undef _SC_PAGESIZE -#endif - -#if defined(HAS_MMAP_ANON) || defined (MMAP_DEV_ZERO) -static int pagesize; -#endif - -#ifdef MMAP_DEV_ZERO -static int devzerofd = -1; -#include -#endif - -/* - * empty trap function for gdb. Breakpoint here - * to find who tries to free a free area - */ -void XfreeTrap(void) -{ -} - -void * -Xalloc (unsigned long amount) -{ - register unsigned long *ptr; - int indx; - - /* sanity checks */ - - /* zero size requested */ - if (amount == 0) { - LOG_ALLOC("Xalloc=0", amount, 0); - return NULL; - } - /* negative size (or size > 2GB) - what do we do? */ - if ((long)amount < 0) { - /* Diagnostic */ -#ifdef FATALERRORS - FatalError("Xalloc: Xalloc(<0)\n"); -#else - ErrorF("Xalloc warning: Xalloc(<0) ignored..\n"); -#endif - LOG_ALLOC("Xalloc<0", amount, 0); - return NULL; - } - - /* alignment check */ -#if defined(__alpha__) || defined(__alpha) || \ - defined(__sparc__) || \ - defined(__mips__) || \ - defined(__powerpc__) || \ - defined(__arm32__) || \ - defined(__ia64__) || defined(ia64) || \ - defined(__s390x__) || defined(__s390__) - amount = (amount + (sizeof(long)-1)) & ~(sizeof(long)-1); -#endif - - if (amount <= MAX_SMALL) { - /* - * small block - */ - /* pick a ready to use small chunk */ - indx = (amount-1) / SIZE_STEPS; - ptr = free_lists[indx]; - if (NULL == ptr) { - /* list empty - get 20 or 40 more */ - /* amount = size rounded up */ - amount = (indx+1) * SIZE_STEPS; - ptr = (unsigned long *)calloc(1,(amount+SIZE_HEADER+TAIL_SIZE) - * (amount<100 ? 40 : 20)); - if (NULL!=ptr) { - int i; - unsigned long *p1, *p2; - p1 = 0; - p2 = (unsigned long *)((char *)ptr + SIZE_HEADER); - for (i=0; i<(amount<100 ? 40 : 20); i++) { - p1 = p2; - p1[-2] = amount; -#ifdef XALLOC_DEBUG - p1[-1] = MAGIC_FREE; -#endif /* XALLOC_DEBUG */ -#ifdef SIZE_TAIL - *(unsigned long *)((unsigned char *)p1 + amount) = MAGIC2; -#endif /* SIZE_TAIL */ - p2 = (unsigned long *)((char *)p1 + SIZE_HEADER + amount + TAIL_SIZE); - *(unsigned long **)p1 = p2; - } - /* last one has no next one */ - *(unsigned long **)p1 = NULL; - /* put the second in the list */ - free_lists[indx] = (unsigned long *)((char *)ptr + SIZE_HEADER + amount + TAIL_SIZE + SIZE_HEADER); - /* take the fist one */ - ptr = (unsigned long *)((char *)ptr + SIZE_HEADER); - LOG_ALLOC("Xalloc-S", amount, ptr); - ptr[-1] = MAGIC; - return (void *)ptr; - } /* else fall through to 'Out of memory' */ - } else { - /* take that piece of mem out of the list */ - free_lists[indx] = *((unsigned long **)ptr); - /* already has size (and evtl. magic) filled in */ -#ifdef XALLOC_DEBUG - ptr[-1] = MAGIC; -#endif /* XALLOC_DEBUG */ - LOG_ALLOC("Xalloc-S", amount, ptr); - return (void *)ptr; - } - -#if defined(HAS_MMAP_ANON) || defined(MMAP_DEV_ZERO) - } else if (amount >= MIN_LARGE) { - /* - * large block - */ - /* mmapped malloc */ - /* round up amount */ - amount += SIZE_HEADER + TAIL_SIZE; - /* round up brutto amount to a multiple of the page size */ - amount = (amount + pagesize-1) & ~(pagesize-1); -#ifdef MMAP_DEV_ZERO - ptr = (unsigned long *)mmap((caddr_t)0, - (size_t)amount, - PROT_READ | PROT_WRITE, - MAP_PRIVATE, - devzerofd, - (off_t)0); -#else - ptr = (unsigned long *)mmap((caddr_t)0, - (size_t)amount, - PROT_READ | PROT_WRITE, - MAP_ANON | MAP_PRIVATE, - -1, - (off_t)0); -#endif - if (-1!=(long)ptr) { - ptr[0] = amount - SIZE_HEADER - TAIL_SIZE; -#ifdef XALLOC_DEBUG - ptr[1] = MAGIC; -#endif /* XALLOC_DEBUG */ -#ifdef SIZE_TAIL - ((unsigned long *)((char *)ptr + amount - TAIL_SIZE))[0] = MAGIC2; -#endif /* SIZE_TAIL */ - ptr = (unsigned long *)((char *)ptr + SIZE_HEADER); - LOG_ALLOC("Xalloc-L", amount, ptr); - return (void *)ptr; - } /* else fall through to 'Out of memory' */ -#endif /* HAS_MMAP_ANON || MMAP_DEV_ZERO */ - } else { - /* - * medium sized block - */ - /* 'normal' malloc() */ - ptr=(unsigned long *)calloc(1,amount+SIZE_HEADER+TAIL_SIZE); - if (ptr != (unsigned long *)NULL) { - ptr[0] = amount; -#ifdef XALLOC_DEBUG - ptr[1] = MAGIC; -#endif /* XALLOC_DEBUG */ -#ifdef SIZE_TAIL - *(unsigned long *)((char *)ptr + amount + SIZE_HEADER) = MAGIC2; -#endif /* SIZE_TAIL */ - ptr = (unsigned long *)((char *)ptr + SIZE_HEADER); - LOG_ALLOC("Xalloc-M", amount, ptr); - return (void *)ptr; - } - } - if (Must_have_memory) - FatalError("Out of memory"); - LOG_ALLOC("Xalloc-oom", amount, 0); - return NULL; -} - -/***************** - * XNFalloc - * "no failure" realloc, alternate interface to Xalloc w/o Must_have_memory - *****************/ - -void * -XNFalloc (unsigned long amount) -{ - register void * ptr; - - /* zero size requested */ - if (amount == 0) { - LOG_ALLOC("XNFalloc=0", amount, 0); - return NULL; - } - /* negative size (or size > 2GB) - what do we do? */ - if ((long)amount < 0) { - /* Diagnostic */ -#ifdef FATALERRORS - FatalError("Xalloc: XNFalloc(<0)\n"); -#else - ErrorF("Xalloc warning: XNFalloc(<0) ignored..\n"); -#endif - LOG_ALLOC("XNFalloc<0", amount, 0); - return (unsigned long *)NULL; - } - ptr = Xalloc(amount); - if (!ptr) - { - FatalError("Out of memory"); - } - return ptr; -} - -/***************** - * Xcalloc - *****************/ - -void * -Xcalloc (unsigned long amount) -{ - void * ret; - - ret = Xalloc (amount); - if (ret != 0 -#if defined(HAS_MMAP_ANON) || defined(MMAP_DEV_ZERO) - && (amount < MIN_LARGE) /* mmaped anonymous mem is already cleared */ -#endif - ) - bzero ((char *) ret, (int) amount); - return ret; -} - -/***************** - * XNFcalloc - *****************/ -void * -XNFcalloc (unsigned long amount) -{ - void * ret; - - ret = XNFalloc (amount); - if (ret != 0 -#if defined(HAS_MMAP_ANON) || defined(MMAP_DEV_ZERO) - && (amount < MIN_LARGE) /* mmaped anonymous mem is already cleared */ -#endif - ) - bzero ((char *) ret, (int) amount); - return ret; -} - -/***************** - * Xrealloc - *****************/ - -void * -Xrealloc (void * ptr, unsigned long amount) -{ - register unsigned long *new_ptr; - - /* zero size requested */ - if (amount == 0) { - if (ptr) - Xfree(ptr); - LOG_REALLOC("Xrealloc=0", ptr, amount, 0); - return NULL; - } - /* negative size (or size > 2GB) - what do we do? */ - if ((long)amount < 0) { - /* Diagnostic */ -#ifdef FATALERRORS - FatalError("Xalloc: Xrealloc(<0)\n"); -#else - ErrorF("Xalloc warning: Xrealloc(<0) ignored..\n"); -#endif - if (ptr) - Xfree(ptr); /* ?? */ - LOG_REALLOC("Xrealloc<0", ptr, amount, 0); - return NULL; - } - - new_ptr = Xalloc(amount); - if ( (new_ptr) && (ptr) ) { - unsigned long old_size; - old_size = ((unsigned long *)ptr)[-2]; -#ifdef XALLOC_DEBUG - if (MAGIC != ((unsigned long *)ptr)[-1]) { - if (MAGIC_FREE == ((unsigned long *)ptr)[-1]) { -#ifdef FATALERRORS - XfreeTrap(); - FatalError("Xalloc error: range already freed in Xrealloc() :-(\n"); -#else - ErrorF("Xalloc error: range already freed in Xrealloc() :-(\a\n"); - sleep(5); - XfreeTrap(); -#endif - LOG_REALLOC("Xalloc error: ranged already freed in Xrealloc() :-(", - ptr, amount, 0); - return NULL; - } -#ifdef FATALERRORS - XfreeTrap(); - FatalError("Xalloc error: header corrupt in Xrealloc() :-(\n"); -#else - ErrorF("Xalloc error: header corrupt in Xrealloc() :-(\n"); - XfreeTrap(); -#endif - LOG_REALLOC("Xalloc error: header corrupt in Xrealloc() :-(", - ptr, amount, 0); - return NULL; - } -#endif /* XALLOC_DEBUG */ - /* copy min(old size, new size) */ - memcpy((char *)new_ptr, (char *)ptr, (amount < old_size ? amount : old_size)); - } - if (ptr) - Xfree(ptr); - if (new_ptr) { - LOG_REALLOC("Xrealloc", ptr, amount, new_ptr); - return (void *)new_ptr; - } - if (Must_have_memory) - FatalError("Out of memory"); - LOG_REALLOC("Xrealloc", ptr, amount, 0); - return NULL; -} - -/***************** - * XNFrealloc - * "no failure" realloc, alternate interface to Xrealloc w/o Must_have_memory - *****************/ - -void * -XNFrealloc (void * ptr, unsigned long amount) -{ - if (( ptr = (void *)Xrealloc( ptr, amount ) ) == NULL) - { - FatalError( "Out of memory" ); - } - return ptr; -} - -/***************** - * Xfree - * calls free - *****************/ - -void -Xfree(void * ptr) -{ - unsigned long size; - unsigned long *pheader; - - /* free(NULL) IS valid :-( - and widely used throughout the server.. */ - if (!ptr) - return; - - pheader = (unsigned long *)((char *)ptr - SIZE_HEADER); -#ifdef XALLOC_DEBUG - if (MAGIC != pheader[1]) { - /* Diagnostic */ - if (MAGIC_FREE == pheader[1]) { -#ifdef FATALERRORS - XfreeTrap(); - FatalError("Xalloc error: range already freed in Xrealloc() :-(\n"); -#else - ErrorF("Xalloc error: range already freed in Xrealloc() :-(\a\n"); - sleep(5); - XfreeTrap(); -#endif - LOG_FREE("Xalloc error: ranged already freed in Xrealloc() :-(", ptr); - return; - } -#ifdef FATALERRORS - XfreeTrap(); - FatalError("Xalloc error: Header corrupt in Xfree() :-(\n"); -#else - ErrorF("Xalloc error: Header corrupt in Xfree() :-(\n"); - XfreeTrap(); -#endif - LOG_FREE("Xalloc error: Header corrupt in Xfree() :-(", ptr); - return; - } -#endif /* XALLOC_DEBUG */ - - size = pheader[0]; - if (size <= MAX_SMALL) { - int indx; - /* - * small block - */ -#ifdef SIZE_TAIL - if (MAGIC2 != *(unsigned long *)((char *)ptr + size)) { - /* Diagnostic */ -#ifdef FATALERRORS - XfreeTrap(); - FatalError("Xalloc error: Tail corrupt in Xfree() for small block (adr=0x%x, val=0x%x)\n",(char *)ptr + size,*(unsigned long *)((char *)ptr + size)); -#else - ErrorF("Xalloc error: Tail corrupt in Xfree() for small block (adr=0x%x, val=0x%x)\n",(char *)ptr + size,*(unsigned long *)((char *)ptr + size)); - XfreeTrap(); -#endif - LOG_FREE("Xalloc error: Tail corrupt in Xfree() for small block", ptr); - return; - } -#endif /* SIZE_TAIL */ - -#ifdef XFREE_ERASES - memset(ptr,0xF0,size); -#endif /* XFREE_ERASES */ -#ifdef XALLOC_DEBUG - pheader[1] = MAGIC_FREE; -#endif - /* put this small block at the head of the list */ - indx = (size-1) / SIZE_STEPS; - *(unsigned long **)(ptr) = free_lists[indx]; - free_lists[indx] = (unsigned long *)ptr; - LOG_FREE("Xfree", ptr); - return; - -#if defined(HAS_MMAP_ANON) || defined(MMAP_DEV_ZERO) - } else if (size >= MIN_LARGE) { - /* - * large block - */ -#ifdef SIZE_TAIL - if (MAGIC2 != ((unsigned long *)((char *)ptr + size))[0]) { - /* Diagnostic */ -#ifdef FATALERRORS - XfreeTrap(); - FatalError("Xalloc error: Tail corrupt in Xfree() for big block (adr=0x%x, val=0x%x)\n",(char *)ptr+size,((unsigned long *)((char *)ptr + size))[0]); -#else - ErrorF("Xalloc error: Tail corrupt in Xfree() for big block (adr=0x%x, val=0x%x)\n",(char *)ptr+size,((unsigned long *)((char *)ptr + size))[0]); - XfreeTrap(); -#endif - LOG_FREE("Xalloc error: Tail corrupt in Xfree() for big block", ptr); - return; - } - size += SIZE_TAIL; -#endif /* SIZE_TAIL */ - - LOG_FREE("Xfree", ptr); - size += SIZE_HEADER; - munmap((caddr_t)pheader, (size_t)size); - /* no need to clear - mem is inaccessible after munmap.. */ -#endif /* HAS_MMAP_ANON */ - - } else { - /* - * medium sized block - */ -#ifdef SIZE_TAIL - if (MAGIC2 != *(unsigned long *)((char *)ptr + size)) { - /* Diagnostic */ -#ifdef FATALERRORS - XfreeTrap(); - FatalError("Xalloc error: Tail corrupt in Xfree() for medium block (adr=0x%x, val=0x%x)\n",(char *)ptr + size,*(unsigned long *)((char *)ptr + size)); -#else - ErrorF("Xalloc error: Tail corrupt in Xfree() for medium block (adr=0x%x, val=0x%x)\n",(char *)ptr + size,*(unsigned long *)((char *)ptr + size)); - XfreeTrap(); -#endif - LOG_FREE("Xalloc error: Tail corrupt in Xfree() for medium block", ptr); - return; - } -#endif /* SIZE_TAIL */ - -#ifdef XFREE_ERASES - memset(pheader,0xF0,size+SIZE_HEADER); -#endif /* XFREE_ERASES */ -#ifdef XALLOC_DEBUG - pheader[1] = MAGIC_FREE; -#endif - - LOG_FREE("Xfree", ptr); - free((char *)pheader); - } -} - -void -OsInitAllocator (void) -{ - static Bool beenhere = FALSE; - - if (beenhere) - return; - beenhere = TRUE; - -#if defined(HAS_MMAP_ANON) || defined (MMAP_DEV_ZERO) - pagesize = -1; -#if defined(_SC_PAGESIZE) || defined(HAS_SC_PAGESIZE) - pagesize = sysconf(_SC_PAGESIZE); -#endif -#ifdef _SC_PAGE_SIZE - if (pagesize == -1) - pagesize = sysconf(_SC_PAGE_SIZE); -#endif -#ifdef HAS_GETPAGESIZE - if (pagesize == -1) - pagesize = getpagesize(); -#endif -#ifdef PAGE_SIZE - if (pagesize == -1) - pagesize = PAGE_SIZE; -#endif - if (pagesize == -1) - FatalError("OsInitAllocator: Cannot determine page size\n"); -#endif - - /* set up linked lists of free blocks */ - bzero ((char *) free_lists, MAX_SMALL/SIZE_STEPS*sizeof(unsigned long *)); - -#ifdef MMAP_DEV_ZERO - /* open /dev/zero on systems that have mmap, but not MAP_ANON */ - if (devzerofd < 0) { - if ((devzerofd = open("/dev/zero", O_RDWR, 0)) < 0) - FatalError("OsInitAllocator: Cannot open /dev/zero (errno=%d)\n", - errno); - } -#endif - -#ifdef XALLOC_LOG - /* reset the log file to zero length */ - { - FILE *f; - f = fopen(XALLOC_LOG_FILE, "w"); - if (NULL!=f) - fclose(f); - } -#endif -} - -#else /* !INTERNAL_MALLOC */ -/* This is to avoid an empty .o */ -static int no_internal_xalloc; -#endif /* INTERNAL_MALLOC */ diff --git a/nx-X11/programs/Xserver/os/xdmauth.c b/nx-X11/programs/Xserver/os/xdmauth.c index b55f75a36..a89c5b0c0 100644 --- a/nx-X11/programs/Xserver/os/xdmauth.c +++ b/nx-X11/programs/Xserver/os/xdmauth.c @@ -260,7 +260,7 @@ XdmAuthorizationValidate (unsigned char *plain, int length, *reason = "Bad XDM authorization key length"; return NULL; } - client = (XdmClientAuthPtr) xalloc (sizeof (XdmClientAuthRec)); + client = (XdmClientAuthPtr) malloc (sizeof (XdmClientAuthRec)); if (!client) return NULL; XdmClientAuthDecode (plain, client); @@ -364,7 +364,7 @@ XdmAddCookie (unsigned short data_length, char *data, XID id) /* the first octet of the key must be zero */ if (key_bits[0] != '\0') return 0; - new = (XdmAuthorizationPtr) xalloc (sizeof (XdmAuthorizationRec)); + new = (XdmAuthorizationPtr) malloc (sizeof (XdmAuthorizationRec)); if (!new) return 0; new->next = xdmAuth; @@ -386,7 +386,7 @@ XdmCheckCookie (unsigned short cookie_length, char *cookie, /* Auth packets must be a multiple of 8 bytes long */ if (cookie_length & 7) return (XID) -1; - plain = (unsigned char *) xalloc (cookie_length); + plain = (unsigned char *) malloc (cookie_length); if (!plain) return (XID) -1; for (auth = xdmAuth; auth; auth=auth->next) { @@ -431,7 +431,7 @@ XdmToID (unsigned short cookie_length, char *cookie) XdmClientAuthPtr client; unsigned char *plain; - plain = (unsigned char *) xalloc (cookie_length); + plain = (unsigned char *) malloc (cookie_length); if (!plain) return (XID) -1; for (auth = xdmAuth; auth; auth=auth->next) { diff --git a/nx-X11/programs/Xserver/os/xdmcp.c b/nx-X11/programs/Xserver/os/xdmcp.c index 29785f48e..d48012759 100644 --- a/nx-X11/programs/Xserver/os/xdmcp.c +++ b/nx-X11/programs/Xserver/os/xdmcp.c @@ -407,7 +407,7 @@ XdmcpRegisterAuthentication ( AuthenticationNames.length + 1) && XdmcpReallocARRAYofARRAY8 (&AuthenticationDatas, AuthenticationDatas.length + 1) && - (newFuncs = (AuthenticationFuncsPtr) xalloc ( + (newFuncs = (AuthenticationFuncsPtr) malloc ( (AuthenticationNames.length + 1) * sizeof (AuthenticationFuncsRec))))) { XdmcpDisposeARRAY8 (&AuthenticationName); @@ -507,7 +507,7 @@ XdmcpRegisterConnection ( return; } } - newAddress = (CARD8 *) xalloc (addrlen * sizeof (CARD8)); + newAddress = (CARD8 *) malloc (addrlen * sizeof (CARD8)); if (!newAddress) return; if (!XdmcpReallocARRAY16 (&ConnectionTypes, ConnectionTypes.length + 1)) @@ -548,7 +548,7 @@ XdmcpRegisterAuthorization (char *name, int namelen) ARRAY8 authName; int i; - authName.data = (CARD8 *) xalloc (namelen * sizeof (CARD8)); + authName.data = (CARD8 *) malloc (namelen * sizeof (CARD8)); if (!authName.data) return; if (!XdmcpReallocARRAYofARRAY8 (&AuthorizationNames, AuthorizationNames.length +1)) diff --git a/nx-X11/programs/Xserver/os/xprintf.c b/nx-X11/programs/Xserver/os/xprintf.c index 4423208ff..1bcb36d3c 100644 --- a/nx-X11/programs/Xserver/os/xprintf.c +++ b/nx-X11/programs/Xserver/os/xprintf.c @@ -1,5 +1,5 @@ /* - * printf routines which xalloc their buffer + * printf routines which malloc their buffer */ /* * Copyright (c) 2004 Alexander Gottwald @@ -111,7 +111,7 @@ Xvprintf(const char *format, va_list va) size = vsnprintf(NULL, 0, format, va2); va_end(va2); - ret = (char *)Xalloc(size + 1); + ret = (char *)malloc(size + 1); if (ret == NULL) return NULL; -- cgit v1.2.3