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