From e61108d9b5b64b5d805ccc76fc90a5186097fe40 Mon Sep 17 00:00:00 2001 From: belliash Date: Sun, 21 Aug 2022 16:27:57 +0200 Subject: [PATCH] Implement RtlCopyMemory() and RtlSameMemory(), no inline functions in static library --- sdk/xtklib/CMakeLists.txt | 1 + sdk/xtklib/includes/librtl.h | 17 +++++-- sdk/xtklib/rtl/memory.c | 95 ++++++++++++++++++++++++++++++++++++ sdk/xtklib/rtl/plist.c | 5 -- 4 files changed, 108 insertions(+), 10 deletions(-) create mode 100644 sdk/xtklib/rtl/memory.c diff --git a/sdk/xtklib/CMakeLists.txt b/sdk/xtklib/CMakeLists.txt index e2fdf10..de73c23 100644 --- a/sdk/xtklib/CMakeLists.txt +++ b/sdk/xtklib/CMakeLists.txt @@ -10,6 +10,7 @@ include_directories( list(APPEND XTKLIB_SOURCE ${XTKLIB_SOURCE_DIR}/hl/cport.c ${XTKLIB_SOURCE_DIR}/hl/${ARCH}/cpufunc.c + ${XTKLIB_SOURCE_DIR}/rtl/memory.c ${XTKLIB_SOURCE_DIR}/rtl/plist.c ${XTKLIB_SOURCE_DIR}/rtl/widestr.c) diff --git a/sdk/xtklib/includes/librtl.h b/sdk/xtklib/includes/librtl.h index d49f0cd..3f15519 100644 --- a/sdk/xtklib/includes/librtl.h +++ b/sdk/xtklib/includes/librtl.h @@ -14,28 +14,35 @@ #include "xttypes.h" -XTINLINE +XTAPI +PVOID +RtlCopyMemory(IN PVOID Destination, + IN PCVOID Source, + IN SIZE_T Length); + VOID RtlInitializeListHead(IN PLIST_ENTRY ListHead); -XTINLINE VOID RtlInitializeListHead32(IN PLIST_ENTRY32 ListHead); -XTINLINE VOID RtlInsertHeadList(IN OUT PLIST_ENTRY ListHead, IN OUT PLIST_ENTRY Entry); -XTINLINE VOID RtlInsertTailList(IN OUT PLIST_ENTRY ListHead, IN OUT PLIST_ENTRY Entry); -XTINLINE BOOLEAN RtlListEmpty(PLIST_ENTRY ListHead); +XTAPI +SIZE_T +RtlSameMemory(IN PCVOID LeftBuffer, + IN PCVOID RightBuffer, + IN SIZE_T Length); + INT RtlWideStringCompare(IN CONST PWCHAR String1, IN CONST PWCHAR String2, diff --git a/sdk/xtklib/rtl/memory.c b/sdk/xtklib/rtl/memory.c new file mode 100644 index 0000000..d45ced2 --- /dev/null +++ b/sdk/xtklib/rtl/memory.c @@ -0,0 +1,95 @@ +/** + * PROJECT: ExectOS + * COPYRIGHT: See COPYING.md in the top level directory + * FILE: sdk/xtklib/rtl/memory.c + * DESCRIPTION: Memory related routines + * DEVELOPERS: Rafal Kupiec + */ + +#include + + +/** + * This routine copies a block of memory. + * + * @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 Returns the destination pointer. + * + * @since NT 3.5 + */ +XTAPI +PVOID +RtlCopyMemory(IN PVOID Destination, + IN PCVOID Source, + IN SIZE_T Length) +{ + PCHAR DestinationBytes = (PCHAR)Destination; + PCHAR SourceBytes = (PCHAR)Source; + + /* Forward buffer copy */ + while(Length--) + { + *DestinationBytes++ = *SourceBytes++; + } + + /* Return pointer to destination buffer */ + return Destination; +} + +/** + * 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 A value indicating the relationship between the content of the memory blocks. + * It returns zero (0) if both memory blocks are equal or a value different than + * zero representing which is greater if they do not match. + * + * @since XT 1.0 + */ +XTAPI +SIZE_T +RtlSameMemory(IN PCVOID LeftBuffer, + IN PCVOID RightBuffer, + IN SIZE_T Length) +{ + CONST UCHAR *Left = (PUCHAR)LeftBuffer; + CONST UCHAR *Right = (PUCHAR)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 (*Left - *Right); + } + + /* Advance to next byte */ + Left++; + Right++; + } + } + + /* Buffers equal */ + return 0; +} diff --git a/sdk/xtklib/rtl/plist.c b/sdk/xtklib/rtl/plist.c index 2c3a315..78aef2e 100644 --- a/sdk/xtklib/rtl/plist.c +++ b/sdk/xtklib/rtl/plist.c @@ -19,7 +19,6 @@ * * @since XT 1.0 */ -XTINLINE VOID RtlInitializeListHead(IN PLIST_ENTRY ListHead) { @@ -37,7 +36,6 @@ RtlInitializeListHead(IN PLIST_ENTRY ListHead) * * @since XT 1.0 */ -XTINLINE VOID RtlInitializeListHead32(IN PLIST_ENTRY32 ListHead) { @@ -58,7 +56,6 @@ RtlInitializeListHead32(IN PLIST_ENTRY32 ListHead) * * @since XT 1.0 */ -XTINLINE VOID RtlInsertHeadList(IN OUT PLIST_ENTRY ListHead, IN OUT PLIST_ENTRY Entry) @@ -82,7 +79,6 @@ RtlInsertHeadList(IN OUT PLIST_ENTRY ListHead, * * @since XT 1.0 */ -XTINLINE VOID RtlInsertTailList(IN OUT PLIST_ENTRY ListHead, IN OUT PLIST_ENTRY Entry) @@ -103,7 +99,6 @@ RtlInsertTailList(IN OUT PLIST_ENTRY ListHead, * * @since XT 1.0 */ -XTINLINE BOOLEAN RtlListEmpty(PLIST_ENTRY ListHead) {