1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
|
/* This file is derived from gcc-2.6.3/libgcc2.c, section L_trampoline */
/* Copyright (C) 1989, 1992, 1993, 1994 Free Software Foundation, Inc.
This file is part of GNU CC.
GNU CC is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2, or (at your option)
any later version.
GNU CC is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with GNU CC; see the file COPYING. If not, write to
the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */
/* Jump to a trampoline, loading the static chain address. */
#if defined (__alpha__)
void
__enable_execute_stack (addr)
void *addr;
{
long size = getpagesize ();
long mask = ~(size-1);
char *page = (char *) (((long) addr) & mask);
char *end = (char *) ((((long) (addr + TRAMPOLINE_SIZE)) & mask) + size);
/* 7 is PROT_READ | PROT_WRITE | PROT_EXEC */
if (mprotect (page, end - page, 7) < 0)
perror ("mprotect of trampoline code");
}
#endif
#if defined (NeXT) && defined (__MACH__)
/* Make stack executable so we can call trampolines on stack.
This is called from INITIALIZE_TRAMPOLINE in next.h. */
#ifdef NeXTStep21
#include <mach.h>
|
|
|
|
|
<
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
|
/* This file is derived from the GCC sources. */
/* Copyright (C) 1989-2006 Free Software Foundation, Inc.
This file is part of GNU CC.
GNU CC is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2, or (at your option)
any later version.
GNU CC is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with GNU CC; see the file COPYING. If not, write to
the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */
/* Taken from gcc-4.1.0/gcc/config/alpha/osf.h. */
#if defined (__alpha__)
void
__enable_execute_stack (void *addr)
{
long size = getpagesize ();
long mask = ~(size-1);
char *page = (char *) (((long) addr) & mask);
char *end = (char *) ((((long) (addr + TRAMPOLINE_SIZE)) & mask) + size);
/* 7 is PROT_READ | PROT_WRITE | PROT_EXEC */
if (mprotect (page, end - page, 7) < 0)
perror ("mprotect of trampoline code");
}
#endif
/* Taken from gcc-4.1.0/gcc/config/sparc/freebsd.h. */
#if defined (__sparc__)
extern int sysctlbyname(const char *, void *, size_t *, void *, size_t);
static int need_enable_exec_stack;
static void check_enabling(void) __attribute__ ((constructor));
static void check_enabling(void)
{
int prot = 0;
size_t len = sizeof(prot);
sysctlbyname ("kern.stackprot", &prot, &len, NULL, 0);
if (prot != 7)
need_enable_exec_stack = 1;
}
void __enable_execute_stack (void *addr)
{
if (!need_enable_exec_stack)
return;
else {
/* 7 is PROT_READ | PROT_WRITE | PROT_EXEC */
if (mprotect (addr, TRAMPOLINE_SIZE, 7) < 0)
perror ("mprotect of trampoline code");
}
}
#endif
/* Taken from gcc-4.1.0/gcc/config/sol2.h. */
#if (defined (__sparc__) || defined (__i386__)) && defined(__svr4__) && defined(__sun)
extern long sysconf(int);
static int need_enable_exec_stack;
static void check_enabling(void) __attribute__ ((constructor));
static void check_enabling(void)
{
int prot = (int) sysconf(515 /* _SC_STACK_PROT */);
if (prot != 7 /* STACK_PROT_RWX */)
need_enable_exec_stack = 1;
}
void
__enable_execute_stack (void *addr)
{
if (!need_enable_exec_stack)
return;
else {
long size = getpagesize ();
long mask = ~(size-1);
char *page = (char *) (((long) addr) & mask);
char *end = (char *) ((((long) (addr + TRAMPOLINE_SIZE)) & mask) + size);
if (mprotect (page, end - page, 7 /* STACK_PROT_RWX */) < 0)
perror ("mprotect of trampoline code");
}
}
#endif
/* Taken from gcc-4.1.0/gcc/config/openbsd.h. */
#if defined (__OpenBSD__)
/* Stack is explicitly denied execution rights on OpenBSD platforms. */
void
__enable_execute_stack (void *addr)
{
long size = getpagesize ();
long mask = ~(size-1);
char *page = (char *) (((long) addr) & mask);
char *end = (char *) ((((long) (addr + TRAMPOLINE_SIZE)) & mask) + size);
if (mprotect (page, end - page, PROT_READ | PROT_WRITE | PROT_EXEC) < 0)
perror ("mprotect of trampoline code");
}
#endif
/* Taken from gcc-4.1.0/gcc/config/netbsd.h. */
#if defined (__NetBSD__)
extern int __sysctl (int *, unsigned int, void *, size_t *, void *, size_t);
void
__enable_execute_stack (void *addr)
{
static int size;
static long mask;
char *page, *end;
if (size == 0)
{
int mib[2];
size_t len;
mib[0] = 6; /* CTL_HW */
mib[1] = 7; /* HW_PAGESIZE */
len = sizeof (size);
(void) __sysctl (mib, 2, &size, &len, NULL, 0);
mask = ~((long) size - 1);
}
page = (char *) (((long) addr) & mask);
end = (char *) ((((long) (addr + TRAMPOLINE_SIZE)) & mask) + size);
/* 7 == PROT_READ | PROT_WRITE | PROT_EXEC */
(void) mprotect (page, end - page, 7);
}
#endif
/* The rest is taken from gcc-2.6.3/libgcc2.c. */
#if defined (NeXT) && defined (__MACH__)
/* Make stack executable so we can call trampolines on stack.
This is called from INITIALIZE_TRAMPOLINE in next.h. */
#ifdef NeXTStep21
#include <mach.h>
|