Back to index

glibc  2.9
Classes | Defines | Functions | Variables
dl-error.c File Reference
#include <libintl.h>
#include <setjmp.h>
#include <stdbool.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <ldsodefs.h>
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  catch

Defines

#define CATCH_HOOK   catch_hook

Functions

void internal_function _dl_signal_error (int errcode, const char *objname, const char *occation, const char *errstring)
void internal_function _dl_signal_cerror (int errcode, const char *objname, const char *occation, const char *errstring)
int internal_function _dl_catch_error (const char **objname, const char **errstring, bool *mallocedp, void(*operate)(void *), void *args)
void internal_function _dl_receive_error (receiver_fct fct, void(*operate)(void *), void *args)

Variables

static const char _dl_out_of_memory [] = "out of memory"
static receiver_fct receiver
static struct catchcatch_hook

Class Documentation

struct catch

Definition at line 30 of file dl-error.c.

Class Members
jmp_buf env
const char * errstring
bool malloced
const char * objname

Define Documentation

#define CATCH_HOOK   catch_hook

Definition at line 66 of file dl-error.c.


Function Documentation

int internal_function _dl_catch_error ( const char **  objname,
const char **  errstring,
bool *  mallocedp,
void(*)(void *)  operate,
void *  args 
)

Definition at line 158 of file dl-error.c.

{
  int errcode;
  struct catch *volatile old;
  struct catch c;
  /* We need not handle `receiver' since setting a `catch' is handled
     before it.  */

  /* Some systems (e.g., SPARC) handle constructors to local variables
     inefficient.  So we initialize `c' by hand.  */
  c.errstring = NULL;

  struct catch **const catchp = &CATCH_HOOK;
  old = *catchp;
  /* Do not save the signal mask.  */
  errcode = __sigsetjmp (c.env, 0);
  if (__builtin_expect (errcode, 0) == 0)
    {
      *catchp = &c;
      (*operate) (args);
      *catchp = old;
      *objname = NULL;
      *errstring = NULL;
      *mallocedp = false;
      return 0;
    }

  /* We get here only if we longjmp'd out of OPERATE.  */
  *catchp = old;
  *objname = c.objname;
  *errstring = c.errstring;
  *mallocedp = c.malloced;
  return errcode == -1 ? 0 : errcode;
}

Here is the call graph for this function:

Here is the caller graph for this function:

void internal_function _dl_receive_error ( receiver_fct  fct,
void(*)(void *)  operate,
void *  args 
)

Definition at line 197 of file dl-error.c.

{
  struct catch **const catchp = &CATCH_HOOK;
  struct catch *old_catch;
  receiver_fct old_receiver;

  old_catch = *catchp;
  old_receiver = receiver;

  /* Set the new values.  */
  *catchp = NULL;
  receiver = fct;

  (*operate) (args);

  *catchp = old_catch;
  receiver = old_receiver;
}

Here is the call graph for this function:

void internal_function _dl_signal_cerror ( int  errcode,
const char *  objname,
const char *  occation,
const char *  errstring 
)

Definition at line 136 of file dl-error.c.

{
  if (__builtin_expect (GLRO(dl_debug_mask)
                     & ~(DL_DEBUG_STATISTICS|DL_DEBUG_PRELINK), 0))
    _dl_debug_printf ("%s: error: %s: %s (%s)\n", objname, occation,
                    errstring, receiver ? "continued" : "fatal");

  if (receiver)
    {
      /* We are inside _dl_receive_error.  Call the user supplied
        handler and resume the work.  The receiver will still be
        installed.  */
      (*receiver) (errcode, objname, errstring);
    }
  else
    _dl_signal_error (errcode, objname, occation, errstring);
}

Here is the call graph for this function:

Here is the caller graph for this function:

void internal_function _dl_signal_error ( int  errcode,
const char *  objname,
const char *  occation,
const char *  errstring 
)

Definition at line 71 of file dl-error.c.

{
  struct catch *lcatch;

  if (! errstring)
    errstring = N_("DYNAMIC LINKER BUG!!!");

  lcatch = CATCH_HOOK;
  if (objname == NULL)
    objname = "";
  if (lcatch != NULL)
    {
      /* We are inside _dl_catch_error.  Return to it.  We have to
        duplicate the error string since it might be allocated on the
        stack.  The object name is always a string constant.  */
      size_t len_objname = strlen (objname) + 1;
      size_t len_errstring = strlen (errstring) + 1;

      lcatch->errstring = (char *) malloc (len_objname + len_errstring);
      if (lcatch->errstring != NULL)
       {
         /* Make a copy of the object file name and the error string.  */
         lcatch->objname = memcpy (__mempcpy ((char *) lcatch->errstring,
                                          errstring, len_errstring),
                                objname, len_objname);

         /* If the main executable is relocated it means the libc's malloc
            is used.  */
#ifdef SHARED
         lcatch->malloced = (GL(dl_ns)[LM_ID_BASE]._ns_loaded != NULL
                           && (GL(dl_ns)[LM_ID_BASE]._ns_loaded->l_relocated
                              != 0));
#else
         lcatch->malloced = true;
#endif
       }
      else
       {
         /* This is better than nothing.  */
         lcatch->objname = "";
         lcatch->errstring = _dl_out_of_memory;
         lcatch->malloced = false;
       }
      /* We do not restore the signal mask because none was saved.  */
      __longjmp (lcatch->env[0].__jmpbuf, errcode ?: -1);
    }
  else
    {
      /* Lossage while resolving the program's own symbols is always fatal.  */
      char buffer[1024];
      _dl_fatal_printf ("%s: %s: %s%s%s%s%s\n",
                     rtld_progname ?: "<program name unknown>",
                     occation ?: N_("error while loading shared libraries"),
                     objname, *objname ? ": " : "",
                     errstring, errcode ? ": " : "",
                     (errcode
                      ? __strerror_r (errcode, buffer, sizeof buffer)
                      : ""));
    }
}

Here is the call graph for this function:

Here is the caller graph for this function:


Variable Documentation

const char _dl_out_of_memory[] = "out of memory" [static]

Definition at line 50 of file dl-error.c.

struct catch* catch_hook [static]

Definition at line 65 of file dl-error.c.

Definition at line 60 of file dl-error.c.