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