1 /* SPDX-License-Identifier: GPL-2.0 */
3 * code tagging framework
5 #ifndef _LINUX_CODETAG_H
6 #define _LINUX_CODETAG_H
8 #include <linux/types.h>
10 struct codetag_iterator
;
12 struct codetag_module
;
16 #define CODETAG_SECTION_START_PREFIX "__start_"
17 #define CODETAG_SECTION_STOP_PREFIX "__stop_"
20 * An instance of this structure is created in a special ELF section at every
21 * code location being tagged. At runtime, the special section is treated as
25 unsigned int flags
; /* used in later patches */
36 struct codetag_type_desc
{
39 void (*module_load
)(struct codetag_type
*cttype
,
40 struct codetag_module
*cmod
);
41 void (*module_unload
)(struct codetag_type
*cttype
,
42 struct codetag_module
*cmod
);
44 void (*module_replaced
)(struct module
*mod
, struct module
*new_mod
);
45 bool (*needs_section_mem
)(struct module
*mod
, unsigned long size
);
46 void *(*alloc_section_mem
)(struct module
*mod
, unsigned long size
,
47 unsigned int prepend
, unsigned long align
);
48 void (*free_section_mem
)(struct module
*mod
, bool used
);
52 struct codetag_iterator
{
53 struct codetag_type
*cttype
;
54 struct codetag_module
*cmod
;
60 #define CT_MODULE_NAME KBUILD_MODNAME
62 #define CT_MODULE_NAME NULL
65 #define CODE_TAG_INIT { \
66 .modname = CT_MODULE_NAME, \
67 .function = __func__, \
68 .filename = __FILE__, \
73 void codetag_lock_module_list(struct codetag_type
*cttype
, bool lock
);
74 bool codetag_trylock_module_list(struct codetag_type
*cttype
);
75 struct codetag_iterator
codetag_get_ct_iter(struct codetag_type
*cttype
);
76 struct codetag
*codetag_next_ct(struct codetag_iterator
*iter
);
78 void codetag_to_text(struct seq_buf
*out
, struct codetag
*ct
);
81 codetag_register_type(const struct codetag_type_desc
*desc
);
83 #if defined(CONFIG_CODE_TAGGING) && defined(CONFIG_MODULES)
85 bool codetag_needs_module_section(struct module
*mod
, const char *name
,
87 void *codetag_alloc_module_section(struct module
*mod
, const char *name
,
88 unsigned long size
, unsigned int prepend
,
90 void codetag_free_module_sections(struct module
*mod
);
91 void codetag_module_replaced(struct module
*mod
, struct module
*new_mod
);
92 void codetag_load_module(struct module
*mod
);
93 void codetag_unload_module(struct module
*mod
);
95 #else /* defined(CONFIG_CODE_TAGGING) && defined(CONFIG_MODULES) */
98 codetag_needs_module_section(struct module
*mod
, const char *name
,
99 unsigned long size
) { return false; }
101 codetag_alloc_module_section(struct module
*mod
, const char *name
,
102 unsigned long size
, unsigned int prepend
,
103 unsigned long align
) { return NULL
; }
104 static inline void codetag_free_module_sections(struct module
*mod
) {}
105 static inline void codetag_module_replaced(struct module
*mod
, struct module
*new_mod
) {}
106 static inline void codetag_load_module(struct module
*mod
) {}
107 static inline void codetag_unload_module(struct module
*mod
) {}
109 #endif /* defined(CONFIG_CODE_TAGGING) && defined(CONFIG_MODULES) */
111 #endif /* _LINUX_CODETAG_H */