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, PVOID 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, PVOID 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);
67 RtlCompareMemory(PVOID Source1,
71 * FUNCTION: Compares blocks of memory and returns the number of equal bytes
73 * Source1 = Block to compare
74 * Source2 = Block to compare
75 * Length = Number of bytes to compare
76 * RETURNS: Number of equal bytes
81 for (i=0,total=0;i<Length;i++)
83 if ( ((PUCHAR)Source1)[i] == ((PUCHAR)Source2)[i] )
94 RtlCompareMemoryUlong (
100 * FUNCTION: Compares a block of ULONGs with an ULONG and returns the number of equal bytes
102 * Source = Block to compare
103 * Length = Number of bytes to compare
104 * Value = Value to compare
105 * RETURNS: Number of equal bytes
108 PULONG ptr = (PULONG)Source;
109 ULONG len = Length / sizeof(ULONG);
112 for (i = 0; i < len; i++)
119 return (ULONG)((PCHAR)ptr - (PCHAR)Source);
124 VOID RtlCopyBytes(PVOID Destination,
128 RtlCopyMemory(Destination,Source,Length);
133 VOID RtlCopyMemory(VOID* Destination, CONST VOID* Source, ULONG Length)
135 DPRINT("RtlCopyMemory(Destination %x Source %x Length %d\n",
136 Destination,Source,Length);
137 memcpy(Destination,Source,Length);
138 DPRINT("*Destination %x\n",*(PULONG)Destination);
150 memset(Destination,Fill,Length);
162 PULONG Dest = Destination;
163 ULONG Count = Length / sizeof(ULONG);