Re: How to call function from driver in inline assembler

Tech Tip: Click here to run a free scan for Windows Errors and optimize PC performance



Look at any MASM reference. For plain instructions, the syntax is the same.
Inline assembler doesn't support any of the meta-directives like macros.
There is some inline-assembler-specific syntax relating to using C/C++ types
and variables; the VC++ documentation talks about those.

"Peter" <Peter@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote in message
news:65398F6D-C08F-43F8-AADF-8652324F1147@xxxxxxxxxxxxxxxx
Thanks for tip Carly,

somewhere in the past I saw this way of calling, but I did not understand
it, now it's clean.
(after my last problem).
But I'd like to ask you:
What assembler reference are you using in writting inline _asm {} code on
windows ?

Peter

"Carl Woodward" wrote:

I tend to use "call ds:ExAllocatePoolWithTag", this has always worked for
me

Carly


"Skywing" <skywing_NO_SPAM_@xxxxxxxxxxxxxxxxxxx> wrote in message
news:uB62TkBhGHA.1508@xxxxxxxxxxxxxxxxxxxxxxx
You're calling the import descriptor (a pointer) for that function
instead
of calling through it. Try perhaps 'call dword ptr
[ExAllocatePoolWithTag]` or something along the lines of that.

"Peter" <Peter@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote in message
news:2C76FCB2-86BB-47D1-B480-C1D6A79FEC26@xxxxxxxxxxxxxxxx
I see difference between ExAllocatePoolwithTag caled normally like C
function
and called from _asm {}.
In C case, there is indirect call, instruction is 6 byte and begins
with
FF
15 .
In _asm {} there call instruction is 5 bytes and begins with E8 .
When I step into call compiled in _asm {} block (described in previous
mail),
it jumps into small part of code which begins with symbol
__imp__ExAllocatePoolWithTag .
First instruction in this code is:
test [ebx],dh
(All I am trying in release version built with debug info)
On this instruction blue screen PAGE_FAULT_IN_NONPAGED_AREA occures.
It seems that in calling by this way must be prepared ebx register ?
Or not possible to call other functions than are part of calling
driver ?

Yes I agree with you that using inline _asm is not very effective
I need it only very seldom, it is calculated that it will be used only
in
32-bit driver build.

Peter
"Steve Dispensa" wrote:

You shouldn't use inline asm, especially for something as trivial as
this,
unless you're really just playing around. The 64-bit compilers don't
have
inline asm support at all, and in general, it creates a maintenance
headache
and (unwanted?) job security for the developer.

"Failed" is ambiguous; is it building? What happens when you single
step
it
in a debugger?

-Steve


On 5/29/06 3:50 AM, in article
EFE28483-3D53-42D8-9DEB-1701CB5C180E@xxxxxxxxxxxxx, "Peter"
<Peter@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote:

In my driver I had tried to call two functions from _asm {} block.

Calling of function that is part of this driver was OK.
But calling for example ExAllocatePoolWithTag failed on call
instruction.
I tried this:

push 0x39393939
push 0x48c
push 0
call ExAllocatePoolWithTag
mov resultAddr, eax

Is possible in driver to call in _asm{} block functions which are
not
linked
in the same driver ?

Peter









.



Relevant Pages

  • [patch 02/11] GRU Driver - GRU instructions & macros
    ... This patchs contains macros & inline functions used to issue instructions to ... * Generic instruction format. ... +__opword(unsigned char opcode, unsigned char exopc, unsigned char xtype, ...
    (Linux-Kernel)
  • [patch] measurements, numbers about CONFIG_OPTIMIZE_INLINING=y impact
    ... gcc _does_ have a perfectly fine notion of how heavy-weight ... an "asm" statement is: just count it as a single instruction (and count ... I doubt that it's the inline asm that was the biggest reason ... size increase/decrease of the core kernel, ...
    (Linux-Kernel)
  • Re: Asm programming capability?
    ... I use inline asm and/or externally assembled libraries to create ... (as well as make sure ones' preferred assembler is installed, ... these issues are actually what makes run-time ASM preferable in my case... ...
    (comp.lang.c)
  • Re: Asm programming capability?
    ... use externally assembled asm on the rare occasions I need it. ... vaguely remember reading somewhere that gcc is doing an increasingly ... good job of accepting Intel syntax - I don't know if it's reached the ... probably use inline ASM... ...
    (comp.lang.c)
  • Add My Idea to the C++ Compiler
    ... gain a big improved performance because it only use JMP instruction however ... "inline" there because I don't care if my code is getting bigger and bigger. ... before JMP instruction can always be placed each function. ... Another option is to place 1,000 functions inside switch. ...
    (comp.lang.cpp)