Back to index

glibc  2.9
Functions
init-first.c File Reference
#include <hurd.h>
#include <stdio.h>
#include <unistd.h>
#include <string.h>
#include "hurdstartup.h"
#include "set-hooks.h"
#include "hurdmalloc.h"

Go to the source code of this file.

Functions

void __mach_init (void)
void __init_misc (int, char **, char **)
void _dl_non_dynamic_init (void)
static void * __init (int *data)
 asm ("\ .text\n\ .align 2\n\ init:\n\ subu $29, 32\n\ sw $16, 16($29)\n\ sw $31, 20($29)\n\ move $16, $29\n\ jal __init\n\ lw $31, 20($16)\n\ lw $16, 16($16)\n\ move $29, $2 # set new sp to SP\n\ call_init1:\n\ lw $4, 0($29)\n\ lw $5, 4($29)\n\ lw $6, 8($29)\n\ lw $7, 12($29)\n\ la $25, init1\n\ jr $25\n\ ")
 asm ("\ .text\n\ .align 2\n\ .globl __libc_init_first\n\ __libc_init_first:\n\ subu $29, 4\n\ sw $31, 0($29)\n\ jal __mach_init\n\ lw $4, 0($29)\n\ lw $5, 4($29)\n\ lw $6, 8($29)\n\ lw $7, 12($29)\n\ j ___libc_init_first\n\ ")
static void ___libc_init_first (int return_addr, int argc,...)

Function Documentation

static void ___libc_init_first ( int  return_addr,
int  argc,
  ... 
) [static]

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

{
  void doinit (int *data)
    {
#if 0
      /* This function gets called with the argument data at TOS.  */
      void doinit1 (int argc, ...)
       {
         init (&argc);
       }
#endif
      extern void init (int *data);

      /* 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 `init' with the argument data already on the
        stack.  */
      *--data = return_addr;

#ifdef __mips64
      asm volatile ("ld $31, 0(%0)\n" /* Load the original return address.  */
                  "daddu $29, %0, 8\n" /* Switch to new outermost stack.  */
                  "move $4, $29\n"
                  "jr %1" : : "r" (data), "r" (&init));
#else
      asm volatile ("lw $31, 0(%0)\n" /* Load the original return address.  */
                  "addu $29, %0, 4\n" /* Switch to new outermost stack.  */
                  "move $4, $29\n"
                  "jr %1" : : "r" (data), "r" (&init));
#endif
      /* NOTREACHED */
    }

#if 0
  /* Initialize data structures so we can do RPCs.  */
  __mach_init ();
#endif

  RUN_HOOK (_hurd_preinit_hook, ());

  _hurd_startup ((void **) &argc, &doinit);

  (void) &___libc_init_first;
}

Here is the call graph for this function:

static void* __init ( int data) [static]

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

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

  __environ = envp;
  while (*envp)
    ++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)
    {
      /* Initialize cthreads, which will allocate us a new stack to run on.  */
      void *newsp = (*_cthread_init_routine) ();
      struct hurd_startup_data *od;

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

      /* Set up the Hurd startup data block immediately following
        the argument and environment pointers on the new stack.  */
      od = (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);
      else
       /* 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.  */
      return newsp;
    }

  /* The argument data is just above the stack frame we will unwind by
     returning.  */
  return (void *) data;

  (void) &__init;
}
void __init_misc ( int  ,
char **  ,
char **   
)
void __mach_init ( void  )
void _dl_non_dynamic_init ( void  )

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

{
  char **argv = &arg0;
  char **envp = &argv[argc + 1];
  struct hurd_startup_data *d;

  __libc_argc = argc;
  __libc_argv = argv;
  __environ = envp;
  while (*envp)
    ++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])
    {
      _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 (__hurd_threadvar_stack_mask == 0)
    {
      /* 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 i;
      __hurd_threadvar_stack_offset
       = (unsigned long int) malloc (__hurd_threadvar_max *
                                  sizeof (unsigned long int));
      if (__hurd_threadvar_stack_offset == 0)
       __libc_fatal ("Can't allocate single-threaded per-thread variables.");
      for (i = 0; i < __hurd_threadvar_max; ++i)
       ((unsigned long int *) __hurd_threadvar_stack_offset)[i] = 0;
    }

  if ((void *) d != argv[0] && (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);

#ifndef SHARED
  _dl_non_dynamic_init ();
#endif
  __init_misc (argc, argv, __environ);

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

#ifdef SHARED
  __libc_global_ctors ();
#endif

  (void) &init1;
}
asm ( "\ .text\n\ .align 2\n\init:\n\ subu $  29,
32\n\sw $  16,
16($29)\n\sw $  31,
20($29)\n\move $  16,
$29\n\jal __init\n\lw $  31,
20($16)\n\lw $  16,
16($16)\n\move $  29,
$2#set new sp to SP\n\call_init1:\n\lw $  4,
0($29)\n\lw $  5,
4($29)\n\lw $  6,
8($29)\n\lw $  7,
12($29)\n\la $  25,
init1\n\jr $25\n\"   
)
asm ( "\ .text\n\ .align 2\n\ .globl __libc_init_first\n\__libc_init_first:\n\ subu $  29,
4\n\sw $  31,
0($29)\n\jal __mach_init\n\lw $  4,
0($29)\n\lw $  5,
4($29)\n\lw $  6,
8($29)\n\lw $  7,
12($29)\n\j ___libc_init_first\n\"   
)