kern_resource.c revision 1.26 1 1.26 fvdl /* $NetBSD: kern_resource.c,v 1.26 1995/03/05 20:48:15 fvdl Exp $ */
2 1.20 cgd
3 1.17 cgd /*-
4 1.19 cgd * Copyright (c) 1982, 1986, 1991, 1993
5 1.19 cgd * The Regents of the University of California. All rights reserved.
6 1.17 cgd * (c) UNIX System Laboratories, Inc.
7 1.17 cgd * All or some portions of this file are derived from material licensed
8 1.17 cgd * to the University of California by American Telephone and Telegraph
9 1.17 cgd * Co. or Unix System Laboratories, Inc. and are reproduced herein with
10 1.17 cgd * the permission of UNIX System Laboratories, Inc.
11 1.17 cgd *
12 1.17 cgd * Redistribution and use in source and binary forms, with or without
13 1.17 cgd * modification, are permitted provided that the following conditions
14 1.17 cgd * are met:
15 1.17 cgd * 1. Redistributions of source code must retain the above copyright
16 1.17 cgd * notice, this list of conditions and the following disclaimer.
17 1.17 cgd * 2. Redistributions in binary form must reproduce the above copyright
18 1.17 cgd * notice, this list of conditions and the following disclaimer in the
19 1.17 cgd * documentation and/or other materials provided with the distribution.
20 1.17 cgd * 3. All advertising materials mentioning features or use of this software
21 1.17 cgd * must display the following acknowledgement:
22 1.17 cgd * This product includes software developed by the University of
23 1.17 cgd * California, Berkeley and its contributors.
24 1.17 cgd * 4. Neither the name of the University nor the names of its contributors
25 1.17 cgd * may be used to endorse or promote products derived from this software
26 1.17 cgd * without specific prior written permission.
27 1.17 cgd *
28 1.17 cgd * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
29 1.17 cgd * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
30 1.17 cgd * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
31 1.17 cgd * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
32 1.17 cgd * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
33 1.17 cgd * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
34 1.17 cgd * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
35 1.17 cgd * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
36 1.17 cgd * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
37 1.17 cgd * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
38 1.17 cgd * SUCH DAMAGE.
39 1.17 cgd *
40 1.20 cgd * @(#)kern_resource.c 8.5 (Berkeley) 1/21/94
41 1.17 cgd */
42 1.17 cgd
43 1.17 cgd #include <sys/param.h>
44 1.22 cgd #include <sys/systm.h>
45 1.17 cgd #include <sys/kernel.h>
46 1.19 cgd #include <sys/file.h>
47 1.17 cgd #include <sys/resourcevar.h>
48 1.17 cgd #include <sys/malloc.h>
49 1.17 cgd #include <sys/proc.h>
50 1.17 cgd
51 1.22 cgd #include <sys/mount.h>
52 1.22 cgd #include <sys/syscallargs.h>
53 1.22 cgd
54 1.17 cgd #include <vm/vm.h>
55 1.17 cgd
56 1.25 cgd int donice __P((struct proc *curp, struct proc *chgp, int n));
57 1.25 cgd int dosetrlimit __P((struct proc *p, u_int which, struct rlimit *limp));
58 1.25 cgd
59 1.17 cgd /*
60 1.17 cgd * Resource controls and accounting.
61 1.17 cgd */
62 1.17 cgd
63 1.25 cgd int
64 1.17 cgd getpriority(curp, uap, retval)
65 1.17 cgd struct proc *curp;
66 1.22 cgd register struct getpriority_args /* {
67 1.22 cgd syscallarg(int) which;
68 1.22 cgd syscallarg(int) who;
69 1.22 cgd } */ *uap;
70 1.22 cgd register_t *retval;
71 1.17 cgd {
72 1.17 cgd register struct proc *p;
73 1.17 cgd register int low = PRIO_MAX + 1;
74 1.17 cgd
75 1.22 cgd switch (SCARG(uap, which)) {
76 1.17 cgd
77 1.17 cgd case PRIO_PROCESS:
78 1.22 cgd if (SCARG(uap, who) == 0)
79 1.17 cgd p = curp;
80 1.17 cgd else
81 1.22 cgd p = pfind(SCARG(uap, who));
82 1.17 cgd if (p == 0)
83 1.17 cgd break;
84 1.17 cgd low = p->p_nice;
85 1.17 cgd break;
86 1.17 cgd
87 1.17 cgd case PRIO_PGRP: {
88 1.17 cgd register struct pgrp *pg;
89 1.17 cgd
90 1.22 cgd if (SCARG(uap, who) == 0)
91 1.17 cgd pg = curp->p_pgrp;
92 1.22 cgd else if ((pg = pgfind(SCARG(uap, who))) == NULL)
93 1.17 cgd break;
94 1.21 mycroft for (p = pg->pg_members.lh_first; p != 0; p = p->p_pglist.le_next) {
95 1.17 cgd if (p->p_nice < low)
96 1.17 cgd low = p->p_nice;
97 1.17 cgd }
98 1.17 cgd break;
99 1.17 cgd }
100 1.17 cgd
101 1.17 cgd case PRIO_USER:
102 1.22 cgd if (SCARG(uap, who) == 0)
103 1.22 cgd SCARG(uap, who) = curp->p_ucred->cr_uid;
104 1.21 mycroft for (p = allproc.lh_first; p != 0; p = p->p_list.le_next)
105 1.22 cgd if (p->p_ucred->cr_uid == SCARG(uap, who) &&
106 1.22 cgd p->p_nice < low)
107 1.17 cgd low = p->p_nice;
108 1.17 cgd break;
109 1.17 cgd
110 1.17 cgd default:
111 1.17 cgd return (EINVAL);
112 1.17 cgd }
113 1.17 cgd if (low == PRIO_MAX + 1)
114 1.17 cgd return (ESRCH);
115 1.17 cgd *retval = low;
116 1.17 cgd return (0);
117 1.17 cgd }
118 1.17 cgd
119 1.17 cgd /* ARGSUSED */
120 1.25 cgd int
121 1.17 cgd setpriority(curp, uap, retval)
122 1.17 cgd struct proc *curp;
123 1.22 cgd register struct setpriority_args /* {
124 1.22 cgd syscallarg(int) which;
125 1.22 cgd syscallarg(int) who;
126 1.22 cgd syscallarg(int) prio;
127 1.22 cgd } */ *uap;
128 1.22 cgd register_t *retval;
129 1.17 cgd {
130 1.17 cgd register struct proc *p;
131 1.17 cgd int found = 0, error = 0;
132 1.17 cgd
133 1.22 cgd switch (SCARG(uap, which)) {
134 1.17 cgd
135 1.17 cgd case PRIO_PROCESS:
136 1.22 cgd if (SCARG(uap, who) == 0)
137 1.17 cgd p = curp;
138 1.17 cgd else
139 1.22 cgd p = pfind(SCARG(uap, who));
140 1.17 cgd if (p == 0)
141 1.17 cgd break;
142 1.22 cgd error = donice(curp, p, SCARG(uap, prio));
143 1.17 cgd found++;
144 1.17 cgd break;
145 1.17 cgd
146 1.17 cgd case PRIO_PGRP: {
147 1.17 cgd register struct pgrp *pg;
148 1.17 cgd
149 1.22 cgd if (SCARG(uap, who) == 0)
150 1.17 cgd pg = curp->p_pgrp;
151 1.22 cgd else if ((pg = pgfind(SCARG(uap, who))) == NULL)
152 1.17 cgd break;
153 1.22 cgd for (p = pg->pg_members.lh_first; p != 0;
154 1.22 cgd p = p->p_pglist.le_next) {
155 1.22 cgd error = donice(curp, p, SCARG(uap, prio));
156 1.17 cgd found++;
157 1.17 cgd }
158 1.17 cgd break;
159 1.17 cgd }
160 1.17 cgd
161 1.17 cgd case PRIO_USER:
162 1.22 cgd if (SCARG(uap, who) == 0)
163 1.22 cgd SCARG(uap, who) = curp->p_ucred->cr_uid;
164 1.21 mycroft for (p = allproc.lh_first; p != 0; p = p->p_list.le_next)
165 1.22 cgd if (p->p_ucred->cr_uid == SCARG(uap, who)) {
166 1.22 cgd error = donice(curp, p, SCARG(uap, prio));
167 1.17 cgd found++;
168 1.17 cgd }
169 1.17 cgd break;
170 1.17 cgd
171 1.17 cgd default:
172 1.17 cgd return (EINVAL);
173 1.17 cgd }
174 1.17 cgd if (found == 0)
175 1.17 cgd return (ESRCH);
176 1.17 cgd return (error);
177 1.17 cgd }
178 1.17 cgd
179 1.25 cgd int
180 1.17 cgd donice(curp, chgp, n)
181 1.17 cgd register struct proc *curp, *chgp;
182 1.17 cgd register int n;
183 1.17 cgd {
184 1.17 cgd register struct pcred *pcred = curp->p_cred;
185 1.17 cgd
186 1.17 cgd if (pcred->pc_ucred->cr_uid && pcred->p_ruid &&
187 1.17 cgd pcred->pc_ucred->cr_uid != chgp->p_ucred->cr_uid &&
188 1.17 cgd pcred->p_ruid != chgp->p_ucred->cr_uid)
189 1.17 cgd return (EPERM);
190 1.17 cgd if (n > PRIO_MAX)
191 1.17 cgd n = PRIO_MAX;
192 1.17 cgd if (n < PRIO_MIN)
193 1.17 cgd n = PRIO_MIN;
194 1.17 cgd if (n < chgp->p_nice && suser(pcred->pc_ucred, &curp->p_acflag))
195 1.17 cgd return (EACCES);
196 1.17 cgd chgp->p_nice = n;
197 1.19 cgd (void)resetpriority(chgp);
198 1.17 cgd return (0);
199 1.17 cgd }
200 1.17 cgd
201 1.26 fvdl #if defined(COMPAT_43) || defined(COMPAT_SUNOS) || defined(COMPAT_SVR4) \
202 1.26 fvdl || defined(COMPAT_LINUX)
203 1.17 cgd /* ARGSUSED */
204 1.25 cgd int
205 1.22 cgd compat_43_setrlimit(p, uap, retval)
206 1.17 cgd struct proc *p;
207 1.22 cgd struct compat_43_setrlimit_args /* {
208 1.22 cgd syscallarg(u_int) which;
209 1.22 cgd syscallarg(struct ogetrlimit *) rlp;
210 1.22 cgd } */ *uap;
211 1.22 cgd register_t *retval;
212 1.17 cgd {
213 1.17 cgd struct orlimit olim;
214 1.17 cgd struct rlimit lim;
215 1.17 cgd int error;
216 1.17 cgd
217 1.22 cgd if (error = copyin((caddr_t)SCARG(uap, rlp), (caddr_t)&olim,
218 1.22 cgd sizeof (struct orlimit)))
219 1.17 cgd return (error);
220 1.17 cgd lim.rlim_cur = olim.rlim_cur;
221 1.17 cgd lim.rlim_max = olim.rlim_max;
222 1.22 cgd return (dosetrlimit(p, SCARG(uap, which), &lim));
223 1.17 cgd }
224 1.17 cgd
225 1.17 cgd /* ARGSUSED */
226 1.25 cgd int
227 1.22 cgd compat_43_getrlimit(p, uap, retval)
228 1.17 cgd struct proc *p;
229 1.22 cgd register struct compat_43_getrlimit_args /* {
230 1.22 cgd syscallarg(u_int) which;
231 1.22 cgd syscallarg(struct ogetrlimit *) rlp;
232 1.22 cgd } */ *uap;
233 1.22 cgd register_t *retval;
234 1.17 cgd {
235 1.17 cgd struct orlimit olim;
236 1.17 cgd
237 1.22 cgd if (SCARG(uap, which) >= RLIM_NLIMITS)
238 1.17 cgd return (EINVAL);
239 1.22 cgd olim.rlim_cur = p->p_rlimit[SCARG(uap, which)].rlim_cur;
240 1.17 cgd if (olim.rlim_cur == -1)
241 1.17 cgd olim.rlim_cur = 0x7fffffff;
242 1.22 cgd olim.rlim_max = p->p_rlimit[SCARG(uap, which)].rlim_max;
243 1.17 cgd if (olim.rlim_max == -1)
244 1.17 cgd olim.rlim_max = 0x7fffffff;
245 1.22 cgd return (copyout((caddr_t)&olim, (caddr_t)SCARG(uap, rlp),
246 1.22 cgd sizeof(olim)));
247 1.17 cgd }
248 1.26 fvdl #endif /* COMPAT_43 || COMPAT_SUNOS || COMPAT_SVR4 || COMPAT_LINUX */
249 1.17 cgd
250 1.17 cgd /* ARGSUSED */
251 1.25 cgd int
252 1.17 cgd setrlimit(p, uap, retval)
253 1.17 cgd struct proc *p;
254 1.22 cgd register struct setrlimit_args /* {
255 1.22 cgd syscallarg(u_int) which;
256 1.22 cgd syscallarg(struct rlimit *) rlp;
257 1.22 cgd } */ *uap;
258 1.22 cgd register_t *retval;
259 1.17 cgd {
260 1.19 cgd struct rlimit alim;
261 1.17 cgd int error;
262 1.17 cgd
263 1.22 cgd if (error = copyin((caddr_t)SCARG(uap, rlp), (caddr_t)&alim,
264 1.22 cgd sizeof (struct rlimit)))
265 1.17 cgd return (error);
266 1.22 cgd return (dosetrlimit(p, SCARG(uap, which), &alim));
267 1.17 cgd }
268 1.17 cgd
269 1.17 cgd int
270 1.17 cgd dosetrlimit(p, which, limp)
271 1.17 cgd struct proc *p;
272 1.17 cgd u_int which;
273 1.17 cgd struct rlimit *limp;
274 1.17 cgd {
275 1.17 cgd register struct rlimit *alimp;
276 1.19 cgd extern unsigned maxdmap, maxsmap;
277 1.17 cgd int error;
278 1.17 cgd
279 1.17 cgd if (which >= RLIM_NLIMITS)
280 1.17 cgd return (EINVAL);
281 1.17 cgd alimp = &p->p_rlimit[which];
282 1.19 cgd if (limp->rlim_cur > alimp->rlim_max ||
283 1.17 cgd limp->rlim_max > alimp->rlim_max)
284 1.17 cgd if (error = suser(p->p_ucred, &p->p_acflag))
285 1.17 cgd return (error);
286 1.17 cgd if (limp->rlim_cur > limp->rlim_max)
287 1.17 cgd limp->rlim_cur = limp->rlim_max;
288 1.17 cgd if (p->p_limit->p_refcnt > 1 &&
289 1.17 cgd (p->p_limit->p_lflags & PL_SHAREMOD) == 0) {
290 1.17 cgd p->p_limit->p_refcnt--;
291 1.17 cgd p->p_limit = limcopy(p->p_limit);
292 1.17 cgd alimp = &p->p_rlimit[which];
293 1.17 cgd }
294 1.17 cgd
295 1.17 cgd switch (which) {
296 1.17 cgd
297 1.17 cgd case RLIMIT_DATA:
298 1.19 cgd if (limp->rlim_cur > maxdmap)
299 1.19 cgd limp->rlim_cur = maxdmap;
300 1.19 cgd if (limp->rlim_max > maxdmap)
301 1.19 cgd limp->rlim_max = maxdmap;
302 1.17 cgd break;
303 1.17 cgd
304 1.17 cgd case RLIMIT_STACK:
305 1.19 cgd if (limp->rlim_cur > maxsmap)
306 1.19 cgd limp->rlim_cur = maxsmap;
307 1.19 cgd if (limp->rlim_max > maxsmap)
308 1.19 cgd limp->rlim_max = maxsmap;
309 1.17 cgd /*
310 1.17 cgd * Stack is allocated to the max at exec time with only
311 1.17 cgd * "rlim_cur" bytes accessible. If stack limit is going
312 1.17 cgd * up make more accessible, if going down make inaccessible.
313 1.17 cgd */
314 1.17 cgd if (limp->rlim_cur != alimp->rlim_cur) {
315 1.17 cgd vm_offset_t addr;
316 1.17 cgd vm_size_t size;
317 1.17 cgd vm_prot_t prot;
318 1.17 cgd
319 1.17 cgd if (limp->rlim_cur > alimp->rlim_cur) {
320 1.17 cgd prot = VM_PROT_ALL;
321 1.17 cgd size = limp->rlim_cur - alimp->rlim_cur;
322 1.17 cgd addr = USRSTACK - limp->rlim_cur;
323 1.17 cgd } else {
324 1.17 cgd prot = VM_PROT_NONE;
325 1.17 cgd size = alimp->rlim_cur - limp->rlim_cur;
326 1.17 cgd addr = USRSTACK - alimp->rlim_cur;
327 1.17 cgd }
328 1.17 cgd addr = trunc_page(addr);
329 1.17 cgd size = round_page(size);
330 1.17 cgd (void) vm_map_protect(&p->p_vmspace->vm_map,
331 1.17 cgd addr, addr+size, prot, FALSE);
332 1.17 cgd }
333 1.17 cgd break;
334 1.19 cgd
335 1.19 cgd case RLIMIT_NOFILE:
336 1.19 cgd if (limp->rlim_cur > maxfiles)
337 1.19 cgd limp->rlim_cur = maxfiles;
338 1.19 cgd if (limp->rlim_max > maxfiles)
339 1.19 cgd limp->rlim_max = maxfiles;
340 1.19 cgd break;
341 1.19 cgd
342 1.19 cgd case RLIMIT_NPROC:
343 1.19 cgd if (limp->rlim_cur > maxproc)
344 1.19 cgd limp->rlim_cur = maxproc;
345 1.19 cgd if (limp->rlim_max > maxproc)
346 1.19 cgd limp->rlim_max = maxproc;
347 1.19 cgd break;
348 1.17 cgd }
349 1.17 cgd *alimp = *limp;
350 1.17 cgd return (0);
351 1.17 cgd }
352 1.17 cgd
353 1.17 cgd /* ARGSUSED */
354 1.25 cgd int
355 1.17 cgd getrlimit(p, uap, retval)
356 1.17 cgd struct proc *p;
357 1.22 cgd register struct getrlimit_args /* {
358 1.22 cgd syscallarg(u_int) which;
359 1.22 cgd syscallarg(struct rlimit *) rlp;
360 1.22 cgd } */ *uap;
361 1.22 cgd register_t *retval;
362 1.17 cgd {
363 1.17 cgd
364 1.22 cgd if (SCARG(uap, which) >= RLIM_NLIMITS)
365 1.17 cgd return (EINVAL);
366 1.22 cgd return (copyout((caddr_t)&p->p_rlimit[SCARG(uap, which)],
367 1.22 cgd (caddr_t)SCARG(uap, rlp), sizeof (struct rlimit)));
368 1.17 cgd }
369 1.17 cgd
370 1.17 cgd /*
371 1.17 cgd * Transform the running time and tick information in proc p into user,
372 1.17 cgd * system, and interrupt time usage.
373 1.17 cgd */
374 1.25 cgd void
375 1.17 cgd calcru(p, up, sp, ip)
376 1.17 cgd register struct proc *p;
377 1.17 cgd register struct timeval *up;
378 1.17 cgd register struct timeval *sp;
379 1.17 cgd register struct timeval *ip;
380 1.17 cgd {
381 1.17 cgd register u_quad_t u, st, ut, it, tot;
382 1.17 cgd register u_long sec, usec;
383 1.17 cgd register int s;
384 1.17 cgd struct timeval tv;
385 1.17 cgd
386 1.17 cgd s = splstatclock();
387 1.17 cgd st = p->p_sticks;
388 1.17 cgd ut = p->p_uticks;
389 1.17 cgd it = p->p_iticks;
390 1.17 cgd splx(s);
391 1.17 cgd
392 1.17 cgd tot = st + ut + it;
393 1.17 cgd if (tot == 0) {
394 1.17 cgd up->tv_sec = up->tv_usec = 0;
395 1.17 cgd sp->tv_sec = sp->tv_usec = 0;
396 1.17 cgd if (ip != NULL)
397 1.17 cgd ip->tv_sec = ip->tv_usec = 0;
398 1.17 cgd return;
399 1.17 cgd }
400 1.17 cgd
401 1.17 cgd sec = p->p_rtime.tv_sec;
402 1.17 cgd usec = p->p_rtime.tv_usec;
403 1.17 cgd if (p == curproc) {
404 1.17 cgd /*
405 1.17 cgd * Adjust for the current time slice. This is actually fairly
406 1.17 cgd * important since the error here is on the order of a time
407 1.17 cgd * quantum, which is much greater than the sampling error.
408 1.17 cgd */
409 1.17 cgd microtime(&tv);
410 1.17 cgd sec += tv.tv_sec - runtime.tv_sec;
411 1.17 cgd usec += tv.tv_usec - runtime.tv_usec;
412 1.17 cgd }
413 1.17 cgd u = sec * 1000000 + usec;
414 1.17 cgd st = (u * st) / tot;
415 1.17 cgd sp->tv_sec = st / 1000000;
416 1.17 cgd sp->tv_usec = st % 1000000;
417 1.17 cgd ut = (u * ut) / tot;
418 1.17 cgd up->tv_sec = ut / 1000000;
419 1.17 cgd up->tv_usec = ut % 1000000;
420 1.17 cgd if (ip != NULL) {
421 1.17 cgd it = (u * it) / tot;
422 1.17 cgd ip->tv_sec = it / 1000000;
423 1.17 cgd ip->tv_usec = it % 1000000;
424 1.17 cgd }
425 1.17 cgd }
426 1.17 cgd
427 1.17 cgd /* ARGSUSED */
428 1.25 cgd int
429 1.17 cgd getrusage(p, uap, retval)
430 1.17 cgd register struct proc *p;
431 1.22 cgd register struct getrusage_args /* {
432 1.22 cgd syscallarg(int) who;
433 1.22 cgd syscallarg(struct rusage *) rusage;
434 1.22 cgd } */ *uap;
435 1.22 cgd register_t *retval;
436 1.17 cgd {
437 1.17 cgd register struct rusage *rup;
438 1.17 cgd
439 1.22 cgd switch (SCARG(uap, who)) {
440 1.17 cgd
441 1.19 cgd case RUSAGE_SELF:
442 1.17 cgd rup = &p->p_stats->p_ru;
443 1.17 cgd calcru(p, &rup->ru_utime, &rup->ru_stime, NULL);
444 1.17 cgd break;
445 1.17 cgd
446 1.17 cgd case RUSAGE_CHILDREN:
447 1.17 cgd rup = &p->p_stats->p_cru;
448 1.17 cgd break;
449 1.17 cgd
450 1.17 cgd default:
451 1.17 cgd return (EINVAL);
452 1.17 cgd }
453 1.22 cgd return (copyout((caddr_t)rup, (caddr_t)SCARG(uap, rusage),
454 1.17 cgd sizeof (struct rusage)));
455 1.17 cgd }
456 1.17 cgd
457 1.25 cgd void
458 1.17 cgd ruadd(ru, ru2)
459 1.17 cgd register struct rusage *ru, *ru2;
460 1.17 cgd {
461 1.17 cgd register long *ip, *ip2;
462 1.17 cgd register int i;
463 1.17 cgd
464 1.24 mycroft __timeradd(&ru->ru_utime, &ru2->ru_utime);
465 1.24 mycroft __timeradd(&ru->ru_stime, &ru2->ru_stime);
466 1.17 cgd if (ru->ru_maxrss < ru2->ru_maxrss)
467 1.17 cgd ru->ru_maxrss = ru2->ru_maxrss;
468 1.17 cgd ip = &ru->ru_first; ip2 = &ru2->ru_first;
469 1.17 cgd for (i = &ru->ru_last - &ru->ru_first; i >= 0; i--)
470 1.17 cgd *ip++ += *ip2++;
471 1.17 cgd }
472 1.17 cgd
473 1.17 cgd /*
474 1.17 cgd * Make a copy of the plimit structure.
475 1.17 cgd * We share these structures copy-on-write after fork,
476 1.17 cgd * and copy when a limit is changed.
477 1.17 cgd */
478 1.17 cgd struct plimit *
479 1.17 cgd limcopy(lim)
480 1.17 cgd struct plimit *lim;
481 1.17 cgd {
482 1.17 cgd register struct plimit *copy;
483 1.17 cgd
484 1.17 cgd MALLOC(copy, struct plimit *, sizeof(struct plimit),
485 1.17 cgd M_SUBPROC, M_WAITOK);
486 1.17 cgd bcopy(lim->pl_rlimit, copy->pl_rlimit,
487 1.17 cgd sizeof(struct rlimit) * RLIM_NLIMITS);
488 1.17 cgd copy->p_lflags = 0;
489 1.17 cgd copy->p_refcnt = 1;
490 1.17 cgd return (copy);
491 1.17 cgd }
492