[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
hurd-l4/libhurd-cap cap-user.c cap.h
From: |
Marcus Brinkmann |
Subject: |
hurd-l4/libhurd-cap cap-user.c cap.h |
Date: |
Wed, 27 Aug 2003 18:52:00 -0400 |
CVSROOT: /cvsroot/hurd
Module name: hurd-l4
Branch:
Changes by: Marcus Brinkmann <address@hidden> 03/08/27 18:51:59
Modified files:
libhurd-cap : cap-user.c cap.h
Log message:
Some fixes to the enter function.
CVSWeb URLs:
http://savannah.gnu.org/cgi-bin/viewcvs/hurd/hurd-l4/libhurd-cap/cap-user.c.diff?tr1=1.5&tr2=1.6&r1=text&r2=text
http://savannah.gnu.org/cgi-bin/viewcvs/hurd/hurd-l4/libhurd-cap/cap.h.diff?tr1=1.4&tr2=1.5&r1=text&r2=text
Patches:
Index: hurd-l4/libhurd-cap/cap-user.c
diff -u hurd-l4/libhurd-cap/cap-user.c:1.5 hurd-l4/libhurd-cap/cap-user.c:1.6
--- hurd-l4/libhurd-cap/cap-user.c:1.5 Tue Aug 26 19:52:16 2003
+++ hurd-l4/libhurd-cap/cap-user.c Wed Aug 27 18:51:59 2003
@@ -1,4 +1,5 @@
-/* Copyright (C) 2003 Free Software Foundation, Inc.
+/* cap-user.c - User side of the capability implementation.
+ Copyright (C) 2003 Free Software Foundation, Inc.
Written by Marcus Brinkmann <address@hidden>
This file is part of the GNU Hurd.
@@ -28,14 +29,18 @@
#include "cap-intern.h"
+/* This hash table maps server thread IDs to server connections. */
static struct hurd_ihash server_to_sconn
= HURD_IHASH_INITIALIZER (HURD_IHASH_NO_LOCP);
+
+/* This lock protects SERVER_TO_SCONN. You can also lock server
+ connection objects while holding this lock. */
static pthread_mutex_t server_to_sconn_lock = PTHREAD_MUTEX_INITIALIZER;
/* Deallocate one reference for SCONN, which must be locked.
- SERVER_TO_SCONN_LOCK is not locked. Afterwards, SCONN is
- unlocked. */
+ SERVER_TO_SCONN_LOCK is not locked. Afterwards, SCONN is unlocked
+ (if it still exists). */
void
_hurd_cap_sconn_dealloc (hurd_cap_sconn_t sconn)
{
@@ -71,7 +76,8 @@
pthread_mutex_unlock (&sconn->lock);
pthread_mutex_destroy (&sconn->lock);
hurd_ihash_destroy (&sconn->id_to_cap);
- hurd_cap_deallocate (sconn->server_task_id);
+ if (sconn->server_task_id)
+ hurd_cap_deallocate (sconn->server_task_id);
free (sconn);
}
@@ -95,13 +101,12 @@
/* Enter a new send capability provided by the server SERVER_THREAD
(with the task ID reference SERVER_TASK_ID) and the cap ID SCID.
- The SERVER_TASK_ID reference is _not_ consumed but copied if
- necessary. If successful, the locked capability is returned with
- one (additional) reference in CAP. The server connection and
+ If successful, the locked capability is returned with one
+ (additional) reference in CAP. The server connection and
capability object are created if necessary. */
error_t
_hurd_cap_sconn_enter (l4_thread_id_t server_thread, uint32_t scid,
- task_id_t server_task_id, hurd_cap_t *cap)
+ hurd_cap_t *cap)
{
hurd_cap_sconn_t sconn;
int sconn_created = 0;
@@ -111,6 +116,11 @@
if (!sconn)
{
error_t err;
+ hurd_task_id_t server_task = hurd_task_id_from_thread_id (server_thread);
+ hurd_task_id_t taskserver_task;
+
+ taskserver_task = hurd_task_id_from_thread_id
+ (hurd_cap_get_thread_id (hurd_task_self()));
sconn = malloc (sizeof (*sconn));
if (!sconn)
@@ -125,10 +135,25 @@
pthread_mutex_unlock (&server_to_sconn_lock);
return errno;
}
- hurd_ihash_init (&sconn->id_to_cap);
+
+ if (server_task != taskserver_task)
+ {
+ err = hurd_task_info_create (hurd_task_self (),
+ server_task,
+ &sconn->server_task_id);
+ if (err)
+ {
+ pthread_mutex_destroy (&sconn->lock);
+ free (sconn);
+ pthread_mutex_unlock (&server_to_sconn_lock);
+ return errno;
+ }
+ }
+ else
+ sconn->server_task_id = 0;
+ hurd_ihash_init (&sconn->id_to_cap);
sconn->server_thread = server_thread;
- sconn->server_task_id = server_task_id;
sconn->refs = 0;
/* Enter the new server connection object. */
@@ -141,9 +166,6 @@
pthread_mutex_unlock (&server_to_sconn_lock);
return errno;
}
-
- /* FIXME: This could, theoretically, overflow. */
- hurd_cap_mod_refs (server_task_id, +1);
}
pthread_mutex_lock (&sconn->lock);
sconn->refs++;
Index: hurd-l4/libhurd-cap/cap.h
diff -u hurd-l4/libhurd-cap/cap.h:1.4 hurd-l4/libhurd-cap/cap.h:1.5
--- hurd-l4/libhurd-cap/cap.h:1.4 Sun Aug 17 01:48:22 2003
+++ hurd-l4/libhurd-cap/cap.h Wed Aug 27 18:51:59 2003
@@ -36,7 +36,8 @@
/* The server thread to which messages should be sent. */
l4_thread_id_t server_thread;
- /* A reference for the servers task ID to prevent reuse. */
+ /* A reference for the servers task ID to prevent reuse. This is 0
+ if this is the connection to the task server itself. */
task_id_t server_task_id;
/* The lock protecting the variable members of the server connection
@@ -81,7 +82,7 @@
the capability is dead. */
hurd_cap_sconn_t sconn;
- /* The task-specific ID for this capability. Only valid id SCONN is
+ /* The task-specific ID for this capability. Only valid if SCONN is
not NULL. */
hurd_cap_scid_t scid;