Back to index

glibc  2.9
Defines | Functions | Variables
tst-basic7.c File Reference
#include <errno.h>
#include <pthread.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <sys/mman.h>
#include <sys/resource.h>
#include "../test-skeleton.c"

Go to the source code of this file.

Defines

#define TEST_FUNCTION   do_test ()

Functions

static void use_stack (size_t needed)
static void use_up_memory (void)
static void * child (void *arg)
static int do_test (void)

Variables

void(* use_stack_ptr )(size_t) = use_stack

Define Documentation

#define TEST_FUNCTION   do_test ()

Definition at line 73 of file tst-basic7.c.


Function Documentation

static void* child ( void *  arg) [static]

Definition at line 44 of file tst-basic7.c.

{
  sleep (1);
  return arg;
}

Here is the call graph for this function:

Here is the caller graph for this function:

static int do_test ( void  ) [static]

Definition at line 51 of file tst-basic7.c.

{
  int err;
  pthread_t tid;

  /* Allocate the memory needed for the stack.  */
  use_stack_ptr (PTHREAD_STACK_MIN);

  use_up_memory ();

  err = pthread_create (&tid, NULL, child, NULL);
  if (err != 0)
    {
      printf ("pthread_create returns %d: %s\n", err,
             err == EAGAIN ? "OK" : "FAIL");
      return err != EAGAIN;
    }

  /* We did not fail to allocate memory despite the preparation.  Oh well.  */
  return 0;
}

Here is the call graph for this function:

static void use_stack ( size_t  needed) [static]

Definition at line 15 of file tst-basic7.c.

{
  size_t sz = sysconf (_SC_PAGESIZE);
  char *buf = alloca (sz);
  memset (buf, '\0', sz);

  if (needed > sz)
    use_stack_ptr (needed  - sz);
}

Here is the call graph for this function:

static void use_up_memory ( void  ) [static]

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

{
  struct rlimit rl;
  getrlimit (RLIMIT_AS, &rl);
  rl.rlim_cur = 10 * 1024 * 1024;
  setrlimit (RLIMIT_AS, &rl);

  char *c;
  int PAGESIZE = getpagesize ();
  while (1)
    {
      c = mmap (NULL, PAGESIZE, PROT_NONE, MAP_ANON | MAP_PRIVATE, -1, 0);
      if (c == MAP_FAILED)
       break;
    }
}

Here is the call graph for this function:

Here is the caller graph for this function:


Variable Documentation

Definition at line 12 of file tst-basic7.c.