From d4c0d603331166db1911dae5b05ecb1d5b970c44 Mon Sep 17 00:00:00 2001 From: Justus Winter <4winter@informatik.uni-hamburg.de> Date: Sat, 23 Nov 2013 16:19:08 +0100 Subject: [PATCH hurd 01/30] libports: add ports_lookup_payload * 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 | 40 ++++++++++++++++++++++++++++++++++++++++ libports/ports.h | 6 ++++++ 3 files changed, 47 insertions(+), 1 deletion(-) create mode 100644 libports/lookup-payload.c diff --git a/libports/Makefile b/libports/Makefile index 30da1c1..eb2cb8b 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..53c1b34 --- /dev/null +++ b/libports/lookup-payload.c @@ -0,0 +1,40 @@ +/* + 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 . */ + +#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) + refcounts_unsafe_ref (&pi->refcounts, NULL); + + return pi; +} diff --git a/libports/ports.h b/libports/ports.h index 652edb8..b650847 100644 --- a/libports/ports.h +++ b/libports/ports.h @@ -234,6 +234,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); -- 2.1.3