从本机DLL堆栈溢出从托管应用程序调用 [英] Stack overflow from native DLL called from managed application

查看:303
本文介绍了从本机DLL堆栈溢出从托管应用程序调用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是从我的应用程序获得了臭名昭著的 0xC00000FD (堆栈溢出)异常时,我打电话到本机DLL。这是正在从Windows CE 5(SH4处理器)上的托管C#应用程序来完成。编译使用相同的托管应用程序,一切都在同一个DLL的Windows XP工作正常(无溢出)。在DLL的程序是做一些非常复杂的递归这最终是什么原因造成的溢出,但同样,它工作正常的PC上。

I'm getting the infamous 0xC00000FD (stack overflow) exception from my application when I call into a native DLL. This is being done from a managed C# application on Windows CE 5 (SH4 processor). Compiling the same DLL for Windows XP using the same managed application and everything works fine (no overflow). The routine in the DLL is doing some very complex recursion which is ultimately what is causing the overflow, but again, it works fine on a PC.

这似乎是建立DLL时,我可能只需要调整堆栈大小?我相信,这两个CE默认的堆栈大小和XP都是1MB使用Visual C编译器的时候(我使用Visual Studio 2005中,如果该事项)。如果他们都默认为相同的大小,我不知道为什么人们会溢出和其他不会,但是。我试着调整堆栈大小用/ F编译器标志和/ STACK链接器标志,但似乎没有做任何事情。这也并不完全清楚,我认为我可以指定一个DLL的堆栈大小,而在于可执行文件必须设置它。但如果是我会怎么调整我的管理过程调用到本机DLL时使用?堆栈大小的情况下

It seems like I may just need to adjust the stack size when building the DLL? I believe the default stack size for both CE and XP are both 1MB when using the Visual C compiler (I'm using Visual Studio 2005, if that matters). If they both default to the same size, I'm not sure why one would overflow and the other would not, however. I tried adjusting the stack size with the /F compiler flag and the /STACK linker flag but that didn't seem to do anything. It is also not entirely clear to me that I can specify the stack size in a DLL, but rather the executable must set it. But if that is the case how would I adjust the stack size for my managed process to use when calling into the native DLL?

推荐答案

下面是一个链接的的Windows CE的内存架构的讨论。

Here's a link to a discussion of the memory architecture of Windows CE.

最后,很少有你可以做编程,或在编译时调整堆栈大小;基于若干因素,包括存储器可用性操作系统会有所不同的。设置堆栈大小与/ f仅设置可以(并且通常将)被由OS忽略的默认值。和/ F不上一个.DLL工作,无论如何;它只编译可执行文件时的作品。 .DLL文件没有一个堆栈;属于该线程和(最终)的过程。

Ultimately, there is very little you can do to adjust the stack size programmatically or at compile time; the OS will vary it based on a number of factors, including memory availability. Setting stack size with /F only sets a default value that can (and often will) be ignored by the OS. And /F doesn't work on a .DLL, anyway; it only works when compiling the executable. .DLLs don't have a stack; that belongs to the thread and (ultimately) to the process.

这也许是时候回去了绘图板以消除你的递归。

It might be time to go back to the drawing board to remove your recursion.

这篇关于从本机DLL堆栈溢出从托管应用程序调用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆