View Issue Details

IDProjectCategoryView StatusLast Update
0000283LDMudRuntimepublic2009-10-02 09:32
ReporterlarsAssigned To 
PrioritynormalSeverityfeatureReproducibilityN/A
Status newResolutionopen 
Summary0000283: Stack size watch
DescriptionShort: Stack size watch
From: Lars Duening <lars@bearnip.com>
Date: Sat, 09 Mar 2002 22:40:26 -0700
Type: Feature
State: New

Add a new configuration parameter MAX_STACK_SIZE/--max-stack (default: 0 =
infinite), which is used by assert_stack_gap() to limit recursions.

On systems which provide limits on stack/heap (BSD: getrlimit(), BeOS:
Hardcoded system constants?), use these values to override the max-stack/max-
malloc.


AIX uses the ulimit() efun.
  
                                   
-------------------------------------------------------------------------------
      Base Operating System and Extensions Technical Reference, Volume 2
-------------------------------------------------------------------------------

ulimit Subroutine

Purpose

Sets and gets user limits.

Library

Standard C Library (libc.a)

Syntax

The syntax for the ulimit subroutine when the Command parameter specifies a
value of GET_FSIZE or SET_FSIZE is:
#include <ulimit.h>

long int ulimit (Command, NewLimit)

int Command;

off_t NewLimit;

The syntax for the ulimit subroutine when the Command parameter specifies a
value of GET_DATALIM, SET_DATALIM, GET_STACKLIM, SET_STACKLIM, GET_REALDIR, or
SET_REALDIR is:
#include <ulimit.h>

long int ulimit (Command, NewLimit)

int Command;

int NewLimit;

Description

The ulimit subroutine controls process limits.

Even with remote files, the ulimit subroutine values of the process on the
client node are used.

    Note: Raising the data ulimit does not necessarily raise the program break
    value. If the proper memory segments are not initialized at program load
    time, raising your memory limit will not allow access to this memory. Also,
    without these memory segments initialized, the value returned after such a
    change may not be the proper break value. If your data limit is
    RLIM_INFINITY, this value will never advance past the segment size, even if
    that data is available. Use the -bmaxdata flag of the ld command to set up
    these segments at load time.

Parameters

Command Specifies the form of control. The following Command parameter values
require that the NewLimit parameter be declared as an off_t structure:

GET_FSIZE (1) Returns the process file size limit. The limit is in units of
UBSIZE blocks (see the sys/param.h file) and is inherited by child processes.
Files of any size can be read. The process file size limit is returned in the
off_t structure specified by the NewLimit parameter.

SET_FSIZE (2) Sets the process file size limit to the value in the off_t
structure specified by the NewLimit parameter. Any process can decrease this
limit, but only a process with root user authority can increase the limit. The
new file size limit is returned.

The following Command parameter values require that the NewLimit parameter be
declared as an integer:

GET_DATALIM (3) Returns the maximum possible break value (as described in the
brk or sbrk subroutine).

SET_DATALIM (1004) Sets the maximum possible break value (described in the brk
and sbrk subroutines). Returns the new maximum break value, which is the
NewLimit parameter rounded up to the nearest page boundary.

GET_STACKLIM (1005) Returns the lowest valid stack address.

    Note: Stacks grow from high addresses to low addresses.

SET_STACKLIM (1006) Sets the lowest valid stack address. Returns the new minimum
valid stack address, which is the NewLimit parameter rounded down to the nearest
page boundary.

GET_REALDIR (1007) Returns the current value of the real directory read flag. If
this flag is a value of 0, a read system call (or readx with Extension parameter
value of 0) against a directory returns fixed-format entries compatible with the
System V UNIX operating system. Otherwise, a read system call(or readx with
Extension parameter value of 0) against a directory returns the underlying
physical format.

SET_REALDIR (1008) Sets the value of the real directory read flag. If the
NewLimit parameter is a value of 0, this flag is cleared; otherwise, it is set.
The old value of the real directory read flag is returned.

NewLimit Specifies the new limit. The value and data type or structure of the
NewLimit parameter depends on the Command parameter value that is used.

Examples

To increase the size of the stack by 4096 bytes (use 4096 or PAGESIZE), and set
the rc to the new lowest valid stack address, enter:
rc = ulimit(SET_STACKLIM, ulimit(GET_STACKLIM, 0) - 4096);

Return Values

Upon successful completion, the value of the requested limit is returned.
Otherwise, a value of -1 is returned and the errno global variable is set to
indicate the error.

All return values are permissible if the ulimit subroutine is successful. To
check for error situations, an application should set the errno global variable
to 0 before calling the ulimit subroutine. If the ulimit subroutine returns a
value of -1, the application should check the errno global variable to verify
that it is nonzero.

Error Codes

The ulimit subroutine is unsuccessful and the limit remains unchanged if one of
the following is true:

EPERM A process without root user authority attempts to increase the file size
limit.

EINVAL The Command parameter is a value other than GET_FSIZE, SET_FSIZE,
GET_DATALIM, SET_DATALIM, GET_STACKLIM, SET_STACKLIM, GET_REALDIR, or
SET_REALDIR.

Implementation Specifics

This subroutine is part of Base Operating System (BOS) Runtime.

Related Information

The brk subroutine, sbrk subroutine, getrlimit or setrlimit subroutine, pathconf
subroutine, read subroutines, vlimit subroutine, write subroutine.
-------------------------------------------------------------------------------
TagsNo tags attached.
External Data (URL)

Activities

zesstra

2009-10-02 09:32

administrator   ~0001415

One problem ist, that it is not so easy to find out about the stack size. ulimit is highly platform dependent and last time I checked, not many implement something like GET_STACKLIM/SET_STACKLIM. Also Posix does not define many ulimit commands:
http://www.opengroup.org/onlinepubs/009695399/basedefs/ulimit.h.html
getrlimit() is better in the respect that you can set the maximum stack size on more platforms, but there is no way to query the current stack size there.

So, while this is a nice idea and I thought about this also in the bug about too many recursions in PCRE (0000524), I am very sceptical, there is a sane and portable way to do this.
Additionally, the checks for exceeded stack size on many systems are not really reliable, see 0000532. Most have a guard page and any access to that page causes SIGSEGV, but if you exceed that guard page any access _after_ that guard page does not an error.

Issue History

Date Modified Username Field Change
2004-11-27 00:49 lars New Issue
2009-10-02 09:32 zesstra Note Added: 0001415