diff options
Diffstat (limited to 'libiohelp')
-rw-r--r-- | libiohelp/ChangeLog | 106 | ||||
-rw-r--r-- | libiohelp/Makefile | 31 | ||||
-rw-r--r-- | libiohelp/get_conch.c | 57 | ||||
-rw-r--r-- | libiohelp/handle_io_get_conch.c | 50 | ||||
-rw-r--r-- | libiohelp/handle_io_release_conch.c | 41 | ||||
-rw-r--r-- | libiohelp/initialize_conch.c | 30 | ||||
-rw-r--r-- | libiohelp/iohelp.h | 107 | ||||
-rw-r--r-- | libiohelp/iouser-create.c | 33 | ||||
-rw-r--r-- | libiohelp/iouser-dup.c | 51 | ||||
-rw-r--r-- | libiohelp/iouser-free.c | 28 | ||||
-rw-r--r-- | libiohelp/iouser-reauth.c | 102 | ||||
-rw-r--r-- | libiohelp/return-buffer.c | 54 | ||||
-rw-r--r-- | libiohelp/shared.c | 41 | ||||
-rw-r--r-- | libiohelp/verify_user_conch.c | 40 |
14 files changed, 771 insertions, 0 deletions
diff --git a/libiohelp/ChangeLog b/libiohelp/ChangeLog new file mode 100644 index 00000000..0388b756 --- /dev/null +++ b/libiohelp/ChangeLog @@ -0,0 +1,106 @@ +1999-07-11 Thomas Bushnell, BSG <tb@mit.edu> + + * return-buffer.c: Include <sys/mman.h>. + + * iouser-reauth.c (iohelp_reauth): Cast first arg to munmap + correctly. + +1999-07-10 Roland McGrath <roland@baalperazim.frob.com> + + * iouser-reauth.c: Add #include <sys/mman.h> for munmap decl. + +1999-07-09 Thomas Bushnell, BSG <tb@mit.edu> + + * return-buffer.c (iohelp_return_malloced_buffer): Use mmap + instead of vm_allocate. + +1999-07-03 Thomas Bushnell, BSG <tb@mit.edu> + + * iouser-reauth.c (iohelp_reauth): Use munmap instead of + vm_deallocate. + +1998-08-21 Roland McGrath <roland@baalperazim.frob.com> + + * Makefile (SRCS): Add return-buffer.c. + +1998-08-20 Roland McGrath <roland@baalperazim.frob.com> + + * return-buffer.c (iohelp_return_malloced_buffer): Moved here from + ../libfshelp/return-buffer.c and renamed from fshelp to iohelp. + * iohelp.h (iohelp_return_malloced_buffer): Declare it. + +Mon Nov 18 16:37:59 1996 Thomas Bushnell, n/BSG <thomas@gnu.ai.mit.edu> + + * iouser-reauth.c: Include <hurd/auth.h>. + +Sat Nov 16 17:54:50 1996 Thomas Bushnell, n/BSG <thomas@gnu.ai.mit.edu> + + * Makefile (SRCS): Add shared.c. + * shared.c: New file. + +Fri Nov 15 13:39:46 1996 Thomas Bushnell, n/BSG <thomas@gnu.ai.mit.edu> + + * iouser-create.c (iohelp_create_iouser): Set NEW->hook to zero. + * iouser-dup.c (iohelp_dup_iouser): Likewise. + +Tue Nov 12 21:51:29 1996 Thomas Bushnell, n/BSG <thomas@gnu.ai.mit.edu> + + * iohelp.h: Include <idvec.h>. + +Wed Nov 6 19:26:14 1996 Thomas Bushnell, n/BSG <thomas@gnu.ai.mit.edu> + + * Makefile (SRCS): Add iouser-create.c, iouser-dup.c + iouser-reauth.c, and iouser-free.c. + (OBJS): Compute automatically. + + * iohelp.h (iohelp_create_user): New function. + * iouser-create.c: New file. + +Tue Nov 5 21:51:24 1996 Thomas Bushnell, n/BSG <thomas@gnu.ai.mit.edu> + + * iohelp.h (struct iouser): New type. + (iohelp_dup_iouser, iohelp_free_iouser, iohelp_reauth): New + functions. + * iouser-dup.c, iouser-reauth.c, iouser-free.c: New files. + +Thu Sep 12 16:18:46 1996 Thomas Bushnell, n/BSG <thomas@gnu.ai.mit.edu> + + * Makefile (HURDLIBS): New variable. + (libfshelp.so): Delete special dependency. + +Thu May 9 12:42:51 1996 Michael I. Bushnell, p/BSG <mib@gnu.ai.mit.edu> + + * Makefile: All occurrences of `ioserver' replaced with `iohelp'. + +Mon May 6 16:27:20 1996 Michael I. Bushnell, p/BSG <mib@gnu.ai.mit.edu> + + * iohelp.h: Renamed from `ioserver.h'. All local includes + updated. + * get_conch.c: All occurrences of `ioserver' replaced with + `iohelp'. + * handle_io_get_conch.c: Likewise. + * handle_io_release_conch.c: Likewise. + * initialize_conch.c: Likewise. + * verify_user_conch.c: Likewise. + * iohelp.h: Likewise. + +Mon Oct 9 14:57:48 1995 Roland McGrath <roland@churchy.gnu.ai.mit.edu> + + * Makefile: Specify shared library dependencies. + +Thu Jul 6 15:35:56 1995 Michael I Bushnell <mib@duality.gnu.ai.mit.edu> + + * Makefile: Removed dependencies that are now automatically + generated. + +Fri Jul 22 11:43:56 1994 Michael I Bushnell <mib@geech.gnu.ai.mit.edu> + + * Makefile: Converted to new scheme. + +Tue Jul 5 14:13:09 1994 Michael I Bushnell (mib@churchy.gnu.ai.mit.edu) + + * Makefile (TAGSHDRS): New variable. + +Thu May 5 07:48:45 1994 Roland McGrath (roland@churchy.gnu.ai.mit.edu) + + * Makefile: Change uses of $(headers) to $(includedir). diff --git a/libiohelp/Makefile b/libiohelp/Makefile new file mode 100644 index 00000000..d2680665 --- /dev/null +++ b/libiohelp/Makefile @@ -0,0 +1,31 @@ +# +# Copyright (C) 1993, 94, 95, 96, 98 Free Software Foundation, Inc. +# +# This program 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. +# +# 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 +# General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + +dir := libiohelp +makemode := library + +SRCS = get_conch.c handle_io_get_conch.c handle_io_release_conch.c \ + initialize_conch.c verify_user_conch.c iouser-create.c \ + iouser-dup.c iouser-reauth.c iouser-free.c shared.c \ + return-buffer.c +OBJS = $(SRCS:.c=.o) +LCLHDRS = iohelp.h +HURDLIBS = threads +libname = libiohelp +installhdrs = iohelp.h + +include ../Makeconf diff --git a/libiohelp/get_conch.c b/libiohelp/get_conch.c new file mode 100644 index 00000000..64d347ab --- /dev/null +++ b/libiohelp/get_conch.c @@ -0,0 +1,57 @@ +/* + Copyright (C) 1993, 1994, 1996 Free Software Foundation + + This program 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. + + 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 + General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ + +#include "iohelp.h" + +/* The conch must be locked when calling this routine. */ +/* Remove any current holder of conch C. */ +void +iohelp_get_conch (struct conch *c) +{ + struct shared_io *user_sh; + + again: + user_sh = c->holder_shared_page; + + if (user_sh) + { + spin_lock (&user_sh->lock); + switch (user_sh->conch_status) + { + case USER_HAS_CONCH: + user_sh->conch_status = USER_RELEASE_CONCH; + /* fall through ... */ + case USER_RELEASE_CONCH: + spin_unlock (&user_sh->lock); + condition_wait (&c->wait, c->lock); + /* Anything can have happened */ + goto again; + + case USER_COULD_HAVE_CONCH: + user_sh->conch_status = USER_HAS_NOT_CONCH; + spin_unlock (&user_sh->lock); + iohelp_fetch_shared_data (c->holder); + break; + + case USER_HAS_NOT_CONCH: + spin_unlock (&user_sh->lock); + break; + } + } + c->holder = 0; + c->holder_shared_page = 0; +} diff --git a/libiohelp/handle_io_get_conch.c b/libiohelp/handle_io_get_conch.c new file mode 100644 index 00000000..452b3cfb --- /dev/null +++ b/libiohelp/handle_io_get_conch.c @@ -0,0 +1,50 @@ +/* + Copyright (C) 19931996 Free Software Foundation + + This program 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. + + 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 + General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ + + +#include "iohelp.h" + +/* Called by an I/O server when an io_get_conch message is received. + The user represented by USER and USER_SH wants conch C; give it + to her or return an error. */ +void +iohelp_handle_io_get_conch (struct conch *c, void *user, + struct shared_io *user_sh) +{ + + if (c->holder == user) + { + if (user_sh->conch_status != USER_HAS_NOT_CONCH) + iohelp_fetch_shared_data (user); + else + user_sh->accessed = user_sh->written = 0; + + iohelp_put_shared_data (user); + user_sh->conch_status = USER_HAS_CONCH; + } + else + { + iohelp_get_conch (c); + + c->holder = user; + c->holder_shared_page = user_sh; + if (user_sh->conch_status == USER_HAS_NOT_CONCH) + user_sh->accessed = user_sh->written = 0; + user_sh->conch_status = USER_HAS_CONCH; + iohelp_put_shared_data (user); + } +} diff --git a/libiohelp/handle_io_release_conch.c b/libiohelp/handle_io_release_conch.c new file mode 100644 index 00000000..fa95a6e5 --- /dev/null +++ b/libiohelp/handle_io_release_conch.c @@ -0,0 +1,41 @@ +/* + Copyright (C) 1993, 1994, 1996 Free Software Foundation + + This program 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. + + 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 + General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ + +#include "iohelp.h" + +/* Called by an I/O server upon receipt of an io_release_conch message; + The user identified by USER is done with conch C; release it and + allow a waiting user to obtain the conch. */ +void +iohelp_handle_io_release_conch (struct conch *c, void *user) +{ + + if (c->holder_shared_page->conch_status != USER_HAS_NOT_CONCH) + { + c->holder_shared_page->conch_status = USER_HAS_NOT_CONCH; + iohelp_fetch_shared_data (c->holder); + } + + if (c->holder == user) + { + c->holder = 0; + c->holder_shared_page = 0; + } + + condition_broadcast (&c->wait); +} + diff --git a/libiohelp/initialize_conch.c b/libiohelp/initialize_conch.c new file mode 100644 index 00000000..a5d5b76e --- /dev/null +++ b/libiohelp/initialize_conch.c @@ -0,0 +1,30 @@ +/* + Copyright (C) 1993, 1994, 1996 Free Software Foundation + + This program 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. + + 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 + General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ + +#include "iohelp.h" + +/* Called by an I/O server to initialize a conch structure C; + M will be used to lock conch data structures. */ +void +iohelp_initialize_conch (struct conch *c, struct mutex *m) +{ + c->lock = m; + condition_init (&c->wait); + c->holder = 0; + c->holder_shared_page = 0; +} + diff --git a/libiohelp/iohelp.h b/libiohelp/iohelp.h new file mode 100644 index 00000000..13af41e5 --- /dev/null +++ b/libiohelp/iohelp.h @@ -0,0 +1,107 @@ +/* Library providing helper functions for io servers. + Copyright (C) 1993, 94, 96, 98 Free Software Foundation, Inc. + + This program 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. + + 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 + General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ + +#ifndef _HURD_IOHELP_ +#define _HURD_IOHELP_ + +#include <mach.h> +#include <hurd/hurd_types.h> +#include <cthreads.h> +#include <hurd/shared.h> + +/* Conch manipulation. */ +struct conch +{ + struct mutex *lock; + struct condition wait; + void *holder; + struct shared_io *holder_shared_page; +}; + +/* Initialize a conch box */ +void iohelp_initialize_conch (struct conch *, struct mutex *); + +/* These routines are not reentrant. The server is responsible + for ensuring that all calls to these routines are serialized + by locking the lock passed to initialize_conch. */ + +/* Handle a user request to obtain the conch (io_get_conch) */ +void iohelp_handle_io_get_conch (struct conch *, void *, + struct shared_io *); + +/* Obtain the conch for the server */ +void iohelp_get_conch (struct conch *); + +/* Handle a user request to release the conch (io_release_conch). */ +void iohelp_handle_io_release_conch (struct conch *, void *); + +/* Check if the user is allowed to make a shared-data notification + message. */ +error_t iohelp_verify_user_conch (struct conch *, void *); + +/* This function must by defined by the server. It should transfer + information from the current conch holder's shared page to the server's + data (the arg is the conch owner). */ +void iohelp_fetch_shared_data (void *); + +/* This function must be defined by the server. It should transfer + information from the server's data to the current conch holder's + shared page (the arg is the conch owner). */ +void iohelp_put_shared_data (void *); + + + +/* User identification */ + +#include <idvec.h> + +struct iouser +{ + struct idvec *uids, *gids; + void *hook; /* Never used by iohelp library */ +}; + +/* Return a copy of IOUSER. */ +struct iouser *iohelp_dup_iouser (struct iouser *iouser); + +/* Free a reference to IOUSER. */ +void iohelp_free_iouser (struct iouser *iouser); + +/* Create a new IOUSER for the specified idvecs */ +struct iouser *iohelp_create_iouser (struct idvec *uids, struct idvec *gids); + +/* Conduct a reauthentication transaction, returning a new iouser. + AUTHSERVER is the I/O servers auth port. The rendezvous port + provided by the user is REND_PORT. If the transaction cannot be + completed, return zero, unless PERMIT_FAILURE is non-zero. If + PERMIT_FAILURE is nonzero, then should the transaction fail, return + an iouser that has no ids. The new port to be sent to the user is + newright. */ +struct iouser *iohelp_reauth (auth_t authserver, mach_port_t rend_port, + mach_port_t newright, int permit_failure); + + +/* Puts data from the malloced buffer BUF, LEN bytes long, into RBUF & RLEN, + suitable for returning from a mach rpc. If LEN > 0, BUF is freed, + regardless of whether an error is returned or not. */ +error_t iohelp_return_malloced_buffer (char *buf, size_t len, + char **rbuf, + mach_msg_type_number_t *rlen); + + + +#endif diff --git a/libiohelp/iouser-create.c b/libiohelp/iouser-create.c new file mode 100644 index 00000000..fab77787 --- /dev/null +++ b/libiohelp/iouser-create.c @@ -0,0 +1,33 @@ +/* + Copyright (C) 1996 Free Software Foundation + + This program 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. + + 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 + General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ + +#include "iohelp.h" + +struct iouser * +iohelp_create_iouser (struct idvec *uids, struct idvec *gids) +{ + struct iouser *new; + new = malloc (sizeof (struct iouser)); + if (!new) + return 0; + + new->uids = uids; + new->gids = gids; + new->hook = 0; + return new; +} + diff --git a/libiohelp/iouser-dup.c b/libiohelp/iouser-dup.c new file mode 100644 index 00000000..7bc1f87f --- /dev/null +++ b/libiohelp/iouser-dup.c @@ -0,0 +1,51 @@ +/* + Copyright (C) 1996 Free Software Foundation + + This program 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. + + 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 + General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ + +#include "iohelp.h" + +struct iouser * +iohelp_dup_iouser (struct iouser *iouser) +{ + struct iouser *new; + error_t err = 0; + + new = malloc (sizeof (struct iouser)); + if (!new) + return 0; + + new->uids = make_idvec (); + new->gids = make_idvec (); + new->hook = 0; + if (!new->uids || !new->gids) + goto lose; + + err = idvec_set (new->uids, iouser->uids); + if (!err) + err = idvec_set (new->gids, iouser->gids); + + if (err) + { + lose: + if (new->uids) + idvec_free (new->uids); + if (new->gids) + idvec_free (new->gids); + free (new); + return 0; + } + return new; +} diff --git a/libiohelp/iouser-free.c b/libiohelp/iouser-free.c new file mode 100644 index 00000000..4cfdc954 --- /dev/null +++ b/libiohelp/iouser-free.c @@ -0,0 +1,28 @@ +/* + Copyright (C) 1996 Free Software Foundation + + This program 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. + + 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 + General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ + +#include "iohelp.h" + +void +iohelp_free_iouser (struct iouser *iouser) +{ + idvec_free (iouser->uids); + idvec_free (iouser->gids); + free (iouser); +} + + diff --git a/libiohelp/iouser-reauth.c b/libiohelp/iouser-reauth.c new file mode 100644 index 00000000..3514b5d8 --- /dev/null +++ b/libiohelp/iouser-reauth.c @@ -0,0 +1,102 @@ +/* + Copyright (C) 1996, 1999 Free Software Foundation + + This program 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. + + 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 + General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ + +#include "iohelp.h" +#include <hurd/auth.h> +#include <sys/mman.h> + +/* Conduct a reauthentication transaction, returning a new iouser. + AUTHSERVER is the I/O servers auth port. The rendezvous port + provided by the user is REND_PORT. If the transaction cannot be + completed, return zero, unless PERMIT_FAILURE is non-zero. If + PERMIT_FAILURE is nonzero, then should the transaction fail, return + an iouser that has no ids. The new port to be sent to the user is + newright. */ +struct iouser *iohelp_reauth (auth_t authserver, mach_port_t rend_port, + mach_port_t newright, int permit_failure) +{ + uid_t gubuf[20], ggbuf[20], aubuf[20], agbuf[20]; + uid_t *gen_uids, *gen_gids, *aux_uids, *aux_gids; + u_int genuidlen, gengidlen, auxuidlen, auxgidlen; + error_t err; + struct iouser *new; + + new = malloc (sizeof (struct iouser)); + if (!new) + return 0; + + new->uids = make_idvec (); + new->gids = make_idvec (); + if (!new->uids || !new->gids) + { + if (new->uids) + idvec_free (new->uids); + if (new->gids) + idvec_free (new->gids); + free (new); + return 0; + } + + genuidlen = gengidlen = auxuidlen = auxgidlen = 20; + gen_uids = gubuf; + gen_gids = ggbuf; + aux_uids = aubuf; + aux_gids = agbuf; + + do + err = auth_server_authenticate (authserver, + rend_port, + MACH_MSG_TYPE_COPY_SEND, + newright, + MACH_MSG_TYPE_COPY_SEND, + &gen_uids, &genuidlen, + &aux_uids, &auxuidlen, + &gen_gids, &gengidlen, + &aux_gids, &auxgidlen); + while (err == EINTR); + + if (err) + { + if (permit_failure) + genuidlen = gengidlen = 0; + else + goto out; + } + + err = idvec_set_ids (new->uids, gen_uids, genuidlen); + if (!err) + err = idvec_set_ids (new->gids, gen_gids, gengidlen); + + if (gubuf != gen_uids) + munmap ((caddr_t) gen_uids, genuidlen * sizeof (uid_t)); + if (ggbuf != gen_gids) + munmap ((caddr_t) gen_gids, gengidlen * sizeof (uid_t)); + if (aubuf != aux_uids) + munmap ((caddr_t) aux_uids, auxuidlen * sizeof (uid_t)); + if (agbuf != aux_gids) + munmap ((caddr_t) aux_gids, auxgidlen * sizeof (uid_t)); + + if (err) + { + out: + idvec_free (new->uids); + idvec_free (new->gids); + free (new); + return 0; + } + return new; +} diff --git a/libiohelp/return-buffer.c b/libiohelp/return-buffer.c new file mode 100644 index 00000000..3095dfb6 --- /dev/null +++ b/libiohelp/return-buffer.c @@ -0,0 +1,54 @@ +/* Make a malloced buffer suitable for returning from a mach rpc + + Copyright (C) 1996, 1998, 1999 Free Software Foundation, Inc. + + Written by Miles Bader <miles@gnu.org> + + 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 this program; if not, write to the Free Software Foundation, Inc., + 675 Mass Ave, Cambridge, MA 02139, USA. */ + +#include <string.h> +#include <mach.h> +#include <sys/mman.h> + +#include "iohelp.h" + +/* Puts data from the malloced buffer BUF, LEN bytes long, into RBUF & RLEN, + suitable for returning from a mach rpc. If LEN > 0, BUF is freed, + regardless of whether an error is returned or not. */ +error_t +iohelp_return_malloced_buffer (char *buf, size_t len, + char **rbuf, mach_msg_type_number_t *rlen) +{ + error_t err = 0; + + if (*rlen < len) + { + *rbuf = mmap (0, len, PROT_READ|PROT_WRITE, MAP_ANON, 0, 0); + err = (*rbuf == (char *) -1) ? errno : 0; + } + if (! err) + { + if (len) + bcopy (buf, *rbuf, len); + *rlen = len; + } + + if (len > 0) + free (buf); + + return err; +} diff --git a/libiohelp/shared.c b/libiohelp/shared.c new file mode 100644 index 00000000..42180985 --- /dev/null +++ b/libiohelp/shared.c @@ -0,0 +1,41 @@ +/* Default functions + Copyright (C) 1996 Free Software Foundation + + This program 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. + + 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 + General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ + + +#include "iohelp.h" + +/* These definitions exist to satisfy the linker. */ + + +void +iohelp_fetch_shared_data (void *foo) +{ + abort (); +} + +void +iohelp_put_shared_data (void *foo) +{ + abort (); +} + + +void +iohelp_fetch_shared_data (void *foo) __attribute__ ((weak)); +void +iohelp_put_shared_data (void *foo) __attribute__ ((weak)); + diff --git a/libiohelp/verify_user_conch.c b/libiohelp/verify_user_conch.c new file mode 100644 index 00000000..c7e3e62e --- /dev/null +++ b/libiohelp/verify_user_conch.c @@ -0,0 +1,40 @@ +/* + Copyright (C) 1993, 1994, 1996 Free Software Foundation + + This program 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. + + 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 + General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ + +#include "iohelp.h" +#include <errno.h> + +/* Check to see if the user identified by USER has conch C; if not, + return an error, else, return 0. */ +error_t +iohelp_verify_user_conch (struct conch *c, void *user) +{ + struct shared_io *user_sh; + + if (user != c->holder) + return EPERM; + user_sh = c->holder_shared_page; + spin_lock (&user_sh->lock); + if (user_sh->conch_status != USER_HAS_CONCH + && user_sh->conch_status != USER_RELEASE_CONCH) + { + spin_unlock (&user_sh->lock); + return EPERM; + } + spin_unlock (&user_sh->lock); + return 0; +} |