00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 #include "config.h"
00022 #include "system.h"
00023 #include "coretypes.h"
00024 #include <sys/mman.h>
00025 #include "hosthooks.h"
00026 #include "hosthooks-def.h"
00027 #include "toplev.h"
00028 #include "diagnostic.h"
00029
00030 static void * cygwin_gt_pch_get_address (size_t, int fd);
00031 static size_t cygwin_gt_pch_alloc_granularity (void);
00032
00033 #undef HOST_HOOKS_GT_PCH_GET_ADDRESS
00034 #define HOST_HOOKS_GT_PCH_GET_ADDRESS cygwin_gt_pch_get_address
00035 #undef HOST_HOOKS_GT_PCH_ALLOC_GRANULARITY
00036 #define HOST_HOOKS_GT_PCH_ALLOC_GRANULARITY cygwin_gt_pch_alloc_granularity
00037
00038
00039 static const size_t va_granularity = 0x10000;
00040
00041
00042 static size_t
00043 cygwin_gt_pch_alloc_granularity (void)
00044 {
00045 return va_granularity;
00046 }
00047
00048
00049
00050
00051 static void *
00052 cygwin_gt_pch_get_address (size_t sz, int fd)
00053 {
00054 void *base;
00055 off_t p = lseek(fd, 0, SEEK_CUR);
00056
00057 if (p == (off_t) -1)
00058 fatal_error ("can't get position in PCH file: %m");
00059
00060
00061
00062 if ((size_t) p < sz)
00063 {
00064 if ( ftruncate (fd, sz) == -1 )
00065 fatal_error ("can't extend PCH file: %m");
00066 }
00067
00068 base = mmap (NULL, sz, PROT_READ | PROT_WRITE, MAP_PRIVATE, fd, 0);
00069
00070 if (base == MAP_FAILED)
00071 base = NULL;
00072 else
00073 munmap (base, sz);
00074
00075 if (lseek (fd, p, SEEK_SET) == (off_t) -1 )
00076 fatal_error ("can't set position in PCH file: %m");
00077
00078 return base;
00079 }
00080
00081 const struct host_hooks host_hooks = HOST_HOOKS_INITIALIZER;