brintos

brintos / linux-shallow public Read only

0
0
Text · 4.9 KiB · b3b8d3d Raw
175 lines · c
1/* SPDX-License-Identifier: GPL-2.0 */2#ifndef _LINUX_OBJTOOL_H3#define _LINUX_OBJTOOL_H4 5#include <linux/objtool_types.h>6 7#ifdef CONFIG_OBJTOOL8 9#include <asm/asm.h>10 11#ifndef __ASSEMBLY__12 13#define UNWIND_HINT(type, sp_reg, sp_offset, signal)	\14	"987: \n\t"						\15	".pushsection .discard.unwind_hints\n\t"		\16	/* struct unwind_hint */				\17	".long 987b - .\n\t"					\18	".short " __stringify(sp_offset) "\n\t"			\19	".byte " __stringify(sp_reg) "\n\t"			\20	".byte " __stringify(type) "\n\t"			\21	".byte " __stringify(signal) "\n\t"			\22	".balign 4 \n\t"					\23	".popsection\n\t"24 25/*26 * This macro marks the given function's stack frame as "non-standard", which27 * tells objtool to ignore the function when doing stack metadata validation.28 * It should only be used in special cases where you're 100% sure it won't29 * affect the reliability of frame pointers and kernel stack traces.30 *31 * For more information, see tools/objtool/Documentation/objtool.txt.32 */33#define STACK_FRAME_NON_STANDARD(func) \34	static void __used __section(".discard.func_stack_frame_non_standard") \35		*__func_stack_frame_non_standard_##func = func36 37/*38 * STACK_FRAME_NON_STANDARD_FP() is a frame-pointer-specific function ignore39 * for the case where a function is intentionally missing frame pointer setup,40 * but otherwise needs objtool/ORC coverage when frame pointers are disabled.41 */42#ifdef CONFIG_FRAME_POINTER43#define STACK_FRAME_NON_STANDARD_FP(func) STACK_FRAME_NON_STANDARD(func)44#else45#define STACK_FRAME_NON_STANDARD_FP(func)46#endif47 48#define ANNOTATE_NOENDBR					\49	"986: \n\t"						\50	".pushsection .discard.noendbr\n\t"			\51	".long 986b\n\t"					\52	".popsection\n\t"53 54#define ASM_REACHABLE							\55	"998:\n\t"							\56	".pushsection .discard.reachable\n\t"				\57	".long 998b\n\t"						\58	".popsection\n\t"59 60#else /* __ASSEMBLY__ */61 62/*63 * This macro indicates that the following intra-function call is valid.64 * Any non-annotated intra-function call will cause objtool to issue a warning.65 */66#define ANNOTATE_INTRA_FUNCTION_CALL				\67	999:							\68	.pushsection .discard.intra_function_calls;		\69	.long 999b;						\70	.popsection;71 72/*73 * In asm, there are two kinds of code: normal C-type callable functions and74 * the rest.  The normal callable functions can be called by other code, and75 * don't do anything unusual with the stack.  Such normal callable functions76 * are annotated with the ENTRY/ENDPROC macros.  Most asm code falls in this77 * category.  In this case, no special debugging annotations are needed because78 * objtool can automatically generate the ORC data for the ORC unwinder to read79 * at runtime.80 *81 * Anything which doesn't fall into the above category, such as syscall and82 * interrupt handlers, tends to not be called directly by other functions, and83 * often does unusual non-C-function-type things with the stack pointer.  Such84 * code needs to be annotated such that objtool can understand it.  The85 * following CFI hint macros are for this type of code.86 *87 * These macros provide hints to objtool about the state of the stack at each88 * instruction.  Objtool starts from the hints and follows the code flow,89 * making automatic CFI adjustments when it sees pushes and pops, filling out90 * the debuginfo as necessary.  It will also warn if it sees any91 * inconsistencies.92 */93.macro UNWIND_HINT type:req sp_reg=0 sp_offset=0 signal=094.Lhere_\@:95	.pushsection .discard.unwind_hints96		/* struct unwind_hint */97		.long .Lhere_\@ - .98		.short \sp_offset99		.byte \sp_reg100		.byte \type101		.byte \signal102		.balign 4103	.popsection104.endm105 106.macro STACK_FRAME_NON_STANDARD func:req107	.pushsection .discard.func_stack_frame_non_standard, "aw"108	.long \func - .109	.popsection110.endm111 112.macro STACK_FRAME_NON_STANDARD_FP func:req113#ifdef CONFIG_FRAME_POINTER114	STACK_FRAME_NON_STANDARD \func115#endif116.endm117 118.macro ANNOTATE_NOENDBR119.Lhere_\@:120	.pushsection .discard.noendbr121	.long	.Lhere_\@122	.popsection123.endm124 125/*126 * Use objtool to validate the entry requirement that all code paths do127 * VALIDATE_UNRET_END before RET.128 *129 * NOTE: The macro must be used at the beginning of a global symbol, otherwise130 * it will be ignored.131 */132.macro VALIDATE_UNRET_BEGIN133#if defined(CONFIG_NOINSTR_VALIDATION) && \134	(defined(CONFIG_MITIGATION_UNRET_ENTRY) || defined(CONFIG_MITIGATION_SRSO))135.Lhere_\@:136	.pushsection .discard.validate_unret137	.long	.Lhere_\@ - .138	.popsection139#endif140.endm141 142.macro REACHABLE143.Lhere_\@:144	.pushsection .discard.reachable145	.long	.Lhere_\@146	.popsection147.endm148 149#endif /* __ASSEMBLY__ */150 151#else /* !CONFIG_OBJTOOL */152 153#ifndef __ASSEMBLY__154 155#define UNWIND_HINT(type, sp_reg, sp_offset, signal) "\n\t"156#define STACK_FRAME_NON_STANDARD(func)157#define STACK_FRAME_NON_STANDARD_FP(func)158#define ANNOTATE_NOENDBR159#define ASM_REACHABLE160#else161#define ANNOTATE_INTRA_FUNCTION_CALL162.macro UNWIND_HINT type:req sp_reg=0 sp_offset=0 signal=0163.endm164.macro STACK_FRAME_NON_STANDARD func:req165.endm166.macro ANNOTATE_NOENDBR167.endm168.macro REACHABLE169.endm170#endif171 172#endif /* CONFIG_OBJTOOL */173 174#endif /* _LINUX_OBJTOOL_H */175