debugobjects.h 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  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. * @fixup_init: fixup function, which is called when the init check
  37. * fails
  38. * @fixup_activate: fixup function, which is called when the activate check
  39. * fails
  40. * @fixup_destroy: fixup function, which is called when the destroy check
  41. * fails
  42. * @fixup_free: fixup function, which is called when the free check
  43. * fails
  44. * @fixup_assert_init: fixup function, which is called when the assert_init
  45. * check fails
  46. */
  47. struct debug_obj_descr {
  48. const char *name;
  49. void *(*debug_hint) (void *addr);
  50. int (*fixup_init) (void *addr, enum debug_obj_state state);
  51. int (*fixup_activate) (void *addr, enum debug_obj_state state);
  52. int (*fixup_destroy) (void *addr, enum debug_obj_state state);
  53. int (*fixup_free) (void *addr, enum debug_obj_state state);
  54. int (*fixup_assert_init)(void *addr, enum debug_obj_state state);
  55. };
  56. #ifdef CONFIG_DEBUG_OBJECTS
  57. extern void debug_object_init (void *addr, struct debug_obj_descr *descr);
  58. extern void
  59. debug_object_init_on_stack(void *addr, struct debug_obj_descr *descr);
  60. extern int debug_object_activate (void *addr, struct debug_obj_descr *descr);
  61. extern void debug_object_deactivate(void *addr, struct debug_obj_descr *descr);
  62. extern void debug_object_destroy (void *addr, struct debug_obj_descr *descr);
  63. extern void debug_object_free (void *addr, struct debug_obj_descr *descr);
  64. extern void debug_object_assert_init(void *addr, struct debug_obj_descr *descr);
  65. /*
  66. * Active state:
  67. * - Set at 0 upon initialization.
  68. * - Must return to 0 before deactivation.
  69. */
  70. extern void
  71. debug_object_active_state(void *addr, struct debug_obj_descr *descr,
  72. unsigned int expect, unsigned int next);
  73. extern void debug_objects_early_init(void);
  74. extern void debug_objects_mem_init(void);
  75. #else
  76. static inline void
  77. debug_object_init (void *addr, struct debug_obj_descr *descr) { }
  78. static inline void
  79. debug_object_init_on_stack(void *addr, struct debug_obj_descr *descr) { }
  80. static inline int
  81. debug_object_activate (void *addr, struct debug_obj_descr *descr) { return 0; }
  82. static inline void
  83. debug_object_deactivate(void *addr, struct debug_obj_descr *descr) { }
  84. static inline void
  85. debug_object_destroy (void *addr, struct debug_obj_descr *descr) { }
  86. static inline void
  87. debug_object_free (void *addr, struct debug_obj_descr *descr) { }
  88. static inline void
  89. debug_object_assert_init(void *addr, struct debug_obj_descr *descr) { }
  90. static inline void debug_objects_early_init(void) { }
  91. static inline void debug_objects_mem_init(void) { }
  92. #endif
  93. #ifdef CONFIG_DEBUG_OBJECTS_FREE
  94. extern void debug_check_no_obj_freed(const void *address, unsigned long size);
  95. #else
  96. static inline void
  97. debug_check_no_obj_freed(const void *address, unsigned long size) { }
  98. #endif
  99. #endif