${PROJECT_DIRECTORY}/src/xbt/backtrace_windows.c
${PROJECT_DIRECTORY}/src/xbt/backtrace_dummy.c
${PROJECT_DIRECTORY}/src/xbt/setset_private.h
- ${PROJECT_DIRECTORY}/src/xbt/mmalloc/ansidecl.h
${PROJECT_DIRECTORY}/src/xbt/mmalloc/keys.c
${PROJECT_DIRECTORY}/src/xbt/mmalloc/mmalloc.c
${PROJECT_DIRECTORY}/src/xbt/mmalloc/mmalloc.h
#### mmalloc cruft -- to be integrated into cmake
EXTRA_DIST+= \
- xbt/mmalloc/ansidecl.h xbt/mmalloc/keys.c xbt/mmalloc/mmalloc.c \
+ xbt/mmalloc/keys.c xbt/mmalloc/mmalloc.c \
xbt/mmalloc/mm.c xbt/mmalloc/mmprivate.h xbt/mmalloc/mrealloc.c \
xbt/mmalloc/attach.c xbt/mmalloc/mcalloc.c xbt/mmalloc/mmalloc.h \
xbt/mmalloc/mmcheck.c xbt/mmalloc/mmstats.c xbt/mmalloc/mvalloc.c \
/* Forward declarations/prototypes for local functions */
-static struct mdesc *reuse PARAMS ((int));
+static struct mdesc *reuse (int fd);
/* Initialize access to a mmalloc managed region.
On failure returns NULL. */
-PTR
-mmalloc_attach (fd, baseaddr)
- int fd;
- PTR baseaddr;
+void *
+mmalloc_attach (int fd, void *baseaddr)
{
struct mdesc mtemp;
struct mdesc *mdp;
- PTR mbase;
+ void* mbase;
struct stat sbuf;
/* First check to see if FD is a valid file descriptor, and if so, see
return (NULL);
else if (sbuf.st_size > 0)
- return ((PTR) reuse (fd));
+ return ((void*) reuse (fd));
}
/* If the user provided NULL BASEADDR then fail */
// mdp = NULL;
}
- return ((PTR) mbase);
+ return ((void*) mbase);
}
/* Given an valid file descriptor on an open file, test to see if that file
unsuccessful for some reason. */
static struct mdesc *
-reuse (fd)
- int fd;
+reuse (int fd)
{
struct mdesc mtemp;
struct mdesc *mdp = NULL;
mdp -> morecore = __mmalloc_mmap_morecore;
if (mdp -> mfree_hook != NULL)
{
- mmcheckf ((PTR) mdp, (void (*) PARAMS ((void))) NULL, 1);
+ mmcheckf ((void*) mdp, (void (*) (void)) NULL, 1);
}
}
return (mdp);
always fails. */
/* ARGSUSED */
-PTR
-mmalloc_attach (fd, baseaddr)
- int fd;
- PTR baseaddr;
+void*
+mmalloc_attach (int fd, void* baseaddr)
{
return (NULL);
}
region we are about to unmap, so we first make a local copy of it on the
stack and use the copy. */
-PTR
-mmalloc_detach (md)
- PTR md;
+void*
+mmalloc_detach (void *md)
{
struct mdesc mtemp;
+++ /dev/null
-/* ANSI and traditional C compatability macros
- Copyright 1991, 1992, 1993, 1994, 1995, 1996, 1998, 1999, 2000, 2001
- Free Software Foundation, Inc.
- This file is part of the GNU C Library.
-
-This program is free software; you can redistribute it and/or modify
-it under the terms of the GNU General Public License as published by
-the Free Software Foundation; either version 2 of the License, or
-(at your option) any later version.
-
-This program is distributed in the hope that it will be useful,
-but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-GNU General Public License for more details.
-
-You should have received a copy of the GNU General Public License
-along with this program; if not, write to the Free Software
-Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
-
-/* ANSI and traditional C compatibility macros
-
- ANSI C is assumed if __STDC__ is #defined.
-
- Macro ANSI C definition Traditional C definition
- ----- ---- - ---------- ----------- - ----------
- ANSI_PROTOTYPES 1 not defined
- PTR `void *' `char *'
- PTRCONST `void *const' `char *'
- LONG_DOUBLE `long double' `double'
- const not defined `'
- volatile not defined `'
- signed not defined `'
- VA_START(ap, var) va_start(ap, var) va_start(ap)
-
- Note that it is safe to write "void foo();" indicating a function
- with no return value, in all K+R compilers we have been able to test.
-
- For declaring functions with prototypes, we also provide these:
-
- PARAMS ((prototype))
- -- for functions which take a fixed number of arguments. Use this
- when declaring the function. When defining the function, write a
- K+R style argument list. For example:
-
- char *strcpy PARAMS ((char *dest, char *source));
- ...
- char *
- strcpy (dest, source)
- char *dest;
- char *source;
- { ... }
-
-
- VPARAMS ((prototype, ...))
- -- for functions which take a variable number of arguments. Use
- PARAMS to declare the function, VPARAMS to define it. For example:
-
- int printf PARAMS ((const char *format, ...));
- ...
- int
- printf VPARAMS ((const char *format, ...))
- {
- ...
- }
-
- For writing functions which take variable numbers of arguments, we
- also provide the VA_OPEN, VA_CLOSE, and VA_FIXEDARG macros. These
- hide the differences between K+R <varargs.h> and C89 <stdarg.h> more
- thoroughly than the simple VA_START() macro mentioned above.
-
- VA_OPEN and VA_CLOSE are used *instead of* va_start and va_end.
- Immediately after VA_OPEN, put a sequence of VA_FIXEDARG calls
- corresponding to the list of fixed arguments. Then use va_arg
- normally to get the variable arguments, or pass your va_list object
- around. You do not declare the va_list yourself; VA_OPEN does it
- for you.
-
- Here is a complete example:
-
- int
- printf VPARAMS ((const char *format, ...))
- {
- int result;
-
- VA_OPEN (ap, format);
- VA_FIXEDARG (ap, const char *, format);
-
- result = vfprintf (stdout, format, ap);
- VA_CLOSE (ap);
-
- return result;
- }
-
-
- You can declare variables either before or after the VA_OPEN,
- VA_FIXEDARG sequence. Also, VA_OPEN and VA_CLOSE are the beginning
- and end of a block. They must appear at the same nesting level,
- and any variables declared after VA_OPEN go out of scope at
- VA_CLOSE. Unfortunately, with a K+R compiler, that includes the
- argument list. You can have multiple instances of VA_OPEN/VA_CLOSE
- pairs in a single function in case you need to traverse the
- argument list more than once.
-
- For ease of writing code which uses GCC extensions but needs to be
- portable to other compilers, we provide the GCC_VERSION macro that
- simplifies testing __GNUC__ and __GNUC_MINOR__ together, and various
- wrappers around __attribute__. Also, __extension__ will be #defined
- to nothing if it doesn't work. See below.
-
- This header also defines a lot of obsolete macros:
- CONST, VOLATILE, SIGNED, PROTO, EXFUN, DEFUN, DEFUN_VOID,
- AND, DOTS, NOARGS. Don't use them. */
-
-#ifndef _ANSIDECL_H
-#define _ANSIDECL_H 1
-
-/* Every source file includes this file,
- so they will all get the switch for lint. */
-/* LINTLIBRARY */
-
-/* Using MACRO(x,y) in cpp #if conditionals does not work with some
- older preprocessors. Thus we can't define something like this:
-
-#define HAVE_GCC_VERSION(MAJOR, MINOR) \
- (__GNUC__ > (MAJOR) || (__GNUC__ == (MAJOR) && __GNUC_MINOR__ >= (MINOR)))
-
-and then test "#if HAVE_GCC_VERSION(2,7)".
-
-So instead we use the macro below and test it against specific values. */
-
-/* This macro simplifies testing whether we are using gcc, and if it
- is of a particular minimum version. (Both major & minor numbers are
- significant.) This macro will evaluate to 0 if we are not using
- gcc at all. */
-#ifndef GCC_VERSION
-#define GCC_VERSION (__GNUC__ * 1000 + __GNUC_MINOR__)
-#endif /* GCC_VERSION */
-
-#if defined (__STDC__) || defined (_AIX) || (defined (__mips) && defined (_SYSTYPE_SVR4)) || defined(_WIN32) || (defined(__alpha) && defined(__cplusplus))
-/* All known AIX compilers implement these things (but don't always
- define __STDC__). The RISC/OS MIPS compiler defines these things
- in SVR4 mode, but does not define __STDC__. */
-/* eraxxon@alumni.rice.edu: The Compaq C++ compiler, unlike many other
- C++ compilers, does not define __STDC__, though it acts as if this
- was so. (Verified versions: 5.7, 6.2, 6.3, 6.5) */
-
-#define ANSI_PROTOTYPES 1
-#define PTR void *
-#define PTRCONST void *const
-#define LONG_DOUBLE long double
-
-#define PARAMS(ARGS) ARGS
-#define VPARAMS(ARGS) ARGS
-#define VA_START(VA_LIST, VAR) va_start(VA_LIST, VAR)
-
-/* variadic function helper macros */
-/* "struct Qdmy" swallows the semicolon after VA_OPEN/VA_FIXEDARG's
- use without inhibiting further decls and without declaring an
- actual variable. */
-#define VA_OPEN(AP, VAR) { va_list AP; va_start(AP, VAR); { struct Qdmy
-#define VA_CLOSE(AP) } va_end(AP); }
-#define VA_FIXEDARG(AP, T, N) struct Qdmy
-
-#undef const
-#undef volatile
-#undef signed
-
-/* inline requires special treatment; it's in C99, and GCC >=2.7 supports
- it too, but it's not in C89. */
-#undef inline
-#if __STDC_VERSION__ > 199901L
-/* it's a keyword */
-#else
-# if GCC_VERSION >= 2007
-# define inline __inline__ /* __inline__ prevents -pedantic warnings */
-# else
-# define inline /* nothing */
-# endif
-#endif
-
-/* These are obsolete. Do not use. */
-#ifndef IN_GCC
-#define CONST const
-#define VOLATILE volatile
-#define SIGNED signed
-
-#define PROTO(type, name, arglist) type name arglist
-#define EXFUN(name, proto) name proto
-#define DEFUN(name, arglist, args) name(args)
-#define DEFUN_VOID(name) name(void)
-#define AND ,
-#define DOTS , ...
-#define NOARGS void
-#endif /* ! IN_GCC */
-
-#else /* Not ANSI C. */
-
-#undef ANSI_PROTOTYPES
-#define PTR char *
-#define PTRCONST PTR
-#define LONG_DOUBLE double
-
-#define PARAMS(args) ()
-#define VPARAMS(args) (va_alist) va_dcl
-#define VA_START(va_list, var) va_start(va_list)
-
-#define VA_OPEN(AP, VAR) { va_list AP; va_start(AP); { struct Qdmy
-#define VA_CLOSE(AP) } va_end(AP); }
-#define VA_FIXEDARG(AP, TYPE, NAME) TYPE NAME = va_arg(AP, TYPE)
-
-/* some systems define these in header files for non-ansi mode */
-#undef const
-#undef volatile
-#undef signed
-#undef inline
-#define const
-#define volatile
-#define signed
-#define inline
-
-#ifndef IN_GCC
-#define CONST
-#define VOLATILE
-#define SIGNED
-
-#define PROTO(type, name, arglist) type name ()
-#define EXFUN(name, proto) name()
-#define DEFUN(name, arglist, args) name arglist args;
-#define DEFUN_VOID(name) name()
-#define AND ;
-#define DOTS
-#define NOARGS
-#endif /* ! IN_GCC */
-
-#endif /* ANSI C. */
-
-/* Define macros for some gcc attributes. This permits us to use the
- macros freely, and know that they will come into play for the
- version of gcc in which they are supported. */
-
-#if (GCC_VERSION < 2007)
-# define __attribute__(x)
-#endif
-
-/* Attribute __malloc__ on functions was valid as of gcc 2.96. */
-#ifndef ATTRIBUTE_MALLOC
-# if (GCC_VERSION >= 2096)
-# define ATTRIBUTE_MALLOC __attribute__ ((__malloc__))
-# else
-# define ATTRIBUTE_MALLOC
-# endif /* GNUC >= 2.96 */
-#endif /* ATTRIBUTE_MALLOC */
-
-/* Attributes on labels were valid as of gcc 2.93. */
-#ifndef ATTRIBUTE_UNUSED_LABEL
-# if (GCC_VERSION >= 2093)
-# define ATTRIBUTE_UNUSED_LABEL ATTRIBUTE_UNUSED
-# else
-# define ATTRIBUTE_UNUSED_LABEL
-# endif /* GNUC >= 2.93 */
-#endif /* ATTRIBUTE_UNUSED_LABEL */
-
-#ifndef ATTRIBUTE_UNUSED
-#define ATTRIBUTE_UNUSED __attribute__ ((__unused__))
-#endif /* ATTRIBUTE_UNUSED */
-
-#ifndef ATTRIBUTE_NORETURN
-#define ATTRIBUTE_NORETURN __attribute__ ((__noreturn__))
-#endif /* ATTRIBUTE_NORETURN */
-
-/* Attribute `nonnull' was valid as of gcc 3.3. */
-#ifndef ATTRIBUTE_NONNULL
-# if (GCC_VERSION >= 3003)
-# define ATTRIBUTE_NONNULL(m) __attribute__ ((__nonnull__ (m)))
-# else
-# define ATTRIBUTE_NONNULL(m)
-# endif /* GNUC >= 3.3 */
-#endif /* ATTRIBUTE_NONNULL */
-
-/* Use ATTRIBUTE_PRINTF when the format specifier must not be NULL.
- This was the case for the `printf' format attribute by itself
- before GCC 3.3, but as of 3.3 we need to add the `nonnull'
- attribute to retain this behavior. */
-#ifndef ATTRIBUTE_PRINTF
-#define ATTRIBUTE_PRINTF(m, n) __attribute__ ((__format__ (__printf__, m, n))) ATTRIBUTE_NONNULL(m)
-#define ATTRIBUTE_PRINTF_1 ATTRIBUTE_PRINTF(1, 2)
-#define ATTRIBUTE_PRINTF_2 ATTRIBUTE_PRINTF(2, 3)
-#define ATTRIBUTE_PRINTF_3 ATTRIBUTE_PRINTF(3, 4)
-#define ATTRIBUTE_PRINTF_4 ATTRIBUTE_PRINTF(4, 5)
-#define ATTRIBUTE_PRINTF_5 ATTRIBUTE_PRINTF(5, 6)
-#endif /* ATTRIBUTE_PRINTF */
-
-/* Use ATTRIBUTE_NULL_PRINTF when the format specifier may be NULL. A
- NULL format specifier was allowed as of gcc 3.3. */
-#ifndef ATTRIBUTE_NULL_PRINTF
-# if (GCC_VERSION >= 3003)
-# define ATTRIBUTE_NULL_PRINTF(m, n) __attribute__ ((__format__ (__printf__, m, n)))
-# else
-# define ATTRIBUTE_NULL_PRINTF(m, n)
-# endif /* GNUC >= 3.3 */
-# define ATTRIBUTE_NULL_PRINTF_1 ATTRIBUTE_NULL_PRINTF(1, 2)
-# define ATTRIBUTE_NULL_PRINTF_2 ATTRIBUTE_NULL_PRINTF(2, 3)
-# define ATTRIBUTE_NULL_PRINTF_3 ATTRIBUTE_NULL_PRINTF(3, 4)
-# define ATTRIBUTE_NULL_PRINTF_4 ATTRIBUTE_NULL_PRINTF(4, 5)
-# define ATTRIBUTE_NULL_PRINTF_5 ATTRIBUTE_NULL_PRINTF(5, 6)
-#endif /* ATTRIBUTE_NULL_PRINTF */
-
-/* We use __extension__ in some places to suppress -pedantic warnings
- about GCC extensions. This feature didn't work properly before
- gcc 2.8. */
-#if GCC_VERSION < 2008
-#define __extension__
-#endif
-
-#endif /* ansidecl.h */
#include "mmprivate.h"
int
-mmalloc_setkey (md, keynum, key)
- PTR md;
- int keynum;
- PTR key;
+mmalloc_setkey (void *md, int keynum, void *key)
{
struct mdesc *mdp = (struct mdesc *) md;
int result = 0;
return (result);
}
-PTR
-mmalloc_getkey (md, keynum)
- PTR md;
- int keynum;
+void*
+mmalloc_getkey (void *md, int keynum)
{
struct mdesc *mdp = (struct mdesc *) md;
- PTR keyval = NULL;
+ void* keyval = NULL;
if ((mdp != NULL) && (keynum >= 0) && (keynum < MMALLOC_KEYS))
{
/* Allocate an array of NMEMB elements each SIZE bytes long.
The entire array is initialized to zeros. */
-PTR
-mcalloc (md, nmemb, size)
- PTR md;
- register size_t nmemb;
- register size_t size;
+void *
+mcalloc (void *md, register size_t nmemb, register size_t size)
{
- register PTR result;
+ register void* result;
if ((result = mmalloc (md, nmemb * size)) != NULL)
{
the application contains any "hidden" calls to malloc/realloc/free (such
as inside a system library). */
-PTR
-calloc (nmemb, size)
- size_t nmemb;
- size_t size;
+void*
+calloc (size_t nmemb, size_t size)
{
- return (mcalloc ((PTR) NULL, nmemb, size));
+ return (mcalloc ((void*) NULL, nmemb, size));
}
Like `mfree' but don't call a mfree_hook if there is one. */
void
-__mmalloc_free (mdp, ptr)
- struct mdesc *mdp;
- PTR ptr;
+__mmalloc_free (struct mdesc *mdp, void *ptr)
{
int type;
size_t block;//, blocks; unused variable?
mdp -> heapstats.chunks_free -= BLOCKSIZE >> type;
mdp -> heapstats.bytes_free -= BLOCKSIZE;
- mfree ((PTR) mdp, (PTR) ADDRESS(block));
+ mfree ((void*) mdp, (void*) ADDRESS(block));
}
else if (mdp -> heapinfo[block].busy.info.frag.nfree != 0)
{
/* Return memory to the heap. */
void
-mfree (md, ptr)
- PTR md;
- PTR ptr;
+mfree (void *md, void *ptr)
{
struct mdesc *mdp;
register struct alignlist *l;
as inside a system library). */
void
-free (PTR ptr)
+free (void* ptr)
{
- mfree ((PTR) NULL, ptr);
+ mfree ((void*) NULL, ptr);
}
/* Prototypes for local functions */
-static int initialize PARAMS ((struct mdesc *));
-static PTR morecore PARAMS ((struct mdesc *, size_t));
-static PTR align PARAMS ((struct mdesc *, size_t));
+static int initialize (struct mdesc *mdp);
+static void* morecore (struct mdesc *mdp, size_t size);
+static void* align (struct mdesc *mdp, size_t size);
/* Aligned allocation. */
-static PTR
-align (mdp, size)
- struct mdesc *mdp;
- size_t size;
+static void*
+align (struct mdesc *mdp, size_t size)
{
- PTR result;
+ void* result;
unsigned long int adj;
result = mdp -> morecore (mdp, size);
/* Set everything up and remember that we have. */
static int
-initialize (mdp)
- struct mdesc *mdp;
+initialize (struct mdesc *mdp)
{
mdp -> heapsize = HEAP / BLOCKSIZE;
mdp -> heapinfo = (malloc_info *)
{
return (0);
}
- memset ((PTR)mdp -> heapinfo, 0, mdp -> heapsize * sizeof (malloc_info));
+ memset ((void*)mdp -> heapinfo, 0, mdp -> heapsize * sizeof (malloc_info));
mdp -> heapinfo[0].free.size = 0;
mdp -> heapinfo[0].free.next = mdp -> heapinfo[0].free.prev = 0;
mdp -> heapindex = 0;
- mdp -> heapbase = (PTR) mdp -> heapinfo;
+ mdp -> heapbase = (void*) mdp -> heapinfo;
mdp -> flags |= MMALLOC_INITIALIZED;
return (1);
}
/* Get neatly aligned memory, initializing or
growing the heap info table as necessary. */
-static PTR
-morecore (mdp, size)
- struct mdesc *mdp;
- size_t size;
+static void*
+morecore (struct mdesc *mdp, size_t size)
{
- PTR result;
+ void* result;
malloc_info *newinfo, *oldinfo;
size_t newsize;
mdp -> morecore (mdp, -size);
return (NULL);
}
- memset ((PTR) newinfo, 0, newsize * sizeof (malloc_info));
- memcpy ((PTR) newinfo, (PTR) mdp -> heapinfo,
+ memset ((void*) newinfo, 0, newsize * sizeof (malloc_info));
+ memcpy ((void*) newinfo, (void*) mdp -> heapinfo,
mdp -> heapsize * sizeof (malloc_info));
oldinfo = mdp -> heapinfo;
newinfo[BLOCK (oldinfo)].busy.type = 0;
newinfo[BLOCK (oldinfo)].busy.info.size
= BLOCKIFY (mdp -> heapsize * sizeof (malloc_info));
mdp -> heapinfo = newinfo;
- __mmalloc_free (mdp, (PTR)oldinfo);
+ __mmalloc_free (mdp, (void*)oldinfo);
mdp -> heapsize = newsize;
}
/* Allocate memory from the heap. */
-PTR
+void*
mmalloc (md, size)
- PTR md;
+ void* md;
size_t size;
{
struct mdesc *mdp;
- PTR result;
+ void* result;
size_t block, blocks, lastblocks, start;
register size_t i;
struct list *next;
/* There are free fragments of this size.
Pop a fragment out of the fragment list and return it.
Update the block's nfree and first counters. */
- result = (PTR) next;
+ result = (void*) next;
next -> prev -> next = next -> next;
if (next -> next != NULL)
{
the application contains any "hidden" calls to malloc/realloc/free (such
as inside a system library). */
-PTR
-malloc (size)
- size_t size;
+void*
+malloc (size_t size)
{
- PTR result;
- result = mmalloc ((PTR) NULL, size);
+ void* result;
+ result = mmalloc (NULL, size);
return (result);
}
# include <sys/types.h> /* for size_t */
# include <stdio.h> /* for NULL */
#endif
+//#include "./include/ansidecl.h"
-#include "./include/ansidecl.h"
-
/* Allocate SIZE bytes of memory. */
-extern PTR mmalloc PARAMS ((PTR, size_t));
+extern void* mmalloc(void* md, size_t size);
-/* Re-allocate the previously allocated block in PTR, making the new block
+/* Re-allocate the previously allocated block in void*, making the new block
SIZE bytes long. */
-extern PTR mrealloc PARAMS ((PTR, PTR, size_t));
+extern void* mrealloc(void* md, void* ptr, size_t size);
/* Allocate NMEMB elements of SIZE bytes each, all initialized to 0. */
-extern PTR mcalloc PARAMS ((PTR, size_t, size_t));
+extern void* mcalloc (void* md, size_t nmemb, size_t size);
/* Free a block allocated by `mmalloc', `mrealloc' or `mcalloc'. */
-extern void mfree PARAMS ((PTR, PTR));
+extern void mfree (void* md, void* ptr);
/* Allocate SIZE bytes allocated to ALIGNMENT bytes. */
-extern PTR mmemalign PARAMS ((PTR, size_t, size_t));
+extern void* mmemalign (void* md, size_t alignment, size_t size);
/* Allocate SIZE bytes on a page boundary. */
-extern PTR mvalloc PARAMS ((PTR, size_t));
+extern void* mvalloc (void* md, size_t size);
/* Activate a standard collection of debugging hooks. */
-extern int mmcheck PARAMS ((PTR, void (*) (void)));
+extern int mmcheck (void* md, void (*func) (void));
-extern int mmcheckf PARAMS ((PTR, void (*) (void), int));
+extern int mmcheckf (void* md, void (*func) (void), int force);
/* Pick up the current statistics. (see FIXME elsewhere) */
-extern struct mstats mmstats PARAMS ((PTR));
+extern struct mstats mmstats (void* md);
-extern PTR mmalloc_attach PARAMS ((int, PTR));
+extern void* mmalloc_attach (int fd, void* baseaddr);
-extern PTR mmalloc_detach PARAMS ((PTR));
+extern void* mmalloc_detach (void* md);
-extern int mmalloc_setkey PARAMS ((PTR, int, PTR));
+extern int mmalloc_setkey (void* md, int keynum, void* key);
-extern PTR mmalloc_getkey PARAMS ((PTR, int));
+extern void* mmalloc_getkey (void* md, int keynum);
-extern int mmalloc_errno PARAMS ((PTR));
+// FIXME: this function is not implemented anymore?
+//extern int mmalloc_errno (void* md);
-extern int mmtrace PARAMS ((void));
+extern int mmtrace(void);
-extern PTR mmalloc_findbase PARAMS ((int));
+extern void* mmalloc_findbase(int size);
#endif /* MMALLOC_H */
static size_t pagesize;
#if NEED_DECLARATION_GETPAGESIZE
-extern int getpagesize PARAMS ((void));
+extern int getpagesize (void);
#endif
-#define PAGE_ALIGN(addr) (PTR) (((long)(addr) + pagesize - 1) & \
+#define PAGE_ALIGN(addr) (void*) (((long)(addr) + pagesize - 1) & \
~(pagesize - 1))
/* Return MAP_PRIVATE if MDP represents /dev/zero. Otherwise, return
amount to either add to or subtract from the existing region. Works
like sbrk(), but using mmap(). */
-PTR
-__mmalloc_mmap_morecore (mdp, size)
- struct mdesc *mdp;
- int size;
+void*
+__mmalloc_mmap_morecore (struct mdesc *mdp, int size)
{
- PTR result = NULL;
+ void* result = NULL;
off_t foffset; /* File offset at which new mapping will start */
size_t mapbytes; /* Number of bytes to map */
- PTR moveto; /* Address where we wish to move "break value" to */
- PTR mapto; /* Address we actually mapped to */
+ void* moveto; /* Address where we wish to move "break value" to */
+ void* mapto; /* Address we actually mapped to */
char buf = 0; /* Single byte to write to extend mapped file */
if (pagesize == 0)
us to try to deallocate back past the base of the mmap'd region
then do nothing, and return NULL. Otherwise, deallocate the
memory and return the old break value. */
- if (mdp -> breakval + size >= mdp -> base)
+ if (((char*)mdp -> breakval) + size >= (char*)mdp -> base)
{
- result = (PTR) mdp -> breakval;
- mdp -> breakval += size;
+ result = (void*) mdp -> breakval;
+ mdp -> breakval = (char*) mdp->breakval + size;
moveto = PAGE_ALIGN (mdp -> breakval);
- munmap (moveto, (size_t) (mdp -> top - moveto) - 1);
+ munmap (moveto, (size_t) (((char*)mdp -> top) - ((char*)moveto)) - 1);
mdp -> top = moveto;
}
}
{
result = NULL;
}
- else if (mdp -> breakval + size > mdp -> top)
+ else if ((char*)mdp -> breakval + size > (char*)mdp -> top)
{
/* The request would move us past the end of the currently
mapped memory, so map in enough more memory to satisfy
the request. This means we also have to grow the mapped-to
file by an appropriate amount, since mmap cannot be used
to extend a file. */
- moveto = PAGE_ALIGN (mdp -> breakval + size);
- mapbytes = moveto - mdp -> top;
- foffset = mdp -> top - mdp -> base;
+ moveto = PAGE_ALIGN ((char*)mdp -> breakval + size);
+ mapbytes = (char*)moveto - (char*)mdp -> top;
+ foffset = (char*)mdp -> top - (char*)mdp -> base;
if( mdp -> fd > 0){
/* FIXME: Test results of lseek() and write() */
MAP_PRIVATE_OR_SHARED(mdp) | MAP_IS_ANONYMOUS(mdp) | MAP_FIXED,
MAP_ANON_OR_FD(mdp), foffset);
- if (mapto != (PTR) -1){
+ if (mapto != (void*) -1){
if(mdp -> top == 0)
mdp -> base = mdp -> breakval = mapto;
- mdp -> top = PAGE_ALIGN (mdp -> breakval + size);
- result = (PTR) mdp -> breakval;
- mdp -> breakval += size;
+ mdp -> top = PAGE_ALIGN ((char*)mdp -> breakval + size);
+ result = (void*) mdp -> breakval;
+ mdp -> breakval = (char*)mdp->breakval + size;
}
}
else
{
- result = (PTR) mdp -> breakval;
- mdp -> breakval += size;
+ result = (void*) mdp -> breakval;
+ mdp -> breakval = (char*)mdp->breakval + size;
}
}
return (result);
}
-PTR
-__mmalloc_remap_core (mdp)
- struct mdesc *mdp;
+void*
+__mmalloc_remap_core (struct mdesc *mdp)
{
- PTR base;
+ void* base;
/* FIXME: Quick hack, needs error checking and other attention. */
- base = mmap (mdp -> base, mdp -> top - mdp -> base,
+ base = mmap (mdp -> base, (char*)mdp -> top - (char*)mdp -> base,
PROT_READ | PROT_WRITE | PROT_EXEC, MAP_PRIVATE_OR_SHARED (mdp) | MAP_FIXED,
mdp -> fd, 0);
- return ((PTR) base);
+ return ((void*) base);
}
-PTR
-mmalloc_findbase (size)
- int size;
+void*
+mmalloc_findbase (int size)
{
int fd;
int flags;
- PTR base = NULL;
+ void* base = NULL;
#ifdef MAP_ANONYMOUS
flags = MAP_PRIVATE | MAP_ANONYMOUS;
fd = open ("/dev/zero", O_RDWR);
if (fd != -1)
{
- return ((PTR) NULL);
+ return ((void*) NULL);
}
#endif
base = mmap (0, size, PROT_READ | PROT_WRITE, flags, fd, 0);
- if (base != (PTR) -1)
+ if (base != (void*) -1)
{
munmap (base, (size_t) size);
}
to signal an error return, and besides, it is useful to
catch NULL pointers if it is unmapped. Instead start
at the next page boundary. */
- base = (PTR) getpagesize ();
+ base = (void*) getpagesize ();
}
- else if (base == (PTR) -1)
+ else if (base == (void*) -1)
{
base = NULL;
}
- return ((PTR) base);
+ return ((void*) base);
}
-
-#else /* defined(HAVE_MMAP) */
-/* Prevent "empty translation unit" warnings from the idiots at X3J11. */
-//static char ansi_c_idiots = 69;
#endif /* defined(HAVE_MMAP) */
can specify an alternate function to be called instead (and probably will
want to). */
-extern void abort PARAMS ((void));
+extern void abort (void);
/* Arbitrary magical numbers. */
unsigned long int magic; /* Magic number to check header integrity. */
};
-static void checkhdr PARAMS ((struct mdesc *, CONST struct hdr *));
-static void mfree_check PARAMS ((PTR, PTR));
-static PTR mmalloc_check PARAMS ((PTR, size_t));
-static PTR mrealloc_check PARAMS ((PTR, PTR, size_t));
+static void checkhdr (struct mdesc *mdp, const struct hdr *hdr);
+static void mfree_check (void* md, void* ptr);
+static void* mmalloc_check (void* md, size_t size);
+static void* mrealloc_check (void* md, void* ptr, size_t size);
/* Check the magicword and magicbyte, and if either is corrupted then
call the emergency abort function specified for the heap in use. */
static void
-checkhdr (mdp, hdr)
- struct mdesc *mdp;
- CONST struct hdr *hdr;
+checkhdr (struct mdesc *mdp, const struct hdr *hdr)
{
if (hdr -> magic != MAGICWORD ||
((char *) &hdr[1])[hdr -> size] != MAGICBYTE)
}
static void
-mfree_check (md, ptr)
- PTR md;
- PTR ptr;
+mfree_check (void *md, void *ptr)
{
struct hdr *hdr = ((struct hdr *) ptr) - 1;
struct mdesc *mdp;
checkhdr (mdp, hdr);
hdr -> magic = MAGICWORDFREE;
mdp -> mfree_hook = NULL;
- mfree (md, (PTR)hdr);
+ mfree (md, (void*)hdr);
mdp -> mfree_hook = mfree_check;
}
-static PTR
-mmalloc_check (md, size)
- PTR md;
- size_t size;
+static void*
+mmalloc_check (void *md, size_t size)
{
struct hdr *hdr;
struct mdesc *mdp;
hdr++;
*((char *) hdr + size) = MAGICBYTE;
}
- return ((PTR) hdr);
+ return ((void*) hdr);
}
-static PTR
-mrealloc_check (md, ptr, size)
- PTR md;
- PTR ptr;
- size_t size;
+static void*
+mrealloc_check (void* md, void* ptr, size_t size)
{
struct hdr *hdr = ((struct hdr *) ptr) - 1;
struct mdesc *mdp;
mdp -> mmalloc_hook = NULL;
mdp -> mrealloc_hook = NULL;
nbytes = sizeof (struct hdr) + size + 1;
- hdr = (struct hdr *) mrealloc (md, (PTR) hdr, nbytes);
+ hdr = (struct hdr *) mrealloc (md, (void*) hdr, nbytes);
mdp -> mfree_hook = mfree_check;
mdp -> mmalloc_hook = mmalloc_check;
mdp -> mrealloc_hook = mrealloc_check;
hdr++;
*((char *) hdr + size) = MAGICBYTE;
}
- return ((PTR) hdr);
+ return ((void*) hdr);
}
/* Turn on default checking for mmalloc/mrealloc/mfree, for the heap specified
Returns non-zero if checking is successfully enabled, zero otherwise. */
int
-mmcheckf (md, func, force)
- PTR md;
- void (*func) PARAMS ((void));
- int force;
+mmcheckf (void *md, void (*func)(void), int force)
{
struct mdesc *mdp;
int rtnval;
still callers to the original mmcheck function. */
int
-mmcheck (md, func)
- PTR md;
- void (*func) PARAMS ((void));
+mmcheck (void *md, void (*func) (void))
{
int rtnval;
#include "mmprivate.h"
-PTR
-mmemalign (md, alignment, size)
- PTR md;
- size_t alignment;
- size_t size;
+void *
+mmemalign (void *md, size_t alignment, size_t size)
{
- PTR result;
+ void* result;
unsigned long int adj;
struct alignlist *l;
struct mdesc *mdp;
#define BLOCK(A) (((char*) (A) - (char*) mdp -> heapbase) / BLOCKSIZE + 1)
-#define ADDRESS(B) ((PTR) (((ADDR2UINT(B)) - 1) * BLOCKSIZE + (char*) mdp -> heapbase))
+#define ADDRESS(B) ((void*) (((ADDR2UINT(B)) - 1) * BLOCKSIZE + (char*) mdp -> heapbase))
/* Data structure giving per-block information. */
struct alignlist
{
struct alignlist *next;
- PTR aligned; /* The address that mmemaligned returned. */
- PTR exact; /* The address that malloc returned. */
+ void* aligned; /* The address that mmemaligned returned. */
+ void* exact; /* The address that malloc returned. */
};
/* Doubly linked lists of free fragments. */
FIXME: For mapped regions shared by more than one process, this
needs to be maintained on a per-process basis. */
- PTR (*morecore) PARAMS ((struct mdesc *, int));
+ void* (*morecore) (struct mdesc *mdp, int size);
/* Pointer to the function that causes an abort when the memory checking
features are activated. By default this is set to abort(), but can
FIXME: For mapped regions shared by more than one process, this
needs to be maintained on a per-process basis. */
- void (*abortfunc) PARAMS ((void));
+ void (*abortfunc) (void);
/* Debugging hook for free.
FIXME: For mapped regions shared by more than one process, this
needs to be maintained on a per-process basis. */
- void (*mfree_hook) PARAMS ((PTR, PTR));
+ void (*mfree_hook) (void* mdp, void* ptr);
/* Debugging hook for `malloc'.
FIXME: For mapped regions shared by more than one process, this
needs to be maintained on a per-process basis. */
- PTR (*mmalloc_hook) PARAMS ((PTR, size_t));
+ void* (*mmalloc_hook) (void* mdp, size_t size);
/* Debugging hook for realloc.
FIXME: For mapped regions shared by more than one process, this
needs to be maintained on a per-process basis. */
- PTR (*mrealloc_hook) PARAMS ((PTR, PTR, size_t));
+ void* (*mrealloc_hook) (void* mdp, void* ptr, size_t size);
/* Number of info entries. */
/* Pointer to first block of the heap (base of the first block). */
- PTR heapbase;
+ void* heapbase;
/* Current search index for the heap table. */
/* Search index in the info table. */
is the location where the bookkeeping data for mmap and for malloc
begins. */
- PTR base;
+ void* base;
/* The current location in the memory region for this malloc heap which
represents the end of memory in use. */
- PTR breakval;
+ void* breakval;
/* The end of the current memory region for this malloc heap. This is
the first location past the end of mapped memory. */
- PTR top;
+ void* top;
/* Open file descriptor for the file to which this malloc heap is mapped.
This will always be a valid file descriptor, since /dev/zero is used
/* An array of keys to data within the mapped region, for use by the
application. */
- PTR keys[MMALLOC_KEYS];
+ void* keys[MMALLOC_KEYS];
};
/* Internal version of `mfree' used in `morecore'. */
-extern void __mmalloc_free PARAMS ((struct mdesc *, PTR));
-
-/* Hooks for debugging versions. */
-
-extern void (*__mfree_hook) PARAMS ((PTR, PTR));
-extern PTR (*__mmalloc_hook) PARAMS ((PTR, size_t));
-extern PTR (*__mrealloc_hook) PARAMS ((PTR, PTR, size_t));
+extern void __mmalloc_free (struct mdesc *mdp, void* ptr);
/* A default malloc descriptor for the single sbrk() managed region. */
/* Initialize the first use of the default malloc descriptor, which uses
an sbrk() region. */
-extern struct mdesc *__mmalloc_sbrk_init PARAMS ((void));
+extern struct mdesc *__mmalloc_sbrk_init (void);
/* Grow or shrink a contiguous mapped region using mmap().
Works much like sbrk() */
#if defined(HAVE_MMAP)
-extern PTR __mmalloc_mmap_morecore PARAMS ((struct mdesc *, int));
+extern void* __mmalloc_mmap_morecore (struct mdesc *mdp, int size);
#endif
/* Remap a mmalloc region that was previously mapped. */
-extern PTR __mmalloc_remap_core PARAMS ((struct mdesc *));
+extern void* __mmalloc_remap_core (struct mdesc *mdp);
/* Macro to convert from a user supplied malloc descriptor to pointer to the
internal malloc descriptor. If the user supplied descriptor is NULL, then
outside the library. */
struct mstats
-mmstats (md)
- PTR md;
+mmstats (void *md)
{
struct mstats result;
struct mdesc *mdp;
#include <stdio.h>
#include "mmprivate.h"
-static void tr_break PARAMS ((void));
-static void tr_freehook PARAMS ((PTR, PTR));
-static PTR tr_mallochook PARAMS ((PTR, size_t));
-static PTR tr_reallochook PARAMS ((PTR, PTR, size_t));
+static void tr_break (void);
+static void tr_freehook (void*md, void*ptr);
+static void* tr_mallochook (void* md, size_t size);
+static void* tr_reallochook (void* md, void* ptr, size_t size);
#ifndef __GNU_LIBRARY__
extern char *getenv ();
#endif
/* Address to breakpoint on accesses to... */
-static PTR mallwatch;
+static void* mallwatch;
/* Old hook values. */
-static void (*old_mfree_hook) PARAMS ((PTR, PTR));
-static PTR (*old_mmalloc_hook) PARAMS ((PTR, size_t));
-static PTR (*old_mrealloc_hook) PARAMS ((PTR, PTR, size_t));
+static void (*old_mfree_hook) (void* md, void* ptr);
+static void* (*old_mmalloc_hook) (void* md, size_t size);
+static void* (*old_mrealloc_hook) (void* md, void* ptr, size_t size);
/* This function is called when the block being alloc'd, realloc'd, or
freed has an address matching the variable "mallwatch". In a debugger,
tr_break. */
static void
-tr_break ()
+tr_break (void)
{
}
static void
-tr_freehook (md, ptr)
- PTR md;
- PTR ptr;
+tr_freehook (void *md, void *ptr)
{
struct mdesc *mdp;
mdp -> mfree_hook = tr_freehook;
}
-static PTR
-tr_mallochook (md, size)
- PTR md;
- size_t size;
+static void*
+tr_mallochook (void* md, size_t size)
{
- PTR hdr;
+ void* hdr;
struct mdesc *mdp;
mdp = MD_TO_MDP (md);
mdp -> mmalloc_hook = old_mmalloc_hook;
- hdr = (PTR) mmalloc (md, size);
+ hdr = (void*) mmalloc (md, size);
mdp -> mmalloc_hook = tr_mallochook;
/* We could be printing a NULL here; that's OK. */
return (hdr);
}
-static PTR
-tr_reallochook (md, ptr, size)
- PTR md;
- PTR ptr;
- size_t size;
+static void*
+tr_reallochook (void *md, void *ptr, size_t size)
{
- PTR hdr;
+ void* hdr;
struct mdesc *mdp;
mdp = MD_TO_MDP (md);
mdp -> mfree_hook = old_mfree_hook;
mdp -> mmalloc_hook = old_mmalloc_hook;
mdp -> mrealloc_hook = old_mrealloc_hook;
- hdr = (PTR) mrealloc (md, ptr, size);
+ hdr = (void*) mrealloc (md, ptr, size);
mdp -> mfree_hook = tr_freehook;
mdp -> mmalloc_hook = tr_mallochook;
mdp -> mrealloc_hook = tr_reallochook;
don't forget to set a breakpoint on tr_break! */
int
-mmtrace ()
+mmtrace (void)
{
#if 0 /* FIXME! This is disabled for now until we figure out how to
maintain a stack of hooks per heap, since we might have other
new region. This module has incestuous knowledge of the
internals of both mfree and mmalloc. */
-PTR
-mrealloc (md, ptr, size)
- PTR md;
- PTR ptr;
- size_t size;
+void*
+mrealloc (void *md, void *ptr, size_t size)
{
struct mdesc *mdp;
- PTR result;
+ void* result;
int type;
size_t block, blocks, oldlimit;
the application contains any "hidden" calls to malloc/realloc/free (such
as inside a system library). */
-PTR
-realloc (ptr, size)
- PTR ptr;
- size_t size;
+void *
+realloc (void *ptr, size_t size)
{
- PTR result;
+ void* result;
- result = mrealloc ((PTR) NULL, ptr, size);
+ result = mrealloc (NULL, ptr, size);
return (result);
}
extern int getpagesize PARAMS ((void));
#endif
-PTR
-mvalloc (md, size)
- PTR md;
- size_t size;
+void*
+mvalloc (void *md, size_t size)
{
if (cache_pagesize == 0)
{
}
/* Useless prototype to make gcc happy */
-PTR valloc (size_t size);
+void* valloc (size_t size);
-PTR
-valloc (size_t size)
-{
- return mvalloc ((PTR) NULL, size);
+void* valloc (size_t size) {
+ return mvalloc (NULL, size);
}
#include "mmprivate.h"
-static PTR sbrk_morecore PARAMS ((struct mdesc *, int));
+static void* sbrk_morecore (struct mdesc *mdp, int size);
#if NEED_DECLARATION_SBRK
-extern PTR sbrk PARAMS ((int));
+extern void* sbrk (int size);
#endif
/* The mmalloc() package can use a single implicit malloc descriptor
/* Use sbrk() to get more core. */
-static PTR
+static void*
sbrk_morecore (mdp, size)
struct mdesc *mdp;
int size;
{
- PTR result;
+ void* result;
- if ((result = sbrk (size)) == (PTR) -1)
+ if ((result = sbrk (size)) == (void*) -1)
{
result = NULL;
}
base address must be suitably aligned. */
struct mdesc *
-__mmalloc_sbrk_init ()
+__mmalloc_sbrk_init (void)
{
- PTR base;
+ void* base;
unsigned int adj;
base = sbrk (0);