xref: /titanic_52/usr/src/lib/libproc/common/pr_getrlimit.c (revision dd51520e127b452179a2ce4ea3bd8dee949f9afe)
1 /*
2  * CDDL HEADER START
3  *
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.
8  *
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.
13  *
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]
19  *
20  * CDDL HEADER END
21  */
22 /*
23  * Copyright (c) 1997-2000 by Sun Microsystems, Inc.
24  * All rights reserved.
25  */
26 
27 #pragma ident	"%Z%%M%	%I%	%E% SMI"
28 
29 #define	_LARGEFILE64_SOURCE
30 
31 #include <stdlib.h>
32 #include <unistd.h>
33 #include <errno.h>
34 #include <sys/resource.h>
35 #include "libproc.h"
36 
37 /*
38  * getrlimit() system call -- executed by subject process.
39  */
40 int
41 pr_getrlimit(struct ps_prochandle *Pr,
42 	int resource, struct rlimit *rlp)
43 {
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;
49 
50 	if (Pr == NULL)		/* no subject process */
51 		return (getrlimit(resource, rlp));
52 
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;
59 
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);
66 
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 */
75 
76 	error = Psyscall(Pr, &rval, sysnum, 2, &argd[0]);
77 
78 	if (error) {
79 		errno = (error > 0)? error : ENOSYS;
80 		return (-1);
81 	}
82 	return (rval.sys_rval1);
83 }
84 
85 /*
86  * setrlimit() system call -- executed by subject process.
87  */
88 int
89 pr_setrlimit(struct ps_prochandle *Pr,
90 	int resource, const struct rlimit *rlp)
91 {
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;
97 
98 	if (Pr == NULL)		/* no subject process */
99 		return (setrlimit(resource, rlp));
100 
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;
107 
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);
114 
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 */
123 
124 	error = Psyscall(Pr, &rval, sysnum, 2, &argd[0]);
125 
126 	if (error) {
127 		errno = (error > 0)? error : ENOSYS;
128 		return (-1);
129 	}
130 	return (rval.sys_rval1);
131 }
132 
133 /*
134  * getrlimit64() system call -- executed by subject process.
135  */
136 int
137 pr_getrlimit64(struct ps_prochandle *Pr,
138 	int resource, struct rlimit64 *rlp)
139 {
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;
145 
146 	if (Pr == NULL)		/* no subject process */
147 		return (getrlimit64(resource, rlp));
148 
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;
155 
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);
162 
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 */
171 
172 	error = Psyscall(Pr, &rval, sysnum, 2, &argd[0]);
173 
174 	if (error) {
175 		errno = (error > 0)? error : ENOSYS;
176 		return (-1);
177 	}
178 	return (rval.sys_rval1);
179 }
180 
181 /*
182  * setrlimit64() system call -- executed by subject process.
183  */
184 int
185 pr_setrlimit64(struct ps_prochandle *Pr,
186 	int resource, const struct rlimit64 *rlp)
187 {
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;
193 
194 	if (Pr == NULL)		/* no subject process */
195 		return (setrlimit64(resource, rlp));
196 
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;
203 
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);
210 
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 */
219 
220 	error = Psyscall(Pr, &rval, sysnum, 2, &argd[0]);
221 
222 	if (error) {
223 		errno = (error > 0)? error : ENOSYS;
224 		return (-1);
225 	}
226 	return (rval.sys_rval1);
227 }
228