mirror of
https://gitee.com/bianbu-linux/linux-6.6
synced 2025-04-24 14:07:52 -04:00
ptrace: introduce ptrace_event_enabled() and simplify ptrace_event() and tracehook_prepare_clone()
This patch implements ptrace_event_enabled() which tests whether a given PTRACE_EVENT_* is enabled and use it to simplify ptrace_event() and tracehook_prepare_clone(). PT_EVENT_FLAG() macro is added which calculates PT_TRACE_* flag from PTRACE_EVENT_*. This is used to define PT_TRACE_* flags and by ptrace_event_enabled() to find the matching flag. This is used to make ptrace_event() and tracehook_prepare_clone() simpler. * ptrace_event() callers were responsible for providing mask to test whether the event was enabled. This patch implements ptrace_event_enabled() and make ptrace_event() drop @mask and determine whether the event is enabled from @event. Note that @event is constant and this conversion doesn't add runtime overhead. All conversions except tracehook_report_clone_complete() are trivial. tracehook_report_clone_complete() used to use 0 for @mask (always enabled) but now tests whether the specified event is enabled. This doesn't cause any behavior difference as it's guaranteed that the event specified by @trace is enabled. * tracehook_prepare_clone() now only determines which event is applicable and use ptrace_event_enabled() for enable test. This doesn't introduce any behavior change. Signed-off-by: Tejun Heo <tj@kernel.org> Signed-off-by: Oleg Nesterov <oleg@redhat.com>
This commit is contained in:
parent
d21142ece4
commit
643ad8388e
2 changed files with 45 additions and 27 deletions
|
@ -201,7 +201,7 @@ static inline void tracehook_report_exec(struct linux_binfmt *fmt,
|
|||
struct linux_binprm *bprm,
|
||||
struct pt_regs *regs)
|
||||
{
|
||||
if (!ptrace_event(PT_TRACE_EXEC, PTRACE_EVENT_EXEC, 0) &&
|
||||
if (!ptrace_event(PTRACE_EVENT_EXEC, 0) &&
|
||||
unlikely(current->ptrace & PT_PTRACED))
|
||||
send_sig(SIGTRAP, current, 0);
|
||||
}
|
||||
|
@ -218,7 +218,7 @@ static inline void tracehook_report_exec(struct linux_binfmt *fmt,
|
|||
*/
|
||||
static inline void tracehook_report_exit(long *exit_code)
|
||||
{
|
||||
ptrace_event(PT_TRACE_EXIT, PTRACE_EVENT_EXIT, *exit_code);
|
||||
ptrace_event(PTRACE_EVENT_EXIT, *exit_code);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -232,19 +232,19 @@ static inline void tracehook_report_exit(long *exit_code)
|
|||
*/
|
||||
static inline int tracehook_prepare_clone(unsigned clone_flags)
|
||||
{
|
||||
int event = 0;
|
||||
|
||||
if (clone_flags & CLONE_UNTRACED)
|
||||
return 0;
|
||||
|
||||
if (clone_flags & CLONE_VFORK) {
|
||||
if (current->ptrace & PT_TRACE_VFORK)
|
||||
return PTRACE_EVENT_VFORK;
|
||||
} else if ((clone_flags & CSIGNAL) != SIGCHLD) {
|
||||
if (current->ptrace & PT_TRACE_CLONE)
|
||||
return PTRACE_EVENT_CLONE;
|
||||
} else if (current->ptrace & PT_TRACE_FORK)
|
||||
return PTRACE_EVENT_FORK;
|
||||
if (clone_flags & CLONE_VFORK)
|
||||
event = PTRACE_EVENT_VFORK;
|
||||
else if ((clone_flags & CSIGNAL) != SIGCHLD)
|
||||
event = PTRACE_EVENT_CLONE;
|
||||
else
|
||||
event = PTRACE_EVENT_FORK;
|
||||
|
||||
return 0;
|
||||
return ptrace_event_enabled(current, event) ? event : 0;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -318,7 +318,7 @@ static inline void tracehook_report_clone_complete(int trace,
|
|||
struct task_struct *child)
|
||||
{
|
||||
if (unlikely(trace))
|
||||
ptrace_event(0, trace, pid);
|
||||
ptrace_event(trace, pid);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -336,7 +336,7 @@ static inline void tracehook_report_clone_complete(int trace,
|
|||
static inline void tracehook_report_vfork_done(struct task_struct *child,
|
||||
pid_t pid)
|
||||
{
|
||||
ptrace_event(PT_TRACE_VFORK_DONE, PTRACE_EVENT_VFORK_DONE, pid);
|
||||
ptrace_event(PTRACE_EVENT_VFORK_DONE, pid);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue