Fix values returned by getrlimit(RLIMIT_STACK)

* resource.cc (getrlimit): Fix values returned by RLIMIT_STACK.
	Explain why this had to be changed.

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
This commit is contained in:
Corinna Vinschen 2015-06-26 20:41:54 +02:00
parent 153385d847
commit 2ecaa3c176
2 changed files with 31 additions and 10 deletions

View File

@ -1,3 +1,8 @@
2015-06-26 Corinna Vinschen <corinna@vinschen.de>
* resource.cc (getrlimit): Fix values returned by RLIMIT_STACK.
Explain why this had to be changed.
2015-06-23 Ken Brown <kbrown@cornell.edu> 2015-06-23 Ken Brown <kbrown@cornell.edu>
* include/cygwin/signal.h (SIGEV_*): Add macros. * include/cygwin/signal.h (SIGEV_*): Add macros.

View File

@ -114,8 +114,6 @@ getrusage (int intwho, struct rusage *rusage_in)
extern "C" int extern "C" int
getrlimit (int resource, struct rlimit *rlp) getrlimit (int resource, struct rlimit *rlp)
{ {
MEMORY_BASIC_INFORMATION m;
__try __try
{ {
rlp->rlim_cur = RLIM_INFINITY; rlp->rlim_cur = RLIM_INFINITY;
@ -129,14 +127,32 @@ getrlimit (int resource, struct rlimit *rlp)
case RLIMIT_AS: case RLIMIT_AS:
break; break;
case RLIMIT_STACK: case RLIMIT_STACK:
if (!VirtualQuery ((LPCVOID) &m, &m, sizeof m)) PTEB teb;
debug_printf ("couldn't get stack info, returning def.values. %E"); /* 2015-06-26: Originally rlim_cur returned the size of the still
else available stack area on the current stack, rlim_max the total size
{ of the current stack. Two problems:
rlp->rlim_cur = (rlim_t) &m - (rlim_t) m.AllocationBase;
rlp->rlim_max = (rlim_t) m.BaseAddress + m.RegionSize - Per POSIX, RLIMIT_STACK returns "the maximum size of the initial
- (rlim_t) m.AllocationBase; thread's stack, in bytes. The implementation does not
} automatically grow the stack beyond this limit".
- With the implementation of sigaltstack, the current stack is not
necessarily the "initial thread's stack" anymore. Rather, when
called from a signal handler running on the alternate stack,
RLIMIT_STACK should return the size of the original stack.
rlim_cur is now the size of the stack. For system-provided stacks
it's the size between DeallocationStack and StackBase. For
application-provided stacks (via pthread_attr_setstack),
DeallocationStack is NULL, but StackLimit points to the bottom
of the stack.
rlim_max is set to RLIM_INFINITY since there's no hard limit
for stack sizes on Windows. */
teb = NtCurrentTeb ();
rlp->rlim_cur = (rlim_t) teb->Tib.StackBase
- (rlim_t) (teb->DeallocationStack
?: teb->Tib.StackLimit);
break; break;
case RLIMIT_NOFILE: case RLIMIT_NOFILE:
rlp->rlim_cur = getdtablesize (); rlp->rlim_cur = getdtablesize ();