Skip to contentSkip to conversation

sched/headers: Fix sched_setattr userspace compilation issues

RFC PATCH New Joel Fernandes (Google) 1 participant 1 message May 22, 2020 Stable branch

lore
Share & tools
lore
#0 lore raw

RFC PATCH v2 1/1 sched/headers: Fix sched_setattr userspace compilation issues

On a modern Linux distro, compiling the following program fails:
#include<stdlib.h>
#include<stdint.h>
#include<pthread.h>
#include<linux/sched/types.h>

 void main() {
         struct sched_attr sa;

         return;

}

with:

/usr/include/linux/sched/types.h:8:8: \
			error: redefinition of ‘struct sched_param’
    8 | struct sched_param {
      |        ^~~~~~~~~~~
In file included from /usr/include/x86_64-linux-gnu/bits/sched.h:74,
                 from /usr/include/sched.h:43,
                 from /usr/include/pthread.h:23,
                 from /tmp/s.c:4:
/usr/include/x86_64-linux-gnu/bits/types/struct_sched_param.h:23:8:
note: originally defined here
   23 | struct sched_param
      |        ^~~~~~~~~~~

This is also causing a problem with using sched_attr in Chrome. The issue is struct sched_param is already provided by glibc and is in POSIX.

Guard the kernel's UAPI definition of sched_param with __KERNEL__ so that userspace and the kernel can both compile.

---
v1->v2:
With the chance that libc needs resolving something, I'm resending with libc-alpha added as suggested by Christian, and minor commit message fixes.

 include/uapi/linux/sched/types.h | 2 ++
 1 file changed, 2 insertions(+)
include/uapi/linux/sched/types.h +2 -0
index c852153ddb0d3..1f10d935a63fe 100644
@@ -4,9 +4,11 @@
 
 #include <linux/types.h>
 
+#if defined(__KERNEL__)
 struct sched_param {
 	int sched_priority;
 };
+#endif
 
 #define SCHED_ATTR_SIZE_VER0	48	/* sizeof first published struct */
 #define SCHED_ATTR_SIZE_VER1	56	/* add: util_{min,max} */
Signature · 1 line
2.26.2.761.g0e0b3e54be-goog