Mercurial > hg > CbC > CbC_gcc
comparison gcc/config/host-solaris.c @ 67:f6334be47118
update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
author | nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp> |
---|---|
date | Tue, 22 Mar 2011 17:18:12 +0900 |
parents | b7f97abdc517 |
children | 04ced10e8804 |
comparison
equal
deleted
inserted
replaced
65:65488c3d617d | 67:f6334be47118 |
---|---|
18 <http://www.gnu.org/licenses/>. */ | 18 <http://www.gnu.org/licenses/>. */ |
19 | 19 |
20 #include "config.h" | 20 #include "config.h" |
21 #include "system.h" | 21 #include "system.h" |
22 #include "coretypes.h" | 22 #include "coretypes.h" |
23 #include <sys/mman.h> | |
24 #include "hosthooks.h" | 23 #include "hosthooks.h" |
25 #include "hosthooks-def.h" | 24 #include "hosthooks-def.h" |
26 | 25 |
27 | 26 |
28 #undef HOST_HOOKS_GT_PCH_GET_ADDRESS | 27 #undef HOST_HOOKS_GT_PCH_GET_ADDRESS |
29 #define HOST_HOOKS_GT_PCH_GET_ADDRESS sol_gt_pch_get_address | 28 #define HOST_HOOKS_GT_PCH_GET_ADDRESS sol_gt_pch_get_address |
30 #undef HOST_HOOKS_GT_PCH_USE_ADDRESS | 29 #undef HOST_HOOKS_GT_PCH_USE_ADDRESS |
31 #define HOST_HOOKS_GT_PCH_USE_ADDRESS sol_gt_pch_use_address | 30 #define HOST_HOOKS_GT_PCH_USE_ADDRESS sol_gt_pch_use_address |
31 | |
32 /* Before Solaris 11, the mmap ADDR parameter is mostly ignored without | |
33 MAP_FIXED set. Before we give up, search the desired address space with | |
34 mincore to see if the space is really free. */ | |
35 | |
36 static void * | |
37 mmap_fixed (void *addr, size_t len, int prot, int flags, int fd, off_t off) | |
38 { | |
39 void *base; | |
40 | |
41 base = mmap ((caddr_t) addr, len, prot, flags, fd, off); | |
42 | |
43 if (base != addr) | |
44 { | |
45 size_t page_size = getpagesize(); | |
46 char one_byte; | |
47 size_t i; | |
48 | |
49 if (base != (void *) MAP_FAILED) | |
50 munmap ((caddr_t) base, len); | |
51 | |
52 errno = 0; | |
53 for (i = 0; i < len; i += page_size) | |
54 if (mincore ((char *)addr + i, page_size, (char *) &one_byte) == -1 | |
55 && errno == ENOMEM) | |
56 continue; /* The page is not mapped. */ | |
57 else | |
58 break; | |
59 | |
60 if (i >= len) | |
61 base = mmap ((caddr_t) addr, len, prot, flags | MAP_FIXED, fd, off); | |
62 } | |
63 | |
64 return base; | |
65 } | |
32 | 66 |
33 /* For various ports, try to guess a fixed spot in the vm space | 67 /* For various ports, try to guess a fixed spot in the vm space |
34 that's probably free. Based on McDougall, Mauro, Solaris Internals, 2nd | 68 that's probably free. Based on McDougall, Mauro, Solaris Internals, 2nd |
35 ed., p.460-461, fig. 9-3, 9-4, 9-5. */ | 69 ed., p.460-461, fig. 9-3, 9-4, 9-5. */ |
36 #if defined(__sparcv9__) | 70 #if defined(__sparcv9__) |
53 static void * | 87 static void * |
54 sol_gt_pch_get_address (size_t size, int fd) | 88 sol_gt_pch_get_address (size_t size, int fd) |
55 { | 89 { |
56 void *addr; | 90 void *addr; |
57 | 91 |
58 addr = mmap ((caddr_t) TRY_EMPTY_VM_SPACE, size, PROT_READ | PROT_WRITE, | 92 addr = mmap_fixed ((caddr_t) TRY_EMPTY_VM_SPACE, size, |
59 MAP_PRIVATE, fd, 0); | 93 PROT_READ | PROT_WRITE, MAP_PRIVATE, fd, 0); |
60 | 94 |
61 /* If we failed the map, that means there's *no* free space. */ | 95 /* If we failed the map, that means there's *no* free space. */ |
62 if (addr == (void *) MAP_FAILED) | 96 if (addr == (void *) MAP_FAILED) |
63 return NULL; | 97 return NULL; |
64 /* Unmap the area before returning. */ | 98 /* Unmap the area before returning. */ |
79 file at all. This allows the hook to free any static space that | 113 file at all. This allows the hook to free any static space that |
80 we might have allocated at link time. */ | 114 we might have allocated at link time. */ |
81 if (size == 0) | 115 if (size == 0) |
82 return -1; | 116 return -1; |
83 | 117 |
84 addr = mmap ((caddr_t) base, size, PROT_READ | PROT_WRITE, MAP_PRIVATE, | 118 addr = mmap_fixed ((caddr_t) base, size, |
85 fd, offset); | 119 PROT_READ | PROT_WRITE, MAP_PRIVATE, fd, offset); |
86 | |
87 /* Solaris isn't good about honoring the mmap START parameter | |
88 without MAP_FIXED set. Before we give up, search the desired | |
89 address space with mincore to see if the space is really free. */ | |
90 if (addr != base) | |
91 { | |
92 size_t page_size = getpagesize(); | |
93 char one_byte; | |
94 size_t i; | |
95 | |
96 if (addr != (void *) MAP_FAILED) | |
97 munmap ((caddr_t) addr, size); | |
98 | |
99 errno = 0; | |
100 for (i = 0; i < size; i += page_size) | |
101 if (mincore ((char *)base + i, page_size, (char *) &one_byte) == -1 | |
102 && errno == ENOMEM) | |
103 continue; /* The page is not mapped. */ | |
104 else | |
105 break; | |
106 | |
107 if (i >= size) | |
108 addr = mmap ((caddr_t) base, size, | |
109 PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_FIXED, | |
110 fd, offset); | |
111 } | |
112 | 120 |
113 return addr == base ? 1 : -1; | 121 return addr == base ? 1 : -1; |
114 } | 122 } |
115 | 123 |
116 | 124 |