dmake: do not set MAKEFLAGS=k
[unleashed/tickless.git] / usr / src / lib / libproc / common / pr_getrlimit.c
blobd5ea456cef46a08e67e9e8fd9c7a641f1204678a
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 #define _LARGEFILE64_SOURCE
31 #include <stdlib.h>
32 #include <unistd.h>
33 #include <errno.h>
34 #include <sys/resource.h>
35 #include "libproc.h"
38 * getrlimit() system call -- executed by subject process.
40 int
41 pr_getrlimit(struct ps_prochandle *Pr,
42 int resource, struct rlimit *rlp)
44 sysret_t rval; /* return value from getrlimit() */
45 argdes_t argd[2]; /* arg descriptors for getrlimit() */
46 argdes_t *adp;
47 int sysnum;
48 int error;
50 if (Pr == NULL) /* no subject process */
51 return (getrlimit(resource, rlp));
53 adp = &argd[0]; /* resource argument */
54 adp->arg_value = resource;
55 adp->arg_object = NULL;
56 adp->arg_type = AT_BYVAL;
57 adp->arg_inout = AI_INPUT;
58 adp->arg_size = 0;
60 adp++; /* rlp argument */
61 adp->arg_value = 0;
62 adp->arg_object = rlp;
63 adp->arg_type = AT_BYREF;
64 adp->arg_inout = AI_OUTPUT;
65 adp->arg_size = sizeof (*rlp);
67 #ifdef _LP64
68 if (Pstatus(Pr)->pr_dmodel == PR_MODEL_ILP32)
69 sysnum = SYS_getrlimit64;
70 else
71 sysnum = SYS_getrlimit;
72 #else /* _LP64 */
73 sysnum = SYS_getrlimit;
74 #endif /* _LP64 */
76 error = Psyscall(Pr, &rval, sysnum, 2, &argd[0]);
78 if (error) {
79 errno = (error > 0)? error : ENOSYS;
80 return (-1);
82 return (rval.sys_rval1);
86 * setrlimit() system call -- executed by subject process.
88 int
89 pr_setrlimit(struct ps_prochandle *Pr,
90 int resource, const struct rlimit *rlp)
92 sysret_t rval; /* return value from setrlimit() */
93 argdes_t argd[2]; /* arg descriptors for setrlimit() */
94 argdes_t *adp;
95 int sysnum;
96 int error;
98 if (Pr == NULL) /* no subject process */
99 return (setrlimit(resource, rlp));
101 adp = &argd[0]; /* resource argument */
102 adp->arg_value = resource;
103 adp->arg_object = NULL;
104 adp->arg_type = AT_BYVAL;
105 adp->arg_inout = AI_INPUT;
106 adp->arg_size = 0;
108 adp++; /* rlp argument */
109 adp->arg_value = 0;
110 adp->arg_object = (void *)rlp;
111 adp->arg_type = AT_BYREF;
112 adp->arg_inout = AI_INPUT;
113 adp->arg_size = sizeof (*rlp);
115 #ifdef _LP64
116 if (Pstatus(Pr)->pr_dmodel == PR_MODEL_ILP32)
117 sysnum = SYS_setrlimit64;
118 else
119 sysnum = SYS_setrlimit;
120 #else /* _LP64 */
121 sysnum = SYS_setrlimit;
122 #endif /* _LP64 */
124 error = Psyscall(Pr, &rval, sysnum, 2, &argd[0]);
126 if (error) {
127 errno = (error > 0)? error : ENOSYS;
128 return (-1);
130 return (rval.sys_rval1);
134 * getrlimit64() system call -- executed by subject process.
137 pr_getrlimit64(struct ps_prochandle *Pr,
138 int resource, struct rlimit64 *rlp)
140 sysret_t rval; /* return value from getrlimit() */
141 argdes_t argd[2]; /* arg descriptors for getrlimit() */
142 argdes_t *adp;
143 int sysnum;
144 int error;
146 if (Pr == NULL) /* no subject process */
147 return (getrlimit64(resource, rlp));
149 adp = &argd[0]; /* resource argument */
150 adp->arg_value = resource;
151 adp->arg_object = NULL;
152 adp->arg_type = AT_BYVAL;
153 adp->arg_inout = AI_INPUT;
154 adp->arg_size = 0;
156 adp++; /* rlp argument */
157 adp->arg_value = 0;
158 adp->arg_object = rlp;
159 adp->arg_type = AT_BYREF;
160 adp->arg_inout = AI_OUTPUT;
161 adp->arg_size = sizeof (*rlp);
163 #ifdef _LP64
164 if (Pstatus(Pr)->pr_dmodel == PR_MODEL_ILP32)
165 sysnum = SYS_getrlimit64;
166 else
167 sysnum = SYS_getrlimit;
168 #else /* _LP64 */
169 sysnum = SYS_getrlimit64;
170 #endif /* _LP64 */
172 error = Psyscall(Pr, &rval, sysnum, 2, &argd[0]);
174 if (error) {
175 errno = (error > 0)? error : ENOSYS;
176 return (-1);
178 return (rval.sys_rval1);
182 * setrlimit64() system call -- executed by subject process.
185 pr_setrlimit64(struct ps_prochandle *Pr,
186 int resource, const struct rlimit64 *rlp)
188 sysret_t rval; /* return value from setrlimit() */
189 argdes_t argd[2]; /* arg descriptors for setrlimit() */
190 argdes_t *adp;
191 int sysnum;
192 int error;
194 if (Pr == NULL) /* no subject process */
195 return (setrlimit64(resource, rlp));
197 adp = &argd[0]; /* resource argument */
198 adp->arg_value = resource;
199 adp->arg_object = NULL;
200 adp->arg_type = AT_BYVAL;
201 adp->arg_inout = AI_INPUT;
202 adp->arg_size = 0;
204 adp++; /* rlp argument */
205 adp->arg_value = 0;
206 adp->arg_object = (void *)rlp;
207 adp->arg_type = AT_BYREF;
208 adp->arg_inout = AI_INPUT;
209 adp->arg_size = sizeof (*rlp);
211 #ifdef _LP64
212 if (Pstatus(Pr)->pr_dmodel == PR_MODEL_ILP32)
213 sysnum = SYS_setrlimit64;
214 else
215 sysnum = SYS_setrlimit;
216 #else /* _LP64 */
217 sysnum = SYS_setrlimit64;
218 #endif /* _LP64 */
220 error = Psyscall(Pr, &rval, sysnum, 2, &argd[0]);
222 if (error) {
223 errno = (error > 0)? error : ENOSYS;
224 return (-1);
226 return (rval.sys_rval1);