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/