1/* Darwin/powerpc host-specific hook definitions.
2 Copyright (C) 2003, 2004 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 2, or (at your
9 option) any later version.
10
--- 121 unchanged lines hidden (view full) ---
132
133 sigemptyset(&sact.sa_mask);
134 sact.sa_flags = SA_ONSTACK | SA_SIGINFO;
135 sact.sa_sigaction = segv_handler;
136 if (sigaction (SIGSEGV, &sact, 0) < 0)
137 fatal_error ("While setting up signal handler: %m");
138}
139
140#undef HOST_HOOKS_GT_PCH_GET_ADDRESS
141#define HOST_HOOKS_GT_PCH_GET_ADDRESS darwin_rs6000_gt_pch_get_address
142#undef HOST_HOOKS_GT_PCH_USE_ADDRESS
143#define HOST_HOOKS_GT_PCH_USE_ADDRESS darwin_rs6000_gt_pch_use_address
144
145/* Yes, this is really supposed to work. */
146static char pch_address_space[1024*1024*1024] __attribute__((aligned (4096)));
147
148/* Return the address of the PCH address space, if the PCH will fit in it. */
149
150static void *
151darwin_rs6000_gt_pch_get_address (size_t sz, int fd ATTRIBUTE_UNUSED)
152{
153 if (sz <= sizeof (pch_address_space))
154 return pch_address_space;
155 else
156 return NULL;
157}
158
159/* Check ADDR and SZ for validity, and deallocate (using munmap) that part of
160 pch_address_space beyond SZ. */
161
162static int
163darwin_rs6000_gt_pch_use_address (void *addr, size_t sz, int fd, size_t off)
164{
165 const size_t pagesize = getpagesize();
166 void *mmap_result;
167 int ret;
168
169 if ((size_t)pch_address_space % pagesize != 0
170 || sizeof (pch_address_space) % pagesize != 0)
171 abort ();
172
173 ret = (addr == pch_address_space && sz <= sizeof (pch_address_space));
174 if (! ret)
175 sz = 0;
176
177 /* Round the size to a whole page size. Normally this is a no-op. */
178 sz = (sz + pagesize - 1) / pagesize * pagesize;
179
180 if (munmap (pch_address_space + sz, sizeof (pch_address_space) - sz) != 0)
181 fatal_error ("couldn't unmap pch_address_space: %m\n");
182
183 if (ret)
184 {
185 mmap_result = mmap (addr, sz,
186 PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_FIXED,
187 fd, off);
188
189 /* The file might not be mmap-able. */
190 ret = mmap_result != (void *) MAP_FAILED;
191
192 /* Sanity check for broken MAP_FIXED. */
193 if (ret && mmap_result != addr)
194 abort ();
195 }
196
197 return ret;
198}
199
200
201const struct host_hooks host_hooks = HOST_HOOKS_INITIALIZER;
2 Copyright (C) 2003, 2004 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 2, or (at your
9 option) any later version.
10
--- 121 unchanged lines hidden (view full) ---
132
133 sigemptyset(&sact.sa_mask);
134 sact.sa_flags = SA_ONSTACK | SA_SIGINFO;
135 sact.sa_sigaction = segv_handler;
136 if (sigaction (SIGSEGV, &sact, 0) < 0)
137 fatal_error ("While setting up signal handler: %m");
138}
139
140#undef HOST_HOOKS_GT_PCH_GET_ADDRESS
141#define HOST_HOOKS_GT_PCH_GET_ADDRESS darwin_rs6000_gt_pch_get_address
142#undef HOST_HOOKS_GT_PCH_USE_ADDRESS
143#define HOST_HOOKS_GT_PCH_USE_ADDRESS darwin_rs6000_gt_pch_use_address
144
145/* Yes, this is really supposed to work. */
146static char pch_address_space[1024*1024*1024] __attribute__((aligned (4096)));
147
148/* Return the address of the PCH address space, if the PCH will fit in it. */
149
150static void *
151darwin_rs6000_gt_pch_get_address (size_t sz, int fd ATTRIBUTE_UNUSED)
152{
153 if (sz <= sizeof (pch_address_space))
154 return pch_address_space;
155 else
156 return NULL;
157}
158
159/* Check ADDR and SZ for validity, and deallocate (using munmap) that part of
160 pch_address_space beyond SZ. */
161
162static int
163darwin_rs6000_gt_pch_use_address (void *addr, size_t sz, int fd, size_t off)
164{
165 const size_t pagesize = getpagesize();
166 void *mmap_result;
167 int ret;
168
169 if ((size_t)pch_address_space % pagesize != 0
170 || sizeof (pch_address_space) % pagesize != 0)
171 abort ();
172
173 ret = (addr == pch_address_space && sz <= sizeof (pch_address_space));
174 if (! ret)
175 sz = 0;
176
177 /* Round the size to a whole page size. Normally this is a no-op. */
178 sz = (sz + pagesize - 1) / pagesize * pagesize;
179
180 if (munmap (pch_address_space + sz, sizeof (pch_address_space) - sz) != 0)
181 fatal_error ("couldn't unmap pch_address_space: %m\n");
182
183 if (ret)
184 {
185 mmap_result = mmap (addr, sz,
186 PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_FIXED,
187 fd, off);
188
189 /* The file might not be mmap-able. */
190 ret = mmap_result != (void *) MAP_FAILED;
191
192 /* Sanity check for broken MAP_FIXED. */
193 if (ret && mmap_result != addr)
194 abort ();
195 }
196
197 return ret;
198}
199
200
201const struct host_hooks host_hooks = HOST_HOOKS_INITIALIZER;