* arm.cc: Added support for ARM group relocations.
[binutils.git] / gold / mremap.c
blob332fded11c9dc39a2ef0c3db0c5c613177d396d0
1 /* mremap.c -- version of mremap for gold. */
3 /* Copyright 2009 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. */
23 #include "config.h"
24 #include "ansidecl.h"
26 #include <string.h>
27 #include <sys/types.h>
28 #include <sys/mman.h>
30 /* This file implements mremap for systems which don't have it. The
31 gold code requires support for mmap. However, there are systems
32 which have mmap but not mremap. This is not a general replacement
33 for mremap; it only supports the features which are required for
34 gold. In particular, we assume that the MREMAP_MAYMOVE flag is
35 set. */
37 /* Some BSD systems still use MAP_ANON instead of MAP_ANONYMOUS. */
39 #ifndef MAP_ANONYMOUS
40 # define MAP_ANONYMOUS MAP_ANON
41 #endif
43 extern void *mremap (void *, size_t, size_t, int, ...);
45 void *
46 mremap (void *old_address, size_t old_size, size_t new_size,
47 int flags ATTRIBUTE_UNUSED, ...)
49 void *ret;
51 ret = mmap (0, new_size, PROT_READ | PROT_WRITE,
52 MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
53 if (ret == MAP_FAILED)
54 return ret;
55 memcpy (ret, old_address,
56 old_size < new_size ? old_size : new_size);
57 (void) munmap (old_address, old_size);
58 return ret;