Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Unsafe native methods

1 view
Skip to first unread message

Andrew Jarvis

unread,
Dec 1, 2009, 8:23:50 AM12/1/09
to
I have a VC++/CLR method that calls some assembly code.

At a point where the assembly codes tries to load the ebp register with a
value, execution switches to a function called
System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop
never to return.

What do I have to do to allow my code to execute unmolested?


Pavel A.

unread,
Dec 1, 2009, 8:57:58 AM12/1/09
to
"Andrew Jarvis" <someone@somewhere> wrote in message
news:OI#lGmocK...@TK2MSFTNGP06.phx.gbl...

Save and restore registers correctly? Tell whoever wrote these assembly
codes to fix them?

--pa

Andrew Jarvis

unread,
Dec 1, 2009, 12:26:01 PM12/1/09
to
> Tell whoever wrote these assembly codes to fix them?

I wrote the code!

These are the first few instructions...

======
_SWExportPixelsB PROC

push ebx
push edi
push esi
push ebp

cld
mov esi,[esp+srcData]
mov edi,[esp+dstData]
mov ebp,[esp+lutData]
======

The exception happens on the last line - mov ebp,[esp+lutData].
Since the routine exits abnormally, it would not matter if the registers
were not saved.

If I use ebx instead of ebp, its works fine but then ebx has two roles and
additional loading and saving is required.

AJ


"Pavel A." <pav...@12fastmail34.fm> wrote in message
news:OK2Yv5oc...@TK2MSFTNGP04.phx.gbl...

Andrew Jarvis

unread,
Dec 1, 2009, 12:48:28 PM12/1/09
to
I should emphasise that my code performs correctly.
It is just that it takes a detour via the 'unsafe method' trap. I don't know
exactly what is happening here, but the trap eventually returns and
execution continues.
I wanted to know if there is a way to stop these checks. I found the
SuppressUnmanagedCodeSecurity attribute but my code is being called during a
message handler so the managed/native transition seems beyond my control.

"Pavel A." <pav...@12fastmail34.fm> wrote in message
news:OK2Yv5oc...@TK2MSFTNGP04.phx.gbl...

Pavel A.

unread,
Dec 1, 2009, 6:55:45 PM12/1/09
to
"Andrew Jarvis" <someone@somewhere> wrote in message
news:O6pIctqc...@TK2MSFTNGP06.phx.gbl...

>> Tell whoever wrote these assembly codes to fix them?
>
> I wrote the code!
>
> These are the first few instructions...
>
> ======
> _SWExportPixelsB PROC
>
> push ebx
> push edi
> push esi
> push ebp
>
> cld
> mov esi,[esp+srcData]
> mov edi,[esp+dstData]
> mov ebp,[esp+lutData]
> ======
>
> The exception happens on the last line - mov ebp,[esp+lutData].
> Since the routine exits abnormally, it would not matter if the registers
> were not saved.
>
> If I use ebx instead of ebp, its works fine but then ebx has two roles and
> additional loading and saving is required.
>
> AJ

Do you single step in a debugger? If so, which debugger?
Maybe some other debugger won't be confused by unexpected change of ebp...

--pa

0 new messages