blob: afc416e5dcabd77b461b4c198503c71ce6b75fb3 [file] [log] [blame]
Greg Kroah-Hartmanb2441312017-11-01 15:07:57 +01001/* SPDX-License-Identifier: GPL-2.0 */
Thomas Gleixner3ac7fe52008-04-30 00:55:01 -07002#ifndef _LINUX_DEBUGOBJECTS_H
3#define _LINUX_DEBUGOBJECTS_H
4
5#include <linux/list.h>
6#include <linux/spinlock.h>
7
8enum 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
18struct debug_obj_descr;
19
20/**
21 * struct debug_obj - representaion of an tracked object
22 * @node: hlist node to link the object into the tracker list
23 * @state: tracked object state
Mathieu Desnoyersa5d8e462010-04-17 08:48:38 -040024 * @astate: current active state
Thomas Gleixner3ac7fe52008-04-30 00:55:01 -070025 * @object: pointer to the real object
26 * @descr: pointer to an object type specific debug description structure
27 */
28struct debug_obj {
29 struct hlist_node node;
30 enum debug_obj_state state;
Mathieu Desnoyersa5d8e462010-04-17 08:48:38 -040031 unsigned int astate;
Thomas Gleixner3ac7fe52008-04-30 00:55:01 -070032 void *object;
33 struct debug_obj_descr *descr;
34};
35
36/**
37 * struct debug_obj_descr - object type specific debug description structure
Stanislaw Gruszka99777282011-03-07 09:58:33 +010038 *
Thomas Gleixner3ac7fe52008-04-30 00:55:01 -070039 * @name: name of the object typee
Stanislaw Gruszka99777282011-03-07 09:58:33 +010040 * @debug_hint: function returning address, which have associated
41 * kernel symbol, to allow identify the object
Randy Dunlap17359a82016-07-26 15:21:26 -070042 * @is_static_object: return true if the obj is static, otherwise return false
Thomas Gleixner3ac7fe52008-04-30 00:55:01 -070043 * @fixup_init: fixup function, which is called when the init check
Du, Changbinb1e4d9d2016-05-19 17:09:20 -070044 * fails. All fixup functions must return true if fixup
45 * was successful, otherwise return false
Thomas Gleixner3ac7fe52008-04-30 00:55:01 -070046 * @fixup_activate: fixup function, which is called when the activate check
47 * fails
48 * @fixup_destroy: fixup function, which is called when the destroy check
49 * fails
50 * @fixup_free: fixup function, which is called when the free check
51 * fails
Christine Chanb84d4352011-11-07 19:48:27 -080052 * @fixup_assert_init: fixup function, which is called when the assert_init
53 * check fails
Thomas Gleixner3ac7fe52008-04-30 00:55:01 -070054 */
55struct debug_obj_descr {
56 const char *name;
Du, Changbinb1e4d9d2016-05-19 17:09:20 -070057 void *(*debug_hint)(void *addr);
Du, Changbinb9fdac72016-05-19 17:09:41 -070058 bool (*is_static_object)(void *addr);
Du, Changbinb1e4d9d2016-05-19 17:09:20 -070059 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);
Thomas Gleixner3ac7fe52008-04-30 00:55:01 -070064};
65
66#ifdef CONFIG_DEBUG_OBJECTS
67extern void debug_object_init (void *addr, struct debug_obj_descr *descr);
68extern void
69debug_object_init_on_stack(void *addr, struct debug_obj_descr *descr);
Paul E. McKenneyb778ae22013-04-23 12:51:11 -070070extern int debug_object_activate (void *addr, struct debug_obj_descr *descr);
Thomas Gleixner3ac7fe52008-04-30 00:55:01 -070071extern void debug_object_deactivate(void *addr, struct debug_obj_descr *descr);
72extern void debug_object_destroy (void *addr, struct debug_obj_descr *descr);
73extern void debug_object_free (void *addr, struct debug_obj_descr *descr);
Christine Chanb84d4352011-11-07 19:48:27 -080074extern void debug_object_assert_init(void *addr, struct debug_obj_descr *descr);
Thomas Gleixner3ac7fe52008-04-30 00:55:01 -070075
Mathieu Desnoyersa5d8e462010-04-17 08:48:38 -040076/*
77 * Active state:
78 * - Set at 0 upon initialization.
79 * - Must return to 0 before deactivation.
80 */
81extern void
82debug_object_active_state(void *addr, struct debug_obj_descr *descr,
83 unsigned int expect, unsigned int next);
84
Thomas Gleixner3ac7fe52008-04-30 00:55:01 -070085extern void debug_objects_early_init(void);
86extern void debug_objects_mem_init(void);
87#else
88static inline void
89debug_object_init (void *addr, struct debug_obj_descr *descr) { }
90static inline void
91debug_object_init_on_stack(void *addr, struct debug_obj_descr *descr) { }
Paul E. McKenneyb778ae22013-04-23 12:51:11 -070092static inline int
93debug_object_activate (void *addr, struct debug_obj_descr *descr) { return 0; }
Thomas Gleixner3ac7fe52008-04-30 00:55:01 -070094static inline void
95debug_object_deactivate(void *addr, struct debug_obj_descr *descr) { }
96static inline void
97debug_object_destroy (void *addr, struct debug_obj_descr *descr) { }
98static inline void
99debug_object_free (void *addr, struct debug_obj_descr *descr) { }
Christine Chanb84d4352011-11-07 19:48:27 -0800100static inline void
101debug_object_assert_init(void *addr, struct debug_obj_descr *descr) { }
Thomas Gleixner3ac7fe52008-04-30 00:55:01 -0700102
103static inline void debug_objects_early_init(void) { }
104static inline void debug_objects_mem_init(void) { }
105#endif
106
107#ifdef CONFIG_DEBUG_OBJECTS_FREE
108extern void debug_check_no_obj_freed(const void *address, unsigned long size);
109#else
110static inline void
111debug_check_no_obj_freed(const void *address, unsigned long size) { }
112#endif
113
114#endif