1169689Skan/* Cygwin host-specific hook definitions. 2169689Skan Copyright (C) 2004 Free Software Foundation, Inc. 3169689Skan 4169689Skan This file is part of GCC. 5169689Skan 6169689Skan GCC is free software; you can redistribute it and/or modify it 7169689Skan under the terms of the GNU General Public License as published 8169689Skan by the Free Software Foundation; either version 2, or (at your 9169689Skan option) any later version. 10169689Skan 11169689Skan GCC is distributed in the hope that it will be useful, but WITHOUT 12169689Skan ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 13169689Skan or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public 14169689Skan License for more details. 15169689Skan 16169689Skan You should have received a copy of the GNU General Public License 17169689Skan along with GCC; see the file COPYING. If not, write to the 18169689Skan Free Software Foundation, 51 Franklin Street, Fifth Floor, Boston, 19169689Skan MA 02110-1301, USA. */ 20169689Skan 21169689Skan#include "config.h" 22169689Skan#include "system.h" 23169689Skan#include "coretypes.h" 24169689Skan#include <sys/mman.h> 25169689Skan#include "hosthooks.h" 26169689Skan#include "hosthooks-def.h" 27169689Skan#include "toplev.h" 28169689Skan#include "diagnostic.h" 29169689Skan 30169689Skanstatic void * cygwin_gt_pch_get_address (size_t, int fd); 31169689Skanstatic size_t cygwin_gt_pch_alloc_granularity (void); 32169689Skan 33169689Skan#undef HOST_HOOKS_GT_PCH_GET_ADDRESS 34169689Skan#define HOST_HOOKS_GT_PCH_GET_ADDRESS cygwin_gt_pch_get_address 35169689Skan#undef HOST_HOOKS_GT_PCH_ALLOC_GRANULARITY 36169689Skan#define HOST_HOOKS_GT_PCH_ALLOC_GRANULARITY cygwin_gt_pch_alloc_granularity 37169689Skan 38169689Skan/* Granularity for reserving address space. */ 39169689Skanstatic const size_t va_granularity = 0x10000; 40169689Skan 41169689Skan/* Return the alignment required for allocating virtual memory. */ 42169689Skanstatic size_t 43169689Skancygwin_gt_pch_alloc_granularity (void) 44169689Skan{ 45169689Skan return va_granularity; 46169689Skan} 47169689Skan 48169689Skan/* Identify an address that's likely to be free in a subsequent invocation 49169689Skan of the compiler. The area should be able to hold SIZE bytes. FD is an 50169689Skan open file descriptor if the host would like to probe with mmap. */ 51169689Skanstatic void * 52169689Skancygwin_gt_pch_get_address (size_t sz, int fd) 53169689Skan{ 54169689Skan void *base; 55169689Skan off_t p = lseek(fd, 0, SEEK_CUR); 56169689Skan 57169689Skan if (p == (off_t) -1) 58169689Skan fatal_error ("can't get position in PCH file: %m"); 59169689Skan 60169689Skan /* Cygwin requires that the underlying file be at least 61169689Skan as large as the requested mapping. */ 62169689Skan if ((size_t) p < sz) 63169689Skan { 64169689Skan if ( ftruncate (fd, sz) == -1 ) 65169689Skan fatal_error ("can't extend PCH file: %m"); 66169689Skan } 67169689Skan 68169689Skan base = mmap (NULL, sz, PROT_READ | PROT_WRITE, MAP_PRIVATE, fd, 0); 69169689Skan 70169689Skan if (base == MAP_FAILED) 71169689Skan base = NULL; 72169689Skan else 73169689Skan munmap (base, sz); 74169689Skan 75169689Skan if (lseek (fd, p, SEEK_SET) == (off_t) -1 ) 76169689Skan fatal_error ("can't set position in PCH file: %m"); 77169689Skan 78169689Skan return base; 79169689Skan} 80169689Skan 81169689Skanconst struct host_hooks host_hooks = HOST_HOOKS_INITIALIZER; 82