1 /* Support for sbrk() regions.
2 Copyright 1992, 2000 Free Software Foundation, Inc.
3 Contributed by Fred Fish at Cygnus Support. fnf@cygnus.com
5 This file is part of the GNU C Library.
7 The GNU C Library is free software; you can redistribute it and/or
8 modify it under the terms of the GNU Library General Public License as
9 published by the Free Software Foundation; either version 2 of the
10 License, or (at your option) any later version.
12 The GNU C Library is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 Library General Public License for more details.
17 You should have received a copy of the GNU Library General Public
18 License along with the GNU C Library; see the file COPYING.LIB. If
19 not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
20 Boston, MA 02111-1307, USA. */
23 #include <unistd.h> /* Prototypes for sbrk (maybe) */
25 #include <string.h> /* Prototypes for memcpy, memmove, memset, etc */
27 #include "mmprivate.h"
29 static PTR sbrk_morecore
PARAMS ((struct mdesc
*, int));
30 #if NEED_DECLARATION_SBRK
31 extern PTR sbrk
PARAMS ((int));
34 /* The mmalloc() package can use a single implicit malloc descriptor
35 for mmalloc/mrealloc/mfree operations which do not supply an explicit
36 descriptor. For these operations, sbrk() is used to obtain more core
37 from the system, or return core. This allows mmalloc() to provide
38 backwards compatibility with the non-mmap'd version. */
40 struct mdesc
*__mmalloc_default_mdp
;
42 /* Use sbrk() to get more core. */
45 sbrk_morecore (mdp
, size
)
51 if ((result
= sbrk (size
)) == (PTR
) -1)
57 mdp
-> breakval
+= size
;
63 /* Initialize the default malloc descriptor if this is the first time
64 a request has been made to use the default sbrk'd region.
66 Since no alignment guarantees are made about the initial value returned
67 by sbrk, test the initial value and (if necessary) sbrk enough additional
68 memory to start off with alignment to BLOCKSIZE. We actually only need
69 it aligned to an alignment suitable for any object, so this is overkill.
70 But at most it wastes just part of one BLOCKSIZE chunk of memory and
71 minimizes portability problems by avoiding us having to figure out
72 what the actual minimal alignment is. The rest of the malloc code
73 avoids this as well, by always aligning to the minimum of the requested
74 size rounded up to a power of two, or to BLOCKSIZE.
76 Note that we are going to use some memory starting at this initial sbrk
77 address for the sbrk region malloc descriptor, which is a struct, so the
78 base address must be suitably aligned. */
81 __mmalloc_sbrk_init ()
87 adj
= RESIDUAL (base
, BLOCKSIZE
);
90 sbrk (BLOCKSIZE
- adj
);
93 __mmalloc_default_mdp
= (struct mdesc
*) sbrk (sizeof (struct mdesc
));
94 memset ((char *) __mmalloc_default_mdp
, 0, sizeof (struct mdesc
));
95 __mmalloc_default_mdp
-> morecore
= sbrk_morecore
;
96 __mmalloc_default_mdp
-> base
= base
;
97 __mmalloc_default_mdp
-> breakval
= __mmalloc_default_mdp
-> top
= sbrk (0);
98 __mmalloc_default_mdp
-> fd
= -1;
99 return (__mmalloc_default_mdp
);
This page took 0.040086 seconds and 4 git commands to generate.