diff options
author | Tejun Heo <tj@kernel.org> | 2011-06-17 10:50:35 -0400 |
---|---|---|
committer | Oleg Nesterov <oleg@redhat.com> | 2011-06-22 13:26:28 -0400 |
commit | 643ad8388e189dfd14ef76972cf7dc394b3cbebd (patch) | |
tree | 82d4787ddc09cf5a6fc9fc1345839973ab7763f5 /include/linux/tracehook.h | |
parent | d21142ece414ce1088cfcae760689aa60d6fee80 (diff) |
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>
Diffstat (limited to 'include/linux/tracehook.h')
-rw-r--r-- | include/linux/tracehook.h | 26 |
1 files changed, 13 insertions, 13 deletions
diff --git a/include/linux/tracehook.h b/include/linux/tracehook.h index a3e838784f43..7d38571b0c05 100644 --- a/include/linux/tracehook.h +++ b/include/linux/tracehook.h | |||
@@ -201,7 +201,7 @@ static inline void tracehook_report_exec(struct linux_binfmt *fmt, | |||
201 | struct linux_binprm *bprm, | 201 | struct linux_binprm *bprm, |
202 | struct pt_regs *regs) | 202 | struct pt_regs *regs) |
203 | { | 203 | { |
204 | if (!ptrace_event(PT_TRACE_EXEC, PTRACE_EVENT_EXEC, 0) && | 204 | if (!ptrace_event(PTRACE_EVENT_EXEC, 0) && |
205 | unlikely(current->ptrace & PT_PTRACED)) | 205 | unlikely(current->ptrace & PT_PTRACED)) |
206 | send_sig(SIGTRAP, current, 0); | 206 | send_sig(SIGTRAP, current, 0); |
207 | } | 207 | } |
@@ -218,7 +218,7 @@ static inline void tracehook_report_exec(struct linux_binfmt *fmt, | |||
218 | */ | 218 | */ |
219 | static inline void tracehook_report_exit(long *exit_code) | 219 | static inline void tracehook_report_exit(long *exit_code) |
220 | { | 220 | { |
221 | ptrace_event(PT_TRACE_EXIT, PTRACE_EVENT_EXIT, *exit_code); | 221 | ptrace_event(PTRACE_EVENT_EXIT, *exit_code); |
222 | } | 222 | } |
223 | 223 | ||
224 | /** | 224 | /** |
@@ -232,19 +232,19 @@ static inline void tracehook_report_exit(long *exit_code) | |||
232 | */ | 232 | */ |
233 | static inline int tracehook_prepare_clone(unsigned clone_flags) | 233 | static inline int tracehook_prepare_clone(unsigned clone_flags) |
234 | { | 234 | { |
235 | int event = 0; | ||
236 | |||
235 | if (clone_flags & CLONE_UNTRACED) | 237 | if (clone_flags & CLONE_UNTRACED) |
236 | return 0; | 238 | return 0; |
237 | 239 | ||
238 | if (clone_flags & CLONE_VFORK) { | 240 | if (clone_flags & CLONE_VFORK) |
239 | if (current->ptrace & PT_TRACE_VFORK) | 241 | event = PTRACE_EVENT_VFORK; |
240 | return PTRACE_EVENT_VFORK; | 242 | else if ((clone_flags & CSIGNAL) != SIGCHLD) |
241 | } else if ((clone_flags & CSIGNAL) != SIGCHLD) { | 243 | event = PTRACE_EVENT_CLONE; |
242 | if (current->ptrace & PT_TRACE_CLONE) | 244 | else |
243 | return PTRACE_EVENT_CLONE; | 245 | event = PTRACE_EVENT_FORK; |
244 | } else if (current->ptrace & PT_TRACE_FORK) | ||
245 | return PTRACE_EVENT_FORK; | ||
246 | 246 | ||
247 | return 0; | 247 | return ptrace_event_enabled(current, event) ? event : 0; |
248 | } | 248 | } |
249 | 249 | ||
250 | /** | 250 | /** |
@@ -318,7 +318,7 @@ static inline void tracehook_report_clone_complete(int trace, | |||
318 | struct task_struct *child) | 318 | struct task_struct *child) |
319 | { | 319 | { |
320 | if (unlikely(trace)) | 320 | if (unlikely(trace)) |
321 | ptrace_event(0, trace, pid); | 321 | ptrace_event(trace, pid); |
322 | } | 322 | } |
323 | 323 | ||
324 | /** | 324 | /** |
@@ -336,7 +336,7 @@ static inline void tracehook_report_clone_complete(int trace, | |||
336 | static inline void tracehook_report_vfork_done(struct task_struct *child, | 336 | static inline void tracehook_report_vfork_done(struct task_struct *child, |
337 | pid_t pid) | 337 | pid_t pid) |
338 | { | 338 | { |
339 | ptrace_event(PT_TRACE_VFORK_DONE, PTRACE_EVENT_VFORK_DONE, pid); | 339 | ptrace_event(PTRACE_EVENT_VFORK_DONE, pid); |
340 | } | 340 | } |
341 | 341 | ||
342 | /** | 342 | /** |