1 /* $NetBSD: irix_resource.c,v 1.14 2008/04/28 20:23:42 martin Exp $ */
4 * Copyright (c) 2002 The NetBSD Foundation, Inc.
7 * This code is derived from software contributed to The NetBSD Foundation
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
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>
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);
55 irix_to_native_resource(int irix_res
)
63 case IRIX_RLIMIT_FSIZE
:
64 bsd_res
= RLIMIT_FSIZE
;
66 case IRIX_RLIMIT_DATA
:
67 bsd_res
= RLIMIT_DATA
;
69 case IRIX_RLIMIT_STACK
:
70 bsd_res
= RLIMIT_STACK
;
72 case IRIX_RLIMIT_CORE
:
73 bsd_res
= RLIMIT_CORE
;
75 case IRIX_RLIMIT_NOFILE
:
76 bsd_res
= RLIMIT_NOFILE
;
78 case IRIX_RLIMIT_VMEM
:
84 case IRIX_RLIMIT_PTHREAD
:
85 printf("Warning: ignored IRIX pthread rlimit flag\n");
94 irix_sys_getrlimit(struct lwp
*l
, const struct irix_sys_getrlimit_args
*uap
, register_t
*retval
)
97 syscallarg(int) resource;
98 syscallarg(struct irix_rlimit *) rlp;
101 struct irix_rlimit irlp
;
104 which
= irix_to_native_resource(SCARG(uap
, resource
));
108 rlp
= &l
->l_proc
->p_rlimit
[which
];
110 if (rlp
->rlim_cur
== RLIM_INFINITY
)
111 irlp
.rlim_cur
= IRIX_RLIM_INFINITY
;
113 irlp
.rlim_cur
= rlp
->rlim_cur
;
115 if (rlp
->rlim_max
== RLIM_INFINITY
)
116 irlp
.rlim_max
= IRIX_RLIM_INFINITY
;
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
)
127 syscallarg(int) resource;
128 syscallarg(struct irix_rlimit64 *) rlp;
131 struct irix_rlimit64 irlp
;
134 which
= irix_to_native_resource(SCARG(uap
, resource
));
138 rlp
= &l
->l_proc
->p_rlimit
[which
];
140 if (rlp
->rlim_cur
== RLIM_INFINITY
)
141 irlp
.rlim_cur
= IRIX_RLIM64_INFINITY
;
143 irlp
.rlim_cur
= rlp
->rlim_cur
;
145 if (rlp
->rlim_max
== RLIM_INFINITY
)
146 irlp
.rlim_max
= IRIX_RLIM64_INFINITY
;
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
)
157 syscallarg(int) resource;
158 syscallarg(const struct irix_rlimit *) rlp;
160 struct irix_rlimit irlp
;
165 which
= irix_to_native_resource(SCARG(uap
, resource
));
169 if ((error
= copyin(SCARG(uap
, rlp
), &irlp
, sizeof(irlp
))) != 0)
172 if (irlp
.rlim_cur
== IRIX_RLIM_INFINITY
)
173 rlp
.rlim_cur
= RLIM_INFINITY
;
175 rlp
.rlim_cur
= irlp
.rlim_cur
;
177 if (irlp
.rlim_max
== IRIX_RLIM_INFINITY
)
178 rlp
.rlim_max
= RLIM_INFINITY
;
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
)
189 syscallarg(int) resource;
190 syscallarg(const struct irix_rlimit64 *) rlp;
193 struct irix_rlimit64 irlp
;
197 which
= irix_to_native_resource(SCARG(uap
, resource
));
201 if ((error
= copyin(SCARG(uap
, rlp
), &irlp
, sizeof(irlp
))) != 0)
204 if (irlp
.rlim_cur
== IRIX_RLIM64_INFINITY
)
205 rlp
.rlim_cur
= RLIM_INFINITY
;
207 rlp
.rlim_cur
= irlp
.rlim_cur
;
209 if (irlp
.rlim_max
== IRIX_RLIM64_INFINITY
)
210 rlp
.rlim_max
= RLIM_INFINITY
;
212 rlp
.rlim_max
= irlp
.rlim_cur
;
214 return dosetrlimit(l
, l
->l_proc
, which
, &rlp
);