Re: Starting another asynchronous I/O in IOCP worker thread causes stack corruption



Remember that OVERLAPPED structure should remain valid (in the current stack
frame or allocated from heap) during all time while the I/O is in progress.

"Rainny" <rainny@xxxxxxxxx> wrote in message
news:1175700364.089631.182350@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
Hi everybody,

I wonder if it is legal to start another asynchronous socket I/O in
IOCP worker thread. The actual code is too verbose to post here, and
what follows is a sketch:

DWORD WINAPI worker_proc(LPVOID param)
{
LPOVERLAPPED ol;
...

BOOL res = ::GetQueuedCompletionStatus(cport, &n, &ph, &ol,
INFINITE);

if (res == TRUE && ph) {
// foo() allocate a new OVERLAPPED structure,
// using it to start another async i/o operation on the same
socket,
// or simply call ::PostQueuedCompletionStatus(), and then,
SOMETIMES,
// stack below worker_proc() is corrupted.
foo();
}

return 0;
}

By 'corrupted' I mean that the first 4 bytes of foo() stack is
overwritten with '0x00000010', or in the absence of local variables,
the return address (or something) becomes '0x00000010'.

Does anybody know what's going wrong here? It confuses us for a very
long time, and any hint is highly appreciated.



.



Relevant Pages

  • Re: "Heap" (was Re: static, global variable memory allocation)
    ... common to refer to the area used to allocate automatic objects ... Can a perverse but conforming implementation use the "heap" for ... used a linked list of save areas instead of a stack. ... CPU-specific region of memory that grows linearly in one direction, ...
    (comp.lang.c)
  • Re: style question,itoa
    ... able to allocate buffers in some convenient location the callee ... dynamically allocate a block of memory and computing this size to use ... call might require allocating a page for the stack. ... " Checking every single malloc in a bigger application for possible ...
    (comp.unix.programmer)
  • Re: run-time vs compile-time
    ... > offset related to some location (like stack base) somewhere. ... > offset from heap to pi. ... When you allocate an int on the heap, it is allocated at address 1. ... application has a given amount of memory it can use as it wishes. ...
    (comp.lang.cpp)
  • Re: run-time vs compile-time
    ... > offset related to some location (like stack base) somewhere. ... > offset from heap to pi. ... When you allocate an int on the heap, it is allocated at address 1. ... application has a given amount of memory it can use as it wishes. ...
    (alt.comp.lang.learn.c-cpp)
  • Re: heap allocation of arrays
    ... to force all arrays to be allocated on the heap. ... the stack would be replaced with pointers on the stack. ... heap is easier to detect than failure to allocate space on the ...
    (comp.lang.fortran)