]> git.ipfire.org Git - thirdparty/glibc.git/commitdiff
hurd: Implement _S_msg_get_dtable
authorSamuel Thibault <samuel.thibault@ens-lyon.org>
Sun, 2 Jan 2022 01:22:13 +0000 (02:22 +0100)
committerSamuel Thibault <samuel.thibault@ens-lyon.org>
Sun, 2 Jan 2022 01:24:00 +0000 (02:24 +0100)
This will be needed for implementing lsof.

hurd/hurdmsg.c

index 2b9b214102e6e72e77b9f369e2ab9abe36075ab2..4e6ddf2836451b376a3cfd94c2034ed90a2cf77d 100644 (file)
@@ -385,15 +385,58 @@ _S_msg_set_environment (mach_port_t msgport, mach_port_t auth,
 }
 \f
 
-/* XXX */
-
 kern_return_t
 _S_msg_get_dtable (mach_port_t process,
-                  mach_port_t refport,
+                  mach_port_t auth,
                   portarray_t *dtable,
                   mach_msg_type_name_t *dtablePoly,
                   mach_msg_type_number_t *dtableCnt)
-{ return EOPNOTSUPP; }
+{
+  mach_port_t *ports;
+  mach_msg_type_number_t i;
+  error_t err;
+
+  AUTHCHECK;
+
+  HURD_CRITICAL_BEGIN;
+  __mutex_lock (&_hurd_dtable_lock);
+
+  if (err = __vm_allocate (__mach_task_self (), (vm_address_t *) &ports,
+                          _hurd_dtablesize * sizeof(mach_port_t), 1))
+    goto out;
+
+  for (i = 0; i < _hurd_dtablesize; i++)
+    {
+      struct hurd_fd *cell = _hurd_dtable[i];
+      if (cell == NULL)
+       ports[i] = MACH_PORT_NULL;
+      else
+       {
+         __spin_lock (&cell->port.lock);
+         if (cell->port.port == MACH_PORT_NULL)
+           ports[i] = MACH_PORT_NULL;
+         else
+           {
+             ports[i] = cell->port.port;
+             /* We will move this send right.  */
+             __mach_port_mod_refs (__mach_task_self (), ports[i],
+                                   MACH_PORT_RIGHT_SEND, +1);
+           }
+         __spin_unlock (&cell->port.lock);
+       }
+    }
+
+  *dtable = ports;
+  *dtablePoly = MACH_MSG_TYPE_MOVE_SEND;
+  *dtableCnt = _hurd_dtablesize;
+
+out:
+  __mutex_unlock (&_hurd_dtable_lock);
+  HURD_CRITICAL_END;
+  return err;
+}
+
+/* XXX */
 
 kern_return_t
 _S_msg_set_dtable (mach_port_t process,