From patchwork Thu Jan 8 19:17:33 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Roland McGrath X-Patchwork-Id: 4575 Received: (qmail 6460 invoked by alias); 8 Jan 2015 19:17:40 -0000 Mailing-List: contact libc-alpha-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: libc-alpha-owner@sourceware.org Delivered-To: mailing list libc-alpha@sourceware.org Received: (qmail 6440 invoked by uid 89); 8 Jan 2015 19:17:39 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-2.2 required=5.0 tests=AWL, BAYES_00 autolearn=ham version=3.3.2 X-HELO: topped-with-meat.com MIME-Version: 1.0 From: Roland McGrath To: "GNU C. Library" Subject: [COMMITTED PATCH] NPTL: Refactor cpu_set_t validation to be sysdeps-controlled Message-Id: <20150108191733.778FF2C3BC0@topped-with-meat.com> Date: Thu, 8 Jan 2015 11:17:33 -0800 (PST) X-CMAE-Score: 0 X-CMAE-Analysis: v=2.1 cv=SvUDtp+0 c=1 sm=1 tr=0 a=WkljmVdYkabdwxfqvArNOQ==:117 a=14OXPxybAAAA:8 a=kj9zAlcOel0A:10 a=hOe2yjtxAAAA:8 a=mDV3o1hIAAAA:8 a=iYsw09DxwBlgT71IwlcA:9 a=qSGNZPEKsoPcZ-ez:21 a=waE5eKu5iqnHb2Us:21 a=CjuIK1q_8ugA:10 This removes Linuxisms related to cpu_set_t validation from the generic NPTL code and puts them into a new sysdeps header file. Verified on x86_64-linux-gnu that no generated code changes. Thanks, Roland 2015-01-08 Roland McGrath * nptl/pthreadP.h (check_cpuset_attr): Moved ... * sysdeps/unix/sysv/linux/check-cpuset.h: ... to this new file. * nptl/pthread_attr_setaffinity.c: Include it. * nptl/pthread_setattr_default_np.c: Likewise. * nptl/check-cpuset.h: New file. --- /dev/null +++ b/nptl/check-cpuset.h @@ -0,0 +1,32 @@ +/* Validate cpu_set_t values for NPTL. Stub version. + Copyright (C) 2015 Free Software Foundation, Inc. + This file is part of the GNU C Library. + + The GNU C Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + The GNU C Library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with the GNU C Library; if not, see + . */ + +#include + +/* Returns 0 if CS and SZ are valid values for the cpuset and cpuset size + respectively. Otherwise it returns an error number. */ +static inline int +check_cpuset_attr (const cpu_set_t *cs, const size_t sz) +{ + if (sz == 0) + return 0; + + /* This means pthread_attr_setaffinity will return ENOSYS, which + is the right thing when the cpu_set_t features are not available. */ + return ENOSYS; +} --- a/nptl/pthreadP.h +++ b/nptl/pthreadP.h @@ -629,31 +629,4 @@ check_stacksize_attr (size_t st) return EINVAL; } -/* Defined in pthread_setaffinity.c. */ -extern size_t __kernel_cpumask_size attribute_hidden; -extern int __determine_cpumask_size (pid_t tid); - -/* Returns 0 if CS and SZ are valid values for the cpuset and cpuset size - respectively. Otherwise it returns an error number. */ -static inline int -check_cpuset_attr (const cpu_set_t *cs, const size_t sz) -{ - if (__kernel_cpumask_size == 0) - { - int res = __determine_cpumask_size (THREAD_SELF->tid); - if (res) - return res; - } - - /* Check whether the new bitmask has any bit set beyond the - last one the kernel accepts. */ - for (size_t cnt = __kernel_cpumask_size; cnt < sz; ++cnt) - if (((char *) cs)[cnt] != '\0') - /* Found a nonzero byte. This means the user request cannot be - fulfilled. */ - return EINVAL; - - return 0; -} - #endif /* pthreadP.h */ --- a/nptl/pthread_attr_setaffinity.c +++ b/nptl/pthread_attr_setaffinity.c @@ -23,8 +23,7 @@ #include #include #include - - +#include int --- a/nptl/pthread_setattr_default_np.c +++ b/nptl/pthread_setattr_default_np.c @@ -21,6 +21,8 @@ #include #include #include +#include + int pthread_setattr_default_np (const pthread_attr_t *in) --- /dev/null +++ b/sysdeps/unix/sysv/linux/check-cpuset.h @@ -0,0 +1,48 @@ +/* Validate cpu_set_t values for NPTL. Linux version. + Copyright (C) 2002-2015 Free Software Foundation, Inc. + This file is part of the GNU C Library. + + The GNU C Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + The GNU C Library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with the GNU C Library; if not, see + . */ + +#include +#include + + +/* Defined in pthread_setaffinity.c. */ +extern size_t __kernel_cpumask_size attribute_hidden; +extern int __determine_cpumask_size (pid_t tid); + +/* Returns 0 if CS and SZ are valid values for the cpuset and cpuset size + respectively. Otherwise it returns an error number. */ +static inline int +check_cpuset_attr (const cpu_set_t *cs, const size_t sz) +{ + if (__kernel_cpumask_size == 0) + { + int res = __determine_cpumask_size (THREAD_SELF->tid); + if (res) + return res; + } + + /* Check whether the new bitmask has any bit set beyond the + last one the kernel accepts. */ + for (size_t cnt = __kernel_cpumask_size; cnt < sz; ++cnt) + if (((char *) cs)[cnt] != '\0') + /* Found a nonzero byte. This means the user request cannot be + fulfilled. */ + return EINVAL; + + return 0; +}