Subject: Re: setrlimit(RLIMIT_STACK,..) check for limit < stack usage
To: None <tech-kern@NetBSD.org>
From: der Mouse <mouse@Rodents.Montreal.QC.CA>
List: tech-kern
Date: 11/17/2001 19:36:28
>   The setrlimit() function may fail if:

>      [EINVAL] The limit specified cannot be lowered because
> 	      current usage is already higher than the limit.

> > +		if (limp->rlim_cur < p->p_vmspace->vm_dsize * PAGE_SIZE
> > +		    || limp->rlim_max < p->p_vmspace->vm_dsize * PAGE_SIZE)
> > +			return (EINVAL);

What is the "current usage" of the stack?  I'd argue it's where the
stack pointer points, not the amount of VM presently allocated to the
stack: if something has (say) gulped a megabyte of stack but has since
unwound to where only 10K is in use, I see no obvious reason why it
should be impossible to set the stack size limit to something between
10K and 1M.

/~\ The ASCII				der Mouse
\ / Ribbon Campaign
 X  Against HTML	       mouse@rodents.montreal.qc.ca
/ \ Email!	     7D C8 61 52 5D E7 2D 39  4E F1 31 3E E8 B3 27 4B