Back to index

glibc  2.9
Defines | Functions | Variables
dl-cache.c File Reference
#include <assert.h>
#include <unistd.h>
#include <ldsodefs.h>
#include <sys/mman.h>
#include <dl-cache.h>
#include <dl-procinfo.h>
#include <stdio-common/_itoa.h>

Go to the source code of this file.

Defines

#define _DL_PLATFORMS_COUNT   0
#define _dl_cache_verify_ptr(ptr)   (ptr < cache_data_size)
#define SEARCH_CACHE(cache)
#define _DL_HWCAP_TLS_MASK   (1LL << 63)
#define HWCAP_CHECK
#define HWCAP_CHECK   do {} while (0)

Functions

int internal_function _dl_cache_libcmp (const char *p1, const char *p2)
const char *internal_function _dl_load_cache_lookup (const char *name)
void _dl_unload_cache (void)

Variables

static struct cache_filecache
static struct cache_file_newcache_new
static size_t cachesize

Define Documentation

#define _dl_cache_verify_ptr (   ptr)    (ptr < cache_data_size)

Definition at line 39 of file dl-cache.c.

#define _DL_HWCAP_TLS_MASK   (1LL << 63)
#define _DL_PLATFORMS_COUNT   0

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

#define HWCAP_CHECK
Value:
if (GLRO(dl_osversion) && lib->osversion > GLRO(dl_osversion))       \
       continue;                                                     \
      if (_DL_PLATFORMS_COUNT                                               \
         && (lib->hwcap & _DL_HWCAP_PLATFORM) != 0                          \
         && (lib->hwcap & _DL_HWCAP_PLATFORM) != platform)                  \
       continue;                                                     \
      if (lib->hwcap                                                 \
         & ~(GLRO(dl_hwcap) | _DL_HWCAP_PLATFORM | _DL_HWCAP_TLS_MASK))      \
       continue
#define HWCAP_CHECK   do {} while (0)
#define SEARCH_CACHE (   cache)

Definition at line 41 of file dl-cache.c.


Function Documentation

int internal_function _dl_cache_libcmp ( const char *  p1,
const char *  p2 
)

Definition at line 127 of file dl-cache.c.

{
  while (*p1 != '\0')
    {
      if (*p1 >= '0' && *p1 <= '9')
        {
          if (*p2 >= '0' && *p2 <= '9')
            {
             /* Must compare this numerically.  */
             int val1;
             int val2;

             val1 = *p1++ - '0';
             val2 = *p2++ - '0';
             while (*p1 >= '0' && *p1 <= '9')
               val1 = val1 * 10 + *p1++ - '0';
             while (*p2 >= '0' && *p2 <= '9')
               val2 = val2 * 10 + *p2++ - '0';
             if (val1 != val2)
              return val1 - val2;
           }
         else
            return 1;
        }
      else if (*p2 >= '0' && *p2 <= '9')

Here is the caller graph for this function:

Definition at line 170 of file dl-cache.c.

{
  int left, right, middle;
  int cmpres;
  const char *cache_data;
  uint32_t cache_data_size;
  const char *best;

  /* Print a message if the loading of libs is traced.  */
  if (__builtin_expect (GLRO(dl_debug_mask) & DL_DEBUG_LIBS, 0))
    _dl_debug_printf (" search cache=%s\n", LD_SO_CACHE);

  if (cache == NULL)
    {
      /* Read the contents of the file.  */
      void *file = _dl_sysdep_read_whole_file (LD_SO_CACHE, &cachesize,
                                          PROT_READ);

      /* We can handle three different cache file formats here:
        - the old libc5/glibc2.0/2.1 format
        - the old format with the new format in it
        - only the new format
        The following checks if the cache contains any of these formats.  */
      if (file != MAP_FAILED && cachesize > sizeof *cache
         && memcmp (file, CACHEMAGIC, sizeof CACHEMAGIC - 1) == 0)
       {
         size_t offset;
         /* Looks ok.  */
         cache = file;

         /* Check for new version.  */
         offset = ALIGN_CACHE (sizeof (struct cache_file)
                            + cache->nlibs * sizeof (struct file_entry));

         cache_new = (struct cache_file_new *) ((void *) cache + offset);
         if (cachesize < (offset + sizeof (struct cache_file_new))
             || memcmp (cache_new->magic, CACHEMAGIC_VERSION_NEW,
                      sizeof CACHEMAGIC_VERSION_NEW - 1) != 0)
           cache_new = (void *) -1;
       }
      else if (file != MAP_FAILED && cachesize > sizeof *cache_new
              && memcmp (file, CACHEMAGIC_VERSION_NEW,
                       sizeof CACHEMAGIC_VERSION_NEW - 1) == 0)
       {
         cache_new = file;
         cache = file;
       }
      else
       {
         if (file != MAP_FAILED)
           __munmap (file, cachesize);
         cache = (void *) -1;
       }

      assert (cache != NULL);
    }

  if (cache == (void *) -1)
    /* Previously looked for the cache file and didn't find it.  */
    return NULL;

  best = NULL;

  if (cache_new != (void *) -1)
    {
      uint64_t platform;

      /* This is where the strings start.  */
      cache_data = (const char *) cache_new;

      /* Now we can compute how large the string table is.  */
      cache_data_size = (const char *) cache + cachesize - cache_data;

      platform = _dl_string_platform (GLRO(dl_platform));
      if (platform != (uint64_t) -1)
       platform = 1ULL << platform;

      /* Only accept hwcap if it's for the right platform.  */
#define _DL_HWCAP_TLS_MASK (1LL << 63)
#define HWCAP_CHECK \
      if (GLRO(dl_osversion) && lib->osversion > GLRO(dl_osversion))        \
       continue;                                                     \
      if (_DL_PLATFORMS_COUNT                                               \
         && (lib->hwcap & _DL_HWCAP_PLATFORM) != 0                          \
         && (lib->hwcap & _DL_HWCAP_PLATFORM) != platform)                  \
       continue;                                                     \
      if (lib->hwcap                                                 \
         & ~(GLRO(dl_hwcap) | _DL_HWCAP_PLATFORM | _DL_HWCAP_TLS_MASK))      \
       continue
      SEARCH_CACHE (cache_new);
    }
  else
    {
      /* This is where the strings start.  */
      cache_data = (const char *) &cache->libs[cache->nlibs];

      /* Now we can compute how large the string table is.  */
      cache_data_size = (const char *) cache + cachesize - cache_data;

#undef HWCAP_CHECK

Here is the caller graph for this function:

void _dl_unload_cache ( void  )

Definition at line 288 of file dl-cache.c.

{

Here is the caller graph for this function:


Variable Documentation

struct cache_file* cache [static]

Definition at line 34 of file dl-cache.c.

struct cache_file_new* cache_new [static]

Definition at line 35 of file dl-cache.c.

size_t cachesize [static]

Definition at line 36 of file dl-cache.c.