Module Name:    src
Committed By:   njoly
Date:           Tue Jun 23 13:18:59 UTC 2009

Modified Files:
        src/sys/compat/linux/common: linux_sched.c

Log Message:
sched_getaffinity(2) update:
- dynamically calculate the cpu mask size,
- return it upon success,
- fix generated cpu mask.


To generate a diff of this commit:
cvs rdiff -u -r1.59 -r1.60 src/sys/compat/linux/common/linux_sched.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/compat/linux/common/linux_sched.c
diff -u src/sys/compat/linux/common/linux_sched.c:1.59 src/sys/compat/linux/common/linux_sched.c:1.60
--- src/sys/compat/linux/common/linux_sched.c:1.59	Thu Jun 18 20:36:28 2009
+++ src/sys/compat/linux/common/linux_sched.c	Tue Jun 23 13:18:59 2009
@@ -1,4 +1,4 @@
-/*	$NetBSD: linux_sched.c,v 1.59 2009/06/18 20:36:28 njoly Exp $	*/
+/*	$NetBSD: linux_sched.c,v 1.60 2009/06/23 13:18:59 njoly Exp $	*/
 
 /*-
  * Copyright (c) 1999 The NetBSD Foundation, Inc.
@@ -35,7 +35,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: linux_sched.c,v 1.59 2009/06/18 20:36:28 njoly Exp $");
+__KERNEL_RCSID(0, "$NetBSD: linux_sched.c,v 1.60 2009/06/23 13:18:59 njoly Exp $");
 
 #include <sys/param.h>
 #include <sys/mount.h>
@@ -622,15 +622,12 @@
 		syscallarg(unsigned int) len;
 		syscallarg(unsigned long *) mask;
 	} */
-	int error;
-	int ret;
-	char *data;
-	int *retp;
-
-	if (SCARG(uap, mask) == NULL)
-		return EINVAL;
+	int error, size, nb = ncpu;
+	unsigned long *p, *data;
 
-	if (SCARG(uap, len) < sizeof(int))
+	/* Unlike Linux, dynamically calculate cpu mask size */
+	size = sizeof(long) * ((ncpu + LONG_BIT - 1) / LONG_BIT);
+	if (SCARG(uap, len) < size)
 		return EINVAL;
 
 	if (pfind(SCARG(uap, pid)) == NULL)
@@ -641,14 +638,18 @@
 	 * The result is a mask, the first CPU being in the least significant
 	 * bit.
 	 */
-	ret = (1 << ncpu) - 1;
-	data = malloc(SCARG(uap, len), M_TEMP, M_WAITOK|M_ZERO);
-	retp = (int *)&data[SCARG(uap, len) - sizeof(ret)];
-	*retp = ret;
-
-	error = copyout(data, SCARG(uap, mask), SCARG(uap, len));
+	data = malloc(size, M_TEMP, M_WAITOK|M_ZERO);
+	p = data;
+	while (nb > LONG_BIT) {
+		*p++ = ~0UL;
+		nb -= LONG_BIT;
+	}
+	if (nb)
+		*p = (1 << ncpu) - 1;
 
+	error = copyout(data, SCARG(uap, mask), size);
 	free(data, M_TEMP);
+	*retval = size;
 
 	return error;
 

Reply via email to