Stack overflow from native DLL called from managed application

 ̄綄美尐妖づ 提交于 2019-12-10 17:34:48

问题


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?


回答1:


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.



来源:https://stackoverflow.com/questions/732054/stack-overflow-from-native-dll-called-from-managed-application

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!