Explorar o código

Kernel+LibC: Use argument for TIOCGPGRP ioctl value

In preparation for modifying the Kernel IOCTL API to return KResult
instead of int, we need to fix this ioctl to an argument to receive
it's return value, instead of using the actual function return value.
Brian Gianforcaro %!s(int64=4) %!d(string=hai) anos
pai
achega
46c9b1d81c
Modificáronse 2 ficheiros con 12 adicións e 3 borrados
  1. 7 2
      Kernel/TTY/TTY.cpp
  2. 5 1
      Userland/Libraries/LibC/unistd.cpp

+ 7 - 2
Kernel/TTY/TTY.cpp

@@ -469,8 +469,13 @@ int TTY::ioctl(FileDescription&, unsigned request, Userspace<void*> arg)
     }
     }
 #endif
 #endif
     switch (request) {
     switch (request) {
-    case TIOCGPGRP:
-        return this->pgid().value();
+    case TIOCGPGRP: {
+        auto user_pgid = static_ptr_cast<pid_t*>(arg);
+        auto pgid = this->pgid().value();
+        if (!copy_to_user(user_pgid, &pgid))
+            return -EFAULT;
+        return 0;
+    }
     case TIOCSPGRP: {
     case TIOCSPGRP: {
         ProcessGroupID pgid = static_cast<pid_t>(arg.ptr());
         ProcessGroupID pgid = static_cast<pid_t>(arg.ptr());
         if (pgid <= 0)
         if (pgid <= 0)

+ 5 - 1
Userland/Libraries/LibC/unistd.cpp

@@ -257,7 +257,11 @@ pid_t setsid()
 
 
 pid_t tcgetpgrp(int fd)
 pid_t tcgetpgrp(int fd)
 {
 {
-    return ioctl(fd, TIOCGPGRP);
+    pid_t pgrp;
+    int rc = ioctl(fd, TIOCGPGRP, &pgrp);
+    if (rc < 0)
+        return rc;
+    return pgrp;
 }
 }
 
 
 int tcsetpgrp(int fd, pid_t pgid)
 int tcsetpgrp(int fd, pid_t pgid)