[brandz-discuss] Why not using malloc() in brand support libraries?

Edward Pilatowicz edward.pilatowicz at sun.com
Tue Aug 18 21:18:08 PDT 2009


hey nicolay

malloc usage is not really prohibited.

in the lx brand the brand library is linked against libmapmalloc.  so we
use can do malloc allocations and they don't come from the heap.  (we
leave the heap alone for linux processes.)

in the sn1 brand, we also link against libmapmalloc.  theoretically we
should also be able to do memory allocations there.  once again, we
don't do allocations from the heap because we want to leave that alone
so that only the branded processes code is managing that.

that said, most the memory used in both these brands is just on a
per-system call basis,  so for performance reasons most our memory
allocations in all brands are done via alloca().

also, one last thing to consider is that the sn1 and lx brands are very
different.  there are many more restrictions on what the sn1 brand
emulation layer can do vs the lx brand emulation layer.  the reason for
this is that the lx brand allows the branded processes to set a custom
%gs, which is used by libc on solaris and glibc on linux to point to
per-thread metadata and tls.  in the sn1 brand the brand emulation
library and the target processes code share the same %gs data, which
means they share they share the same thread metadata.  so if you're
developing a brand that is substantially different from solaris itself,
then you'll need to do the %gs emulation that the lx brand does, and the
good news is that this will provide you with much more flexibility than
what is available in the sn1 brand.

ed


On Tue, Aug 04, 2009 at 01:14:37AM -0700, Nicolay wrote:
> I've been reading through the available brand sources (sn1 and lx brands) and now I'm wondering why malloc() usage in brand support libraries is prohibited.
>
> I had no opportunity to test it out myself, but probably someone could suggest what will happen if one attempts to malloc() something from the brand support library?
>
> I'm new to OpenSolaris kernel development. But as far as I can tell appropriate internal structure fields for brk() syscall are just zero-initialized in case of exec'ing certain binary types:
>
>                         env.ex_bssbase = (caddr_t)0;
>                         env.ex_brkbase = (caddr_t)0;
>                         env.ex_brksize = 0;
>
> My understanding of the reasons why this is being done is rather limited, so maybe someone will help me out?
>
> Certainly there should be a way to enable malloc() support for brand support library. If so, what should be done to archive this goal?
>
> Any help is greatly appreciated.
> --
> This message posted from opensolaris.org
> _______________________________________________
> brandz-discuss mailing list
> brandz-discuss at opensolaris.org



More information about the brandz-discuss mailing list