Make MAXTSIZ, DFLDSIZ, MAXDSIZ, DFLSSIZ, MAXSSIZ, SGROWSIZ loader

tunable.

Reviewed by:	peter
MFC after:	2 weeks
This commit is contained in:
ps 2001-10-10 23:06:54 +00:00
parent 63fe581848
commit db0d5cd641
26 changed files with 98 additions and 48 deletions

View File

@ -155,7 +155,7 @@ __ElfType(Hashelt);
* its maximum allowed size.
*/
#define ELF_RTLD_ADDR(vmspace) \
(round_page((vm_offset_t)(vmspace)->vm_daddr + MAXDSIZ))
(round_page((vm_offset_t)(vmspace)->vm_daddr + maxdsiz))
#endif
#endif /* !_MACHINE_ELF_H_ */

View File

@ -138,7 +138,7 @@ __ElfType(Hashelt);
* its maximum allowed size.
*/
#define ELF_RTLD_ADDR(vmspace) \
(round_page((vm_offset_t)(vmspace)->vm_daddr + MAXDSIZ))
(round_page((vm_offset_t)(vmspace)->vm_daddr + maxdsiz))
#endif /* _KERNEL */
#endif /* !_MACHINE_ELF_H_ */

View File

@ -100,7 +100,7 @@
* its maximum allowed size.
*/
#define ELF_RTLD_ADDR(vmspace) \
(round_page((vm_offset_t)(vmspace)->vm_daddr + MAXDSIZ))
(round_page((vm_offset_t)(vmspace)->vm_daddr + maxdsiz))
#endif /* _KERNEL */
#endif /* !_MACHINE_ELF_H_ */

View File

@ -365,7 +365,7 @@ linux_uselib(struct thread *td, struct linux_uselib_args *args)
* XXX - this is not complete. it should check current usage PLUS
* the resources needed by this library.
*/
if (a_out->a_text > MAXTSIZ ||
if (a_out->a_text > maxtsiz ||
a_out->a_data + bss_size >
td->td_proc->p_rlimit[RLIMIT_DATA].rlim_cur) {
error = ENOMEM;

View File

@ -107,7 +107,7 @@ exec_svr4_imgact(imgp)
/*
* text/data/bss must not exceed limits
*/
if (a_out->a_text > MAXTSIZ ||
if (a_out->a_text > maxtsiz ||
a_out->a_data + bss_size > imgp->proc->p_rlimit[RLIMIT_DATA].rlim_cur)
return (ENOMEM);

View File

@ -576,7 +576,7 @@ svr4_sys_mmap64(td, uap)
SCARG(&mm, addr) = SCARG(uap, addr);
SCARG(&mm, pos) = SCARG(uap, pos);
rp = (void *) round_page((vm_offset_t)(td->td_proc->p_vmspace->vm_daddr + MAXDSIZ));
rp = (void *) round_page((vm_offset_t)(td->td_proc->p_vmspace->vm_daddr + maxdsiz));
if ((SCARG(&mm, flags) & MAP_FIXED) == 0 &&
SCARG(&mm, addr) != 0 && (void *)SCARG(&mm, addr) < rp)
SCARG(&mm, addr) = rp;

View File

@ -177,6 +177,9 @@ NSFBUFS opt_param.h
VM_BCACHE_SIZE_MAX opt_param.h
VM_SWZONE_SIZE_MAX opt_param.h
MAXUSERS
DFLDSIZ opt_param.h
MAXDSIZ opt_param.h
MAXSSIZ opt_param.h
# Generic SCSI options.
CAM_MAX_HIGHPOWER opt_cam.h
@ -243,11 +246,6 @@ DEV_ATAPICD opt_ata.h
DEV_ATAPIST opt_ata.h
DEV_ATAPIFD opt_ata.h
# Resource limits.
DFLDSIZ opt_rlimit.h
MAXDSIZ opt_rlimit.h
MAXSSIZ opt_rlimit.h
# Net stuff.
ACCEPT_FILTER_DATA
ACCEPT_FILTER_HTTP

View File

@ -138,7 +138,7 @@ __ElfType(Hashelt);
* its maximum allowed size.
*/
#define ELF_RTLD_ADDR(vmspace) \
(round_page((vm_offset_t)(vmspace)->vm_daddr + MAXDSIZ))
(round_page((vm_offset_t)(vmspace)->vm_daddr + maxdsiz))
#endif /* _KERNEL */
#endif /* !_MACHINE_ELF_H_ */

View File

@ -106,7 +106,7 @@ exec_linux_imgact(imgp)
* text/data/bss must not exceed limits
*/
mtx_assert(&Giant, MA_OWNED);
if (a_out->a_text > MAXTSIZ ||
if (a_out->a_text > maxtsiz ||
a_out->a_data + bss_size > imgp->proc->p_rlimit[RLIMIT_DATA].rlim_cur)
return (ENOMEM);

View File

@ -212,7 +212,7 @@ __ElfType(Hashelt);
* its maximum allowed size.
*/
#define ELF_RTLD_ADDR(vmspace) \
(round_page((vm_offset_t)(vmspace)->vm_daddr + MAXDSIZ))
(round_page((vm_offset_t)(vmspace)->vm_daddr + maxdsiz))
#endif /* _KERNEL */
#endif /* !_MACHINE_ELF_H_ */

View File

@ -163,7 +163,7 @@ exec_aout_imgact(imgp)
*/
mtx_assert(&Giant, MA_OWNED);
if (/* text can't exceed maximum text size */
a_out->a_text > MAXTSIZ ||
a_out->a_text > maxtsiz ||
/* data + bss can't exceed rlimit */
a_out->a_data + bss_size >

View File

@ -30,8 +30,6 @@
* $FreeBSD$
*/
#include "opt_rlimit.h"
#include <sys/param.h>
#include <sys/exec.h>
#include <sys/fcntl.h>

View File

@ -209,7 +209,7 @@ do_aout_hdr(struct imgact_gzip * gz)
*/
mtx_assert(&Giant, MA_OWNED);
if ( /* text can't exceed maximum text size */
gz->a_out.a_text > MAXTSIZ ||
gz->a_out.a_text > maxtsiz ||
/* data + bss can't exceed rlimit */
gz->a_out.a_data + gz->bss_size >

View File

@ -162,6 +162,14 @@ tunable_int_init(void *data)
TUNABLE_INT_FETCH(d->path, d->var);
}
void
tunable_quad_init(void *data)
{
struct tunable_quad *d = (struct tunable_quad *)data;
TUNABLE_QUAD_FETCH(d->path, d->var);
}
void
tunable_str_init(void *data)
{

View File

@ -551,7 +551,7 @@ exec_new_vmspace(imgp)
{
int error;
struct vmspace *vmspace = imgp->proc->p_vmspace;
caddr_t stack_addr = (caddr_t) (USRSTACK - MAXSSIZ);
caddr_t stack_addr = (caddr_t) (USRSTACK - maxssiz);
vm_map_t map = &vmspace->vm_map;
GIANT_REQUIRED;
@ -576,7 +576,7 @@ exec_new_vmspace(imgp)
/* Allocate a new stack */
error = vm_map_stack (&vmspace->vm_map, (vm_offset_t)stack_addr,
(vm_size_t)MAXSSIZ, VM_PROT_ALL, VM_PROT_ALL, 0);
(vm_size_t)maxssiz, VM_PROT_ALL, VM_PROT_ALL, 0);
if (error)
return (error);
@ -588,7 +588,7 @@ exec_new_vmspace(imgp)
* store to grow upwards. This will do for now.
*/
vm_offset_t bsaddr;
bsaddr = USRSTACK - 2*MAXSSIZ;
bsaddr = USRSTACK - 2*maxssiz;
error = vm_map_find(&vmspace->vm_map, 0, 0, &bsaddr,
4*PAGE_SIZE, 0,
VM_PROT_ALL, VM_PROT_ALL, 0);
@ -600,8 +600,8 @@ exec_new_vmspace(imgp)
* VM_STACK case, but they are still used to monitor the size of the
* process stack so we can check the stack rlimit.
*/
vmspace->vm_ssize = SGROWSIZ >> PAGE_SHIFT;
vmspace->vm_maxsaddr = (char *)USRSTACK - MAXSSIZ;
vmspace->vm_ssize = sgrowsiz >> PAGE_SHIFT;
vmspace->vm_maxsaddr = (char *)USRSTACK - maxssiz;
return(0);
}

View File

@ -40,7 +40,6 @@
*/
#include "opt_compat.h"
#include "opt_rlimit.h"
#include <sys/param.h>
#include <sys/systm.h>
@ -518,17 +517,17 @@ dosetrlimit(td, which, limp)
(rlim_t)1000000 * limp->rlim_cur;
break;
case RLIMIT_DATA:
if (limp->rlim_cur > MAXDSIZ)
limp->rlim_cur = MAXDSIZ;
if (limp->rlim_max > MAXDSIZ)
limp->rlim_max = MAXDSIZ;
if (limp->rlim_cur > maxdsiz)
limp->rlim_cur = maxdsiz;
if (limp->rlim_max > maxdsiz)
limp->rlim_max = maxdsiz;
break;
case RLIMIT_STACK:
if (limp->rlim_cur > MAXSSIZ)
limp->rlim_cur = MAXSSIZ;
if (limp->rlim_max > MAXSSIZ)
limp->rlim_max = MAXSSIZ;
if (limp->rlim_cur > maxssiz)
limp->rlim_cur = maxssiz;
if (limp->rlim_max > maxssiz)
limp->rlim_max = maxssiz;
/*
* Stack is allocated to the max at exec time with only
* "rlim_cur" bytes accessible. If stack limit is going

View File

@ -46,6 +46,8 @@
#include <sys/systm.h>
#include <sys/kernel.h>
#include <machine/vmparam.h>
/*
* System parameter formulae.
*/
@ -74,6 +76,12 @@ int nbuf;
int nswbuf;
int maxswzone; /* max swmeta KVA storage */
int maxbcache; /* max buffer cache KVA storage */
u_quad_t maxtsiz; /* max text size */
u_quad_t dfldsiz; /* initial data size limit */
u_quad_t maxdsiz; /* max data size */
u_quad_t dflssiz; /* initial stack size limit */
u_quad_t maxssiz; /* max stack size */
u_quad_t sgrowsiz; /* amount to grow stack */
/*
* These have to be allocated somewhere; allocating
@ -126,4 +134,17 @@ init_param(void)
TUNABLE_INT_FETCH("kern.maxbcache", &maxbcache);
ncallout = 16 + maxproc + maxfiles;
TUNABLE_INT_FETCH("kern.ncallout", &ncallout);
maxtsiz = MAXTSIZ;
TUNABLE_QUAD_FETCH("kern.maxtsiz", &maxtsiz);
dfldsiz = DFLDSIZ;
TUNABLE_QUAD_FETCH("kern.dfldsiz", &dfldsiz);
maxdsiz = MAXDSIZ;
TUNABLE_QUAD_FETCH("kern.maxdsiz", &maxdsiz);
dflssiz = DFLSSIZ;
TUNABLE_QUAD_FETCH("kern.dflssiz", &dflssiz);
maxssiz = MAXSSIZ;
TUNABLE_QUAD_FETCH("kern.maxssiz", &maxssiz);
sgrowsiz = SGROWSIZ;
TUNABLE_QUAD_FETCH("kern.sgrowsiz", &sgrowsiz);
}

View File

@ -32,7 +32,6 @@
*/
#include "opt_compat.h"
#include "opt_rlimit.h"
#include "opt_sysvipc.h"
#include <sys/param.h>
@ -355,7 +354,7 @@ shmat(td, uap)
* put it.
*/
attach_va = round_page((vm_offset_t)p->p_vmspace->vm_taddr
+ MAXTSIZ + MAXDSIZ);
+ maxtsiz + maxdsiz);
}
shm_handle = shmseg->shm_internal;

View File

@ -3,7 +3,7 @@
.PATH: ${.CURDIR}/../../../kern
KMOD= sysvshm
OPTS= opt_sysvipc.h opt_compat.h opt_rlimit.h
OPTS= opt_sysvipc.h opt_compat.h
SRCS= sysv_shm.c $(OPTS)
.include <bsd.kmod.mk>

View File

@ -178,7 +178,7 @@ __ElfType(Hashelt);
* its maximum allowed size.
*/
#define ELF_RTLD_ADDR(vmspace) \
(round_page((vm_offset_t)(vmspace)->vm_daddr + MAXDSIZ))
(round_page((vm_offset_t)(vmspace)->vm_daddr + maxdsiz))
#endif /* _KERNEL */
#endif /* !_MACHINE_ELF_H_ */

View File

@ -121,7 +121,7 @@ __ElfType(Hashelt);
* its maximum allowed size.
*/
#define ELF_RTLD_ADDR(vmspace) \
(round_page((vm_offset_t)(vmspace)->vm_daddr + MAXDSIZ))
(round_page((vm_offset_t)(vmspace)->vm_daddr + maxdsiz))
#endif /* _KERNEL */
#endif /* !_MACHINE_ELF_H_ */

View File

@ -282,6 +282,29 @@ do { \
getenv_int((path), (var)); \
} while (0)
extern void tunable_quad_init(void *);
struct tunable_quad {
const char *path;
quad_t *var;
};
#define TUNABLE_QUAD(path, var) \
_TUNABLE_QUAD((path), (var), __LINE__)
#define _TUNABLE_QUAD(path, var, line) \
__TUNABLE_QUAD((path), (var), line)
#define __TUNABLE_QUAD(path, var, line) \
static struct tunable_quad __tunable_quad_ ## line = { \
path, \
var, \
}; \
SYSINIT(__Tunable_init_ ## line, SI_SUB_TUNABLES, SI_ORDER_MIDDLE, \
tunable_quad_init, &__tunable_quad_ ## line)
#define TUNABLE_QUAD_FETCH(path, var) \
do { \
getenv_quad((path), (var)); \
} while (0)
extern void tunable_str_init(void *);
struct tunable_str {
const char *path;

View File

@ -62,7 +62,6 @@
* $FreeBSD$
*/
#include "opt_rlimit.h"
#include "opt_vm.h"
#include <sys/param.h>
@ -328,10 +327,10 @@ vm_init_limits(udata)
* of memory - half of main memory helps to favor smaller processes,
* and reduces thrashing of the object cache.
*/
p->p_rlimit[RLIMIT_STACK].rlim_cur = DFLSSIZ;
p->p_rlimit[RLIMIT_STACK].rlim_max = MAXSSIZ;
p->p_rlimit[RLIMIT_DATA].rlim_cur = DFLDSIZ;
p->p_rlimit[RLIMIT_DATA].rlim_max = MAXDSIZ;
p->p_rlimit[RLIMIT_STACK].rlim_cur = dflssiz;
p->p_rlimit[RLIMIT_STACK].rlim_max = maxssiz;
p->p_rlimit[RLIMIT_DATA].rlim_cur = dfldsiz;
p->p_rlimit[RLIMIT_DATA].rlim_max = maxdsiz;
/* limit the limit to no less than 2MB */
rss_limit = max(cnt.v_free_count, 512);
p->p_rlimit[RLIMIT_RSS].rlim_cur = ptoa(rss_limit);

View File

@ -2396,10 +2396,10 @@ vm_map_stack (vm_map_t map, vm_offset_t addrbos, vm_size_t max_ssize,
if (VM_MIN_ADDRESS > 0 && addrbos < VM_MIN_ADDRESS)
return (KERN_NO_SPACE);
if (max_ssize < SGROWSIZ)
if (max_ssize < sgrowsiz)
init_ssize = max_ssize;
else
init_ssize = SGROWSIZ;
init_ssize = sgrowsiz;
vm_map_lock(map);
@ -2542,7 +2542,7 @@ vm_map_growstack (struct proc *p, vm_offset_t addr)
}
/* Round up the grow amount modulo SGROWSIZ */
grow_amount = roundup (grow_amount, SGROWSIZ);
grow_amount = roundup (grow_amount, sgrowsiz);
if (grow_amount > stack_entry->avail_ssize) {
grow_amount = stack_entry->avail_ssize;
}

View File

@ -47,7 +47,6 @@
#include "opt_bleed.h"
#include "opt_compat.h"
#include "opt_rlimit.h"
#include <sys/param.h>
#include <sys/systm.h>
@ -276,8 +275,8 @@ mmap(td, uap)
*/
else if (addr == 0 ||
(addr >= round_page((vm_offset_t)vms->vm_taddr) &&
addr < round_page((vm_offset_t)vms->vm_daddr + MAXDSIZ)))
addr = round_page((vm_offset_t)vms->vm_daddr + MAXDSIZ);
addr < round_page((vm_offset_t)vms->vm_daddr + maxdsiz)))
addr = round_page((vm_offset_t)vms->vm_daddr + maxdsiz);
mtx_lock(&Giant); /* syscall marked mp-safe but isn't */
if (flags & MAP_ANON) {

View File

@ -133,6 +133,12 @@ struct xswdev {
#ifdef _KERNEL
#define num_pages(x) \
((vm_offset_t)((((vm_offset_t)(x)) + PAGE_MASK) >> PAGE_SHIFT))
extern u_quad_t maxtsiz;
extern u_quad_t dfldsiz;
extern u_quad_t maxdsiz;
extern u_quad_t dflssiz;
extern u_quad_t maxssiz;
extern u_quad_t sgrowsiz;
#endif /* _KERNEL */
#endif /* ASSEMBLER */
#endif /* _VM_PARAM_ */