1 /* SPDX-License-Identifier: GPL-2.0 */
2 #ifndef _LINUX_DEBUGOBJECTS_H
3 #define _LINUX_DEBUGOBJECTS_H
5 #include <linux/list.h>
6 #include <linux/spinlock.h>
11 ODEBUG_STATE_INACTIVE,
13 ODEBUG_STATE_DESTROYED,
14 ODEBUG_STATE_NOTAVAILABLE,
18 struct debug_obj_descr;
21 * struct debug_obj - representation of an tracked object
22 * @node: hlist node to link the object into the tracker list
23 * @state: tracked object state
24 * @astate: current active state
25 * @object: pointer to the real object
26 * @descr: pointer to an object type specific debug description structure
29 struct hlist_node node;
30 enum debug_obj_state state;
33 const struct debug_obj_descr *descr;
37 * struct debug_obj_descr - object type specific debug description structure
39 * @name: name of the object typee
40 * @debug_hint: function returning address, which have associated
41 * kernel symbol, to allow identify the object
42 * @is_static_object: return true if the obj is static, otherwise return false
43 * @fixup_init: fixup function, which is called when the init check
44 * fails. All fixup functions must return true if fixup
45 * was successful, otherwise return false
46 * @fixup_activate: fixup function, which is called when the activate check
48 * @fixup_destroy: fixup function, which is called when the destroy check
50 * @fixup_free: fixup function, which is called when the free check
52 * @fixup_assert_init: fixup function, which is called when the assert_init
55 struct debug_obj_descr {
57 void *(*debug_hint)(void *addr);
58 bool (*is_static_object)(void *addr);
59 bool (*fixup_init)(void *addr, enum debug_obj_state state);
60 bool (*fixup_activate)(void *addr, enum debug_obj_state state);
61 bool (*fixup_destroy)(void *addr, enum debug_obj_state state);
62 bool (*fixup_free)(void *addr, enum debug_obj_state state);
63 bool (*fixup_assert_init)(void *addr, enum debug_obj_state state);
66 #ifdef CONFIG_DEBUG_OBJECTS
67 extern void debug_object_init (void *addr, const struct debug_obj_descr *descr);
69 debug_object_init_on_stack(void *addr, const struct debug_obj_descr *descr);
70 extern int debug_object_activate (void *addr, const struct debug_obj_descr *descr);
71 extern void debug_object_deactivate(void *addr, const struct debug_obj_descr *descr);
72 extern void debug_object_destroy (void *addr, const struct debug_obj_descr *descr);
73 extern void debug_object_free (void *addr, const struct debug_obj_descr *descr);
74 extern void debug_object_assert_init(void *addr, const struct debug_obj_descr *descr);
78 * - Set at 0 upon initialization.
79 * - Must return to 0 before deactivation.
82 debug_object_active_state(void *addr, const struct debug_obj_descr *descr,
83 unsigned int expect, unsigned int next);
85 extern void debug_objects_early_init(void);
86 extern void debug_objects_mem_init(void);
89 debug_object_init (void *addr, const struct debug_obj_descr *descr) { }
91 debug_object_init_on_stack(void *addr, const struct debug_obj_descr *descr) { }
93 debug_object_activate (void *addr, const struct debug_obj_descr *descr) { return 0; }
95 debug_object_deactivate(void *addr, const struct debug_obj_descr *descr) { }
97 debug_object_destroy (void *addr, const struct debug_obj_descr *descr) { }
99 debug_object_free (void *addr, const struct debug_obj_descr *descr) { }
101 debug_object_assert_init(void *addr, const struct debug_obj_descr *descr) { }
103 static inline void debug_objects_early_init(void) { }
104 static inline void debug_objects_mem_init(void) { }
107 #ifdef CONFIG_DEBUG_OBJECTS_FREE
108 extern void debug_check_no_obj_freed(const void *address, unsigned long size);
111 debug_check_no_obj_freed(const void *address, unsigned long size) { }