1/* Darwin/powerpc host-specific hook definitions.
2 Copyright (C) 2003 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
140static void * darwin_rs6000_gt_pch_get_address (size_t);
141static bool darwin_rs6000_gt_pch_use_address (void *, size_t);
142
143#undef HOST_HOOKS_GT_PCH_GET_ADDRESS
144#define HOST_HOOKS_GT_PCH_GET_ADDRESS darwin_rs6000_gt_pch_get_address
145#undef HOST_HOOKS_GT_PCH_USE_ADDRESS
146#define HOST_HOOKS_GT_PCH_USE_ADDRESS darwin_rs6000_gt_pch_use_address
147
148
149/* Yes, this is really supposed to work. */
150static char pch_address_space[1024*1024*1024] __attribute__((aligned (4096)));
151
152/* Return the address of the PCH address space, if the PCH will fit in it. */
153
154static void *
155darwin_rs6000_gt_pch_get_address (size_t sz)
156{
157 if (sz <= sizeof (pch_address_space))
158 return pch_address_space;
159 else
160 return NULL;
161}
162
163/* Check ADDR and SZ for validity, and deallocate (using munmap) that part of
164 pch_address_space beyond SZ. */
165
166static bool
167darwin_rs6000_gt_pch_use_address (void *addr, size_t sz)
168{
169 const size_t pagesize = getpagesize();
170 bool result;
171
172 if ((size_t)pch_address_space % pagesize != 0
173 || sizeof (pch_address_space) % pagesize != 0)
174 abort ();
175
176 result = (addr == pch_address_space && sz <= sizeof (pch_address_space));
177 if (! result)
178 sz = 0;
179
180 /* Round the size to a whole page size. Normally this is a no-op. */
181 sz = (sz + pagesize - 1) / pagesize * pagesize;
182
183 if (munmap (pch_address_space + sz, sizeof (pch_address_space) - sz) != 0)
184 fatal_error ("couldn't unmap pch_address_space: %m\n");
185
186 return result;
187}
188
189const struct host_hooks host_hooks = HOST_HOOKS_INITIALIZER;
2 Copyright (C) 2003 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
140static void * darwin_rs6000_gt_pch_get_address (size_t);
141static bool darwin_rs6000_gt_pch_use_address (void *, size_t);
142
143#undef HOST_HOOKS_GT_PCH_GET_ADDRESS
144#define HOST_HOOKS_GT_PCH_GET_ADDRESS darwin_rs6000_gt_pch_get_address
145#undef HOST_HOOKS_GT_PCH_USE_ADDRESS
146#define HOST_HOOKS_GT_PCH_USE_ADDRESS darwin_rs6000_gt_pch_use_address
147
148
149/* Yes, this is really supposed to work. */
150static char pch_address_space[1024*1024*1024] __attribute__((aligned (4096)));
151
152/* Return the address of the PCH address space, if the PCH will fit in it. */
153
154static void *
155darwin_rs6000_gt_pch_get_address (size_t sz)
156{
157 if (sz <= sizeof (pch_address_space))
158 return pch_address_space;
159 else
160 return NULL;
161}
162
163/* Check ADDR and SZ for validity, and deallocate (using munmap) that part of
164 pch_address_space beyond SZ. */
165
166static bool
167darwin_rs6000_gt_pch_use_address (void *addr, size_t sz)
168{
169 const size_t pagesize = getpagesize();
170 bool result;
171
172 if ((size_t)pch_address_space % pagesize != 0
173 || sizeof (pch_address_space) % pagesize != 0)
174 abort ();
175
176 result = (addr == pch_address_space && sz <= sizeof (pch_address_space));
177 if (! result)
178 sz = 0;
179
180 /* Round the size to a whole page size. Normally this is a no-op. */
181 sz = (sz + pagesize - 1) / pagesize * pagesize;
182
183 if (munmap (pch_address_space + sz, sizeof (pch_address_space) - sz) != 0)
184 fatal_error ("couldn't unmap pch_address_space: %m\n");
185
186 return result;
187}
188
189const struct host_hooks host_hooks = HOST_HOOKS_INITIALIZER;