diff options
-rw-r--r-- | Makefile | 4 | ||||
-rw-r--r-- | mig-decls.h | 47 | ||||
-rw-r--r-- | mig-mutate.h | 25 | ||||
-rw-r--r-- | random.c | 55 |
4 files changed, 101 insertions, 30 deletions
@@ -24,6 +24,8 @@ target = random SRCS = random.c gnupg-random.c gnupg-rmd160.c OBJS = $(SRCS:.c=.o) startup_notifyServer.o LCLHDRS = gnupg-random.h gnupg-rmd.h gnupg-bithelp.h random.h -HURDLIBS = trivfs threads ports fshelp ihash shouldbeinlibc +HURDLIBS = trivfs ports fshelp ihash shouldbeinlibc +OTHERLIBS = -lpthread +MIGSFLAGS = -DSEQNOS -imacros $(srcdir)/mig-mutate.h include ../Makeconf diff --git a/mig-decls.h b/mig-decls.h new file mode 100644 index 00000000..87b7eb2a --- /dev/null +++ b/mig-decls.h @@ -0,0 +1,47 @@ +/* + Copyright (C) 2014 Free Software Foundation, Inc. + Written by Justus Winter. + + 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 <http://www.gnu.org/licenses/>. */ + +#ifndef __RANDOM_MIG_DECLS_H__ +#define __RANDOM_MIG_DECLS_H__ + +#include <hurd/ports.h> + +typedef struct port_info *port_info_t; + +extern struct trivfs_control *fsys; +extern struct port_class *shutdown_notify_class; + +/* Called by server stub functions. */ + +static inline struct port_info * __attribute__ ((unused)) +begin_using_startup_port (mach_port_t port) +{ + return ports_lookup_port (fsys->pi.bucket, + handle, + shutdown_notify_class); +} + +static inline void __attribute__ ((unused)) +end_using_startup (struct port_info *p) +{ + if (p) + ports_port_deref (p); +} + +#endif /* __RANDOM_MIG_DECLS_H__ */ diff --git a/mig-mutate.h b/mig-mutate.h new file mode 100644 index 00000000..dab89e56 --- /dev/null +++ b/mig-mutate.h @@ -0,0 +1,25 @@ +/* + Copyright (C) 2014 Free Software Foundation, Inc. + Written by Justus Winter. + + 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 <http://www.gnu.org/licenses/>. */ + +#define STARTUP_INTRAN \ + port_info_t begin_using_startup_port (mach_port_t) +#define STARTUP_DESTRUCTOR \ + end_using_startup (port_info_t) +#define STARTUP_IMPORTS \ + import "mig-decls.h"; @@ -27,8 +27,8 @@ #include <string.h> #include <fcntl.h> #include <sys/mman.h> -#include <cthreads.h> -#include <rwlock.h> +#include <pthread.h> +#include <assert.h> #include <version.h> @@ -39,8 +39,8 @@ struct trivfs_control *fsys; int read_blocked; /* For read and select. */ -struct condition wait; /* For read and select. */ -struct condition select_alert; /* For read and select. */ +pthread_cond_t wait; /* For read and select. */ +pthread_cond_t select_alert; /* For read and select. */ /* The quality of randomness we provide. @@ -105,7 +105,7 @@ gather_random( void (*add)(const void*, size_t, int), int requester, const char *argp_program_version = STANDARD_HURD_VERSION (random); /* This lock protects the GnuPG code. */ -static struct mutex global_lock; +static pthread_mutex_t global_lock; /* Trivfs hooks. */ int trivfs_fstype = FSTYPE_MISC; @@ -148,7 +148,7 @@ trivfs_S_io_read (struct trivfs_protid *cred, else if (! (cred->po->openmodes & O_READ)) return EBADF; - mutex_lock (&global_lock); + pthread_mutex_lock (&global_lock); if (amount > 0) { @@ -157,13 +157,13 @@ trivfs_S_io_read (struct trivfs_protid *cred, { if (cred->po->openmodes & O_NONBLOCK) { - mutex_unlock (&global_lock); + pthread_mutex_unlock (&global_lock); return EWOULDBLOCK; } read_blocked = 1; - if (hurd_condition_wait (&wait, &global_lock)) + if (pthread_hurd_cond_wait_np (&wait, &global_lock)) { - mutex_unlock (&global_lock); + pthread_mutex_unlock (&global_lock); return EINTR; } /* See term/users.c for possible race? */ @@ -192,7 +192,7 @@ trivfs_S_io_read (struct trivfs_protid *cred, /* Set atime, see term/users.c */ - mutex_unlock (&global_lock); + pthread_mutex_unlock (&global_lock); return 0; } @@ -220,7 +220,7 @@ trivfs_S_io_write (struct trivfs_protid *cred, else if (! (cred->po->openmodes & O_WRITE)) return EBADF; - mutex_lock (&global_lock); + pthread_mutex_lock (&global_lock); while (i < datalen) { @@ -235,10 +235,11 @@ trivfs_S_io_write (struct trivfs_protid *cred, if (datalen > 0 && read_blocked) { read_blocked = 0; - condition_broadcast (&wait); + pthread_cond_broadcast (&wait); + pthread_cond_broadcast (&select_alert); } - mutex_unlock (&global_lock); + pthread_mutex_unlock (&global_lock); return 0; } @@ -256,13 +257,13 @@ trivfs_S_io_readable (struct trivfs_protid *cred, else if (! (cred->po->openmodes & O_READ)) return EBADF; - mutex_lock (&global_lock); + pthread_mutex_lock (&global_lock); /* XXX: Before initialization, the amount depends on the amount we want to read. Assume some medium value. */ *amount = readable_pool (POOLSIZE/2, level); - mutex_unlock (&global_lock); + pthread_mutex_unlock (&global_lock); return 0; } @@ -288,7 +289,7 @@ trivfs_S_io_select (struct trivfs_protid *cred, if (*type == 0) return 0; - mutex_lock (&global_lock); + pthread_mutex_lock (&global_lock); while (1) { @@ -298,17 +299,17 @@ trivfs_S_io_select (struct trivfs_protid *cred, if (avail != 0 || *type & SELECT_WRITE) { *type = (avail ? SELECT_READ : 0) | (*type & SELECT_WRITE); - mutex_unlock (&global_lock); + pthread_mutex_unlock (&global_lock); return 0; } ports_interrupt_self_on_port_death (cred, reply); read_blocked = 1; - if (hurd_condition_wait (&select_alert, &global_lock)) + if (pthread_hurd_cond_wait_np (&select_alert, &global_lock)) { *type = 0; - mutex_unlock (&global_lock); + pthread_mutex_unlock (&global_lock); return EINTR; } } @@ -486,7 +487,7 @@ trivfs_append_args (struct trivfs_control *fsys, error_t err = 0; char *opt; - mutex_lock (&global_lock); + pthread_mutex_lock (&global_lock); switch (level) { case 0: @@ -518,7 +519,7 @@ trivfs_append_args (struct trivfs_control *fsys, free (opt); } } - mutex_unlock (&global_lock); + pthread_mutex_unlock (&global_lock); return err; } @@ -536,11 +537,8 @@ struct port_class *shutdown_notify_class; /* The system is going down; destroy all the extant port rights. That will cause net channels and such to close promptly. */ error_t -S_startup_dosync (mach_port_t handle) +S_startup_dosync (struct port_info *inpi) { - struct port_info *inpi = ports_lookup_port (fsys->pi.bucket, handle, - shutdown_notify_class); - if (!inpi) return EOPNOTSUPP; @@ -604,13 +602,12 @@ main (int argc, char **argv) /* Initialize the lock that will protect everything. We must do this before argp_parse, because parse_opt (above) will use the lock. */ - mutex_init (&global_lock); + pthread_mutex_init (&global_lock, NULL); /* The conditions are used to implement proper read/select behaviour. */ - condition_init (&wait); - condition_init (&select_alert); - condition_implies (&wait, &select_alert); + pthread_cond_init (&wait, NULL); + pthread_cond_init (&select_alert, NULL); /* We use the same argp for options available at startup as for options we'll accept in an fsys_set_options RPC. */ |