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);
67 /* FIXME: It should return the length of initial sequence of matching characters,
68 * not the total amount of matching/differing bytes. We are not interested in
69 * the tail after the first non-matching byte.
70 * W32 doc formulation is a bit misleading.
74 RtlCompareMemory(PVOID Source1,
78 * FUNCTION: Compares blocks of memory and returns the number of equal bytes
80 * Source1 = Block to compare
81 * Source2 = Block to compare
82 * Length = Number of bytes to compare
83 * RETURNS: Number of equal bytes
88 for (i=0,total=0;i<Length;i++)
90 if ( ((PUCHAR)Source1)[i] == ((PUCHAR)Source2)[i] )
101 RtlCompareMemoryUlong (
107 * FUNCTION: Compares a block of ULONGs with an ULONG and returns the number of equal bytes
109 * Source = Block to compare
110 * Length = Number of bytes to compare
111 * Value = Value to compare
112 * RETURNS: Number of equal bytes
115 PULONG ptr = (PULONG)Source;
116 ULONG len = Length / sizeof(ULONG);
119 for (i = 0; i < len; i++)
126 return (ULONG)((PCHAR)ptr - (PCHAR)Source);
131 VOID RtlCopyBytes(PVOID Destination,
135 RtlCopyMemory(Destination,Source,Length);
140 VOID RtlCopyMemory(VOID* Destination, CONST VOID* Source, ULONG Length)
142 DPRINT("RtlCopyMemory(Destination %x Source %x Length %d\n",
143 Destination,Source,Length);
144 memcpy(Destination,Source,Length);
145 DPRINT("*Destination %x\n",*(PULONG)Destination);
149 #endif /* LIBCAPTIVE */
159 memset(Destination,Fill,Length);
172 PULONG Dest = Destination;
173 ULONG Count = Length / sizeof(ULONG);
199 #endif /* LIBCAPTIVE */