host-solaris.c 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. /* Solaris host-specific hook definitions.
  2. Copyright (C) 2004-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 "hosthooks.h"
  19. #include "hosthooks-def.h"
  20. #undef HOST_HOOKS_GT_PCH_GET_ADDRESS
  21. #define HOST_HOOKS_GT_PCH_GET_ADDRESS sol_gt_pch_get_address
  22. #undef HOST_HOOKS_GT_PCH_USE_ADDRESS
  23. #define HOST_HOOKS_GT_PCH_USE_ADDRESS sol_gt_pch_use_address
  24. /* Before Solaris 11, the mmap ADDR parameter is mostly ignored without
  25. MAP_FIXED set. Before we give up, search the desired address space with
  26. mincore to see if the space is really free. */
  27. static void *
  28. mmap_fixed (void *addr, size_t len, int prot, int flags, int fd, off_t off)
  29. {
  30. void *base;
  31. base = mmap ((caddr_t) addr, len, prot, flags, fd, off);
  32. if (base != addr)
  33. {
  34. size_t page_size = getpagesize();
  35. char one_byte;
  36. size_t i;
  37. if (base != (void *) MAP_FAILED)
  38. munmap ((caddr_t) base, len);
  39. errno = 0;
  40. for (i = 0; i < len; i += page_size)
  41. if (mincore ((char *)addr + i, page_size, (char *) &one_byte) == -1
  42. && errno == ENOMEM)
  43. continue; /* The page is not mapped. */
  44. else
  45. break;
  46. if (i >= len)
  47. base = mmap ((caddr_t) addr, len, prot, flags | MAP_FIXED, fd, off);
  48. }
  49. return base;
  50. }
  51. /* For various ports, try to guess a fixed spot in the vm space
  52. that's probably free. Based on McDougall, Mauro, Solaris Internals, 2nd
  53. ed., p.460-461, fig. 9-3, 9-4, 9-5. */
  54. #if defined(__sparcv9__)
  55. /* This low to avoid VA hole on UltraSPARC I/II. */
  56. # define TRY_EMPTY_VM_SPACE 0x70000000000
  57. #elif defined(__sparc__)
  58. # define TRY_EMPTY_VM_SPACE 0x80000000
  59. #elif defined(__x86_64__)
  60. # define TRY_EMPTY_VM_SPACE 0x80000000000
  61. #elif defined(__i386__)
  62. # define TRY_EMPTY_VM_SPACE 0xB0000000
  63. #else
  64. # define TRY_EMPTY_VM_SPACE 0
  65. #endif
  66. /* Determine a location where we might be able to reliably allocate
  67. SIZE bytes. FD is the PCH file, though we should return with the
  68. file unmapped. */
  69. static void *
  70. sol_gt_pch_get_address (size_t size, int fd)
  71. {
  72. void *addr;
  73. addr = mmap_fixed ((caddr_t) TRY_EMPTY_VM_SPACE, size,
  74. PROT_READ | PROT_WRITE, MAP_PRIVATE, fd, 0);
  75. /* If we failed the map, that means there's *no* free space. */
  76. if (addr == (void *) MAP_FAILED)
  77. return NULL;
  78. /* Unmap the area before returning. */
  79. munmap ((caddr_t) addr, size);
  80. return addr;
  81. }
  82. /* Map SIZE bytes of FD+OFFSET at BASE. Return 1 if we succeeded at
  83. mapping the data at BASE, -1 if we couldn't. */
  84. static int
  85. sol_gt_pch_use_address (void *base, size_t size, int fd, size_t offset)
  86. {
  87. void *addr;
  88. /* We're called with size == 0 if we're not planning to load a PCH
  89. file at all. This allows the hook to free any static space that
  90. we might have allocated at link time. */
  91. if (size == 0)
  92. return -1;
  93. addr = mmap_fixed ((caddr_t) base, size,
  94. PROT_READ | PROT_WRITE, MAP_PRIVATE, fd, offset);
  95. return addr == base ? 1 : -1;
  96. }
  97. const struct host_hooks host_hooks = HOST_HOOKS_INITIALIZER;