comparison gcc/config/host-solaris.c @ 0:a06113de4d67

first commit
author kent <kent@cr.ie.u-ryukyu.ac.jp>
date Fri, 17 Jul 2009 14:47:48 +0900
parents
children b7f97abdc517
comparison
equal deleted inserted replaced
-1:000000000000 0:a06113de4d67
1 /* Solaris host-specific hook definitions.
2 Copyright (C) 2004, 2007, 2008 Free Software Foundation, Inc.
3
4 This file is part of GCC.
5
6 GCC is free software; you can redistribute it and/or modify it
7 under the terms of the GNU General Public License as published
8 by the Free Software Foundation; either version 3, or (at your
9 option) any later version.
10
11 GCC is distributed in the hope that it will be useful, but WITHOUT
12 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
13 or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
14 License for more details.
15
16 You should have received a copy of the GNU General Public License
17 along with GCC; see the file COPYING3. If not see
18 <http://www.gnu.org/licenses/>. */
19
20 #include "config.h"
21 #include "system.h"
22 #include "coretypes.h"
23 #include <sys/mman.h>
24 #include "hosthooks.h"
25 #include "hosthooks-def.h"
26
27
28 #undef HOST_HOOKS_GT_PCH_USE_ADDRESS
29 #define HOST_HOOKS_GT_PCH_USE_ADDRESS sol_gt_pch_use_address
30
31 /* Map SIZE bytes of FD+OFFSET at BASE. Return 1 if we succeeded at
32 mapping the data at BASE, -1 if we couldn't. */
33
34 static int
35 sol_gt_pch_use_address (void *base, size_t size, int fd, size_t offset)
36 {
37 void *addr;
38
39 /* We're called with size == 0 if we're not planning to load a PCH
40 file at all. This allows the hook to free any static space that
41 we might have allocated at link time. */
42 if (size == 0)
43 return -1;
44
45 addr = mmap ((caddr_t) base, size, PROT_READ | PROT_WRITE, MAP_PRIVATE,
46 fd, offset);
47
48 /* Solaris isn't good about honoring the mmap START parameter
49 without MAP_FIXED set. Before we give up, search the desired
50 address space with mincore to see if the space is really free. */
51 if (addr != base)
52 {
53 size_t page_size = getpagesize();
54 char one_byte;
55 size_t i;
56
57 if (addr != (void *) MAP_FAILED)
58 munmap ((caddr_t) addr, size);
59
60 errno = 0;
61 for (i = 0; i < size; i += page_size)
62 if (mincore ((char *)base + i, page_size, (char *) &one_byte) == -1
63 && errno == ENOMEM)
64 continue; /* The page is not mapped. */
65 else
66 break;
67
68 if (i >= size)
69 addr = mmap ((caddr_t) base, size,
70 PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_FIXED,
71 fd, offset);
72 }
73
74 return addr == base ? 1 : -1;
75 }
76
77
78 const struct host_hooks host_hooks = HOST_HOOKS_INITIALIZER;