summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--libmachdev/Makefile5
-rw-r--r--libmachdev/ds_routines.c146
-rw-r--r--libmachdev/mig-decls.h44
-rw-r--r--libmachdev/mig-mutate.h7
4 files changed, 84 insertions, 118 deletions
diff --git a/libmachdev/Makefile b/libmachdev/Makefile
index e0064610..a47bf325 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/ds_routines.c b/libmachdev/ds_routines.c
index 66e5756c..e415cdb3 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 00000000..1d137cd9
--- /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 f692236e..56c6965a 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";