xref: /titanic_51/usr/src/uts/common/os/rctl_proc.c (revision 5e989a96186a37eb528fb7bb4d28a150874ec799)
17c478bd9Sstevel@tonic-gate /*
27c478bd9Sstevel@tonic-gate  * CDDL HEADER START
37c478bd9Sstevel@tonic-gate  *
47c478bd9Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
5aa042c4bSkchow  * Common Development and Distribution License (the "License").
6aa042c4bSkchow  * You may not use this file except in compliance with the License.
77c478bd9Sstevel@tonic-gate  *
87c478bd9Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
97c478bd9Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
107c478bd9Sstevel@tonic-gate  * See the License for the specific language governing permissions
117c478bd9Sstevel@tonic-gate  * and limitations under the License.
127c478bd9Sstevel@tonic-gate  *
137c478bd9Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
147c478bd9Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
157c478bd9Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
167c478bd9Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
177c478bd9Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
187c478bd9Sstevel@tonic-gate  *
197c478bd9Sstevel@tonic-gate  * CDDL HEADER END
207c478bd9Sstevel@tonic-gate  */
217c478bd9Sstevel@tonic-gate /*
22aa042c4bSkchow  * Copyright 2006 Sun Microsystems, Inc.  All rights reserved.
237c478bd9Sstevel@tonic-gate  * Use is subject to license terms.
247c478bd9Sstevel@tonic-gate  */
257c478bd9Sstevel@tonic-gate 
267c478bd9Sstevel@tonic-gate #include <sys/types.h>
277c478bd9Sstevel@tonic-gate #include <sys/cmn_err.h>
287c478bd9Sstevel@tonic-gate #include <sys/sysmacros.h>
297c478bd9Sstevel@tonic-gate #include <sys/proc.h>
307c478bd9Sstevel@tonic-gate #include <sys/rctl.h>
317c478bd9Sstevel@tonic-gate #include <sys/rctl_impl.h>
327c478bd9Sstevel@tonic-gate #include <sys/port_kernel.h>
33*5e989a96SDavid Höppner #include <sys/signal.h>
34*5e989a96SDavid Höppner #include <sys/var.h>
357c478bd9Sstevel@tonic-gate 
367c478bd9Sstevel@tonic-gate #include <sys/vmparam.h>
377c478bd9Sstevel@tonic-gate #include <sys/machparam.h>
387c478bd9Sstevel@tonic-gate 
397c478bd9Sstevel@tonic-gate /*
407c478bd9Sstevel@tonic-gate  * Process-based resource controls
417c478bd9Sstevel@tonic-gate  *   The structure of the kernel leaves us no particular place where the process
427c478bd9Sstevel@tonic-gate  *   abstraction can be declared--it is intertwined with the growth of the Unix
437c478bd9Sstevel@tonic-gate  *   kernel.  Accordingly, we place all of the resource control logic associated
447c478bd9Sstevel@tonic-gate  *   with processes, both existing and future, in this file.
457c478bd9Sstevel@tonic-gate  */
467c478bd9Sstevel@tonic-gate 
477c478bd9Sstevel@tonic-gate rctl_hndl_t rctlproc_legacy[RLIM_NLIMITS];
487c478bd9Sstevel@tonic-gate uint_t rctlproc_flags[RLIM_NLIMITS] = {
497c478bd9Sstevel@tonic-gate 	RCTL_LOCAL_SIGNAL,			/* RLIMIT_CPU	*/
507c478bd9Sstevel@tonic-gate 	RCTL_LOCAL_DENY | RCTL_LOCAL_SIGNAL,	/* RLIMIT_FSIZE */
517c478bd9Sstevel@tonic-gate 	RCTL_LOCAL_DENY,				/* RLIMIT_DATA	*/
527c478bd9Sstevel@tonic-gate 	RCTL_LOCAL_DENY,				/* RLIMIT_STACK */
537c478bd9Sstevel@tonic-gate 	RCTL_LOCAL_DENY,				/* RLIMIT_CORE	*/
547c478bd9Sstevel@tonic-gate 	RCTL_LOCAL_DENY,				/* RLIMIT_NOFILE */
557c478bd9Sstevel@tonic-gate 	RCTL_LOCAL_DENY				/* RLIMIT_VMEM	*/
567c478bd9Sstevel@tonic-gate };
577c478bd9Sstevel@tonic-gate int rctlproc_signals[RLIM_NLIMITS] = {
587c478bd9Sstevel@tonic-gate 	SIGXCPU,				/* RLIMIT_CPU	*/
597c478bd9Sstevel@tonic-gate 	SIGXFSZ,				/* RLIMIT_FSIZE	*/
607c478bd9Sstevel@tonic-gate 	0, 0, 0, 0, 0				/* remainder do not signal */
617c478bd9Sstevel@tonic-gate };
627c478bd9Sstevel@tonic-gate 
637c478bd9Sstevel@tonic-gate rctl_hndl_t rc_process_msgmnb;
647c478bd9Sstevel@tonic-gate rctl_hndl_t rc_process_msgtql;
657c478bd9Sstevel@tonic-gate rctl_hndl_t rc_process_semmsl;
667c478bd9Sstevel@tonic-gate rctl_hndl_t rc_process_semopm;
677c478bd9Sstevel@tonic-gate rctl_hndl_t rc_process_portev;
68*5e989a96SDavid Höppner rctl_hndl_t rc_process_sigqueue;
697c478bd9Sstevel@tonic-gate 
707c478bd9Sstevel@tonic-gate /*
717c478bd9Sstevel@tonic-gate  * process.max-cpu-time / RLIMIT_CPU
727c478bd9Sstevel@tonic-gate  */
737c478bd9Sstevel@tonic-gate /*ARGSUSED*/
747c478bd9Sstevel@tonic-gate static int
757c478bd9Sstevel@tonic-gate proc_cpu_time_test(struct rctl *rctl, struct proc *p, rctl_entity_p_t *e,
767c478bd9Sstevel@tonic-gate     rctl_val_t *rval, rctl_qty_t inc, uint_t flags)
777c478bd9Sstevel@tonic-gate {
787c478bd9Sstevel@tonic-gate 	return (inc >= rval->rcv_value);
797c478bd9Sstevel@tonic-gate }
807c478bd9Sstevel@tonic-gate 
817c478bd9Sstevel@tonic-gate static rctl_ops_t proc_cpu_time_ops = {
827c478bd9Sstevel@tonic-gate 	rcop_no_action,
837c478bd9Sstevel@tonic-gate 	rcop_no_usage,
847c478bd9Sstevel@tonic-gate 	rcop_no_set,
857c478bd9Sstevel@tonic-gate 	proc_cpu_time_test
867c478bd9Sstevel@tonic-gate };
877c478bd9Sstevel@tonic-gate 
887c478bd9Sstevel@tonic-gate /*
897c478bd9Sstevel@tonic-gate  * process.max-file-size / RLIMIT_FSIZE
907c478bd9Sstevel@tonic-gate  */
917c478bd9Sstevel@tonic-gate static int
927c478bd9Sstevel@tonic-gate proc_filesize_set(rctl_t *rctl, struct proc *p, rctl_entity_p_t *e,
937c478bd9Sstevel@tonic-gate     rctl_qty_t nv)
947c478bd9Sstevel@tonic-gate {
957c478bd9Sstevel@tonic-gate 	if (p->p_model == DATAMODEL_NATIVE)
967c478bd9Sstevel@tonic-gate 		nv = MIN(nv, rctl->rc_dict_entry->rcd_max_native);
977c478bd9Sstevel@tonic-gate 	else
987c478bd9Sstevel@tonic-gate 		nv = MIN(nv, rctl->rc_dict_entry->rcd_max_ilp32);
997c478bd9Sstevel@tonic-gate 
1007c478bd9Sstevel@tonic-gate 	ASSERT(e->rcep_t == RCENTITY_PROCESS);
1017c478bd9Sstevel@tonic-gate 	e->rcep_p.proc->p_fsz_ctl = nv;
1027c478bd9Sstevel@tonic-gate 
1037c478bd9Sstevel@tonic-gate 	return (0);
1047c478bd9Sstevel@tonic-gate }
1057c478bd9Sstevel@tonic-gate 
1067c478bd9Sstevel@tonic-gate static rctl_ops_t proc_filesize_ops = {
1077c478bd9Sstevel@tonic-gate 	rcop_no_action,
1087c478bd9Sstevel@tonic-gate 	rcop_no_usage,
1097c478bd9Sstevel@tonic-gate 	proc_filesize_set,
1107c478bd9Sstevel@tonic-gate 	rcop_no_test
1117c478bd9Sstevel@tonic-gate };
1127c478bd9Sstevel@tonic-gate 
1137c478bd9Sstevel@tonic-gate /*
1147c478bd9Sstevel@tonic-gate  * process.max-data / RLIMIT_DATA
1157c478bd9Sstevel@tonic-gate  */
1167c478bd9Sstevel@tonic-gate 
1177c478bd9Sstevel@tonic-gate /*
1187c478bd9Sstevel@tonic-gate  * process.max-stack-size / RLIMIT_STACK
1197c478bd9Sstevel@tonic-gate  */
1207c478bd9Sstevel@tonic-gate static int
1217c478bd9Sstevel@tonic-gate proc_stack_set(rctl_t *rctl, struct proc *p, rctl_entity_p_t *e,
1227c478bd9Sstevel@tonic-gate     rctl_qty_t nv)
1237c478bd9Sstevel@tonic-gate {
1247c478bd9Sstevel@tonic-gate 	klwp_t *lwp = ttolwp(curthread);
1257c478bd9Sstevel@tonic-gate 
1267c478bd9Sstevel@tonic-gate 	if (p->p_model == DATAMODEL_NATIVE)
1277c478bd9Sstevel@tonic-gate 		nv = MIN(nv, rctl->rc_dict_entry->rcd_max_native);
1287c478bd9Sstevel@tonic-gate 	else
1297c478bd9Sstevel@tonic-gate 		nv = MIN(nv, rctl->rc_dict_entry->rcd_max_ilp32);
1307c478bd9Sstevel@tonic-gate 
1317c478bd9Sstevel@tonic-gate 	/*
1327c478bd9Sstevel@tonic-gate 	 * In the process of changing the rlimit, this function actually
1337c478bd9Sstevel@tonic-gate 	 * gets called a number of times. We only want to save the current
1347c478bd9Sstevel@tonic-gate 	 * rlimit the first time we come through here. In post_syscall(),
1357c478bd9Sstevel@tonic-gate 	 * we copyin() the lwp's ustack, and compare it to the rlimit we
1367c478bd9Sstevel@tonic-gate 	 * save here; if the two match, we adjust the ustack to reflect
1377c478bd9Sstevel@tonic-gate 	 * the new stack bounds.
1387c478bd9Sstevel@tonic-gate 	 *
1397c478bd9Sstevel@tonic-gate 	 * We check to make sure that we're changing the rlimit of our
1407c478bd9Sstevel@tonic-gate 	 * own process rather than on behalf of some other process. The
1417c478bd9Sstevel@tonic-gate 	 * notion of changing this resource limit on behalf of another
1427c478bd9Sstevel@tonic-gate 	 * process is problematic at best, and changing the amount of stack
1437c478bd9Sstevel@tonic-gate 	 * space a process is allowed to consume is a rather antiquated
1447c478bd9Sstevel@tonic-gate 	 * notion that has limited applicability in our multithreaded
1457c478bd9Sstevel@tonic-gate 	 * process model.
1467c478bd9Sstevel@tonic-gate 	 */
1477c478bd9Sstevel@tonic-gate 	ASSERT(e->rcep_t == RCENTITY_PROCESS);
1487c478bd9Sstevel@tonic-gate 	if (lwp != NULL && lwp->lwp_procp == e->rcep_p.proc &&
1497c478bd9Sstevel@tonic-gate 	    lwp->lwp_ustack && lwp->lwp_old_stk_ctl == 0) {
1507c478bd9Sstevel@tonic-gate 		lwp->lwp_old_stk_ctl = (size_t)e->rcep_p.proc->p_stk_ctl;
1517c478bd9Sstevel@tonic-gate 		curthread->t_post_sys = 1;
1527c478bd9Sstevel@tonic-gate 	}
1537c478bd9Sstevel@tonic-gate 
1547c478bd9Sstevel@tonic-gate 	e->rcep_p.proc->p_stk_ctl = nv;
1557c478bd9Sstevel@tonic-gate 
1567c478bd9Sstevel@tonic-gate 	return (0);
1577c478bd9Sstevel@tonic-gate }
1587c478bd9Sstevel@tonic-gate 
1597c478bd9Sstevel@tonic-gate static rctl_ops_t proc_stack_ops = {
1607c478bd9Sstevel@tonic-gate 	rcop_no_action,
1617c478bd9Sstevel@tonic-gate 	rcop_no_usage,
1627c478bd9Sstevel@tonic-gate 	proc_stack_set,
1637c478bd9Sstevel@tonic-gate 	rcop_no_test
1647c478bd9Sstevel@tonic-gate };
1657c478bd9Sstevel@tonic-gate 
1667c478bd9Sstevel@tonic-gate /*
1677c478bd9Sstevel@tonic-gate  * process.max-file-descriptors / RLIMIT_NOFILE
1687c478bd9Sstevel@tonic-gate  */
1697c478bd9Sstevel@tonic-gate static int
1707c478bd9Sstevel@tonic-gate proc_nofile_set(rctl_t *rctl, struct proc *p, rctl_entity_p_t *e, rctl_qty_t nv)
1717c478bd9Sstevel@tonic-gate {
1727c478bd9Sstevel@tonic-gate 	ASSERT(e->rcep_t == RCENTITY_PROCESS);
1737c478bd9Sstevel@tonic-gate 	if (p->p_model == DATAMODEL_NATIVE)
1747c478bd9Sstevel@tonic-gate 		nv = MIN(nv, rctl->rc_dict_entry->rcd_max_native);
1757c478bd9Sstevel@tonic-gate 	else
1767c478bd9Sstevel@tonic-gate 		nv = MIN(nv, rctl->rc_dict_entry->rcd_max_ilp32);
1777c478bd9Sstevel@tonic-gate 
1787c478bd9Sstevel@tonic-gate 	e->rcep_p.proc->p_fno_ctl = nv;
1797c478bd9Sstevel@tonic-gate 
1807c478bd9Sstevel@tonic-gate 	return (0);
1817c478bd9Sstevel@tonic-gate }
1827c478bd9Sstevel@tonic-gate 
1837c478bd9Sstevel@tonic-gate static rctl_ops_t proc_nofile_ops = {
1847c478bd9Sstevel@tonic-gate 	rcop_no_action,
1857c478bd9Sstevel@tonic-gate 	rcop_no_usage,
1867c478bd9Sstevel@tonic-gate 	proc_nofile_set,
1877c478bd9Sstevel@tonic-gate 	rcop_absolute_test
1887c478bd9Sstevel@tonic-gate };
1897c478bd9Sstevel@tonic-gate 
1907c478bd9Sstevel@tonic-gate /*
1917c478bd9Sstevel@tonic-gate  * process.max-address-space / RLIMIT_VMEM
1927c478bd9Sstevel@tonic-gate  */
1937c478bd9Sstevel@tonic-gate static int
1947c478bd9Sstevel@tonic-gate proc_vmem_set(rctl_t *rctl, struct proc *p, rctl_entity_p_t *e, rctl_qty_t nv)
1957c478bd9Sstevel@tonic-gate {
1967c478bd9Sstevel@tonic-gate 	ASSERT(e->rcep_t == RCENTITY_PROCESS);
1977c478bd9Sstevel@tonic-gate 	if (p->p_model == DATAMODEL_ILP32)
1987c478bd9Sstevel@tonic-gate 		nv = MIN(nv, rctl->rc_dict_entry->rcd_max_ilp32);
1997c478bd9Sstevel@tonic-gate 	else
2007c478bd9Sstevel@tonic-gate 		nv = MIN(nv, rctl->rc_dict_entry->rcd_max_native);
2017c478bd9Sstevel@tonic-gate 
2027c478bd9Sstevel@tonic-gate 	e->rcep_p.proc->p_vmem_ctl = nv;
2037c478bd9Sstevel@tonic-gate 
2047c478bd9Sstevel@tonic-gate 	return (0);
2057c478bd9Sstevel@tonic-gate }
2067c478bd9Sstevel@tonic-gate 
2077c478bd9Sstevel@tonic-gate static rctl_ops_t proc_vmem_ops = {
2087c478bd9Sstevel@tonic-gate 	rcop_no_action,
2097c478bd9Sstevel@tonic-gate 	rcop_no_usage,
2107c478bd9Sstevel@tonic-gate 	proc_vmem_set,
2117c478bd9Sstevel@tonic-gate 	rcop_no_test
2127c478bd9Sstevel@tonic-gate };
2137c478bd9Sstevel@tonic-gate 
2147c478bd9Sstevel@tonic-gate /*
2157c478bd9Sstevel@tonic-gate  * void rctlproc_default_init()
2167c478bd9Sstevel@tonic-gate  *
2177c478bd9Sstevel@tonic-gate  * Overview
2187c478bd9Sstevel@tonic-gate  *   Establish default basic and privileged control values on the init process.
2197c478bd9Sstevel@tonic-gate  *   These correspond to the soft and hard limits, respectively.
2207c478bd9Sstevel@tonic-gate  */
2217c478bd9Sstevel@tonic-gate void
2227c478bd9Sstevel@tonic-gate rctlproc_default_init(struct proc *initp, rctl_alloc_gp_t *gp)
2237c478bd9Sstevel@tonic-gate {
2247c478bd9Sstevel@tonic-gate 	struct rlimit64 rlp64;
2257c478bd9Sstevel@tonic-gate 
2267c478bd9Sstevel@tonic-gate 	/*
2277c478bd9Sstevel@tonic-gate 	 * RLIMIT_CPU: deny never, sigtoproc(pp, NULL, SIGXCPU).
2287c478bd9Sstevel@tonic-gate 	 */
2297c478bd9Sstevel@tonic-gate 	rlp64.rlim_cur = rlp64.rlim_max = RLIM64_INFINITY;
2307c478bd9Sstevel@tonic-gate 	(void) rctl_rlimit_set(rctlproc_legacy[RLIMIT_CPU], initp, &rlp64, gp,
2317c478bd9Sstevel@tonic-gate 	    RCTL_LOCAL_SIGNAL, SIGXCPU, kcred);
2327c478bd9Sstevel@tonic-gate 
2337c478bd9Sstevel@tonic-gate 	/*
2347c478bd9Sstevel@tonic-gate 	 * RLIMIT_FSIZE: deny always, sigtoproc(pp, NULL, SIGXFSZ).
2357c478bd9Sstevel@tonic-gate 	 */
2367c478bd9Sstevel@tonic-gate 	rlp64.rlim_cur = rlp64.rlim_max = RLIM64_INFINITY;
2377c478bd9Sstevel@tonic-gate 	(void) rctl_rlimit_set(rctlproc_legacy[RLIMIT_FSIZE], initp, &rlp64, gp,
2387c478bd9Sstevel@tonic-gate 	    RCTL_LOCAL_SIGNAL | RCTL_LOCAL_DENY, SIGXFSZ, kcred);
2397c478bd9Sstevel@tonic-gate 
2407c478bd9Sstevel@tonic-gate 	/*
2417c478bd9Sstevel@tonic-gate 	 * RLIMIT_DATA: deny always, no default action.
2427c478bd9Sstevel@tonic-gate 	 */
2437c478bd9Sstevel@tonic-gate 	rlp64.rlim_cur = rlp64.rlim_max = RLIM64_INFINITY;
2447c478bd9Sstevel@tonic-gate 	(void) rctl_rlimit_set(rctlproc_legacy[RLIMIT_DATA], initp, &rlp64, gp,
2457c478bd9Sstevel@tonic-gate 	    RCTL_LOCAL_DENY, 0, kcred);
2467c478bd9Sstevel@tonic-gate 
2477c478bd9Sstevel@tonic-gate 	/*
2487c478bd9Sstevel@tonic-gate 	 * RLIMIT_STACK: deny always, no default action.
2497c478bd9Sstevel@tonic-gate 	 */
2507c478bd9Sstevel@tonic-gate #ifdef __sparc
2517c478bd9Sstevel@tonic-gate 	rlp64.rlim_cur = DFLSSIZ;
2527c478bd9Sstevel@tonic-gate 	rlp64.rlim_max = LONG_MAX;
2537c478bd9Sstevel@tonic-gate #else
2547c478bd9Sstevel@tonic-gate 	rlp64.rlim_cur = DFLSSIZ;
2557c478bd9Sstevel@tonic-gate 	rlp64.rlim_max = MAXSSIZ;
2567c478bd9Sstevel@tonic-gate #endif
2577c478bd9Sstevel@tonic-gate 	(void) rctl_rlimit_set(rctlproc_legacy[RLIMIT_STACK], initp, &rlp64, gp,
2587c478bd9Sstevel@tonic-gate 	    RCTL_LOCAL_DENY, 0, kcred);
2597c478bd9Sstevel@tonic-gate 
2607c478bd9Sstevel@tonic-gate 	/*
2617c478bd9Sstevel@tonic-gate 	 * RLIMIT_CORE: deny always, no default action.
2627c478bd9Sstevel@tonic-gate 	 */
2637c478bd9Sstevel@tonic-gate 	rlp64.rlim_cur = rlp64.rlim_max = RLIM64_INFINITY;
2647c478bd9Sstevel@tonic-gate 	(void) rctl_rlimit_set(rctlproc_legacy[RLIMIT_CORE], initp, &rlp64, gp,
2657c478bd9Sstevel@tonic-gate 	    RCTL_LOCAL_DENY, 0, kcred);
2667c478bd9Sstevel@tonic-gate 
2677c478bd9Sstevel@tonic-gate 	/*
2687c478bd9Sstevel@tonic-gate 	 * RLIMIT_NOFILE: deny always, no action.
2697c478bd9Sstevel@tonic-gate 	 */
2707c478bd9Sstevel@tonic-gate 	rlp64.rlim_cur = rlim_fd_cur;
2717c478bd9Sstevel@tonic-gate 	rlp64.rlim_max = rlim_fd_max;
2727c478bd9Sstevel@tonic-gate 	(void) rctl_rlimit_set(rctlproc_legacy[RLIMIT_NOFILE], initp, &rlp64,
2737c478bd9Sstevel@tonic-gate 	    gp, RCTL_LOCAL_DENY, 0, kcred);
2747c478bd9Sstevel@tonic-gate 
2757c478bd9Sstevel@tonic-gate 	/*
2767c478bd9Sstevel@tonic-gate 	 * RLIMIT_VMEM
2777c478bd9Sstevel@tonic-gate 	 */
2787c478bd9Sstevel@tonic-gate 	rlp64.rlim_cur = rlp64.rlim_max = RLIM64_INFINITY;
2797c478bd9Sstevel@tonic-gate 	(void) rctl_rlimit_set(rctlproc_legacy[RLIMIT_VMEM], initp, &rlp64, gp,
2807c478bd9Sstevel@tonic-gate 	    RCTL_LOCAL_DENY, 0, kcred);
2817c478bd9Sstevel@tonic-gate }
2827c478bd9Sstevel@tonic-gate 
2837c478bd9Sstevel@tonic-gate /*
2847c478bd9Sstevel@tonic-gate  * void rctlproc_init()
2857c478bd9Sstevel@tonic-gate  *
2867c478bd9Sstevel@tonic-gate  * Overview
2877c478bd9Sstevel@tonic-gate  *   Register the various resource controls associated with process entities.
2887c478bd9Sstevel@tonic-gate  *   The historical rlim_infinity_map and rlim_infinity32_map are now encoded
2897c478bd9Sstevel@tonic-gate  *   here as the native and ILP32 infinite values for each resource control.
2907c478bd9Sstevel@tonic-gate  */
2917c478bd9Sstevel@tonic-gate void
292*5e989a96SDavid Höppner rctlproc_init(void)
2937c478bd9Sstevel@tonic-gate {
2947c478bd9Sstevel@tonic-gate 	rctl_set_t *set;
2957c478bd9Sstevel@tonic-gate 	rctl_alloc_gp_t *gp;
2967c478bd9Sstevel@tonic-gate 	rctl_entity_p_t e;
2977c478bd9Sstevel@tonic-gate 
2987c478bd9Sstevel@tonic-gate 	rctlproc_legacy[RLIMIT_CPU] = rctl_register("process.max-cpu-time",
2997c478bd9Sstevel@tonic-gate 	    RCENTITY_PROCESS, RCTL_GLOBAL_LOWERABLE | RCTL_GLOBAL_DENY_NEVER |
3007c478bd9Sstevel@tonic-gate 	    RCTL_GLOBAL_CPU_TIME | RCTL_GLOBAL_INFINITE | RCTL_GLOBAL_SECONDS,
3017c478bd9Sstevel@tonic-gate 	    UINT64_MAX, UINT64_MAX, &proc_cpu_time_ops);
3027c478bd9Sstevel@tonic-gate 	rctlproc_legacy[RLIMIT_FSIZE] = rctl_register("process.max-file-size",
3037c478bd9Sstevel@tonic-gate 	    RCENTITY_PROCESS, RCTL_GLOBAL_LOWERABLE | RCTL_GLOBAL_DENY_ALWAYS |
3047c478bd9Sstevel@tonic-gate 	    RCTL_GLOBAL_FILE_SIZE | RCTL_GLOBAL_BYTES,
3057c478bd9Sstevel@tonic-gate 	    MAXOFFSET_T, MAXOFFSET_T, &proc_filesize_ops);
3067c478bd9Sstevel@tonic-gate 	rctlproc_legacy[RLIMIT_DATA] = rctl_register("process.max-data-size",
3077c478bd9Sstevel@tonic-gate 	    RCENTITY_PROCESS, RCTL_GLOBAL_LOWERABLE | RCTL_GLOBAL_DENY_ALWAYS |
3087c478bd9Sstevel@tonic-gate 	    RCTL_GLOBAL_SIGNAL_NEVER | RCTL_GLOBAL_BYTES,
3097c478bd9Sstevel@tonic-gate 	    ULONG_MAX, UINT32_MAX, &rctl_default_ops);
3107c478bd9Sstevel@tonic-gate #ifdef _LP64
3117c478bd9Sstevel@tonic-gate #ifdef __sparc
3127c478bd9Sstevel@tonic-gate 	rctlproc_legacy[RLIMIT_STACK] = rctl_register("process.max-stack-size",
3137c478bd9Sstevel@tonic-gate 	    RCENTITY_PROCESS, RCTL_GLOBAL_LOWERABLE | RCTL_GLOBAL_DENY_ALWAYS |
3147c478bd9Sstevel@tonic-gate 	    RCTL_GLOBAL_SIGNAL_NEVER | RCTL_GLOBAL_BYTES,
3157c478bd9Sstevel@tonic-gate 	    LONG_MAX, INT32_MAX, &proc_stack_ops);
3167c478bd9Sstevel@tonic-gate #else	/* __sparc */
3177c478bd9Sstevel@tonic-gate 	rctlproc_legacy[RLIMIT_STACK] = rctl_register("process.max-stack-size",
3187c478bd9Sstevel@tonic-gate 	    RCENTITY_PROCESS, RCTL_GLOBAL_LOWERABLE | RCTL_GLOBAL_DENY_ALWAYS |
3197c478bd9Sstevel@tonic-gate 	    RCTL_GLOBAL_SIGNAL_NEVER | RCTL_GLOBAL_BYTES,
320aa042c4bSkchow 	    MAXSSIZ, USRSTACK32 - PAGESIZE, &proc_stack_ops);
3217c478bd9Sstevel@tonic-gate #endif	/* __sparc */
3227c478bd9Sstevel@tonic-gate #else 	/* _LP64 */
3237c478bd9Sstevel@tonic-gate 	rctlproc_legacy[RLIMIT_STACK] = rctl_register("process.max-stack-size",
3247c478bd9Sstevel@tonic-gate 	    RCENTITY_PROCESS, RCTL_GLOBAL_LOWERABLE | RCTL_GLOBAL_DENY_ALWAYS |
3257c478bd9Sstevel@tonic-gate 	    RCTL_GLOBAL_SIGNAL_NEVER | RCTL_GLOBAL_BYTES,
326aa042c4bSkchow 	    USRSTACK - PAGESIZE, USRSTACK - PAGESIZE, &proc_stack_ops);
3277c478bd9Sstevel@tonic-gate #endif
3287c478bd9Sstevel@tonic-gate 	rctlproc_legacy[RLIMIT_CORE] = rctl_register("process.max-core-size",
3297c478bd9Sstevel@tonic-gate 	    RCENTITY_PROCESS, RCTL_GLOBAL_LOWERABLE | RCTL_GLOBAL_DENY_ALWAYS |
3307c478bd9Sstevel@tonic-gate 	    RCTL_GLOBAL_SIGNAL_NEVER | RCTL_GLOBAL_BYTES,
3317c478bd9Sstevel@tonic-gate 	    MIN(MAXOFFSET_T, ULONG_MAX), UINT32_MAX, &rctl_default_ops);
3327c478bd9Sstevel@tonic-gate 	rctlproc_legacy[RLIMIT_NOFILE] = rctl_register(
3337c478bd9Sstevel@tonic-gate 	    "process.max-file-descriptor", RCENTITY_PROCESS,
3347c478bd9Sstevel@tonic-gate 	    RCTL_GLOBAL_LOWERABLE | RCTL_GLOBAL_DENY_ALWAYS |
3357c478bd9Sstevel@tonic-gate 	    RCTL_GLOBAL_COUNT, INT32_MAX, INT32_MAX, &proc_nofile_ops);
3367c478bd9Sstevel@tonic-gate 	rctlproc_legacy[RLIMIT_VMEM] =
3377c478bd9Sstevel@tonic-gate 	    rctl_register("process.max-address-space", RCENTITY_PROCESS,
3387c478bd9Sstevel@tonic-gate 	    RCTL_GLOBAL_LOWERABLE | RCTL_GLOBAL_DENY_ALWAYS |
3397c478bd9Sstevel@tonic-gate 	    RCTL_GLOBAL_SIGNAL_NEVER | RCTL_GLOBAL_BYTES,
3407c478bd9Sstevel@tonic-gate 	    ULONG_MAX, UINT32_MAX, &proc_vmem_ops);
3417c478bd9Sstevel@tonic-gate 
3427c478bd9Sstevel@tonic-gate 	rc_process_semmsl = rctl_register("process.max-sem-nsems",
3437c478bd9Sstevel@tonic-gate 	    RCENTITY_PROCESS, RCTL_GLOBAL_DENY_ALWAYS | RCTL_GLOBAL_COUNT,
3447c478bd9Sstevel@tonic-gate 	    SHRT_MAX, SHRT_MAX, &rctl_absolute_ops);
3457c478bd9Sstevel@tonic-gate 	rctl_add_legacy_limit("process.max-sem-nsems", "semsys",
3467c478bd9Sstevel@tonic-gate 	    "seminfo_semmsl", 512, SHRT_MAX);
3477c478bd9Sstevel@tonic-gate 
3487c478bd9Sstevel@tonic-gate 	rc_process_semopm = rctl_register("process.max-sem-ops",
3497c478bd9Sstevel@tonic-gate 	    RCENTITY_PROCESS, RCTL_GLOBAL_DENY_ALWAYS | RCTL_GLOBAL_COUNT,
3507c478bd9Sstevel@tonic-gate 	    INT_MAX, INT_MAX, &rctl_absolute_ops);
3517c478bd9Sstevel@tonic-gate 	rctl_add_legacy_limit("process.max-sem-ops", "semsys",
3527c478bd9Sstevel@tonic-gate 	    "seminfo_semopm", 512, INT_MAX);
3537c478bd9Sstevel@tonic-gate 
3547c478bd9Sstevel@tonic-gate 	rc_process_msgmnb = rctl_register("process.max-msg-qbytes",
3557c478bd9Sstevel@tonic-gate 	    RCENTITY_PROCESS, RCTL_GLOBAL_DENY_ALWAYS | RCTL_GLOBAL_BYTES,
3567c478bd9Sstevel@tonic-gate 	    ULONG_MAX, ULONG_MAX, &rctl_absolute_ops);
3577c478bd9Sstevel@tonic-gate 	rctl_add_legacy_limit("process.max-msg-qbytes", "msgsys",
3587c478bd9Sstevel@tonic-gate 	    "msginfo_msgmnb", 65536, ULONG_MAX);
3597c478bd9Sstevel@tonic-gate 
3607c478bd9Sstevel@tonic-gate 	rc_process_msgtql = rctl_register("process.max-msg-messages",
3617c478bd9Sstevel@tonic-gate 	    RCENTITY_PROCESS, RCTL_GLOBAL_DENY_ALWAYS | RCTL_GLOBAL_COUNT,
3627c478bd9Sstevel@tonic-gate 	    UINT_MAX, UINT_MAX, &rctl_absolute_ops);
3637c478bd9Sstevel@tonic-gate 	rctl_add_legacy_limit("process.max-msg-messages", "msgsys",
3647c478bd9Sstevel@tonic-gate 	    "msginfo_msgtql", 8192, UINT_MAX);
3657c478bd9Sstevel@tonic-gate 
3667c478bd9Sstevel@tonic-gate 	rc_process_portev = rctl_register("process.max-port-events",
3677c478bd9Sstevel@tonic-gate 	    RCENTITY_PROCESS, RCTL_GLOBAL_DENY_ALWAYS | RCTL_GLOBAL_COUNT,
3687c478bd9Sstevel@tonic-gate 	    PORT_MAX_EVENTS, PORT_MAX_EVENTS, &rctl_absolute_ops);
3697c478bd9Sstevel@tonic-gate 	rctl_add_default_limit("process.max-port-events", PORT_DEFAULT_EVENTS,
3707c478bd9Sstevel@tonic-gate 	    RCPRIV_PRIVILEGED, RCTL_LOCAL_DENY);
3717c478bd9Sstevel@tonic-gate 
3727c478bd9Sstevel@tonic-gate 	/*
373*5e989a96SDavid Höppner 	 * We set the upper limit to the maximum number of user processes to
374*5e989a96SDavid Höppner 	 * make it theoretically possible to deliver all SIGCHILD signals on
375*5e989a96SDavid Höppner 	 * child termination, but at least to 8k.
376*5e989a96SDavid Höppner 	 */
377*5e989a96SDavid Höppner 	rc_process_sigqueue = rctl_register("process.max-sigqueue-size",
378*5e989a96SDavid Höppner 	    RCENTITY_PROCESS, RCTL_GLOBAL_LOWERABLE | RCTL_GLOBAL_DENY_ALWAYS |
379*5e989a96SDavid Höppner 	    RCTL_GLOBAL_COUNT, MAX(v.v_maxup, 8192), MAX(v.v_maxup, 8192),
380*5e989a96SDavid Höppner 	    &rctl_absolute_ops);
381*5e989a96SDavid Höppner 	rctl_add_default_limit("process.max-sigqueue-size",
382*5e989a96SDavid Höppner 	    _SIGQUEUE_SIZE_BASIC, RCPRIV_BASIC, RCTL_LOCAL_DENY);
383*5e989a96SDavid Höppner 	rctl_add_default_limit("process.max-sigqueue-size",
384*5e989a96SDavid Höppner 	    _SIGQUEUE_SIZE_PRIVILEGED, RCPRIV_PRIVILEGED, RCTL_LOCAL_DENY);
385*5e989a96SDavid Höppner 
386*5e989a96SDavid Höppner 	/*
3877c478bd9Sstevel@tonic-gate 	 * Place minimal set of controls on "sched" process for inheritance by
3887c478bd9Sstevel@tonic-gate 	 * processes created via newproc().
3897c478bd9Sstevel@tonic-gate 	 */
3907c478bd9Sstevel@tonic-gate 	set = rctl_set_create();
3917c478bd9Sstevel@tonic-gate 	gp = rctl_set_init_prealloc(RCENTITY_PROCESS);
3927c478bd9Sstevel@tonic-gate 	mutex_enter(&curproc->p_lock);
3937c478bd9Sstevel@tonic-gate 	e.rcep_p.proc = curproc;
3947c478bd9Sstevel@tonic-gate 	e.rcep_t = RCENTITY_PROCESS;
3957c478bd9Sstevel@tonic-gate 	curproc->p_rctls = rctl_set_init(RCENTITY_PROCESS, curproc, &e,
3967c478bd9Sstevel@tonic-gate 	    set, gp);
3977c478bd9Sstevel@tonic-gate 	mutex_exit(&curproc->p_lock);
3987c478bd9Sstevel@tonic-gate 	rctl_prealloc_destroy(gp);
3997c478bd9Sstevel@tonic-gate }
400