debugobjects.h 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  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. */
  45. struct debug_obj_descr {
  46. const char *name;
  47. void *(*debug_hint) (void *addr);
  48. int (*fixup_init) (void *addr, enum debug_obj_state state);
  49. int (*fixup_activate) (void *addr, enum debug_obj_state state);
  50. int (*fixup_destroy) (void *addr, enum debug_obj_state state);
  51. int (*fixup_free) (void *addr, enum debug_obj_state state);
  52. };
  53. #ifdef CONFIG_DEBUG_OBJECTS
  54. extern void debug_object_init (void *addr, struct debug_obj_descr *descr);
  55. extern void
  56. debug_object_init_on_stack(void *addr, struct debug_obj_descr *descr);
  57. extern void debug_object_activate (void *addr, struct debug_obj_descr *descr);
  58. extern void debug_object_deactivate(void *addr, struct debug_obj_descr *descr);
  59. extern void debug_object_destroy (void *addr, struct debug_obj_descr *descr);
  60. extern void debug_object_free (void *addr, struct debug_obj_descr *descr);
  61. /*
  62. * Active state:
  63. * - Set at 0 upon initialization.
  64. * - Must return to 0 before deactivation.
  65. */
  66. extern void
  67. debug_object_active_state(void *addr, struct debug_obj_descr *descr,
  68. unsigned int expect, unsigned int next);
  69. extern void debug_objects_early_init(void);
  70. extern void debug_objects_mem_init(void);
  71. #else
  72. static inline void
  73. debug_object_init (void *addr, struct debug_obj_descr *descr) { }
  74. static inline void
  75. debug_object_init_on_stack(void *addr, struct debug_obj_descr *descr) { }
  76. static inline void
  77. debug_object_activate (void *addr, struct debug_obj_descr *descr) { }
  78. static inline void
  79. debug_object_deactivate(void *addr, struct debug_obj_descr *descr) { }
  80. static inline void
  81. debug_object_destroy (void *addr, struct debug_obj_descr *descr) { }
  82. static inline void
  83. debug_object_free (void *addr, struct debug_obj_descr *descr) { }
  84. static inline void debug_objects_early_init(void) { }
  85. static inline void debug_objects_mem_init(void) { }
  86. #endif
  87. #ifdef CONFIG_DEBUG_OBJECTS_FREE
  88. extern void debug_check_no_obj_freed(const void *address, unsigned long size);
  89. #else
  90. static inline void
  91. debug_check_no_obj_freed(const void *address, unsigned long size) { }
  92. #endif
  93. #endif