host-darwin.c 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. /* Darwin host-specific hook definitions.
  2. Copyright (C) 2003-2015 Free Software Foundation, Inc.
  3. This file is part of GCC.
  4. GCC is free software; you can redistribute it and/or modify it
  5. under the terms of the GNU General Public License as published
  6. by the Free Software Foundation; either version 3, or (at your
  7. option) any later version.
  8. GCC is distributed in the hope that it will be useful, but WITHOUT
  9. ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
  10. or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
  11. License for more details.
  12. You should have received a copy of the GNU General Public License
  13. along with GCC; see the file COPYING3. If not see
  14. <http://www.gnu.org/licenses/>. */
  15. #include "config.h"
  16. #include "system.h"
  17. #include "coretypes.h"
  18. #include "diagnostic-core.h"
  19. #include "config/host-darwin.h"
  20. /* Yes, this is really supposed to work. */
  21. static char pch_address_space[1024*1024*1024] __attribute__((aligned (4096)));
  22. /* Return the address of the PCH address space, if the PCH will fit in it. */
  23. void *
  24. darwin_gt_pch_get_address (size_t sz, int fd ATTRIBUTE_UNUSED)
  25. {
  26. if (sz <= sizeof (pch_address_space))
  27. return pch_address_space;
  28. else
  29. return NULL;
  30. }
  31. /* Check ADDR and SZ for validity, and deallocate (using munmap) that part of
  32. pch_address_space beyond SZ. */
  33. int
  34. darwin_gt_pch_use_address (void *addr, size_t sz, int fd, size_t off)
  35. {
  36. const size_t pagesize = getpagesize();
  37. void *mmap_result;
  38. int ret;
  39. gcc_assert ((size_t)pch_address_space % pagesize == 0
  40. && sizeof (pch_address_space) % pagesize == 0);
  41. ret = (addr == pch_address_space && sz <= sizeof (pch_address_space));
  42. if (! ret)
  43. sz = 0;
  44. /* Round the size to a whole page size. Normally this is a no-op. */
  45. sz = (sz + pagesize - 1) / pagesize * pagesize;
  46. if (munmap (pch_address_space + sz, sizeof (pch_address_space) - sz) != 0)
  47. fatal_error (input_location, "couldn%'t unmap pch_address_space: %m");
  48. if (ret)
  49. {
  50. mmap_result = mmap (addr, sz,
  51. PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_FIXED,
  52. fd, off);
  53. /* The file might not be mmap-able. */
  54. ret = mmap_result != (void *) MAP_FAILED;
  55. /* Sanity check for broken MAP_FIXED. */
  56. gcc_assert (!ret || mmap_result == addr);
  57. }
  58. return ret;
  59. }