Re: [fw-wiz] Stack size

From: Chuck Swiger (chuck_at_codefab.com)
Date: 04/27/03

  • Next message: SimonChan_at_lifeisgreat.com.sg: "Re: RE: [fw-wiz] vpn with fw4.1 and ngfp3"
    To: firewall-wizards@honor.icsalabs.com
    Date: Sat, 26 Apr 2003 21:37:04 -0400
    

    Cat Okita wrote:
    > In the process of doing some trivial (and admittedly sloppy) programming
    > recently, it became apparent that OSX has a surprisingly low stack size
    > of 512K (measured via getrlimit, to show the current (soft) limit, and
    > the hard limit).

    512K probably still represents a thousand or so PPC stack frames, which
    is arguably too small-- certainly if the program uses alloca() or local
    variables to any extent.

    > Checking other (albeit not the same hardware architecture) systems for
    > curiousity, it seems that it's much more common to have a stack size
    > of 8Mb.

    8 MB is common, yes. See /etc/login.conf on FreeBSD for how to change
    the defaults, or /etc/profile on most systems for a place to adjust the
    defaults limits to something you find more reasonable. Something like
    this, and/or with -H instead of -S to adjust the hard limits:

    # Set reasonable soft process limits.
    ulimit -Sc 0
    ulimit -Sd 512000
    ulimit -Ss 16384
    ulimit -Sn 256
    ulimit -Su 100

    > Is there any particular reason why it would be advantageous to have
    > such a small stack size?

    In terms of security? No, not really, although the Mach kernel used by
    OS X has long made the distinction between VM pages which are readable,
    writable, or executable, if the underlying hardware supports it. So it
    already supports prevention of executing code on the stack if the G4 CPU
    can, mitigating the risk of some exploits.

    If you're asking why OS X has such a small default, it's possibly
    because that's the amount of stack space per thread per task, and some
    Mach apps are heavily threaded. If you reserve 16 MB of space per stack
    with an app that forks a few dozen threads, you can overrun the chunk of
    VM address space that the system expects the stack(s) to fit into. More
    of a legacy setting from the days of MachO fixed-VM shared libraries
    (from NEXTSTEP)...

    -Chuck

    _______________________________________________
    firewall-wizards mailing list
    firewall-wizards@honor.icsalabs.com
    http://honor.icsalabs.com/mailman/listinfo/firewall-wizards


  • Next message: SimonChan_at_lifeisgreat.com.sg: "Re: RE: [fw-wiz] vpn with fw4.1 and ngfp3"

    Relevant Pages

    • Setting stacksize and its default
      ... To set the stacksize for everyone we simply add 'ulimit -s 32767' to ... - Is there a way to set a hard limit for the stack size in the ...
      (SunManagers)
    • Re: Whats the cost of using hundreds of threads?
      ... On Windows XP, the limit is around 2000 threads and i ... 'ulimit -aH' yields this output on my fedora core2. ... The default stack size is set as unlimited hence ... Mail has the best spam protection around ...
      (comp.lang.python)
    • Re: Too much on the stack?
      ... >> only reason for this program to run out of stack is if it exceeds stack ... >> ulimit, or comes close to where shared libraries are mapped. ... If you set your ulimit stack space to unlimited you ... "To educate a man in mind and not in morals is to ...
      (comp.unix.programmer)
    • Re: many-threaded process large virtual size
      ... > app by adjusting ulimit -s. ... So why would it need to create the thread's stack at ... the actual physical memory usage can be smaller. ... mappings in the upper most region of the address ...
      (comp.os.linux.development.apps)
    • Re: maximum number of threads
      ... See ulimit man pages. ... Each thread is allocated 8MB of stack. ... exarkun@charm:~$ python Desktop/test.py ... Biggest number of threads: 382 ...
      (comp.lang.python)