debugobjects.h 3.9 KB

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