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 *****************************************************************/
23 MmCopyToCaller(PVOID Dest, const VOID *Src, ULONG NumberOfBytes)
27 if (ExGetPreviousMode() == UserMode)
29 if ((ULONG)Dest >= KERNEL_BASE)
31 return(STATUS_ACCESS_VIOLATION);
33 Status = MmSafeCopyToUser(Dest, Src, NumberOfBytes);
38 memcpy(Dest, Src, NumberOfBytes);
39 return(STATUS_SUCCESS);
44 MmCopyFromCaller(PVOID Dest, const VOID *Src, ULONG NumberOfBytes)
48 if (ExGetPreviousMode() == UserMode)
50 if ((ULONG)Src >= KERNEL_BASE)
52 return(STATUS_ACCESS_VIOLATION);
54 Status = MmSafeCopyFromUser(Dest, Src, NumberOfBytes);
59 memcpy(Dest, Src, NumberOfBytes);
60 return(STATUS_SUCCESS);
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] )
100 RtlCompareMemoryUlong (
106 * FUNCTION: Compares a block of ULONGs with an ULONG and returns the number of equal bytes
108 * Source = Block to compare
109 * Length = Number of bytes to compare
110 * Value = Value to compare
111 * RETURNS: Number of equal bytes
114 PULONG ptr = (PULONG)Source;
115 ULONG len = Length / sizeof(ULONG);
118 for (i = 0; i < len; i++)
125 return (ULONG)((PCHAR)ptr - (PCHAR)Source);
130 VOID RtlCopyBytes(PVOID Destination,
134 RtlCopyMemory(Destination,Source,Length);
139 VOID RtlCopyMemory(VOID* Destination, CONST VOID* Source, ULONG Length)
141 DPRINT("RtlCopyMemory(Destination %x Source %x Length %d\n",
142 Destination,Source,Length);
143 memcpy(Destination,Source,Length);
144 DPRINT("*Destination %x\n",*(PULONG)Destination);
159 memset(Destination,Fill,Length);
174 PULONG Dest = Destination;
175 ULONG Count = Length / sizeof(ULONG);