Annotation of ports/patches/patch-gcc_config_host-openbsd_c, Revision 1.1.1.1
1.1 pascal 1: $OpenBSD: patch-gcc_config_host-openbsd_c,v 1.2 2008/06/12 01:14:06 kurt Exp $
2: --- gcc/config/host-openbsd.c.orig Wed Apr 23 07:42:45 2008
3: +++ gcc/config/host-openbsd.c Wed Apr 23 17:57:19 2008
4: @@ -0,0 +1,107 @@
5: +/* OpenBSD host-specific hook definitions.
6: + Copyright (C) 2005 Free Software Foundation, Inc.
7: +
8: + This file is part of GCC.
9: +
10: + GCC is free software; you can redistribute it and/or modify it
11: + under the terms of the GNU General Public License as published
12: + by the Free Software Foundation; either version 2, or (at your
13: + option) any later version.
14: +
15: + GCC is distributed in the hope that it will be useful, but WITHOUT
16: + ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
17: + or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
18: + License for more details.
19: +
20: + You should have received a copy of the GNU General Public License
21: + along with GCC; see the file COPYING. If not, write to the
22: + Free Software Foundation, 59 Temple Place - Suite 330, Boston,
23: + MA 02111-1307, USA. */
24: +
25: +#include <limits.h>
26: +#include <unistd.h>
27: +
28: +#include "config.h"
29: +#include "system.h"
30: +#include "coretypes.h"
31: +#include "hosthooks.h"
32: +#include "hosthooks-def.h"
33: +
34: +#undef HOST_HOOKS_GT_PCH_GET_ADDRESS
35: +#define HOST_HOOKS_GT_PCH_GET_ADDRESS openbsd_gt_pch_get_address
36: +
37: +#undef HOST_HOOKS_GT_PCH_USE_ADDRESS
38: +#define HOST_HOOKS_GT_PCH_USE_ADDRESS openbsd_gt_pch_use_address
39: +
40: +/* Return the address of the PCH address space, if the PCH will fit in it. */
41: +
42: +void *
43: +openbsd_gt_pch_get_address (size_t size, int fd ATTRIBUTE_UNUSED)
44: +{
45: + void *base, *addr;
46: + size_t pgsz;
47: +
48: + if (size > INT_MAX)
49: + return NULL;
50: +
51: + pgsz = sysconf(_SC_PAGESIZE);
52: + if (pgsz == (size_t)-1)
53: + return NULL;
54: +
55: + base = sbrk(0);
56: +
57: + /* round up to nearest page */
58: + base = (void *)(((long)base + (pgsz - 1)) & ~(pgsz - 1));
59: + if (brk(base) != 0)
60: + return NULL;
61: +
62: + /* attempt to allocate size */
63: + addr = sbrk(size);
64: + if (addr == (void *)-1)
65: + return NULL;
66: +
67: + /* deallocate the memory */
68: + if (brk(base) != 0)
69: + return NULL;
70: +
71: + /* confirm addr is as expected */
72: + if (addr != base)
73: + return NULL;
74: +
75: + return base;
76: +}
77: +
78: +/* Return 0 if we can reserve the PCH address space. */
79: +
80: +int
81: +openbsd_gt_pch_use_address (void *base, size_t size, int fd ATTRIBUTE_UNUSED, size_t off ATTRIBUTE_UNUSED)
82: +{
83: + void *addr;
84: +
85: + if (size == 0)
86: + return -1;
87: +
88: + /* sanity check base address */
89: + addr = sbrk(0);
90: + if (addr == (void *)-1 || base < addr)
91: + return -1;
92: +
93: + /* set base for sbrk */
94: + if (brk(base) != 0)
95: + return -1;
96: +
97: + /* attempt to get the memory */
98: + addr = sbrk(size);
99: + if (addr == (void *)-1)
100: + return -1;
101: +
102: + /* sanity check the result */
103: + if (addr != base) {
104: + brk(base);
105: + return -1;
106: + }
107: +
108: + return 0;
109: +}
110: +
111: +const struct host_hooks host_hooks = HOST_HOOKS_INITIALIZER;