1 /* Copyright (C) 2003-2024 Free Software Foundation, Inc.
2 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.
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.
14 You should have received a copy of the GNU Lesser General Public
15 License along with the GNU C Library; if not, see
16 <https://www.gnu.org/licenses/>. */
22 #include <sys/types.h>
23 #include <sys/param.h>
24 #include <shlib-compat.h>
28 __pthread_attr_getaffinity_new (const pthread_attr_t
*attr
, size_t cpusetsize
,
31 const struct pthread_attr
*iattr
;
33 iattr
= (const struct pthread_attr
*) attr
;
35 if (iattr
->extension
!= NULL
&& iattr
->extension
->cpuset
!= NULL
)
37 /* Check whether there are any bits set beyond the limits
38 the user requested. */
39 for (size_t cnt
= cpusetsize
; cnt
< iattr
->extension
->cpusetsize
; ++cnt
)
40 if (((char *) iattr
->extension
->cpuset
)[cnt
] != 0)
43 /* Copy over the cpuset from the thread attribute object. Limit the copy
44 to the minimum of the source and destination sizes to prevent a buffer
45 overrun. If the destination is larger, fill the remaining space with
47 void *p
= mempcpy (cpuset
, iattr
->extension
->cpuset
,
48 MIN (iattr
->extension
->cpusetsize
, cpusetsize
));
49 if (cpusetsize
> iattr
->extension
->cpusetsize
)
50 memset (p
, '\0', cpusetsize
- iattr
->extension
->cpusetsize
);
53 /* We have no information. */
54 memset (cpuset
, -1, cpusetsize
);
58 versioned_symbol (libpthread
, __pthread_attr_getaffinity_new
,
59 pthread_attr_getaffinity_np
, GLIBC_2_34
);
60 #if OTHER_SHLIB_COMPAT (libpthread, GLIBC_2_3_4, GLIBC_2_34)
61 compat_symbol (libpthread
, __pthread_attr_getaffinity_new
,
62 pthread_attr_getaffinity_np
, GLIBC_2_3_4
);
66 #if OTHER_SHLIB_COMPAT (libpthread, GLIBC_2_3_3, GLIBC_2_3_4)
68 __pthread_attr_getaffinity_old (const pthread_attr_t
*attr
, cpu_set_t
*cpuset
)
70 /* The old interface by default assumed a 1024 processor bitmap. */
71 return __pthread_attr_getaffinity_new (attr
, 128, cpuset
);
73 compat_symbol (libpthread
, __pthread_attr_getaffinity_old
,
74 pthread_attr_getaffinity_np
, GLIBC_2_3_3
);