pthread_attr_setstack.c 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. /* Copyright (C) 2002-2019 Free Software Foundation, Inc.
  2. This file is part of the GNU C Library.
  3. Contributed by Ulrich Drepper <drepper@redhat.com>, 2002.
  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 <errno.h>
  16. #include <limits.h>
  17. #include "pthreadP.h"
  18. #ifndef NEW_VERNUM
  19. # define NEW_VERNUM GLIBC_2_3_3
  20. #endif
  21. int
  22. __pthread_attr_setstack (pthread_attr_t *attr, void *stackaddr,
  23. size_t stacksize)
  24. {
  25. struct pthread_attr *iattr;
  26. iattr = (struct pthread_attr *) attr;
  27. /* Catch invalid sizes. */
  28. int ret = check_stacksize_attr (stacksize);
  29. if (ret)
  30. return ret;
  31. #ifdef EXTRA_PARAM_CHECKS
  32. EXTRA_PARAM_CHECKS;
  33. #endif
  34. iattr->stacksize = stacksize;
  35. #if _STACK_GROWS_DOWN
  36. iattr->stackaddr = (char *) stackaddr + stacksize;
  37. #else
  38. iattr->stackaddr = (char *) stackaddr;
  39. #endif
  40. iattr->flags |= ATTR_FLAG_STACKADDR;
  41. return 0;
  42. }
  43. #if PTHREAD_STACK_MIN == 16384
  44. strong_alias (__pthread_attr_setstack, pthread_attr_setstack)
  45. #else
  46. # include <shlib-compat.h>
  47. versioned_symbol (libpthread, __pthread_attr_setstack, pthread_attr_setstack,
  48. NEW_VERNUM);
  49. # if SHLIB_COMPAT(libpthread, GLIBC_2_2, NEW_VERNUM)
  50. int
  51. __old_pthread_attr_setstack (pthread_attr_t *attr, void *stackaddr,
  52. size_t stacksize)
  53. {
  54. struct pthread_attr *iattr;
  55. iattr = (struct pthread_attr *) attr;
  56. /* Catch invalid sizes. */
  57. if (stacksize < 16384)
  58. return EINVAL;
  59. # ifdef EXTRA_PARAM_CHECKS
  60. EXTRA_PARAM_CHECKS;
  61. # endif
  62. iattr->stacksize = stacksize;
  63. #if _STACK_GROWS_DOWN
  64. iattr->stackaddr = (char *) stackaddr + stacksize;
  65. #else
  66. iattr->stackaddr = (char *) stackaddr;
  67. #endif
  68. iattr->flags |= ATTR_FLAG_STACKADDR;
  69. return 0;
  70. }
  71. compat_symbol (libpthread, __old_pthread_attr_setstack, pthread_attr_setstack,
  72. GLIBC_2_2);
  73. # endif
  74. #endif