debugobjects.h 3.2 KB

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