summaryrefslogtreecommitdiff
path: root/libhurd-cap-server/obj-copy-out.c
diff options
context:
space:
mode:
authormarcus <marcus>2004-04-08 00:40:38 +0000
committermarcus <marcus>2004-04-08 00:40:38 +0000
commitd6c70dba6b1f3cb64c38fbaa4c8b14dbb257a10c (patch)
tree153d25793fb71603311f2c2d17309bcfe2f88537 /libhurd-cap-server/obj-copy-out.c
parenta93fd7dadd804e2765de74a8792d2608505ed93c (diff)
2004-04-08 Marcus Brinkmann <marcus@gnu.org>
* bucket-inject.c, obj-copy-out.c: New files. * Makefile.am (libhurd_cap_server_a_SOURCES): Add bucket-inject.c and obj-copy-out.c * bucket-create.c (hurd_cap_bucket_create): Initialize members is_managed, nr_caps, waiting_rpcs of BUCKET. Set R_BUCKET. * cap-server-intern.h (_hurd_cap_client_dealloc): Add new argument BUCKET to prototype. (struct hurd_cap_client): Remove declaration. (struct _hurd_cap_list_item): Add new member tid. Change type for member client to _hurd_cap_client_t. (_hurd_cap_list_item_add, _hurd_cap_list_item_remove, _hurd_cap_list_item_dequeued): New inline functions. (struct _hurd_cap_obj_entry): Rename member IDX to ID. (_hurd_cap_obj_copy_out): New prototype. (_hurd_cap_client_create): Remove argument R_IDX from prototype. (struct _hurd_cap_bucket): Add new members MANAGER, IS_MANAGED, IS_MANAGER_WAITING, NR_CAPS, WAITING_RPCS, and FREE_WORKER. (_hurd_cap_client_t): Type definition moved to ... * cap-server.h (_hurd_cap_client_t): Here. (struct _hurd_cap_client_t): New declaration. (struct hurd_cap_rpc_context): Define it. (hurd_cap_class_demux_t): Renamed to ... (hurd_cap_class_demuxer_t): ... this. (hurd_cap_class_create, hurd_cap_class_init): Use new type for demuxer argument in prototype. (hurd_cap_bucket_inject): New prototype. * cap-server.h: Include <hurd/types.h> * class-create (hurd_cap_class_create): Use new type for demuxer argument. Set R_CLASS. * class-init (hurd_cap_class_init): Use new type for demuxer argument. * client-release.c (_hurd_cap_client_dealloc): Take new argument BUCKET. New local variable NR_CAPS. Keep track of number of capabilities removed. Update BUCKET->nr_caps before return. (_hurd_cap_client_release): Pass new argument BUCKET to _hurd_cap_client_release. * client-create.c (_hurd_cap_client_create): Remove argument R_IDX. Consequently, do not set R_IDX anymore. Set R_CLIENT. Pass new argument BUCKET to _hurd_cap_client_dealloc. * bucket-inhibit.c (hurd_cap_bucket_end): Check BUCKET->nr_caps if FORCE flag is not set. Cancel the manager thread if needed. (_hurd_cap_bucket_cond_busy): Move to ... * cap-server-intern.h (_hurd_cap_bucket_cond_busy): ... here. Add attribute always-inline. (_hurd_cap_bucket_cond_check): New inline function. * client-inhibit.c (_hurd_cap_client_cond_busy): Move to ... * cap-server-intern.h (_hurd_cap_client_cond_busy): ... here. Add attribute always-inline. (_hurd_cap_client_cond_check): New inline function. * class-inhibit.c (_hurd_cap_class_cond_busy): Move to ... * cap-server-intern.h (_hurd_cap_class_cond_busy): ... here. Add attribute always-inline. (_hurd_cap_class_cond_check): New inline function. * obj-inhibit.c (_hurd_cap_obj_cond_busy): Move to ... * cap-server-intern.h (_hurd_cap_obj_cond_busy): ... here. Add attribute always-inline. (_hurd_cap_obj_cond_check): New inline function.
Diffstat (limited to 'libhurd-cap-server/obj-copy-out.c')
-rw-r--r--libhurd-cap-server/obj-copy-out.c118
1 files changed, 118 insertions, 0 deletions
diff --git a/libhurd-cap-server/obj-copy-out.c b/libhurd-cap-server/obj-copy-out.c
new file mode 100644
index 0000000..1edfe7d
--- /dev/null
+++ b/libhurd-cap-server/obj-copy-out.c
@@ -0,0 +1,118 @@
+/* obj-copy-out.c - Copy out a capability to a client.
+ Copyright (C) 2004 Free Software Foundation, Inc.
+ Written by Marcus Brinkmann <marcus@gnu.org>
+
+ This file is part of the GNU Hurd.
+
+ This program is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ This program 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
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with this program; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#if HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include <errno.h>
+#include <pthread.h>
+#include <stdlib.h>
+
+#include "cap-server-intern.h"
+
+
+/* Copy out a capability for the capability OBJ to the user CLIENT.
+ Returns the capability ID (valid only for this user) in *R_ID, or
+ an error. OBJ must be locked. Note: No internal reference for
+ this capability is allocated for the caller. */
+error_t
+_hurd_cap_obj_copy_out (hurd_cap_obj_t obj, hurd_cap_bucket_t bucket,
+ _hurd_cap_client_t client, hurd_cap_id_t *r_id)
+{
+ _hurd_cap_obj_entry_t entry;
+
+ pthread_mutex_lock (&client->lock);
+ entry = (_hurd_cap_obj_entry_t) hurd_ihash_find (&client->caps_reverse,
+ (hurd_ihash_key_t) obj);
+
+ if (entry)
+ {
+ entry->external_refs++;
+ *r_id = entry->id;
+ pthread_mutex_unlock (&client->lock);
+ return 0;
+ }
+ else
+ {
+ _hurd_cap_obj_entry_t entry_check;
+ error_t err;
+
+ pthread_mutex_unlock (&client->lock);
+ err = hurd_slab_alloc (&_hurd_cap_obj_entry_space, (void **) &entry);
+ if (err)
+ return err;
+
+ entry->cap_obj = obj;
+ /* ID is filled in when adding the object to the table. */
+ /* CLIENT_ITEM is filled after the object has been entered. */
+ /* DEAD is 0 for initialized objects. */
+ /* INTERNAL_REFS is 1 for initialized objects. */
+ /* EXTERNAL_REFS is 1 for initialized objects. */
+
+ pthread_mutex_lock (&client->lock);
+ entry_check = hurd_ihash_find (&client->caps_reverse,
+ (hurd_ihash_key_t) obj);
+ if (entry_check)
+ {
+ /* Somebody else was faster. */
+ entry_check->external_refs++;
+ *r_id = entry_check->id;
+ pthread_mutex_unlock (&client->lock);
+ hurd_slab_dealloc (&_hurd_cap_obj_entry_space, entry);
+ return 0;
+ }
+
+ /* Add the entry to the caps table of the client. */
+ err = hurd_table_enter (&client->caps, &entry, &entry->id);
+ if (err)
+ {
+ pthread_mutex_unlock (&client->lock);
+ hurd_slab_dealloc (&_hurd_cap_obj_entry_space, entry);
+ return err;
+ }
+ err = hurd_ihash_add (&client->caps_reverse,
+ (hurd_ihash_key_t) obj, entry);
+ if (err)
+ {
+ hurd_table_remove (&client->caps, entry->id);
+ pthread_mutex_unlock (&client->lock);
+ hurd_slab_dealloc (&_hurd_cap_obj_entry_space, entry);
+ return err;
+ }
+
+ pthread_mutex_unlock (&client->lock);
+
+ /* Add the object to the list. */
+ _hurd_cap_list_item_add (&obj->clients, &entry->client_item);
+
+ /* Add a reference for the internal reference of the capability
+ entry to the capability object. */
+ obj->refs++;
+
+ /* FIXME: Should probably use spin lock here, or so. */
+ pthread_mutex_lock (&bucket->lock);
+ bucket->nr_caps++;
+ pthread_mutex_unlock (&bucket->lock);
+
+ return 0;
+ }
+}