Forum > General
CryptLib + SigSev (Runtime error 216) on program exit
KennethH:
Hi all...
Let me preface this with "I have an acceptable work-around"...
I am linking to CryptLib in a rather complex program that is throwing a mysterious run-time error on exit. After much stripping down, here is the MOST simple code that will throw the error:
--- Code: Pascal [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---program Test; function cryptInit: Integer; stdcall; external 'CL64.DLL';function cryptEnd: Integer; stdcall; external 'CL64.DLL'; begin if cryptInit = 0 then Writeln('Init!'); cryptEnd; Writeln('Complete'); end.
This code runs fine in Windows 10 but throws the error on Windows 2012 Server R2.
Notes:
* Compiled on FPC 3.04 and on FPC 3.2.2, as I read on this forum 3.0.4 has a bug that can cause this
* Error only on that one OS. SAME code and SAME DLL work in Windows 10
* Works fine in 2012 when compiled in 32-bit mode
Question to the forum: Am I missing any obvious compiler options that would help debug this? I've tried {$S+} and {$INLINE OFF}
--- Quote from: DebugLog ---=library-loaded,id="C:\\Windows\\SYSTEM32\\cryptbase.dll",target-name="C:\\Windows\\SYSTEM32\\cryptbase.dll",host-name="C:\\Windows\\SYSTEM32\\cryptbase.dll",symbols-loaded="0",thread-group="i1"
=library-loaded,id="C:\\Windows\\SYSTEM32\\bcryptprimitives.dll",target-name="C:\\Windows\\SYSTEM32\\bcryptprimitives.dll",host-name="C:\\Windows\\SYSTEM32\\bcryptprimitives.dll",symbols-loaded="0",thread-group="i1"
=library-loaded,id="C:\\Windows\\SYSTEM32\\cryptsp.dll",target-name="C:\\Windows\\SYSTEM32\\cryptsp.dll",host-name="C:\\Windows\\SYSTEM32\\cryptsp.dll",symbols-loaded="0",thread-group="i1"
=library-loaded,id="C:\\Windows\\system32\\shell32.dll",target-name="C:\\Windows\\system32\\shell32.dll",host-name="C:\\Windows\\system32\\shell32.dll",symbols-loaded="0",thread-group="i1"
=library-loaded,id="C:\\Windows\\system32\\shlwapi.dll",target-name="C:\\Windows\\system32\\shlwapi.dll",host-name="C:\\Windows\\system32\\shlwapi.dll",symbols-loaded="0",thread-group="i1"
=library-loaded,id="C:\\Windows\\SYSTEM32\\SHCore.dll",target-name="C:\\Windows\\SYSTEM32\\SHCore.dll",host-name="C:\\Windows\\SYSTEM32\\SHCore.dll",symbols-loaded="0",thread-group="i1"
=library-loaded,id="C:\\Windows\\SYSTEM32\\profapi.dll",target-name="C:\\Windows\\SYSTEM32\\profapi.dll",host-name="C:\\Windows\\SYSTEM32\\profapi.dll",symbols-loaded="0",thread-group="i1"
=thread-created,id="2",group-id="i1"
~"[New Thread 5380.0x27ac]\n"
*running,thread-id="all"
=thread-exited,id="2",group-id="i1"
*stopped,reason="signal-received",signal-name="SIGSEGV",signal-meaning="Segmentation fault",frame={addr="0x0000000000000000",func="??",args=[]},thread-id="1",stopped-threads="all"
(gdb)
<info program>
&"info program\n"
~"\tUsing the running image of child Thread 5380.0x2718.\n"
~"Program stopped at 0x0.\n"
~"It stopped with signal SIGSEGV, Segmentation fault.\n"
--- End quote ---
===WORK AROUND===
The following code does NOT throw the error. Because there was no change in the DLL, it leads me to search for the problem in FPC-side, not the within the DLL
--- Code: Pascal [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---program Test; uses Windows; type CFunction = function: Integer; stdcall; var cryptInit, cryptEnd: CFunction; H: THandle;begin H := LoadLibrary('CL64.DLL'); cryptInit := CFunction(GetProcAddress(H, 'cryptInit')); cryptEnd := CFunction(GetProcAddress(H, 'cryptEnd')); if cryptInit() = 0 then Writeln('Init!'); cryptEnd(); FreeLibrary(H); Writeln('Complete'); end.
I consider this an acceptable work-around but the programmer in me cannot let this go. Any help on compiler directives appreciated
KennethH:
Note that I do not 100% rule out an error in the DLL.
For example, in cryptlib.pas that comes from their site, we see:
--- Code: Pascal [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---const {$IFDEF WIN32} cryptlibname = 'CL32.DLL'; { dynamic linkname for Windows (Delphi) } {$ELSE} cryptlibname = 'libcl.so'; { library name for Unix/Linux (Kylix) } { symbolic link should be used for libcl.so -> libcl.so.3.x.y } {$ENDIF} function cryptInit: Integer;{$IFDEF WIN32} stdcall; {$ELSE} cdecl; {$ENDIF} external cryptlibname; function cryptEnd: Integer;{$IFDEF WIN32} stdcall; {$ELSE} cdecl; {$ENDIF} external cryptlibname;
which does not play nicely in WIN64. So I had to make some corrections to their lib just to get it to run in Win10. I'm poking at the code right now in Visual Studio to see if I can spot other problem spots.
jamie:
Try appending the "name" at the end.
Fascal is not a case sensitive language. But u can specify the real name at the end.
......name 'theName'
U can even use index if u know it.
KennethH:
--- Quote from: jamie on January 30, 2023, 06:11:36 pm ---Try appending the "name" at the end.
Fascal is not a case sensitive language. But u can specify the real name at the end.
......name 'theName'
U can even use index if u know it.
--- End quote ---
Thank you, however still no-go
--- Code: Pascal [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---program Test; function cryptInit: Integer; stdcall; external 'CL64.DLL' name 'cryptInit';function cryptEnd: Integer; stdcall; external 'CL64.DLL' name 'cryptEnd'; begin if cryptInit = 0 then Writeln('Init!'); cryptEnd; Writeln('Complete'); end.
--- Quote from: Output ---Init!
Complete
Runtime error 216 at $0000000000000000
$0000000000000000
$00007FFDB166909A
$00007FFDB16B381B
$00007FFDD590C414
$00007FFDD590B822
$00007FFDD59084F8
$00007FFDD5114F8A
$0000000100007F0B
$000000010000383F
$000000010000162D
$0000000100001646
$0000000100007F70
$00000001000015A0
$00007FFDD5111412
$00007FFDD5905504
--- End quote ---
jamie:
Looks like u r in 64bit mode.?
R u sure that is a 32bit dll?
I meant 64 bit
Navigation
[0] Message Index
[#] Next page