[fpc-devel] arm-embedded apps crash in exception handler initialization because heapmanager is not initialized
Florian Klämpfl
florian at freepascal.org
Sun Mar 3 09:52:31 CET 2013
Am 02.03.2013 23:17, schrieb Michael Ring:
> I am not sure if I have hit work in progress code here....
>
> my arm-embedded app crashes during initialization, the reason is that
> now exceptions are part of the rtl but there is no properly initialized
> heapmanager:
>
> Procedure InitExceptions;
> {
> Must install uncaught exception handler (ExceptProc)
> and install exceptions for system exceptions or signals.
> (e.g: SIGSEGV -> ESegFault or so.)
> }
> begin
> ExceptionClass := Exception;
> ExceptProc:=@CatchUnhandledException;
> // Create objects that may have problems when there is no memory.
> //CRASH BOOM BANG in the following line
> OutOfMemory:=EOutOfMemory.Create(SOutOfMemory);
>
>
> Creating the object fails because the MemoryManager is not properly
> initialized yet.
>
> When I put heapmgr unit before sysutils im my program (this should not
> be necesary, right???)
Yes, this is a requirement.
> I can debug a little deeper in object
> initialization but still the root cause exists that there has never been
> a call to RegisterHeapBlock so objects cannot be initiated because
> there's no memory block defined that heapmgr can draw memory from.
>
> I can hack the RegisterHeapBlock call into the initialization code of
> the unit heapmgr but this is more a hack than a proper solution -->
> seems a bad idea to me.
>
> How can this be properly solved?
I think allocating a small block (128 bytes for arm?) during the start
up of heapmgr should be fine?
var
InitialBlock: array[0..255] of byte;
...
RegisterHeapBlock(@InitialBlock,sizeof(InitialBlock));
If one includes heapmgr he wants to use the heap after all.
More information about the fpc-devel
mailing list