blob: b76a1807028ddcdd41df38064a174d36d8748646 [file] [log] [blame]
Greg Kroah-Hartmanb2441312017-11-01 15:07:57 +01001/* SPDX-License-Identifier: GPL-2.0 */
Dmitry Vyukov5c9a8752016-03-22 14:27:30 -07002#ifndef _LINUX_KCOV_H
3#define _LINUX_KCOV_H
4
5#include <uapi/linux/kcov.h>
6
7struct task_struct;
8
9#ifdef CONFIG_KCOV
10
Dmitry Vyukov5c9a8752016-03-22 14:27:30 -070011enum kcov_mode {
12 /* Coverage collection is not enabled yet. */
13 KCOV_MODE_DISABLED = 0,
Victor Chibotaruded97d22017-11-17 15:30:46 -080014 /* KCOV was initialized, but tracing mode hasn't been chosen yet. */
15 KCOV_MODE_INIT = 1,
Dmitry Vyukov5c9a8752016-03-22 14:27:30 -070016 /*
17 * Tracing coverage collection mode.
18 * Covered PCs are collected in a per-task buffer.
19 */
Victor Chibotaruded97d22017-11-17 15:30:46 -080020 KCOV_MODE_TRACE_PC = 2,
21 /* Collecting comparison operands mode. */
22 KCOV_MODE_TRACE_CMP = 3,
Dmitry Vyukov5c9a8752016-03-22 14:27:30 -070023};
24
Mark Rutland0ed557a2018-06-14 15:27:41 -070025#define KCOV_IN_CTXSW (1 << 30)
26
Victor Chibotaruded97d22017-11-17 15:30:46 -080027void kcov_task_init(struct task_struct *t);
28void kcov_task_exit(struct task_struct *t);
29
Mark Rutland0ed557a2018-06-14 15:27:41 -070030#define kcov_prepare_switch(t) \
31do { \
32 (t)->kcov_mode |= KCOV_IN_CTXSW; \
33} while (0)
34
35#define kcov_finish_switch(t) \
36do { \
37 (t)->kcov_mode &= ~KCOV_IN_CTXSW; \
38} while (0)
39
Dmitry Vyukov5c9a8752016-03-22 14:27:30 -070040#else
41
42static inline void kcov_task_init(struct task_struct *t) {}
43static inline void kcov_task_exit(struct task_struct *t) {}
Mark Rutland0ed557a2018-06-14 15:27:41 -070044static inline void kcov_prepare_switch(struct task_struct *t) {}
45static inline void kcov_finish_switch(struct task_struct *t) {}
Dmitry Vyukov5c9a8752016-03-22 14:27:30 -070046
47#endif /* CONFIG_KCOV */
48#endif /* _LINUX_KCOV_H */