From 90fa9705d5cd29cf11c5dc7319299788dec2546a Mon Sep 17 00:00:00 2001 From: Konstantin Belousov Date: Thu, 11 Nov 2021 10:01:54 +0200 Subject: [PATCH] sched.h: Hide all Linux compat sched_* functions under _WITH_CPU_SET_T Instead of only hiding cpu_set_t compat typedef itself. Too many software packages assume that sched_getaffinity() presence implies full source compatibility with glibc. We can (and should) handle missing CPU_* macros, but then there are incompatible BIT_* uses which cannot be fixed in src/. So hide everything under _WITH_CPU_SET_T, in particular, do not expose sched_getcpu(), sched_get/setaffinity(), as well as CPU_* and BIT_* macros. Consumers that want sched* functions must opt-in. Reported by: portmgr (antoine) Sponsored by: The FreeBSD Foundation MFC after: 1 week --- include/sched.h | 7 +++---- lib/libc/gen/sched_getaffinity.c | 1 + lib/libc/gen/sched_getcpu_gen.c | 1 + lib/libc/gen/sched_setaffinity.c | 1 + lib/libc/x86/sys/sched_getcpu_x86.c | 1 + 5 files changed, 7 insertions(+), 4 deletions(-) diff --git a/include/sched.h b/include/sched.h index 1c41cda79046..460d3bfed154 100644 --- a/include/sched.h +++ b/include/sched.h @@ -32,12 +32,9 @@ #include #include #include -#if __BSD_VISIBLE -#include -#endif /* __BSD_VISIBLE */ - #if __BSD_VISIBLE #ifdef _WITH_CPU_SET_T +#include struct _cpuset; typedef struct _cpuset cpu_set_t; #endif /* _WITH_CPU_SET_T */ @@ -45,9 +42,11 @@ typedef struct _cpuset cpu_set_t; __BEGIN_DECLS #if __BSD_VISIBLE +#ifdef _WITH_CPU_SET_T int sched_getaffinity(pid_t pid, size_t cpusetsz, cpuset_t *cpuset); int sched_setaffinity(int pid, size_t cpusetsz, const cpuset_t *cpuset); int sched_getcpu(void); +#endif /* _WITH_CPU_SET_T */ #endif /* __BSD_VISIBLE */ __END_DECLS diff --git a/lib/libc/gen/sched_getaffinity.c b/lib/libc/gen/sched_getaffinity.c index 191374a3c5e3..5557d3d93b47 100644 --- a/lib/libc/gen/sched_getaffinity.c +++ b/lib/libc/gen/sched_getaffinity.c @@ -26,6 +26,7 @@ * SUCH DAMAGE. */ +#define _WITH_CPU_SET_T #include int diff --git a/lib/libc/gen/sched_getcpu_gen.c b/lib/libc/gen/sched_getcpu_gen.c index ef1bebc2915a..704075c0ae53 100644 --- a/lib/libc/gen/sched_getcpu_gen.c +++ b/lib/libc/gen/sched_getcpu_gen.c @@ -26,6 +26,7 @@ * SUCH DAMAGE. */ +#define _WITH_CPU_SET_T #include #include "libc_private.h" diff --git a/lib/libc/gen/sched_setaffinity.c b/lib/libc/gen/sched_setaffinity.c index 9368b1752b74..ad775b5dbce5 100644 --- a/lib/libc/gen/sched_setaffinity.c +++ b/lib/libc/gen/sched_setaffinity.c @@ -26,6 +26,7 @@ * SUCH DAMAGE. */ +#define _WITH_CPU_SET_T #include int diff --git a/lib/libc/x86/sys/sched_getcpu_x86.c b/lib/libc/x86/sys/sched_getcpu_x86.c index 13ba18ef5e36..5e3bd5311734 100644 --- a/lib/libc/x86/sys/sched_getcpu_x86.c +++ b/lib/libc/x86/sys/sched_getcpu_x86.c @@ -32,6 +32,7 @@ #include #include #include +#define _WITH_CPU_SET_T #include #include "libc_private.h"