#1 Re: mORMot 1 » TSynLog automatic handling exceptions and SafeLoadLibrary problem » 2017-05-11 11:29:04

Thank you for quick reply.
I use Delphi 10 Seatle (Win32).
Here is example based on sample 11 - Exception logging
example program code (LibraryTest - procedure Test dynamically linked) - https://pastebin.com/g5yCSLWH
example library code (MyLibrary  - procedure Test only raise exception) - https://pastebin.com/4yzGmz7p
You can see what is happening watching address RtlUnwindProc.
After TSynLog.Family.Level := LOG_VERBOSE; there is a change -> RtlUnwindProc is set (RTLUnwindProc := @SynRtlUnwind;)
After SafeLoadLibrary RtlUnWindProc is restored to orginal address
(SaveLoadLibrary System.pas -> _StartLib ->
  version CPUX86
        MOV     EAX, offset RaiseException
        MOV     RaiseExceptionProc, EAX
        MOV     EAX, offset RTLUnwind
        MOV     RTLUnwindProc, EAX
  version CPUX64  -> not assembler so more readable (for me)
  // Setup exception handler
  RaiseExceptionProc := @RaiseException;
  RTLUnwindProc := @RTLUnwind;
)
Procedure statically linked (procedure Test; external 'MyLibrary.dll';) is working because
library is loaded first and then after TSynLog.Family.Level := LOG_VERBOSE; address is already setup correctly.

Another issue is how to use TSynLog, what is the best practise.
I'dont want add duplicatiing code (SynCommons, SynLog) to program and every dll so I built package mormot.bpl with SynCommons, SynLog and used it like runtime package in my program and dll.
It works ok. But in such case there is problem with locating map files. TSynMapFile uses fMapFile := GetModuleName(hInstance); and finding mormot.bpl instead exe or dll name.

#2 mORMot 1 » TSynLog automatic handling exceptions and SafeLoadLibrary problem » 2017-05-10 14:01:22

mduch
Replies: 5

I have application build with many dynamic loaded modules (dll). (loaded on need)
I tested TSynLog and discovered that after using SafeLoadLibrary automatic handling of exceptions doesn't work.
It happens because of overwriting RtlUnwindProc by SafeLoadLibrary -> _StartLib  (System.pas).
So using TSynLog.Family.Level:= LOG_VERBOSE in begining of program setup RtlUnwindProc and SafeLoadLibrary restore orginal RtlUnwind.

Is it possible to use TSynLog with automatic handling of exception in application which is using dynamic loading libraries ?

Board footer

Powered by FluxBB