longjmp crashes on Windows
Piotr Podsiadły" <ppodsiadly at mykolab.com>
Piotr Podsiadły" <ppodsiadly at mykolab.com>
Sat Nov 16 06:14:23 PST 2013
Hello,
I'm trying to use setjmp and longjmp on Windows with DMD compiler
(version 2.064). When compiled as 64-bit application, it works,
but 32-bit version crashes inside longjmp. What should be changed
to get it to work?
I tried changing value of _JBLEN for x86 to some bigger number
(like 1024), but it crashes too.
Code:
import std.stdio;
version(Windows)
{
version(X86)
enum _JBLEN = 64;
else version(X86_64)
enum _JBLEN = 256;
else version(IA64)
enum _JBLEN = 528;
alias ubyte[_JBLEN] jmp_buf;
extern(C)
{
int _setjmp(ref jmp_buf _Buf);
void longjmp(ref jmp_buf _Buf, int _Value);
}
alias _setjmp setjmp;
}
void main()
{
jmp_buf env;
uint i;
if(setjmp(env) < 3)
{
writeln("ping");
longjmp(env, ++i);
}
writeln("done");
}
Call stack:
c:\Users\vbox\Documents\test>test.exe
ping
object.Error: Access Violation
----------------
0x00423F78 in _local_unwind
0x004214D0 in longjmp
0x0040B300 in void rt.dmain2._d_run_main(int, char**, extern (C)
int function(char[][])*).runAll().void __lambda1()
0x0040B2D3 in void rt.dmain2._d_run_main(int, char**, extern (C)
int function(char[][])*).runAll()
0x0040B1EB in _d_run_main
0x0040B018 in main
0x0042142D in mainCRTStartup
0x754F3677 in BaseThreadInitThunk
0x77959F42 in RtlInitializeExceptionChain
0x77959F15 in RtlInitializeExceptionChain
----------------
More information about the Digitalmars-d-learn
mailing list