]> CyberLeo.Net >> Repos - FreeBSD/releng/9.2.git/blob - contrib/gcc/config/i386/host-cygwin.c
- Copy stable/9 to releng/9.2 as part of the 9.2-RELEASE cycle.
[FreeBSD/releng/9.2.git] / contrib / gcc / config / i386 / host-cygwin.c
1 /* Cygwin host-specific hook definitions.
2  Copyright (C) 2004 Free Software Foundation, Inc.
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
8  by the Free Software Foundation; either version 2, or (at your
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
17  along with GCC; see the file COPYING. If not, write to the
18  Free Software Foundation, 51 Franklin Street, Fifth Floor, Boston,
19  MA 02110-1301, USA. */
20
21 #include "config.h"
22 #include "system.h"
23 #include "coretypes.h"
24 #include <sys/mman.h>
25 #include "hosthooks.h"
26 #include "hosthooks-def.h"
27 #include "toplev.h"
28 #include "diagnostic.h"
29
30 static void * cygwin_gt_pch_get_address (size_t, int fd);
31 static size_t cygwin_gt_pch_alloc_granularity (void);
32
33 #undef HOST_HOOKS_GT_PCH_GET_ADDRESS
34 #define HOST_HOOKS_GT_PCH_GET_ADDRESS cygwin_gt_pch_get_address
35 #undef HOST_HOOKS_GT_PCH_ALLOC_GRANULARITY
36 #define HOST_HOOKS_GT_PCH_ALLOC_GRANULARITY cygwin_gt_pch_alloc_granularity
37
38 /* Granularity for reserving address space.  */
39 static const size_t va_granularity = 0x10000;
40
41 /*  Return the alignment required for allocating virtual memory. */
42 static size_t
43 cygwin_gt_pch_alloc_granularity (void)
44 {
45   return va_granularity;
46 }
47
48 /* Identify an address that's likely to be free in a subsequent invocation
49    of the compiler.  The area should be able to hold SIZE bytes.  FD is an
50    open file descriptor if the host would like to probe with mmap.  */
51 static void *
52 cygwin_gt_pch_get_address (size_t sz, int fd)
53 {
54   void *base;
55   off_t p = lseek(fd, 0, SEEK_CUR);
56
57   if (p == (off_t) -1)
58     fatal_error ("can't get position in PCH file: %m");
59
60    /* Cygwin requires that the underlying file be at least
61       as large as the requested mapping.  */
62   if ((size_t) p < sz)
63   { 
64     if ( ftruncate (fd, sz) == -1 )
65       fatal_error ("can't extend PCH file: %m");
66   }
67
68   base = mmap (NULL, sz, PROT_READ | PROT_WRITE, MAP_PRIVATE, fd, 0);
69
70   if (base == MAP_FAILED)
71     base = NULL;
72   else
73     munmap (base, sz);
74
75   if (lseek (fd, p, SEEK_SET) == (off_t) -1 )
76     fatal_error ("can't set position in PCH file: %m");
77
78   return base;
79 }
80
81 const struct host_hooks host_hooks = HOST_HOOKS_INITIALIZER;