2 * utrace infrastructure interface for debugging user processes
4 * Copyright (C) 2006-2009 Red Hat, Inc. All rights reserved.
6 * This copyrighted material is made available to anyone wishing to use,
7 * modify, copy, or redistribute it subject to the terms and conditions
8 * of the GNU General Public License v.2.
10 * Red Hat Author: Roland McGrath.
12 * This interface allows for notification of interesting events in a
13 * thread. It also mediates access to thread state such as registers.
14 * Multiple unrelated users can be associated with a single thread.
15 * We call each of these a tracing engine.
17 * A tracing engine starts by calling utrace_attach_task() or
18 * utrace_attach_pid() on the chosen thread, passing in a set of hooks
19 * (&struct utrace_engine_ops), and some associated data. This produces a
20 * &struct utrace_engine, which is the handle used for all other
21 * operations. An attached engine has its ops vector, its data, and an
22 * event mask controlled by utrace_set_events().
24 * For each event bit that is set, that engine will get the
25 * appropriate ops->report_*() callback when the event occurs. The
26 * &struct utrace_engine_ops need not provide callbacks for an event
27 * unless the engine sets one of the associated event bits.
30 #ifndef _LINUX_UTRACE_H
31 #define _LINUX_UTRACE_H 1
33 #include <linux/list.h>
34 #include <linux/kref.h>
35 #include <linux/signal.h>
36 #include <linux/sched.h>
42 struct user_regset_view
;
45 * Event bits passed to utrace_set_events().
46 * These appear in &struct task_struct.@utrace_flags
47 * and &struct utrace_engine.@flags.
50 _UTRACE_EVENT_QUIESCE
, /* Thread is available for examination. */
51 _UTRACE_EVENT_REAP
, /* Zombie reaped, no more tracing possible. */
52 _UTRACE_EVENT_CLONE
, /* Successful clone/fork/vfork just done. */
53 _UTRACE_EVENT_EXEC
, /* Successful execve just completed. */
54 _UTRACE_EVENT_EXIT
, /* Thread exit in progress. */
55 _UTRACE_EVENT_DEATH
, /* Thread has died. */
56 _UTRACE_EVENT_SYSCALL_ENTRY
, /* User entered kernel for system call. */
57 _UTRACE_EVENT_SYSCALL_EXIT
, /* Returning to user after system call. */
58 _UTRACE_EVENT_SIGNAL
, /* Signal delivery will run a user handler. */
59 _UTRACE_EVENT_SIGNAL_IGN
, /* No-op signal to be delivered. */
60 _UTRACE_EVENT_SIGNAL_STOP
, /* Signal delivery will suspend. */
61 _UTRACE_EVENT_SIGNAL_TERM
, /* Signal delivery will terminate. */
62 _UTRACE_EVENT_SIGNAL_CORE
, /* Signal delivery will dump core. */
63 _UTRACE_EVENT_JCTL
, /* Job control stop or continue completed. */
66 #define UTRACE_EVENT(type) (1UL << _UTRACE_EVENT_##type)
69 * All the kinds of signal events.
70 * These all use the @report_signal() callback.
72 #define UTRACE_EVENT_SIGNAL_ALL (UTRACE_EVENT(SIGNAL) \
73 | UTRACE_EVENT(SIGNAL_IGN) \
74 | UTRACE_EVENT(SIGNAL_STOP) \
75 | UTRACE_EVENT(SIGNAL_TERM) \
76 | UTRACE_EVENT(SIGNAL_CORE))
78 * Both kinds of syscall events; these call the @report_syscall_entry()
79 * and @report_syscall_exit() callbacks, respectively.
81 #define UTRACE_EVENT_SYSCALL \
82 (UTRACE_EVENT(SYSCALL_ENTRY) | UTRACE_EVENT(SYSCALL_EXIT))
85 * The event reports triggered synchronously by task death.
87 #define _UTRACE_DEATH_EVENTS (UTRACE_EVENT(DEATH) | UTRACE_EVENT(QUIESCE))
90 * Hooks in <linux/tracehook.h> call these entry points to the
91 * utrace dispatch. They are weak references here only so
92 * tracehook.h doesn't need to #ifndef CONFIG_UTRACE them to
93 * avoid external references in case of unoptimized compilation.
95 bool utrace_interrupt_pending(void)
96 __attribute__((weak
));
97 void utrace_resume(struct task_struct
*, struct pt_regs
*)
98 __attribute__((weak
));
99 int utrace_get_signal(struct task_struct
*, struct pt_regs
*,
100 siginfo_t
*, struct k_sigaction
*)
101 __attribute__((weak
));
102 void utrace_report_clone(unsigned long, struct task_struct
*)
103 __attribute__((weak
));
104 void utrace_finish_vfork(struct task_struct
*)
105 __attribute__((weak
));
106 void utrace_report_exit(long *exit_code
)
107 __attribute__((weak
));
108 void utrace_report_death(struct task_struct
*, struct utrace
*, bool, int)
109 __attribute__((weak
));
110 void utrace_report_jctl(int notify
, int type
)
111 __attribute__((weak
));
112 void utrace_report_exec(struct linux_binfmt
*, struct linux_binprm
*,
113 struct pt_regs
*regs
)
114 __attribute__((weak
));
115 bool utrace_report_syscall_entry(struct pt_regs
*)
116 __attribute__((weak
));
117 void utrace_report_syscall_exit(struct pt_regs
*)
118 __attribute__((weak
));
119 void utrace_signal_handler(struct task_struct
*, int)
120 __attribute__((weak
));
122 #ifndef CONFIG_UTRACE
125 * <linux/tracehook.h> uses these accessors to avoid #ifdef CONFIG_UTRACE.
127 static inline unsigned long task_utrace_flags(struct task_struct
*task
)
131 static inline struct utrace
*task_utrace_struct(struct task_struct
*task
)
135 static inline void utrace_init_task(struct task_struct
*child
)
138 static inline void utrace_release_task(struct task_struct
*task
)
142 static inline void task_utrace_proc_status(struct seq_file
*m
,
143 struct task_struct
*p
)
147 #else /* CONFIG_UTRACE */
149 static inline unsigned long task_utrace_flags(struct task_struct
*task
)
151 return task
->utrace_flags
;
154 static inline struct utrace
*task_utrace_struct(struct task_struct
*task
)
156 return &task
->utrace
;
159 static inline void utrace_init_task(struct task_struct
*task
)
161 task
->utrace_flags
= 0;
162 memset(&task
->utrace
, 0, sizeof(task
->utrace
));
163 INIT_LIST_HEAD(&task
->utrace
.attached
);
164 INIT_LIST_HEAD(&task
->utrace
.attaching
);
165 spin_lock_init(&task
->utrace
.lock
);
168 void utrace_release_task(struct task_struct
*);
169 void task_utrace_proc_status(struct seq_file
*m
, struct task_struct
*p
);
173 * Version number of the API defined in this file. This will change
174 * whenever a tracing engine's code would need some updates to keep
175 * working. We maintain this here for the benefit of tracing engine code
176 * that is developed concurrently with utrace API improvements before they
177 * are merged into the kernel, making LINUX_VERSION_CODE checks unwieldy.
179 #define UTRACE_API_VERSION 20090302
182 * enum utrace_resume_action - engine's choice of action for a traced task
183 * @UTRACE_STOP: Stay quiescent after callbacks.
184 * @UTRACE_REPORT: Make some callback soon.
185 * @UTRACE_INTERRUPT: Make @report_signal() callback soon.
186 * @UTRACE_SINGLESTEP: Resume in user mode for one instruction.
187 * @UTRACE_BLOCKSTEP: Resume in user mode until next branch.
188 * @UTRACE_RESUME: Resume normally in user mode.
189 * @UTRACE_DETACH: Detach my engine (implies %UTRACE_RESUME).
191 * See utrace_control() for detailed descriptions of each action. This is
192 * encoded in the @action argument and the return value for every callback
193 * with a &u32 return value.
195 * The order of these is important. When there is more than one engine,
196 * each supplies its choice and the smallest value prevails.
198 enum utrace_resume_action
{
207 #define UTRACE_RESUME_MASK 0x0f
210 * utrace_resume_action - &enum utrace_resume_action from callback action
211 * @action: &u32 callback @action argument or return value
213 * This extracts the &enum utrace_resume_action from @action,
214 * which is the @action argument to a &struct utrace_engine_ops
215 * callback or the return value from one.
217 static inline enum utrace_resume_action
utrace_resume_action(u32 action
)
219 return action
& UTRACE_RESUME_MASK
;
223 * enum utrace_signal_action - disposition of signal
224 * @UTRACE_SIGNAL_DELIVER: Deliver according to sigaction.
225 * @UTRACE_SIGNAL_IGN: Ignore the signal.
226 * @UTRACE_SIGNAL_TERM: Terminate the process.
227 * @UTRACE_SIGNAL_CORE: Terminate with core dump.
228 * @UTRACE_SIGNAL_STOP: Deliver as absolute stop.
229 * @UTRACE_SIGNAL_TSTP: Deliver as job control stop.
230 * @UTRACE_SIGNAL_REPORT: Reporting before pending signals.
231 * @UTRACE_SIGNAL_HANDLER: Reporting after signal handler setup.
233 * This is encoded in the @action argument and the return value for
234 * a @report_signal() callback. It says what will happen to the
235 * signal described by the &siginfo_t parameter to the callback.
237 * The %UTRACE_SIGNAL_REPORT value is used in an @action argument when
238 * a tracing report is being made before dequeuing any pending signal.
239 * If this is immediately after a signal handler has been set up, then
240 * %UTRACE_SIGNAL_HANDLER is used instead. A @report_signal callback
241 * that uses %UTRACE_SIGNAL_DELIVER|%UTRACE_SINGLESTEP will ensure
242 * it sees a %UTRACE_SIGNAL_HANDLER report.
244 enum utrace_signal_action
{
245 UTRACE_SIGNAL_DELIVER
= 0x00,
246 UTRACE_SIGNAL_IGN
= 0x10,
247 UTRACE_SIGNAL_TERM
= 0x20,
248 UTRACE_SIGNAL_CORE
= 0x30,
249 UTRACE_SIGNAL_STOP
= 0x40,
250 UTRACE_SIGNAL_TSTP
= 0x50,
251 UTRACE_SIGNAL_REPORT
= 0x60,
252 UTRACE_SIGNAL_HANDLER
= 0x70
254 #define UTRACE_SIGNAL_MASK 0xf0
255 #define UTRACE_SIGNAL_HOLD 0x100 /* Flag, push signal back on queue. */
258 * utrace_signal_action - &enum utrace_signal_action from callback action
259 * @action: @report_signal callback @action argument or return value
261 * This extracts the &enum utrace_signal_action from @action, which
262 * is the @action argument to a @report_signal callback or the
263 * return value from one.
265 static inline enum utrace_signal_action
utrace_signal_action(u32 action
)
267 return action
& UTRACE_SIGNAL_MASK
;
271 * enum utrace_syscall_action - disposition of system call attempt
272 * @UTRACE_SYSCALL_RUN: Run the system call.
273 * @UTRACE_SYSCALL_ABORT: Don't run the system call.
275 * This is encoded in the @action argument and the return value for
276 * a @report_syscall_entry callback.
278 enum utrace_syscall_action
{
279 UTRACE_SYSCALL_RUN
= 0x00,
280 UTRACE_SYSCALL_ABORT
= 0x10
282 #define UTRACE_SYSCALL_MASK 0xf0
285 * utrace_syscall_action - &enum utrace_syscall_action from callback action
286 * @action: @report_syscall_entry callback @action or return value
288 * This extracts the &enum utrace_syscall_action from @action, which
289 * is the @action argument to a @report_syscall_entry callback or the
290 * return value from one.
292 static inline enum utrace_syscall_action
utrace_syscall_action(u32 action
)
294 return action
& UTRACE_SYSCALL_MASK
;
298 * Flags for utrace_attach_task() and utrace_attach_pid().
300 #define UTRACE_ATTACH_CREATE 0x0010 /* Attach a new engine. */
301 #define UTRACE_ATTACH_EXCLUSIVE 0x0020 /* Refuse if existing match. */
302 #define UTRACE_ATTACH_MATCH_OPS 0x0001 /* Match engines on ops. */
303 #define UTRACE_ATTACH_MATCH_DATA 0x0002 /* Match engines on data. */
304 #define UTRACE_ATTACH_MATCH_MASK 0x000f
307 * struct utrace_engine - per-engine structure
308 * @ops: &struct utrace_engine_ops pointer passed to utrace_attach_task()
309 * @data: engine-private &void * passed to utrace_attach_task()
310 * @flags: event mask set by utrace_set_events() plus internal flag bits
312 * The task itself never has to worry about engines detaching while
313 * it's doing event callbacks. These structures are removed from the
314 * task's active list only when it's stopped, or by the task itself.
316 * utrace_engine_get() and utrace_engine_put() maintain a reference count.
317 * When it drops to zero, the structure is freed. One reference is held
318 * implicitly while the engine is attached to its task.
320 struct utrace_engine
{
323 struct list_head entry
;
326 const struct utrace_engine_ops
*ops
;
333 * utrace_engine_get - acquire a reference on a &struct utrace_engine
334 * @engine: &struct utrace_engine pointer
336 * You must hold a reference on @engine, and you get another.
338 static inline void utrace_engine_get(struct utrace_engine
*engine
)
340 kref_get(&engine
->kref
);
343 void __utrace_engine_release(struct kref
*);
346 * utrace_engine_put - release a reference on a &struct utrace_engine
347 * @engine: &struct utrace_engine pointer
349 * You must hold a reference on @engine, and you lose that reference.
350 * If it was the last one, @engine becomes an invalid pointer.
352 static inline void utrace_engine_put(struct utrace_engine
*engine
)
354 kref_put(&engine
->kref
, __utrace_engine_release
);
358 * struct utrace_engine_ops - tracing engine callbacks
360 * Each @report_*() callback corresponds to an %UTRACE_EVENT(*) bit.
361 * utrace_set_events() calls on @engine choose which callbacks will be made
362 * to @engine from @task.
364 * Most callbacks take an @action argument, giving the resume action
365 * chosen by other tracing engines. All callbacks take an @engine
366 * argument, and a @task argument, which is always equal to @current.
367 * For some calls, @action also includes bits specific to that event
368 * and utrace_resume_action() is used to extract the resume action.
369 * This shows what would happen if @engine wasn't there, or will if
370 * the callback's return value uses %UTRACE_RESUME. This always
371 * starts as %UTRACE_RESUME when no other tracing is being done on
374 * All return values contain &enum utrace_resume_action bits. For
375 * some calls, other bits specific to that kind of event are added to
376 * the resume action bits with OR. These are the same bits used in
377 * the @action argument. The resume action returned by a callback
378 * does not override previous engines' choices, it only says what
379 * @engine wants done. What @task actually does is the action that's
380 * most constrained among the choices made by all attached engines.
381 * See utrace_control() for more information on the actions.
383 * When %UTRACE_STOP is used in @report_syscall_entry, then @task
384 * stops before attempting the system call. In other cases, the
385 * resume action does not take effect until @task is ready to check
386 * for signals and return to user mode. If there are more callbacks
387 * to be made, the last round of calls determines the final action.
388 * A @report_quiesce callback with @event zero, or a @report_signal
389 * callback, will always be the last one made before @task resumes.
390 * Only %UTRACE_STOP is "sticky"--if @engine returned %UTRACE_STOP
391 * then @task stays stopped unless @engine returns different from a
392 * following callback.
394 * The report_death() and report_reap() callbacks do not take @action
395 * arguments, and only %UTRACE_DETACH is meaningful in the return value
396 * from a report_death() callback. None of the resume actions applies
399 * All @report_*() hooks are called with no locks held, in a generally
400 * safe environment when we will be returning to user mode soon (or just
401 * entered the kernel). It is fine to block for memory allocation and
402 * the like, but all hooks are asynchronous and must not block on
403 * external events! If you want the thread to block, use %UTRACE_STOP
404 * in your hook's return value; then later wake it up with utrace_control().
407 * Requested by %UTRACE_EVENT(%QUIESCE).
408 * This does not indicate any event, but just that @task (the current
409 * thread) is in a safe place for examination. This call is made
410 * before each specific event callback, except for @report_reap.
411 * The @event argument gives the %UTRACE_EVENT(@which) value for
412 * the event occurring. This callback might be made for events @engine
413 * has not requested, if some other engine is tracing the event;
414 * calling utrace_set_events() call here can request the immediate
415 * callback for this occurrence of @event. @event is zero when there
416 * is no other event, @task is now ready to check for signals and
417 * return to user mode, and some engine has used %UTRACE_REPORT or
418 * %UTRACE_INTERRUPT to request this callback. For this case,
419 * if @report_signal is not %NULL, the @report_quiesce callback
420 * may be replaced with a @report_signal callback passing
421 * %UTRACE_SIGNAL_REPORT in its @action argument, whenever @task is
422 * entering the signal-check path anyway.
425 * Requested by %UTRACE_EVENT(%SIGNAL_*) or %UTRACE_EVENT(%QUIESCE).
426 * Use utrace_signal_action() and utrace_resume_action() on @action.
427 * The signal action is %UTRACE_SIGNAL_REPORT when some engine has
428 * used %UTRACE_REPORT or %UTRACE_INTERRUPT; the callback can choose
429 * to stop or to deliver an artificial signal, before pending signals.
430 * It's %UTRACE_SIGNAL_HANDLER instead when signal handler setup just
431 * finished (after a previous %UTRACE_SIGNAL_DELIVER return); this
432 * serves in lieu of any %UTRACE_SIGNAL_REPORT callback requested by
433 * %UTRACE_REPORT or %UTRACE_INTERRUPT, and is also implicitly
434 * requested by %UTRACE_SINGLESTEP or %UTRACE_BLOCKSTEP into the
435 * signal delivery. The other signal actions indicate a signal about
436 * to be delivered; the previous engine's return value sets the signal
437 * action seen by the the following engine's callback. The @info data
438 * can be changed at will, including @info->si_signo. The settings in
439 * @return_ka determines what %UTRACE_SIGNAL_DELIVER does. @orig_ka
440 * is what was in force before other tracing engines intervened, and
441 * it's %NULL when this report began as %UTRACE_SIGNAL_REPORT or
442 * %UTRACE_SIGNAL_HANDLER. For a report without a new signal, @info
443 * is left uninitialized and must be set completely by an engine that
444 * chooses to deliver a signal; if there was a previous @report_signal
445 * callback ending in %UTRACE_STOP and it was just resumed using
446 * %UTRACE_REPORT or %UTRACE_INTERRUPT, then @info is left unchanged
447 * from the previous callback. In this way, the original signal can
448 * be left in @info while returning %UTRACE_STOP|%UTRACE_SIGNAL_IGN
449 * and then found again when resuming @task with %UTRACE_INTERRUPT.
450 * The %UTRACE_SIGNAL_HOLD flag bit can be OR'd into the return value,
451 * and might be in @action if the previous engine returned it. This
452 * flag asks that the signal in @info be pushed back on @task's queue
453 * so that it will be seen again after whatever action is taken now.
456 * Requested by %UTRACE_EVENT(%CLONE).
457 * Event reported for parent, before the new task @child might run.
458 * @clone_flags gives the flags used in the clone system call,
459 * or equivalent flags for a fork() or vfork() system call.
460 * This function can use utrace_attach_task() on @child. It's guaranteed
461 * that asynchronous utrace_attach_task() calls will be ordered after
462 * any calls in @report_clone callbacks for the parent. Thus
463 * when using %UTRACE_ATTACH_EXCLUSIVE in the asynchronous calls,
464 * you can be sure that the parent's @report_clone callback has
465 * already attached to @child or chosen not to. Passing %UTRACE_STOP
466 * to utrace_control() on @child here keeps the child stopped before
467 * it ever runs in user mode, %UTRACE_REPORT or %UTRACE_INTERRUPT
468 * ensures a callback from @child before it starts in user mode.
471 * Requested by %UTRACE_EVENT(%JCTL).
472 * Job control event; @type is %CLD_STOPPED or %CLD_CONTINUED,
473 * indicating whether we are stopping or resuming now. If @notify
474 * is nonzero, @task is the last thread to stop and so will send
475 * %SIGCHLD to its parent after this callback; @notify reflects
476 * what the parent's %SIGCHLD has in @si_code, which can sometimes
477 * be %CLD_STOPPED even when @type is %CLD_CONTINUED.
480 * Requested by %UTRACE_EVENT(%EXEC).
481 * An execve system call has succeeded and the new program is about to
482 * start running. The initial user register state is handy to be tweaked
483 * directly in @regs. @fmt and @bprm gives the details of this exec.
485 * @report_syscall_entry:
486 * Requested by %UTRACE_EVENT(%SYSCALL_ENTRY).
487 * Thread has entered the kernel to request a system call.
488 * The user register state is handy to be tweaked directly in @regs.
489 * The @action argument contains an &enum utrace_syscall_action,
490 * use utrace_syscall_action() to extract it. The return value
491 * overrides the last engine's action for the system call.
492 * If the final action is %UTRACE_SYSCALL_ABORT, no system call
493 * is made. The details of the system call being attempted can
494 * be fetched here with syscall_get_nr() and syscall_get_arguments().
495 * The parameter registers can be changed with syscall_set_arguments().
497 * @report_syscall_exit:
498 * Requested by %UTRACE_EVENT(%SYSCALL_EXIT).
499 * Thread is about to leave the kernel after a system call request.
500 * The user register state is handy to be tweaked directly in @regs.
501 * The results of the system call attempt can be examined here using
502 * syscall_get_error() and syscall_get_return_value(). It is safe
503 * here to call syscall_set_return_value() or syscall_rollback().
506 * Requested by %UTRACE_EVENT(%EXIT).
507 * Thread is exiting and cannot be prevented from doing so,
508 * but all its state is still live. The @code value will be
509 * the wait result seen by the parent, and can be changed by
510 * this engine or others. The @orig_code value is the real
511 * status, not changed by any tracing engine. Returning %UTRACE_STOP
512 * here keeps @task stopped before it cleans up its state and dies,
513 * so it can be examined by other processes. When @task is allowed
514 * to run, it will die and get to the @report_death callback.
517 * Requested by %UTRACE_EVENT(%DEATH).
518 * Thread is really dead now. It might be reaped by its parent at
519 * any time, or self-reap immediately. Though the actual reaping
520 * may happen in parallel, a report_reap() callback will always be
521 * ordered after a report_death() callback.
524 * Requested by %UTRACE_EVENT(%REAP).
525 * Called when someone reaps the dead task (parent, init, or self).
526 * This means the parent called wait, or else this was a detached
527 * thread or a process whose parent ignores SIGCHLD.
528 * No more callbacks are made after this one.
529 * The engine is always detached.
530 * There is nothing more a tracing engine can do about this thread.
531 * After this callback, the @engine pointer will become invalid.
532 * The @task pointer may become invalid if get_task_struct() hasn't
533 * been used to keep it alive.
534 * An engine should always request this callback if it stores the
535 * @engine pointer or stores any pointer in @engine->data, so it
536 * can clean up its data structures.
537 * Unlike other callbacks, this can be called from the parent's context
538 * rather than from the traced thread itself--it must not delay the
539 * parent by blocking.
541 struct utrace_engine_ops
{
542 u32 (*report_quiesce
)(enum utrace_resume_action action
,
543 struct utrace_engine
*engine
,
544 struct task_struct
*task
,
545 unsigned long event
);
546 u32 (*report_signal
)(u32 action
,
547 struct utrace_engine
*engine
,
548 struct task_struct
*task
,
549 struct pt_regs
*regs
,
551 const struct k_sigaction
*orig_ka
,
552 struct k_sigaction
*return_ka
);
553 u32 (*report_clone
)(enum utrace_resume_action action
,
554 struct utrace_engine
*engine
,
555 struct task_struct
*parent
,
556 unsigned long clone_flags
,
557 struct task_struct
*child
);
558 u32 (*report_jctl
)(enum utrace_resume_action action
,
559 struct utrace_engine
*engine
,
560 struct task_struct
*task
,
561 int type
, int notify
);
562 u32 (*report_exec
)(enum utrace_resume_action action
,
563 struct utrace_engine
*engine
,
564 struct task_struct
*task
,
565 const struct linux_binfmt
*fmt
,
566 const struct linux_binprm
*bprm
,
567 struct pt_regs
*regs
);
568 u32 (*report_syscall_entry
)(u32 action
,
569 struct utrace_engine
*engine
,
570 struct task_struct
*task
,
571 struct pt_regs
*regs
);
572 u32 (*report_syscall_exit
)(enum utrace_resume_action action
,
573 struct utrace_engine
*engine
,
574 struct task_struct
*task
,
575 struct pt_regs
*regs
);
576 u32 (*report_exit
)(enum utrace_resume_action action
,
577 struct utrace_engine
*engine
,
578 struct task_struct
*task
,
579 long orig_code
, long *code
);
580 u32 (*report_death
)(struct utrace_engine
*engine
,
581 struct task_struct
*task
,
582 bool group_dead
, int signal
);
583 void (*report_reap
)(struct utrace_engine
*engine
,
584 struct task_struct
*task
);
588 * struct utrace_examiner - private state for using utrace_prepare_examine()
590 * The members of &struct utrace_examiner are private to the implementation.
591 * This data type holds the state from a call to utrace_prepare_examine()
592 * to be used by a call to utrace_finish_examine().
594 struct utrace_examiner
{
601 * These are the exported entry points for tracing engines to use.
602 * See kernel/utrace.c for their kerneldoc comments with interface details.
604 struct utrace_engine
*utrace_attach_task(struct task_struct
*, int,
605 const struct utrace_engine_ops
*,
607 struct utrace_engine
*utrace_attach_pid(struct pid
*, int,
608 const struct utrace_engine_ops
*,
610 int __must_check
utrace_control(struct task_struct
*,
611 struct utrace_engine
*,
612 enum utrace_resume_action
);
613 int __must_check
utrace_set_events(struct task_struct
*,
614 struct utrace_engine
*,
615 unsigned long eventmask
);
616 int __must_check
utrace_barrier(struct task_struct
*,
617 struct utrace_engine
*);
618 int __must_check
utrace_prepare_examine(struct task_struct
*,
619 struct utrace_engine
*,
620 struct utrace_examiner
*);
621 int __must_check
utrace_finish_examine(struct task_struct
*,
622 struct utrace_engine
*,
623 struct utrace_examiner
*);
626 * utrace_control_pid - control a thread being traced by a tracing engine
627 * @pid: thread to affect
628 * @engine: attached engine to affect
629 * @action: &enum utrace_resume_action for thread to do
631 * This is the same as utrace_control(), but takes a &struct pid
632 * pointer rather than a &struct task_struct pointer. The caller must
633 * hold a ref on @pid, but does not need to worry about the task
634 * staying valid. If it's been reaped so that @pid points nowhere,
635 * then this call returns -%ESRCH.
637 static inline __must_check
int utrace_control_pid(
638 struct pid
*pid
, struct utrace_engine
*engine
,
639 enum utrace_resume_action action
)
642 * We don't bother with rcu_read_lock() here to protect the
643 * task_struct pointer, because utrace_control will return
644 * -ESRCH without looking at that pointer if the engine is
645 * already detached. A task_struct pointer can't die before
646 * all the engines are detached in release_task() first.
648 struct task_struct
*task
= pid_task(pid
, PIDTYPE_PID
);
649 return unlikely(!task
) ? -ESRCH
: utrace_control(task
, engine
, action
);
653 * utrace_set_events_pid - choose which event reports a tracing engine gets
654 * @pid: thread to affect
655 * @engine: attached engine to affect
656 * @eventmask: new event mask
658 * This is the same as utrace_set_events(), but takes a &struct pid
659 * pointer rather than a &struct task_struct pointer. The caller must
660 * hold a ref on @pid, but does not need to worry about the task
661 * staying valid. If it's been reaped so that @pid points nowhere,
662 * then this call returns -%ESRCH.
664 static inline __must_check
int utrace_set_events_pid(
665 struct pid
*pid
, struct utrace_engine
*engine
, unsigned long eventmask
)
667 struct task_struct
*task
= pid_task(pid
, PIDTYPE_PID
);
668 return unlikely(!task
) ? -ESRCH
:
669 utrace_set_events(task
, engine
, eventmask
);
673 * utrace_barrier_pid - synchronize with simultaneous tracing callbacks
674 * @pid: thread to affect
675 * @engine: engine to affect (can be detached)
677 * This is the same as utrace_barrier(), but takes a &struct pid
678 * pointer rather than a &struct task_struct pointer. The caller must
679 * hold a ref on @pid, but does not need to worry about the task
680 * staying valid. If it's been reaped so that @pid points nowhere,
681 * then this call returns -%ESRCH.
683 static inline __must_check
int utrace_barrier_pid(struct pid
*pid
,
684 struct utrace_engine
*engine
)
686 struct task_struct
*task
= pid_task(pid
, PIDTYPE_PID
);
687 return unlikely(!task
) ? -ESRCH
: utrace_barrier(task
, engine
);
690 #endif /* CONFIG_UTRACE */
692 #endif /* linux/utrace.h */