1f38cb55John Wren Kennedy/*
2f38cb55John Wren Kennedy * CDDL HEADER START
3f38cb55John Wren Kennedy *
4f38cb55John Wren Kennedy * The contents of this file are subject to the terms of the
5f38cb55John Wren Kennedy * Common Development and Distribution License (the "License").
6f38cb55John Wren Kennedy * You may not use this file except in compliance with the License.
7f38cb55John Wren Kennedy *
8f38cb55John Wren Kennedy * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9f38cb55John Wren Kennedy * or http://www.opensolaris.org/os/licensing.
10f38cb55John Wren Kennedy * See the License for the specific language governing permissions
11f38cb55John Wren Kennedy * and limitations under the License.
12f38cb55John Wren Kennedy *
13f38cb55John Wren Kennedy * When distributing Covered Code, include this CDDL HEADER in each
14f38cb55John Wren Kennedy * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15f38cb55John Wren Kennedy * If applicable, add the following below this CDDL HEADER, with the
16f38cb55John Wren Kennedy * fields enclosed by brackets "[]" replaced with your own identifying
17f38cb55John Wren Kennedy * information: Portions Copyright [yyyy] [name of copyright owner]
18f38cb55John Wren Kennedy *
19f38cb55John Wren Kennedy * CDDL HEADER END
20f38cb55John Wren Kennedy */
21f38cb55John Wren Kennedy
22f38cb55John Wren Kennedy/*
23f38cb55John Wren Kennedy * Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
24f38cb55John Wren Kennedy * Use is subject to license terms.
25f38cb55John Wren Kennedy */
26f38cb55John Wren Kennedy
27f38cb55John Wren Kennedy/*
28f38cb55John Wren Kennedy * Copyright (c) 2013 by Delphix. All rights reserved.
29f38cb55John Wren Kennedy */
30f38cb55John Wren Kennedy
31f38cb55John Wren Kennedy#include <stdio.h>
32f38cb55John Wren Kennedy#include <sys/stat.h>
33f38cb55John Wren Kennedy#include <fcntl.h>
34f38cb55John Wren Kennedy#include <sys/types.h>
35f38cb55John Wren Kennedy#include <sys/mman.h>
36f38cb55John Wren Kennedy#include <errno.h>
37f38cb55John Wren Kennedy
38f38cb55John Wren Kennedyextern int errno;
39f38cb55John Wren Kennedy
40f38cb55John Wren Kennedyint
41f38cb55John Wren Kennedymain(int argc, char *argv[])
42f38cb55John Wren Kennedy{
43f38cb55John Wren Kennedy	int fd;
44f38cb55John Wren Kennedy	struct stat statbuf;
45f38cb55John Wren Kennedy
46f38cb55John Wren Kennedy	if (argc != 2) {
47f38cb55John Wren Kennedy		(void) printf("Error: missing binary name.\n");
48f38cb55John Wren Kennedy		(void) printf("Usage:\n\t%s <binary name>\n",
49f38cb55John Wren Kennedy		    argv[0]);
50f38cb55John Wren Kennedy		return (1);
51f38cb55John Wren Kennedy	}
52f38cb55John Wren Kennedy
53f38cb55John Wren Kennedy	errno = 0;
54f38cb55John Wren Kennedy
55f38cb55John Wren Kennedy	if ((fd = open(argv[1], O_RDONLY)) < 0) {
56f38cb55John Wren Kennedy		perror("open");
57f38cb55John Wren Kennedy		return (errno);
58f38cb55John Wren Kennedy	}
59f38cb55John Wren Kennedy	if (fstat(fd, &statbuf) < 0) {
60f38cb55John Wren Kennedy		perror("fstat");
61f38cb55John Wren Kennedy		return (errno);
62f38cb55John Wren Kennedy	}
63f38cb55John Wren Kennedy
64f38cb55John Wren Kennedy	if (mmap(0, statbuf.st_size,
65f38cb55John Wren Kennedy	    PROT_EXEC, MAP_SHARED, fd, 0) == MAP_FAILED) {
66f38cb55John Wren Kennedy		perror("mmap");
67f38cb55John Wren Kennedy		return (errno);
68f38cb55John Wren Kennedy	}
69f38cb55John Wren Kennedy
70f38cb55John Wren Kennedy	return (0);
71f38cb55John Wren Kennedy}
72