Back to index

glibc  2.9
Defines | Functions | Variables
dl-minimal.c File Reference
#include <errno.h>
#include <limits.h>
#include <string.h>
#include <tls.h>
#include <unistd.h>
#include <sys/mman.h>
#include <sys/param.h>
#include <sys/types.h>
#include <ldsodefs.h>
#include <stdio-common/_itoa.h>
#include <assert.h>
#include <setjmp.h>

Go to the source code of this file.

Defines

#define MAP_ANON   0
#define HALF_SIZE_T   (((size_t) 1) << (8 * sizeof (size_t) / 2))

Functions

void weak_function free (void *ptr)
void *weak_function realloc (void *ptr, size_t n)
unsigned long int weak_function __strtoul_internal (const char *nptr, char **endptr, int base, int group)
unsigned long int weak_function strtoul (const char *nptr, char **endptr, int base)
void *weak_function __libc_memalign (size_t align, size_t n)
void *weak_function malloc (size_t n)
void *weak_function calloc (size_t nmemb, size_t size)
int weak_function __sigjmp_save (sigjmp_buf env, int savemask __attribute__((unused)))
char *weak_function __strerror_r (int errnum, char *buf, size_t buflen)
void weak_function __assert_fail (const char *assertion, const char *file, unsigned int line, const char *function)
 rtld_hidden_weak (__assert_fail)
 rtld_hidden_weak (__assert_perror_fail)
char * _itoa (unsigned long long int value, char *buflim, unsigned int base, int upper_case)
char * __strsep (char **stringp, const char *delim)
 weak_alias (strong_alias(__strsep, strsep)

Variables

static void * alloc_ptr
static void * alloc_end
static void * alloc_last_block

Define Documentation

#define HALF_SIZE_T   (((size_t) 1) << (8 * sizeof (size_t) / 2))
#define MAP_ANON   0

Function Documentation

void weak_function __assert_fail ( const char *  assertion,
const char *  file,
unsigned int  line,
const char *  function 
)

Definition at line 215 of file dl-minimal.c.

{
  _dl_fatal_printf ("\
Inconsistency detected by ld.so: %s: %u: %s%sAssertion `%s' failed!\n",
                  file, line, function ?: "", function ? ": " : "",
                  assertion);

}
void* weak_function __libc_memalign ( size_t  align,
size_t  n 
)

Definition at line 52 of file dl-minimal.c.

{
#ifdef MAP_ANON
#define       _dl_zerofd (-1)
#else
  extern int _dl_zerofd;

  if (_dl_zerofd == -1)
    _dl_zerofd = _dl_sysdep_open_zero_fill ();
#define MAP_ANON 0
#endif

  if (alloc_end == 0)
    {
      /* Consume any unused space in the last page of our data segment.  */
      extern int _end attribute_hidden;
      alloc_ptr = &_end;
      alloc_end = (void *) 0 + (((alloc_ptr - (void *) 0)
                             + GLRO(dl_pagesize) - 1)
                            & ~(GLRO(dl_pagesize) - 1));
    }

  /* Make sure the allocation pointer is ideally aligned.  */
  alloc_ptr = (void *) 0 + (((alloc_ptr - (void *) 0) + align - 1)
                         & ~(align - 1));

  if (alloc_ptr + n >= alloc_end || n >= -(uintptr_t) alloc_ptr)
    {
      /* Insufficient space left; allocate another page.  */
      caddr_t page;
      size_t nup = (n + GLRO(dl_pagesize) - 1) & ~(GLRO(dl_pagesize) - 1);
      if (__builtin_expect (nup == 0, 0))
       {
         if (n)
           return NULL;
         nup = GLRO(dl_pagesize);
       }
      page = __mmap (0, nup, PROT_READ|PROT_WRITE,
                   MAP_ANON|MAP_PRIVATE, _dl_zerofd, 0);
      if (page == MAP_FAILED)
       return NULL;
      if (page != alloc_end)
       alloc_ptr = page;
      alloc_end = page + nup;
    }

  alloc_last_block = (void *) alloc_ptr;
  alloc_ptr += n;
  return alloc_last_block;
}

Here is the call graph for this function:

Here is the caller graph for this function:

int weak_function __sigjmp_save ( sigjmp_buf  env,
int savemask   __attribute__(unused) 
)

Definition at line 160 of file dl-minimal.c.

{
  env[0].__mask_was_saved = 0;
  return 0;
}

Here is the caller graph for this function:

char* weak_function __strerror_r ( int  errnum,
char *  buf,
size_t  buflen 
)

Definition at line 171 of file dl-minimal.c.

{
  char *msg;

  switch (errnum)
    {
    case ENOMEM:
      msg = (char *) "Cannot allocate memory";
      break;
    case EINVAL:
      msg = (char *) "Invalid argument";
      break;
    case ENOENT:
      msg = (char *) "No such file or directory";
      break;
    case EPERM:
      msg = (char *) "Operation not permitted";
      break;
    case EIO:
      msg = (char *) "Input/output error";
      break;
    case EACCES:
      msg = (char *) "Permission denied";
      break;
    default:
      /* No need to check buffer size, all calls in the dynamic linker
        provide enough space.  */
      buf[buflen - 1] = '\0';
      msg = _itoa (errnum, buf + buflen - 1, 10, 0);
      msg = memcpy (msg - (sizeof ("Error ") - 1), "Error ",
                  sizeof ("Error ") - 1);
      break;
    }

  return msg;
}
char* __strsep ( char **  stringp,
const char *  delim 
)

Definition at line 329 of file dl-minimal.c.

{
  char *begin;

  assert (delim[0] != '\0');

  begin = *stringp;
  if (begin != NULL)
    {
      char *end = begin;

      while (*end != '\0' || (end = NULL))
       {
         const char *dp = delim;

         do
           if (*dp == *end)
             break;
         while (*++dp != '\0');

         if (*dp != '\0')
           {
             *end++ = '\0';
             break;
           }

         ++end;
       }

      *stringp = end;
    }

  return begin;
}
unsigned long int weak_function __strtoul_internal ( const char *  nptr,
char **  endptr,
int  base,
int  group 
)

Here is the caller graph for this function:

char* _itoa ( unsigned long long int  value,
char *  buflim,
unsigned int  base,
int  upper_case 
)

Definition at line 305 of file dl-minimal.c.

{
  extern const char INTUSE(_itoa_lower_digits)[] attribute_hidden;

  assert (! upper_case);

  do
    *--buflim = INTUSE(_itoa_lower_digits)[value % base];
  while ((value /= base) != 0);

  return buflim;
}
void* weak_function calloc ( size_t  nmemb,
size_t  size 
)

Definition at line 113 of file dl-minimal.c.

{
  /* New memory from the trivial malloc above is always already cleared.
     (We make sure that's true in the rare occasion it might not be,
     by clearing memory in free, below.)  */
  size_t bytes = nmemb * size;

#define HALF_SIZE_T (((size_t) 1) << (8 * sizeof (size_t) / 2))
  if (__builtin_expect ((nmemb | size) >= HALF_SIZE_T, 0)
      && size != 0 && bytes / size != nmemb)
    return NULL;

  return malloc (bytes);
}
void weak_function free ( void *  ptr)

Definition at line 130 of file dl-minimal.c.

{
  /* We can free only the last block allocated.  */
  if (ptr == alloc_last_block)
    {
      /* Since this is rare, we clear the freed block here
        so that calloc can presume malloc returns cleared memory.  */
      memset (alloc_last_block, '\0', alloc_ptr - alloc_last_block);
      alloc_ptr = alloc_last_block;
    }
}
void* weak_function malloc ( size_t  n)

Definition at line 104 of file dl-minimal.c.

{
  return __libc_memalign (sizeof (double), n);
}
void *weak_function realloc ( void *  ptr,
size_t  n 
)

Definition at line 144 of file dl-minimal.c.

{
  if (ptr == NULL)
    return malloc (n);
  assert (ptr == alloc_last_block);
  size_t old_size = alloc_ptr - alloc_last_block;
  alloc_ptr = alloc_last_block;
  void *new = malloc (n);
  return new != ptr ? memcpy (new, ptr, old_size) : new;
}

Definition at line 224 of file dl-minimal.c.

{
  char errbuf[400];
  _dl_fatal_printf ("\
Inconsistency detected by ld.so: %s: %u: %s%sUnexpected error: %s.\n",
                  file, line, function ?: "", function ? ": " : "",
                  __strerror_r (errnum, errbuf, sizeof errbuf));

}

Definition at line 238 of file dl-minimal.c.

{
  unsigned long int result = 0;
  long int sign = 1;

  while (*nptr == ' ' || *nptr == '\t')
    ++nptr;

  if (*nptr == '-')
    {
      sign = -1;
      ++nptr;
    }
  else if (*nptr == '+')
    ++nptr;

  if (*nptr < '0' || *nptr > '9')
    {
      if (endptr != NULL)
       *endptr = (char *) nptr;
      return 0UL;
    }

  assert (base == 0);
  base = 10;
  if (*nptr == '0')
    {
      if (nptr[1] == 'x' || nptr[1] == 'X')
       {
         base = 16;
         nptr += 2;
       }
      else
       base = 8;
    }

  while (*nptr >= '0' && *nptr <= '9')
    {
      unsigned long int digval = *nptr - '0';
      if (result > ULONG_MAX / 10
         || (result == ULONG_MAX / 10 && digval > ULONG_MAX % 10))
       {
         errno = ERANGE;
         if (endptr != NULL)
           *endptr = (char *) nptr;
         return ULONG_MAX;
       }
      result *= base;
      result += digval;
      ++nptr;
    }

  if (endptr != NULL)
    *endptr = (char *) nptr;
  return result * sign;
}
unsigned long int weak_function strtoul ( const char *  nptr,
char **  endptr,
int  base 
)
weak_alias ( strong_alias __strsep,
strsep   
)

Definition at line 363 of file dl-minimal.c.

{
  _exit (127);
}

Variable Documentation

void * alloc_end [static]

Definition at line 37 of file dl-minimal.c.

void * alloc_last_block [static]

Definition at line 37 of file dl-minimal.c.

void* alloc_ptr [static]

Definition at line 37 of file dl-minimal.c.