sigstack.c 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. /* Emulate sigstack function using sigaltstack.
  2. Copyright (C) 1998-2019 Free Software Foundation, Inc.
  3. This file is part of the GNU C Library.
  4. Contributed by Ulrich Drepper <drepper@cygnus.com>, 1998.
  5. The GNU C Library is free software; you can redistribute it and/or
  6. modify it under the terms of the GNU Lesser General Public
  7. License as published by the Free Software Foundation; either
  8. version 2.1 of the License, or (at your option) any later version.
  9. The GNU C Library is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  12. Lesser General Public License for more details.
  13. You should have received a copy of the GNU Lesser General Public
  14. License along with the GNU C Library; if not, see
  15. <http://www.gnu.org/licenses/>. */
  16. #include <signal.h>
  17. #include <stddef.h>
  18. #include <sys/syscall.h>
  19. #ifdef __NR_sigaltstack
  20. int
  21. sigstack (struct sigstack *ss, struct sigstack *oss)
  22. {
  23. stack_t sas;
  24. stack_t *sasp = NULL;
  25. stack_t osas;
  26. stack_t *osasp = oss == NULL ? NULL : &osas;
  27. int result;
  28. if (ss != NULL)
  29. {
  30. /* We have to convert the information. */
  31. sas.ss_sp = ss->ss_sp;
  32. sas.ss_flags = ss->ss_onstack ? SS_ONSTACK : 0;
  33. /* For the size of the stack we have no value we can pass to the
  34. kernel. This is why this function should not be used. We simply
  35. assume that all the memory down to address zero (in case the stack
  36. grows down) is available. */
  37. sas.ss_size = ss->ss_sp - NULL;
  38. sasp = &sas;
  39. }
  40. /* Call the kernel. */
  41. result = __sigaltstack (sasp, osasp);
  42. /* Convert the result, if wanted and possible. */
  43. if (result == 0 && oss != NULL)
  44. {
  45. oss->ss_sp = osas.ss_sp;
  46. oss->ss_onstack = (osas.ss_flags & SS_ONSTACK) != 0;
  47. }
  48. return result;
  49. }
  50. link_warning (sigstack, "the `sigstack' function is dangerous. `sigaltstack' should be used instead.")
  51. #else
  52. # include <signal/sigstack.c>
  53. #endif