include/linux/ftrace.h

Source file repositories/reference/linux-study-clean/include/linux/ftrace.h

File Facts

System
Linux kernel
Corpus path
include/linux/ftrace.h
Extension
.h
Size
46841 bytes
Lines
1401
Domain
Core OS
Bucket
Core Kernel Interface
Inferred role
Core OS: exported/initcall integration point
Status
integration implementation candidate

Why This File Exists

Core operating-system implementation surface: boot, tasks, memory, VFS, syscall-facing interfaces, synchronization, credentials, and isolation.

Dependency Surface

Detected Declarations

Annotated Snippet

struct ftrace_regs {
	/* Nothing to see here, use the accessor functions! */
};

#define ftrace_regs_size()	sizeof(struct __arch_ftrace_regs)

#ifndef CONFIG_HAVE_DYNAMIC_FTRACE_WITH_ARGS
/*
 * Architectures that define HAVE_DYNAMIC_FTRACE_WITH_ARGS must define their own
 * arch_ftrace_get_regs() where it only returns pt_regs *if* it is fully
 * populated. It should return NULL otherwise.
 */
static inline struct pt_regs *arch_ftrace_get_regs(struct ftrace_regs *fregs)
{
	return &arch_ftrace_regs(fregs)->regs;
}

/*
 * ftrace_regs_set_instruction_pointer() is to be defined by the architecture
 * if to allow setting of the instruction pointer from the ftrace_regs when
 * HAVE_DYNAMIC_FTRACE_WITH_ARGS is set and it supports live kernel patching.
 */
#define ftrace_regs_set_instruction_pointer(fregs, ip) do { } while (0)
#endif /* CONFIG_HAVE_DYNAMIC_FTRACE_WITH_ARGS */

#ifdef CONFIG_HAVE_FTRACE_REGS_HAVING_PT_REGS

static_assert(sizeof(struct pt_regs) == ftrace_regs_size());

#endif /* CONFIG_HAVE_FTRACE_REGS_HAVING_PT_REGS */

static __always_inline struct pt_regs *ftrace_get_regs(struct ftrace_regs *fregs)
{
	if (!fregs)
		return NULL;

	return arch_ftrace_get_regs(fregs);
}

#if !defined(CONFIG_HAVE_DYNAMIC_FTRACE_WITH_ARGS) || \
	defined(CONFIG_HAVE_FTRACE_REGS_HAVING_PT_REGS)

#ifndef arch_ftrace_partial_regs
#define arch_ftrace_partial_regs(regs) do {} while (0)
#endif

static __always_inline struct pt_regs *
ftrace_partial_regs(struct ftrace_regs *fregs, struct pt_regs *regs)
{
	/*
	 * If CONFIG_HAVE_FTRACE_REGS_HAVING_PT_REGS=y, ftrace_regs memory
	 * layout is including pt_regs. So always returns that address.
	 * Since arch_ftrace_get_regs() will check some members and may return
	 * NULL, we can not use it.
	 */
	regs = &arch_ftrace_regs(fregs)->regs;

	/* Allow arch specific updates to regs. */
	arch_ftrace_partial_regs(regs);
	return regs;
}

#endif /* !CONFIG_HAVE_DYNAMIC_FTRACE_WITH_ARGS || CONFIG_HAVE_FTRACE_REGS_HAVING_PT_REGS */

#ifdef CONFIG_HAVE_DYNAMIC_FTRACE_WITH_ARGS

/*
 * Please define arch dependent pt_regs which compatible to the
 * perf_arch_fetch_caller_regs() but based on ftrace_regs.
 * This requires
 *   - user_mode(_regs) returns false (always kernel mode).
 *   - able to use the _regs for stack trace.
 */
#ifndef arch_ftrace_fill_perf_regs
/* As same as perf_arch_fetch_caller_regs(), do nothing by default */
#define arch_ftrace_fill_perf_regs(fregs, _regs) do {} while (0)
#endif

static __always_inline struct pt_regs *
ftrace_fill_perf_regs(struct ftrace_regs *fregs, struct pt_regs *regs)
{
	arch_ftrace_fill_perf_regs(fregs, regs);
	return regs;
}

#else /* !CONFIG_HAVE_DYNAMIC_FTRACE_WITH_ARGS */

static __always_inline struct pt_regs *
ftrace_fill_perf_regs(struct ftrace_regs *fregs, struct pt_regs *regs)
{

Annotation

Implementation Notes