Print this page
11787 Kernel needs to be built with retpolines
11788 Kernel needs to generally use RSB stuffing
Reviewed by: Jerry Jelinek <jerry.jelinek@joyent.com>
Reviewed by: John Levon <john.levon@joyent.com>
Split |
Close |
Expand all |
Collapse all |
--- old/usr/src/uts/intel/ia32/sys/asm_linkage.h
+++ new/usr/src/uts/intel/ia32/sys/asm_linkage.h
1 1 /*
2 2 * CDDL HEADER START
3 3 *
4 4 * The contents of this file are subject to the terms of the
5 5 * Common Development and Distribution License (the "License").
6 6 * You may not use this file except in compliance with the License.
7 7 *
8 8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 9 * or http://www.opensolaris.org/os/licensing.
10 10 * See the License for the specific language governing permissions
11 11 * and limitations under the License.
12 12 *
13 13 * When distributing Covered Code, include this CDDL HEADER in each
14 14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 15 * If applicable, add the following below this CDDL HEADER, with the
16 16 * fields enclosed by brackets "[]" replaced with your own identifying
↓ open down ↓ |
16 lines elided |
↑ open up ↑ |
17 17 * information: Portions Copyright [yyyy] [name of copyright owner]
18 18 *
19 19 * CDDL HEADER END
20 20 */
21 21
22 22 /*
23 23 * Copyright 2008 Sun Microsystems, Inc. All rights reserved.
24 24 * Use is subject to license terms.
25 25 */
26 26
27 +/*
28 + * Copyright 2019 Joyent, Inc.
29 + */
30 +
27 31 #ifndef _IA32_SYS_ASM_LINKAGE_H
28 32 #define _IA32_SYS_ASM_LINKAGE_H
29 33
30 -#pragma ident "%Z%%M% %I% %E% SMI"
31 -
32 34 #include <sys/stack.h>
33 35 #include <sys/trap.h>
34 36
35 37 #ifdef __cplusplus
36 38 extern "C" {
37 39 #endif
38 40
39 41 #ifdef _ASM /* The remainder of this file is only for assembly files */
40 42
41 43 /*
42 44 * make annoying differences in assembler syntax go away
43 45 */
44 46
45 47 /*
46 48 * D16 and A16 are used to insert instructions prefixes; the
47 49 * macros help the assembler code be slightly more portable.
48 50 */
49 51 #if !defined(__GNUC_AS__)
50 52 /*
51 53 * /usr/ccs/bin/as prefixes are parsed as separate instructions
52 54 */
53 55 #define D16 data16;
54 56 #define A16 addr16;
55 57
56 58 /*
57 59 * (There are some weird constructs in constant expressions)
58 60 */
59 61 #define _CONST(const) [const]
60 62 #define _BITNOT(const) -1!_CONST(const)
61 63 #define _MUL(a, b) _CONST(a \* b)
62 64
63 65 #else
64 66 /*
65 67 * Why not use the 'data16' and 'addr16' prefixes .. well, the
66 68 * assembler doesn't quite believe in real mode, and thus argues with
67 69 * us about what we're trying to do.
68 70 */
69 71 #define D16 .byte 0x66;
70 72 #define A16 .byte 0x67;
71 73
72 74 #define _CONST(const) (const)
73 75 #define _BITNOT(const) ~_CONST(const)
74 76 #define _MUL(a, b) _CONST(a * b)
75 77
76 78 #endif
77 79
78 80 /*
79 81 * C pointers are different sizes between i386 and amd64.
80 82 * These constants can be used to compute offsets into pointer arrays.
81 83 */
82 84 #if defined(__amd64)
83 85 #define CLONGSHIFT 3
84 86 #define CLONGSIZE 8
85 87 #define CLONGMASK 7
86 88 #elif defined(__i386)
87 89 #define CLONGSHIFT 2
88 90 #define CLONGSIZE 4
89 91 #define CLONGMASK 3
90 92 #endif
91 93
92 94 /*
93 95 * Since we know we're either ILP32 or LP64 ..
94 96 */
95 97 #define CPTRSHIFT CLONGSHIFT
96 98 #define CPTRSIZE CLONGSIZE
97 99 #define CPTRMASK CLONGMASK
98 100
99 101 #if CPTRSIZE != (1 << CPTRSHIFT) || CLONGSIZE != (1 << CLONGSHIFT)
100 102 #error "inconsistent shift constants"
101 103 #endif
102 104
103 105 #if CPTRMASK != (CPTRSIZE - 1) || CLONGMASK != (CLONGSIZE - 1)
104 106 #error "inconsistent mask constants"
105 107 #endif
106 108
107 109 #define ASM_ENTRY_ALIGN 16
108 110
109 111 /*
110 112 * SSE register alignment and save areas
111 113 */
112 114
113 115 #define XMM_SIZE 16
114 116 #define XMM_ALIGN 16
115 117
116 118 #if defined(__amd64)
117 119
118 120 #define SAVE_XMM_PROLOG(sreg, nreg) \
119 121 subq $_CONST(_MUL(XMM_SIZE, nreg)), %rsp; \
120 122 movq %rsp, sreg
121 123
122 124 #define RSTOR_XMM_EPILOG(sreg, nreg) \
123 125 addq $_CONST(_MUL(XMM_SIZE, nreg)), %rsp
124 126
125 127 #elif defined(__i386)
126 128
127 129 #define SAVE_XMM_PROLOG(sreg, nreg) \
128 130 subl $_CONST(_MUL(XMM_SIZE, nreg) + XMM_ALIGN), %esp; \
129 131 movl %esp, sreg; \
130 132 addl $XMM_ALIGN, sreg; \
131 133 andl $_BITNOT(XMM_ALIGN-1), sreg
132 134
133 135 #define RSTOR_XMM_EPILOG(sreg, nreg) \
134 136 addl $_CONST(_MUL(XMM_SIZE, nreg) + XMM_ALIGN), %esp;
135 137
136 138 #endif /* __i386 */
137 139
138 140 /*
139 141 * profiling causes definitions of the MCOUNT and RTMCOUNT
140 142 * particular to the type
141 143 */
142 144 #ifdef GPROF
143 145
144 146 #define MCOUNT(x) \
145 147 pushl %ebp; \
146 148 movl %esp, %ebp; \
147 149 call _mcount; \
148 150 popl %ebp
149 151
150 152 #endif /* GPROF */
151 153
152 154 #ifdef PROF
153 155
154 156 #define MCOUNT(x) \
155 157 /* CSTYLED */ \
156 158 .lcomm .L_/**/x/**/1, 4, 4; \
157 159 pushl %ebp; \
158 160 movl %esp, %ebp; \
159 161 /* CSTYLED */ \
160 162 movl $.L_/**/x/**/1, %edx; \
161 163 call _mcount; \
162 164 popl %ebp
163 165
164 166 #endif /* PROF */
165 167
166 168 /*
167 169 * if we are not profiling, MCOUNT should be defined to nothing
168 170 */
169 171 #if !defined(PROF) && !defined(GPROF)
170 172 #define MCOUNT(x)
171 173 #endif /* !defined(PROF) && !defined(GPROF) */
172 174
173 175 #define RTMCOUNT(x) MCOUNT(x)
174 176
175 177 /*
176 178 * Macro to define weak symbol aliases. These are similar to the ANSI-C
177 179 * #pragma weak _name = name
178 180 * except a compiler can determine type. The assembler must be told. Hence,
179 181 * the second parameter must be the type of the symbol (i.e.: function,...)
180 182 */
181 183 #define ANSI_PRAGMA_WEAK(sym, stype) \
182 184 /* CSTYLED */ \
183 185 .weak _/**/sym; \
184 186 /* CSTYLED */ \
185 187 .type _/**/sym, @stype; \
186 188 /* CSTYLED */ \
187 189 _/**/sym = sym
188 190
189 191 /*
190 192 * Like ANSI_PRAGMA_WEAK(), but for unrelated names, as in:
191 193 * #pragma weak sym1 = sym2
192 194 */
193 195 #define ANSI_PRAGMA_WEAK2(sym1, sym2, stype) \
194 196 .weak sym1; \
195 197 .type sym1, @stype; \
196 198 sym1 = sym2
197 199
198 200 /*
199 201 * ENTRY provides the standard procedure entry code and an easy way to
200 202 * insert the calls to mcount for profiling. ENTRY_NP is identical, but
201 203 * never calls mcount.
202 204 */
203 205 #define ENTRY(x) \
204 206 .text; \
205 207 .align ASM_ENTRY_ALIGN; \
206 208 .globl x; \
207 209 .type x, @function; \
208 210 x: MCOUNT(x)
209 211
210 212 #define ENTRY_NP(x) \
211 213 .text; \
212 214 .align ASM_ENTRY_ALIGN; \
213 215 .globl x; \
214 216 .type x, @function; \
215 217 x:
216 218
217 219 #define RTENTRY(x) \
218 220 .text; \
219 221 .align ASM_ENTRY_ALIGN; \
220 222 .globl x; \
221 223 .type x, @function; \
222 224 x: RTMCOUNT(x)
223 225
224 226 /*
225 227 * ENTRY2 is identical to ENTRY but provides two labels for the entry point.
226 228 */
227 229 #define ENTRY2(x, y) \
228 230 .text; \
229 231 .align ASM_ENTRY_ALIGN; \
230 232 .globl x, y; \
231 233 .type x, @function; \
232 234 .type y, @function; \
233 235 /* CSTYLED */ \
234 236 x: ; \
235 237 y: MCOUNT(x)
236 238
237 239 #define ENTRY_NP2(x, y) \
238 240 .text; \
239 241 .align ASM_ENTRY_ALIGN; \
240 242 .globl x, y; \
241 243 .type x, @function; \
242 244 .type y, @function; \
243 245 /* CSTYLED */ \
244 246 x: ; \
245 247 y:
246 248
247 249
248 250 /*
249 251 * ALTENTRY provides for additional entry points.
250 252 */
251 253 #define ALTENTRY(x) \
252 254 .globl x; \
253 255 .type x, @function; \
254 256 x:
255 257
256 258 /*
257 259 * DGDEF and DGDEF2 provide global data declarations.
258 260 *
259 261 * DGDEF provides a word aligned word of storage.
260 262 *
261 263 * DGDEF2 allocates "sz" bytes of storage with **NO** alignment. This
262 264 * implies this macro is best used for byte arrays.
263 265 *
264 266 * DGDEF3 allocates "sz" bytes of storage with "algn" alignment.
265 267 */
266 268 #define DGDEF2(name, sz) \
267 269 .data; \
268 270 .globl name; \
269 271 .type name, @object; \
270 272 .size name, sz; \
271 273 name:
272 274
273 275 #define DGDEF3(name, sz, algn) \
274 276 .data; \
275 277 .align algn; \
276 278 .globl name; \
277 279 .type name, @object; \
278 280 .size name, sz; \
279 281 name:
280 282
281 283 #define DGDEF(name) DGDEF3(name, 4, 4)
282 284
283 285 /*
284 286 * SET_SIZE trails a function and set the size for the ELF symbol table.
285 287 */
286 288 #define SET_SIZE(x) \
287 289 .size x, [.-x]
288 290
289 291 /*
290 292 * NWORD provides native word value.
291 293 */
292 294 #if defined(__amd64)
↓ open down ↓ |
251 lines elided |
↑ open up ↑ |
293 295
294 296 /*CSTYLED*/
295 297 #define NWORD quad
296 298
297 299 #elif defined(__i386)
298 300
299 301 #define NWORD long
300 302
301 303 #endif /* __i386 */
302 304
305 +/*
306 + * These macros should be used when making indirect calls in the kernel. They
307 + * will perform a jump or call to the corresponding register in a way that knows
308 + * about retpolines and handles whether such mitigations are enabled or not.
309 + *
310 + * INDIRECT_JMP_REG will jump to named register. INDIRECT_CALL_REG will instead
311 + * do a call. These macros cannot be used to dereference a register. For
312 + * example, if you need to do something that looks like the following:
313 + *
314 + * call *24(%rdi)
315 + * jmp *(%r15)
316 + *
317 + * You must instead first do a movq into the corresponding location. You need to
318 + * be careful to make sure that the register that its loaded into is safe to
319 + * use. Often that register may be saved or used elsewhere so it may not be safe
320 + * to clobber the value. Usually, loading into %rax would be safe. These would
321 + * turn into something like:
322 + *
323 + * movq 24(%rdi), %rdi; INDIRECT_CALL_REG(rdi)
324 + * movq (%r15), %r15; INDIRECT_JMP_REG(r15)
325 + *
326 + * If you are trying to call a global function, then use the following pattern
327 + * (substituting the register in question):
328 + *
329 + * leaq my_favorite_function(%rip), %rax
330 + * INDIRECT_CALL_REG(rax)
331 + *
332 + * If you instead have a function pointer (say gethrtimef for example), then you
333 + * need to do:
334 + *
335 + * movq my_favorite_function_pointer(%rip), %rax
336 + * INDIRECT_CALL_REG(rax)
337 + */
338 +
339 +/* CSTYLED */
340 +#define INDIRECT_JMP_REG(reg) jmp __x86_indirect_thunk_/**/reg;
341 +
342 +/* CSTYLED */
343 +#define INDIRECT_CALL_REG(reg) call __x86_indirect_thunk_/**/reg;
344 +
303 345 #endif /* _ASM */
304 346
305 347 #ifdef __cplusplus
306 348 }
307 349 #endif
308 350
309 351 #endif /* _IA32_SYS_ASM_LINKAGE_H */
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX