summaryrefslogtreecommitdiffstats
path: root/gmalloc.c
diff options
context:
space:
mode:
authorBryan Newbold <bnewbold@robocracy.org>2017-02-20 00:05:25 -0800
committerBryan Newbold <bnewbold@robocracy.org>2017-02-20 00:05:25 -0800
commitdb04688faa20f3576257c0fe41752ec435beab9a (patch)
tree6d638c2e1f65afd5f49d20b2d22ce35bd74705ff /gmalloc.c
parent1edcb9b62a1a520eddae8403c19d841c9b18737f (diff)
downloadscm-db04688faa20f3576257c0fe41752ec435beab9a.tar.gz
scm-db04688faa20f3576257c0fe41752ec435beab9a.zip
Import Upstream version 5c3upstream/5c3
Diffstat (limited to 'gmalloc.c')
-rw-r--r--gmalloc.c168
1 files changed, 108 insertions, 60 deletions
diff --git a/gmalloc.c b/gmalloc.c
index d9eaf1b..cf0fad2 100644
--- a/gmalloc.c
+++ b/gmalloc.c
@@ -1,4 +1,4 @@
-/* DO NOT EDIT THIS FILE -- it is automagically generated. -*- C -*- */
+/* This file is no longer automatically generated from libc. */
#define _MALLOC_INTERNAL
@@ -37,13 +37,13 @@ Cambridge, MA 02139, USA.
#endif
#if defined (__cplusplus) || (defined (__STDC__) && __STDC__)
-#undef __P
-#define __P(args) args
+#undef PP
+#define PP(args) args
#undef __ptr_t
#define __ptr_t void *
#else /* Not C++ or ANSI C. */
-#undef __P
-#define __P(args) ()
+#undef PP
+#define PP(args) ()
#undef const
#define const
#undef __ptr_t
@@ -96,24 +96,24 @@ extern "C"
/* Allocate SIZE bytes of memory. */
-extern __ptr_t malloc __P ((__malloc_size_t __size));
+extern __ptr_t malloc PP ((__malloc_size_t __size));
/* Re-allocate the previously allocated block
in __ptr_t, making the new block SIZE bytes long. */
-extern __ptr_t realloc __P ((__ptr_t __ptr, __malloc_size_t __size));
+extern __ptr_t realloc PP ((__ptr_t __ptr, __malloc_size_t __size));
/* Allocate NMEMB elements of SIZE bytes each, all initialized to 0. */
-extern __ptr_t calloc __P ((__malloc_size_t __nmemb, __malloc_size_t __size));
+extern __ptr_t calloc PP ((__malloc_size_t __nmemb, __malloc_size_t __size));
/* Free a block allocated by `malloc', `realloc' or `calloc'. */
-extern void free __P ((__ptr_t __ptr));
+extern void free PP ((__ptr_t __ptr));
/* Allocate SIZE bytes allocated to ALIGNMENT bytes. */
#if ! (defined (_MALLOC_INTERNAL) && __DJGPP__ - 0 == 1) /* Avoid conflict. */
-extern __ptr_t memalign __P ((__malloc_size_t __alignment,
- __malloc_size_t __size));
+extern __ptr_t memalign PP ((__malloc_size_t __alignment,
+ __malloc_size_t __size));
#endif
/* Allocate SIZE bytes on a page boundary. */
#if ! (defined (_MALLOC_INTERNAL) && defined (GMALLOC_INHIBIT_VALLOC))
-extern __ptr_t valloc __P ((__malloc_size_t __size));
+extern __ptr_t valloc PP ((__malloc_size_t __size));
#endif
@@ -213,26 +213,26 @@ extern __malloc_size_t _bytes_free;
/* Internal versions of `malloc', `realloc', and `free'
used when these functions need to call each other.
They are the same but don't call the hooks. */
-extern __ptr_t _malloc_internal __P ((__malloc_size_t __size));
-extern __ptr_t _realloc_internal __P ((__ptr_t __ptr, __malloc_size_t __size));
-extern void _free_internal __P ((__ptr_t __ptr));
+extern __ptr_t _malloc_internal PP ((__malloc_size_t __size));
+extern __ptr_t _realloc_internal PP ((__ptr_t __ptr, __malloc_size_t __size));
+extern void _free_internal PP ((__ptr_t __ptr));
#endif /* _MALLOC_INTERNAL. */
/* Given an address in the middle of a malloc'd object,
return the address of the beginning of the object. */
-extern __ptr_t malloc_find_object_address __P ((__ptr_t __ptr));
+extern __ptr_t malloc_find_object_address PP ((__ptr_t __ptr));
/* Underlying allocation function; successive calls should
return contiguous pieces of memory. */
-extern __ptr_t (*__morecore) __P ((__malloc_ptrdiff_t __size));
+extern __ptr_t (*__morecore) PP ((__malloc_ptrdiff_t __size));
/* Default value of `__morecore'. */
-extern __ptr_t __default_morecore __P ((__malloc_ptrdiff_t __size));
+extern __ptr_t __default_morecore PP ((__malloc_ptrdiff_t __size));
/* If not NULL, this function is called after each time
`__morecore' is called to increase the data size. */
-extern void (*__after_morecore_hook) __P ((void));
+extern void (*__after_morecore_hook) PP ((void));
/* Number of extra blocks to get each time we ask for more core.
This reduces the frequency of calling `(*__morecore)'. */
@@ -241,15 +241,19 @@ extern __malloc_size_t __malloc_extra_blocks;
/* Nonzero if `malloc' has been called and done its initialization. */
extern int __malloc_initialized;
/* Function called to initialize malloc data structures. */
-extern int __malloc_initialize __P ((void));
+extern int __malloc_initialize PP ((void));
/* Hooks for debugging versions. */
-extern void (*__malloc_initialize_hook) __P ((void));
-extern void (*__free_hook) __P ((__ptr_t __ptr));
-extern __ptr_t (*__malloc_hook) __P ((__malloc_size_t __size));
-extern __ptr_t (*__realloc_hook) __P ((__ptr_t __ptr, __malloc_size_t __size));
-extern __ptr_t (*__memalign_hook) __P ((__malloc_size_t __size,
- __malloc_size_t __alignment));
+extern void (*__malloc_initialize_hook) PP ((void));
+extern void (*__free_hook) PP ((__ptr_t __ptr));
+extern __ptr_t (*__malloc_hook) PP ((__malloc_size_t __size));
+extern __ptr_t (*__realloc_hook) PP ((__ptr_t __ptr, __malloc_size_t __size));
+extern __ptr_t (*__memalign_hook) PP ((__malloc_size_t __size,
+ __malloc_size_t __alignment));
+
+ /* Debugging functions, added by Radey Shouman */
+int check_block __P((__malloc_size_t block, int cont));
+int check_frag_blocks __P((void));
/* Return values for `mprobe': these are the kinds of inconsistencies that
`mcheck' enables detection of. */
@@ -266,16 +270,16 @@ enum mcheck_status
before `malloc' is ever called. ABORTFUNC is called with an error code
(see enum above) when an inconsistency is detected. If ABORTFUNC is
null, the standard function prints on stderr and then calls `abort'. */
-extern int mcheck __P ((void (*__abortfunc) __P ((enum mcheck_status))));
+extern int mcheck PP ((void (*__abortfunc) PP ((enum mcheck_status))));
/* Check for aberrations in a particular malloc'd block. You must have
called `mcheck' already. These are the same checks that `mcheck' does
when you free or reallocate a block. */
-extern enum mcheck_status mprobe __P ((__ptr_t __ptr));
+extern enum mcheck_status mprobe PP ((__ptr_t __ptr));
/* Activate a standard collection of tracing hooks. */
-extern void mtrace __P ((void));
-extern void muntrace __P ((void));
+extern void mtrace PP ((void));
+extern void muntrace PP ((void));
/* Statistics available to the user. */
struct mstats
@@ -288,23 +292,23 @@ struct mstats
};
/* Pick up the current statistics. */
-extern struct mstats mstats __P ((void));
+extern struct mstats mstats PP ((void));
/* Call WARNFUN with a warning message when memory usage is high. */
-extern void memory_warnings __P ((__ptr_t __start,
- void (*__warnfun) __P ((const char *))));
+extern void memory_warnings PP ((__ptr_t __start,
+ void (*__warnfun) PP ((const char *))));
/* Relocating allocator. */
/* Allocate SIZE bytes, and store the address in *HANDLEPTR. */
-extern __ptr_t r_alloc __P ((__ptr_t *__handleptr, __malloc_size_t __size));
+extern __ptr_t r_alloc PP ((__ptr_t *__handleptr, __malloc_size_t __size));
/* Free the storage allocated in HANDLEPTR. */
-extern void r_alloc_free __P ((__ptr_t *__handleptr));
+extern void r_alloc_free PP ((__ptr_t *__handleptr));
/* Adjust the block at HANDLEPTR to be SIZE bytes long. */
-extern __ptr_t r_re_alloc __P ((__ptr_t *__handleptr, __malloc_size_t __size));
+extern __ptr_t r_re_alloc PP ((__ptr_t *__handleptr, __malloc_size_t __size));
#ifdef __cplusplus
@@ -341,10 +345,10 @@ Cambridge, MA 02139, USA.
#include <errno.h>
/* How to really get more memory. */
-__ptr_t (*__morecore) __P ((ptrdiff_t __size)) = __default_morecore;
+__ptr_t (*__morecore) PP ((ptrdiff_t __size)) = __default_morecore;
/* Debugging hook for `malloc'. */
-__ptr_t (*__malloc_hook) __P ((__malloc_size_t __size));
+__ptr_t (*__malloc_hook) PP ((__malloc_size_t __size));
/* Pointer to the base of the first block. */
char *_heapbase;
@@ -375,12 +379,12 @@ int __malloc_initialized;
__malloc_size_t __malloc_extra_blocks;
-void (*__malloc_initialize_hook) __P ((void));
-void (*__after_morecore_hook) __P ((void));
+void (*__malloc_initialize_hook) PP ((void));
+void (*__after_morecore_hook) PP ((void));
/* Aligned allocation. */
-static __ptr_t align __P ((__malloc_size_t));
+static __ptr_t align PP ((__malloc_size_t));
static __ptr_t
align (size)
__malloc_size_t size;
@@ -408,7 +412,7 @@ align (size)
/* Get SIZE bytes, if we can get them starting at END.
Return the address of the space we got.
If we cannot get space at END, fail and return 0. */
-static __ptr_t get_contiguous_space __P ((__malloc_ptrdiff_t, __ptr_t));
+static __ptr_t get_contiguous_space PP ((__malloc_ptrdiff_t, __ptr_t));
static __ptr_t
get_contiguous_space (size, position)
__malloc_ptrdiff_t size;
@@ -442,7 +446,7 @@ get_contiguous_space (size, position)
/* This is called when `_heapinfo' and `heapsize' have just
been set to describe a new info table. Set up the table
to describe itself and account for it in the statistics. */
-static void register_heapinfo __P ((void));
+static void register_heapinfo PP ((void));
#ifdef __GNUC__
__inline__
#endif
@@ -497,7 +501,7 @@ static int morecore_recursing;
/* Get neatly aligned memory, initializing or
growing the heap info table as necessary. */
-static __ptr_t morecore __P ((__malloc_size_t));
+static __ptr_t morecore PP ((__malloc_size_t));
static __ptr_t
morecore (size)
__malloc_size_t size;
@@ -875,14 +879,14 @@ Cambridge, MA 02139, USA.
#define __malloc_safe_bcopy safe_bcopy
#endif
/* This function is defined in realloc.c. */
-extern void __malloc_safe_bcopy __P ((__ptr_t, __ptr_t, __malloc_size_t));
+extern void __malloc_safe_bcopy PP ((__ptr_t, __ptr_t, __malloc_size_t));
#define memmove(to, from, size) __malloc_safe_bcopy ((from), (to), (size))
#endif
#endif
/* Debugging hook for free. */
-void (*__free_hook) __P ((__ptr_t __ptr));
+void (*__free_hook) PP ((__ptr_t __ptr));
/* List of blocks allocated by memalign. */
struct alignlist *_aligned_blocks = NULL;
@@ -1248,7 +1252,7 @@ __malloc_safe_bcopy (afrom, ato, size)
#endif /* emacs */
#ifndef memmove
-extern void __malloc_safe_bcopy __P ((__ptr_t, __ptr_t, __malloc_size_t));
+extern void __malloc_safe_bcopy PP ((__ptr_t, __ptr_t, __malloc_size_t));
#define memmove(to, from, size) __malloc_safe_bcopy ((from), (to), (size))
#endif
@@ -1258,7 +1262,7 @@ extern void __malloc_safe_bcopy __P ((__ptr_t, __ptr_t, __malloc_size_t));
#define min(A, B) ((A) < (B) ? (A) : (B))
/* Debugging hook for realloc. */
-__ptr_t (*__realloc_hook) __P ((__ptr_t __ptr, __malloc_size_t __size));
+__ptr_t (*__realloc_hook) PP ((__ptr_t __ptr, __malloc_size_t __size));
/* Resize the given region to the new size, returning a pointer
to the (possibly moved) region. This is optimized for speed;
@@ -1460,7 +1464,7 @@ the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */
systems with potentially hostile include files. */
#include <stddef.h>
-extern __ptr_t __sbrk __P ((ptrdiff_t increment));
+extern __ptr_t __sbrk PP ((ptrdiff_t increment));
#endif
#ifndef NULL
@@ -1508,7 +1512,7 @@ Cambridge, MA 02139, USA. */
#else
-__ptr_t (*__memalign_hook) __P ((size_t __size, size_t __alignment));
+__ptr_t (*__memalign_hook) PP ((size_t __size, size_t __alignment));
__ptr_t
memalign (alignment, size)
@@ -1612,19 +1616,13 @@ Cambridge, MA 02139, USA.
#if defined (__GNU_LIBRARY__) || defined (_LIBC)
#include <stddef.h>
#include <sys/cdefs.h>
-extern size_t __getpagesize __P ((void));
+#if defined (__GLIBC__) && __GLIBC__ >= 2
+/* __getpagesize is already declared in <unistd.h> with return type int */
#else
-/* added by Denys Duchier: handle missing getpagesize.h
- on solaris: getpagesize is in the c library, but there
- is no include file that declares it.
- */
-#if defined(sun) && defined(__svr4__) && !defined(__GNUG__)
-extern int getpagesize(void);
+extern size_t __getpagesize PP ((void));
+#endif
#else
-#ifndef hpux
#include "getpagesize.h"
-#endif
-#endif
#define __getpagesize() getpagesize()
#endif
@@ -1646,3 +1644,53 @@ valloc (size)
}
#endif /* Not ELIDE_VALLOC. */
+
+/* Debugging functions added by Radey Shouman */
+struct list *check_block_prev;
+int check_block(block, cont)
+ __malloc_size_t block;
+ int cont;
+{
+ char *minptr, *maxptr;
+ struct list *ptr, *prev;
+ int nfree, type = _heapinfo[block].busy.type;
+ tail:
+ nfree = _heapinfo[block].busy.info.frag.nfree;
+ minptr = ((char *)ADDRESS(block));
+ maxptr = ((char *)ADDRESS(block) + BLOCKSIZE);
+ if (0==type) return 0;
+ prev = ptr = (struct list *) ((char *) ADDRESS (block) +
+ (_heapinfo[block].busy.info.frag.first << type));
+ if ((BLOCKSIZE >> type) <= nfree)
+ return 1;
+ if (nfree < 0)
+ return 2;
+ while (nfree--) {
+ if (! (((char *)ptr >= minptr) && ((char *)ptr < maxptr)))
+ return 3;
+ prev = ptr;
+ ptr = prev->next;
+ }
+ check_block_prev = prev;
+ if (cont && ptr) {
+ block = BLOCK(ptr);
+ if (type != _heapinfo[block].busy.type) return 4;
+ goto tail;
+ }
+ return 0;
+}
+
+int check_frag_blocks()
+{
+ __malloc_size_t block;
+ int err;
+ __malloc_size_t log;
+ for (log = 1; log < BLOCKLOG; log++)
+ if (_fraghead[log].next) {
+ block = BLOCK(_fraghead[log].next);
+ err = check_block(block, !0);
+ if (err) return err;
+ }
+ return 0;
+}
+