aboutsummaryrefslogtreecommitdiffstats
path: root/main/musl/0003-reduce-impact-of-REG_-namespace-pollution-in-x86-_64.patch
blob: da727113c1209e5a234309226c48865aa627b26b (plain)
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
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
From 150747b41e1ecefe82aa45d68c84b9e957b03e29 Mon Sep 17 00:00:00 2001
From: Rich Felker <dalias@aerifal.cx>
Date: Wed, 4 Jan 2017 17:08:19 -0500
Subject: [PATCH] reduce impact of REG_* namespace pollution in x86[_64]
 signal.h

when _GNU_SOURCE is defined, which is always the case when compiling
c++ with gcc, these macros for the the indices in gregset_t are
exposed and likely to clash with applications. by using enum constants
rather than macros defined with integer literals, we can make the
clash slightly less likely to break software. the macros are still
defined in case anything checks for them with #ifdef, but they're
defined to expand to themselves so that non-file-scope (e.g.
namespaced) identifiers by the same names still work.

for the sake of avoiding mistakes, the changes were generated with sed
via the command:

sed -i -e 's/#define  *\(REG_[A-Z_0-9]\{1,\}\)  *\([0-9]\{1,\}\)'\
'/enum { \1 = \2 };\n#define \1 \1/' \
arch/i386/bits/signal.h arch/x86_64/bits/signal.h arch/x32/bits/signal.h
---
 arch/i386/bits/signal.h   | 57 ++++++++++++++++++++++++++-------------
 arch/x32/bits/signal.h    | 69 +++++++++++++++++++++++++++++++----------------
 arch/x86_64/bits/signal.h | 69 +++++++++++++++++++++++++++++++----------------
 3 files changed, 130 insertions(+), 65 deletions(-)

diff --git a/arch/i386/bits/signal.h b/arch/i386/bits/signal.h
index 1f9085a5..9931ee93 100644
--- a/arch/i386/bits/signal.h
+++ b/arch/i386/bits/signal.h
@@ -7,25 +7,44 @@
 #endif
 
 #ifdef _GNU_SOURCE
-#define REG_GS          0
-#define REG_FS          1
-#define REG_ES          2
-#define REG_DS          3
-#define REG_EDI         4
-#define REG_ESI         5
-#define REG_EBP         6
-#define REG_ESP         7
-#define REG_EBX         8
-#define REG_EDX         9
-#define REG_ECX         10
-#define REG_EAX         11
-#define REG_TRAPNO      12
-#define REG_ERR         13
-#define REG_EIP         14
-#define REG_CS          15
-#define REG_EFL         16
-#define REG_UESP        17
-#define REG_SS          18
+enum { REG_GS = 0 };
+#define REG_GS REG_GS
+enum { REG_FS = 1 };
+#define REG_FS REG_FS
+enum { REG_ES = 2 };
+#define REG_ES REG_ES
+enum { REG_DS = 3 };
+#define REG_DS REG_DS
+enum { REG_EDI = 4 };
+#define REG_EDI REG_EDI
+enum { REG_ESI = 5 };
+#define REG_ESI REG_ESI
+enum { REG_EBP = 6 };
+#define REG_EBP REG_EBP
+enum { REG_ESP = 7 };
+#define REG_ESP REG_ESP
+enum { REG_EBX = 8 };
+#define REG_EBX REG_EBX
+enum { REG_EDX = 9 };
+#define REG_EDX REG_EDX
+enum { REG_ECX = 10 };
+#define REG_ECX REG_ECX
+enum { REG_EAX = 11 };
+#define REG_EAX REG_EAX
+enum { REG_TRAPNO = 12 };
+#define REG_TRAPNO REG_TRAPNO
+enum { REG_ERR = 13 };
+#define REG_ERR REG_ERR
+enum { REG_EIP = 14 };
+#define REG_EIP REG_EIP
+enum { REG_CS = 15 };
+#define REG_CS REG_CS
+enum { REG_EFL = 16 };
+#define REG_EFL REG_EFL
+enum { REG_UESP = 17 };
+#define REG_UESP REG_UESP
+enum { REG_SS = 18 };
+#define REG_SS REG_SS
 #endif
 
 #if defined(_GNU_SOURCE) || defined(_BSD_SOURCE)
diff --git a/arch/x32/bits/signal.h b/arch/x32/bits/signal.h
index 4c4adf31..097be6f4 100644
--- a/arch/x32/bits/signal.h
+++ b/arch/x32/bits/signal.h
@@ -7,29 +7,52 @@
 #endif
 
 #ifdef _GNU_SOURCE
-#define REG_R8          0
-#define REG_R9          1
-#define REG_R10         2
-#define REG_R11         3
-#define REG_R12         4
-#define REG_R13         5
-#define REG_R14         6
-#define REG_R15         7
-#define REG_RDI         8
-#define REG_RSI         9
-#define REG_RBP         10
-#define REG_RBX         11
-#define REG_RDX         12
-#define REG_RAX         13
-#define REG_RCX         14
-#define REG_RSP         15
-#define REG_RIP         16
-#define REG_EFL         17
-#define REG_CSGSFS      18
-#define REG_ERR         19
-#define REG_TRAPNO      20
-#define REG_OLDMASK     21
-#define REG_CR2         22
+enum { REG_R8 = 0 };
+#define REG_R8 REG_R8
+enum { REG_R9 = 1 };
+#define REG_R9 REG_R9
+enum { REG_R10 = 2 };
+#define REG_R10 REG_R10
+enum { REG_R11 = 3 };
+#define REG_R11 REG_R11
+enum { REG_R12 = 4 };
+#define REG_R12 REG_R12
+enum { REG_R13 = 5 };
+#define REG_R13 REG_R13
+enum { REG_R14 = 6 };
+#define REG_R14 REG_R14
+enum { REG_R15 = 7 };
+#define REG_R15 REG_R15
+enum { REG_RDI = 8 };
+#define REG_RDI REG_RDI
+enum { REG_RSI = 9 };
+#define REG_RSI REG_RSI
+enum { REG_RBP = 10 };
+#define REG_RBP REG_RBP
+enum { REG_RBX = 11 };
+#define REG_RBX REG_RBX
+enum { REG_RDX = 12 };
+#define REG_RDX REG_RDX
+enum { REG_RAX = 13 };
+#define REG_RAX REG_RAX
+enum { REG_RCX = 14 };
+#define REG_RCX REG_RCX
+enum { REG_RSP = 15 };
+#define REG_RSP REG_RSP
+enum { REG_RIP = 16 };
+#define REG_RIP REG_RIP
+enum { REG_EFL = 17 };
+#define REG_EFL REG_EFL
+enum { REG_CSGSFS = 18 };
+#define REG_CSGSFS REG_CSGSFS
+enum { REG_ERR = 19 };
+#define REG_ERR REG_ERR
+enum { REG_TRAPNO = 20 };
+#define REG_TRAPNO REG_TRAPNO
+enum { REG_OLDMASK = 21 };
+#define REG_OLDMASK REG_OLDMASK
+enum { REG_CR2 = 22 };
+#define REG_CR2 REG_CR2
 #endif
 
 #if defined(_GNU_SOURCE) || defined(_BSD_SOURCE)
diff --git a/arch/x86_64/bits/signal.h b/arch/x86_64/bits/signal.h
index e3c31417..c99317d3 100644
--- a/arch/x86_64/bits/signal.h
+++ b/arch/x86_64/bits/signal.h
@@ -7,29 +7,52 @@
 #endif
 
 #ifdef _GNU_SOURCE
-#define REG_R8          0
-#define REG_R9          1
-#define REG_R10         2
-#define REG_R11         3
-#define REG_R12         4
-#define REG_R13         5
-#define REG_R14         6
-#define REG_R15         7
-#define REG_RDI         8
-#define REG_RSI         9
-#define REG_RBP         10
-#define REG_RBX         11
-#define REG_RDX         12
-#define REG_RAX         13
-#define REG_RCX         14
-#define REG_RSP         15
-#define REG_RIP         16
-#define REG_EFL         17
-#define REG_CSGSFS      18
-#define REG_ERR         19
-#define REG_TRAPNO      20
-#define REG_OLDMASK     21
-#define REG_CR2         22
+enum { REG_R8 = 0 };
+#define REG_R8 REG_R8
+enum { REG_R9 = 1 };
+#define REG_R9 REG_R9
+enum { REG_R10 = 2 };
+#define REG_R10 REG_R10
+enum { REG_R11 = 3 };
+#define REG_R11 REG_R11
+enum { REG_R12 = 4 };
+#define REG_R12 REG_R12
+enum { REG_R13 = 5 };
+#define REG_R13 REG_R13
+enum { REG_R14 = 6 };
+#define REG_R14 REG_R14
+enum { REG_R15 = 7 };
+#define REG_R15 REG_R15
+enum { REG_RDI = 8 };
+#define REG_RDI REG_RDI
+enum { REG_RSI = 9 };
+#define REG_RSI REG_RSI
+enum { REG_RBP = 10 };
+#define REG_RBP REG_RBP
+enum { REG_RBX = 11 };
+#define REG_RBX REG_RBX
+enum { REG_RDX = 12 };
+#define REG_RDX REG_RDX
+enum { REG_RAX = 13 };
+#define REG_RAX REG_RAX
+enum { REG_RCX = 14 };
+#define REG_RCX REG_RCX
+enum { REG_RSP = 15 };
+#define REG_RSP REG_RSP
+enum { REG_RIP = 16 };
+#define REG_RIP REG_RIP
+enum { REG_EFL = 17 };
+#define REG_EFL REG_EFL
+enum { REG_CSGSFS = 18 };
+#define REG_CSGSFS REG_CSGSFS
+enum { REG_ERR = 19 };
+#define REG_ERR REG_ERR
+enum { REG_TRAPNO = 20 };
+#define REG_TRAPNO REG_TRAPNO
+enum { REG_OLDMASK = 21 };
+#define REG_OLDMASK REG_OLDMASK
+enum { REG_CR2 = 22 };
+#define REG_CR2 REG_CR2
 #endif
 
 #if defined(_GNU_SOURCE) || defined(_BSD_SOURCE)
-- 
2.11.0