tst-align2.c 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  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, see
  13. <http://www.gnu.org/licenses/>. */
  14. #include <sched.h>
  15. #include <stdbool.h>
  16. #include <stdint.h>
  17. #include <stdio.h>
  18. #include <string.h>
  19. #include <sys/wait.h>
  20. #include <unistd.h>
  21. #include "tst-stack-align.h"
  22. static int
  23. f (void *arg)
  24. {
  25. bool ok = true;
  26. if (TEST_STACK_ALIGN ())
  27. ok = false;
  28. return ok ? 0 : 1;
  29. }
  30. static int
  31. do_test (void)
  32. {
  33. bool ok = true;
  34. puts ("in main");
  35. if (TEST_STACK_ALIGN ())
  36. ok = false;
  37. #ifdef __ia64__
  38. extern int __clone2 (int (*__fn) (void *__arg), void *__child_stack_base,
  39. size_t __child_stack_size, int __flags,
  40. void *__arg, ...);
  41. char st[256 * 1024];
  42. pid_t p = __clone2 (f, st, sizeof (st), 0, 0);
  43. #else
  44. char st[128 * 1024];
  45. pid_t p = clone (f, st + sizeof (st), 0, 0);
  46. #endif
  47. if (p == -1)
  48. {
  49. printf("clone failed: %m\n");
  50. return 1;
  51. }
  52. int e;
  53. if (waitpid (p, &e, __WCLONE) != p)
  54. {
  55. puts ("waitpid failed");
  56. kill (p, SIGKILL);
  57. return 1;
  58. }
  59. if (!WIFEXITED (e))
  60. {
  61. if (WIFSIGNALED (e))
  62. printf ("died from signal %s\n", strsignal (WTERMSIG (e)));
  63. else
  64. puts ("did not terminate correctly");
  65. return 1;
  66. }
  67. if (WEXITSTATUS (e) != 0)
  68. ok = false;
  69. return ok ? 0 : 1;
  70. }
  71. #define TEST_FUNCTION do_test ()
  72. #include "../test-skeleton.c"