1 /* Copyright (C) 2002, 2003, 2004, 2005, 2006 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, write to the Free
16 Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
23 #include <sys/types.h>
24 #include <sys/syscall.h>
26 #ifdef INTERNAL_SYSCALL /* remove this when all archs has this #defined */
30 #include <sys/param.h>
31 #include <sys/types.h>
34 libc_hidden_proto(getpid)
36 #define __NR___syscall_sched_setaffinity __NR_sched_setaffinity
37 static inline _syscall3(int, __syscall_sched_setaffinity, __kernel_pid_t, pid,
38 size_t, cpusetsize, cpu_set_t *, cpuset);
40 static size_t __kernel_cpumask_size;
42 int sched_setaffinity(pid_t pid, size_t cpusetsize, const cpu_set_t *cpuset)
45 if (unlikely (__kernel_cpumask_size == 0)) {
46 INTERNAL_SYSCALL_DECL (err);
49 void *p = alloca (psize);
51 while (res = INTERNAL_SYSCALL (sched_getaffinity, err, 3, getpid (),
53 INTERNAL_SYSCALL_ERROR_P (res, err)
54 && INTERNAL_SYSCALL_ERRNO (res, err) == EINVAL)
55 p = extend_alloca (p, psize, 2 * psize);
57 if (res == 0 || INTERNAL_SYSCALL_ERROR_P (res, err)) {
58 __set_errno (INTERNAL_SYSCALL_ERRNO (res, err));
62 __kernel_cpumask_size = res;
65 /* We now know the size of the kernel cpumask_t. Make sure the user
66 does not request to set a bit beyond that. */
67 for (cnt = __kernel_cpumask_size; cnt < cpusetsize; ++cnt)
68 if (((char *) cpuset)[cnt] != '\0') {
69 /* Found a nonzero byte. This means the user request cannot be
75 return INLINE_SYSCALL (sched_setaffinity, 3, pid, cpusetsize, cpuset);