Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 13485ab5 authored by Alexander van Heukelum's avatar Alexander van Heukelum Committed by Ingo Molnar
Browse files

x86: traps_xx: restructure do_general_protection()



 - if (cond) block -> if (!cond) goto end_of_block
 - local caching of current

Signed-off-by: default avatarAlexander van Heukelum <heukelum@fastmail.fm>
Acked-by: default avatarCyrill Gorcunov <gorcunov@gmail.com>
Signed-off-by: default avatarIngo Molnar <mingo@elte.hu>
parent a7bbb0ce
Loading
Loading
Loading
Loading
+20 −16
Original line number Original line Diff line number Diff line
@@ -598,8 +598,10 @@ DO_ERROR(12, SIGBUS, "stack segment", stack_segment)
DO_ERROR_INFO(17, SIGBUS, "alignment check", alignment_check, BUS_ADRALN, 0, 0)
DO_ERROR_INFO(17, SIGBUS, "alignment check", alignment_check, BUS_ADRALN, 0, 0)
DO_ERROR_INFO(32, SIGILL, "iret exception", iret_error, ILL_BADSTK, 0, 1)
DO_ERROR_INFO(32, SIGILL, "iret exception", iret_error, ILL_BADSTK, 0, 1)


void __kprobes do_general_protection(struct pt_regs *regs, long error_code)
void __kprobes
do_general_protection(struct pt_regs *regs, long error_code)
{
{
	struct task_struct *tsk;
	struct thread_struct *thread;
	struct thread_struct *thread;
	struct tss_struct *tss;
	struct tss_struct *tss;
	int cpu;
	int cpu;
@@ -640,23 +642,24 @@ void __kprobes do_general_protection(struct pt_regs *regs, long error_code)
	if (regs->flags & X86_VM_MASK)
	if (regs->flags & X86_VM_MASK)
		goto gp_in_vm86;
		goto gp_in_vm86;


	tsk = current;
	if (!user_mode(regs))
	if (!user_mode(regs))
		goto gp_in_kernel;
		goto gp_in_kernel;


	current->thread.error_code = error_code;
	tsk->thread.error_code = error_code;
	current->thread.trap_no = 13;
	tsk->thread.trap_no = 13;


	if (show_unhandled_signals && unhandled_signal(current, SIGSEGV) &&
	if (show_unhandled_signals && unhandled_signal(tsk, SIGSEGV) &&
			printk_ratelimit()) {
			printk_ratelimit()) {
		printk(KERN_INFO
		printk(KERN_INFO
			"%s[%d] general protection ip:%lx sp:%lx error:%lx",
			"%s[%d] general protection ip:%lx sp:%lx error:%lx",
		    current->comm, task_pid_nr(current),
			tsk->comm, task_pid_nr(tsk),
			regs->ip, regs->sp, error_code);
			regs->ip, regs->sp, error_code);
		print_vma_addr(" in ", regs->ip);
		print_vma_addr(" in ", regs->ip);
		printk("\n");
		printk("\n");
	}
	}


	force_sig(SIGSEGV, current);
	force_sig(SIGSEGV, tsk);
	return;
	return;


gp_in_vm86:
gp_in_vm86:
@@ -665,15 +668,16 @@ void __kprobes do_general_protection(struct pt_regs *regs, long error_code)
	return;
	return;


gp_in_kernel:
gp_in_kernel:
	if (!fixup_exception(regs)) {
	if (fixup_exception(regs))
		current->thread.error_code = error_code;
		return;
		current->thread.trap_no = 13;

	tsk->thread.error_code = error_code;
	tsk->thread.trap_no = 13;
	if (notify_die(DIE_GPF, "general protection fault", regs,
	if (notify_die(DIE_GPF, "general protection fault", regs,
				error_code, 13, SIGSEGV) == NOTIFY_STOP)
				error_code, 13, SIGSEGV) == NOTIFY_STOP)
		return;
		return;
	die("general protection fault", regs, error_code);
	die("general protection fault", regs, error_code);
}
}
}


static notrace __kprobes void
static notrace __kprobes void
mem_parity_error(unsigned char reason, struct pt_regs *regs)
mem_parity_error(unsigned char reason, struct pt_regs *regs)
+22 −19
Original line number Original line Diff line number Diff line
@@ -733,14 +733,17 @@ asmlinkage void do_double_fault(struct pt_regs * regs, long error_code)
		die(str, regs, error_code);
		die(str, regs, error_code);
}
}


asmlinkage void __kprobes do_general_protection(struct pt_regs * regs,
asmlinkage void __kprobes
						long error_code)
do_general_protection(struct pt_regs *regs, long error_code)
{
{
	struct task_struct *tsk = current;
	struct task_struct *tsk;


	conditional_sti(regs);
	conditional_sti(regs);


	if (user_mode(regs)) {
	tsk = current;
	if (!user_mode(regs))
		goto gp_in_kernel;

	tsk->thread.error_code = error_code;
	tsk->thread.error_code = error_code;
	tsk->thread.trap_no = 13;
	tsk->thread.trap_no = 13;


@@ -756,8 +759,8 @@ asmlinkage void __kprobes do_general_protection(struct pt_regs * regs,


	force_sig(SIGSEGV, tsk);
	force_sig(SIGSEGV, tsk);
	return;
	return;
	} 


gp_in_kernel:
	if (fixup_exception(regs))
	if (fixup_exception(regs))
		return;
		return;