bug-hurd
[Top][All Lists]
Advanced

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

[PATCH] Use long_natural_t for recnum_t


From: Flavio Cruz
Subject: [PATCH] Use long_natural_t for recnum_t
Date: Sun, 18 Dec 2022 12:21:27 -0500

For 64 bits, device operations will provide an addressing space of 64
bits.

Also define the translation functions if long_natural_t or
long_integer_t are ever used in RPCs.

Note that MIG does not implicitly inherit the translation functions from
types hence the need to redefine them for recnum_t.
---
 device/subrs.c                            |  2 +-
 i386/include/mach/i386/machine_types.defs | 53 ++++++++++++++---------
 i386/include/mach/i386/vm_types.h         | 20 +++++++++
 include/device/device_types.defs          | 11 ++++-
 include/device/device_types.h             |  3 +-
 5 files changed, 65 insertions(+), 24 deletions(-)

diff --git a/device/subrs.c b/device/subrs.c
index be710132..7a56f4b7 100644
--- a/device/subrs.c
+++ b/device/subrs.c
@@ -42,7 +42,7 @@
  */
 void harderr(const io_req_t ior, const char *cp)
 {
-       printf("%s%d%c: hard error sn%d ",
+       printf("%s%d%c: hard error sn%lu ",
               cp,
               minor(ior->io_unit) >> 3,
               'a' + (minor(ior->io_unit) & 0x7),
diff --git a/i386/include/mach/i386/machine_types.defs 
b/i386/include/mach/i386/machine_types.defs
index d1b61be9..3d540be9 100755
--- a/i386/include/mach/i386/machine_types.defs
+++ b/i386/include/mach/i386/machine_types.defs
@@ -55,37 +55,48 @@ type natural_t = uint32_t;
 type integer_t = int32_t;
 
 /*
- * A long_natural_t is a possibly larger unsigned integer type than natural_t.
- * Should be used instead of natural_t when we want the data to be less subject
- * to overflows.
+ * long_natural_t and long_integer_t for kernel <-> userland interfaces as the
+ * size depends on the architecture of both kernel and userland.
  */
+#if defined(KERNEL_SERVER) && defined(USER32)
+type rpc_long_natural_t = uint32_t;
+type rpc_long_integer_t = int32_t;
+#else /* KERNEL and USER32 */
 #if defined(__x86_64__)
-type long_natural_t = uint64_t;
+type rpc_long_natural_t = uint64_t;
+type rpc_long_integer_t = int64_t;
 #else
-type long_natural_t = uint32_t;
+type rpc_long_natural_t = uint32_t;
+type rpc_long_integer_t = int32_t;
 #endif /* __x86_64__ */
+#endif /* KERNEL_SERVER and USER32 */
 
 /*
- * Larger version of integer_t. Only used when we want to hold possibly larger
- * values than what is possible with integer_t.
+ * A long_natural_t is a possibly larger unsigned integer type than natural_t.
+ * Should be used instead of natural_t when we want the data to be less subject
+ * to overflows.
  */
-#if defined(__x86_64__)
-type long_integer_t = int64_t;
-#else
-type long_integer_t = int32_t;
-#endif /* __x86_64__ */
+type long_natural_t = rpc_long_natural_t
+#if defined(KERNEL_SERVER)
+    intran: long_natural_t convert_long_natural_from_user(rpc_long_natural_t)
+    outtran: rpc_long_natural_t convert_long_natural_to_user(long_natural_t)
+#elif defined(KERNEL_USER)
+    ctype: rpc_long_natural_t
+#endif
+    ;
 
 /*
- * long_natural_t and long_integer_t for kernel <-> userland interfaces as the
- * size depends on the architecture of both kernel and userland.
+ * Larger version of integer_t. Only used when we want to hold possibly larger
+ * values than what is possible with integer_t.
  */
-#if defined(KERNEL) && defined(USER32)
-type rpc_long_natural_t = uint32_t;
-type rpc_long_integer_t = int32_t;
-#else /* KERNEL and USER32 */
-type rpc_long_natural_t = long_natural_t;
-type rpc_long_integer_t = long_integer_t;
-#endif /* KERNEL_SERVER and USER32 */
+type long_integer_t = rpc_long_integer_t
+#if defined(KERNEL_SERVER)
+    intran: long_integer_t convert_long_integer_from_user(rpc_long_integer_t)
+    outtran: rpc_long_integer_t convert_long_integer_to_user(long_integer_t)
+#elif defined(KERNEL_USER)
+    ctype: rpc_long_integer_t
+#endif
+    ;
 
 /*
  * Physical address size
diff --git a/i386/include/mach/i386/vm_types.h 
b/i386/include/mach/i386/vm_types.h
index 7e5857a5..bb43a9fb 100644
--- a/i386/include/mach/i386/vm_types.h
+++ b/i386/include/mach/i386/vm_types.h
@@ -113,6 +113,7 @@ typedef     vm_size_t *     vm_size_array_t;
 typedef __mach_uint32_t        rpc_vm_address_t;
 typedef __mach_uint32_t        rpc_vm_offset_t;
 typedef __mach_uint32_t        rpc_vm_size_t;
+
 static inline __mach_uint64_t convert_vm_from_user(__mach_uint32_t uaddr)
 {
     return (__mach_uint64_t)uaddr;
@@ -122,18 +123,37 @@ static inline __mach_uint32_t 
convert_vm_to_user(__mach_uint64_t kaddr)
     assert(kaddr <= 0xFFFFFFFF);
     return (__mach_uint32_t)kaddr;
 }
+
 typedef __mach_uint32_t rpc_long_natural_t;
 typedef __mach_int32_t rpc_long_integer_t;
+
+static inline __mach_int64_t convert_long_integer_from_user(__mach_int32_t i)
+{
+       return (__mach_int64_t)i;
+}
+static inline __mach_int32_t convert_long_integer_to_user(__mach_int64_t i)
+{
+    assert(i <= 0x7FFFFFFF);
+       return (__mach_int32_t)i;
+}
 #else /* MACH_KERNEL */
 typedef vm_offset_t    rpc_vm_address_t;
 typedef vm_offset_t    rpc_vm_offset_t;
 typedef vm_size_t      rpc_vm_size_t;
+
 #define convert_vm_to_user null_conversion
 #define convert_vm_from_user null_conversion
+
 typedef long_natural_t rpc_long_natural_t;
 typedef long_integer_t rpc_long_integer_t;
+
+#define convert_long_integer_to_user null_conversion
+#define convert_long_integer_from_user null_conversion
 #endif /* MACH_KERNEL */
 
+#define convert_long_natural_to_user convert_vm_to_user
+#define convert_long_natural_from_user convert_vm_from_user
+
 #endif /* __ASSEMBLER__ */
 
 /*
diff --git a/include/device/device_types.defs b/include/device/device_types.defs
index e97d89ca..de8dbb02 100644
--- a/include/device/device_types.defs
+++ b/include/device/device_types.defs
@@ -43,7 +43,16 @@
 DEVICE_IMPORTS
 #endif
 
-type recnum_t          = uint32_t;
+type rpc_recnum_t      = rpc_long_natural_t;
+type recnum_t          = rpc_recnum_t
+#if defined(KERNEL_SERVER)
+       intran: recnum_t convert_long_natural_from_user(rpc_recnum_t)
+       outtran: rpc_recnum_t convert_long_natural_to_user(recnum_t)
+#elif defined(KERNEL_USER)
+       ctype: rpc_recnum_t
+#endif
+       ;
+
 type dev_mode_t                = uint32_t;
 type dev_flavor_t      = uint32_t;
 type dev_name_t                = (MACH_MSG_TYPE_STRING_C, 8*128);
diff --git a/include/device/device_types.h b/include/device/device_types.h
index f13122f0..7c533723 100644
--- a/include/device/device_types.h
+++ b/include/device/device_types.h
@@ -89,7 +89,8 @@ typedef struct {
 /*
  * Record number for random-access devices
  */
-typedef        unsigned int    recnum_t;
+typedef        long_natural_t recnum_t;
+typedef rpc_long_natural_t rpc_recnum_t;
 
 /*
  * Flavors of set/get statuses
-- 
2.37.2




reply via email to

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