提交 a56e3394 编写于 作者: R Rich Felker

fix uninitialized output from sched_getaffinity

the sched_getaffinity syscall only fills a cpu set up to the set size
used/supported by the kernel. the rest is left untouched and userspace
is responsible for zero-filling it based on the return value of the
syscall.
上级 b72cd07f
#define _GNU_SOURCE #define _GNU_SOURCE
#include <sched.h> #include <sched.h>
#include <string.h>
#include "pthread_impl.h" #include "pthread_impl.h"
#include "syscall.h" #include "syscall.h"
...@@ -16,7 +17,10 @@ int pthread_setaffinity_np(pthread_t td, size_t size, const cpu_set_t *set) ...@@ -16,7 +17,10 @@ int pthread_setaffinity_np(pthread_t td, size_t size, const cpu_set_t *set)
int sched_getaffinity(pid_t tid, size_t size, cpu_set_t *set) int sched_getaffinity(pid_t tid, size_t size, cpu_set_t *set)
{ {
long ret = __syscall(SYS_sched_getaffinity, tid, size, set); long ret = __syscall(SYS_sched_getaffinity, tid, size, set);
if (ret > 0) ret = 0; if (ret > 0) {
if (ret < size) memset((char *)set+ret, 0, size-ret);
ret = 0;
}
return __syscall_ret(ret); return __syscall_ret(ret);
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册