]> git.ipfire.org Git - thirdparty/gcc.git/blame - gcc/config/i386/host-cygwin.c
Update copyright years.
[thirdparty/gcc.git] / gcc / config / i386 / host-cygwin.c
CommitLineData
5fa09df4 1/* Cygwin host-specific hook definitions.
8d9254fc 2 Copyright (C) 2004-2020 Free Software Foundation, Inc.
5fa09df4
EC
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
2f83c7d6 8 by the Free Software Foundation; either version 3, or (at your
5fa09df4
EC
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
2f83c7d6
NC
17 along with GCC; see the file COPYING3. If not see
18 <http://www.gnu.org/licenses/>. */
5fa09df4 19
8fcc61f8
RS
20#define IN_TARGET_CODE 1
21
5fa09df4
EC
22#include "config.h"
23#include "system.h"
24#include "coretypes.h"
e11c4407 25#include "diagnostic.h"
5fa09df4
EC
26#include "hosthooks.h"
27#include "hosthooks-def.h"
5fa09df4
EC
28
29static void * cygwin_gt_pch_get_address (size_t, int fd);
30static size_t cygwin_gt_pch_alloc_granularity (void);
31
32#undef HOST_HOOKS_GT_PCH_GET_ADDRESS
33#define HOST_HOOKS_GT_PCH_GET_ADDRESS cygwin_gt_pch_get_address
34#undef HOST_HOOKS_GT_PCH_ALLOC_GRANULARITY
35#define HOST_HOOKS_GT_PCH_ALLOC_GRANULARITY cygwin_gt_pch_alloc_granularity
36
37/* Granularity for reserving address space. */
38static const size_t va_granularity = 0x10000;
39
40/* Return the alignment required for allocating virtual memory. */
41static size_t
42cygwin_gt_pch_alloc_granularity (void)
43{
44 return va_granularity;
45}
46
47/* Identify an address that's likely to be free in a subsequent invocation
48 of the compiler. The area should be able to hold SIZE bytes. FD is an
49 open file descriptor if the host would like to probe with mmap. */
50static void *
51cygwin_gt_pch_get_address (size_t sz, int fd)
52{
53 void *base;
54 off_t p = lseek(fd, 0, SEEK_CUR);
55
56 if (p == (off_t) -1)
40fecdd6 57 fatal_error (input_location, "can%'t get position in PCH file: %m");
5fa09df4
EC
58
59 /* Cygwin requires that the underlying file be at least
60 as large as the requested mapping. */
61 if ((size_t) p < sz)
62 {
63 if ( ftruncate (fd, sz) == -1 )
40fecdd6 64 fatal_error (input_location, "can%'t extend PCH file: %m");
5fa09df4
EC
65 }
66
67 base = mmap (NULL, sz, PROT_READ | PROT_WRITE, MAP_PRIVATE, fd, 0);
68
69 if (base == MAP_FAILED)
70 base = NULL;
71 else
72 munmap (base, sz);
73
74 if (lseek (fd, p, SEEK_SET) == (off_t) -1 )
40fecdd6 75 fatal_error (input_location, "can%'t set position in PCH file: %m");
5fa09df4
EC
76
77 return base;
78}
79
80const struct host_hooks host_hooks = HOST_HOOKS_INITIALIZER;