Back to index

glibc  2.9
tst-align2.c
Go to the documentation of this file.
00001 /* Copyright (C) 2004, 2007 Free Software Foundation, Inc.
00002    This file is part of the GNU C Library.
00003 
00004    The GNU C Library is free software; you can redistribute it and/or
00005    modify it under the terms of the GNU Lesser General Public
00006    License as published by the Free Software Foundation; either
00007    version 2.1 of the License, or (at your option) any later version.
00008 
00009    The GNU C Library is distributed in the hope that it will be useful,
00010    but WITHOUT ANY WARRANTY; without even the implied warranty of
00011    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00012    Lesser General Public License for more details.
00013 
00014    You should have received a copy of the GNU Lesser General Public
00015    License along with the GNU C Library; if not, write to the Free
00016    Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
00017    02111-1307 USA.  */
00018 
00019 #include <sched.h>
00020 #include <stdbool.h>
00021 #include <stdint.h>
00022 #include <stdio.h>
00023 #include <string.h>
00024 #include <sys/wait.h>
00025 #include <unistd.h>
00026 #include <tst-stack-align.h>
00027 #include <stackinfo.h>
00028 
00029 static int
00030 f (void *arg)
00031 {
00032   bool ok = true;
00033 
00034   puts ("in f");
00035 
00036   if (TEST_STACK_ALIGN ())
00037     ok = false;
00038 
00039   return ok ? 0 : 1;
00040 }
00041 
00042 static int
00043 do_test (void)
00044 {
00045   bool ok = true;
00046 
00047   puts ("in main");
00048 
00049   if (TEST_STACK_ALIGN ())
00050     ok = false;
00051 
00052 #ifdef __ia64__
00053   extern int __clone2 (int (*__fn) (void *__arg), void *__child_stack_base,
00054                      size_t __child_stack_size, int __flags,
00055                      void *__arg, ...);
00056   char st[256 * 1024];
00057   pid_t p = __clone2 (f, st, sizeof (st), 0, 0);
00058 #else
00059   char st[128 * 1024] __attribute__ ((aligned));
00060 # if _STACK_GROWS_DOWN
00061   pid_t p = clone (f, st + sizeof (st), 0, 0);
00062 # elif _STACK_GROWS_UP
00063   pid_t p = clone (f, st, 0, 0);
00064 # else
00065 #  error "Define either _STACK_GROWS_DOWN or _STACK_GROWS_UP"
00066 # endif
00067 #endif
00068   if (p == -1)
00069     {
00070       printf("clone failed: %m\n");
00071       return 1;
00072     }
00073 
00074   int e;
00075   if (waitpid (p, &e, __WCLONE) != p)
00076     {
00077       puts ("waitpid failed");
00078       kill (p, SIGKILL);
00079       return 1;
00080     }
00081   if (!WIFEXITED (e))
00082     {
00083       if (WIFSIGNALED (e))
00084        printf ("died from signal %s\n", strsignal (WTERMSIG (e)));
00085       else
00086        puts ("did not terminate correctly");
00087       return 1;
00088     }
00089   if (WEXITSTATUS (e) != 0)
00090     ok = false;
00091 
00092   return ok ? 0 : 1;
00093 }
00094 
00095 #define TEST_FUNCTION do_test ()
00096 #include "../test-skeleton.c"