Justus Winter, le Fri 11 Apr 2014 15:34:13 +0200, a écrit : > Previously, the device definitions were filtered using sed to replace > the device_t type with mach_port_send_t to make the device argument of > device_open polymorphic. Rather than doing that, which makes it > impossible to use translation functions, the definition of device_open > has been amended.
Ack. > * libmachdev/Makefile: Remove ourdevice hack that changes > device_t to mach_port_send_t. > * libmachdev/device.defs (device_open): Make the device parameter > polymorphic like it was done in gnumach. > * libmachdev/ds_routines.c (port_bucket): Drop static qualifier so > that it can be used in the intrans function. > (dev_class): Likewise. > (ds_*): Fix all device_t receiver lookups. > * libmachdev/mig-decls.h: New file. > * libmachdev/mig-mutate.h: Add mutators. > --- > libmachdev/Makefile | 5 +- > libmachdev/device.defs | 11 +++- > libmachdev/ds_routines.c | 146 > +++++++++++------------------------------------ > libmachdev/mig-decls.h | 44 ++++++++++++++ > libmachdev/mig-mutate.h | 7 +++ > 5 files changed, 94 insertions(+), 119 deletions(-) > create mode 100644 libmachdev/mig-decls.h > > diff --git a/libmachdev/Makefile b/libmachdev/Makefile > index e006461..a47bf32 100644 > --- a/libmachdev/Makefile > +++ b/libmachdev/Makefile > @@ -20,7 +20,7 @@ makemode := library > libname = libmachdev > > SRCS = deviceUser.c machUser.c net.c ds_routines.c queue.c trivfs_server.c \ > - device_replyUser.c ourdeviceServer.c notifyServer.c misc.c block.c > + device_replyUser.c deviceServer.c notifyServer.c misc.c block.c > LCLHDRS = dev_hdr.h device_emul.h ds_routines.h vm_param.h \ > util.h queue.h io_req.h if_ether.h machdev.h linux-errno.h \ > errno-base.h > @@ -32,8 +32,5 @@ MIGSFLAGS = -imacros $(srcdir)/mig-mutate.h > > include ../Makeconf > > -ourdevice.defs: device.defs > - $(CPP) $(CPPFLAGS) -x c $< | sed -e '/out[ ]*device[ ]*:[ > ]*device_t/s/device_t/mach_port_send_t/' > $@ > - > $(libname).so.$(hurd-version): > echo "INPUT ( $(libname).a )" > $@ > diff --git a/libmachdev/device.defs b/libmachdev/device.defs > index 7c39f8a..5c16a37 100644 > --- a/libmachdev/device.defs > +++ b/libmachdev/device.defs > @@ -56,7 +56,16 @@ routine device_open( > sreplyport reply_port : reply_port_t; > mode : dev_mode_t; > name : dev_name_t; > - out device : device_t > + out device : device_t = > + MACH_MSG_TYPE_PORT_SEND > + ctype: mach_port_t > +#if KERNEL_SERVER > + outtran: mach_port_t convert_device_to_port(device_t) > +#else > +#ifdef DEVICE_OUTTRAN > + outtran: DEVICE_OUTTRAN > +#endif > +#endif /* KERNEL_SERVER */ > ); > > routine device_close( > diff --git a/libmachdev/ds_routines.c b/libmachdev/ds_routines.c > index 66e5756..e415cdb 100644 > --- a/libmachdev/ds_routines.c > +++ b/libmachdev/ds_routines.c > @@ -70,8 +70,8 @@ > #include "queue.h" > #include "mach_glue.h" > > -static struct port_bucket *port_bucket; > -static struct port_class *dev_class; > +struct port_bucket *port_bucket; > +struct port_class *dev_class; > > #define NUM_EMULATION num_emul > #define MAX_NUM_EMULATION 32 > @@ -88,12 +88,6 @@ mach_device_deallocate (void *device) > ports_port_deref (device); > } > > -static inline struct mach_device * > -mach_convert_port_to_device (device_t device) > -{ > - return ports_lookup_port (port_bucket, device, dev_class); > -} > - > /* > * What follows is the interface for the native Mach devices. > */ > @@ -110,21 +104,21 @@ mach_convert_device_to_port (mach_device_t device) > > /* Implementation of device interface */ > kern_return_t > -ds_xxx_device_set_status (device_t device, dev_flavor_t flavor, > +ds_xxx_device_set_status (struct mach_device *device, dev_flavor_t flavor, > dev_status_t status, size_t statu_cnt) > { > return D_INVALID_OPERATION; > } > > kern_return_t > -ds_xxx_device_get_status (device_t device, dev_flavor_t flavor, > +ds_xxx_device_get_status (struct mach_device *device, dev_flavor_t flavor, > dev_status_t status, size_t *statuscnt) > { > return D_INVALID_OPERATION; > } > > kern_return_t > -ds_xxx_device_set_filter (device_t device, mach_port_t rec, > +ds_xxx_device_set_filter (struct mach_device *device, mach_port_t rec, > int pri, filter_array_t filt, size_t len) > { > return D_INVALID_OPERATION; > @@ -176,244 +170,168 @@ ds_device_open (mach_port_t open_port, mach_port_t > reply_port, > } > > io_return_t > -ds_device_close (device_t dev) > +ds_device_close (struct mach_device *device) > { > - struct mach_device *device; > io_return_t ret; > > - /* Refuse if device is dead or not completely open. */ > - if (dev == MACH_PORT_NULL) > + if (device == NULL) > return D_NO_SUCH_DEVICE; > > - device = mach_convert_port_to_device (dev); > ret = (device->dev.emul_ops->close > ? (*device->dev.emul_ops->close) (device->dev.emul_data) > : D_SUCCESS); > mach_device_deallocate (device); > - > - ports_port_deref (device); > return ret; > } > > io_return_t > -ds_device_write (device_t dev, mach_port_t reply_port, > +ds_device_write (struct mach_device *device, mach_port_t reply_port, > mach_msg_type_name_t reply_port_type, dev_mode_t mode, > recnum_t recnum, io_buf_ptr_t data, unsigned int count, > int *bytes_written) > { > - struct mach_device *device; > io_return_t ret; > > - /* Refuse if device is dead or not completely open. */ > - if (dev == MACH_PORT_NULL) > - return D_NO_SUCH_DEVICE; > - > if (data == 0) > return D_INVALID_SIZE; > > - device = mach_convert_port_to_device (dev); > if (device == NULL) > - return D_INVALID_OPERATION; > + return D_NO_SUCH_DEVICE; > > if (! device->dev.emul_ops->write) > - { > - ports_port_deref (device); > - return D_INVALID_OPERATION; > - } > + return D_INVALID_OPERATION; > > ret = (*device->dev.emul_ops->write) (device->dev.emul_data, reply_port, > reply_port_type, mode, recnum, > data, count, bytes_written); > - ports_port_deref (device); > - > return ret; > } > > io_return_t > -ds_device_write_inband (device_t dev, mach_port_t reply_port, > +ds_device_write_inband (struct mach_device *device, mach_port_t reply_port, > mach_msg_type_name_t reply_port_type, > dev_mode_t mode, recnum_t recnum, > io_buf_ptr_inband_t data, unsigned count, > int *bytes_written) > { > - struct mach_device *device; > io_return_t ret; > > - /* Refuse if device is dead or not completely open. */ > - if (dev == MACH_PORT_NULL) > - return D_NO_SUCH_DEVICE; > - > if (data == 0) > return D_INVALID_SIZE; > > - device = mach_convert_port_to_device (dev); > if (device == NULL) > - return D_INVALID_OPERATION; > + return D_NO_SUCH_DEVICE; > > if (! device->dev.emul_ops->write_inband) > - { > - ports_port_deref (device); > - return D_INVALID_OPERATION; > - } > + return D_INVALID_OPERATION; > > ret = (*device->dev.emul_ops->write_inband) (device->dev.emul_data, > reply_port, reply_port_type, > mode, recnum, > data, count, bytes_written); > - ports_port_deref (device); > - > return ret; > } > > io_return_t > -ds_device_read (device_t dev, mach_port_t reply_port, > +ds_device_read (struct mach_device *device, mach_port_t reply_port, > mach_msg_type_name_t reply_port_type, dev_mode_t mode, > recnum_t recnum, int count, io_buf_ptr_t *data, > unsigned *bytes_read) > { > - struct mach_device *device; > io_return_t ret; > > - /* Refuse if device is dead or not completely open. */ > - if (dev == MACH_PORT_NULL) > - return D_NO_SUCH_DEVICE; > - > - device = mach_convert_port_to_device (dev); > if (device == NULL) > - return D_INVALID_OPERATION; > + return D_NO_SUCH_DEVICE; > > if (! device->dev.emul_ops->read) > - { > - ports_port_deref (device); > - return D_INVALID_OPERATION; > - } > + return D_INVALID_OPERATION; > > ret = (*device->dev.emul_ops->read) (device->dev.emul_data, reply_port, > reply_port_type, mode, recnum, > count, data, bytes_read); > - ports_port_deref (device); > return ret; > } > > io_return_t > -ds_device_read_inband (device_t dev, mach_port_t reply_port, > +ds_device_read_inband (struct mach_device *device, mach_port_t reply_port, > mach_msg_type_name_t reply_port_type, dev_mode_t mode, > recnum_t recnum, int count, char *data, > unsigned *bytes_read) > { > - struct mach_device *device; > io_return_t ret; > > - /* Refuse if device is dead or not completely open. */ > - if (dev == MACH_PORT_NULL) > - return D_NO_SUCH_DEVICE; > - > - device = mach_convert_port_to_device (dev); > if (device == NULL) > - return D_INVALID_OPERATION; > + return D_NO_SUCH_DEVICE; > > if (! device->dev.emul_ops->read_inband) > - { > - ports_port_deref (device); > - return D_INVALID_OPERATION; > - } > + return D_INVALID_OPERATION; > > ret = (*device->dev.emul_ops->read_inband) (device->dev.emul_data, > reply_port, > reply_port_type, mode, recnum, > count, data, bytes_read); > - ports_port_deref (device); > return ret; > } > > io_return_t > -ds_device_set_status (device_t dev, dev_flavor_t flavor, > +ds_device_set_status (struct mach_device *device, dev_flavor_t flavor, > dev_status_t status, mach_msg_type_number_t status_count) > { > - struct mach_device *device; > io_return_t ret; > > - /* Refuse if device is dead or not completely open. */ > - if (dev == MACH_PORT_NULL) > - return D_NO_SUCH_DEVICE; > - > - device = mach_convert_port_to_device (dev); > if (device == NULL) > - return D_INVALID_OPERATION; > + return D_NO_SUCH_DEVICE; > > if (! device->dev.emul_ops->set_status) > - { > - ports_port_deref (device); > - return D_INVALID_OPERATION; > - } > + return D_INVALID_OPERATION; > > ret = (*device->dev.emul_ops->set_status) (device->dev.emul_data, flavor, > status, status_count); > - ports_port_deref (device); > return ret; > } > > io_return_t > -ds_device_get_status (device_t dev, dev_flavor_t flavor, dev_status_t status, > +ds_device_get_status (struct mach_device *device, dev_flavor_t flavor, > + dev_status_t status, > mach_msg_type_number_t *status_count) > { > - struct mach_device *device; > io_return_t ret; > > - /* Refuse if device is dead or not completely open. */ > - if (dev == MACH_PORT_NULL) > - return D_NO_SUCH_DEVICE; > - > - device = mach_convert_port_to_device (dev); > if (device == NULL) > - return D_INVALID_OPERATION; > + return D_NO_SUCH_DEVICE; > > if (! device->dev.emul_ops->get_status) > - { > - ports_port_deref (device); > - return D_INVALID_OPERATION; > - } > + return D_INVALID_OPERATION; > > ret = (*device->dev.emul_ops->get_status) (device->dev.emul_data, flavor, > status, status_count); > - ports_port_deref (device); > return ret; > } > > io_return_t > -ds_device_set_filter (device_t dev, mach_port_t receive_port, int priority, > - filter_t *filter, unsigned filter_count) > +ds_device_set_filter (struct mach_device *device, mach_port_t receive_port, > + int priority, filter_t *filter, unsigned filter_count) > { > - struct mach_device *device; > io_return_t ret; > > - /* Refuse if device is dead or not completely open. */ > - if (dev == MACH_PORT_NULL) > - return D_NO_SUCH_DEVICE; > - > - device = mach_convert_port_to_device (dev); > if (device == NULL) > - return D_INVALID_OPERATION; > + return D_NO_SUCH_DEVICE; > > if (! device->dev.emul_ops->set_filter) > - { > - ports_port_deref (device); > - return D_INVALID_OPERATION; > - } > + return D_INVALID_OPERATION; > > ret = (*device->dev.emul_ops->set_filter) (device->dev.emul_data, > receive_port, > priority, filter, filter_count); > - ports_port_deref (device); > return ret; > } > > io_return_t > -ds_device_map (device_t dev, vm_prot_t prot, vm_offset_t offset, > +ds_device_map (struct mach_device *device, vm_prot_t prot, vm_offset_t > offset, > vm_size_t size, mach_port_t *pager, boolean_t unmap) > { > /* Refuse if device is dead or not completely open. */ > - if (dev == MACH_PORT_NULL) > + if (device == NULL) > return D_NO_SUCH_DEVICE; > > return D_INVALID_OPERATION; > diff --git a/libmachdev/mig-decls.h b/libmachdev/mig-decls.h > new file mode 100644 > index 0000000..1d137cd > --- /dev/null > +++ b/libmachdev/mig-decls.h > @@ -0,0 +1,44 @@ > +/* > + 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 __LIBMACHDEV_MIG_DECLS_H__ > +#define __LIBMACHDEV_MIG_DECLS_H__ > + > +#include <hurd/ports.h> > +#include "dev_hdr.h" > + > +extern struct port_bucket *port_bucket; > +extern struct port_class *dev_class; > + > +/* Called by server stub functions. */ > + > +static inline struct mach_device * __attribute__ ((unused)) > +begin_using_device_port (mach_port_t port) > +{ > + return ports_lookup_port (port_bucket, port, dev_class); > +} > + > +static inline void __attribute__ ((unused)) > +end_using_device (struct mach_device *p) > +{ > + if (p) > + ports_port_deref (p); > +} > + > +#endif /* __LIBMACHDEV_MIG_DECLS_H__ */ > diff --git a/libmachdev/mig-mutate.h b/libmachdev/mig-mutate.h > index f692236..56c6965 100644 > --- a/libmachdev/mig-mutate.h > +++ b/libmachdev/mig-mutate.h > @@ -23,3 +23,10 @@ > end_using_port_info (port_info_t) > #define NOTIFY_IMPORTS \ > import "libports/mig-decls.h"; > + > +#define DEVICE_INTRAN \ > + mach_device_t begin_using_device_port (mach_port_t) > +#define DEVICE_DESTRUCTOR \ > + end_using_device (mach_device_t) > +#define DEVICE_IMPORTS \ > + import "libmachdev/mig-decls.h"; > -- > 1.9.1 > -- Samuel Running Windows on a Pentium is like having a brand new Porsche but only be able to drive backwards with the handbrake on. (Unknown source)