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"
|
||||
|
||||
|
||||
XTAPI
|
||||
SIZE_T
|
||||
RtlCompareMemory(IN PCVOID LeftBuffer,
|
||||
IN PCVOID RightBuffer,
|
||||
IN SIZE_T Length);
|
||||
|
||||
XTAPI
|
||||
VOID
|
||||
RtlCopyMemory(IN PVOID Destination,
|
||||
RtlCopyMemory(OUT PVOID Destination,
|
||||
IN PCVOID Source,
|
||||
IN SIZE_T Length);
|
||||
|
||||
XTAPI
|
||||
VOID
|
||||
RtlFillMemory(OUT PVOID Destination,
|
||||
IN SIZE_T Length,
|
||||
IN UCHAR Value);
|
||||
|
||||
VOID
|
||||
RtlInitializeListHead(IN PLIST_ENTRY ListHead);
|
||||
|
||||
@ -37,12 +49,24 @@ RtlInsertTailList(IN OUT PLIST_ENTRY ListHead,
|
||||
BOOLEAN
|
||||
RtlListEmpty(PLIST_ENTRY ListHead);
|
||||
|
||||
XTAPI
|
||||
VOID
|
||||
RtlMoveMemory(OUT PVOID Destination,
|
||||
IN PCVOID Source,
|
||||
IN SIZE_T Length);
|
||||
|
||||
XTAPI
|
||||
BOOLEAN
|
||||
RtlSameMemory(IN PCVOID LeftBuffer,
|
||||
IN PCVOID RightBuffer,
|
||||
IN SIZE_T Length);
|
||||
|
||||
XTAPI
|
||||
VOID
|
||||
RtlSetMemory(OUT PVOID Destination,
|
||||
IN UCHAR Byte,
|
||||
IN SIZE_T Length);
|
||||
|
||||
XTCDECL
|
||||
INT
|
||||
RtlWideStringCompare(IN CONST PWCHAR String1,
|
||||
@ -55,4 +79,9 @@ RtlWideStringTokenize(IN PWCHAR String,
|
||||
IN CONST PWCHAR Delimiter,
|
||||
IN OUT PWCHAR *SavePtr);
|
||||
|
||||
XTAPI
|
||||
VOID
|
||||
RtlZeroMemory(OUT PVOID Destination,
|
||||
IN SIZE_T Length);
|
||||
|
||||
#endif /* __XTDK_RTLFUNCS_H */
|
||||
|
@ -9,6 +9,52 @@
|
||||
#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.
|
||||
*
|
||||
@ -27,7 +73,7 @@
|
||||
*/
|
||||
XTAPI
|
||||
VOID
|
||||
RtlCopyMemory(IN PVOID Destination,
|
||||
RtlCopyMemory(OUT PVOID Destination,
|
||||
IN PCVOID Source,
|
||||
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.
|
||||
*
|
||||
@ -63,28 +184,58 @@ RtlSameMemory(IN PCVOID LeftBuffer,
|
||||
IN PCVOID RightBuffer,
|
||||
IN SIZE_T Length)
|
||||
{
|
||||
CONST CHAR *Left = (PCHAR)LeftBuffer;
|
||||
CONST CHAR *Right = (PCHAR)RightBuffer;
|
||||
|
||||
/* Check if there is anything to compare */
|
||||
if(Length)
|
||||
{
|
||||
/* Iterate through whole buffer length */
|
||||
while(Length--)
|
||||
{
|
||||
/* Compare bytes from both bufers */
|
||||
if(*Left != *Right)
|
||||
{
|
||||
/* Buffers differ */
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
/* Advance to next byte */
|
||||
Left++;
|
||||
Right++;
|
||||
}
|
||||
}
|
||||
|
||||
/* Buffers equal */
|
||||
return TRUE;
|
||||
return (RtlCompareMemory(LeftBuffer, RightBuffer, Length) == Length) ? TRUE : FALSE;
|
||||
}
|
||||
|
||||
/**
|
||||
* This routine fills a section of memory with a specified byte.
|
||||
*
|
||||
* @param Destination
|
||||
* Supplies a pointer to the buffer to fill.
|
||||
*
|
||||
* @param Byte
|
||||
* Supplies a pattern to fill memory.
|
||||
*
|
||||
* @param Length
|
||||
* Specifies a number of bytes to store in memory.
|
||||
*
|
||||
* @return This routine does not return any value.
|
||||
*
|
||||
* @since XT 1.0
|
||||
*/
|
||||
XTAPI
|
||||
VOID
|
||||
RtlSetMemory(OUT PVOID Destination,
|
||||
IN UCHAR Byte,
|
||||
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 HlIoPortOutByte(ptr long)
|
||||
@ stdcall RtlCompareMemory(ptr ptr long)
|
||||
@ stdcall RtlCopyMemory(ptr ptr long)
|
||||
@ stdcall RtlFillMemory(ptr long long)
|
||||
@ stdcall RtlMoveMemory(ptr ptr long)
|
||||
@ stdcall RtlSameMemory(ptr ptr long)
|
||||
@ stdcall RtlSetMemory(ptr long 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