================================================================================
Activation frame
================================================================================

RexxActivity.hpp
   inline void allocateStackFrame(RexxExpressionStack *stack, size_t entries)
   {
       stack->setFrame(frameStack.allocateFrame(entries), entries);
   }

   inline RexxObject **allocateFrame(size_t entries)
   {
       return frameStack.allocateFrame(entries);
   }

   inline void releaseStackFrame(RexxObject **frame)
   {
       frameStack.releaseFrame(frame);
   }

   RexxActivationStack   frameStack;   /* our stack used for activation frames */

   // the activation frame stack.  This stack is one RexxActivation or
   // RexxNativeActivation for every level of the call stack.  The activationStackSize
   // is the current size of the stack (which is expanded, if necessary).  The
   // activationStackDepth is the current count of frames in the stack.
   RexxInternalStack  *activations;
   size_t   activationStackSize;
   size_t   stackFrameDepth;

   // the following two fields represent the current top of the activation stack
   // and the top Rexx frame in the stack.  Generally, if executing Rexx code,
   // then currentRexxFrame == topStackFrame.  If we're at the base of the stack
   // topStackFrame will be the root stack element (a RexxNativeActivation instance)
   // and the currentRexxFrame will be OREF_NULL.  If we've made a callout from a
   // Rexx context, then the topStackFrame will be the RexxNativeActivation that
   // made the callout and the currentRexxFrame will be the predecessor frame.
   RexxActivation     *currentRexxFrame;
   RexxActivationBase *topStackFrame;

   inline RexxActivation *getCurrentRexxFrame() {return currentRexxFrame;}



RexxActivationStack.hpp
    class RexxActivationFrameBuffer
    {
        ...
         inline bool hasCapacity(size_t entries) { return size - next >= entries; }
         inline RexxObject **allocateFrame(size_t entries)
         {
             RexxObject **frame = &buffer[next];
             next += entries;
             return frame;
         }

        size_t size;                        /* size of the buffer (in slots) */
        size_t next;                        /* location of next allocation */
        RexxActivationFrameBuffer *previous;/* previous entry in the stack */
        RexxObject *buffer[1];              /* start of the buffer location */
    };

    class RexxActivationStack
    {
        ...
        void expandCapacity(size_t entries);
        inline void ensureCapacity(size_t entries) { if (!current->hasCapacity(entries)) { expandCapacity(entries); } }
        inline RexxObject **allocateFrame(size_t entries)
        {
            /* make sure we have space first */
            ensureCapacity(entries);
            /* now allocate from the current stack buffer */
            return current->allocateFrame(entries);
        }

        RexxActivationFrameBuffer *current;
        RexxActivationFrameBuffer *unused;
    };


================================================================================
callers of allocateStackFrame
================================================================================

ExpressionStack.cpp

    void RexxExpressionStack::migrate(RexxActivity *activity)
    /******************************************************************************/
    /* Function:  Migrate the expression stack to a new activity                  */
    /******************************************************************************/
    {
        RexxObject **oldFrame = stack;
        /* allocate a new frame */
        activity->allocateStackFrame(this, size);
        /* copy the enties over to the new stack. */
        memcpy(stack, oldFrame, sizeof(RexxObject *) * size);
    }


RexxActivation.cpp

    /**
     * Initialize an activation for a method invocation.
     *
     * @param _activity The activity we're running under.
     * @param _method   The method being invoked.
     * @param _code     The code to execute.
     */
    RexxActivation::RexxActivation(RexxActivity* _activity, RexxMethod * _method, RexxCode *_code)
    {
        ...
        _activity->allocateStackFrame(&this->stack, this->code->getMaxStackSize());


    /**
     * Create a new Rexx activation for an internal level call.
     * An internal level call is an internal call, a call trap,
     * an Interpret statement, or a debug pause execution.
     *
     * @param _activity The current activity.
     * @param _parent   The parent activation.
     * @param _code     The code to be executed.  For interpret and debug pauses, this
     *                  is a new code object.  For call activations, this is the
     *                  parent code object.
     * @param context   The type of call being made.
     */
    RexxActivation::RexxActivation(RexxActivity *_activity, RexxActivation *_parent, RexxCode *_code, int context)
    {
        ...
        _activity->allocateStackFrame(&stack, code->getMaxStackSize());


    /**
     * Create a top-level activation of Rexx code.  This will
     * either a toplevel program or an external call.
     *
     * @param _activity The current thread we're running on.
     * @param _routine  The routine to invoke.
     * @param _code     The code object to be executed.
     * @param calltype  Type type of call being made (function or subroutine)
     * @param env       The default address environment
     * @param context   The type of call context.
     */
    RexxActivation::RexxActivation(RexxActivity *_activity, RoutineClass *_routine, RexxCode *_code,
        RexxString *calltype, RexxString *env, int context)
    {
        _activity->allocateStackFrame(&stack, code->getMaxStackSize());


================================================================================
getMaxStackSize (= maxStack which is calculated during parsing)
================================================================================

RexxCode.hpp
    class RexxCode
    {
       inline size_t getMaxStackSize() { return maxStack; }
       ...
    protected:

      size_t            maxStack;          /* maximum stack depth               */

RexxCode.cpp
    RexxCode::RexxCode(
         RexxSource      * _source,        /* source object                     */
         RexxInstruction * _start,         /* start of the code tree            */
         RexxDirectory   * _labels,        /* method labels                     */
         size_t            maxstack,       /* max operator stack size           */
         size_t            variable_index) /* save of the vdict                 */
    /******************************************************************************/
    /* Function:  Initialize a rexxmethod code object                             */
    /******************************************************************************/
    {
      OrefSet(this, this->source, _source); /* save the program source         */
      OrefSet(this, this->start, _start);   /* the parse tree                    */
      OrefSet(this, this->labels, _labels); /* the method's labels               */
      /* save the stack info               */
      this->maxStack = maxstack;
      this->vdictSize = variable_index;    /* save the initial vdict size       */
    }


SourceFile.cpp
    /**
     * Perform a non-contextual install of a package.
     */
    void RexxSource::install()
    {
        if (needsInstallation())
        {
            // In order to install, we need to call something.  We manage this by
            // creating a dummy stub routine that we can call to force things to install
            RexxCode *stub = new RexxCode(this, OREF_NULL, OREF_NULL, 10, FIRST_VARIABLE_INDEX);
            ProtectedObject p2(stub);
            RoutineClass *code = new RoutineClass(programName, stub);
            p2 = code;
            ProtectedObject dummy;
            code->call(ActivityManager::currentActivity, programName, NULL, 0, dummy);
        }
    }


    RexxCode *RexxSource::translateBlock(
        RexxDirectory *_labels )            /* labels (for interpret)            */
    /******************************************************************************/
    /* Function:  Translate a block of REXX code (delimited by possible           */
    /*            directive instructions                                          */
    /******************************************************************************/
    {
        ...
        return new RexxCode(this, this->first, this->labels, (this->maxstack+ 10), this->variableindex);
    }


================================================================================
maxStack, currentstack
================================================================================

SourceFile.hpp

    class RexxSource
    {
        ...
        size_t           currentstack;       /* current expression stack depth    */
        size_t           maxstack;           /* maximum stack depth               */


SourceFile.cpp

    void RexxSource::pushTerm(
        RexxObject *term )                 /* term to push                      */
    /******************************************************************************/
    /* Function:  Push a term onto the expression term stack                      */
    /******************************************************************************/
    {
        this->terms->push(term);             /* push the term on the stack      */
        this->currentstack++;                /* step the stack depth              */
                                             /* new "high water" mark?            */
        if (this->currentstack > this->maxstack)
        {
            /* make it the highest point         */
            this->maxstack = this->currentstack;
        }
    }


    /**
     * Push a term on to the expression sub term stack.  The
     * subterms normally contribute to the total required stack
     * size, so make sure we account for these when calculating the
     * total required stack size.  Only use this method of pushing
     * the term when the max stack size is affected.
     *
     * @param term   The term object.
     */
    void RexxSource::pushSubTerm(RexxObject *term )
    {
        // push the term on to the stack.
        subTerms->push(term);

        // we keep track of how large the term stack gets during parsing.  This
        // tells us how much stack space we need to allocate at run time.
        currentstack++;
        // maxStack = Numerics::maxVal(currentStack, maxStack);
        if (currentstack > maxstack) maxstack = currentstack;
    }

===================================================================

   void        popStackFrame(bool  reply);
   void        popStackFrame(RexxActivationBase *);
   void        unwindStackFrame();
   void        unwindToDepth(size_t depth);
   void        unwindToFrame(RexxActivation *frame);
   void        cleanupStackFrame(RexxActivationBase *poppedStackFrame);

findRexxContext

setPreviousStackFrame
    RexxActivity::pushStackFrame
        RexxActivity::exitKernel
        RexxActivity::run
        RexxActivation::run
        RexxActivation::interpret
        RexxActivation::debugInterpret
        RexxActivation::internalCall
        RexxActivation::internalCallTrap
        RexxCode::call
        RexxCode::run
        RexxNativeMethod::run
        RexxNativeRoutine::call
        RegisteredRoutine::call


================================================================================
Review of stack space checking (because doers-stress.rex crashes under win7)
================================================================================

Diagnostic :
I think the crash comes from the fact TOTAL_STACK_SIZE = value of /STACK
When calling checkStackSpace, a part of the stack is already used, so there is not
exactly TOTAL_STACK_SIZE available.
[later]
In fact, MIN_C_STACK is used to keep a reserve stack when checking the remaining space.


checkStackSpace

Controlled by the following macro definitions :
    interpreter\platform\unix\PlatformDefinitions.h
        #define MIN_C_STACK 1024*16                         16384
        #define TOTAL_STACK_SIZE 1024*512
        #define C_STACK_SIZE TOTAL_STACK_SIZE
        #define STACKCHECK
    interpreter\platform\windows\PlatformDefinitions.h
        #define MIN_C_STACK 1024*(32 + sizeof(void *))      before fix : 32768, after fix for 32 bits : 1024*(32+4)=36864, for 64 bits : 1024*(32+8)=40960
        #define TOTAL_STACK_SIZE 1024*512
        #define C_STACK_SIZE 60000                          has been changed in official : TOTAL_STACK_SIZE instead of 60000
        #define STACKCHECK
and also by activity->stackcheck, which is always true, except here :
    RexxActivity::messageSubstitution
don't know why this special case...


Official
    interpreter\platform\unix\PlatformDefinitions.h
        #define MIN_C_STACK 1024*(32 + sizeof(void *))
        #define TOTAL_STACK_SIZE 1024*512
        #define C_STACK_SIZE TOTAL_STACK_SIZE
    interpreter\platform\windows\PlatformDefinitions.h
        #define MIN_C_STACK 1024*(32 + sizeof(void *))
        #define TOTAL_STACK_SIZE 1024*512
        #define C_STACK_SIZE TOTAL_STACK_SIZE


RexxActivity.cpp
    void RexxActivity::checkStackSpace()
    /******************************************************************************/
    /* Function:  Make sure there is enough stack space to run a method           */
    /******************************************************************************/
    {
    #ifdef STACKCHECK
      size_t temp;                          // if checking and there isn't room
      if (((char *)&temp - (char *)this->stackBase) < MIN_C_STACK && this->stackcheck == true)
      {
                                            // go raise an exception
          reportException(Error_Control_stack_full);
      }
    #endif
    }

called from :
    void RexxObject::messageSend        (ObjectClass.cpp)
    RexxActivation::interpret           (RexxActivation.cpp)
    RexxCode::call                      (RexxCode.cpp)
    RexxExpressionFunction::evaluate    (ExpressionFunction.cpp)
    RexxInstructionCall::execute        (CallInstruction.cpp)


---------------------------------------------------------------
Review of stack size declarations
---------------------------------------------------------------

There are TWO implementations of threads.                           Unix                                Windows
one used by trunk\rexxapi\server
    stack size (used to create thread, to calculate stack base)     THREAD_STACK_SIZE = 1024*96         THREAD_STACK_SIZE = 1024*512
    check stack space                                               no                                  no
one used by trunk\interpreter
    stack size (used only to calculate the stack base)              TOTAL_STACK_SIZE = 1024*512         TOTAL_STACK_SIZE = 1024*512
    check stack space : minimal reserve                             MIN_C_STACK = 1024*16               MIN_C_STACK = 1024*(32 + sizeof(void *))
    stack size used to create thread                                C_STACK_SIZE = TOTAL_STACK_SIZE     C_STACK_SIZE = 60000 (in official = TOTAL_STACK_SIZE)
                                                                                                        /STACK:524288 (1024 * 512)
Note :
MIN_C_STACK for Windows 32 bits = 1024*(32+4)=36864
MIN_C_STACK for Windows 64 bits = 1024*(32+8)=40960

Note :
The first thread is not created by ooRexx, it's the main thread of the process.
The stack size of this first thread is system dependent :
    Windows : given by /STACK:524288
    Unix : ???
The stackSize of the other threads is given by C_STACK_SIZE
RexxActivity::RexxActivity(bool createThread)
    ...
    currentThread.create(this, C_STACK_SIZE)        JLF : SysActivity currentThread;
    ...

C:\jlf\local\rexx\oorexx\executor\sandbox\jlf\trunk\interpreter\platform\unix\SysActivity.cpp
    void SysActivity::create(RexxActivity *activity, size_t stackSize)
        ...
        rc = pthread_attr_setstacksize(&newThreadAttr, stackSize);
        ...
C:\jlf\local\rexx\oorexx\executor\sandbox\jlf\trunk\interpreter\platform\windows\SysActivity.cpp
    void SysActivity::create(RexxActivity *activity, size_t stackSize)
        ...
        hThread = CreateThread(NULL, stackSize, call_thread_function, (void *)activity, 0, &res);
        ...

Note :
The stack grows from higher addresses to lower addresses.
getStackBase returns the stack's lowest address, but the calculation is empirical !
The calculation depends on the parameter stackSize, whose value is TOTAL_STACK_SIZE.


Only in trunk\rexxapi\server :

    trunk\common\platform\unix\SysThread.hpp
        THREAD_STACK_SIZE = 1024*96

    trunk\common\platform\unix\SysThread.cpp
        NOT USED !
        char *SysThread::getStackBase()
        {
           int32_t temp;
           return ((char *)(&temp)) - THREAD_STACK_SIZE;
        }

    trunk\common\platform\windows\SysThread.hpp
        THREAD_STACK_SIZE = 1024*512

    trunk\common\platform\windows\SysThread.cpp
        NOT USED !
        char *SysThread::getStackBase()
        {
           int32_t temp;
           return ((char *)(&temp)) - THREAD_STACK_SIZE;
    }

Only in trunk\interpreter :
    trunk\interpreter\platform\unix\PlatformDefinitions.h
        #define MIN_C_STACK 1024*16
        #define TOTAL_STACK_SIZE 1024*512               0x80000    524288

    trunk\interpreter\platform\windows\PlatformDefinitions.h
        // we need a little more space on 64-bit platforms, so add some padding based on
        // the size of a pointer
        #define MIN_C_STACK 1024*(32 + sizeof(void *))   0xa000     40960   sizeof(void *) == 8 bytes
        #define TOTAL_STACK_SIZE 1024*512               0x80000    524288

    trunk\interpreter\platform\unix\SysActivity.cpp
        char *SysActivity::getStackBase(size_t stackSize)
        {
            size_t temp;
            return (char *)&temp - stackSize;
        }
    trunk\interpreter\platform\windows\SysActivity.cpp
        char *SysActivity::getStackBase(size_t stackSize)
        {
            size_t temp;
            return(char *)&temp - stackSize;
        }

    trunk\interpreter\concurrency\RexxActivity.hpp
        class RexxActivity : public RexxInternalObject {
            SysActivity currentThread;          /* descriptor for this thread        */
            char       *stackBase;              /* pointer to base of C stack        */

    trunk\interpreter\concurrency\RexxActivity.cpp
        void RexxActivity::runThread()
        {
            this->stackBase = currentThread.getStackBase(TOTAL_STACK_SIZE);
            ...

        void RexxActivity::checkStackSpace()
        {
            size_t temp;                          // if checking and there isn't room
            if (((char *)&temp - (char *)this->stackBase) < MIN_C_STACK && this->stackcheck == true)
            ...


(char *)&temp =           0x00000000000c75a0
(char *)this->stackBase = 0x00000000000bd5e0
                                        9fc0

RexxActivity.cpp
RexxActivity::RexxActivity
if (createThread)   --> 1er appel : false


 	rexx.dll!RexxActivity::RexxActivity(bool createThread)  Ligne 265	C++
 	rexx.dll!ActivityManager::createCurrentActivity()  Ligne 378 + 0x23 octets	C++
 	rexx.dll!ActivityManager::getRootActivity()  Ligne 691 + 0x5 octets	C++
 	rexx.dll!Interpreter::createInterpreterInstance(RexxOption * options)  Ligne 315 + 0x5 octets	C++
 	rexx.dll!Interpreter::createInterpreterInstance()  Ligne 95 + 0xb octets	C++
 	rexx.dll!InstanceBlock::InstanceBlock()  Ligne 383 + 0x5 octets	C++
 	rexx.dll!Interpreter::startInterpreter(Interpreter::InterpreterStartupMode mode)  Ligne 144 + 0xa octets	C++
 	rexx.dll!Interpreter::createInterpreterInstance(RexxOption * options)  Ligne 308 + 0xa octets	C++
 	rexx.dll!Interpreter::createInstance(RexxInstance_ * & instance, RexxThreadContext_ * & threadContext, RexxOption * options)  Ligne 266 + 0xd octets	C++
 	rexx.dll!RexxCreateInterpreter(RexxInstance_ * * instance, RexxThreadContext_ * * context, RexxOption * options)  Ligne 382 + 0x14 octets	C++
>	rexx.exe!main(int argc, char * * argv)  Ligne 198	C++

GetCurrentThreadId
GetCurrentThread

MSDN
http://msdn.microsoft.com/en-us/library/windows/desktop/ms686774%28v=vs.85%29.aspx
The default size for the reserved and initially committed stack memory is specified in the executable file header.
The default stack reservation size used by the linker is 1 MB. To specify a different default stack reservation size for all threads and fibers, use the STACKSIZE statement in the module definition (.def) file. The operating system rounds up the specified size to the nearest multiple of the system's allocation granularity (typically 64 KB).


trunk\utilities\rexx\platform\windows\rexx.mak
trunk\utilities\rexxc\platform\windows\rexxc.mak
trunk\utilities\platform\windows\rexxpaws\rexxpaws.mak
trunk\utilities\platform\windows\rexxhide\rexxhide.mak
trunk\platform\windows\rexximage.mak
/STACK:524288       JLF = 1024 * 512 donc même taille que pour thread stack (TOTAL_STACK_SIZE)


trunk\extensions\platform\windows\orxscrpt\orxscrpt.def
STACKSIZE 10240

trunk\extensions\platform\windows\orxscrpt\orxscrpt.mak
$(OR_OUTDIR)\ORXSCRPT.lib : $(CPPOBJS) $(OR_ORXSCRIPTSRC)\ORXSCRPT.def


===============================================================================
http://stackoverflow.com/questions/199747/how-to-detect-possible-potential-stack-overflow-problems-in-a-c-c-program
===============================================================================

On windows, the stack (for specific thread) grows on-demand until the stack size specified
for this thread prior to its creation has been reached.

On-demand growing is impelmented using guard pages, in that there's a only a fragment of stack available initially,
followed by a guard page, which, when hit, will trigger an exception - this exception is special,
and is handled by the system for you - the handling increases the available stack space
(also checked if a limit has been reached!) and the read operation is retried.

Once the limit is reached, there's no more growing which results in stack overflow exception.
The current stack base and limit are stored in thread environment block, in a struct called _NT_TIB (thread information block).
If you have a debugger handy, this is what you see:

0:000> dt ntdll!_teb @$teb nttib.
   +0x000 NtTib  :
      +0x000 ExceptionList : 0x0012e030 _EXCEPTION_REGISTRATION_RECORD
      +0x004 StackBase : 0x00130000
      +0x008 StackLimit : 0x0011e000
      +0x00c SubSystemTib : (null)
      +0x010 FiberData : 0x00001e00
      +0x010 Version : 0x1e00
      +0x014 ArbitraryUserPointer : (null)
      +0x018 Self   : 0x7ffdf000 _NT_TIB
The StackLimit attribute will get updated on-demand. If you check the attributes on this memory block, you'll see something similar to that:

0:000> !address 0x0011e000
    00030000 : 0011e000 - 00012000
                    Type     00020000 MEM_PRIVATE
                    Protect  00000004 PAGE_READWRITE
                    State    00001000 MEM_COMMIT
                    Usage    RegionUsageStack
                    Pid.Tid  abc.560
And checking a page next to it reveals the guard attribute:

0:000> !address 0x0011e000-1000
    00030000 : 0011d000 - 00001000
                    Type     00020000 MEM_PRIVATE
                    Protect  00000104 PAGE_READWRITE | PAGE_GUARD
                    State    00001000 MEM_COMMIT
                    Usage    RegionUsageStack
                    Pid.Tid  abc.560


===============================================================================
https://software.intel.com/en-us/blogs/2010/07/01/the-reasons-why-64-bit-programs-require-more-stack-memory/
===============================================================================

In forums, people often say that 64-bit versions of programs consume a larger amount of memory and stack.
Saying so, they usually argue that the sizes of data have become twice larger.
But this statement is unfounded since the size of most types (char, short, int, float) in the C/C++ language remains the same on 64-bit systems.
Of course, for instance, the size of a pointer has increased but far not all the data in a program consist of pointers.
The reasons why the memory amount consumed by programs has increased are more complex.
I decided to investigate this issue in detail.

In this post, I will speak about the stack and in future I plan to discuss memory allocation and binary code's size.
And I would like also to note right away that the article covers the language C/C++ and Microsoft Visual Studio development environment.

Until recently, I have believed that the code of a 64-bit application cannot consume the stack quicker than twice in comparison to 32-bit code.
Relying on this assumption, in my articles, I recommended to increase the program stack two times just in case.
But now I have explored an unpleasant thing: stack consumption might grow much higher than twice.
I was astonished since I considered the stack growth of two times the worst-case scenario.
The reason of my unfounded hopes will become clear a bit later.
But now let's see how parameters are passed in a 64-bit program when calling functions.

When developing calling conventions for the x86-64 architecture, they decided to bring an end to various versions of function calls.
In Win32, there was a wide range of calling conventions: stdcall, cdecl, fastcall, thiscall, etc.
In Win64, there is only one "native" calling convention.
Modifiers like __cdecl are ignored by the compiler.
I think everybody agrees that such an axe of calling conventions is noble.

The calling convention on the x86-64 platform resembles the fastcall convention existing in x86.
In the x64-convention, the first four integer arguments (left to right) are passed in 64-bit registers chosen specially for this purpose:
RCX: the 1-st integer argument
RDX: the 2-nd integer argument
R8: the 3-rd integer argument
R9: the 4-th integer argument
The rest integer arguments are passed through the stack.
The pointer "this" is considered an integer argument, so it is always placed into the RCX register.
If floating-point values are passed, the first four of them are passed in the registers XMM0-XMM3 while all the next are passed through the stack.

Relying on this information, I concluded that a 64-bit program can in many cases save the stack memory unlike a 32-bit one.
For if parameters are passed through registers and the code of the function is brief and there is no need to save the arguments in the memory (stack),
then the size of the stack memory being consumed must be smaller. But it is not so.

Although arguments can be passed in registers, the compiler all the same reserves some space for them in the stack
by reducing the value of the RSP register (the stack pointer).
Each function must reserve at least 32 bytes (four 64-bit values corresponding to the registers RCX, RDX, R8, R9) in the stack.
This space in the stack allows to easily save the contents of the registers passed into the function in the stack.
The function being called is not required to save input parameters passed through the registers into the stack
but reserving space in the stack allows to do this if necessary.
If more than four integer parameters are passed, some additional space must be reserved in the stack.

Let's consider an example. Some function passes two integer parameters to a child function.
The compiler places the arguments' values into the registers RCX and RDX and meanwhile subtracts 32 bytes from the RSP register.
The function being called can address the parameters through the registers RCX and RDX.
If the code of this function needs these registers for some purpose, it can copy their contents into the reserved space in the stack with the size 32 bytes.

The described feature leads to a significant growth of the stack consumption speed.
Even if the function does not have parameters, 32 bytes will be "bit off" the stack anyway and they will not be used anyhow then.
I failed to find the reason for such a wasteful mechanism.
There were some explanations concerning unification and simplification of debugging but this information was too vague.

Note another thing. The stack pointer RSP must be aligned on a 16-byte boundary before a next function call.
Thus, the total size of the stack being used when calling a function without parameters in 64-bit code is:
8 (the return address) + 8 (alignment) + 32 (reserved space for arguments) = 48 bytes!

Let's see what it might cause in practice.
Here and further, I will use Visual Studio 2010 for my experiments. Let's make a recursive function like this:

void StackUse(size_t *depth)
{
  volatile size_t *ptr = 0;
  if (depth != NULL)
    ptr = depth;
  cout << *ptr << endl;
  (*ptr)++;
  StackUse(depth);
  (*ptr)--;
}

The function is deliberately a bit confused to prevent the optimizer from turning it into "nothing".
The main thing here is: the function has an argument of the pointer type and one local variable, also pointer-type.
Let's see how much stack is consumed by the function in the 32-bit and 64-bit versions
and how many times it can be recursively called when the stack's size is 1 Mbyte (the size by default).

Release 32-bit: the last displayed number (stack depth) - 51331
The compiler uses 20 bytes when calling this function.

Release 64-bit: the last displayed number - 21288
The compiler uses 48 bytes when calling this function.

Thus, the 64-bit version of the StackUse function is more than twice voracious than the 32-bit one.
Note that changing of data alignment rules might also influence the size of consumed stack.
Let's assume that the function takes the following structure as an argument:

struct S
{
  char a;
  size_t b;
  char c;
};

void StackUse(S s) { ... }

The size of the 'S' structure increases from 12 bytes to 24 bytes when being recompiled in the 64-bit version
due to changes of alignment rules and change of the 'b' member's size.
The structure is passed into the function by the value.
And, correspondingly, the structure will also take twice more memory in the stack.

Can it all be so bad? No.
Do not forget that the 64-bit compiler can handle more registers than the 32-bit one.
Let's complicate the experiment function's code:

void StackUse(size_t *depth, char a, int b)
{
  volatile size_t *ptr = 0;
  int c = 1;
  int d = -1;
  for (int i = 0; i < b; i++)
    for (char j = 0; j < a; j++)
      for (char k = 0; k < 5; k++)
        if (*depth > 10 && k > 2)
        {
          c += j * k - i;
          d -= (i - j) * c;
        }
  if (depth != NULL)
    ptr = depth;
  cout << c << " " << d << " " << *ptr << endl;
  (*ptr)++;
  StackUse(depth, a, b);
  (*ptr)--;
}

Here are the results of its execution:

Release 32-bit: the last displayed number - 16060
The compiler uses 64 bytes this time when calling this function.

Release 64-bit: the last displayed number - 21310
The compiler still uses 48 bytes when calling this function.

The 64-bit compiler managed to use additional registers for this sample and build a more efficient code
allowing us to reduce the amount of the stack memory being consumed!

Conclusions
One cannot foresee how much stack memory a 64-bit version of a program will consume in comparison to a 32-bit one.
It might be both less (unlikely) and much more.

For a 64-bit program, you should increase the amount of reserved stack 2-3 times.
3 times is better - just to feel at ease.
To do this, see the parameter Stack Reserve Size (the /STACK:reserve switch) in project settings. By default the stack's size is 1 Mbyte.

You should not worry if your 64-bit program consumes more stack memory.
There is much more physical memory in 64-bit systems.
The stack with the size 2 Mbytes on a 64-bit system with 8 Gbytes of memory takes fewer percent of memory
than 1 Mbyte of stack in a 32-bit system with 2 Gbytes.
