Path: blob/main/sys/contrib/openzfs/tests/zfs-tests/cmd/mmap_exec.c
48529 views
// SPDX-License-Identifier: CDDL-1.01/*2* CDDL HEADER START3*4* The contents of this file are subject to the terms of the5* Common Development and Distribution License (the "License").6* You may not use this file except in compliance with the License.7*8* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE9* or https://opensource.org/licenses/CDDL-1.0.10* See the License for the specific language governing permissions11* and limitations under the License.12*13* When distributing Covered Code, include this CDDL HEADER in each14* file and include the License file at usr/src/OPENSOLARIS.LICENSE.15* If applicable, add the following below this CDDL HEADER, with the16* fields enclosed by brackets "[]" replaced with your own identifying17* information: Portions Copyright [yyyy] [name of copyright owner]18*19* CDDL HEADER END20*/2122/*23* Copyright 2007 Sun Microsystems, Inc. All rights reserved.24* Use is subject to license terms.25*/2627/*28* Copyright (c) 2013 by Delphix. All rights reserved.29*/3031#include <stdio.h>32#include <sys/stat.h>33#include <fcntl.h>34#include <sys/types.h>35#include <sys/mman.h>36#include <errno.h>3738int39main(int argc, char *argv[])40{41int error, fd;42struct stat statbuf;4344if (argc != 2) {45(void) printf("Error: missing binary name.\n");46(void) printf("Usage:\n\t%s <binary name>\n",47argv[0]);48return (1);49}5051errno = 0;5253if ((fd = open(argv[1], O_RDONLY)) < 0) {54error = errno;55perror("open");56return (error);57}58if (fstat(fd, &statbuf) < 0) {59error = errno;60perror("fstat");61return (error);62}6364if (mmap(0, statbuf.st_size,65PROT_EXEC, MAP_SHARED, fd, 0) == MAP_FAILED) {66error = errno;67perror("mmap");68return (error);69}7071return (0);72}737475