-/* $OpenBSD: kcov.c,v 1.40 2021/12/19 07:45:59 anton Exp $ */
+/* $OpenBSD: kcov.c,v 1.41 2021/12/21 06:08:57 anton Exp $ */
/*
* Copyright (c) 2018 Anton Lindqvist <anton@openbsd.org>
break;
case KIOENABLE:
/* Only one kcov descriptor can be enabled per thread. */
- if (p->p_kd != NULL || kd->kd_state != KCOV_STATE_READY) {
+ if (p->p_kd != NULL) {
error = EBUSY;
break;
}
+ if (kd->kd_state != KCOV_STATE_READY) {
+ error = ENXIO;
+ break;
+ }
mode = *((int *)data);
if (mode != KCOV_MODE_TRACE_PC && mode != KCOV_MODE_TRACE_CMP) {
error = EINVAL;
break;
case KIODISABLE:
/* Only the enabled thread may disable itself. */
- if ((p->p_kd != kd && kd->kd_kr == NULL) ||
- kd->kd_state != KCOV_STATE_TRACE) {
- error = EBUSY;
+ if ((p->p_kd != kd && kd->kd_kr == NULL)) {
+ error = EPERM;
+ break;
+ }
+ if (kd->kd_state != KCOV_STATE_TRACE) {
+ error = ENXIO;
break;
}
kd->kd_state = KCOV_STATE_READY;
MUTEX_ASSERT_LOCKED(&kcov_mtx);
if (kd->kd_state != KCOV_STATE_READY)
- return (EBUSY);
+ return (ENXIO);
- if (arg->subsystem == KCOV_REMOTE_COMMON)
+ if (arg->subsystem == KCOV_REMOTE_COMMON) {
kr = kcov_remote_register_locked(KCOV_REMOTE_COMMON,
curproc->p_p);
- if (kr == NULL)
+ if (kr == NULL)
+ return (EBUSY);
+ } else {
return (EINVAL);
+ }
kr->kr_state = KCOV_STATE_READY;
kr->kr_kd = kd;