diff options
author | Justus Winter <4winter@informatik.uni-hamburg.de> | 2013-11-23 16:19:08 +0100 |
---|---|---|
committer | Justus Winter <4winter@informatik.uni-hamburg.de> | 2014-12-07 15:38:17 +0100 |
commit | 92b49a0fc6f24cbd970f8a9f79cf2513cd58a1b3 (patch) | |
tree | 6e0105a70e498ca059433e87d679dc82f065015a | |
parent | 9a5ede46033e225b870cd289221ac0608540a6d3 (diff) |
libports: add `ports_lookup_payload' and `ports_payload_get_name'
These two functions map payloads to objects and port names. The former
can be used like `ports_lookup_port' to look up objects, the latter to
map payloads to port names if the server function expects a
`mach_port_t'.
* libports/ports.h: Add function ports_payload_get_name.
* libports/lookup-payload.c: New file.
* libports/ports.h (ports_lookup_payload): Add declaration.
* libports/Makefile (SRCS): Add lookup-payload.c.
-rw-r--r-- | libports/Makefile | 2 | ||||
-rw-r--r-- | libports/extern-inline.c | 22 | ||||
-rw-r--r-- | libports/ports.h | 53 |
3 files changed, 76 insertions, 1 deletions
diff --git a/libports/Makefile b/libports/Makefile index 30da1c11..f49cb9fd 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 extern-inline.c installhdrs = ports.h diff --git a/libports/extern-inline.c b/libports/extern-inline.c new file mode 100644 index 00000000..fbc9e539 --- /dev/null +++ b/libports/extern-inline.c @@ -0,0 +1,22 @@ +/* Run time callable functions for extern inlines. + Copyright (C) 2014 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/>. */ + +#define PORTS_DEFINE_EI +#include "ports.h" diff --git a/libports/ports.h b/libports/ports.h index 652edb88..a625b479 100644 --- a/libports/ports.h +++ b/libports/ports.h @@ -29,6 +29,12 @@ #include <pthread.h> #include <refcount.h> +#ifdef PORTS_DEFINE_EI +#define PORTS_EI +#else +#define PORTS_EI __extern_inline +#endif + /* These are global values for common flags used in the various structures. Not all of these are meaningful in all flag fields. */ #define PORTS_INHIBITED 0x0100 /* block RPC's */ @@ -234,6 +240,53 @@ 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. */ +extern void *ports_lookup_payload (struct port_bucket *bucket, + unsigned long payload, + struct port_class *class); + +/* This returns the ports name. This function can be used as + intranpayload function turning payloads back into port names. If + this function is used, PAYLOAD must be a pointer to the port + structure. */ +extern mach_port_t ports_payload_get_name (unsigned int payload); + +#if defined(__USE_EXTERN_INLINES) || defined(PORTS_DEFINE_EI) + +PORTS_EI 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) + refcounts_unsafe_ref (&pi->refcounts, NULL); + + return pi; +} + +PORTS_EI mach_port_t +ports_payload_get_name (unsigned int payload) +{ + struct port_info *pi = (struct port_info *) payload; + + if (pi) + return pi->port_right; + + return MACH_PORT_NULL; +} + +#endif /* Use extern inlines. */ + /* Allocate another reference to PORT. */ void ports_port_ref (void *port); |