bug-hurd
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[PATCH 03/23] libports: add ports_lookup_payload


From: Justus Winter
Subject: [PATCH 03/23] libports: add ports_lookup_payload
Date: Fri, 29 Nov 2013 01:03:31 +0100

* libports/lookup-payload.c: New file.
* libports/ports.h (ports_lookup_payload): Add declaration.
* libports/Makefile (SRCS): Add lookup-payload.c.
---
 libports/Makefile         |    2 +-
 libports/lookup-payload.c |   44 ++++++++++++++++++++++++++++++++++++++++++++
 libports/ports.h          |    6 ++++++
 3 files changed, 51 insertions(+), 1 deletion(-)
 create mode 100644 libports/lookup-payload.c

diff --git a/libports/Makefile b/libports/Makefile
index 767ee73..934b151 100644
--- a/libports/Makefile
+++ b/libports/Makefile
@@ -36,7 +36,7 @@ SRCS = create-bucket.c create-class.c \
  interrupt-operation.c interrupt-on-notify.c interrupt-notified-rpcs.c \
  dead-name.c create-port.c import-port.c default-uninhibitable-rpcs.c \
  claim-right.c transfer-right.c create-port-noinstall.c create-internal.c \
- interrupted.c
+ interrupted.c lookup-payload.c
 
 installhdrs = ports.h
 
diff --git a/libports/lookup-payload.c b/libports/lookup-payload.c
new file mode 100644
index 0000000..92f54b6
--- /dev/null
+++ b/libports/lookup-payload.c
@@ -0,0 +1,44 @@
+/*
+   Copyright (C) 2013 Free Software Foundation, Inc.
+
+   Written by Justus Winter <4winter@informatik.uni-hamburg.de>
+
+   This file is part of the GNU Hurd.
+
+   The GNU Hurd is free software; you can redistribute it and/or
+   modify it under the terms of the GNU General Public License as
+   published by the Free Software Foundation; either version 2, or (at
+   your option) any later version.
+
+   The GNU Hurd is distributed in the hope that it will be useful, but
+   WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   General Public License for more details.
+
+   You should have received a copy of the GNU General Public License
+   along with the GNU Hurd.  If not, see <http://www.gnu.org/licenses/>.  */
+
+#include "ports.h"
+
+void *
+ports_lookup_payload (struct port_bucket *bucket,
+                     unsigned long payload,
+                     struct port_class *class)
+{
+  struct port_info *pi = (struct port_info *) payload;
+
+  if (pi && bucket && pi->bucket != bucket)
+    pi = NULL;
+
+  if (pi && class && pi->class != class)
+    pi = NULL;
+
+  if (pi)
+    {
+      pthread_mutex_lock (&_ports_lock);
+      pi->refcnt++;
+      pthread_mutex_unlock (&_ports_lock);
+    }
+
+  return pi;
+}
diff --git a/libports/ports.h b/libports/ports.h
index 0791841..2f63142 100644
--- a/libports/ports.h
+++ b/libports/ports.h
@@ -232,6 +232,12 @@ mach_port_t ports_get_send_right (void *port);
 void *ports_lookup_port (struct port_bucket *bucket,
                         mach_port_t port, struct port_class *class);
 
+/* Like ports_lookup_port, but uses PAYLOAD to look up the object.  If
+   this function is used, PAYLOAD must be a pointer to the port
+   structure.  */
+void *ports_lookup_payload (struct port_bucket *bucket,
+                            unsigned long payload, struct port_class *class);
+
 /* Allocate another reference to PORT. */
 void ports_port_ref (void *port);
 
-- 
1.7.10.4




reply via email to

[Prev in Thread] Current Thread [Next in Thread]