Logo Search packages:      
Sourcecode: virtualbox-ose version File versions

int kldrDyldModGetMainStack ( PKLDRDYLDMOD  pMod,
void **  ppvStack,
KSIZE *  pcbStack 
)

Gets the main stack, allocate it if necessary.

Returns:
0 on success, non-zero native OS or kLdr status code on failure.
Parameters:
pMod The module.
ppvStack Where to store the address of the stack (lowest address).
pcbStack Where to store the size of the stack.

Definition at line 1137 of file kLdrDyldMod.c.

References KLDRSTACKINFO::Address, KLDRSTACKINFO::cbStack, KLDRDYLDMOD::fExecutable, g_cbkLdrDyldMainStack, g_fkLdrDyldDoneMainStack, g_fkLdrDyldMainStackAllocated, g_pvkLdrDyldMainStack, K_MAX, KLDR_ERR_MAIN_STACK_ALLOC_FAILED, KLDRDYLDMOD_ASSERT, kldrDyldOSAllocStack(), KLDRMOD_BASEADDRESS_MAP, kLdrModGetStackInfo(), KSIZE, KLDRSTACKINFO::LinkAddress, NIL_KLDRADDR, NULL, and KLDRDYLDMOD::pMod.

Referenced by kLdrDyldLoadExe(), and kldrDyldModStartExe().

{
    int rc = 0;
    KLDRSTACKINFO StackInfo;
    KLDRDYLDMOD_ASSERT(pMod->fExecutable);

    /*
     * Since we might have to allocate the stack ourselves, and there will only
     * ever be one main stack, we'll be keeping the main stack info in globals.
     */
    if (!g_fkLdrDyldDoneMainStack)
    {
        rc = kLdrModGetStackInfo(pMod->pMod, NULL, KLDRMOD_BASEADDRESS_MAP, &StackInfo);
        if (!rc)
        {
            /* check if there is a stack size override/default. */
            KSIZE cbDefOverride;
            if (kHlpGetEnvUZ("KLDR_MAIN_STACK_SIZE", &cbDefOverride))
                cbDefOverride = 0;


            /* needs allocating? */
            if (    StackInfo.LinkAddress == NIL_KLDRADDR
                ||  StackInfo.cbStack < cbDefOverride)
            {
                KSIZE cbStack = (KSIZE)K_MAX(StackInfo.cbStack, cbDefOverride);

                g_pvkLdrDyldMainStack = kldrDyldOSAllocStack(cbStack);
                if (g_pvkLdrDyldMainStack)
                {
                    g_cbkLdrDyldMainStack = cbStack;
                    g_fkLdrDyldMainStackAllocated = 1;
                }
                else
                    rc = KLDR_ERR_MAIN_STACK_ALLOC_FAILED;
            }
            else
            {
                KLDRDYLDMOD_ASSERT(StackInfo.Address != NIL_KLDRADDR);
                KLDRDYLDMOD_ASSERT(StackInfo.cbStack > 0);

                g_fkLdrDyldMainStackAllocated = 0;
                g_pvkLdrDyldMainStack = (void *)(KUPTR)StackInfo.Address;
                KLDRDYLDMOD_ASSERT((KUPTR)g_pvkLdrDyldMainStack == StackInfo.Address);

                g_cbkLdrDyldMainStack = (KSIZE)StackInfo.cbStack;
                KLDRDYLDMOD_ASSERT(StackInfo.cbStack == g_cbkLdrDyldMainStack);
            }
        }
        if (!rc)
            g_fkLdrDyldDoneMainStack = 1;
    }

    if (!rc)
    {
        if (ppvStack)
            *ppvStack = g_pvkLdrDyldMainStack;
        if (pcbStack)
            *pcbStack = g_cbkLdrDyldMainStack;
    }

    return rc;
}


Generated by  Doxygen 1.6.0   Back to index