diff options
Diffstat (limited to 'gcc/config/rs6000/host-darwin.c')
-rw-r--r-- | gcc/config/rs6000/host-darwin.c | 50 |
1 files changed, 50 insertions, 0 deletions
diff --git a/gcc/config/rs6000/host-darwin.c b/gcc/config/rs6000/host-darwin.c index 7ef7c9aefdc..7e8055690e4 100644 --- a/gcc/config/rs6000/host-darwin.c +++ b/gcc/config/rs6000/host-darwin.c @@ -23,6 +23,7 @@ #include "coretypes.h" #include <signal.h> #include <sys/ucontext.h> +#include <sys/mman.h> #include "hosthooks.h" #include "hosthooks-def.h" #include "toplev.h" @@ -135,5 +136,54 @@ darwin_rs6000_extra_signals (void) if (sigaction (SIGSEGV, &sact, 0) < 0) fatal_error ("While setting up signal handler: %m"); } + +static void * darwin_rs6000_gt_pch_get_address (size_t); +static bool darwin_rs6000_gt_pch_use_address (void *, size_t); + +#undef HOST_HOOKS_GT_PCH_GET_ADDRESS +#define HOST_HOOKS_GT_PCH_GET_ADDRESS darwin_rs6000_gt_pch_get_address +#undef HOST_HOOKS_GT_PCH_USE_ADDRESS +#define HOST_HOOKS_GT_PCH_USE_ADDRESS darwin_rs6000_gt_pch_use_address + + +/* Yes, this is really supposed to work. */ +static char pch_address_space[1024*1024*1024] __attribute__((aligned (4096))); + +/* Return the address of the PCH address space, if the PCH will fit in it. */ + +static void * +darwin_rs6000_gt_pch_get_address (size_t sz) +{ + if (sz <= sizeof (pch_address_space)) + return pch_address_space; + else + return NULL; +} + +/* Check ADDR and SZ for validity, and deallocate (using munmap) that part of + pch_address_space beyond SZ. */ + +static bool +darwin_rs6000_gt_pch_use_address (void *addr, size_t sz) +{ + const size_t pagesize = getpagesize(); + bool result; + + if ((size_t)pch_address_space % pagesize != 0 + || sizeof (pch_address_space) % pagesize != 0) + abort (); + + result = (addr == pch_address_space && sz <= sizeof (pch_address_space)); + if (! result) + sz = 0; + + /* Round the size to a whole page size. Normally this is a no-op. */ + sz = (sz + pagesize - 1) / pagesize * pagesize; + + if (munmap (pch_address_space + sz, sizeof (pch_address_space) - sz) != 0) + fatal_error ("couldn't unmap pch_address_space: %m\n"); + + return result; +} const struct host_hooks host_hooks = HOST_HOOKS_INITIALIZER; |