csky: Update syscall_trace_enter/exit implementation
Previous syscall_trace implementation couldn't support AUDITSYSCALL and SYSCALL_TRACEPOINTS. Now we redesign it to support audit_syscall and syscall_tracepoints just like other archs'. Signed-off-by: Guo Ren <ren_guo@c-sky.com> Cc: Dmitry V. Levin <ldv@altlinux.org> Cc: Arnd Bergmann <arnd@arndb.de>
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
// SPDX-License-Identifier: GPL-2.0
|
||||
// Copyright (C) 2018 Hangzhou C-SKY Microsystems co.,ltd.
|
||||
|
||||
#include <linux/audit.h>
|
||||
#include <linux/elf.h>
|
||||
#include <linux/errno.h>
|
||||
#include <linux/kernel.h>
|
||||
@@ -11,6 +12,7 @@
|
||||
#include <linux/sched/task_stack.h>
|
||||
#include <linux/signal.h>
|
||||
#include <linux/smp.h>
|
||||
#include <linux/tracehook.h>
|
||||
#include <linux/uaccess.h>
|
||||
#include <linux/user.h>
|
||||
|
||||
@@ -22,6 +24,9 @@
|
||||
|
||||
#include <abi/regdef.h>
|
||||
|
||||
#define CREATE_TRACE_POINTS
|
||||
#include <trace/events/syscalls.h>
|
||||
|
||||
/* sets the trace bits. */
|
||||
#define TRACE_MODE_SI (1 << 14)
|
||||
#define TRACE_MODE_RUN 0
|
||||
@@ -207,35 +212,26 @@ long arch_ptrace(struct task_struct *child, long request,
|
||||
return ret;
|
||||
}
|
||||
|
||||
/*
|
||||
* If process's system calls is traces, do some corresponding handles in this
|
||||
* function before entering system call function and after exiting system call
|
||||
* function.
|
||||
*/
|
||||
asmlinkage void syscall_trace(int why, struct pt_regs *regs)
|
||||
asmlinkage void syscall_trace_enter(struct pt_regs *regs)
|
||||
{
|
||||
long saved_why;
|
||||
/*
|
||||
* Save saved_why, why is used to denote syscall entry/exit;
|
||||
* why = 0:entry, why = 1: exit
|
||||
*/
|
||||
saved_why = regs->regs[SYSTRACE_SAVENUM];
|
||||
regs->regs[SYSTRACE_SAVENUM] = why;
|
||||
if (test_thread_flag(TIF_SYSCALL_TRACE))
|
||||
tracehook_report_syscall_entry(regs);
|
||||
|
||||
ptrace_notify(SIGTRAP | ((current->ptrace & PT_TRACESYSGOOD)
|
||||
? 0x80 : 0));
|
||||
if (test_thread_flag(TIF_SYSCALL_TRACEPOINT))
|
||||
trace_sys_enter(regs, syscall_get_nr(current, regs));
|
||||
|
||||
/*
|
||||
* this isn't the same as continuing with a signal, but it will do
|
||||
* for normal use. strace only continues with a signal if the
|
||||
* stopping signal is not SIGTRAP. -brl
|
||||
*/
|
||||
if (current->exit_code) {
|
||||
send_sig(current->exit_code, current, 1);
|
||||
current->exit_code = 0;
|
||||
}
|
||||
audit_syscall_entry(regs_syscallid(regs), regs->a0, regs->a1, regs->a2, regs->a3);
|
||||
}
|
||||
|
||||
regs->regs[SYSTRACE_SAVENUM] = saved_why;
|
||||
asmlinkage void syscall_trace_exit(struct pt_regs *regs)
|
||||
{
|
||||
audit_syscall_exit(regs);
|
||||
|
||||
if (test_thread_flag(TIF_SYSCALL_TRACE))
|
||||
tracehook_report_syscall_exit(regs, 0);
|
||||
|
||||
if (test_thread_flag(TIF_SYSCALL_TRACEPOINT))
|
||||
trace_sys_exit(regs, syscall_get_return_value(current, regs));
|
||||
}
|
||||
|
||||
extern void show_stack(struct task_struct *task, unsigned long *stack);
|
||||
|
Reference in New Issue
Block a user