Simple solutions are the best ;-) Thanks for opening my eyes to this easy approach.
I have created a patch for heapmgr.pp, could I ask you to commit it to svn?
For a little more flexible solution I would like to ask you one more questions, it may seem dumb to you but I have never been that deep into a compiler before so I am learning a lot atm.
I can see that the compiler param -Ch can be used to define the heapsize, I can also see in the assembler code of my main program that when I set -Ch I also get a section:
-Ch2048 results in this:
.section .data.n___heapsize
.balign 4
.globl __heapsize
__heapsize:
.long 2048
but I do not seem to be able to access __heapsize in my code, how could I use this information to make the heapsize configurable?
and, it is (as far as I understand) a must to include heapmgr in the code because if not the program will always die on startup because of the object created in Exception class, where would be the right place to do this?
Yes, I can put heapmgr as the first unit included in my main program, but wouldn't it be better to put it in some global initialization loop, like the VariantManager, which always gets initialized without me triggering this in any way.
Michael
Index: rtl/embedded/heapmgr.pp
=================================================================== --- rtl/embedded/heapmgr.pp (revision 23681)
+++ rtl/embedded/heapmgr.pp (working copy)
@@ -34,6 +34,7 @@
var
Blocks: PHeapBlock = nil;
+ InitialBlock: array[0..255] of byte;
procedure InternalFreeMem(Addr: Pointer; Size: ptruint); forward;
@@ -242,6 +243,7 @@
initialization
SetMemoryManager(MyMemoryManager);
+ RegisterHeapBlock(@InitialBlock,sizeof(InitialBlock));
finalization
//FinalizeHeap;
end.
Florian Klämpfl wrote 53 lines
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;
> ;
> // 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.
_______________________________________________
fpc-devel maillist -
http://lists.freepascal.org/mailman/listinfo/fpc-devel