示例#1
0
int
main ()
{
  uintptr_t value1, value2, value3;

  value1 = get_rusage_as ();

  memchunk1 = malloc (0x88);

  value2 = get_rusage_as ();

  memchunk2 = malloc (0x281237);

  value3 = get_rusage_as ();

  if (value1 == 0 && value2 == 0 && value3 == 0)
    {
      fprintf (stderr, "Skipping test: no way to determine address space size\n");
      return 77;
    }
  else
    {
      /* The address space size is positive.  */
      ASSERT (value1 > 0);

      /* Allocating memory should not decrease the address space size.  */
      ASSERT (value2 >= value1);
      ASSERT (value3 >= value2);

      /* Allocating 2.5 MB of memory should increase the address space size.  */
      ASSERT (value3 > value1);

      return 0;
    }
}
示例#2
0
int
main ()
{
  printf ("Initially:           0x%08lX 0x%08lX 0x%08lX\n",
          get_rusage_as_via_setrlimit (), get_rusage_as_via_iterator (),
          get_rusage_as ());
  malloc (0x88);
  printf ("After small malloc:  0x%08lX 0x%08lX 0x%08lX\n",
          get_rusage_as_via_setrlimit (), get_rusage_as_via_iterator (),
          get_rusage_as ());
  malloc (0x8812);
  printf ("After medium malloc: 0x%08lX 0x%08lX 0x%08lX\n",
          get_rusage_as_via_setrlimit (), get_rusage_as_via_iterator (),
          get_rusage_as ());
  malloc (0x281237);
  printf ("After large malloc:  0x%08lX 0x%08lX 0x%08lX\n",
          get_rusage_as_via_setrlimit (), get_rusage_as_via_iterator (),
          get_rusage_as ());
  return 0;
}
示例#3
0
int
main (int argc, char *argv[])
{
  uintptr_t initial_rusage_as;
  int arg;
  int result;

  /* Limit the amount of malloc()ed memory to MAX_ALLOC_TOTAL or less.  */

  /* On AIX systems, malloc() is limited by RLIMIT_DATA.  */
#if HAVE_GETRLIMIT && HAVE_SETRLIMIT && defined RLIMIT_DATA
  {
    struct rlimit limit;

    if (getrlimit (RLIMIT_DATA, &limit) >= 0)
      {
        if (limit.rlim_max == RLIM_INFINITY || limit.rlim_max > MAX_ALLOC_TOTAL)
          limit.rlim_max = MAX_ALLOC_TOTAL;
        limit.rlim_cur = limit.rlim_max;
        (void) setrlimit (RLIMIT_DATA, &limit);
      }
  }
#endif
  /* On all systems except AIX and OpenBSD, malloc() is limited by RLIMIT_AS.
     On some systems, setrlimit of RLIMIT_AS doesn't work but get_rusage_as ()
     does.  Allow the address space size to grow by at most MAX_ALLOC_TOTAL.  */
  initial_rusage_as = get_rusage_as ();
#if !defined _AIX
  if (initial_rusage_as == 0)
    return 77;
#endif

  arg = atoi (argv[1]);
  if (arg == 0)
    {
      void *memory = malloc (MAX_ALLOC_TOTAL);
      if (memory == NULL)
        return 1;
      memset (memory, 17, MAX_ALLOC_TOTAL);
      result = 78;
    }
  else
    {
      /* Perform the test and test whether it triggers a permanent memory
         allocation of more than MAX_ALLOC_TOTAL bytes.  */
      int repeat;

      for (repeat = 0; repeat < NUM_ROUNDS; repeat++)
        {
          /* This may produce a temporary memory allocation of 11000 bytes.
             but should not result in a permanent memory allocation.  */
          if (fprintf (stdout, "%011000d\n", 17) == -1
              && errno == ENOMEM)
            return 1;
        }

      result = 0;
    }

  if (get_rusage_as () > initial_rusage_as + MAX_ALLOC_TOTAL)
    return 1;

  return result;
}