Sync usage with man page.
[netbsd-mini2440.git] / sys / compat / irix / irix_resource.c
blobce183e636fa6b319a8d953e8e2d6dde1320986c0
1 /* $NetBSD: irix_resource.c,v 1.14 2008/04/28 20:23:42 martin Exp $ */
3 /*-
4 * Copyright (c) 2002 The NetBSD Foundation, Inc.
5 * All rights reserved.
7 * This code is derived from software contributed to The NetBSD Foundation
8 * by Emmanuel Dreyfus.
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
12 * are met:
13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer.
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in the
17 * documentation and/or other materials provided with the distribution.
19 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
20 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
21 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
23 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29 * POSSIBILITY OF SUCH DAMAGE.
32 #include <sys/cdefs.h>
33 __KERNEL_RCSID(0, "$NetBSD: irix_resource.c,v 1.14 2008/04/28 20:23:42 martin Exp $");
35 #include <sys/types.h>
36 #include <sys/signal.h>
37 #include <sys/param.h>
38 #include <sys/mount.h>
39 #include <sys/proc.h>
40 #include <sys/systm.h>
41 #include <sys/resource.h>
42 #include <sys/resourcevar.h>
43 #include <sys/syscallargs.h>
45 #include <compat/common/compat_util.h>
47 #include <compat/irix/irix_types.h>
48 #include <compat/irix/irix_signal.h>
49 #include <compat/irix/irix_resource.h>
50 #include <compat/irix/irix_syscallargs.h>
52 static int irix_to_native_resource(int);
54 static int
55 irix_to_native_resource(int irix_res)
57 int bsd_res;
59 switch(irix_res) {
60 case IRIX_RLIMIT_CPU:
61 bsd_res = RLIMIT_CPU;
62 break;
63 case IRIX_RLIMIT_FSIZE:
64 bsd_res = RLIMIT_FSIZE;
65 break;
66 case IRIX_RLIMIT_DATA:
67 bsd_res = RLIMIT_DATA;
68 break;
69 case IRIX_RLIMIT_STACK:
70 bsd_res = RLIMIT_STACK;
71 break;
72 case IRIX_RLIMIT_CORE:
73 bsd_res = RLIMIT_CORE;
74 break;
75 case IRIX_RLIMIT_NOFILE:
76 bsd_res = RLIMIT_NOFILE;
77 break;
78 case IRIX_RLIMIT_VMEM:
79 bsd_res = RLIMIT_AS;
80 break;
81 case IRIX_RLIMIT_RSS:
82 bsd_res = RLIMIT_RSS;
83 break;
84 case IRIX_RLIMIT_PTHREAD:
85 printf("Warning: ignored IRIX pthread rlimit flag\n");
86 default:
87 bsd_res = -1;
88 break;
90 return bsd_res;
93 int
94 irix_sys_getrlimit(struct lwp *l, const struct irix_sys_getrlimit_args *uap, register_t *retval)
96 /* {
97 syscallarg(int) resource;
98 syscallarg(struct irix_rlimit *) rlp;
99 } */
100 struct rlimit *rlp;
101 struct irix_rlimit irlp;
102 int which;
104 which = irix_to_native_resource(SCARG(uap, resource));
105 if (which < 0)
106 return EINVAL;
108 rlp = &l->l_proc->p_rlimit[which];
110 if (rlp->rlim_cur == RLIM_INFINITY)
111 irlp.rlim_cur = IRIX_RLIM_INFINITY;
112 else
113 irlp.rlim_cur = rlp->rlim_cur;
115 if (rlp->rlim_max == RLIM_INFINITY)
116 irlp.rlim_max = IRIX_RLIM_INFINITY;
117 else
118 irlp.rlim_max = rlp->rlim_cur;
120 return copyout(&irlp, SCARG(uap, rlp), sizeof(irlp));
124 irix_sys_getrlimit64(struct lwp *l, const struct irix_sys_getrlimit64_args *uap, register_t *retval)
126 /* {
127 syscallarg(int) resource;
128 syscallarg(struct irix_rlimit64 *) rlp;
129 } */
130 struct rlimit *rlp;
131 struct irix_rlimit64 irlp;
132 int which;
134 which = irix_to_native_resource(SCARG(uap, resource));
135 if (which < 0)
136 return EINVAL;
138 rlp = &l->l_proc->p_rlimit[which];
140 if (rlp->rlim_cur == RLIM_INFINITY)
141 irlp.rlim_cur = IRIX_RLIM64_INFINITY;
142 else
143 irlp.rlim_cur = rlp->rlim_cur;
145 if (rlp->rlim_max == RLIM_INFINITY)
146 irlp.rlim_max = IRIX_RLIM64_INFINITY;
147 else
148 irlp.rlim_max = rlp->rlim_cur;
150 return copyout(&irlp, SCARG(uap, rlp), sizeof(irlp));
154 irix_sys_setrlimit(struct lwp *l, const struct irix_sys_setrlimit_args *uap, register_t *retval)
156 /* {
157 syscallarg(int) resource;
158 syscallarg(const struct irix_rlimit *) rlp;
159 } */
160 struct irix_rlimit irlp;
161 struct rlimit rlp;
162 int which;
163 int error;
165 which = irix_to_native_resource(SCARG(uap, resource));
166 if (which < 0)
167 return EINVAL;
169 if ((error = copyin(SCARG(uap, rlp), &irlp, sizeof(irlp))) != 0)
170 return error;
172 if (irlp.rlim_cur == IRIX_RLIM_INFINITY)
173 rlp.rlim_cur = RLIM_INFINITY;
174 else
175 rlp.rlim_cur = irlp.rlim_cur;
177 if (irlp.rlim_max == IRIX_RLIM_INFINITY)
178 rlp.rlim_max = RLIM_INFINITY;
179 else
180 rlp.rlim_max = irlp.rlim_cur;
182 return dosetrlimit(l, l->l_proc, which, &rlp);
186 irix_sys_setrlimit64(struct lwp *l, const struct irix_sys_setrlimit64_args *uap, register_t *retval)
188 /* {
189 syscallarg(int) resource;
190 syscallarg(const struct irix_rlimit64 *) rlp;
191 } */
192 struct rlimit rlp;
193 struct irix_rlimit64 irlp;
194 int which;
195 int error;
197 which = irix_to_native_resource(SCARG(uap, resource));
198 if (which < 0)
199 return EINVAL;
201 if ((error = copyin(SCARG(uap, rlp), &irlp, sizeof(irlp))) != 0)
202 return error;
204 if (irlp.rlim_cur == IRIX_RLIM64_INFINITY)
205 rlp.rlim_cur = RLIM_INFINITY;
206 else
207 rlp.rlim_cur = irlp.rlim_cur;
209 if (irlp.rlim_max == IRIX_RLIM64_INFINITY)
210 rlp.rlim_max = RLIM_INFINITY;
211 else
212 rlp.rlim_max = irlp.rlim_cur;
214 return dosetrlimit(l, l->l_proc, which, &rlp);