From bbb55ef2618bea1deac717192cd69983ad7db3ac Mon Sep 17 00:00:00 2001 From: Tomoki Shirasawa Date: Mon, 28 Nov 2016 14:04:44 +0900 Subject: [PATCH] sched_setparam: thread lock is necessary when update other thread data --- kernel/syscall.c | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/kernel/syscall.c b/kernel/syscall.c index cfaac1a7..f45f09f9 100644 --- a/kernel/syscall.c +++ b/kernel/syscall.c @@ -5590,8 +5590,8 @@ SYSCALL_DECLARE(sched_setparam) struct sched_param param; struct thread *thread = cpu_local_var(current); struct mcs_rwlock_node_irqsave lock; - struct syscall_request request1 IHK_DMA_ALIGN; + int other_thread = 0; dkprintf("sched_setparam: pid: %d, uparam: 0x%lx\n", pid, uparam); @@ -5603,12 +5603,11 @@ SYSCALL_DECLARE(sched_setparam) pid = thread->proc->pid; if (thread->proc->pid != pid) { + other_thread = 1; thread = find_thread(pid, pid, &lock); if (!thread) { return -ESRCH; } - // TODO: unlock 場所のチェック - // 何をしようとしているのか理解 thread_unlock(thread, &lock); /* Ask Linux about ownership.. */ @@ -5627,7 +5626,17 @@ SYSCALL_DECLARE(sched_setparam) return -EFAULT; } - return setscheduler(thread, thread->sched_policy, ¶m); + if (other_thread) { + thread = find_thread(pid, pid, &lock); + if (!thread) { + return -ESRCH; + } + } + retval = setscheduler(thread, thread->sched_policy, ¶m); + if (other_thread) { + thread_unlock(thread, &lock); + } + return retval; } SYSCALL_DECLARE(sched_getparam)