-/* $OpenBSD: kcov.c,v 1.38 2021/07/05 05:50:19 anton Exp $ */
+/* $OpenBSD: kcov.c,v 1.39 2021/12/18 08:24:31 anton Exp $ */
/*
* Copyright (c) 2018 Anton Lindqvist <anton@openbsd.org>
* its corresponding coverage buffer.
*/
void
-trace_cmp(uint64_t type, uint64_t arg1, uint64_t arg2, uintptr_t pc)
+trace_cmp(struct kcov_dev *kd, uint64_t type, uint64_t arg1, uint64_t arg2,
+ uintptr_t pc)
{
- struct kcov_dev *kd;
uint64_t idx;
- kd = kd_curproc(KCOV_MODE_TRACE_CMP);
- if (kd == NULL)
- return;
-
if ((idx = kd_claim(kd, KCOV_STRIDE_TRACE_CMP, 1))) {
kd->kd_buf[idx] = type;
kd->kd_buf[idx + 1] = arg1;
}
}
+#define TRACE_CMP(type, arg1, arg2) do { \
+ struct kcov_dev *kd; \
+ if ((kd = kd_curproc(KCOV_MODE_TRACE_CMP)) == NULL) \
+ return; \
+ trace_cmp(kd, (type), (arg1), (arg2), \
+ (uintptr_t)__builtin_return_address(0)); \
+} while (0)
+
void
__sanitizer_cov_trace_cmp1(uint8_t arg1, uint8_t arg2)
{
- trace_cmp(KCOV_CMP_SIZE(0), arg1, arg2,
- (uintptr_t)__builtin_return_address(0));
+ TRACE_CMP(KCOV_CMP_SIZE(0), arg1, arg2);
}
void
__sanitizer_cov_trace_cmp2(uint16_t arg1, uint16_t arg2)
{
- trace_cmp(KCOV_CMP_SIZE(1), arg1, arg2,
- (uintptr_t)__builtin_return_address(0));
+ TRACE_CMP(KCOV_CMP_SIZE(1), arg1, arg2);
}
void
__sanitizer_cov_trace_cmp4(uint32_t arg1, uint32_t arg2)
{
- trace_cmp(KCOV_CMP_SIZE(2), arg1, arg2,
- (uintptr_t)__builtin_return_address(0));
+ TRACE_CMP(KCOV_CMP_SIZE(2), arg1, arg2);
}
void
__sanitizer_cov_trace_cmp8(uint64_t arg1, uint64_t arg2)
{
- trace_cmp(KCOV_CMP_SIZE(3), arg1, arg2,
- (uintptr_t)__builtin_return_address(0));
+ TRACE_CMP(KCOV_CMP_SIZE(3), arg1, arg2);
}
void
__sanitizer_cov_trace_const_cmp1(uint8_t arg1, uint8_t arg2)
{
- trace_cmp(KCOV_CMP_SIZE(0) | KCOV_CMP_CONST, arg1, arg2,
- (uintptr_t)__builtin_return_address(0));
+ TRACE_CMP(KCOV_CMP_SIZE(0) | KCOV_CMP_CONST, arg1, arg2);
}
void
__sanitizer_cov_trace_const_cmp2(uint16_t arg1, uint16_t arg2)
{
- trace_cmp(KCOV_CMP_SIZE(1) | KCOV_CMP_CONST, arg1, arg2,
- (uintptr_t)__builtin_return_address(0));
+ TRACE_CMP(KCOV_CMP_SIZE(1) | KCOV_CMP_CONST, arg1, arg2);
}
void
__sanitizer_cov_trace_const_cmp4(uint32_t arg1, uint32_t arg2)
{
- trace_cmp(KCOV_CMP_SIZE(2) | KCOV_CMP_CONST, arg1, arg2,
- (uintptr_t)__builtin_return_address(0));
+ TRACE_CMP(KCOV_CMP_SIZE(2) | KCOV_CMP_CONST, arg1, arg2);
}
void
__sanitizer_cov_trace_const_cmp8(uint64_t arg1, uint64_t arg2)
{
- trace_cmp(KCOV_CMP_SIZE(3) | KCOV_CMP_CONST, arg1, arg2,
- (uintptr_t)__builtin_return_address(0));
+ TRACE_CMP(KCOV_CMP_SIZE(3) | KCOV_CMP_CONST, arg1, arg2);
}
void
__sanitizer_cov_trace_switch(uint64_t val, uint64_t *cases)
{
+ struct kcov_dev *kd;
uint64_t i, nbits, ncases, type;
uintptr_t pc;
+ kd = kd_curproc(KCOV_MODE_TRACE_CMP);
+ if (kd == NULL)
+ return;
+
pc = (uintptr_t)__builtin_return_address(0);
ncases = cases[0];
nbits = cases[1];
type |= KCOV_CMP_CONST;
for (i = 0; i < ncases; i++)
- trace_cmp(type, cases[i + 2], val, pc);
+ trace_cmp(kd, type, cases[i + 2], val, pc);
}
void