首先说明得到此地址的原因。因为要用在线汇编,需要动态使用堆栈中的空间。最安全的方法就是使用_alloca函数。(_alloca函数决不是简单地分配一点空间那么简单,它还要判断下一个堆栈页的可读性,并负责动态增长堆栈。如果你盲目地去访问堆栈那很容易死翘翘的)尝试1:
void * (*_cdecl AllocaAddress)(size_t);
AllocaAddress=_alloca;连接器报告:找不到符号_alloca。
含入带有_alloca声明的malloc.h头文件之后,结果依然。尝试2:
生成如下代码的汇编列表
  _alloca(100);
汇编成
  mov eax,100;
  call __alloca_probe;
欣喜中,认为编译器实际上认为_alloca是另一个符号_alloca_probe的名称。
于是写出
AllocaAddress=_alloca_probe;
编译器报错:找不到符号_alloca_probe。
现在实在是束手无策了。那位高人知道的话指点一下。

解决方案 »

  1.   

    搂主可以使用depend或类是的工具 来观察 VC.NET 2003 的使用的lib,或 dll 的情况, 你或许能从 dll中,或从lib库中查出alloca 函数的address。个人观点仅供参考。
      

  2.   

    楼上那位,我找到他在lib中的address有什么用呢?绝不能靠静态工具得到地址,因为我要在代码中动态使用这个地址,但每次连接,这个地址都可能变化的啊。
      

  3.   

    找到这个函数所在的dll,然后用GetProcAddress行不行?
    FARPROC GetProcAddress(
      HMODULE hModule,    // handle to DLL module
      LPCSTR lpProcName   // function name
    );
      

  4.   

    _alloca_probe是NTDLL(在2K下)的输出函数,你不能自己调用
    为什么一定要这个函数呢?
      

  5.   

    To Phourm():
    我是没有办法啊。void MyFunc()
    {
       __asm
      {
          mov eax,100;
          call _alloca;
      }
    }
    无法通过编译,报告:找不到标号_alloca
      

  6.   

    跟踪发现进入了chkstk.asm,说不定可以这些代码抄过去
      

  7.   

    To XiangDong(木头):
    没有其他办法的话,也只好这样了……
      

  8.   

    _alloca是内部函数,在任何情况下它总是被inline的,所以你不可能得到他的地址,即使使用了
    #pragma intrinsic
    也不行。
    在msdn中索引pragma下子项intrinsic中对此有详细说明
      

  9.   

    sorry,上面写错了一点_alloca是内部函数,在任何情况下它总是被inline的,所以你不可能得到他的地址,即使使用了
    #pragma function
    也不行。
    在msdn中索引pragmas下子项intrinsic中对此有详细说明
      

  10.   

    To LocalVar(分乃身外之物,即使我回答对了,也别给分):
    我找了MSDN,里面没有提到_alloca啊?
      

  11.   

    直接从索引处确实找不到_alloca,要通过比较曲折的方法才能找到关于他的文档(我也记不太清了)
    但有关你的问题在msdn中索引pragmas下子项intrinsic中就有详细说明_alloca的文档这样找
    索引malloc function
        See Also节中的Memory Allocation Routines
            里面就有_alloca了,不过这里没有与此问题相关的内容我用的是vs.net不是2003,所以查找方法可能有区别
      

  12.   

    pragmas下子项intrinsic?
    我几乎翻烂了,没找着啊?倒是看见一大堆memcpy之类的
      

  13.   

    我给你贴在这吧
    #pragma intrinsic( function1 [, function2, ...] )
    Specifies that calls to functions specified in the pragma's argument list are intrinsic. The compiler generates intrinsic functions as inline code, not as function calls. The library functions with intrinsic forms are listed below. Once an intrinsic pragma is seen, it takes effect at the first function definition containing a specified intrinsic function. The effect continues to the end of the source file or to the appearance of a function pragma specifying the same intrinsic function. The intrinsic pragma can be used only outside of a function definition — at the global level.The following functions have intrinsic forms:_disable _outp fabs strcmp 
    _enable _outpw labs strcpy 
    _inp _rotl memcmp strlen 
    _inpw _rotr memcpy   
    _lrotl _strset memset   
    _lrotr abs strcat   Programs that use intrinsic functions are faster because they do not have the overhead of function calls but may be larger due to the additional code generated.Note   The _alloca and setjmp functions are always generated inline; this behavior is not affected by the intrinsic pragma.
    就是上面这一句
      

  14.   

    下面是那篇文档的后半部分x86 SpecificThe _disable and _enable parameters are kernel-mode instructions to disable/enable interrupts and could be useful in kernel-mode drivers.Example
    Compile the following code from the command line with "cl -c -FAs sample.c" and look at sample.asm to see that they turn into x86 instructions CLI and STI:// pragma_directive_intrinsic.cpp
    #include <dos.h>   // definitions for _disable, _enable
    #pragma intrinsic(_disable)
    #pragma intrinsic(_enable)
    void f1(void) {
       _disable();
       // do some work here that should not be interrupted
       _enable();
    }
    void main() {
    }
    End x86 SpecificThe floating-point functions listed below do not have true intrinsic forms. Instead they have versions that pass arguments directly to the floating-point chip rather than pushing them onto the program stack:acos cosh pow tanh 
    asin fmod sinh   The floating-point functions listed below have true intrinsic forms when you specify both the /Oi and /Og compiler options (or any option that includes /Og: /Ox, /O1, and /O2):atan exp log10 sqrt 
    atan2 log sin tan 
    cos       You can use the /Op or /Za compiler option to override generation of true intrinsic floating-point options. In this case, the functions are generated as library routines that pass arguments directly to the floating-point chip instead of pushing them onto the program stack. See # pragma function for information and an example on how to enable/disable intrinsics for a block of source text.
      

  15.   

    自己写一个函数让asm 调用好了
    void* myalloc(size_t len)
    {
    return _alloca(len);
    }
      

  16.   

    to Onega():这种方法对其他函数可行,但对_alloca却是万万不能,因为它是在栈上分配内存,函数返回时,内存也就被释放了,这也是为什么没有与它相对应的释放内存的函数的原因。另外,由于函数返回时,总是要恢复堆栈的,这就是_alloca总被inline的原因,因为作为函数调用,堆栈恢复后等于没有分配任何内存,只有inline才能确保它分配的内存确实可用,这就是楼主得不到_alloca的地址的原因。
      

  17.   

    哎,Visual Studio.NET 2003里面带的跟MSDN网站上的不一样:(
    我今天上网站查了才发现哪个Note...
      

  18.   

    写一个naked function,自己控制是否恢复堆栈
      

  19.   

    __declspec(naked) int __fastcall  power(int i, int j) 
    {
        /* calculates i^j, assumes that j >= 0 */    /* prolog */
        __asm {
            push   ebp
            mov      ebp, esp
            sub      esp, __LOCAL_SIZE
           // store ECX and EDX into stack locations allocated for i and j
            mov   i, ecx
            mov   j, edx
        }
          
        {
            int k=1; // return value
            while (j-- > 0) k *= i;
            __asm { mov eax, k };
        }    /* epilog */
        __asm  
        {
            mov      esp, ebp
            pop      ebp
            ret
        }
    }
      

  20.   

    naked function也不行,编译错误
      

  21.   

    end inline asm statement, call _alloca from C[++], then start
    a new asm statement__asm{
    ...
    ;end asm block , allocate memory by C++
    }
    void* p=_alloca(lenght);
    __asm{
    ;use p in the asm block
    }