Back to index

glibc  2.9
Enumerations | Functions
mcheck.h File Reference
#include <features.h>

Go to the source code of this file.

Enumerations

enum  mcheck_status {
  MCHECK_DISABLED = -1, MCHECK_OK, MCHECK_FREE, MCHECK_HEAD,
  MCHECK_TAIL
}

Functions

int mcheck (void(*__abortfunc)(enum mcheck_status)) __THROW
int mcheck_pedantic (void(*__abortfunc)(enum mcheck_status)) __THROW
void mcheck_check_all (void)
enum mcheck_status mprobe (void *__ptr) __THROW
void mtrace (void) __THROW
void muntrace (void) __THROW

Enumeration Type Documentation

Enumerator:
MCHECK_DISABLED 
MCHECK_OK 
MCHECK_FREE 
MCHECK_HEAD 
MCHECK_TAIL 

Definition at line 28 of file mcheck.h.

  {
    MCHECK_DISABLED = -1,       /* Consistency checking is not turned on.  */
    MCHECK_OK,                  /* Block is fine.  */
    MCHECK_FREE,                /* Block freed twice.  */
    MCHECK_HEAD,                /* Memory before the block was clobbered.  */
    MCHECK_TAIL                 /* Memory after the block was clobbered.  */
  };

Function Documentation

int mcheck ( void(*)(enum mcheck_status __abortfunc)

Definition at line 355 of file mcheck.c.

{
  abortfunc = (func != NULL) ? func : &mabort;

  /* These hooks may not be safely inserted if malloc is already in use.  */
  if (__malloc_initialized <= 0 && !mcheck_used)
    {
      /* We call malloc() once here to ensure it is initialized.  */
      void *p = malloc (0);
      free (p);

      old_free_hook = __free_hook;
      __free_hook = freehook;
      old_malloc_hook = __malloc_hook;
      __malloc_hook = mallochook;
      old_memalign_hook = __memalign_hook;
      __memalign_hook = memalignhook;
      old_realloc_hook = __realloc_hook;
      __realloc_hook = reallochook;
      mcheck_used = 1;
    }

  return mcheck_used ? 0 : -1;
}

Here is the call graph for this function:

Here is the caller graph for this function:

void mcheck_check_all ( void  )

Definition at line 122 of file mcheck.c.

{
  /* Walk through all the active blocks and test whether they were tempered
     with.  */
  struct hdr *runp = root;

  /* Temporarily turn off the checks.  */
  pedantic = 0;

  while (runp != NULL)
    {
      (void) checkhdr (runp);

      runp = runp->next;
    }

  /* Turn checks on again.  */
  pedantic = 1;
}

Here is the call graph for this function:

Here is the caller graph for this function:

int mcheck_pedantic ( void(*)(enum mcheck_status __abortfunc)

Definition at line 385 of file mcheck.c.

{
  int res = mcheck (func);
  if (res == 0)
    pedantic = 1;
  return res;
}

Here is the call graph for this function:

Here is the caller graph for this function:

enum mcheck_status mprobe ( void *  __ptr)
void mtrace ( void  )

Definition at line 293 of file mtrace.c.

{
#ifdef _LIBC
  static int added_atexit_handler;
#endif
  char *mallfile;

  /* Don't panic if we're called more than once.  */
  if (mallstream != NULL)
    return;

#ifdef _LIBC
  /* When compiling the GNU libc we use the secure getenv function
     which prevents the misuse in case of SUID or SGID enabled
     programs.  */
  mallfile = __secure_getenv (mallenv);
#else
  mallfile = getenv (mallenv);
#endif
  if (mallfile != NULL || mallwatch != NULL)
    {
      char *mtb = malloc (TRACE_BUFFER_SIZE);
      if (mtb == NULL)
       return;

      mallstream = fopen (mallfile != NULL ? mallfile : "/dev/null", "wce");
      if (mallstream != NULL)
       {
#ifndef __ASSUME_O_CLOEXEC
         /* Make sure we close the file descriptor on exec.  */
         int flags = __fcntl (fileno (mallstream), F_GETFD, 0);
         if (flags >= 0)
           {
             flags |= FD_CLOEXEC;
             __fcntl (fileno (mallstream), F_SETFD, flags);
           }
#endif
         /* Be sure it doesn't malloc its buffer!  */
         malloc_trace_buffer = mtb;
         setvbuf (mallstream, malloc_trace_buffer, _IOFBF, TRACE_BUFFER_SIZE);
         fprintf (mallstream, "= Start\n");
         tr_old_free_hook = __free_hook;
         __free_hook = tr_freehook;
         tr_old_malloc_hook = __malloc_hook;
         __malloc_hook = tr_mallochook;
         tr_old_realloc_hook = __realloc_hook;
         __realloc_hook = tr_reallochook;
         tr_old_memalign_hook = __memalign_hook;
         __memalign_hook = tr_memalignhook;
#ifdef _LIBC
         if (!added_atexit_handler)
           {
             extern void *__dso_handle __attribute__ ((__weak__));
             added_atexit_handler = 1;
             __cxa_atexit ((void (*) (void *)) release_libc_mem, NULL,
                          &__dso_handle ? __dso_handle : NULL);
           }
#endif
       }
      else
       free (mtb);
    }
}

Here is the call graph for this function:

Here is the caller graph for this function:

void muntrace ( void  )

Definition at line 358 of file mtrace.c.

Here is the call graph for this function:

Here is the caller graph for this function: