• Re: stack overflow

    From Marcel Mueller@21:1/5 to All on Sun Mar 31 18:02:32 2024
    Am 31.03.24 um 09:19 schrieb Paul Edwards:
    From memory, when I ran a program on OS/2, the
    stack was put into a different segment, which
    presumably had a specific length.

    No in the 32 bit flat memory model the stack segment refers to the same
    virtual address space than any other segment register. Otherwise 32 bit pointers would not work.

    Does that meant that OS/2 programs crash on
    stack overflow instead of trashing random
    things like happens on other environments?

    *All* programs on any OS crash on stack overflow.

    This is not simply an out of memory condition because the stack segment
    must be continuous in virtual address space. When a thread starts it get
    a restricted amount of virtual address space. The stack can grow up to
    this limit, but beyond the limit other allocations may exist. On OS/2
    stack space is typically in between 64kB and 1MB. The latter is
    recommended for MMOS2 applications.

    Additionally the stack is protected by a guard page. Only if the guard
    page is touched the stack grows by 4kB and the guard page is moved one
    page lower. Accessing reserved stack space below the current guard page
    is considered an invalid memory access and the program terminates. For
    this reason an application must call a specific API function to move the
    guard page explicitly if a stack frame of a function uses more than 4kB
    stack space at once. Some compilers forget to do so causing the
    application to crash.


    Marcel

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)