about summary refs log tree commit diff
path: root/hurd
diff options
context:
space:
mode:
authorSamuel Thibault <samuel.thibault@ens-lyon.org>2022-01-02 02:22:13 +0100
committerSamuel Thibault <samuel.thibault@ens-lyon.org>2022-01-02 02:24:00 +0100
commita51faeee6ae68da63e65eb0a1eb6c9ec2ce2148b (patch)
tree47f9f38fc099d51655abe1b48e38cd2ccff40f44 /hurd
parentb92a49359f33a461db080a33940d73f47c756126 (diff)
downloadglibc-a51faeee6ae68da63e65eb0a1eb6c9ec2ce2148b.tar.gz
glibc-a51faeee6ae68da63e65eb0a1eb6c9ec2ce2148b.tar.xz
glibc-a51faeee6ae68da63e65eb0a1eb6c9ec2ce2148b.zip
hurd: Implement _S_msg_get_dtable
This will be needed for implementing lsof.
Diffstat (limited to 'hurd')
-rw-r--r--hurd/hurdmsg.c51
1 files changed, 47 insertions, 4 deletions
diff --git a/hurd/hurdmsg.c b/hurd/hurdmsg.c
index 2b9b214102..4e6ddf2836 100644
--- a/hurd/hurdmsg.c
+++ b/hurd/hurdmsg.c
@@ -385,15 +385,58 @@ _S_msg_set_environment (mach_port_t msgport, mach_port_t auth,
 }
 
 
-/* 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,