Skip to content

Commit

Permalink
Allow the kcov buffer to be mmaped multiple times.
Browse files Browse the repository at this point in the history
After r344391 this restriction is no longer needed.

Sponsored by:	DARPA, AFRL
  • Loading branch information
zxombie committed Feb 21, 2019
1 parent ccea7c1 commit 27723fd
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 10 deletions.
6 changes: 1 addition & 5 deletions sys/kern/kern_kcov.c
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,6 @@ struct kcov_info {
size_t bufsize; /* (o) */
kcov_state_t state; /* (s) */
int mode; /* (l) */
bool mmap;
};

/* Prototypes */
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down
16 changes: 11 additions & 5 deletions tests/sys/kern/kcov.c
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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_CHECK(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);

*(uint64_t *)data1 = 0x123456789abcdeful;
ATF_REQUIRE(*(uint64_t *)data2 == 0x123456789abcdefull);
*(uint64_t *)data2 = 0xfedcba9876543210ul;
ATF_REQUIRE(*(uint64_t *)data1 == 0xfedcba9876543210ull);

munmap(data, 2 * PAGE_SIZE);
munmap(data1, 2 * PAGE_SIZE);
munmap(data2, 2 * PAGE_SIZE);

close(fd);
}
Expand Down

0 comments on commit 27723fd

Please sign in to comment.