About "UNEXPECTED_KERNEL_MODE_TRAP " error

Hi,
I use the Wincap souce code to do someting .When i receive a
packets , i’ll insert a function to a queue , then wake a thread to
process the queue .But when the thread execute over 2400 times , a
error "UNEXPECTED_KERNEL_MODE_TRAP p1=0x8 ;p2 =0;p3=0;p4=0 " will
shown in SoftIce,
I use the IoGetRemainingStackSize() in thread to check the stack of
thread. The first time run IoGetRemainingStackSize() , the value is
11660.
When thread run each time ,the stack size will be eaten 4,and when the
value reduce to 1960, the error will come out .
So do somebody can tell me why stack be eaten ,and how can avoid it?
Wish for your suggestions.
Thanks
Josephxu

The following are queue structure and some piece of code :

// – typedefs -----------------------------------------------------------------
typedef struct{
S8 name[40];
void (*func)(void *);
void *param;
U8 status;
U8 dbg_mode;
}TASK, *PTASK;
typedef struct{
TASK task[MAX_TASKQ_SIZE];
U16 w_idx;
U16 r_idx;
U16 count;
U16 show_cnt;
}TASK_Q;
TASK_Q task_queue_tc;

/*thread process*/
void TaskProc(
IN PTC_DEVICE_EXTENSION pdx
)
{
PTASK task;
NTSTATUS status;
NDIS_HANDLE ProtocolBindingContext = NULL;
POPEN_INSTANCE Open;
ULONG i;

//test file I/O
HANDLE handle=NULL;
PWCHAR filename;
BOOLEAN read;
ULONG numwritten;
#define arraysize(p) (sizeof(p)/sizeof((p)[0]))

PVOID pollevents = {
(PVOID) &pdx->evKill,
(PVOID) &pdx->evRequest,
};

// Wait for a request to arrive at our StartIoRead routine or for
// someone to kill this thread.

//set current thread prioriy : 20
//KeSetPriorityThread(KeGetCurrentThread(), 20);

while (TRUE)
{
// Block until time to poll again

status = KeWaitForMultipleObjects(arraysize(pollevents),
pollevents, WaitAny, Executive, KernelMode, FALSE, NULL, NULL);

if (!NT_SUCCESS(status))
{ // error in wait
KdPrint((“- KeWaitForMultipleObjects failed - %X\n”, status));
break; // from read next byte
} // error in wait

if (status == STATUS_WAIT_0)
{ // told to quit
status = STATUS_DELETE_PENDING;
break; // from read next byte
} // told to quit

//

while( CheckTaskQueue() )
{
task = GetTask();
task->status = TASK_START;
task->func(task->param); //run the process
}
} // read next byte

PsTerminateSystemThread(STATUS_SUCCESS); //terminate the system thread byself

} // TaskProc