Commit | Line | Data |
---|---|---|
b2441318 | 1 | /* SPDX-License-Identifier: GPL-2.0 */ |
3ac7fe5a TG |
2 | #ifndef _LINUX_DEBUGOBJECTS_H |
3 | #define _LINUX_DEBUGOBJECTS_H | |
4 | ||
5 | #include <linux/list.h> | |
6 | #include <linux/spinlock.h> | |
7 | ||
8 | enum debug_obj_state { | |
9 | ODEBUG_STATE_NONE, | |
10 | ODEBUG_STATE_INIT, | |
11 | ODEBUG_STATE_INACTIVE, | |
12 | ODEBUG_STATE_ACTIVE, | |
13 | ODEBUG_STATE_DESTROYED, | |
14 | ODEBUG_STATE_NOTAVAILABLE, | |
15 | ODEBUG_STATE_MAX, | |
16 | }; | |
17 | ||
18 | struct debug_obj_descr; | |
19 | ||
20 | /** | |
c23c8082 | 21 | * struct debug_obj - representation of an tracked object |
3ac7fe5a TG |
22 | * @node: hlist node to link the object into the tracker list |
23 | * @state: tracked object state | |
a5d8e467 | 24 | * @astate: current active state |
3ac7fe5a | 25 | * @object: pointer to the real object |
74fe1ad4 | 26 | * @batch_last: pointer to the last hlist node in a batch |
3ac7fe5a TG |
27 | * @descr: pointer to an object type specific debug description structure |
28 | */ | |
29 | struct debug_obj { | |
74fe1ad4 TG |
30 | struct hlist_node node; |
31 | enum debug_obj_state state; | |
32 | unsigned int astate; | |
33 | union { | |
34 | void *object; | |
35 | struct hlist_node *batch_last; | |
36 | }; | |
aedcade6 | 37 | const struct debug_obj_descr *descr; |
3ac7fe5a TG |
38 | }; |
39 | ||
40 | /** | |
41 | * struct debug_obj_descr - object type specific debug description structure | |
99777288 | 42 | * |
3ac7fe5a | 43 | * @name: name of the object typee |
99777288 SG |
44 | * @debug_hint: function returning address, which have associated |
45 | * kernel symbol, to allow identify the object | |
17359a80 | 46 | * @is_static_object: return true if the obj is static, otherwise return false |
3ac7fe5a | 47 | * @fixup_init: fixup function, which is called when the init check |
b1e4d9d8 DC |
48 | * fails. All fixup functions must return true if fixup |
49 | * was successful, otherwise return false | |
3ac7fe5a TG |
50 | * @fixup_activate: fixup function, which is called when the activate check |
51 | * fails | |
52 | * @fixup_destroy: fixup function, which is called when the destroy check | |
53 | * fails | |
54 | * @fixup_free: fixup function, which is called when the free check | |
55 | * fails | |
b84d435c CC |
56 | * @fixup_assert_init: fixup function, which is called when the assert_init |
57 | * check fails | |
3ac7fe5a TG |
58 | */ |
59 | struct debug_obj_descr { | |
60 | const char *name; | |
b1e4d9d8 | 61 | void *(*debug_hint)(void *addr); |
b9fdac7f | 62 | bool (*is_static_object)(void *addr); |
b1e4d9d8 DC |
63 | bool (*fixup_init)(void *addr, enum debug_obj_state state); |
64 | bool (*fixup_activate)(void *addr, enum debug_obj_state state); | |
65 | bool (*fixup_destroy)(void *addr, enum debug_obj_state state); | |
66 | bool (*fixup_free)(void *addr, enum debug_obj_state state); | |
67 | bool (*fixup_assert_init)(void *addr, enum debug_obj_state state); | |
3ac7fe5a TG |
68 | }; |
69 | ||
70 | #ifdef CONFIG_DEBUG_OBJECTS | |
aedcade6 | 71 | extern void debug_object_init (void *addr, const struct debug_obj_descr *descr); |
3ac7fe5a | 72 | extern void |
aedcade6 SB |
73 | debug_object_init_on_stack(void *addr, const struct debug_obj_descr *descr); |
74 | extern int debug_object_activate (void *addr, const struct debug_obj_descr *descr); | |
75 | extern void debug_object_deactivate(void *addr, const struct debug_obj_descr *descr); | |
76 | extern void debug_object_destroy (void *addr, const struct debug_obj_descr *descr); | |
77 | extern void debug_object_free (void *addr, const struct debug_obj_descr *descr); | |
78 | extern void debug_object_assert_init(void *addr, const struct debug_obj_descr *descr); | |
3ac7fe5a | 79 | |
a5d8e467 MD |
80 | /* |
81 | * Active state: | |
82 | * - Set at 0 upon initialization. | |
83 | * - Must return to 0 before deactivation. | |
84 | */ | |
85 | extern void | |
aedcade6 | 86 | debug_object_active_state(void *addr, const struct debug_obj_descr *descr, |
a5d8e467 MD |
87 | unsigned int expect, unsigned int next); |
88 | ||
3ac7fe5a TG |
89 | extern void debug_objects_early_init(void); |
90 | extern void debug_objects_mem_init(void); | |
91 | #else | |
92 | static inline void | |
aedcade6 | 93 | debug_object_init (void *addr, const struct debug_obj_descr *descr) { } |
3ac7fe5a | 94 | static inline void |
aedcade6 | 95 | debug_object_init_on_stack(void *addr, const struct debug_obj_descr *descr) { } |
b778ae25 | 96 | static inline int |
aedcade6 | 97 | debug_object_activate (void *addr, const struct debug_obj_descr *descr) { return 0; } |
3ac7fe5a | 98 | static inline void |
aedcade6 | 99 | debug_object_deactivate(void *addr, const struct debug_obj_descr *descr) { } |
3ac7fe5a | 100 | static inline void |
aedcade6 | 101 | debug_object_destroy (void *addr, const struct debug_obj_descr *descr) { } |
3ac7fe5a | 102 | static inline void |
aedcade6 | 103 | debug_object_free (void *addr, const struct debug_obj_descr *descr) { } |
b84d435c | 104 | static inline void |
aedcade6 | 105 | debug_object_assert_init(void *addr, const struct debug_obj_descr *descr) { } |
3ac7fe5a TG |
106 | |
107 | static inline void debug_objects_early_init(void) { } | |
108 | static inline void debug_objects_mem_init(void) { } | |
109 | #endif | |
110 | ||
111 | #ifdef CONFIG_DEBUG_OBJECTS_FREE | |
112 | extern void debug_check_no_obj_freed(const void *address, unsigned long size); | |
113 | #else | |
114 | static inline void | |
115 | debug_check_no_obj_freed(const void *address, unsigned long size) { } | |
116 | #endif | |
117 | ||
118 | #endif |