Path: blob/main/tests/sys/kern/coredump_phnum_helper.c
39483 views
/*1* Copyright (c) 2016, Conrad Meyer2* All rights reserved.3*4* Redistribution and use in source and binary forms, with or without5* modification, are permitted provided that the following conditions are met:6*7* 1. Redistributions of source code must retain the above copyright notice,8* this list of conditions and the following disclaimer.9*10* 2. Redistributions in binary form must reproduce the above copyright notice,11* this list of conditions and the following disclaimer in the documentation12* and/or other materials provided with the distribution.13*14* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"15* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE16* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE17* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE18* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR19* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF20* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS21* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN22* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)23* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE24* POSSIBILITY OF SUCH DAMAGE.25*/2627#include <sys/param.h>28#include <sys/mman.h>2930#include <err.h>31#include <stdint.h>32#include <stdlib.h>33#include <unistd.h>3435/*36* This program is intended to create a bunch of segment mappings, then dump37* core.38*/39int40main(int argc __unused, char **argv __unused)41{42void *v;43size_t i, pages, page_size;4445page_size = getpagesize();46pages = UINT16_MAX + 1000;47v = mmap(NULL, pages * page_size, PROT_READ | PROT_WRITE,48MAP_ANON | MAP_PRIVATE, -1, 0);49if (v == NULL)50err(1, "mmap");51for (i = 0; i < pages; i += 2) {52/*53* Alternate protections to interleave RW and R PT_LOAD54* segments.55*/56if (mprotect((char *)v + i * page_size, page_size,57PROT_READ) != 0)58err(1, "mprotect");59}6061/* Dump core. */62abort();63}646566