tst-align2.c 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. /* Copyright (C) 2004 Free Software Foundation, Inc.
  2. This file is part of the GNU C Library.
  3. The GNU C Library is free software; you can redistribute it and/or
  4. modify it under the terms of the GNU Lesser General Public
  5. License as published by the Free Software Foundation; either
  6. version 2.1 of the License, or (at your option) any later version.
  7. The GNU C Library is distributed in the hope that it will be useful,
  8. but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  10. Lesser General Public License for more details.
  11. You should have received a copy of the GNU Lesser General Public
  12. License along with the GNU C Library; if not, write to the Free
  13. Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
  14. 02111-1307 USA. */
  15. #include <sched.h>
  16. #include <stdbool.h>
  17. #include <stdint.h>
  18. #include <stdio.h>
  19. #include <string.h>
  20. #include <sys/wait.h>
  21. #include <unistd.h>
  22. #include "tst-stack-align.h"
  23. static int
  24. f (void *arg)
  25. {
  26. bool ok = true;
  27. if (TEST_STACK_ALIGN ())
  28. ok = false;
  29. return ok ? 0 : 1;
  30. }
  31. static int
  32. do_test (void)
  33. {
  34. bool ok = true;
  35. puts ("in main");
  36. if (TEST_STACK_ALIGN ())
  37. ok = false;
  38. #ifdef __ia64__
  39. extern int __clone2 (int (*__fn) (void *__arg), void *__child_stack_base,
  40. size_t __child_stack_size, int __flags,
  41. void *__arg, ...);
  42. char st[256 * 1024];
  43. pid_t p = __clone2 (f, st, sizeof (st), 0, 0);
  44. #else
  45. char st[128 * 1024];
  46. pid_t p = clone (f, st + sizeof (st), 0, 0);
  47. #endif
  48. if (p == -1)
  49. {
  50. printf("clone failed: %m\n");
  51. return 1;
  52. }
  53. int e;
  54. if (waitpid (p, &e, __WCLONE) != p)
  55. {
  56. puts ("waitpid failed");
  57. kill (p, SIGKILL);
  58. return 1;
  59. }
  60. if (!WIFEXITED (e))
  61. {
  62. if (WIFSIGNALED (e))
  63. printf ("died from signal %s\n", strsignal (WTERMSIG (e)));
  64. else
  65. puts ("did not terminate correctly");
  66. return 1;
  67. }
  68. if (WEXITSTATUS (e) != 0)
  69. ok = false;
  70. return ok ? 0 : 1;
  71. }
  72. #define TEST_FUNCTION do_test ()
  73. #include "../test-skeleton.c"