longjmp crashes on Windows
Maxim Fomin
maxim at maxim-fomin.ru
Sat Nov 16 06:41:45 PST 2013
On Saturday, 16 November 2013 at 14:14:24 UTC, Piotr Podsiadły
wrote:
> 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;
> }
What kind of problem you try to solve by manual defining system
data structures? Why not use platform independent valid
declarations? Why did you decide that _JBLEN is 64, 256, 528
according to version? Why did you decide that having _JBLEN bytes
filled with zeros is a valid value of jmp_buf object? Why should
setjmp/longjmp take buffer by reference?
> 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
> ----------------
Try to use proper version of setjmp/jmp_buf from druntime.
By the way, why did you decide to use it in D language in a first
place?
More information about the Digitalmars-d-learn
mailing list