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 /libports/ports.h | |
parent | 9a5ede46033e225b870cd289221ac0608540a6d3 (diff) | |
download | hurd-92b49a0fc6f24cbd970f8a9f79cf2513cd58a1b3.tar.gz hurd-92b49a0fc6f24cbd970f8a9f79cf2513cd58a1b3.tar.bz2 hurd-92b49a0fc6f24cbd970f8a9f79cf2513cd58a1b3.zip |
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.
Diffstat (limited to 'libports/ports.h')
-rw-r--r-- | libports/ports.h | 53 |
1 files changed, 53 insertions, 0 deletions
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); |