dmake: do not set MAKEFLAGS=k
[unleashed/tickless.git] / usr / src / lib / libproc / common / pr_mmap.c
blob9dd863a435c8ad9a9364254df53b6b22dea25724
1 /*
2 * CDDL HEADER START
4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License, Version 1.0 only
6 * (the "License"). You may not use this file except in compliance
7 * with the License.
9 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10 * or http://www.opensolaris.org/os/licensing.
11 * See the License for the specific language governing permissions
12 * and limitations under the License.
14 * When distributing Covered Code, include this CDDL HEADER in each
15 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16 * If applicable, add the following below this CDDL HEADER, with the
17 * fields enclosed by brackets "[]" replaced with your own identifying
18 * information: Portions Copyright [yyyy] [name of copyright owner]
20 * CDDL HEADER END
23 * Copyright (c) 1997-2000 by Sun Microsystems, Inc.
24 * All rights reserved.
27 #pragma ident "%Z%%M% %I% %E% SMI"
29 #include <stdlib.h>
30 #include <unistd.h>
31 #include <errno.h>
32 #include <sys/mman.h>
33 #include "libproc.h"
36 * mmap() system call -- executed by subject process
38 void *
39 pr_mmap(struct ps_prochandle *Pr,
40 void *addr, size_t len, int prot, int flags, int fd, off_t off)
42 sysret_t rval; /* return value from mmap() */
43 argdes_t argd[6]; /* arg descriptors for mmap() */
44 argdes_t *adp;
45 int error;
47 if (Pr == NULL) /* no subject process */
48 return (mmap(addr, len, prot, flags, fd, off));
50 adp = &argd[0]; /* addr argument */
51 adp->arg_value = (long)addr;
52 adp->arg_object = NULL;
53 adp->arg_type = AT_BYVAL;
54 adp->arg_inout = AI_INPUT;
55 adp->arg_size = 0;
57 adp++; /* len argument */
58 adp->arg_value = (long)len;
59 adp->arg_object = NULL;
60 adp->arg_type = AT_BYVAL;
61 adp->arg_inout = AI_INPUT;
62 adp->arg_size = 0;
64 adp++; /* prot argument */
65 adp->arg_value = (long)prot;
66 adp->arg_object = NULL;
67 adp->arg_type = AT_BYVAL;
68 adp->arg_inout = AI_INPUT;
69 adp->arg_size = 0;
71 adp++; /* flags argument */
72 adp->arg_value = (long)flags;
73 adp->arg_object = NULL;
74 adp->arg_type = AT_BYVAL;
75 adp->arg_inout = AI_INPUT;
76 adp->arg_size = 0;
78 adp++; /* fd argument */
79 adp->arg_value = (long)fd;
80 adp->arg_object = NULL;
81 adp->arg_type = AT_BYVAL;
82 adp->arg_inout = AI_INPUT;
83 adp->arg_size = 0;
85 adp++; /* off argument */
86 adp->arg_value = (long)off;
87 adp->arg_object = NULL;
88 adp->arg_type = AT_BYVAL;
89 adp->arg_inout = AI_INPUT;
90 adp->arg_size = 0;
92 error = Psyscall(Pr, &rval, SYS_mmap, 6, &argd[0]);
94 if (error) {
95 errno = (error > 0)? error : ENOSYS;
96 return ((void *)(-1));
98 return ((void *)rval.sys_rval1);
102 * munmap() system call -- executed by subject process
105 pr_munmap(struct ps_prochandle *Pr, void *addr, size_t len)
107 sysret_t rval; /* return value from munmap() */
108 argdes_t argd[2]; /* arg descriptors for munmap() */
109 argdes_t *adp;
110 int error;
112 if (Pr == NULL) /* no subject process */
113 return (munmap(addr, len));
115 adp = &argd[0]; /* addr argument */
116 adp->arg_value = (long)addr;
117 adp->arg_object = NULL;
118 adp->arg_type = AT_BYVAL;
119 adp->arg_inout = AI_INPUT;
120 adp->arg_size = 0;
122 adp++; /* len argument */
123 adp->arg_value = (long)len;
124 adp->arg_object = NULL;
125 adp->arg_type = AT_BYVAL;
126 adp->arg_inout = AI_INPUT;
127 adp->arg_size = 0;
129 error = Psyscall(Pr, &rval, SYS_munmap, 2, &argd[0]);
131 if (error) {
132 errno = (error > 0)? error : ENOSYS;
133 return (-1);
135 return (rval.sys_rval1);
139 * zmap() -- convenience function; mmap(MAP_ANON) executed by subject process.
141 void *
142 pr_zmap(struct ps_prochandle *Pr, void *addr, size_t len, int prot, int flags)
144 return (pr_mmap(Pr, addr, len, prot, flags | MAP_ANON, -1, (off_t)0));