stackdepot.h 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. /* SPDX-License-Identifier: GPL-2.0-or-later */
  2. /*
  3. * A generic stack depot implementation
  4. *
  5. * Author: Alexander Potapenko <[email protected]>
  6. * Copyright (C) 2016 Google, Inc.
  7. *
  8. * Based on code by Dmitry Chernenkov.
  9. */
  10. #ifndef _LINUX_STACKDEPOT_H
  11. #define _LINUX_STACKDEPOT_H
  12. #include <linux/gfp.h>
  13. typedef u32 depot_stack_handle_t;
  14. /*
  15. * Number of bits in the handle that stack depot doesn't use. Users may store
  16. * information in them.
  17. */
  18. #define STACK_DEPOT_EXTRA_BITS 5
  19. depot_stack_handle_t __stack_depot_save(unsigned long *entries,
  20. unsigned int nr_entries,
  21. unsigned int extra_bits,
  22. gfp_t gfp_flags, bool can_alloc);
  23. /*
  24. * Every user of stack depot has to call stack_depot_init() during its own init
  25. * when it's decided that it will be calling stack_depot_save() later. This is
  26. * recommended for e.g. modules initialized later in the boot process, when
  27. * slab_is_available() is true.
  28. *
  29. * The alternative is to select STACKDEPOT_ALWAYS_INIT to have stack depot
  30. * enabled as part of mm_init(), for subsystems where it's known at compile time
  31. * that stack depot will be used.
  32. *
  33. * Another alternative is to call stack_depot_want_early_init(), when the
  34. * decision to use stack depot is taken e.g. when evaluating kernel boot
  35. * parameters, which precedes the enablement point in mm_init().
  36. *
  37. * stack_depot_init() and stack_depot_want_early_init() can be called regardless
  38. * of CONFIG_STACKDEPOT and are no-op when disabled. The actual save/fetch/print
  39. * functions should only be called from code that makes sure CONFIG_STACKDEPOT
  40. * is enabled.
  41. */
  42. #ifdef CONFIG_STACKDEPOT
  43. int stack_depot_init(void);
  44. void __init stack_depot_want_early_init(void);
  45. /* This is supposed to be called only from mm_init() */
  46. int __init stack_depot_early_init(void);
  47. #else
  48. static inline int stack_depot_init(void) { return 0; }
  49. static inline void stack_depot_want_early_init(void) { }
  50. static inline int stack_depot_early_init(void) { return 0; }
  51. #endif
  52. depot_stack_handle_t stack_depot_save(unsigned long *entries,
  53. unsigned int nr_entries, gfp_t gfp_flags);
  54. unsigned int stack_depot_fetch(depot_stack_handle_t handle,
  55. unsigned long **entries);
  56. unsigned int stack_depot_get_extra_bits(depot_stack_handle_t handle);
  57. int stack_depot_snprint(depot_stack_handle_t handle, char *buf, size_t size,
  58. int spaces);
  59. void stack_depot_print(depot_stack_handle_t stack);
  60. #endif