Re: Is it safe to send one thread's stack buffer pointer to another th
"Igor Tandetnik" <itandetnik@mvps.org> wrote in message
news:ue4udKo4HHA.3400@TK2MSFTNGP03.phx.gbl...
"pango" <pango@discussions.microsoft.com> wrote in message
news:22EB684E-7E1A-4C23-93A3-D50DCE64926D@microsoft.com
My program hook some API call in main thread,and deliver the call to
another thread.I use below ASM code get a API call's input param
buffer(just the stack pointer):
_asm push eax,ebp;
_asm add eax,8; // eax register then store stack buffer address
and send this pointer to another thread, and thread will use the
pointer to repeat API call just
like below:
Meanwhile, what does the main thread do? Do you suspend it in some way
while the second thread performs the call on its behalf?
It is OK to pass a pointer into a thread's stack to another thread - as
long as you can be sure the stack frame is alive as long as the second
thread refers to it. That is, the main thread must not return from the
function call before the second thread does. At which point, it's not
clear why you would want to switch to another thread in the first place.
COM marshalling would be a good reason to do so.
In fact, pointers to stack variables are commonly passed to another thread
using the SendMessage function, which does indeed block until the other
thread indicates it is done using the parameters by returning from the
wndproc.
What's the point of the exercise? What exactly is this elaborate scheme
supposed to achieve?
--
With best wishes,
Igor Tandetnik
With sufficient thrust, pigs fly just fine. However, this is not
necessarily a good idea. It is hard to be sure where they are going to
land, and it could be dangerous sitting under them as they fly
overhead. -- RFC 1925