Blame malloc/tst-mallocstate.c

Packit 6c4009
/* Emulate Emacs heap dumping to test malloc_set_state.
Packit 6c4009
   Copyright (C) 2001-2018 Free Software Foundation, Inc.
Packit 6c4009
   This file is part of the GNU C Library.
Packit 6c4009
   Contributed by Wolfram Gloger <wg@malloc.de>, 2001.
Packit 6c4009
Packit 6c4009
   The GNU C Library is free software; you can redistribute it and/or
Packit 6c4009
   modify it under the terms of the GNU Lesser General Public
Packit 6c4009
   License as published by the Free Software Foundation; either
Packit 6c4009
   version 2.1 of the License, or (at your option) any later version.
Packit 6c4009
Packit 6c4009
   The GNU C Library is distributed in the hope that it will be useful,
Packit 6c4009
   but WITHOUT ANY WARRANTY; without even the implied warranty of
Packit 6c4009
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
Packit 6c4009
   Lesser General Public License for more details.
Packit 6c4009
Packit 6c4009
   You should have received a copy of the GNU Lesser General Public
Packit 6c4009
   License along with the GNU C Library; if not, see
Packit 6c4009
   <http://www.gnu.org/licenses/>.  */
Packit 6c4009
Packit 6c4009
#include <errno.h>
Packit 6c4009
#include <stdbool.h>
Packit 6c4009
#include <stdio.h>
Packit 6c4009
#include <string.h>
Packit 6c4009
#include <libc-symbols.h>
Packit 6c4009
#include <shlib-compat.h>
Packit 6c4009
#include <support/check.h>
Packit 6c4009
#include <support/support.h>
Packit 6c4009
#include <support/test-driver.h>
Packit 6c4009
Packit 6c4009
#include "malloc.h"
Packit 6c4009
Packit 6c4009
#if TEST_COMPAT (libc, GLIBC_2_0, GLIBC_2_25)
Packit 6c4009
Packit 6c4009
/* Make the compatibility symbols availabile to this test case.  */
Packit 6c4009
void *malloc_get_state (void);
Packit 6c4009
compat_symbol_reference (libc, malloc_get_state, malloc_get_state, GLIBC_2_0);
Packit 6c4009
int malloc_set_state (void *);
Packit 6c4009
compat_symbol_reference (libc, malloc_set_state, malloc_set_state, GLIBC_2_0);
Packit 6c4009
Packit 6c4009
/* Maximum object size in the fake heap.  */
Packit 6c4009
enum { max_size = 64 };
Packit 6c4009
Packit 6c4009
/* Allocation actions.  These are randomized actions executed on the
Packit 6c4009
   dumped heap (see allocation_tasks below).  They are interspersed
Packit 6c4009
   with operations on the new heap (see heap_activity).  */
Packit 6c4009
enum allocation_action
Packit 6c4009
  {
Packit 6c4009
    action_free,                /* Dumped and freed.  */
Packit 6c4009
    action_realloc,             /* Dumped and realloc'ed.  */
Packit 6c4009
    action_realloc_same,        /* Dumped and realloc'ed, same size.  */
Packit 6c4009
    action_realloc_smaller,     /* Dumped and realloc'ed, shrinked.  */
Packit 6c4009
    action_count
Packit 6c4009
  };
Packit 6c4009
Packit 6c4009
/* Dumped heap.  Initialize it, so that the object is placed into the
Packit 6c4009
   .data section, for increased realism.  The size is an upper bound;
Packit 6c4009
   we use about half of the space.  */
Packit 6c4009
static size_t dumped_heap[action_count * max_size * max_size
Packit 6c4009
                          / sizeof (size_t)] = {1};
Packit 6c4009
Packit 6c4009
/* Next free space in the dumped heap.  Also top of the heap at the
Packit 6c4009
   end of the initialization procedure.  */
Packit 6c4009
static size_t *next_heap_chunk;
Packit 6c4009
Packit 6c4009
/* Copied from malloc.c and hooks.c.  The version is deliberately
Packit 6c4009
   lower than the final version of malloc_set_state.  */
Packit 6c4009
# define NBINS 128
Packit 6c4009
# define MALLOC_STATE_MAGIC   0x444c4541l
Packit 6c4009
# define MALLOC_STATE_VERSION (0 * 0x100l + 4l)
Packit 6c4009
static struct
Packit 6c4009
{
Packit 6c4009
  long magic;
Packit 6c4009
  long version;
Packit 6c4009
  void *av[NBINS * 2 + 2];
Packit 6c4009
  char *sbrk_base;
Packit 6c4009
  int sbrked_mem_bytes;
Packit 6c4009
  unsigned long trim_threshold;
Packit 6c4009
  unsigned long top_pad;
Packit 6c4009
  unsigned int n_mmaps_max;
Packit 6c4009
  unsigned long mmap_threshold;
Packit 6c4009
  int check_action;
Packit 6c4009
  unsigned long max_sbrked_mem;
Packit 6c4009
  unsigned long max_total_mem;
Packit 6c4009
  unsigned int n_mmaps;
Packit 6c4009
  unsigned int max_n_mmaps;
Packit 6c4009
  unsigned long mmapped_mem;
Packit 6c4009
  unsigned long max_mmapped_mem;
Packit 6c4009
  int using_malloc_checking;
Packit 6c4009
  unsigned long max_fast;
Packit 6c4009
  unsigned long arena_test;
Packit 6c4009
  unsigned long arena_max;
Packit 6c4009
  unsigned long narenas;
Packit 6c4009
} save_state =
Packit 6c4009
  {
Packit 6c4009
    .magic = MALLOC_STATE_MAGIC,
Packit 6c4009
    .version = MALLOC_STATE_VERSION,
Packit 6c4009
  };
Packit 6c4009
Packit 6c4009
/* Allocate a blob in the fake heap.  */
Packit 6c4009
static void *
Packit 6c4009
dumped_heap_alloc (size_t length)
Packit 6c4009
{
Packit 6c4009
  /* malloc needs three state bits in the size field, so the minimum
Packit 6c4009
     alignment is 8 even on 32-bit architectures.  malloc_set_state
Packit 6c4009
     should be compatible with such heaps even if it currently
Packit 6c4009
     provides more alignment to applications.  */
Packit 6c4009
  enum
Packit 6c4009
  {
Packit 6c4009
    heap_alignment = 8,
Packit 6c4009
    heap_alignment_mask = heap_alignment - 1
Packit 6c4009
  };
Packit 6c4009
  _Static_assert (sizeof (size_t) <= heap_alignment,
Packit 6c4009
                  "size_t compatible with heap alignment");
Packit 6c4009
Packit 6c4009
  /* Need at least this many bytes for metadata and application
Packit 6c4009
     data. */
Packit 6c4009
  size_t chunk_size = sizeof (size_t) + length;
Packit 6c4009
  /* Round up the allocation size to the heap alignment.  */
Packit 6c4009
  chunk_size += heap_alignment_mask;
Packit 6c4009
  chunk_size &= ~heap_alignment_mask;
Packit 6c4009
  TEST_VERIFY_EXIT ((chunk_size & 3) == 0);
Packit 6c4009
  if (next_heap_chunk == NULL)
Packit 6c4009
    /* Initialize the top of the heap.  Add one word of zero padding,
Packit 6c4009
       to match existing practice.  */
Packit 6c4009
    {
Packit 6c4009
      dumped_heap[0] = 0;
Packit 6c4009
      next_heap_chunk = dumped_heap + 1;
Packit 6c4009
    }
Packit 6c4009
  else
Packit 6c4009
    /* The previous chunk is allocated. */
Packit 6c4009
    chunk_size |= 1;
Packit 6c4009
  *next_heap_chunk = chunk_size;
Packit 6c4009
Packit 6c4009
  /* User data starts after the chunk header.  */
Packit 6c4009
  void *result = next_heap_chunk + 1;
Packit 6c4009
  next_heap_chunk += chunk_size / sizeof (size_t);
Packit 6c4009
Packit 6c4009
  /* Mark the previous chunk as used.   */
Packit 6c4009
  *next_heap_chunk = 1;
Packit 6c4009
  return result;
Packit 6c4009
}
Packit 6c4009
Packit 6c4009
/* Global seed variable for the random number generator.  */
Packit 6c4009
static unsigned long long global_seed;
Packit 6c4009
Packit 6c4009
/* Simple random number generator.  The numbers are in the range from
Packit 6c4009
   0 to UINT_MAX (inclusive).  */
Packit 6c4009
static unsigned int
Packit 6c4009
rand_next (unsigned long long *seed)
Packit 6c4009
{
Packit 6c4009
  /* Linear congruential generated as used for MMIX.  */
Packit 6c4009
  *seed = *seed * 6364136223846793005ULL + 1442695040888963407ULL;
Packit 6c4009
  return *seed >> 32;
Packit 6c4009
}
Packit 6c4009
Packit 6c4009
/* Fill LENGTH bytes at BUFFER with random contents, as determined by
Packit 6c4009
   SEED.  */
Packit 6c4009
static void
Packit 6c4009
randomize_buffer (unsigned char *buffer, size_t length,
Packit 6c4009
                  unsigned long long seed)
Packit 6c4009
{
Packit 6c4009
  for (size_t i = 0; i < length; ++i)
Packit 6c4009
    buffer[i] = rand_next (&seed);
Packit 6c4009
}
Packit 6c4009
Packit 6c4009
/* Dumps the buffer to standard output,  in hexadecimal.  */
Packit 6c4009
static void
Packit 6c4009
dump_hex (unsigned char *buffer, size_t length)
Packit 6c4009
{
Packit 6c4009
  for (int i = 0; i < length; ++i)
Packit 6c4009
    printf (" %02X", buffer[i]);
Packit 6c4009
}
Packit 6c4009
Packit 6c4009
/* Set to true if an error is encountered.  */
Packit 6c4009
static bool errors = false;
Packit 6c4009
Packit 6c4009
/* Keep track of object allocations.  */
Packit 6c4009
struct allocation
Packit 6c4009
{
Packit 6c4009
  unsigned char *data;
Packit 6c4009
  unsigned int size;
Packit 6c4009
  unsigned int seed;
Packit 6c4009
};
Packit 6c4009
Packit 6c4009
/* Check that the allocation task allocation has the expected
Packit 6c4009
   contents.  */
Packit 6c4009
static void
Packit 6c4009
check_allocation (const struct allocation *alloc, int index)
Packit 6c4009
{
Packit 6c4009
  size_t size = alloc->size;
Packit 6c4009
  if (alloc->data == NULL)
Packit 6c4009
    {
Packit 6c4009
      printf ("error: NULL pointer for allocation of size %zu at %d, seed %u\n",
Packit 6c4009
              size, index, alloc->seed);
Packit 6c4009
      errors = true;
Packit 6c4009
      return;
Packit 6c4009
    }
Packit 6c4009
Packit 6c4009
  unsigned char expected[4096];
Packit 6c4009
  if (size > sizeof (expected))
Packit 6c4009
    {
Packit 6c4009
      printf ("error: invalid allocation size %zu at %d, seed %u\n",
Packit 6c4009
              size, index, alloc->seed);
Packit 6c4009
      errors = true;
Packit 6c4009
      return;
Packit 6c4009
    }
Packit 6c4009
  randomize_buffer (expected, size, alloc->seed);
Packit 6c4009
  if (memcmp (alloc->data, expected, size) != 0)
Packit 6c4009
    {
Packit 6c4009
      printf ("error: allocation %d data mismatch, size %zu, seed %u\n",
Packit 6c4009
              index, size, alloc->seed);
Packit 6c4009
      printf ("  expected:");
Packit 6c4009
      dump_hex (expected, size);
Packit 6c4009
      putc ('\n', stdout);
Packit 6c4009
      printf ("    actual:");
Packit 6c4009
      dump_hex (alloc->data, size);
Packit 6c4009
      putc ('\n', stdout);
Packit 6c4009
      errors = true;
Packit 6c4009
    }
Packit 6c4009
}
Packit 6c4009
Packit 6c4009
/* A heap allocation combined with pending actions on it.  */
Packit 6c4009
struct allocation_task
Packit 6c4009
{
Packit 6c4009
  struct allocation allocation;
Packit 6c4009
  enum allocation_action action;
Packit 6c4009
};
Packit 6c4009
Packit 6c4009
/* Allocation tasks.  Initialized by init_allocation_tasks and used by
Packit 6c4009
   perform_allocations.  */
Packit 6c4009
enum { allocation_task_count = action_count * max_size };
Packit 6c4009
static struct allocation_task allocation_tasks[allocation_task_count];
Packit 6c4009
Packit 6c4009
/* Fisher-Yates shuffle of allocation_tasks.  */
Packit 6c4009
static void
Packit 6c4009
shuffle_allocation_tasks (void)
Packit 6c4009
{
Packit 6c4009
  for (int i = 0; i < allocation_task_count - 1; ++i)
Packit 6c4009
    {
Packit 6c4009
      /* Pick pair in the tail of the array.  */
Packit 6c4009
      int j = i + (rand_next (&global_seed)
Packit 6c4009
                   % ((unsigned) (allocation_task_count - i)));
Packit 6c4009
      TEST_VERIFY_EXIT (j >= 0 && j < allocation_task_count);
Packit 6c4009
      /* Exchange. */
Packit 6c4009
      struct allocation_task tmp = allocation_tasks[i];
Packit 6c4009
      allocation_tasks[i] = allocation_tasks[j];
Packit 6c4009
      allocation_tasks[j] = tmp;
Packit 6c4009
    }
Packit 6c4009
}
Packit 6c4009
Packit 6c4009
/* Set up the allocation tasks and the dumped heap.  */
Packit 6c4009
static void
Packit 6c4009
initial_allocations (void)
Packit 6c4009
{
Packit 6c4009
  /* Initialize in a position-dependent way.  */
Packit 6c4009
  for (int i = 0; i < allocation_task_count; ++i)
Packit 6c4009
    allocation_tasks[i] = (struct allocation_task)
Packit 6c4009
      {
Packit 6c4009
        .allocation =
Packit 6c4009
          {
Packit 6c4009
            .size = 1 + (i / action_count),
Packit 6c4009
            .seed = i,
Packit 6c4009
          },
Packit 6c4009
        .action = i % action_count
Packit 6c4009
      };
Packit 6c4009
Packit 6c4009
  /* Execute the tasks in a random order.  */
Packit 6c4009
  shuffle_allocation_tasks ();
Packit 6c4009
Packit 6c4009
  /* Initialize the contents of the dumped heap.   */
Packit 6c4009
  for (int i = 0; i < allocation_task_count; ++i)
Packit 6c4009
    {
Packit 6c4009
      struct allocation_task *task = allocation_tasks + i;
Packit 6c4009
      task->allocation.data = dumped_heap_alloc (task->allocation.size);
Packit 6c4009
      randomize_buffer (task->allocation.data, task->allocation.size,
Packit 6c4009
                        task->allocation.seed);
Packit 6c4009
    }
Packit 6c4009
Packit 6c4009
  for (int i = 0; i < allocation_task_count; ++i)
Packit 6c4009
    check_allocation (&allocation_tasks[i].allocation, i);
Packit 6c4009
}
Packit 6c4009
Packit 6c4009
/* Indicates whether init_heap has run.  This variable needs to be
Packit 6c4009
   volatile because malloc is declared __THROW, which implies it is a
Packit 6c4009
   leaf function, but we expect it to run our hooks.  */
Packit 6c4009
static volatile bool heap_initialized;
Packit 6c4009
Packit 6c4009
/* Executed by glibc malloc, through __malloc_initialize_hook
Packit 6c4009
   below.  */
Packit 6c4009
static void
Packit 6c4009
init_heap (void)
Packit 6c4009
{
Packit 6c4009
  if (test_verbose)
Packit 6c4009
    printf ("info: performing heap initialization\n");
Packit 6c4009
  heap_initialized = true;
Packit 6c4009
Packit 6c4009
  /* Populate the dumped heap.  */
Packit 6c4009
  initial_allocations ();
Packit 6c4009
Packit 6c4009
  /* Complete initialization of the saved heap data structure.  */
Packit 6c4009
  save_state.sbrk_base = (void *) dumped_heap;
Packit 6c4009
  save_state.sbrked_mem_bytes = sizeof (dumped_heap);
Packit 6c4009
  /* Top pointer.  Adjust so that it points to the start of struct
Packit 6c4009
     malloc_chunk.  */
Packit 6c4009
  save_state.av[2] = (void *) (next_heap_chunk - 1);
Packit 6c4009
Packit 6c4009
  /* Integrate the dumped heap into the process heap.  */
Packit 6c4009
  TEST_VERIFY_EXIT (malloc_set_state (&save_state) == 0);
Packit 6c4009
}
Packit 6c4009
Packit 6c4009
/* Interpose the initialization callback.  */
Packit 6c4009
void (*volatile __malloc_initialize_hook) (void) = init_heap;
Packit 6c4009
Packit 6c4009
/* Simulate occasional unrelated heap activity in the non-dumped
Packit 6c4009
   heap.  */
Packit 6c4009
enum { heap_activity_allocations_count = 32 };
Packit 6c4009
static struct allocation heap_activity_allocations
Packit 6c4009
  [heap_activity_allocations_count] = {};
Packit 6c4009
static int heap_activity_seed_counter = 1000 * 1000;
Packit 6c4009
Packit 6c4009
static void
Packit 6c4009
heap_activity (void)
Packit 6c4009
{
Packit 6c4009
  /* Only do this from time to time.  */
Packit 6c4009
  if ((rand_next (&global_seed) % 4) == 0)
Packit 6c4009
    {
Packit 6c4009
      int slot = rand_next (&global_seed) % heap_activity_allocations_count;
Packit 6c4009
      struct allocation *alloc = heap_activity_allocations + slot;
Packit 6c4009
      if (alloc->data == NULL)
Packit 6c4009
        {
Packit 6c4009
          alloc->size = rand_next (&global_seed) % (4096U + 1);
Packit 6c4009
          alloc->data = xmalloc (alloc->size);
Packit 6c4009
          alloc->seed = heap_activity_seed_counter++;
Packit 6c4009
          randomize_buffer (alloc->data, alloc->size, alloc->seed);
Packit 6c4009
          check_allocation (alloc, 1000 + slot);
Packit 6c4009
        }
Packit 6c4009
      else
Packit 6c4009
        {
Packit 6c4009
          check_allocation (alloc, 1000 + slot);
Packit 6c4009
          free (alloc->data);
Packit 6c4009
          alloc->data = NULL;
Packit 6c4009
        }
Packit 6c4009
    }
Packit 6c4009
}
Packit 6c4009
Packit 6c4009
static void
Packit 6c4009
heap_activity_deallocate (void)
Packit 6c4009
{
Packit 6c4009
  for (int i = 0; i < heap_activity_allocations_count; ++i)
Packit 6c4009
    free (heap_activity_allocations[i].data);
Packit 6c4009
}
Packit 6c4009
Packit 6c4009
/* Perform a full heap check across the dumped heap allocation tasks,
Packit 6c4009
   and the simulated heap activity directly above.  */
Packit 6c4009
static void
Packit 6c4009
full_heap_check (void)
Packit 6c4009
{
Packit 6c4009
  /* Dumped heap.  */
Packit 6c4009
  for (int i = 0; i < allocation_task_count; ++i)
Packit 6c4009
    if (allocation_tasks[i].allocation.data != NULL)
Packit 6c4009
      check_allocation (&allocation_tasks[i].allocation, i);
Packit 6c4009
Packit 6c4009
  /* Heap activity allocations.  */
Packit 6c4009
  for (int i = 0; i < heap_activity_allocations_count; ++i)
Packit 6c4009
    if (heap_activity_allocations[i].data != NULL)
Packit 6c4009
      check_allocation (heap_activity_allocations + i, i);
Packit 6c4009
}
Packit 6c4009
Packit 6c4009
/* Used as an optimization barrier to force a heap allocation.  */
Packit 6c4009
__attribute__ ((noinline, noclone))
Packit 6c4009
static void
Packit 6c4009
my_free (void *ptr)
Packit 6c4009
{
Packit 6c4009
  free (ptr);
Packit 6c4009
}
Packit 6c4009
Packit 6c4009
static int
Packit 6c4009
do_test (void)
Packit 6c4009
{
Packit 6c4009
  my_free (malloc (1));
Packit 6c4009
  TEST_VERIFY_EXIT (heap_initialized);
Packit 6c4009
Packit 6c4009
  /* The first pass performs the randomly generated allocation
Packit 6c4009
     tasks.  */
Packit 6c4009
  if (test_verbose)
Packit 6c4009
    printf ("info: first pass through allocation tasks\n");
Packit 6c4009
  full_heap_check ();
Packit 6c4009
Packit 6c4009
  /* Execute the post-undump tasks in a random order.  */
Packit 6c4009
  shuffle_allocation_tasks ();
Packit 6c4009
Packit 6c4009
  for (int i = 0; i < allocation_task_count; ++i)
Packit 6c4009
    {
Packit 6c4009
      heap_activity ();
Packit 6c4009
      struct allocation_task *task = allocation_tasks + i;
Packit 6c4009
      switch (task->action)
Packit 6c4009
        {
Packit 6c4009
        case action_free:
Packit 6c4009
          check_allocation (&task->allocation, i);
Packit 6c4009
          free (task->allocation.data);
Packit 6c4009
          task->allocation.data = NULL;
Packit 6c4009
          break;
Packit 6c4009
Packit 6c4009
        case action_realloc:
Packit 6c4009
          check_allocation (&task->allocation, i);
Packit 6c4009
          task->allocation.data = xrealloc
Packit 6c4009
            (task->allocation.data, task->allocation.size + max_size);
Packit 6c4009
          check_allocation (&task->allocation, i);
Packit 6c4009
          break;
Packit 6c4009
Packit 6c4009
        case action_realloc_same:
Packit 6c4009
          check_allocation (&task->allocation, i);
Packit 6c4009
          task->allocation.data = xrealloc
Packit 6c4009
            (task->allocation.data, task->allocation.size);
Packit 6c4009
          check_allocation (&task->allocation, i);
Packit 6c4009
          break;
Packit 6c4009
Packit 6c4009
        case action_realloc_smaller:
Packit 6c4009
          check_allocation (&task->allocation, i);
Packit 6c4009
          size_t new_size = task->allocation.size - 1;
Packit 6c4009
          task->allocation.data = xrealloc (task->allocation.data, new_size);
Packit 6c4009
          if (new_size == 0)
Packit 6c4009
            {
Packit 6c4009
              if (task->allocation.data != NULL)
Packit 6c4009
                {
Packit 6c4009
                  printf ("error: realloc with size zero did not deallocate\n");
Packit 6c4009
                  errors = true;
Packit 6c4009
                }
Packit 6c4009
              /* No further action on this task.  */
Packit 6c4009
              task->action = action_free;
Packit 6c4009
            }
Packit 6c4009
          else
Packit 6c4009
            {
Packit 6c4009
              task->allocation.size = new_size;
Packit 6c4009
              check_allocation (&task->allocation, i);
Packit 6c4009
            }
Packit 6c4009
          break;
Packit 6c4009
Packit 6c4009
        case action_count:
Packit 6c4009
          FAIL_EXIT1 ("task->action should never be action_count");
Packit 6c4009
        }
Packit 6c4009
      full_heap_check ();
Packit 6c4009
    }
Packit 6c4009
Packit 6c4009
  /* The second pass frees the objects which were allocated during the
Packit 6c4009
     first pass.  */
Packit 6c4009
  if (test_verbose)
Packit 6c4009
    printf ("info: second pass through allocation tasks\n");
Packit 6c4009
Packit 6c4009
  shuffle_allocation_tasks ();
Packit 6c4009
  for (int i = 0; i < allocation_task_count; ++i)
Packit 6c4009
    {
Packit 6c4009
      heap_activity ();
Packit 6c4009
      struct allocation_task *task = allocation_tasks + i;
Packit 6c4009
      switch (task->action)
Packit 6c4009
        {
Packit 6c4009
        case action_free:
Packit 6c4009
          /* Already freed, nothing to do.  */
Packit 6c4009
          break;
Packit 6c4009
Packit 6c4009
        case action_realloc:
Packit 6c4009
        case action_realloc_same:
Packit 6c4009
        case action_realloc_smaller:
Packit 6c4009
          check_allocation (&task->allocation, i);
Packit 6c4009
          free (task->allocation.data);
Packit 6c4009
          task->allocation.data = NULL;
Packit 6c4009
          break;
Packit 6c4009
Packit 6c4009
        case action_count:
Packit 6c4009
          FAIL_EXIT1 ("task->action should never be action_count");
Packit 6c4009
        }
Packit 6c4009
      full_heap_check ();
Packit 6c4009
    }
Packit 6c4009
Packit 6c4009
  heap_activity_deallocate ();
Packit 6c4009
Packit 6c4009
  /* Check that the malloc_get_state stub behaves in the intended
Packit 6c4009
     way.  */
Packit 6c4009
  errno = 0;
Packit 6c4009
  if (malloc_get_state () != NULL)
Packit 6c4009
    {
Packit 6c4009
      printf ("error: malloc_get_state succeeded\n");
Packit 6c4009
      errors = true;
Packit 6c4009
    }
Packit 6c4009
  if (errno != ENOSYS)
Packit 6c4009
    {
Packit 6c4009
      printf ("error: malloc_get_state: %m\n");
Packit 6c4009
      errors = true;
Packit 6c4009
    }
Packit 6c4009
Packit 6c4009
  return errors;
Packit 6c4009
}
Packit 6c4009
#else
Packit 6c4009
static int
Packit 6c4009
do_test (void)
Packit 6c4009
{
Packit 6c4009
  return 77;
Packit 6c4009
}
Packit 6c4009
#endif
Packit 6c4009
Packit 6c4009
#include <support/test-driver.c>