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