Bladeren bron

[uaccess] Add userptr_sub() to find the difference between two user pointers

Signed-off-by: Michael Brown <mcb30@ipxe.org>
tags/v1.20.1
Michael Brown 12 jaren geleden
bovenliggende
commit
1494d41d0a

+ 6
- 0
src/arch/i386/include/librm.h Bestand weergeven

@@ -68,6 +68,12 @@ UACCESS_INLINE ( librm, userptr_add ) ( userptr_t userptr, off_t offset ) {
68 68
 	return trivial_userptr_add ( userptr, offset );
69 69
 }
70 70
 
71
+static inline __always_inline off_t
72
+UACCESS_INLINE ( librm, userptr_sub ) ( userptr_t userptr,
73
+					userptr_t subtrahend ) {
74
+	return trivial_userptr_sub ( userptr, subtrahend );
75
+}
76
+
71 77
 static inline __always_inline void
72 78
 UACCESS_INLINE ( librm, memcpy_user ) ( userptr_t dest, off_t dest_off,
73 79
 					userptr_t src, off_t src_off,

+ 6
- 0
src/include/ipxe/efi/efi_uaccess.h Bestand weergeven

@@ -56,6 +56,12 @@ UACCESS_INLINE ( efi, userptr_add ) ( userptr_t userptr, off_t offset ) {
56 56
 	return trivial_userptr_add ( userptr, offset );
57 57
 }
58 58
 
59
+static inline __always_inline off_t
60
+UACCESS_INLINE ( efi, userptr_sub ) ( userptr_t userptr,
61
+				      userptr_t subtrahend ) {
62
+	return trivial_userptr_sub ( userptr, subtrahend );
63
+}
64
+
59 65
 static inline __always_inline void
60 66
 UACCESS_INLINE ( efi, memcpy_user ) ( userptr_t dest, off_t dest_off,
61 67
 					userptr_t src, off_t src_off,

+ 6
- 0
src/include/ipxe/linux/linux_uaccess.h Bestand weergeven

@@ -71,6 +71,12 @@ UACCESS_INLINE(linux, userptr_add)(userptr_t userptr, off_t offset)
71 71
 	return trivial_userptr_add(userptr, offset);
72 72
 }
73 73
 
74
+static inline __always_inline off_t
75
+UACCESS_INLINE(linux, userptr_sub)(userptr_t userptr, userptr_t subtrahend)
76
+{
77
+	return trivial_userptr_sub ( userptr, subtrahend );
78
+}
79
+
74 80
 static inline __always_inline void
75 81
 UACCESS_INLINE(linux, memcpy_user)(userptr_t dest, off_t dest_off, userptr_t src, off_t src_off, size_t len)
76 82
 {

+ 21
- 0
src/include/ipxe/uaccess.h Bestand weergeven

@@ -82,6 +82,18 @@ trivial_userptr_add ( userptr_t userptr, off_t offset ) {
82 82
 	return ( userptr + offset );
83 83
 }
84 84
 
85
+/**
86
+ * Subtract user pointers
87
+ *
88
+ * @v userptr		User pointer
89
+ * @v subtrahend	User pointer to be subtracted
90
+ * @ret offset		Offset
91
+ */
92
+static inline __always_inline off_t
93
+trivial_userptr_sub ( userptr_t userptr, userptr_t subtrahend ) {
94
+	return ( userptr - subtrahend );
95
+}
96
+
85 97
 /**
86 98
  * Copy data between user buffers
87 99
  *
@@ -239,6 +251,15 @@ void * user_to_virt ( userptr_t userptr, off_t offset );
239 251
  */
240 252
 userptr_t userptr_add ( userptr_t userptr, off_t offset );
241 253
 
254
+/**
255
+ * Subtract user pointers
256
+ *
257
+ * @v userptr		User pointer
258
+ * @v subtrahend	User pointer to be subtracted
259
+ * @ret offset		Offset
260
+ */
261
+off_t userptr_sub ( userptr_t userptr, userptr_t subtrahend );
262
+
242 263
 /**
243 264
  * Convert virtual address to a physical address
244 265
  *

Laden…
Annuleren
Opslaan