Blame sysdeps/unix/sysv/linux/tst-align-clone.c

Packit 6c4009
/* Copyright (C) 2004-2018 Free Software Foundation, Inc.
Packit 6c4009
   This file is part of the GNU C Library.
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 <sched.h>
Packit 6c4009
#include <stdbool.h>
Packit 6c4009
#include <stdint.h>
Packit 6c4009
#include <stdio.h>
Packit 6c4009
#include <string.h>
Packit 6c4009
#include <sys/wait.h>
Packit 6c4009
#include <unistd.h>
Packit 6c4009
#include <tst-stack-align.h>
Packit 6c4009
#include <stackinfo.h>
Packit 6c4009
Packit 6c4009
static int
Packit 6c4009
f (void *arg)
Packit 6c4009
{
Packit 6c4009
  bool ok = true;
Packit 6c4009
Packit 6c4009
  puts ("in f");
Packit 6c4009
Packit 6c4009
  if (TEST_STACK_ALIGN ())
Packit 6c4009
    ok = false;
Packit 6c4009
Packit 6c4009
  return ok ? 0 : 1;
Packit 6c4009
}
Packit 6c4009
Packit 6c4009
static int
Packit 6c4009
do_test (void)
Packit 6c4009
{
Packit 6c4009
  bool ok = true;
Packit 6c4009
Packit 6c4009
  puts ("in main");
Packit 6c4009
Packit 6c4009
  if (TEST_STACK_ALIGN ())
Packit 6c4009
    ok = false;
Packit 6c4009
Packit 6c4009
#ifdef __ia64__
Packit 6c4009
  extern int __clone2 (int (*__fn) (void *__arg), void *__child_stack_base,
Packit 6c4009
		       size_t __child_stack_size, int __flags,
Packit 6c4009
		       void *__arg, ...);
Packit 6c4009
  char st[256 * 1024];
Packit 6c4009
  pid_t p = __clone2 (f, st, sizeof (st), 0, 0);
Packit 6c4009
#else
Packit 6c4009
  char st[128 * 1024] __attribute__ ((aligned));
Packit 6c4009
# if _STACK_GROWS_DOWN
Packit 6c4009
  pid_t p = clone (f, st + sizeof (st), 0, 0);
Packit 6c4009
# elif _STACK_GROWS_UP
Packit 6c4009
  pid_t p = clone (f, st, 0, 0);
Packit 6c4009
# else
Packit 6c4009
#  error "Define either _STACK_GROWS_DOWN or _STACK_GROWS_UP"
Packit 6c4009
# endif
Packit 6c4009
#endif
Packit 6c4009
  if (p == -1)
Packit 6c4009
    {
Packit 6c4009
      printf("clone failed: %m\n");
Packit 6c4009
      return 1;
Packit 6c4009
    }
Packit 6c4009
Packit 6c4009
  int e;
Packit 6c4009
  if (waitpid (p, &e, __WCLONE) != p)
Packit 6c4009
    {
Packit 6c4009
      puts ("waitpid failed");
Packit 6c4009
      kill (p, SIGKILL);
Packit 6c4009
      return 1;
Packit 6c4009
    }
Packit 6c4009
  if (!WIFEXITED (e))
Packit 6c4009
    {
Packit 6c4009
      if (WIFSIGNALED (e))
Packit 6c4009
	printf ("died from signal %s\n", strsignal (WTERMSIG (e)));
Packit 6c4009
      else
Packit 6c4009
	puts ("did not terminate correctly");
Packit 6c4009
      return 1;
Packit 6c4009
    }
Packit 6c4009
  if (WEXITSTATUS (e) != 0)
Packit 6c4009
    ok = false;
Packit 6c4009
Packit 6c4009
  return ok ? 0 : 1;
Packit 6c4009
}
Packit 6c4009
Packit 6c4009
#define TEST_FUNCTION do_test ()
Packit 6c4009
#include "../test-skeleton.c"