X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/blobdiff_plain/c0bf08270464302ec402873aed75a459b08e0a8c..011b6e172c0b7366132196dd9797f7bc3b951df2:/src/xbt/mmalloc/sbrk-sup.c diff --git a/src/xbt/mmalloc/sbrk-sup.c b/src/xbt/mmalloc/sbrk-sup.c index d3b4f38898..40638c970c 100644 --- a/src/xbt/mmalloc/sbrk-sup.c +++ b/src/xbt/mmalloc/sbrk-sup.c @@ -8,83 +8,32 @@ /* This program is free software; you can redistribute it and/or modify it * under the terms of the license (GNU LGPL) which comes with this package. */ -#include /* Prototypes for sbrk (maybe) */ +#include /* Prototypes for sbrk (maybe) */ -#include /* Prototypes for memcpy, memmove, memset, etc */ +#include /* Prototypes for memcpy, memmove, memset, etc */ +#include "xbt.h" #include "mmprivate.h" -static void* sbrk_morecore (struct mdesc *mdp, int size); +static void *sbrk_morecore(struct mdesc *mdp, int size); #if NEED_DECLARATION_SBRK -extern void* sbrk (int size); +extern void *sbrk(int size); #endif -/* The mmalloc() package can use a single implicit malloc descriptor - for mmalloc/mrealloc/mfree operations which do not supply an explicit - descriptor. For these operations, sbrk() is used to obtain more core - from the system, or return core. This allows mmalloc() to provide - backwards compatibility with the non-mmap'd version. */ - -struct mdesc *__mmalloc_default_mdp; /* Use sbrk() to get more core. */ -static void* -sbrk_morecore (mdp, size) - struct mdesc *mdp; - int size; +static void *sbrk_morecore(mdp, size) +struct mdesc *mdp; +int size; { - void* result; - - if ((result = sbrk (size)) == (void*) -1) - { - result = NULL; - } - else - { - mdp -> breakval = (char*)mdp -> breakval + size; - mdp -> top = (char*)mdp -> top + size; - } + void *result; + + if ((result = sbrk(size)) == (void *) -1) { + result = NULL; + } else { + mdp->breakval = (char *) mdp->breakval + size; + mdp->top = (char *) mdp->top + size; + } return (result); } - -/* Initialize the default malloc descriptor if this is the first time - a request has been made to use the default sbrk'd region. - - Since no alignment guarantees are made about the initial value returned - by sbrk, test the initial value and (if necessary) sbrk enough additional - memory to start off with alignment to BLOCKSIZE. We actually only need - it aligned to an alignment suitable for any object, so this is overkill. - But at most it wastes just part of one BLOCKSIZE chunk of memory and - minimizes portability problems by avoiding us having to figure out - what the actual minimal alignment is. The rest of the malloc code - avoids this as well, by always aligning to the minimum of the requested - size rounded up to a power of two, or to BLOCKSIZE. - - Note that we are going to use some memory starting at this initial sbrk - address for the sbrk region malloc descriptor, which is a struct, so the - base address must be suitably aligned. */ - -struct mdesc * -__mmalloc_sbrk_init (void) -{ - void* base; - unsigned int adj; - - base = sbrk (0); - adj = RESIDUAL (base, BLOCKSIZE); - if (adj != 0) - { - sbrk (BLOCKSIZE - adj); - base = sbrk (0); - } - __mmalloc_default_mdp = (struct mdesc *) sbrk (sizeof (struct mdesc)); - memset ((char *) __mmalloc_default_mdp, 0, sizeof (struct mdesc)); - __mmalloc_default_mdp -> morecore = sbrk_morecore; - __mmalloc_default_mdp -> base = base; - __mmalloc_default_mdp -> breakval = __mmalloc_default_mdp -> top = sbrk (0); - __mmalloc_default_mdp -> fd = -1; - return (__mmalloc_default_mdp); -} - -