From bdffe3b5bf0008664ec7d1d8c919f71014538830 Mon Sep 17 00:00:00 2001 From: Andrew Turner Date: Thu, 21 Feb 2019 10:11:15 +0000 Subject: [PATCH] Allow the kcov buffer to be mmaped multiple times. After r344391 this restriction is no longer needed. Sponsored by: DARPA, AFRL --- sys/kern/kern_kcov.c | 6 +----- tests/sys/kern/kcov.c | 16 +++++++++++----- 2 files changed, 12 insertions(+), 10 deletions(-) diff --git a/sys/kern/kern_kcov.c b/sys/kern/kern_kcov.c index d6ac2aea9227..5b17a6ca5f44 100644 --- a/sys/kern/kern_kcov.c +++ b/sys/kern/kern_kcov.c @@ -127,7 +127,6 @@ struct kcov_info { size_t bufsize; /* (o) */ kcov_state_t state; /* (s) */ int mode; /* (l) */ - bool mmap; }; /* Prototypes */ @@ -303,7 +302,6 @@ kcov_open(struct cdev *dev, int oflags, int devtype, struct thread *td) info->state = KCOV_STATE_OPEN; info->thread = NULL; info->mode = -1; - info->mmap = false; if ((error = devfs_set_cdevpriv(info, kcov_mmap_cleanup)) != 0) kcov_mmap_cleanup(info); @@ -344,12 +342,10 @@ kcov_mmap_single(struct cdev *dev, vm_ooffset_t *offset, vm_size_t size, if ((error = devfs_get_cdevpriv((void **)&info)) != 0) return (error); - if (info->kvaddr == 0 || size / KCOV_ELEMENT_SIZE != info->entries || - info->mmap != false) + if (info->kvaddr == 0 || size / KCOV_ELEMENT_SIZE != info->entries) return (EINVAL); vm_object_reference(info->bufobj); - info->mmap = true; *offset = 0; *object = info->bufobj; return (0); diff --git a/tests/sys/kern/kcov.c b/tests/sys/kern/kcov.c index c892e69523d9..0a59ddbeff73 100644 --- a/tests/sys/kern/kcov.c +++ b/tests/sys/kern/kcov.c @@ -80,7 +80,7 @@ ATF_TC_BODY(kcov_bufsize, tc) ATF_TC_WITHOUT_HEAD(kcov_mmap); ATF_TC_BODY(kcov_mmap, tc) { - void *data; + void *data1, *data2; int fd; fd = open_kcov(); @@ -95,12 +95,18 @@ ATF_TC_BODY(kcov_mmap, tc) fd, 0) == MAP_FAILED); ATF_CHECK(mmap(NULL, 3 * PAGE_SIZE, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0) == MAP_FAILED); - ATF_REQUIRE((data = mmap(NULL, 2 * PAGE_SIZE, PROT_READ | PROT_WRITE, + ATF_REQUIRE((data1 = mmap(NULL, 2 * PAGE_SIZE, PROT_READ | PROT_WRITE, + MAP_SHARED, fd, 0)) != MAP_FAILED); + ATF_REQUIRE((data2 = mmap(NULL, 2 * PAGE_SIZE, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0)) != MAP_FAILED); - ATF_CHECK(mmap(NULL, 2 * PAGE_SIZE, PROT_READ | PROT_WRITE, MAP_SHARED, - fd, 0) == MAP_FAILED); - munmap(data, 2 * PAGE_SIZE); + *(uint64_t *)data1 = 0x123456789abcdeful; + ATF_REQUIRE(*(uint64_t *)data2 == 0x123456789abcdefull); + *(uint64_t *)data2 = 0xfedcba9876543210ul; + ATF_REQUIRE(*(uint64_t *)data1 == 0xfedcba9876543210ull); + + munmap(data1, 2 * PAGE_SIZE); + munmap(data2, 2 * PAGE_SIZE); close(fd); }