Changeset View
Changeset View
Standalone View
Standalone View
tests/sys/kern/coredump_phnum_helper.c
Show All 36 Lines | |||||
/* | /* | ||||
* This program is intended to create a bunch of segment mappings, then dump | * This program is intended to create a bunch of segment mappings, then dump | ||||
* core. | * core. | ||||
*/ | */ | ||||
int | int | ||||
main(int argc __unused, char **argv __unused) | main(int argc __unused, char **argv __unused) | ||||
{ | { | ||||
void *v; | void *v; | ||||
unsigned i; | size_t i, pages; | ||||
for (i = 0; i < UINT16_MAX + 1000; i++) { | pages = UINT16_MAX + 1000; | ||||
/* | v = mmap(NULL, pages * PAGE_SIZE, PROT_READ | PROT_WRITE, | ||||
* Alternate protections; otherwise the kernel will just extend | |||||
* the adjacent same-protection previous mapping. | |||||
*/ | |||||
v = mmap(NULL, PAGE_SIZE, | |||||
(((i % 2) == 0) ? PROT_READ : 0) | PROT_WRITE, | |||||
MAP_ANON | MAP_PRIVATE, -1, 0); | MAP_ANON | MAP_PRIVATE, -1, 0); | ||||
if (v == MAP_FAILED) | if (v == NULL) | ||||
err(1, "mmap"); | err(1, "mmap"); | ||||
for (i = 0; i < pages; i += 2) { | |||||
/* | |||||
* Alternate protections to interleave RW and R PT_LOAD | |||||
* segments. | |||||
*/ | |||||
if (mprotect((char *)v + i * PAGE_SIZE, PAGE_SIZE, | |||||
PROT_READ) != 0) | |||||
err(1, "mprotect"); | |||||
kib: Since you are mprotect'ing at the page (i+1), shouldn't loop use i < pages - 1 as the stop… | |||||
} | } | ||||
/* Dump core. */ | /* Dump core. */ | ||||
abort(); | abort(); | ||||
} | } |
Since you are mprotect'ing at the page (i+1), shouldn't loop use i < pages - 1 as the stop condition? For me, it looks like you are changing protection of one page after the mmaped region.
Or change mmap to allocate pages + 1 pages.