1 /* mremap.c -- version of mremap for gold. */
3 /* Copyright 2009, 2011 Free Software Foundation, Inc.
4 Written by Ian Lance Taylor <iant@google.com>.
6 This file is part of gold.
8 This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 3 of the License, or
11 (at your option) any later version.
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with this program; if not, write to the Free Software
20 Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
21 MA 02110-1301, USA. */
28 #include <sys/types.h>
30 #ifdef HAVE_SYS_MMAN_H
34 extern void *gold_mremap (void *, size_t, size_t, int);
38 /* This file implements mremap for systems which don't have it. The
39 gold code requires support for mmap. However, there are systems
40 which have mmap but not mremap. This is not a general replacement
41 for mremap; it only supports the features which are required for
42 gold. In particular, we assume that the MREMAP_MAYMOVE flag is
45 /* Some BSD systems still use MAP_ANON instead of MAP_ANONYMOUS. */
48 # define MAP_ANONYMOUS MAP_ANON
52 gold_mremap (void *old_address
, size_t old_size
, size_t new_size
,
53 int flags ATTRIBUTE_UNUSED
)
57 ret
= mmap (0, new_size
, PROT_READ
| PROT_WRITE
,
58 MAP_PRIVATE
| MAP_ANONYMOUS
, -1, 0);
59 if (ret
== MAP_FAILED
)
61 memcpy (ret
, old_address
,
62 old_size
< new_size
? old_size
: new_size
);
63 (void) munmap (old_address
, old_size
);
67 #else /* !defined(HAVE_MMAP) */
70 #define MAP_FAILED ((void *) -1)
78 gold_mremap (void *old_address ATTRIBUTE_UNUSED
,
79 size_t old_size ATTRIBUTE_UNUSED
,
80 size_t new_size ATTRIBUTE_UNUSED
,
81 int flags ATTRIBUTE_UNUSED
)
87 #endif /* !defined(HAVE_MMAP) */