[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [microblaze-uclinux] User application stack size checking in the microblaze..



Thanx falk for the response,
It would have been great if it is in the kernel code (something like
this http://mailman.uclinux.org/pipermail/uclinux-dev/2004-November/029603.html)
so that i dont' change all my application code.  Try to replicate that
code with mblaze pt_reg[r1] for stack. Not sure what i am missing.

There was also another one in uclinux-dev for blackfin to check the
stack through this
(http://lists.blackfin.uclinux.org/pipermail/gcc3-devel/2005-August/000638.html).

- Prasad

On 5/2/06, Brettschneider Falk <fbrettschneider@xxxxxxxxxxxxxxxxx> wrote:
Hi Prasad,

DeviPrasad Natesan wrote:
> Is there any tool or inline code to check the user application code
> stack overflow in the microblaze
...
> Is there any inline code that i can add in the kernel to
> detect user application stack overflow.
once upon a time I posted source code of a little thread test application to
uclinux-dev to report&demonstrate a Linux hang with SCHED_RR apps (meanwhile
fixed by JW). It also contained this which watches the user app stack. We
fill the stack with a pattern on thread initialisation and can use it for a
check later.

initThread()
{
...
    if (stackSize) {
        size_t curStackSize;
        error = pthread_attr_getstacksize(&pThread->attr, &curStackSize);
        error = pthread_attr_setstacksize(&pThread->attr, stackSize);
    }
    if (pStackPtr) {
        unsigned int* pCurStackAddr;
        size_t curStackSize;
        error = pthread_attr_getstack(&pThread->attr,
(void**)(&pCurStackAddr), &curStackSize);
        error = pthread_attr_setstack(&pThread->attr, pStackPtr,
curStackSize);
        if (stackAreaSize) { /* init stack contents */
            pThread->nStackAreaSize = stackAreaSize;
            pthread_attr_getstack(&pThread->attr, (void**)(&pCurStackAddr),
&curStackSize);
            curStackSize = stackAreaSize; curStackSize /= 4;
            while (curStackSize > 0) { *(--pCurStackAddr) = 0x01020304;
curStackSize--; }
        }
    }
}

bool checkStack(struct Thread* pThread)
{
    unsigned int* pCurStackAddr;
    size_t curStackSize;
    bool bStackOk = true;

    if (pThread->nStackAreaSize == 0) { return true; }
    pthread_attr_getstack(&pThread->attr, (void**)(&pCurStackAddr),
&curStackSize);
    if (pThread->nStackAreaSize < curStackSize) { return true; }
    pCurStackAddr -= curStackSize/4;
    curStackSize = (pThread->nStackAreaSize-curStackSize)/4;
    while (curStackSize > 0) {
        if (*(--pCurStackAddr) != 0x01020304) { bStackOk = false; break; }
        curStackSize--;
    }
    return bStackOk;
}

unsigned int maxStackUsage(struct Thread* pThread)
{
    unsigned int* pCurStackAddr, *pCheckStackAddr, *pLastUsedStackAddr = 0L;
    size_t curStackSize;
    if (pThread->nStackAreaSize == 0) { return 0; }
    pthread_attr_getstack(&pThread->attr, (void**)(&pCurStackAddr),
&curStackSize);
    pCheckStackAddr = pCurStackAddr - pThread->nStackAreaSize/4;
    while (pCheckStackAddr != pCurStackAddr) {
        if (*pCheckStackAddr != 0x01020304) { pLastUsedStackAddr =
pCheckStackAddr; break; }
        pCheckStackAddr++;
    } {
    int bytes = (pCurStackAddr-pLastUsedStackAddr)*4;
    int percent = bytes * 100 / curStackSize;
    }
    return (pCurStackAddr-pLastUsedStackAddr)*4;
}

CU, F@lk
___________________________
microblaze-uclinux mailing list
microblaze-uclinux@xxxxxxxxxxxxxx
Project Home Page : http://www.itee.uq.edu.au/~jwilliams/mblaze-uclinux
Mailing List Archive : http://www.itee.uq.edu.au/~listarch/microblaze-uclinux/



___________________________
microblaze-uclinux mailing list
microblaze-uclinux@xxxxxxxxxxxxxx
Project Home Page : http://www.itee.uq.edu.au/~jwilliams/mblaze-uclinux
Mailing List Archive : http://www.itee.uq.edu.au/~listarch/microblaze-uclinux/