annotate gcc/config/host-openbsd.c @ 131:84e7813d76e9

gcc-8.2
author mir3636
date Thu, 25 Oct 2018 07:37:49 +0900
parents 04ced10e8804
children 1830386684a0
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
111
kono
parents:
diff changeset
1 /* OpenBSD host-specific hook definitions.
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
2 Copyright (C) 2004-2018 Free Software Foundation, Inc.
111
kono
parents:
diff changeset
3
kono
parents:
diff changeset
4 This file is part of GCC.
kono
parents:
diff changeset
5
kono
parents:
diff changeset
6 GCC is free software; you can redistribute it and/or modify it
kono
parents:
diff changeset
7 under the terms of the GNU General Public License as published
kono
parents:
diff changeset
8 by the Free Software Foundation; either version 3, or (at your
kono
parents:
diff changeset
9 option) any later version.
kono
parents:
diff changeset
10
kono
parents:
diff changeset
11 GCC is distributed in the hope that it will be useful, but WITHOUT
kono
parents:
diff changeset
12 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
kono
parents:
diff changeset
13 or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
kono
parents:
diff changeset
14 License for more details.
kono
parents:
diff changeset
15
kono
parents:
diff changeset
16 You should have received a copy of the GNU General Public License
kono
parents:
diff changeset
17 along with GCC; see the file COPYING3. If not see
kono
parents:
diff changeset
18 <http://www.gnu.org/licenses/>. */
kono
parents:
diff changeset
19
kono
parents:
diff changeset
20 #include "config.h"
kono
parents:
diff changeset
21 #include "system.h"
kono
parents:
diff changeset
22 #include "coretypes.h"
kono
parents:
diff changeset
23 #include "hosthooks.h"
kono
parents:
diff changeset
24 #include "hosthooks-def.h"
kono
parents:
diff changeset
25
kono
parents:
diff changeset
26
kono
parents:
diff changeset
27 #undef HOST_HOOKS_GT_PCH_GET_ADDRESS
kono
parents:
diff changeset
28 #define HOST_HOOKS_GT_PCH_GET_ADDRESS openbsd_gt_pch_get_address
kono
parents:
diff changeset
29 #undef HOST_HOOKS_GT_PCH_USE_ADDRESS
kono
parents:
diff changeset
30 #define HOST_HOOKS_GT_PCH_USE_ADDRESS openbsd_gt_pch_use_address
kono
parents:
diff changeset
31
kono
parents:
diff changeset
32 /* For various ports, try to guess a fixed spot in the vm space
kono
parents:
diff changeset
33 that's probably free. */
kono
parents:
diff changeset
34 #if defined(__amd64__)
kono
parents:
diff changeset
35 # define TRY_EMPTY_VM_SPACE 0x400000000000
kono
parents:
diff changeset
36 #elif defined(__hppa__)
kono
parents:
diff changeset
37 # define TRY_EMPTY_VM_SPACE 0xb0000000
kono
parents:
diff changeset
38 #elif defined(__i386__)
kono
parents:
diff changeset
39 # define TRY_EMPTY_VM_SPACE 0xb0000000
kono
parents:
diff changeset
40 #else
kono
parents:
diff changeset
41 # define TRY_EMPTY_VM_SPACE 0
kono
parents:
diff changeset
42 #endif
kono
parents:
diff changeset
43
kono
parents:
diff changeset
44 /* Determine a location where we might be able to reliably allocate
kono
parents:
diff changeset
45 SIZE bytes. FD is the PCH file, though we should return with the
kono
parents:
diff changeset
46 file unmapped. */
kono
parents:
diff changeset
47
kono
parents:
diff changeset
48 static void *
kono
parents:
diff changeset
49 openbsd_gt_pch_get_address (size_t size, int fd)
kono
parents:
diff changeset
50 {
kono
parents:
diff changeset
51 void *addr;
kono
parents:
diff changeset
52
kono
parents:
diff changeset
53 addr = mmap ((void *) TRY_EMPTY_VM_SPACE, size, PROT_READ | PROT_WRITE,
kono
parents:
diff changeset
54 MAP_PRIVATE, fd, 0);
kono
parents:
diff changeset
55
kono
parents:
diff changeset
56 /* If we failed the map, that means there's *no* free space. */
kono
parents:
diff changeset
57 if (addr == (void *) MAP_FAILED)
kono
parents:
diff changeset
58 return NULL;
kono
parents:
diff changeset
59 /* Unmap the area before returning. */
kono
parents:
diff changeset
60 munmap (addr, size);
kono
parents:
diff changeset
61
kono
parents:
diff changeset
62 return addr;
kono
parents:
diff changeset
63 }
kono
parents:
diff changeset
64
kono
parents:
diff changeset
65 /* Map SIZE bytes of FD+OFFSET at BASE. Return 1 if we succeeded at
kono
parents:
diff changeset
66 mapping the data at BASE, -1 if we couldn't. */
kono
parents:
diff changeset
67
kono
parents:
diff changeset
68 static int
kono
parents:
diff changeset
69 openbsd_gt_pch_use_address (void *base, size_t size, int fd, size_t offset)
kono
parents:
diff changeset
70 {
kono
parents:
diff changeset
71 void *addr;
kono
parents:
diff changeset
72
kono
parents:
diff changeset
73 /* We're called with size == 0 if we're not planning to load a PCH
kono
parents:
diff changeset
74 file at all. This allows the hook to free any static space that
kono
parents:
diff changeset
75 we might have allocated at link time. */
kono
parents:
diff changeset
76 if (size == 0)
kono
parents:
diff changeset
77 return -1;
kono
parents:
diff changeset
78
kono
parents:
diff changeset
79 addr = mmap (base, size, PROT_READ | PROT_WRITE, MAP_PRIVATE, fd, offset);
kono
parents:
diff changeset
80
kono
parents:
diff changeset
81 return addr == base ? 1 : -1;
kono
parents:
diff changeset
82 }
kono
parents:
diff changeset
83
kono
parents:
diff changeset
84
kono
parents:
diff changeset
85 const struct host_hooks host_hooks = HOST_HOOKS_INITIALIZER;