bug-hurd
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Using mach_convert_device_to_port() in the device pager


From: Marin Ramesa
Subject: Using mach_convert_device_to_port() in the device pager
Date: Wed, 18 Sep 2013 07:38:54 +0200

This is more a question than a patch.

Why don't the device pager hash functions use the device server routines to 
track 
the device associated ports?

If the the devices and associated ports are not in one-to-one correspodence, 
why do
hash functions take ports as arguments, why not simply devices?

Wouldn't something like this be better (please don't apply this, it probably 
breaks
something):

* device/ds_routines.h (mach_convert_device_to_port): Add extern declaration.
* device/dev_pager.c: Call mach_convert_device_to_port() before the call to 
hash functions.

---
 device/dev_pager.c   | 6 +++---
 device/ds_routines.h | 3 +++
 2 files changed, 6 insertions(+), 3 deletions(-)

diff --git a/device/dev_pager.c b/device/dev_pager.c
index e0ca2c7..0829f5d 100644
--- a/device/dev_pager.c
+++ b/device/dev_pager.c
@@ -260,7 +260,7 @@ kern_return_t       device_pager_setup(
         *      and port to represent this object.
         */
 
-       d = dev_pager_hash_lookup((ipc_port_t)device);  /* HACK */
+       d = dev_pager_hash_lookup(mach_convert_device_to_port(device));
        if (d != DEV_PAGER_NULL) {
                *pager = (mach_port_t) ipc_port_make_send(d->pager);
                dev_pager_deallocate(d);
@@ -297,7 +297,7 @@ kern_return_t       device_pager_setup(
        }
 
        dev_pager_hash_insert(d->pager, d);
-       dev_pager_hash_insert((ipc_port_t)device, d);   /* HACK */
+       dev_pager_hash_insert(mach_convert_device_to_port(device), d);
 
        *pager = (mach_port_t) ipc_port_make_send(d->pager);
        return (KERN_SUCCESS);
@@ -662,7 +662,7 @@ kern_return_t device_pager_terminate(
        assert(ds->pager_name == pager_name);
 
        dev_pager_hash_delete(ds->pager);
-       dev_pager_hash_delete((ipc_port_t)ds->device);  /* HACK */
+       dev_pager_hash_delete(mach_convert_device_to_port(ds->device));
        mach_device_deallocate(ds->device);
 
        /* release the send rights we have saved from the init call */
diff --git a/device/ds_routines.h b/device/ds_routines.h
index c4333f4..c1e3c29 100644
--- a/device/ds_routines.h
+++ b/device/ds_routines.h
@@ -65,4 +65,7 @@ kern_return_t device_pager_setup(
        vm_size_t       size,
        mach_port_t     *pager);
 
+extern ipc_port_t
+mach_convert_device_to_port (mach_device_t device);
+
 #endif /* DS_ROUTINES_H */
-- 
1.8.1.4




reply via email to

[Prev in Thread] Current Thread [Next in Thread]