Allow the kcov buffer to be mmaped multiple times.
After r344391 this restriction is no longer needed. Sponsored by: DARPA, AFRL
This commit is contained in:
parent
ccea7c15ea
commit
27723fd7ce
@ -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);
|
||||
|
@ -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);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user