Back to index

glibc  2.9
Defines | Functions
tst-dlmodcount.c File Reference
#include <link.h>
#include <stddef.h>
#include <stdio.h>
#include <stdlib.h>

Go to the source code of this file.

Defines

#define SET   0
#define ADD   1
#define REMOVE   2
#define leq(l, r)   (((r) - (l)) <= ~0ULL / 2)

Functions

static int callback (struct dl_phdr_info *info, size_t size, void *ptr)
static void * load (const char *path)
static void unload (const char *path, void *handle)
int main (int argc, char **argv)

Define Documentation

#define ADD   1

Definition at line 26 of file tst-dlmodcount.c.

#define leq (   l,
  r 
)    (((r) - (l)) <= ~0ULL / 2)

Definition at line 29 of file tst-dlmodcount.c.

#define REMOVE   2

Definition at line 27 of file tst-dlmodcount.c.

#define SET   0

Definition at line 25 of file tst-dlmodcount.c.


Function Documentation

static int callback ( struct dl_phdr_info *  info,
size_t  size,
void *  ptr 
) [static]

Definition at line 32 of file tst-dlmodcount.c.

{
  static int last_adds = 0, last_subs = 0;
  intptr_t cmd = (intptr_t) ptr;

  printf ("  size = %Zu\n", size);
  if (size < (offsetof (struct dl_phdr_info, dlpi_subs)
             + sizeof (info->dlpi_subs)))
    {
      fprintf (stderr, "dl_iterate_phdr failed to pass dlpi_adds/dlpi_subs\n");
      exit (5);
    }

  printf ("  dlpi_adds = %Lu dlpi_subs = %Lu\n",
         info->dlpi_adds, info->dlpi_subs);

  switch (cmd)
    {
    case SET:
      break;

    case ADD:
      if (leq (info->dlpi_adds, last_adds))
       {
         fprintf (stderr, "dlpi_adds failed to get incremented!\n");
         exit (3);
       }
      break;

    case REMOVE:
      if (leq (info->dlpi_subs, last_subs))
       {
         fprintf (stderr, "dlpi_subs failed to get incremented!\n");
         exit (4);
       }
      break;
    }
  last_adds = info->dlpi_adds;
  last_subs = info->dlpi_subs;
  return -1;
}

Here is the call graph for this function:

Here is the caller graph for this function:

static void* load ( const char *  path) [static]

Definition at line 75 of file tst-dlmodcount.c.

{
  void *handle;

  printf ("loading `%s'\n", path);
  handle = dlopen (path, RTLD_LAZY);
  if (!handle)
    exit (1);
  dl_iterate_phdr (callback, (void *)(intptr_t) ADD);
  return handle;
}

Here is the call graph for this function:

Here is the caller graph for this function:

int main ( int  argc,
char **  argv 
)

Definition at line 97 of file tst-dlmodcount.c.

{
  void *handle1, *handle2;

  dl_iterate_phdr (callback, (void *)(intptr_t) SET);
  handle1 = load ("firstobj.so");
  handle2 = load ("globalmod1.so");
  unload ("firstobj.so", handle1);
  unload ("globalmod1.so", handle2);
  return 0;
}

Here is the call graph for this function:

static void unload ( const char *  path,
void *  handle 
) [static]

Definition at line 88 of file tst-dlmodcount.c.

{
  printf ("unloading `%s'\n", path);
  if (dlclose (handle) < 0)
    exit (2);
  dl_iterate_phdr (callback, (void *)(intptr_t) REMOVE);
}

Here is the call graph for this function:

Here is the caller graph for this function: