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

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

问题描述

当我调用本机DLL时,我从应用程序中获取臭名昭着的 0xC00000FD (堆栈溢出)异常。这是从Windows CE 5(SH4处理器)上的托管C#应用程序完成的。使用相同的托管应用程序为Windows XP编译相同的DLL,一切正常(无溢出)。 DLL中的例程正在执行一些非常复杂的递归,这是最终导致溢出的原因,但是再一次,它在PC上正常工作。



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

解决方案

以下是 Windows CE的内存架构讨论的链接



最终,您可以通过编程方式或在编译时调整堆栈大小,操作系统将根据许多因素(包括内存可用性)进行更改。使用/ F设置堆栈大小只能设置一个默认值(通常会被操作系统忽略)。无论如何,/ F不适用于.DLL。它仅在编译可执行文件时有效。 .DLL没有堆栈;属于线程(最终)的过程。



可能要回到绘图板删除您的递归。


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.

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?

解决方案

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

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天全站免登陆