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>


   7  *
   8  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
   9  * or http://www.opensolaris.org/os/licensing.
  10  * See the License for the specific language governing permissions
  11  * and limitations under the License.
  12  *
  13  * When distributing Covered Code, include this CDDL HEADER in each
  14  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
  15  * If applicable, add the following below this CDDL HEADER, with the
  16  * fields enclosed by brackets "[]" replaced with your own identifying
  17  * information: Portions Copyright [yyyy] [name of copyright owner]
  18  *
  19  * CDDL HEADER END
  20  */
  21 
  22 /*
  23  * Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
  24  * Use is subject to license terms.
  25  */
  26 




  27 #ifndef _IA32_SYS_ASM_LINKAGE_H
  28 #define _IA32_SYS_ASM_LINKAGE_H
  29 
  30 #pragma ident   "%Z%%M% %I%     %E% SMI"
  31 
  32 #include <sys/stack.h>
  33 #include <sys/trap.h>
  34 
  35 #ifdef  __cplusplus
  36 extern "C" {
  37 #endif
  38 
  39 #ifdef _ASM     /* The remainder of this file is only for assembly files */
  40 
  41 /*
  42  * make annoying differences in assembler syntax go away
  43  */
  44 
  45 /*
  46  * D16 and A16 are used to insert instructions prefixes; the
  47  * macros help the assembler code be slightly more portable.
  48  */
  49 #if !defined(__GNUC_AS__)
  50 /*
  51  * /usr/ccs/bin/as prefixes are parsed as separate instructions


 283 /*
 284  * SET_SIZE trails a function and set the size for the ELF symbol table.
 285  */
 286 #define SET_SIZE(x) \
 287         .size   x, [.-x]
 288 
 289 /*
 290  * NWORD provides native word value.
 291  */
 292 #if defined(__amd64)
 293 
 294 /*CSTYLED*/
 295 #define NWORD   quad
 296 
 297 #elif defined(__i386)
 298 
 299 #define NWORD   long
 300 
 301 #endif  /* __i386 */
 302 








































 303 #endif /* _ASM */
 304 
 305 #ifdef  __cplusplus
 306 }
 307 #endif
 308 
 309 #endif  /* _IA32_SYS_ASM_LINKAGE_H */


   7  *
   8  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
   9  * or http://www.opensolaris.org/os/licensing.
  10  * See the License for the specific language governing permissions
  11  * and limitations under the License.
  12  *
  13  * When distributing Covered Code, include this CDDL HEADER in each
  14  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
  15  * If applicable, add the following below this CDDL HEADER, with the
  16  * fields enclosed by brackets "[]" replaced with your own identifying
  17  * information: Portions Copyright [yyyy] [name of copyright owner]
  18  *
  19  * CDDL HEADER END
  20  */
  21 
  22 /*
  23  * Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
  24  * Use is subject to license terms.
  25  */
  26 
  27 /*
  28  * Copyright 2019 Joyent, Inc.
  29  */
  30 
  31 #ifndef _IA32_SYS_ASM_LINKAGE_H
  32 #define _IA32_SYS_ASM_LINKAGE_H
  33 


  34 #include <sys/stack.h>
  35 #include <sys/trap.h>
  36 
  37 #ifdef  __cplusplus
  38 extern "C" {
  39 #endif
  40 
  41 #ifdef _ASM     /* The remainder of this file is only for assembly files */
  42 
  43 /*
  44  * make annoying differences in assembler syntax go away
  45  */
  46 
  47 /*
  48  * D16 and A16 are used to insert instructions prefixes; the
  49  * macros help the assembler code be slightly more portable.
  50  */
  51 #if !defined(__GNUC_AS__)
  52 /*
  53  * /usr/ccs/bin/as prefixes are parsed as separate instructions


 285 /*
 286  * SET_SIZE trails a function and set the size for the ELF symbol table.
 287  */
 288 #define SET_SIZE(x) \
 289         .size   x, [.-x]
 290 
 291 /*
 292  * NWORD provides native word value.
 293  */
 294 #if defined(__amd64)
 295 
 296 /*CSTYLED*/
 297 #define NWORD   quad
 298 
 299 #elif defined(__i386)
 300 
 301 #define NWORD   long
 302 
 303 #endif  /* __i386 */
 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 
 345 #endif /* _ASM */
 346 
 347 #ifdef  __cplusplus
 348 }
 349 #endif
 350 
 351 #endif  /* _IA32_SYS_ASM_LINKAGE_H */