[Prev][Next][Index][Thread]

Re: Environment required for minimal libc



Alastair Reid <reid@cs.utah.edu> writes:

> Hi Lars,
> 
> I've been working on improving the componentisation of the OSKit -
> including eliminating the services database and the libc_environment
> and automatically generating initialisation sequences.  The new system
> isn't ready for public release yet but recent oskit releases contain
> the hooks needed to make it work and it should be possible to use
> those same hooks.
> 
> > - oskit_clientos_init failes because it can not allocate memory in
> >   oskit_services_create (com/services.c). Are there other functions
> >   which must be overwritten and do I need oskit_clientos_init at all if 
> >   I just want to use the minimal libc?
> 
> The only bit you really need from clientos is
> clientos/{mem,morecore}.c.  If you compile these with -DCPUNITS, this
> defines a symbol called "oskit_mem_object" (a pointer to a COM
> object).  This needs no initialisation (because the only thing it
> really needs is malloc_lmm which is initialized by multiboot_init
> which is the first thing called by any kernel).
> 
> libc/malloc/*.c normally requires libc_memory_object and
> oskit_library_services_lookup but if you compile it with -DCPUNITS
> all it needs is "libc_memory_object" which should be a pointer to the
> same object that oskit_mem_object points to.  
> 
> You can either arrange to initialise libc_memory_object by running an
> initialiser along the lines of:
> 
>   libc_memory_object = oskit_mem_object;
> 
> but, as you've probably discovered, kernels start allocating memory
> quite early on so it's hard to put the initialization in the right
> place.  A better approach then is to compile clientos/mem.c with
> -Doskit_mem_object=libc_memory_object and let cpp and the linker do
> the rest.  (If this doesn't appeal/work, I can send you a tool for
> renaming symbols in .o files - which is what I normally use.)
> 
> > - oskit_libkern is required to link a program (otherwise, ld misses
> >   oskit_sendsig_init). Can I replace this by a dummy function?
> 
> If you can kill enough of clientos, the ndefined symbol will go away
> (I think).

Thanks for the quick response. This is what I've done now:

- added -DCPUNITS to {clientos,libc}/GNUmakerules
- build my support functions:

  lmm_t malloc_lmm = LMM_INITIALIZER;
  lmm_region_t heap_region;

  void init(unsigned heap_addr, unsigned heap_max_size)
  {	
    /* setup OSKit malloc */
    lmm_add_region(&malloc_lmm,&heap_region,
		   (void *)heap_addr,heap_max_size,0,0);

    /* set libc's memory object */
    libc_memory_object = oskit_mem_object;
  }

  void *oskit_mem_morecore(oskit_size_t size, int flags)
  {
    /* allocate mem pages */
    ...

    return new_addr;
  } 

This seems to work so far. What other initialisations are necessary to 
use the libc, e.g. getopt? 
To give you a bit more background: I want to use the OSKit libc to
build servers wich run as user processes on top of the L4/Fiasco
microkernel. Normally, I only  want to use the libc with a minimal
support environment and only in case I need more OSKit components
(like device drivers) I want to provide a full OS environment. 

Lars

-- 
Dipl.-Inf. Lars Reuther              Dresden University of Technology
Department of Computer Science       Operating Systems Research Group
Phone: +49 (351) 463-8401            Fax: +49 (351) 463-8284
Email: reuther@os.inf.tu-dresden.de