1 /* GDB support for an sbrk-like function that uses mmap.
2 Copyright 1992 Free Software Foundation, Inc.
3 Contributed by Cygnus Support, using pieces from other GDB modules.
5 This file is part of GDB.
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version.
12 This program 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
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
30 #define MMAP_BASE ((caddr_t) 0x81000000)
31 #define MMAP_PGSZ 0x00002000 /* Must be multiple of real page size */
33 #define MMAP_BASE ((caddr_t) 0xC2000000)
34 #define MMAP_PGSZ 0x00002000 /* Must be multiple of real page size */
37 #define PAGE_ALIGN(addr) (caddr_t) (((long)(addr) + MMAP_PGSZ - 1) & \
40 static caddr_t mbase
= MMAP_BASE
; /* Current base of mmap'd region */
41 static caddr_t mbreak
= MMAP_BASE
; /* Current "break" address */
42 static caddr_t mtop
= MMAP_BASE
; /* Current top of mmap'd region */
44 static int fd
= -1; /* Open fd for /dev/zero */
47 /* Provide a utility routine for other modules to obtain compatible
51 mmap_page_align (addr
)
54 return (PAGE_ALIGN (addr
));
57 /* Return the base address of the start of the mmap'd region. Note that
58 we can find the end of the region at anytime by calling mmap_sbrk(0) */
66 /* Works like sbrk(), but uses mmap to add to or subtract from a
79 /* Just return the current "break" value. */
84 /* We are deallocating memory. If the amount requested would cause
85 us to try to deallocate back past the base of the mmap'd region
86 then do nothing, and return NULL. Otherwise, deallocate the
87 memory and return the old break value. */
88 if (mbreak
+ size
>= mbase
)
90 result
= (PTR
) mbreak
;
92 moveto
= PAGE_ALIGN (mbreak
);
93 munmap (moveto
, (size_t) (mtop
- moveto
));
99 /* We are allocating memory. Make sure we have an open file
100 descriptor and then go on to get the memory. */
101 if ((fd
== -1) && (fd
= open ("/dev/zero", O_RDONLY
)) < 0)
105 else if (mbreak
+ size
> mtop
)
107 /* The request would move us past the end of the currently
108 mapped memory, so map in enough more memory to satisfy
110 moveto
= PAGE_ALIGN (mbreak
+ size
);
111 if (mmap (mtop
, moveto
- mtop
, PROT_READ
| PROT_WRITE
,
112 MAP_PRIVATE
| MAP_FIXED
, fd
, 0) == mtop
)
115 result
= (PTR
) mbreak
;
121 result
= (PTR
) mbreak
;
129 mmap_remap (base
, mapsize
, fd
, foffset
)
135 /* FIXME: Quick hack, needs error checking and other attention. */
136 munmap (mbase
, (size_t) (mtop
- mbase
));
138 mtop
= mbase
+ mapsize
;
139 base
= mmap (base
, mapsize
, PROT_READ
| PROT_WRITE
,
140 MAP_PRIVATE
| MAP_FIXED
, dup (fd
), foffset
);
145 #endif /* HAVE_MMAP */
This page took 0.032002 seconds and 4 git commands to generate.