Back to index

glibc  2.9
init-first.c File Reference
#include <assert.h>
#include <hurd.h>
#include <stdio.h>
#include <unistd.h>
#include <string.h>
#include <sysdep.h>
#include <set-hooks.h>
#include "hurdstartup.h"
#include "hurdmalloc.h"
#include "../locale/localeinfo.h"
#include <ldsodefs.h>
#include <fpu_control.h>

Go to the source code of this file.


void __mach_init (void)
void __init_misc (int, char **, char **)
void _dl_non_dynamic_init (void)
static void init1 (int argc, char *arg0,...)
static void init (int *data)
 asm ("switch_stacks:\n"" movl %eax, %esp\n"" jmp *%ecx")
 asm ("call_init1:\n"" push %eax\n"" jmp *%ecx\n")
static void first_init (void)
 strong_alias (posixland_init, __libc_init_first)
void _hurd_stack_setup (void)
void _dl_start (void)

Function Documentation

void __init_misc ( int  ,
char **  ,
char **   
void __mach_init ( void  )
void _dl_non_dynamic_init ( void  )

Definition at line 41 of file init-first.c.

  __libc_multiple_libcs = &_dl_starting_up && !_dl_starting_up;

  /* Make sure we don't initialize twice.  */
  if (!__libc_multiple_libcs)
      /* Set the FPU control word to the proper default value.  */
      __setfpucw (__fpu_control);

  /* Save the command-line arguments.  */
  __libc_argc = argc;
  __libc_argv = argv;
  __environ = envp;

#ifndef SHARED
  _dl_non_dynamic_init ();
  __init_misc (argc, argv, envp);

  /* This is a hack to make the special getopt in GNU libc working.  */
  __getopt_clean_environment (envp);

#ifdef SHARED
  __libc_global_ctors ();
void _dl_start ( void  )

Definition at line 390 of file init-first.c.

  abort ();

Here is the call graph for this function:

void _hurd_stack_setup ( void  )

Definition at line 354 of file init-first.c.

  intptr_t caller = (intptr_t) __builtin_return_address (0);

  void doinit (intptr_t *data)
      /* This function gets called with the argument data at TOS.  */
      void doinit1 (void)
         init ((int *) __builtin_frame_address (0) + 2);

      /* Push the user return address after the argument data, and then
         jump to `doinit1' (above), so it is as if __libc_init_first's
         caller had called `doinit1' with the argument data already on the
         stack.  */
      *--data = caller;
      asm volatile ("movl %0, %%esp\n" /* Switch to new outermost stack.  */
                  "movl $0, %%ebp\n" /* Clear outermost frame pointer.  */
                  "jmp *%1" : : "r" (data), "r" (&doinit1) : "sp");
      /* NOTREACHED */

  first_init ();

  _hurd_startup ((void **) __builtin_frame_address (0) + 2, &doinit);

Here is the call graph for this function:

asm ( "switch_stacks:\n"" movl %  eax,
%esp\n""jmp *%ecx"   
asm ( "call_init1:\n"" push %eax\n"" jmp *%ecx\n )
static void first_init ( void  ) [inline, static]

Definition at line 308 of file init-first.c.

  /* Initialize data structures so we can do RPCs.  */
  __mach_init ();

  RUN_HOOK (_hurd_preinit_hook, ());

Here is the call graph for this function:

Here is the caller graph for this function:

static void init ( int data) [inline, static]

Definition at line 168 of file init-first.c.

  int argc = *data;
  char **argv = (void *) (data + 1);
  char **envp = &argv[argc + 1];
  struct hurd_startup_data *d;
  unsigned long int threadvars[_HURD_THREADVAR_MAX];

  /* Provide temporary storage for thread-specific variables on the
     startup stack so the cthreads initialization code can use them
     for malloc et al, or so we can use malloc below for the real
     threadvars array.  */
  memset (threadvars, 0, sizeof threadvars);
  threadvars[_HURD_THREADVAR_LOCALE] = (unsigned long int) &_nl_global_locale;
  __hurd_threadvar_stack_offset = (unsigned long int) threadvars;

  /* Since the cthreads initialization code uses malloc, and the
     malloc initialization code needs to get at the environment, make
     sure we can find it.  We'll need to do this again later on since
     switching stacks changes the location where the environment is
     stored.  */
  __environ = envp;

  while (*envp)
  d = (void *) ++envp;

  /* The user might have defined a value for this, to get more variables.
     Otherwise it will be zero on startup.  We must make sure it is set
     properly before before cthreads initialization, so cthreads can know
     how much space to leave for thread variables.  */
  if (__hurd_threadvar_max < _HURD_THREADVAR_MAX)
    __hurd_threadvar_max = _HURD_THREADVAR_MAX;

  /* After possibly switching stacks, call `init1' (above) with the user
     code as the return address, and the argument data immediately above
     that on the stack.  */

  if (&_cthread_init_routine && _cthread_init_routine)
      /* Initialize cthreads, which will allocate us a new stack to run on.  */
      int *newsp = (*_cthread_init_routine) ();
      struct hurd_startup_data *od;

      void switch_stacks (void);

      /* Copy per-thread variables from that temporary
        area onto the new cthread stack.  */
      memcpy (__hurd_threadvar_location_from_sp (0, newsp),
             threadvars, sizeof threadvars);

      /* Copy the argdata from the old stack to the new one.  */
      newsp = memcpy (newsp - ((char *) &d[1] - (char *) data), data,
                    (char *) d - (char *) data);

#ifdef SHARED
      /* And readjust the dynamic linker's idea of where the argument
         vector lives.  */
      assert (_dl_argv == argv);
      _dl_argv = (void *) (newsp + 1);

      /* Set up the Hurd startup data block immediately following
        the argument and environment pointers on the new stack.  */
      od = ((void *) newsp + ((char *) d - (char *) data));
      if ((void *) argv[0] == d)
       /* We were started up by the kernel with arguments on the stack.
          There is no Hurd startup data, so zero the block.  */
       memset (od, 0, sizeof *od);
       /* Copy the Hurd startup data block to the new stack.  */
       *od = *d;

      /* Push the user code address on the top of the new stack.  It will
        be the return address for `init1'; we will jump there with NEWSP
        as the stack pointer.  */
      *--newsp = data[-1];
      ((void **) data)[-1] = switch_stacks;
      /* Force NEWSP into %ecx and &init1 into %eax, which are not restored
        by function return.  */
      asm volatile ("# a %0 c %1" : : "a" (newsp), "c" (&init1));
      /* We are not using cthreads, so we will have just a single allocated
        area for the per-thread variables of the main user thread.  */
      unsigned long int *array;
      unsigned int i;
      int usercode;

      void call_init1 (void);

      array = malloc (__hurd_threadvar_max * sizeof (unsigned long int));
      if (array == NULL)
       __libc_fatal ("Can't allocate single-threaded thread variables.");

      /* Copy per-thread variables from the temporary array into the
        newly malloc'd space.  */
      memcpy (array, threadvars, sizeof threadvars);
      __hurd_threadvar_stack_offset = (unsigned long int) array;
      for (i = _HURD_THREADVAR_MAX; i < __hurd_threadvar_max; ++i)
       array[i] = 0;

      /* The argument data is just above the stack frame we will unwind by
        returning.  Mutate our own return address to run the code below.  */
      usercode = data[-1];
      data[-1] = (int) &call_init1;
      /* Force USERCODE into %eax and &init1 into %ecx, which are not
        restored by function return.  */
      asm volatile ("# a %0 c %1" : : "a" (usercode), "c" (&init1));

Here is the call graph for this function:

static void init1 ( int  argc,
char *  arg0,
) [static]

Definition at line 102 of file init-first.c.

  char **argv = &arg0;
  char **envp = &argv[argc + 1];
  struct hurd_startup_data *d;
#ifndef SHARED
  extern ElfW(Phdr) *_dl_phdr;
  extern size_t _dl_phnum;

  while (*envp)
  d = (void *) ++envp;

  /* If we are the bootstrap task started by the kernel,
     then after the environment pointers there is no Hurd
     data block; the argument strings start there.  */
  if ((void *) d == argv[0])
#ifndef SHARED
      /* We may need to see our own phdrs, e.g. for TLS setup.
         Try the usual kludge to find the headers without help from
        the exec server.  */
      extern const void _start;
      const ElfW(Ehdr) *const ehdr = &_start;
      _dl_phdr = (ElfW(Phdr) *) ((const void *) ehdr + ehdr->e_phoff);
      _dl_phnum = ehdr->e_phnum;
      assert (ehdr->e_phentsize == sizeof (ElfW(Phdr)));

#ifndef SHARED
  __libc_enable_secure = d->flags & EXEC_SECURE;

  _dl_phdr = (ElfW(Phdr) *) d->phdr;
  _dl_phnum = d->phdrsz / sizeof (ElfW(Phdr));
  assert (d->phdrsz % sizeof (ElfW(Phdr)) == 0);

  _hurd_init_dtable = d->dtable;
  _hurd_init_dtablesize = d->dtablesize;

    /* Check if the stack we are now on is different from
       the one described by _hurd_stack_{base,size}.  */

    char dummy;
    const vm_address_t newsp = (vm_address_t) &dummy;

    if (d->stack_size != 0 && (newsp < d->stack_base ||
                            newsp - d->stack_base > d->stack_size))
      /* The new stack pointer does not intersect with the
        stack the exec server set up for us, so free that stack.  */
      __vm_deallocate (__mach_task_self (), d->stack_base, d->stack_size);

  if (d->portarray || d->intarray)
    /* Initialize library data structures, start signal processing, etc.  */
    _hurd_init (d->flags, argv,
              d->portarray, d->portarraysize,
              d->intarray, d->intarraysize);

Here is the call graph for this function:

Here is the caller graph for this function:

strong_alias ( posixland_init  ,