Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Implement reentrant mutexes in xbt_os_thread
[simgrid.git] / src / xbt / mmalloc / sbrk-sup.c
1 /* Support for sbrk() regions.
2    Copyright 1992, 2000 Free Software Foundation, Inc.
3    Contributed by Fred Fish at Cygnus Support.   fnf@cygnus.com */
4
5 /* Copyright (c) 2010. The SimGrid Team.
6  * All rights reserved.                                                     */
7
8 /* This program is free software; you can redistribute it and/or modify it
9  * under the terms of the license (GNU LGPL) which comes with this package. */
10
11 #include <unistd.h>             /* Prototypes for sbrk (maybe) */
12
13 #include <string.h>             /* Prototypes for memcpy, memmove, memset, etc */
14
15 #include "xbt.h"
16 #include "mmprivate.h"
17
18 static void *sbrk_morecore(struct mdesc *mdp, int size);
19 #if NEED_DECLARATION_SBRK
20 extern void *sbrk(int size);
21 #endif
22
23 /* The mmalloc() package can use a single implicit malloc descriptor
24    for mmalloc/mrealloc/mfree operations which do not supply an explicit
25    descriptor.  For these operations, sbrk() is used to obtain more core
26    from the system, or return core.  This allows mmalloc() to provide
27    backwards compatibility with the non-mmap'd version. */
28
29 struct mdesc *__mmalloc_default_mdp;
30
31 /* Use sbrk() to get more core. */
32
33 static void *sbrk_morecore(mdp, size)
34 struct mdesc *mdp;
35 int size;
36 {
37   void *result;
38
39   if ((result = sbrk(size)) == (void *) -1) {
40     result = NULL;
41   } else {
42     mdp->breakval = (char *) mdp->breakval + size;
43     mdp->top = (char *) mdp->top + size;
44   }
45   return (result);
46 }