Fix pathconf statvfs namespace (bug 18507).
[glibc.git] / sysdeps / unix / sysv / linux / check-cpuset.h
blob1d55e0bb0e1155511a271aeb84dbd059aa553677
1 /* Validate cpu_set_t values for NPTL. Linux version.
2 Copyright (C) 2002-2015 Free Software Foundation, Inc.
3 This file is part of the GNU C Library.
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.
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.
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 <http://www.gnu.org/licenses/>. */
19 #include <pthread.h>
20 #include <errno.h>
23 /* Defined in pthread_setaffinity.c. */
24 extern size_t __kernel_cpumask_size attribute_hidden;
25 extern int __determine_cpumask_size (pid_t tid);
27 /* Returns 0 if CS and SZ are valid values for the cpuset and cpuset size
28 respectively. Otherwise it returns an error number. */
29 static inline int
30 check_cpuset_attr (const cpu_set_t *cs, const size_t sz)
32 if (__kernel_cpumask_size == 0)
34 int res = __determine_cpumask_size (THREAD_SELF->tid);
35 if (res)
36 return res;
39 /* Check whether the new bitmask has any bit set beyond the
40 last one the kernel accepts. */
41 for (size_t cnt = __kernel_cpumask_size; cnt < sz; ++cnt)
42 if (((char *) cs)[cnt] != '\0')
43 /* Found a nonzero byte. This means the user request cannot be
44 fulfilled. */
45 return EINVAL;
47 return 0;