Initial original import from: fuse-2.4.2-2.fc4
[captive.git] / src / libcaptive / mm / memsafe.c
index a2513d9..0ce26e8 100644 (file)
 
 
 /**
+ * MmSafeCopyFromUser:
+ * @Dest: Destination memory area address.
+ * %NULL value is forbidden.
+ * @Src: Source memory area address.
+ * %NULL value is forbidden.
+ * @NumberOfBytes: Length of memory area.
+ *
+ * This function moves the data between two memory areas.
+ * Given memory areas must not overlap.
+ * libcaptive does not differentiate between user and kernel memory - this functions
+ * implements the simple memcpy() function.
+ * 
+ * Returns: %STATUS_SUCCESS if the memory was copied successfuly.
+ */
+NTSTATUS MmSafeCopyFromUser(PVOID Dest,const VOID *Src,ULONG NumberOfBytes)
+{
+       g_return_val_if_fail(Dest!=NULL,STATUS_INVALID_PARAMETER);
+       g_return_val_if_fail(Dest+NumberOfBytes>=Dest,STATUS_INVALID_PARAMETER);
+       g_return_val_if_fail(Src!=NULL,STATUS_INVALID_PARAMETER);
+       g_return_val_if_fail(Src+NumberOfBytes>=Src,STATUS_INVALID_PARAMETER);
+       /* do not overlap: */
+       g_return_val_if_fail((Dest+NumberOfBytes<=Src || Dest>=Src+NumberOfBytes),STATUS_INVALID_PARAMETER);
+
+       memcpy(Dest,Src,NumberOfBytes);
+
+       return STATUS_SUCCESS;
+}
+
+
+/**
  * MmSafeCopyToUser:
  * @Dest: Destination memory area address.
  * %NULL value is forbidden.
@@ -39,7 +69,7 @@
  * 
  * Returns: %STATUS_SUCCESS if the memory was copied successfuly.
  */
-NTSTATUS MmSafeCopyToUser(PVOID Dest,PVOID Src,ULONG NumberOfBytes)
+NTSTATUS MmSafeCopyToUser(PVOID Dest,const VOID *Src,ULONG NumberOfBytes)
 {
        g_return_val_if_fail(Dest!=NULL,STATUS_INVALID_PARAMETER);
        g_return_val_if_fail(Dest+NumberOfBytes>=Dest,STATUS_INVALID_PARAMETER);