Implemented RtlCompareMemory() for better compatibility with NT and made use of it in RtlSameMemory(), implemented RtlFillMemory(), RtlMoveMemory(), RtlSetMemory() and RtlZeroMemory() as well
All checks were successful
ci/woodpecker/push/build Pipeline was successful
All checks were successful
ci/woodpecker/push/build Pipeline was successful
This commit is contained in:
parent
d56b10f252
commit
41f1aee6e3
@ -14,12 +14,24 @@
|
|||||||
#include "xttypes.h"
|
#include "xttypes.h"
|
||||||
|
|
||||||
|
|
||||||
|
XTAPI
|
||||||
|
SIZE_T
|
||||||
|
RtlCompareMemory(IN PCVOID LeftBuffer,
|
||||||
|
IN PCVOID RightBuffer,
|
||||||
|
IN SIZE_T Length);
|
||||||
|
|
||||||
XTAPI
|
XTAPI
|
||||||
VOID
|
VOID
|
||||||
RtlCopyMemory(IN PVOID Destination,
|
RtlCopyMemory(OUT PVOID Destination,
|
||||||
IN PCVOID Source,
|
IN PCVOID Source,
|
||||||
IN SIZE_T Length);
|
IN SIZE_T Length);
|
||||||
|
|
||||||
|
XTAPI
|
||||||
|
VOID
|
||||||
|
RtlFillMemory(OUT PVOID Destination,
|
||||||
|
IN SIZE_T Length,
|
||||||
|
IN UCHAR Value);
|
||||||
|
|
||||||
VOID
|
VOID
|
||||||
RtlInitializeListHead(IN PLIST_ENTRY ListHead);
|
RtlInitializeListHead(IN PLIST_ENTRY ListHead);
|
||||||
|
|
||||||
@ -37,12 +49,24 @@ RtlInsertTailList(IN OUT PLIST_ENTRY ListHead,
|
|||||||
BOOLEAN
|
BOOLEAN
|
||||||
RtlListEmpty(PLIST_ENTRY ListHead);
|
RtlListEmpty(PLIST_ENTRY ListHead);
|
||||||
|
|
||||||
|
XTAPI
|
||||||
|
VOID
|
||||||
|
RtlMoveMemory(OUT PVOID Destination,
|
||||||
|
IN PCVOID Source,
|
||||||
|
IN SIZE_T Length);
|
||||||
|
|
||||||
XTAPI
|
XTAPI
|
||||||
BOOLEAN
|
BOOLEAN
|
||||||
RtlSameMemory(IN PCVOID LeftBuffer,
|
RtlSameMemory(IN PCVOID LeftBuffer,
|
||||||
IN PCVOID RightBuffer,
|
IN PCVOID RightBuffer,
|
||||||
IN SIZE_T Length);
|
IN SIZE_T Length);
|
||||||
|
|
||||||
|
XTAPI
|
||||||
|
VOID
|
||||||
|
RtlSetMemory(OUT PVOID Destination,
|
||||||
|
IN UCHAR Byte,
|
||||||
|
IN SIZE_T Length);
|
||||||
|
|
||||||
XTCDECL
|
XTCDECL
|
||||||
INT
|
INT
|
||||||
RtlWideStringCompare(IN CONST PWCHAR String1,
|
RtlWideStringCompare(IN CONST PWCHAR String1,
|
||||||
@ -55,4 +79,9 @@ RtlWideStringTokenize(IN PWCHAR String,
|
|||||||
IN CONST PWCHAR Delimiter,
|
IN CONST PWCHAR Delimiter,
|
||||||
IN OUT PWCHAR *SavePtr);
|
IN OUT PWCHAR *SavePtr);
|
||||||
|
|
||||||
|
XTAPI
|
||||||
|
VOID
|
||||||
|
RtlZeroMemory(OUT PVOID Destination,
|
||||||
|
IN SIZE_T Length);
|
||||||
|
|
||||||
#endif /* __XTDK_RTLFUNCS_H */
|
#endif /* __XTDK_RTLFUNCS_H */
|
||||||
|
@ -9,6 +9,52 @@
|
|||||||
#include <xtkmapi.h>
|
#include <xtkmapi.h>
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This routine compares the first bytes of the specified memory buffers.
|
||||||
|
*
|
||||||
|
* @param LeftBuffer
|
||||||
|
* Supplies a pointer to the first block of memory to compare.
|
||||||
|
*
|
||||||
|
* @param RightBuffer
|
||||||
|
* Supplies a pointer to the second block of memory to compare.
|
||||||
|
*
|
||||||
|
* @param Length
|
||||||
|
* Specifies a number of bytes to compare.
|
||||||
|
*
|
||||||
|
* @return This routine returns a number of bytes that are equal in both memory blocks.
|
||||||
|
*
|
||||||
|
* @since NT 3.5
|
||||||
|
*/
|
||||||
|
XTAPI
|
||||||
|
SIZE_T
|
||||||
|
RtlCompareMemory(IN PCVOID LeftBuffer,
|
||||||
|
IN PCVOID RightBuffer,
|
||||||
|
IN SIZE_T Length)
|
||||||
|
{
|
||||||
|
SIZE_T Bytes = 0;
|
||||||
|
|
||||||
|
/* Check if there is anything to compare */
|
||||||
|
if(Length)
|
||||||
|
{
|
||||||
|
/* Iterate through whole buffer length */
|
||||||
|
while(Bytes < Length)
|
||||||
|
{
|
||||||
|
/* Compare bytes from both bufers */
|
||||||
|
if(((CONST PBYTE)LeftBuffer)[Bytes] != ((CONST PBYTE)RightBuffer)[Bytes])
|
||||||
|
{
|
||||||
|
/* Buffers are different */
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Increase number of common bytes */
|
||||||
|
Bytes++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Return number of equal characters */
|
||||||
|
return Bytes;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This routine copies a block of memory.
|
* This routine copies a block of memory.
|
||||||
*
|
*
|
||||||
@ -27,7 +73,7 @@
|
|||||||
*/
|
*/
|
||||||
XTAPI
|
XTAPI
|
||||||
VOID
|
VOID
|
||||||
RtlCopyMemory(IN PVOID Destination,
|
RtlCopyMemory(OUT PVOID Destination,
|
||||||
IN PCVOID Source,
|
IN PCVOID Source,
|
||||||
IN SIZE_T Length)
|
IN SIZE_T Length)
|
||||||
{
|
{
|
||||||
@ -41,6 +87,81 @@ RtlCopyMemory(IN PVOID Destination,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This routine fills a section of memory with a specified byte.
|
||||||
|
*
|
||||||
|
* @param Destination
|
||||||
|
* Supplies a pointer to the buffer to fill.
|
||||||
|
*
|
||||||
|
* @param Length
|
||||||
|
* Specifies a number of bytes to store in memory.
|
||||||
|
*
|
||||||
|
* @param Byte
|
||||||
|
* Supplies a pattern to fill memory.
|
||||||
|
*
|
||||||
|
* @return This routine does not return any value.
|
||||||
|
*
|
||||||
|
* @since NT 3.5
|
||||||
|
*/
|
||||||
|
XTAPI
|
||||||
|
VOID
|
||||||
|
RtlFillMemory(OUT PVOID Destination,
|
||||||
|
IN SIZE_T Length,
|
||||||
|
IN UCHAR Byte)
|
||||||
|
{
|
||||||
|
/* Fill the buffer with specified byte */
|
||||||
|
RtlSetMemory(Destination, Byte, Length);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This routine copies a block of memory either forward of backward, depeding
|
||||||
|
* if source and destination buffers overlap or not.
|
||||||
|
*
|
||||||
|
* @param Destination
|
||||||
|
* Supplies a pointer to the buffer where data will be copied to.
|
||||||
|
*
|
||||||
|
* @param Source
|
||||||
|
* Supplies a pointer to the source buffer that will be copied.
|
||||||
|
*
|
||||||
|
* @param Length
|
||||||
|
* Specifies the number of bytes to copy.
|
||||||
|
*
|
||||||
|
* @return This routine does not return any value.
|
||||||
|
*
|
||||||
|
* @since NT 3.5
|
||||||
|
*/
|
||||||
|
XTAPI
|
||||||
|
VOID
|
||||||
|
RtlMoveMemory(OUT PVOID Destination,
|
||||||
|
IN PCVOID Source,
|
||||||
|
IN SIZE_T Length)
|
||||||
|
{
|
||||||
|
PCHAR DestinationBytes = (PCHAR)Destination;
|
||||||
|
PCHAR SourceBytes = (PCHAR)Source;
|
||||||
|
|
||||||
|
/* Make sure there is anything to copy */
|
||||||
|
if((!SourceBytes) && (!DestinationBytes))
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Check if source and destination overlaps */
|
||||||
|
if((DestinationBytes > SourceBytes) && (SourceBytes + Length > DestinationBytes))
|
||||||
|
{
|
||||||
|
/* Backward buffer copy */
|
||||||
|
while(Length)
|
||||||
|
{
|
||||||
|
DestinationBytes[Length - 1] = SourceBytes[Length - 1];
|
||||||
|
Length--;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
/* Forward buffer copy */
|
||||||
|
RtlCopyMemory(Destination, Source, Length);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This routine compares the first bytes of the specified memory buffers.
|
* This routine compares the first bytes of the specified memory buffers.
|
||||||
*
|
*
|
||||||
@ -63,28 +184,58 @@ RtlSameMemory(IN PCVOID LeftBuffer,
|
|||||||
IN PCVOID RightBuffer,
|
IN PCVOID RightBuffer,
|
||||||
IN SIZE_T Length)
|
IN SIZE_T Length)
|
||||||
{
|
{
|
||||||
CONST CHAR *Left = (PCHAR)LeftBuffer;
|
return (RtlCompareMemory(LeftBuffer, RightBuffer, Length) == Length) ? TRUE : FALSE;
|
||||||
CONST CHAR *Right = (PCHAR)RightBuffer;
|
}
|
||||||
|
|
||||||
/* Check if there is anything to compare */
|
/**
|
||||||
if(Length)
|
* This routine fills a section of memory with a specified byte.
|
||||||
{
|
*
|
||||||
/* Iterate through whole buffer length */
|
* @param Destination
|
||||||
while(Length--)
|
* Supplies a pointer to the buffer to fill.
|
||||||
{
|
*
|
||||||
/* Compare bytes from both bufers */
|
* @param Byte
|
||||||
if(*Left != *Right)
|
* Supplies a pattern to fill memory.
|
||||||
{
|
*
|
||||||
/* Buffers differ */
|
* @param Length
|
||||||
return FALSE;
|
* Specifies a number of bytes to store in memory.
|
||||||
}
|
*
|
||||||
|
* @return This routine does not return any value.
|
||||||
/* Advance to next byte */
|
*
|
||||||
Left++;
|
* @since XT 1.0
|
||||||
Right++;
|
*/
|
||||||
}
|
XTAPI
|
||||||
}
|
VOID
|
||||||
|
RtlSetMemory(OUT PVOID Destination,
|
||||||
/* Buffers equal */
|
IN UCHAR Byte,
|
||||||
return TRUE;
|
IN SIZE_T Length)
|
||||||
|
{
|
||||||
|
PCHAR DestinationBytes = (PCHAR)Destination;
|
||||||
|
|
||||||
|
/* Fill the buffer with specified byte */
|
||||||
|
while(Length--)
|
||||||
|
{
|
||||||
|
*DestinationBytes++ = Byte;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This routine fills a section of memory with zeroes.
|
||||||
|
*
|
||||||
|
* @param Destination
|
||||||
|
* Supplies a pointer to the buffer to fill.
|
||||||
|
*
|
||||||
|
* @param Length
|
||||||
|
* Specifies a number of bytes to be filled with zeroes.
|
||||||
|
*
|
||||||
|
* @return This routine does not return any value.
|
||||||
|
*
|
||||||
|
* @since NT 3.5
|
||||||
|
*/
|
||||||
|
XTAPI
|
||||||
|
VOID
|
||||||
|
RtlZeroMemory(OUT PVOID Destination,
|
||||||
|
IN SIZE_T Length)
|
||||||
|
{
|
||||||
|
/* Fill the buffer with zeroes */
|
||||||
|
RtlSetMemory(Destination, 0, Length);
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,11 @@
|
|||||||
@ stdcall HlIoPortInByte(ptr)
|
@ stdcall HlIoPortInByte(ptr)
|
||||||
@ stdcall HlIoPortOutByte(ptr long)
|
@ stdcall HlIoPortOutByte(ptr long)
|
||||||
|
@ stdcall RtlCompareMemory(ptr ptr long)
|
||||||
@ stdcall RtlCopyMemory(ptr ptr long)
|
@ stdcall RtlCopyMemory(ptr ptr long)
|
||||||
|
@ stdcall RtlFillMemory(ptr long long)
|
||||||
|
@ stdcall RtlMoveMemory(ptr ptr long)
|
||||||
@ stdcall RtlSameMemory(ptr ptr long)
|
@ stdcall RtlSameMemory(ptr ptr long)
|
||||||
|
@ stdcall RtlSetMemory(ptr long long)
|
||||||
@ stdcall RtlWideStringCompare(wstr wstr long)
|
@ stdcall RtlWideStringCompare(wstr wstr long)
|
||||||
@ stdcall RtlWideStringTokenize(wstr wstr wstr)
|
@ stdcall RtlWideStringTokenize(wstr wstr wstr)
|
||||||
|
@ stdcall RtlZeroMemory(ptr long)
|
Loading…
Reference in New Issue
Block a user