Hi,
As a next step, let KIOENABLE accept the desired tracing mode. The API
matches the kcov implementation found both in Linux and FreeBSD. As far
as I know, syzkaller is the only kcov consumer in the wild and I will
make sure to adapt the new API there.

Comments? OK?

Index: share/man/man4/kcov.4
===================================================================
RCS file: /cvs/src/share/man/man4/kcov.4,v
retrieving revision 1.5
diff -u -p -r1.5 kcov.4
--- share/man/man4/kcov.4       30 Sep 2018 09:14:43 -0000      1.5
+++ share/man/man4/kcov.4       27 Dec 2018 10:35:13 -0000
@@ -57,8 +57,16 @@ whereas the returned pointer must be int
 entries.
 The first entry contains the number of entries in the array,
 excluding the first entry.
-.It Dv KIOENABLE Fa void
+.It Dv KIOENABLE Fa int *mode
 Enable code coverage tracing for the current thread.
+The
+.Fa mode
+must be one of the following:
+.Pp
+.Bl -tag -width KCOV_MODE_TRACE_PC -compact
+.It KCOV_MODE_TRACE_PC
+Trace the kernel program counter.
+.El
 .It Dv KIODISABLE Fa void
 Disable code coverage tracing for the current thread.
 .El
@@ -91,7 +99,7 @@ main(void)
 {
        unsigned long *cover, i;
        unsigned long size = 1024;
-       int fd;
+       int fd, mode;
 
        fd = open("/dev/kcov", O_RDWR);
        if (fd == -1)
@@ -104,7 +112,8 @@ main(void)
        if (cover == MAP_FAILED)
                err(1, "mmap");
 
-       if (ioctl(fd, KIOENABLE) == -1)
+       mode = KCOV_MODE_TRACE_PC;
+       if (ioctl(fd, KIOENABLE, &mode) == -1)
                err(1, "ioctl: KIOENABLE");
        read(-1, NULL, 0);
        if (ioctl(fd, KIODISABLE) == -1)
Index: sys/dev/kcov.c
===================================================================
RCS file: /cvs/src/sys/dev/kcov.c,v
retrieving revision 1.7
diff -u -p -r1.7 kcov.c
--- sys/dev/kcov.c      27 Dec 2018 10:04:16 -0000      1.7
+++ sys/dev/kcov.c      27 Dec 2018 10:35:13 -0000
@@ -155,6 +155,7 @@ int
 kcovioctl(dev_t dev, u_long cmd, caddr_t data, int flag, struct proc *p)
 {
        struct kcov_dev *kd;
+       int mode;
        int error = 0;
 
        kd = kd_lookup(minor(dev));
@@ -171,8 +172,13 @@ kcovioctl(dev_t dev, u_long cmd, caddr_t
                        error = EBUSY;
                        break;
                }
+               mode = *((int *)data);
+               if (mode != KCOV_MODE_TRACE_PC) {
+                       error = EINVAL;
+                       break;
+               }
                kd->kd_state = KCOV_STATE_TRACE;
-               kd->kd_mode = KCOV_MODE_TRACE_PC;
+               kd->kd_mode = mode;
                p->p_kd = kd;
                break;
        case KIODISABLE:
Index: sys/sys/kcov.h
===================================================================
RCS file: /cvs/src/sys/sys/kcov.h,v
retrieving revision 1.2
diff -u -p -r1.2 kcov.h
--- sys/sys/kcov.h      27 Dec 2018 10:04:16 -0000      1.2
+++ sys/sys/kcov.h      27 Dec 2018 10:35:13 -0000
@@ -22,7 +22,7 @@
 #include <sys/ioccom.h>
 
 #define KIOSETBUFSIZE  _IOW('K', 1, unsigned long)
-#define KIOENABLE      _IO('K', 2)
+#define KIOENABLE      _IOW('K', 2, int)
 #define KIODISABLE     _IO('K', 3)
 
 #define KCOV_MODE_NONE         0

Reply via email to