pt-getattr.c 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. /* Thread attributes retrieval.
  2. Copyright (C) 2008-2026 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. <https://www.gnu.org/licenses/>. */
  15. #include <assert.h>
  16. #include <errno.h>
  17. #include <pthread.h>
  18. #include <pt-internal.h>
  19. #include <shlib-compat.h>
  20. #include <ldsodefs.h>
  21. /* Initialize thread attribute *ATTR with attributes corresponding to the
  22. already running thread THREAD. It shall be called on an uninitialized ATTR
  23. and destroyed with pthread_attr_destroy when no longer needed. */
  24. int
  25. __pthread_getattr_np (pthread_t thread, pthread_attr_t *attr)
  26. {
  27. struct __pthread *pthread;
  28. pthread = __pthread_getid (thread);
  29. if (pthread == NULL)
  30. return ESRCH;
  31. /* Some attributes (schedparam, inheritsched, contentionscope and schedpolicy)
  32. are not supported yet, so fill them with our default values. */
  33. *attr = __pthread_default_attr;
  34. attr->__stackaddr = (pthread->stackaddr
  35. + ((pthread->guardsize + __vm_page_size - 1)
  36. / __vm_page_size * __vm_page_size));
  37. attr->__stacksize = pthread->stacksize;
  38. attr->__guardsize = pthread->guardsize;
  39. attr->__detachstate = (pthread->state == PTHREAD_DETACHED
  40. ? PTHREAD_CREATE_DETACHED : PTHREAD_CREATE_JOINABLE);
  41. return 0;
  42. }
  43. libc_hidden_def (__pthread_getattr_np)
  44. versioned_symbol (libc, __pthread_getattr_np, pthread_getattr_np, GLIBC_2_43);
  45. #if OTHER_SHLIB_COMPAT (libpthread, GLIBC_2_12, GLIBC_2_43)
  46. compat_symbol (libpthread, __pthread_getattr_np, pthread_getattr_np, GLIBC_2_12);
  47. #endif