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