1 | /* Thread attributes retrieval. |
2 | Copyright (C) 2008-2022 Free Software Foundation, Inc. |
3 | This file is part of the GNU C Library. |
4 | |
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 | |
10 | The GNU C Library is distributed in the hope that it will be useful, |
11 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
13 | Lesser General Public License for more details. |
14 | |
15 | You should have received a copy of the GNU Lesser General Public |
16 | License along with the GNU C Library; if not, see |
17 | <https://www.gnu.org/licenses/>. */ |
18 | |
19 | #include <assert.h> |
20 | #include <errno.h> |
21 | #include <pthread.h> |
22 | |
23 | #include <pt-internal.h> |
24 | |
25 | /* Initialize thread attribute *ATTR with attributes corresponding to the |
26 | already running thread THREAD. It shall be called on an uninitialized ATTR |
27 | and destroyed with pthread_attr_destroy when no longer needed. */ |
28 | int |
29 | __pthread_getattr_np (pthread_t thread, pthread_attr_t *attr) |
30 | { |
31 | struct __pthread *pthread; |
32 | |
33 | pthread = __pthread_getid (thread); |
34 | if (pthread == NULL) |
35 | return ESRCH; |
36 | |
37 | /* Some attributes (schedparam, inheritsched, contentionscope and schedpolicy) |
38 | are not supported yet, so fill them with our default values. */ |
39 | *attr = __pthread_default_attr; |
40 | |
41 | attr->__stackaddr = (pthread->stackaddr |
42 | + ((pthread->guardsize + __vm_page_size - 1) |
43 | / __vm_page_size * __vm_page_size)); |
44 | attr->__stacksize = pthread->stacksize; |
45 | attr->__guardsize = pthread->guardsize; |
46 | attr->__detachstate = (pthread->state == PTHREAD_DETACHED |
47 | ? PTHREAD_CREATE_DETACHED : PTHREAD_CREATE_JOINABLE); |
48 | |
49 | return 0; |
50 | } |
51 | weak_alias (__pthread_getattr_np, pthread_getattr_np) |
52 | |