Mon Dec 24 20:44:39 2018 UTC ()
move rlimit and quota code into their own modules.

(netbsd32_netbsd.c should have only simple shims.  anything more
than copying arguments from one args struct to the other should
not be placed in this file.  still a couple more to move out.)


(mrg)
diff -r1.39 -r1.40 src/sys/compat/netbsd32/files.netbsd32
diff -r1.220 -r1.221 src/sys/compat/netbsd32/netbsd32_netbsd.c
diff -r0 -r1.1 src/sys/compat/netbsd32/netbsd32_quota.c
diff -r0 -r1.1 src/sys/compat/netbsd32/netbsd32_rlimit.c

cvs diff -r1.39 -r1.40 src/sys/compat/netbsd32/files.netbsd32 (expand / switch to context diff)
--- src/sys/compat/netbsd32/files.netbsd32 2016/10/19 09:44:01 1.39
+++ src/sys/compat/netbsd32/files.netbsd32 2018/12/24 20:44:39 1.40
@@ -1,4 +1,4 @@
-#	$NetBSD: files.netbsd32,v 1.39 2016/10/19 09:44:01 skrll Exp $
+#	$NetBSD: files.netbsd32,v 1.40 2018/12/24 20:44:39 mrg Exp $
 #
 # config file description for machine-independent netbsd32 compat code.
 # included by ports that need it.
@@ -22,6 +22,8 @@
 file	compat/netbsd32/netbsd32_mqueue.c	compat_netbsd32 & mqueue
 file	compat/netbsd32/netbsd32_nfssvc.c	compat_netbsd32 & nfsserver
 file	compat/netbsd32/netbsd32_ptrace.c	compat_netbsd32 & ptrace
+file	compat/netbsd32/netbsd32_rlimit.c	compat_netbsd32
+file	compat/netbsd32/netbsd32_quota.c	compat_netbsd32 & quota
 file	compat/netbsd32/netbsd32_select.c	compat_netbsd32
 file	compat/netbsd32/netbsd32_sem.c		compat_netbsd32
 file	compat/netbsd32/netbsd32_signal.c	compat_netbsd32

cvs diff -r1.220 -r1.221 src/sys/compat/netbsd32/netbsd32_netbsd.c (expand / switch to context diff)
--- src/sys/compat/netbsd32/netbsd32_netbsd.c 2018/12/24 20:39:17 1.220
+++ src/sys/compat/netbsd32/netbsd32_netbsd.c 2018/12/24 20:44:39 1.221
@@ -1,4 +1,4 @@
-/*	$NetBSD: netbsd32_netbsd.c,v 1.220 2018/12/24 20:39:17 mrg Exp $	*/
+/*	$NetBSD: netbsd32_netbsd.c,v 1.221 2018/12/24 20:44:39 mrg Exp $	*/
 
 /*
  * Copyright (c) 1998, 2001, 2008, 2018 Matthew R. Green
@@ -27,7 +27,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: netbsd32_netbsd.c,v 1.220 2018/12/24 20:39:17 mrg Exp $");
+__KERNEL_RCSID(0, "$NetBSD: netbsd32_netbsd.c,v 1.221 2018/12/24 20:44:39 mrg Exp $");
 
 /*
  * below are all the standard NetBSD system calls, in the 32bit
@@ -37,6 +37,14 @@
  * calls to the original function.
  */
 
+/*
+ * below are all the standard NetBSD system calls, in the 32bit
+ * environment, with the necessary conversions to 64bit before calling
+ * the real syscall.  anything that needs special attention is handled
+ * elsewhere - this file should only contain structure assignment and
+ * calls to the original function.
+ */
+
 #if defined(_KERNEL_OPT)
 #include "opt_ddb.h"
 #include "opt_ntp.h"
@@ -1206,101 +1214,8 @@
 	return sys_rmdir(l, &ua, retval);
 }
 
+// XXX new file
 int
-netbsd32___quotactl(struct lwp *l, const struct netbsd32___quotactl_args *uap, register_t *retval)
-{
-	/* {
-		syscallarg(const netbsd32_charp) path;
-		syscallarg(netbsd32_voidp) args;
-	} */
-	struct netbsd32_quotactlargs args32;
-	struct quotactl_args args;
-	int error;
-
-	error = copyin(SCARG_P32(uap, args), &args32, sizeof(args32));
-	if (error) {
-		return error;
-	}
-
-	args.qc_op = args32.qc_op;
-	switch (args.qc_op) {
-	    case QUOTACTL_STAT:
-		args.u.stat.qc_info = NETBSD32PTR64(args32.u.stat.qc_info);
-		break;
-	    case QUOTACTL_IDTYPESTAT:
-		args.u.idtypestat.qc_idtype = args32.u.idtypestat.qc_idtype;
-		args.u.idtypestat.qc_info =
-			NETBSD32PTR64(args32.u.idtypestat.qc_info);
-		break;
-	    case QUOTACTL_OBJTYPESTAT:
-		args.u.objtypestat.qc_objtype =
-			args32.u.objtypestat.qc_objtype;
-		args.u.objtypestat.qc_info =
-			NETBSD32PTR64(args32.u.objtypestat.qc_info);
-		break;
-	    case QUOTACTL_GET:
-		args.u.get.qc_key = NETBSD32PTR64(args32.u.get.qc_key);
-		args.u.get.qc_val = NETBSD32PTR64(args32.u.get.qc_val);
-		break;
-	    case QUOTACTL_PUT:
-		args.u.put.qc_key = NETBSD32PTR64(args32.u.put.qc_key);
-		args.u.put.qc_val = NETBSD32PTR64(args32.u.put.qc_val);
-		break;
-	    case QUOTACTL_DEL:
-		args.u.del.qc_key = NETBSD32PTR64(args32.u.del.qc_key);
-		break;
-	    case QUOTACTL_CURSOROPEN:
-		args.u.cursoropen.qc_cursor =
-			NETBSD32PTR64(args32.u.cursoropen.qc_cursor);
-		break;
-	    case QUOTACTL_CURSORCLOSE:
-		args.u.cursorclose.qc_cursor =
-			NETBSD32PTR64(args32.u.cursorclose.qc_cursor);
-		break;
-	    case QUOTACTL_CURSORSKIPIDTYPE:
-		args.u.cursorskipidtype.qc_cursor =
-			NETBSD32PTR64(args32.u.cursorskipidtype.qc_cursor);
-		args.u.cursorskipidtype.qc_idtype =
-			args32.u.cursorskipidtype.qc_idtype;
-		break;
-	    case QUOTACTL_CURSORGET:
-		args.u.cursorget.qc_cursor =
-			NETBSD32PTR64(args32.u.cursorget.qc_cursor);
-		args.u.cursorget.qc_keys =
-			NETBSD32PTR64(args32.u.cursorget.qc_keys);
-		args.u.cursorget.qc_vals =
-			NETBSD32PTR64(args32.u.cursorget.qc_vals);
-		args.u.cursorget.qc_maxnum =
-			args32.u.cursorget.qc_maxnum;
-		args.u.cursorget.qc_ret =
-			NETBSD32PTR64(args32.u.cursorget.qc_ret);
-		break;
-	    case QUOTACTL_CURSORATEND:
-		args.u.cursoratend.qc_cursor =
-			NETBSD32PTR64(args32.u.cursoratend.qc_cursor);
-		args.u.cursoratend.qc_ret =
-			NETBSD32PTR64(args32.u.cursoratend.qc_ret);
-		break;
-	    case QUOTACTL_CURSORREWIND:
-		args.u.cursorrewind.qc_cursor =
-			NETBSD32PTR64(args32.u.cursorrewind.qc_cursor);
-		break;
-	    case QUOTACTL_QUOTAON:
-		args.u.quotaon.qc_idtype = args32.u.quotaon.qc_idtype;
-		args.u.quotaon.qc_quotafile =
-			NETBSD32PTR64(args32.u.quotaon.qc_quotafile);
-		break;
-	    case QUOTACTL_QUOTAOFF:
-		args.u.quotaoff.qc_idtype = args32.u.quotaoff.qc_idtype;
-		break;
-	    default:
-		return EINVAL;
-	}
-
-	return do_sys_quotactl(SCARG_P32(uap, path), &args);
-}
-
-int
 netbsd32___getfh30(struct lwp *l, const struct netbsd32___getfh30_args *uap, register_t *retval)
 {
 	/* {
@@ -1471,76 +1386,12 @@
 
 	NETBSD32TO64_UAP(fd);
 	NETBSD32TO64_UAP(name);
+
 	return sys_fpathconf(l, &ua, retval);
 }
 
-static void
-fixlimit(int which, struct rlimit *alim)
-{
-	switch (which) {
-	case RLIMIT_DATA:
-		if (LIMITCHECK(alim->rlim_cur, MAXDSIZ32))
-			alim->rlim_cur = MAXDSIZ32;
-		if (LIMITCHECK(alim->rlim_max, MAXDSIZ32))
-			alim->rlim_max = MAXDSIZ32;
-		return;
-	case RLIMIT_STACK:
-		if (LIMITCHECK(alim->rlim_cur, MAXSSIZ32))
-			alim->rlim_cur = MAXSSIZ32;
-		if (LIMITCHECK(alim->rlim_max, MAXSSIZ32))
-			alim->rlim_max = MAXSSIZ32;
-		return;
-	default:
-		return;
-	}
-}
-
+// XXX new file
 int
-netbsd32_getrlimit(struct lwp *l, const struct netbsd32_getrlimit_args *uap,
-    register_t *retval)
-{
-	/* {
-		syscallarg(int) which;
-		syscallarg(netbsd32_rlimitp_t) rlp;
-	} */
-	int which = SCARG(uap, which);
-	struct rlimit alim;
-
-	if ((u_int)which >= RLIM_NLIMITS)
-		return EINVAL;
-
-	alim = l->l_proc->p_rlimit[which];
-
-	fixlimit(which, &alim);
-
-	return copyout(&alim, SCARG_P32(uap, rlp), sizeof(alim));
-}
-
-int
-netbsd32_setrlimit(struct lwp *l, const struct netbsd32_setrlimit_args *uap,
-    register_t *retval)
-{
-	/* {
-		syscallarg(int) which;
-		syscallarg(const netbsd32_rlimitp_t) rlp;
-	} */
-		int which = SCARG(uap, which);
-	struct rlimit alim;
-	int error;
-
-	if ((u_int)which >= RLIM_NLIMITS)
-		return EINVAL;
-
-	error = copyin(SCARG_P32(uap, rlp), &alim, sizeof(struct rlimit));
-	if (error)
-		return error;
-
-	fixlimit(which, &alim);
-
-	return dosetrlimit(l, l->l_proc, which, &alim);
-}
-
-int
 netbsd32_mmap(struct lwp *l, const struct netbsd32_mmap_args *uap, register_t *retval)
 {
 	/* {
@@ -2078,56 +1929,6 @@
 	NETBSD32TO64_UAP(anom);
 
 	return sys_ovadvise(l, &ua, retval);
-}
-
-void
-netbsd32_adjust_limits(struct proc *p)
-{
-	static const struct {
-		int id;
-		rlim_t lim;
-	} lm[] = {
-		{ RLIMIT_DATA,	MAXDSIZ32 },
-		{ RLIMIT_STACK, MAXSSIZ32 },
-	};
-	size_t i;
-	struct plimit *lim;
-	struct rlimit *rlim;
-
-	/*
-	 * We can only reduce the current limits, we cannot stop external
-	 * processes from changing them (eg via sysctl) later on.
-	 * So there is no point trying to lock out such changes here.
-	 *
-	 * If we assume that rlim_cur/max are accessed using atomic
-	 * operations, we don't need to lock against any other updates
-	 * that might happen if the plimit structure is shared writable
-	 * between multiple processes.
-	 */
-
-	/* Scan to determine is any limits are out of range */
-	lim = p->p_limit;
-	for (i = 0; ; i++) {
-		if (i >= __arraycount(lm))
-			/* All in range */
-			return;
-		rlim = lim->pl_rlimit + lm[i].id;
-		if (LIMITCHECK(rlim->rlim_cur, lm[i].lim))
-			break;
-		if (LIMITCHECK(rlim->rlim_max, lm[i].lim))
-			break;
-	}
-
-	lim_privatise(p);
-
-	lim = p->p_limit;
-	for (i = 0; i < __arraycount(lm); i++) {
-		rlim = lim->pl_rlimit + lm[i].id;
-		if (LIMITCHECK(rlim->rlim_cur, lm[i].lim))
-			rlim->rlim_cur = lm[i].lim;
-		if (LIMITCHECK(rlim->rlim_max, lm[i].lim))
-			rlim->rlim_max = lm[i].lim;
-	}
 }
 
 int

File Added: src/sys/compat/netbsd32/netbsd32_quota.c
/*	$NetBSD: netbsd32_quota.c,v 1.1 2018/12/24 20:44:39 mrg Exp $	*/

/*
 * Copyright (c) 1998, 2001, 2008, 2018 Matthew R. Green
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 * 1. Redistributions of source code must retain the above copyright
 *    notice, this list of conditions and the following disclaimer.
 * 2. Redistributions in binary form must reproduce the above copyright
 *    notice, this list of conditions and the following disclaimer in the
 *    documentation and/or other materials provided with the distribution.
 *
 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
 * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
 * SUCH DAMAGE.
 *
 * from: NetBSD: netbsd32_netbsd.c,v 1.218 2018/08/10 21:44:58 pgoyette Exp
 */

#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: netbsd32_quota.c,v 1.1 2018/12/24 20:44:39 mrg Exp $");

#include <sys/param.h>
#include <sys/systm.h>
#include <sys/quotactl.h>
#include <sys/filedesc.h>
#include <sys/vfs_syscalls.h>

#include <compat/netbsd32/netbsd32.h>
#include <compat/netbsd32/netbsd32_syscall.h>
#include <compat/netbsd32/netbsd32_syscallargs.h>
#include <compat/netbsd32/netbsd32_conv.h>

int
netbsd32___quotactl(struct lwp *l, const struct netbsd32___quotactl_args *uap, register_t *retval)
{
	/* {
		syscallarg(const netbsd32_charp) path;
		syscallarg(netbsd32_voidp) args;
	} */
	struct netbsd32_quotactlargs args32;
	struct quotactl_args args;
	int error;

	error = copyin(SCARG_P32(uap, args), &args32, sizeof(args32));
	if (error) {
		return error;
	}

	args.qc_op = args32.qc_op;
	switch (args.qc_op) {
	    case QUOTACTL_STAT:
		args.u.stat.qc_info = NETBSD32PTR64(args32.u.stat.qc_info);
		break;
	    case QUOTACTL_IDTYPESTAT:
		args.u.idtypestat.qc_idtype = args32.u.idtypestat.qc_idtype;
		args.u.idtypestat.qc_info =
			NETBSD32PTR64(args32.u.idtypestat.qc_info);
		break;
	    case QUOTACTL_OBJTYPESTAT:
		args.u.objtypestat.qc_objtype =
			args32.u.objtypestat.qc_objtype;
		args.u.objtypestat.qc_info =
			NETBSD32PTR64(args32.u.objtypestat.qc_info);
		break;
	    case QUOTACTL_GET:
		args.u.get.qc_key = NETBSD32PTR64(args32.u.get.qc_key);
		args.u.get.qc_val = NETBSD32PTR64(args32.u.get.qc_val);
		break;
	    case QUOTACTL_PUT:
		args.u.put.qc_key = NETBSD32PTR64(args32.u.put.qc_key);
		args.u.put.qc_val = NETBSD32PTR64(args32.u.put.qc_val);
		break;
	    case QUOTACTL_DEL:
		args.u.del.qc_key = NETBSD32PTR64(args32.u.del.qc_key);
		break;
	    case QUOTACTL_CURSOROPEN:
		args.u.cursoropen.qc_cursor =
			NETBSD32PTR64(args32.u.cursoropen.qc_cursor);
		break;
	    case QUOTACTL_CURSORCLOSE:
		args.u.cursorclose.qc_cursor =
			NETBSD32PTR64(args32.u.cursorclose.qc_cursor);
		break;
	    case QUOTACTL_CURSORSKIPIDTYPE:
		args.u.cursorskipidtype.qc_cursor =
			NETBSD32PTR64(args32.u.cursorskipidtype.qc_cursor);
		args.u.cursorskipidtype.qc_idtype =
			args32.u.cursorskipidtype.qc_idtype;
		break;
	    case QUOTACTL_CURSORGET:
		args.u.cursorget.qc_cursor =
			NETBSD32PTR64(args32.u.cursorget.qc_cursor);
		args.u.cursorget.qc_keys =
			NETBSD32PTR64(args32.u.cursorget.qc_keys);
		args.u.cursorget.qc_vals =
			NETBSD32PTR64(args32.u.cursorget.qc_vals);
		args.u.cursorget.qc_maxnum =
			args32.u.cursorget.qc_maxnum;
		args.u.cursorget.qc_ret =
			NETBSD32PTR64(args32.u.cursorget.qc_ret);
		break;
	    case QUOTACTL_CURSORATEND:
		args.u.cursoratend.qc_cursor =
			NETBSD32PTR64(args32.u.cursoratend.qc_cursor);
		args.u.cursoratend.qc_ret =
			NETBSD32PTR64(args32.u.cursoratend.qc_ret);
		break;
	    case QUOTACTL_CURSORREWIND:
		args.u.cursorrewind.qc_cursor =
			NETBSD32PTR64(args32.u.cursorrewind.qc_cursor);
		break;
	    case QUOTACTL_QUOTAON:
		args.u.quotaon.qc_idtype = args32.u.quotaon.qc_idtype;
		args.u.quotaon.qc_quotafile =
			NETBSD32PTR64(args32.u.quotaon.qc_quotafile);
		break;
	    case QUOTACTL_QUOTAOFF:
		args.u.quotaoff.qc_idtype = args32.u.quotaoff.qc_idtype;
		break;
	    default:
		return EINVAL;
	}

	return do_sys_quotactl(SCARG_P32(uap, path), &args);
}

File Added: src/sys/compat/netbsd32/netbsd32_rlimit.c
/*	$NetBSD: netbsd32_rlimit.c,v 1.1 2018/12/24 20:44:39 mrg Exp $	*/

/*
 * Copyright (c) 1998, 2001, 2008, 2018 Matthew R. Green
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 * 1. Redistributions of source code must retain the above copyright
 *    notice, this list of conditions and the following disclaimer.
 * 2. Redistributions in binary form must reproduce the above copyright
 *    notice, this list of conditions and the following disclaimer in the
 *    documentation and/or other materials provided with the distribution.
 *
 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
 * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
 * SUCH DAMAGE.
 *
 * from: NetBSD: netbsd32_netbsd.c,v 1.218 2018/08/10 21:44:58 pgoyette Exp
 */

/* rlimit netbsd32 related code */

#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: netbsd32_rlimit.c,v 1.1 2018/12/24 20:44:39 mrg Exp $");

#include <sys/param.h>
#include <sys/systm.h>
#include <sys/resource.h>
#include <sys/exec.h>

#include <compat/netbsd32/netbsd32.h>
#include <compat/netbsd32/netbsd32_syscall.h>
#include <compat/netbsd32/netbsd32_syscallargs.h>
#include <compat/netbsd32/netbsd32_conv.h>

#define LIMITCHECK(a, b) ((a) != RLIM_INFINITY && (a) > (b))

static void
fixlimit(int which, struct rlimit *alim)
{
	switch (which) {
	case RLIMIT_DATA:
		if (LIMITCHECK(alim->rlim_cur, MAXDSIZ32))
			alim->rlim_cur = MAXDSIZ32;
		if (LIMITCHECK(alim->rlim_max, MAXDSIZ32))
			alim->rlim_max = MAXDSIZ32;
		return;
	case RLIMIT_STACK:
		if (LIMITCHECK(alim->rlim_cur, MAXSSIZ32))
			alim->rlim_cur = MAXSSIZ32;
		if (LIMITCHECK(alim->rlim_max, MAXSSIZ32))
			alim->rlim_max = MAXSSIZ32;
		return;
	default:
		return;
	}
}

int
netbsd32_getrlimit(struct lwp *l, const struct netbsd32_getrlimit_args *uap,
    register_t *retval)
{
	/* {
		syscallarg(int) which;
		syscallarg(netbsd32_rlimitp_t) rlp;
	} */
	int which = SCARG(uap, which);
	struct rlimit alim;

	if ((u_int)which >= RLIM_NLIMITS)
		return EINVAL;

	alim = l->l_proc->p_rlimit[which];

	fixlimit(which, &alim);

	return copyout(&alim, SCARG_P32(uap, rlp), sizeof(alim));
}

int
netbsd32_setrlimit(struct lwp *l, const struct netbsd32_setrlimit_args *uap,
    register_t *retval)
{
	/* {
		syscallarg(int) which;
		syscallarg(const netbsd32_rlimitp_t) rlp;
	} */
		int which = SCARG(uap, which);
	struct rlimit alim;
	int error;

	if ((u_int)which >= RLIM_NLIMITS)
		return EINVAL;

	error = copyin(SCARG_P32(uap, rlp), &alim, sizeof(struct rlimit));
	if (error)
		return (error);

	fixlimit(which, &alim);

	return dosetrlimit(l, l->l_proc, which, &alim);
}

void
netbsd32_adjust_limits(struct proc *p)
{
	static const struct {
		int id;
		rlim_t lim;
	} lm[] = {
		{ RLIMIT_DATA,	MAXDSIZ32 },
		{ RLIMIT_STACK, MAXSSIZ32 },
	};
	size_t i;
	struct plimit *lim;
	struct rlimit *rlim;

	/*
	 * We can only reduce the current limits, we cannot stop external
	 * processes from changing them (eg via sysctl) later on.
	 * So there is no point trying to lock out such changes here.
	 *
	 * If we assume that rlim_cur/max are accessed using atomic
	 * operations, we don't need to lock against any other updates
	 * that might happen if the plimit structure is shared writable
	 * between multiple processes.
	 */

	/* Scan to determine is any limits are out of range */
	lim = p->p_limit;
	for (i = 0; ; i++) {
		if (i >= __arraycount(lm))
			/* All in range */
			return;
		rlim = lim->pl_rlimit + lm[i].id;
		if (LIMITCHECK(rlim->rlim_cur, lm[i].lim))
			break;
		if (LIMITCHECK(rlim->rlim_max, lm[i].lim))
			break;
	}

	lim_privatise(p);

	lim = p->p_limit;
	for (i = 0; i < __arraycount(lm); i++) {
		rlim = lim->pl_rlimit + lm[i].id;
		if (LIMITCHECK(rlim->rlim_cur, lm[i].lim))
			rlim->rlim_cur = lm[i].lim;
		if (LIMITCHECK(rlim->rlim_max, lm[i].lim))
			rlim->rlim_max = lm[i].lim;
	}
}