]> git.ipfire.org Git - thirdparty/ipxe.git/commitdiff
[uaccess] Add userptr_sub() to find the difference between two user pointers
authorMichael Brown <mcb30@ipxe.org>
Mon, 5 Nov 2012 16:09:38 +0000 (16:09 +0000)
committerMichael Brown <mcb30@ipxe.org>
Mon, 5 Nov 2012 16:15:14 +0000 (16:15 +0000)
Signed-off-by: Michael Brown <mcb30@ipxe.org>
src/arch/i386/include/librm.h
src/include/ipxe/efi/efi_uaccess.h
src/include/ipxe/linux/linux_uaccess.h
src/include/ipxe/uaccess.h

index c6992f64395d581c30031a780b9a8dfab38331a3..801f586b8e39c8291e16b2ebe08070fabbc103f9 100644 (file)
@@ -68,6 +68,12 @@ UACCESS_INLINE ( librm, userptr_add ) ( userptr_t userptr, off_t offset ) {
        return trivial_userptr_add ( userptr, offset );
 }
 
+static inline __always_inline off_t
+UACCESS_INLINE ( librm, userptr_sub ) ( userptr_t userptr,
+                                       userptr_t subtrahend ) {
+       return trivial_userptr_sub ( userptr, subtrahend );
+}
+
 static inline __always_inline void
 UACCESS_INLINE ( librm, memcpy_user ) ( userptr_t dest, off_t dest_off,
                                        userptr_t src, off_t src_off,
index dc226a3e5feac42981918afe71179fa82c3f76a7..79c18972e2257ffb1624ef41e54143952688d437 100644 (file)
@@ -56,6 +56,12 @@ UACCESS_INLINE ( efi, userptr_add ) ( userptr_t userptr, off_t offset ) {
        return trivial_userptr_add ( userptr, offset );
 }
 
+static inline __always_inline off_t
+UACCESS_INLINE ( efi, userptr_sub ) ( userptr_t userptr,
+                                     userptr_t subtrahend ) {
+       return trivial_userptr_sub ( userptr, subtrahend );
+}
+
 static inline __always_inline void
 UACCESS_INLINE ( efi, memcpy_user ) ( userptr_t dest, off_t dest_off,
                                        userptr_t src, off_t src_off,
index 1b496117772e9be45179881383c8c9d80fc950fa..e4dfdd357718c00b39151ad05df90e6cf266f03e 100644 (file)
@@ -71,6 +71,12 @@ UACCESS_INLINE(linux, userptr_add)(userptr_t userptr, off_t offset)
        return trivial_userptr_add(userptr, offset);
 }
 
+static inline __always_inline off_t
+UACCESS_INLINE(linux, userptr_sub)(userptr_t userptr, userptr_t subtrahend)
+{
+       return trivial_userptr_sub ( userptr, subtrahend );
+}
+
 static inline __always_inline void
 UACCESS_INLINE(linux, memcpy_user)(userptr_t dest, off_t dest_off, userptr_t src, off_t src_off, size_t len)
 {
index b574c318326da760e6ad1ffd64ad728e91c90eb2..95e9436759ff8d7970add4d4f6cca43d538f37e7 100644 (file)
@@ -82,6 +82,18 @@ trivial_userptr_add ( userptr_t userptr, off_t offset ) {
        return ( userptr + offset );
 }
 
+/**
+ * Subtract user pointers
+ *
+ * @v userptr          User pointer
+ * @v subtrahend       User pointer to be subtracted
+ * @ret offset         Offset
+ */
+static inline __always_inline off_t
+trivial_userptr_sub ( userptr_t userptr, userptr_t subtrahend ) {
+       return ( userptr - subtrahend );
+}
+
 /**
  * Copy data between user buffers
  *
@@ -239,6 +251,15 @@ void * user_to_virt ( userptr_t userptr, off_t offset );
  */
 userptr_t userptr_add ( userptr_t userptr, off_t offset );
 
+/**
+ * Subtract user pointers
+ *
+ * @v userptr          User pointer
+ * @v subtrahend       User pointer to be subtracted
+ * @ret offset         Offset
+ */
+off_t userptr_sub ( userptr_t userptr, userptr_t subtrahend );
+
 /**
  * Convert virtual address to a physical address
  *