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);
73 * FUNCTION: Compares blocks of memory and returns the number of equal bytes
75 * Source1 = Block to compare
76 * Source2 = Block to compare
77 * Length = Number of bytes to compare
78 * RETURNS: Number of equal bytes
83 for (i=0,total=0;i<Length;i++)
85 if ( ((PUCHAR)Source1)[i] == ((PUCHAR)Source2)[i] )
96 RtlCompareMemoryUlong (
102 * FUNCTION: Compares a block of ULONGs with an ULONG and returns the number of equal bytes
104 * Source = Block to compare
105 * Length = Number of bytes to compare
106 * Value = Value to compare
107 * RETURNS: Number of equal bytes
110 PULONG ptr = (PULONG)Source;
111 ULONG len = Length / sizeof(ULONG);
114 for (i = 0; i < len; i++)
121 return (ULONG)((PCHAR)ptr - (PCHAR)Source);
126 VOID RtlCopyBytes(PVOID Destination,
130 RtlCopyMemory(Destination,Source,Length);
135 VOID RtlCopyMemory(VOID* Destination, CONST VOID* Source, ULONG Length)
137 DPRINT("RtlCopyMemory(Destination %x Source %x Length %d\n",
138 Destination,Source,Length);
139 memcpy(Destination,Source,Length);
140 DPRINT("*Destination %x\n",*(PULONG)Destination);
152 memset(Destination,Fill,Length);
164 PULONG Dest = Destination;
165 ULONG Count = Length / sizeof(ULONG);