Back to home page

OSCL-LXR

 
 

    


0001 /* SPDX-License-Identifier: GPL-2.0 */
0002 #ifndef _LINUX_DEBUGOBJECTS_H
0003 #define _LINUX_DEBUGOBJECTS_H
0004 
0005 #include <linux/list.h>
0006 #include <linux/spinlock.h>
0007 
0008 enum debug_obj_state {
0009     ODEBUG_STATE_NONE,
0010     ODEBUG_STATE_INIT,
0011     ODEBUG_STATE_INACTIVE,
0012     ODEBUG_STATE_ACTIVE,
0013     ODEBUG_STATE_DESTROYED,
0014     ODEBUG_STATE_NOTAVAILABLE,
0015     ODEBUG_STATE_MAX,
0016 };
0017 
0018 struct debug_obj_descr;
0019 
0020 /**
0021  * struct debug_obj - representation of an tracked object
0022  * @node:   hlist node to link the object into the tracker list
0023  * @state:  tracked object state
0024  * @astate: current active state
0025  * @object: pointer to the real object
0026  * @descr:  pointer to an object type specific debug description structure
0027  */
0028 struct debug_obj {
0029     struct hlist_node   node;
0030     enum debug_obj_state    state;
0031     unsigned int        astate;
0032     void            *object;
0033     const struct debug_obj_descr *descr;
0034 };
0035 
0036 /**
0037  * struct debug_obj_descr - object type specific debug description structure
0038  *
0039  * @name:       name of the object typee
0040  * @debug_hint:     function returning address, which have associated
0041  *          kernel symbol, to allow identify the object
0042  * @is_static_object:   return true if the obj is static, otherwise return false
0043  * @fixup_init:     fixup function, which is called when the init check
0044  *          fails. All fixup functions must return true if fixup
0045  *          was successful, otherwise return false
0046  * @fixup_activate: fixup function, which is called when the activate check
0047  *          fails
0048  * @fixup_destroy:  fixup function, which is called when the destroy check
0049  *          fails
0050  * @fixup_free:     fixup function, which is called when the free check
0051  *          fails
0052  * @fixup_assert_init:  fixup function, which is called when the assert_init
0053  *          check fails
0054  */
0055 struct debug_obj_descr {
0056     const char      *name;
0057     void *(*debug_hint)(void *addr);
0058     bool (*is_static_object)(void *addr);
0059     bool (*fixup_init)(void *addr, enum debug_obj_state state);
0060     bool (*fixup_activate)(void *addr, enum debug_obj_state state);
0061     bool (*fixup_destroy)(void *addr, enum debug_obj_state state);
0062     bool (*fixup_free)(void *addr, enum debug_obj_state state);
0063     bool (*fixup_assert_init)(void *addr, enum debug_obj_state state);
0064 };
0065 
0066 #ifdef CONFIG_DEBUG_OBJECTS
0067 extern void debug_object_init      (void *addr, const struct debug_obj_descr *descr);
0068 extern void
0069 debug_object_init_on_stack(void *addr, const struct debug_obj_descr *descr);
0070 extern int debug_object_activate  (void *addr, const struct debug_obj_descr *descr);
0071 extern void debug_object_deactivate(void *addr, const struct debug_obj_descr *descr);
0072 extern void debug_object_destroy   (void *addr, const struct debug_obj_descr *descr);
0073 extern void debug_object_free      (void *addr, const struct debug_obj_descr *descr);
0074 extern void debug_object_assert_init(void *addr, const struct debug_obj_descr *descr);
0075 
0076 /*
0077  * Active state:
0078  * - Set at 0 upon initialization.
0079  * - Must return to 0 before deactivation.
0080  */
0081 extern void
0082 debug_object_active_state(void *addr, const struct debug_obj_descr *descr,
0083               unsigned int expect, unsigned int next);
0084 
0085 extern void debug_objects_early_init(void);
0086 extern void debug_objects_mem_init(void);
0087 #else
0088 static inline void
0089 debug_object_init      (void *addr, const struct debug_obj_descr *descr) { }
0090 static inline void
0091 debug_object_init_on_stack(void *addr, const struct debug_obj_descr *descr) { }
0092 static inline int
0093 debug_object_activate  (void *addr, const struct debug_obj_descr *descr) { return 0; }
0094 static inline void
0095 debug_object_deactivate(void *addr, const struct debug_obj_descr *descr) { }
0096 static inline void
0097 debug_object_destroy   (void *addr, const struct debug_obj_descr *descr) { }
0098 static inline void
0099 debug_object_free      (void *addr, const struct debug_obj_descr *descr) { }
0100 static inline void
0101 debug_object_assert_init(void *addr, const struct debug_obj_descr *descr) { }
0102 
0103 static inline void debug_objects_early_init(void) { }
0104 static inline void debug_objects_mem_init(void) { }
0105 #endif
0106 
0107 #ifdef CONFIG_DEBUG_OBJECTS_FREE
0108 extern void debug_check_no_obj_freed(const void *address, unsigned long size);
0109 #else
0110 static inline void
0111 debug_check_no_obj_freed(const void *address, unsigned long size) { }
0112 #endif
0113 
0114 #endif