0001
0002 #ifndef _LINUX_KCOV_H
0003 #define _LINUX_KCOV_H
0004
0005 #include <linux/sched.h>
0006 #include <uapi/linux/kcov.h>
0007
0008 struct task_struct;
0009
0010 #ifdef CONFIG_KCOV
0011
0012 enum kcov_mode {
0013
0014 KCOV_MODE_DISABLED = 0,
0015
0016 KCOV_MODE_INIT = 1,
0017
0018
0019
0020
0021 KCOV_MODE_TRACE_PC = 2,
0022
0023 KCOV_MODE_TRACE_CMP = 3,
0024 };
0025
0026 #define KCOV_IN_CTXSW (1 << 30)
0027
0028 void kcov_task_init(struct task_struct *t);
0029 void kcov_task_exit(struct task_struct *t);
0030
0031 #define kcov_prepare_switch(t) \
0032 do { \
0033 (t)->kcov_mode |= KCOV_IN_CTXSW; \
0034 } while (0)
0035
0036 #define kcov_finish_switch(t) \
0037 do { \
0038 (t)->kcov_mode &= ~KCOV_IN_CTXSW; \
0039 } while (0)
0040
0041
0042 void kcov_remote_start(u64 handle);
0043 void kcov_remote_stop(void);
0044 u64 kcov_common_handle(void);
0045
0046 static inline void kcov_remote_start_common(u64 id)
0047 {
0048 kcov_remote_start(kcov_remote_handle(KCOV_SUBSYSTEM_COMMON, id));
0049 }
0050
0051 static inline void kcov_remote_start_usb(u64 id)
0052 {
0053 kcov_remote_start(kcov_remote_handle(KCOV_SUBSYSTEM_USB, id));
0054 }
0055
0056
0057
0058
0059
0060
0061
0062
0063 static inline void kcov_remote_start_usb_softirq(u64 id)
0064 {
0065 if (in_serving_softirq())
0066 kcov_remote_start_usb(id);
0067 }
0068
0069 static inline void kcov_remote_stop_softirq(void)
0070 {
0071 if (in_serving_softirq())
0072 kcov_remote_stop();
0073 }
0074
0075 #else
0076
0077 static inline void kcov_task_init(struct task_struct *t) {}
0078 static inline void kcov_task_exit(struct task_struct *t) {}
0079 static inline void kcov_prepare_switch(struct task_struct *t) {}
0080 static inline void kcov_finish_switch(struct task_struct *t) {}
0081 static inline void kcov_remote_start(u64 handle) {}
0082 static inline void kcov_remote_stop(void) {}
0083 static inline u64 kcov_common_handle(void)
0084 {
0085 return 0;
0086 }
0087 static inline void kcov_remote_start_common(u64 id) {}
0088 static inline void kcov_remote_start_usb(u64 id) {}
0089 static inline void kcov_remote_start_usb_softirq(u64 id) {}
0090 static inline void kcov_remote_stop_softirq(void) {}
0091
0092 #endif
0093 #endif