From 68da8b22d2364c1d598605d9ff1bd6b16a37b064 Mon Sep 17 00:00:00 2001 From: Konstantin Belousov Date: Sat, 4 Oct 2008 19:23:30 +0000 Subject: [PATCH] Current linux_fooaffinity() emulation fails, as the FreeBSD affinity syscalls expect the bitmap size in the range from 32 to 128. Old glibc always assumed size 1024, while newer glibc searches for approriate size, starting from 1024 and going up. For now, use FreeBSD size of cpuset_t for bitmap size parameter and return EINVAL if length of user space bitmap less than our size of cpuset_t. Submitted by: dchagin MFC after: 1 week [This requires MFC of the actual linux affinity syscalls] --- sys/compat/linux/linux_misc.c | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/sys/compat/linux/linux_misc.c b/sys/compat/linux/linux_misc.c index 47d7d3fe958d..1be8f92bf021 100644 --- a/sys/compat/linux/linux_misc.c +++ b/sys/compat/linux/linux_misc.c @@ -1828,15 +1828,17 @@ linux_sched_getaffinity(struct thread *td, printf(ARGS(sched_getaffinity, "%d, %d, *"), args->pid, args->len); #endif + if (args->len < sizeof(cpuset_t)) + return (EINVAL); cga.level = CPU_LEVEL_WHICH; cga.which = CPU_WHICH_PID; cga.id = args->pid; - cga.cpusetsize = sizeof(cpumask_t); + cga.cpusetsize = sizeof(cpuset_t); cga.mask = (cpuset_t *) args->user_mask_ptr; - + if ((error = cpuset_getaffinity(td, &cga)) == 0) - td->td_retval[0] = sizeof(cpumask_t); + td->td_retval[0] = sizeof(cpuset_t); return (error); } @@ -1855,10 +1857,13 @@ linux_sched_setaffinity(struct thread *td, printf(ARGS(sched_setaffinity, "%d, %d, *"), args->pid, args->len); #endif + if (args->len < sizeof(cpuset_t)) + return (EINVAL); + csa.level = CPU_LEVEL_WHICH; csa.which = CPU_WHICH_PID; csa.id = args->pid; - csa.cpusetsize = args->len; + csa.cpusetsize = sizeof(cpuset_t); csa.mask = (cpuset_t *) args->user_mask_ptr; return (cpuset_setaffinity(td, &csa));