+MmSafeCopyToUser()
authorshort <>
Fri, 13 Dec 2002 01:57:36 +0000 (01:57 +0000)
committershort <>
Fri, 13 Dec 2002 01:57:36 +0000 (01:57 +0000)
src/libcaptive/mm/Makefile.am
src/libcaptive/mm/memsafe.c [new file with mode: 0644]

index 092bab5..e69d025 100644 (file)
@@ -23,6 +23,7 @@ noinst_LTLIBRARIES=libmm.la
 libmm_la_SOURCES= \
                marea.c \
                mdl.c \
+               memsafe.c \
                mminit.c \
                page.c \
                pool.c \
diff --git a/src/libcaptive/mm/memsafe.c b/src/libcaptive/mm/memsafe.c
new file mode 100644 (file)
index 0000000..a2513d9
--- /dev/null
@@ -0,0 +1,54 @@
+/* $Id$
+ * reactos memory user/kernel memory handling functions emulation of libcaptive
+ * Copyright (C) 2002 Jan Kratochvil <project-captive@jankratochvil.net>
+ * 
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; exactly version 2 of June 1991 is required
+ * 
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ * 
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ */
+
+
+#include "config.h"
+
+#include "reactos/internal/mm.h"       /* self */
+#include <glib/gmessages.h>
+#include <string.h>
+
+
+/**
+ * MmSafeCopyToUser:
+ * @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 MmSafeCopyToUser(PVOID Dest,PVOID 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;
+}