[U-Boot] early_malloc outline

Wolfgang Denk wd at denx.de
Thu Aug 9 14:35:15 CEST 2012


Dear Graeme Russ,

In message <CALButCK7CxJy6fg8Ym2Ao8tVrD5HTihGWaV+TF8Y9qNe62MnFw at mail.gmail.com> you wrote:
> 
> I pointed out that those pointers can only by in either GD or the early
> malloc heap. But either way, there is no generic way to adjust them. Any
> code that uses the early malloc heap and wants to retain that data for
> use after relocation will need to implement it's own relocation code.
> 
> Having a specific early_malloc() has the advantage of being explicit. The

Yes, and we need this explicity to make sure the caller knows which
behaviour he can expect.  Actually, a standard malloc() should either
work reliably or cause build time errors.

> That was never how I thought about it. Anything that uses the early heap
> needs to 'help' the relocation process. My thought was to make the glue
> logic for the helper as seamless as possible.

I agree with that.

> > Because you cannot track which pointers point into it. They can be
> 
> Yes
> 
> > distributed all over the code.  Any function anybody calls might use
> > malloc() internally, and keep static pointers to allocated data.
> 
> No - There can be no static pointers before relocation - All pointers must
> be in either GD or in structures allocated on the early malloc heap

Thanks for correcting me.  That was what I actually meant - the effect
is the same.

> So to summarise:
>   - Early malloc() needs to be a malloc()

Um... no! malloc() is suposed to behave in  standard way, without any
expectations that pointers to storage retured by malloc() will ever
have to be relocated or such.

For early malloc, a function with a different name shall be used.


Best regards,

Wolfgang Denk

-- 
DENX Software Engineering GmbH,     MD: Wolfgang Denk & Detlev Zundel
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: (+49)-8142-66989-10 Fax: (+49)-8142-66989-80 Email: wd at denx.de
"Nobody will ever need more than 640k RAM!"       -- Bill Gates, 1981
"Windows 95 needs at least 8 MB RAM."             -- Bill Gates, 1996
"Nobody will ever need Windows 95."             -- logical conclusion


More information about the U-Boot mailing list