cregit-Linux how code gets into the kernel

Release 4.14 arch/powerpc/oprofile/backtrace.c

/**
 * Copyright (C) 2005 Brian Rogan <bcr6@cornell.edu>, IBM
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version
 * 2 of the License, or (at your option) any later version.
**/

#include <linux/oprofile.h>
#include <linux/sched.h>
#include <asm/processor.h>
#include <linux/uaccess.h>
#include <asm/compat.h>
#include <asm/oprofile_impl.h>


#define STACK_SP(STACK)		*(STACK)


#define STACK_LR64(STACK)	*((unsigned long *)(STACK) + 2)

#define STACK_LR32(STACK)	*((unsigned int *)(STACK) + 1)

#ifdef CONFIG_PPC64

#define STACK_LR(STACK)		STACK_LR64(STACK)
#else

#define STACK_LR(STACK)		STACK_LR32(STACK)
#endif


static unsigned int user_getsp32(unsigned int sp, int is_first) { unsigned int stack_frame[2]; void __user *p = compat_ptr(sp); if (!access_ok(VERIFY_READ, p, sizeof(stack_frame))) return 0; /* * The most likely reason for this is that we returned -EFAULT, * which means that we've done all that we can do from * interrupt context. */ if (__copy_from_user_inatomic(stack_frame, p, sizeof(stack_frame))) return 0; if (!is_first) oprofile_add_trace(STACK_LR32(stack_frame)); /* * We do not enforce increasing stack addresses here because * we may transition to a different stack, eg a signal handler. */ return STACK_SP(stack_frame); }

Contributors

PersonTokensPropCommitsCommitProp
Brian Rogan7586.21%150.00%
Al Viro1213.79%150.00%
Total87100.00%2100.00%

#ifdef CONFIG_PPC64
static unsigned long user_getsp64(unsigned long sp, int is_first) { unsigned long stack_frame[3]; if (!access_ok(VERIFY_READ, (void __user *)sp, sizeof(stack_frame))) return 0; if (__copy_from_user_inatomic(stack_frame, (void __user *)sp, sizeof(stack_frame))) return 0; if (!is_first) oprofile_add_trace(STACK_LR64(stack_frame)); return STACK_SP(stack_frame); }

Contributors

PersonTokensPropCommitsCommitProp
Brian Rogan7992.94%150.00%
Al Viro67.06%150.00%
Total85100.00%2100.00%

#endif
static unsigned long kernel_getsp(unsigned long sp, int is_first) { unsigned long *stack_frame = (unsigned long *)sp; if (!validate_sp(sp, current, STACK_FRAME_OVERHEAD)) return 0; if (!is_first) oprofile_add_trace(STACK_LR(stack_frame)); /* * We do not enforce increasing stack addresses here because * we might be transitioning from an interrupt stack to a kernel * stack. validate_sp() is designed to understand this, so just * use it. */ return STACK_SP(stack_frame); }

Contributors

PersonTokensPropCommitsCommitProp
Brian Rogan61100.00%1100.00%
Total61100.00%1100.00%


void op_powerpc_backtrace(struct pt_regs * const regs, unsigned int depth) { unsigned long sp = regs->gpr[1]; int first_frame = 1; /* We ditch the top stackframe so need to loop through an extra time */ depth += 1; if (!user_mode(regs)) { while (depth--) { sp = kernel_getsp(sp, first_frame); if (!sp) break; first_frame = 0; } } else { pagefault_disable(); #ifdef CONFIG_PPC64 if (!is_32bit_task()) { while (depth--) { sp = user_getsp64(sp, first_frame); if (!sp) break; first_frame = 0; } pagefault_enable(); return; } #endif while (depth--) { sp = user_getsp32(sp, first_frame); if (!sp) break; first_frame = 0; } pagefault_enable(); } }

Contributors

PersonTokensPropCommitsCommitProp
Brian Rogan13992.67%133.33%
Jiang Lu96.00%133.33%
Denis Kirjanov21.33%133.33%
Total150100.00%3100.00%


Overall Contributors

PersonTokensPropCommitsCommitProp
Brian Rogan41391.98%120.00%
Al Viro214.68%120.00%
Jiang Lu102.23%120.00%
Anton Blanchard30.67%120.00%
Denis Kirjanov20.45%120.00%
Total449100.00%5100.00%
Information contained on this website is for historical information purposes only and does not indicate or represent copyright ownership.
Created with cregit.