tst-xsigstack.c 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. /* Test of sigaltstack wrappers.
  2. Copyright (C) 2019 Free Software Foundation, Inc.
  3. This file is part of the GNU C Library.
  4. The GNU C Library is free software; you can redistribute it and/or
  5. modify it under the terms of the GNU Lesser General Public
  6. License as published by the Free Software Foundation; either
  7. version 2.1 of the License, or (at your option) any later version.
  8. The GNU C Library is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  11. Lesser General Public License for more details.
  12. You should have received a copy of the GNU Lesser General Public
  13. License along with the GNU C Library; if not, see
  14. <http://www.gnu.org/licenses/>. */
  15. #include <support/xsignal.h>
  16. #include <support/support.h>
  17. #include <support/xunistd.h>
  18. #include <support/check.h>
  19. #include <stdint.h>
  20. #include <stdio.h>
  21. static volatile uintptr_t handler_stackaddr;
  22. static void
  23. handler (int unused)
  24. {
  25. int var;
  26. handler_stackaddr = (uintptr_t) &var;
  27. }
  28. int
  29. do_test (void)
  30. {
  31. void *sstk = xalloc_sigstack (0);
  32. unsigned char *sp;
  33. size_t size;
  34. xget_sigstack_location (sstk, &sp, &size);
  35. printf ("signal stack installed: sp=%p size=%zu\n", sp, size);
  36. struct sigaction sa;
  37. sa.sa_handler = handler;
  38. sa.sa_flags = SA_RESTART | SA_ONSTACK;
  39. sigfillset (&sa.sa_mask);
  40. if (sigaction (SIGUSR1, &sa, 0))
  41. FAIL_RET ("sigaction (SIGUSR1, handler): %m\n");
  42. raise (SIGUSR1);
  43. uintptr_t haddr = handler_stackaddr;
  44. printf ("address of handler local variable: %p\n", (void *)haddr);
  45. TEST_VERIFY ((uintptr_t)sp < haddr);
  46. TEST_VERIFY (haddr < (uintptr_t)sp + size);
  47. xfree_sigstack (sstk);
  48. return 0;
  49. }
  50. #include <support/test-driver.c>