3 * COPYRIGHT: See COPYING in the top level directory
4 * PROJECT: ReactOS kernel
5 * FILE: kernel/rtl/mem.c
6 * PURPOSE: Memory functions
7 * PROGRAMMER: David Welch (welch@mcmail.com)
12 /* INCLUDES *****************************************************************/
14 #include <ddk/ntddk.h>
15 #include <internal/mm.h>
18 #include <internal/debug.h>
20 /* FUNCTIONS *****************************************************************/
25 MmCopyToCaller(PVOID Dest, PVOID Src, ULONG NumberOfBytes)
29 if (ExGetPreviousMode() == UserMode)
31 if ((ULONG)Dest >= KERNEL_BASE)
33 return(STATUS_ACCESS_VIOLATION);
35 Status = MmSafeCopyToUser(Dest, Src, NumberOfBytes);
40 memcpy(Dest, Src, NumberOfBytes);
41 return(STATUS_SUCCESS);
46 MmCopyFromCaller(PVOID Dest, PVOID Src, ULONG NumberOfBytes)
50 if (ExGetPreviousMode() == UserMode)
52 if ((ULONG)Src >= KERNEL_BASE)
54 return(STATUS_ACCESS_VIOLATION);
56 Status = MmSafeCopyFromUser(Dest, Src, NumberOfBytes);
61 memcpy(Dest, Src, NumberOfBytes);
62 return(STATUS_SUCCESS);
66 #endif /* LIBCAPTIVE */
70 RtlCompareMemory(PVOID Source1,
74 * FUNCTION: Compares blocks of memory and returns the number of equal bytes
76 * Source1 = Block to compare
77 * Source2 = Block to compare
78 * Length = Number of bytes to compare
79 * RETURNS: Number of equal bytes
84 for (i=0,total=0;i<Length;i++)
86 if ( ((PUCHAR)Source1)[i] == ((PUCHAR)Source2)[i] )
98 RtlCompareMemoryUlong (
104 * FUNCTION: Compares a block of ULONGs with an ULONG and returns the number of equal bytes
106 * Source = Block to compare
107 * Length = Number of bytes to compare
108 * Value = Value to compare
109 * RETURNS: Number of equal bytes
112 PULONG ptr = (PULONG)Source;
113 ULONG len = Length / sizeof(ULONG);
116 for (i = 0; i < len; i++)
123 return (ULONG)((PCHAR)ptr - (PCHAR)Source);
128 VOID RtlCopyBytes(PVOID Destination,
132 RtlCopyMemory(Destination,Source,Length);
137 VOID RtlCopyMemory(VOID* Destination, CONST VOID* Source, ULONG Length)
139 DPRINT("RtlCopyMemory(Destination %x Source %x Length %d\n",
140 Destination,Source,Length);
141 memcpy(Destination,Source,Length);
142 DPRINT("*Destination %x\n",*(PULONG)Destination);
146 #endif /* LIBCAPTIVE */
156 memset(Destination,Fill,Length);
169 PULONG Dest = Destination;
170 ULONG Count = Length / sizeof(ULONG);
196 #endif /* LIBCAPTIVE */