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