Initial original import from: fuse-2.4.2-2.fc4
[captive.git] / src / libcaptive / rtl / mem.c
1 /* $Id$
2  * reactos memory user/kernel memory handling functions emulation of libcaptive
3  * Copyright (C) 2003 Jan Kratochvil <project-captive@jankratochvil.net>
4  * 
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
8  * 
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.
13  * 
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
17  */
18
19
20 #include "config.h"
21
22 #include "reactos/internal/safe.h"      /* self */
23 #include <glib/gmessages.h>
24 #include <string.h>
25 #include "reactos/ddk/status.h"
26
27
28 /**
29  * MmCopyFromCaller:
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.
35  *
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.
40  * 
41  * Returns: %STATUS_SUCCESS if the memory was copied successfuly.
42  */
43 NTSTATUS MmCopyFromCaller(PVOID Dest,const VOID *Src,ULONG NumberOfBytes)
44 {
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);
49         /* do not overlap: */
50         g_return_val_if_fail((Dest+NumberOfBytes<=Src || Dest>=Src+NumberOfBytes),STATUS_INVALID_PARAMETER);
51
52         memcpy(Dest,Src,NumberOfBytes);
53
54         return STATUS_SUCCESS;
55 }
56
57
58 /**
59  * MmCopyToCaller:
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.
65  *
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.
70  * 
71  * Returns: %STATUS_SUCCESS if the memory was copied successfuly.
72  */
73 NTSTATUS MmCopyToCaller(PVOID Dest,const VOID *Src,ULONG NumberOfBytes)
74 {
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);
79         /* do not overlap: */
80         g_return_val_if_fail((Dest+NumberOfBytes<=Src || Dest>=Src+NumberOfBytes),STATUS_INVALID_PARAMETER);
81
82         memcpy(Dest,Src,NumberOfBytes);
83
84         return STATUS_SUCCESS;
85 }