2 * reactos memory user/kernel memory handling functions emulation of libcaptive
3 * Copyright (C) 2003 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/safe.h" /* self */
23 #include <glib/gmessages.h>
25 #include "reactos/ddk/status.h"
30 * @Dest: Destination memory area address.
31 * %NULL value is forbidden.
32 * @Src: Source memory area address.
33 * %NULL value is forbidden.
34 * @NumberOfBytes: Length of memory area.
36 * This function moves the data between two memory areas.
37 * Given memory areas must not overlap.
38 * libcaptive does not differentiate between user and kernel memory - this functions
39 * implements the simple memcpy() function.
41 * Returns: %STATUS_SUCCESS if the memory was copied successfuly.
43 NTSTATUS MmCopyFromCaller(PVOID Dest,const VOID *Src,ULONG NumberOfBytes)
45 g_return_val_if_fail(Dest!=NULL,STATUS_INVALID_PARAMETER);
46 g_return_val_if_fail(Dest+NumberOfBytes>=Dest,STATUS_INVALID_PARAMETER);
47 g_return_val_if_fail(Src!=NULL,STATUS_INVALID_PARAMETER);
48 g_return_val_if_fail(Src+NumberOfBytes>=Src,STATUS_INVALID_PARAMETER);
50 g_return_val_if_fail((Dest+NumberOfBytes<=Src || Dest>=Src+NumberOfBytes),STATUS_INVALID_PARAMETER);
52 memcpy(Dest,Src,NumberOfBytes);
54 return STATUS_SUCCESS;
60 * @Dest: Destination memory area address.
61 * %NULL value is forbidden.
62 * @Src: Source memory area address.
63 * %NULL value is forbidden.
64 * @NumberOfBytes: Length of memory area.
66 * This function moves the data between two memory areas.
67 * Given memory areas must not overlap.
68 * libcaptive does not differentiate between user and kernel memory - this functions
69 * implements the simple memcpy() function.
71 * Returns: %STATUS_SUCCESS if the memory was copied successfuly.
73 NTSTATUS MmCopyToCaller(PVOID Dest,const VOID *Src,ULONG NumberOfBytes)
75 g_return_val_if_fail(Dest!=NULL,STATUS_INVALID_PARAMETER);
76 g_return_val_if_fail(Dest+NumberOfBytes>=Dest,STATUS_INVALID_PARAMETER);
77 g_return_val_if_fail(Src!=NULL,STATUS_INVALID_PARAMETER);
78 g_return_val_if_fail(Src+NumberOfBytes>=Src,STATUS_INVALID_PARAMETER);
80 g_return_val_if_fail((Dest+NumberOfBytes<=Src || Dest>=Src+NumberOfBytes),STATUS_INVALID_PARAMETER);
82 memcpy(Dest,Src,NumberOfBytes);
84 return STATUS_SUCCESS;