2 * reactos memory user/kernel memory handling functions emulation of libcaptive
3 * Copyright (C) 2002 Jan Kratochvil <project-captive@jankratochvil.net>
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; exactly version 2 of June 1991 is required
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22 #include "reactos/internal/mm.h" /* self */
23 #include <glib/gmessages.h>
29 * @Dest: Destination memory area address.
30 * %NULL value is forbidden.
31 * @Src: Source memory area address.
32 * %NULL value is forbidden.
33 * @NumberOfBytes: Length of memory area.
35 * This function moves the data between two memory areas.
36 * Given memory areas must not overlap.
37 * libcaptive does not differentiate between user and kernel memory - this functions
38 * implements the simple memcpy() function.
40 * Returns: %STATUS_SUCCESS if the memory was copied successfuly.
42 NTSTATUS MmSafeCopyFromUser(PVOID Dest,const VOID *Src,ULONG NumberOfBytes)
44 g_return_val_if_fail(Dest!=NULL,STATUS_INVALID_PARAMETER);
45 g_return_val_if_fail(Dest+NumberOfBytes>=Dest,STATUS_INVALID_PARAMETER);
46 g_return_val_if_fail(Src!=NULL,STATUS_INVALID_PARAMETER);
47 g_return_val_if_fail(Src+NumberOfBytes>=Src,STATUS_INVALID_PARAMETER);
49 g_return_val_if_fail((Dest+NumberOfBytes<=Src || Dest>=Src+NumberOfBytes),STATUS_INVALID_PARAMETER);
51 memcpy(Dest,Src,NumberOfBytes);
53 return STATUS_SUCCESS;
59 * @Dest: Destination memory area address.
60 * %NULL value is forbidden.
61 * @Src: Source memory area address.
62 * %NULL value is forbidden.
63 * @NumberOfBytes: Length of memory area.
65 * This function moves the data between two memory areas.
66 * Given memory areas must not overlap.
67 * libcaptive does not differentiate between user and kernel memory - this functions
68 * implements the simple memcpy() function.
70 * Returns: %STATUS_SUCCESS if the memory was copied successfuly.
72 NTSTATUS MmSafeCopyToUser(PVOID Dest,const VOID *Src,ULONG NumberOfBytes)
74 g_return_val_if_fail(Dest!=NULL,STATUS_INVALID_PARAMETER);
75 g_return_val_if_fail(Dest+NumberOfBytes>=Dest,STATUS_INVALID_PARAMETER);
76 g_return_val_if_fail(Src!=NULL,STATUS_INVALID_PARAMETER);
77 g_return_val_if_fail(Src+NumberOfBytes>=Src,STATUS_INVALID_PARAMETER);
79 g_return_val_if_fail((Dest+NumberOfBytes<=Src || Dest>=Src+NumberOfBytes),STATUS_INVALID_PARAMETER);
81 memcpy(Dest,Src,NumberOfBytes);
83 return STATUS_SUCCESS;