Browse Source

Kernel: Make sched_setparam() and sched_getparam() operate on threads

Instead of operating on "some random thread in PID", these now operate
on the thread with a specific TID. This matches other systems better.
Andreas Kling 5 năm trước cách đây
mục cha
commit
b93f6b07c2
1 tập tin đã thay đổi với 10 bổ sung11 xóa
  1. 10 11
      Kernel/Process.cpp

+ 10 - 11
Kernel/Process.cpp

@@ -3283,7 +3283,7 @@ int Process::sys$getpeername(int sockfd, sockaddr* addr, socklen_t* addrlen)
     return 0;
 }
 
-int Process::sys$sched_setparam(pid_t pid, const struct sched_param* param)
+int Process::sys$sched_setparam(int tid, const struct sched_param* param)
 {
     REQUIRE_PROMISE(proc);
     if (!validate_read_typed(param))
@@ -3293,20 +3293,20 @@ int Process::sys$sched_setparam(pid_t pid, const struct sched_param* param)
     copy_from_user(&desired_priority, &param->sched_priority);
 
     InterruptDisabler disabler;
-    auto* peer = this;
-    if (pid != 0)
-        peer = Process::from_pid(pid);
+    auto* peer = current;
+    if (tid != 0)
+        peer = Thread::from_tid(tid);
 
     if (!peer)
         return -ESRCH;
 
-    if (!is_superuser() && m_euid != peer->m_uid && m_uid != peer->m_uid)
+    if (!is_superuser() && m_euid != peer->process().m_uid && m_uid != peer->process().m_uid)
         return -EPERM;
 
     if (desired_priority < THREAD_PRIORITY_MIN || desired_priority > THREAD_PRIORITY_MAX)
         return -EINVAL;
 
-    peer->any_thread().set_priority((u32)desired_priority);
+    peer->set_priority((u32)desired_priority);
     return 0;
 }
 
@@ -3317,18 +3317,17 @@ int Process::sys$sched_getparam(pid_t pid, struct sched_param* param)
         return -EFAULT;
 
     InterruptDisabler disabler;
-    auto* peer = this;
+    auto* peer = current;
     if (pid != 0)
-        peer = Process::from_pid(pid);
+        peer = Thread::from_tid(pid);
 
     if (!peer)
         return -ESRCH;
 
-    if (!is_superuser() && m_euid != peer->m_uid && m_uid != peer->m_uid)
+    if (!is_superuser() && m_euid != peer->process().m_uid && m_uid != peer->process().m_uid)
         return -EPERM;
 
-    // FIXME: This doesn't seem like the way to get the right thread!
-    int priority = peer->any_thread().priority();
+    int priority = peer->priority();
     copy_to_user(&param->sched_priority, &priority);
     return 0;
 }