Integrate xtklib with the kernel
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:
95
xtoskrnl/rtl/memory.c
Normal file
95
xtoskrnl/rtl/memory.c
Normal file
@@ -0,0 +1,95 @@
|
||||
/**
|
||||
* PROJECT: ExectOS
|
||||
* COPYRIGHT: See COPYING.md in the top level directory
|
||||
* FILE: xtoskrnl/rtl/memory.c
|
||||
* DESCRIPTION: Memory related routines
|
||||
* DEVELOPERS: Rafal Kupiec <belliash@codingworkshop.eu.org>
|
||||
*/
|
||||
|
||||
#include <xtkmapi.h>
|
||||
|
||||
|
||||
/**
|
||||
* 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;
|
||||
}
|
106
xtoskrnl/rtl/plist.c
Normal file
106
xtoskrnl/rtl/plist.c
Normal file
@@ -0,0 +1,106 @@
|
||||
/**
|
||||
* PROJECT: ExectOS
|
||||
* COPYRIGHT: See COPYING.md in the top level directory
|
||||
* FILE: xtoskrnl/rtl/plist.c
|
||||
* DESCRIPTION: Linked list manipulation routines
|
||||
* DEVELOPERS: Rafal Kupiec <belliash@codingworkshop.eu.org>
|
||||
*/
|
||||
|
||||
#include <xtkmapi.h>
|
||||
|
||||
|
||||
/**
|
||||
* This routine initializes a structure representing the head of a double-linked list.
|
||||
*
|
||||
* @param ListHead
|
||||
* Pointer to a structure that serves as the list header.
|
||||
*
|
||||
* @return This routine does not return any value.
|
||||
*
|
||||
* @since XT 1.0
|
||||
*/
|
||||
VOID
|
||||
RtlInitializeListHead(IN PLIST_ENTRY ListHead)
|
||||
{
|
||||
ListHead->Blink = ListHead;
|
||||
ListHead->Flink = ListHead;
|
||||
}
|
||||
|
||||
/**
|
||||
* This routine initializes a structure representing the head of a 32bit double-linked list.
|
||||
*
|
||||
* @param ListHead
|
||||
* Pointer to a structure that serves as the list header.
|
||||
*
|
||||
* @return This routine does not return any value.
|
||||
*
|
||||
* @since XT 1.0
|
||||
*/
|
||||
VOID
|
||||
RtlInitializeListHead32(IN PLIST_ENTRY32 ListHead)
|
||||
{
|
||||
ListHead->Blink = PtrToUlong(ListHead);
|
||||
ListHead->Flink = PtrToUlong(ListHead);
|
||||
}
|
||||
|
||||
/**
|
||||
* This routine inserts an entry at the head of a double linked list.
|
||||
*
|
||||
* @param ListHead
|
||||
* Pointer to the head of the list.
|
||||
*
|
||||
* @param Entry
|
||||
* Pointer to the entry that will be inserted in the list.
|
||||
*
|
||||
* @return This routine does not return any value.
|
||||
*
|
||||
* @since XT 1.0
|
||||
*/
|
||||
VOID
|
||||
RtlInsertHeadList(IN OUT PLIST_ENTRY ListHead,
|
||||
IN OUT PLIST_ENTRY Entry)
|
||||
{
|
||||
Entry->Flink = ListHead->Flink;
|
||||
Entry->Blink = ListHead;
|
||||
ListHead->Flink->Blink = Entry;
|
||||
ListHead->Flink = Entry;
|
||||
}
|
||||
|
||||
/**
|
||||
* This routine inserts an entry at the tail of a double linked list.
|
||||
*
|
||||
* @param ListHead
|
||||
* Pointer to the head of the list.
|
||||
*
|
||||
* @param Entry
|
||||
* Pointer to the entry that will be inserted in the list.
|
||||
*
|
||||
* @return This routine does not return any value.
|
||||
*
|
||||
* @since XT 1.0
|
||||
*/
|
||||
VOID
|
||||
RtlInsertTailList(IN OUT PLIST_ENTRY ListHead,
|
||||
IN OUT PLIST_ENTRY Entry)
|
||||
{
|
||||
Entry->Flink = ListHead;
|
||||
Entry->Blink = ListHead->Blink;
|
||||
ListHead->Blink->Flink = Entry;
|
||||
ListHead->Blink = Entry;
|
||||
}
|
||||
|
||||
/**
|
||||
* Indicates whether a double linked list structure is empty.
|
||||
*
|
||||
* @param ListHead
|
||||
* Pointer to a structure that represents the head of the list.
|
||||
*
|
||||
* @return TRUE if there are currently no entries in the list or FALSE otherwise.
|
||||
*
|
||||
* @since XT 1.0
|
||||
*/
|
||||
BOOLEAN
|
||||
RtlListEmpty(PLIST_ENTRY ListHead)
|
||||
{
|
||||
return (ListHead->Flink == ListHead);
|
||||
}
|
122
xtoskrnl/rtl/widestr.c
Normal file
122
xtoskrnl/rtl/widestr.c
Normal file
@@ -0,0 +1,122 @@
|
||||
/**
|
||||
* PROJECT: ExectOS
|
||||
* COPYRIGHT: See COPYING.md in the top level directory
|
||||
* FILE: xtoskrnl/rtl/widestr.c
|
||||
* DESCRIPTION: Wide string support
|
||||
* DEVELOPERS: Rafal Kupiec <belliash@codingworkshop.eu.org>
|
||||
*/
|
||||
|
||||
#include "xtkmapi.h"
|
||||
|
||||
|
||||
/**
|
||||
* Compares at most specified number of characters of two C wide strings.
|
||||
*
|
||||
* @param String1
|
||||
* Wide string to be compared.
|
||||
*
|
||||
* @param String2
|
||||
* Wide string to be compared.
|
||||
*
|
||||
* @param Length
|
||||
* Maximum number of characters to compare.
|
||||
*
|
||||
* @return Integral value indicating the relationship between the wide strings.
|
||||
*
|
||||
* @since XT 1.0
|
||||
*/
|
||||
INT
|
||||
RtlWideStringCompare(IN CONST PWCHAR String1,
|
||||
IN CONST PWCHAR String2,
|
||||
IN CONST ULONG Length)
|
||||
{
|
||||
ULONG Index;
|
||||
|
||||
/* Iterate through the strings */
|
||||
for(Index = 0; Index < Length; Index++) {
|
||||
/* Check if string characters are equal */
|
||||
if(String1[Index] != String2[Index])
|
||||
{
|
||||
/* Different characters found */
|
||||
return String1[Index] < String2[Index] ? -1 : 1;
|
||||
}
|
||||
|
||||
/* Check if end of string reached */
|
||||
if(!String1[Index])
|
||||
{
|
||||
/* Equal strings until the end of String1 */
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
/* Strings are equal */
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Finds the next token in a null-terminated wide string.
|
||||
*
|
||||
* @param String
|
||||
* Pointer to the null-terminated wide string to tokenize.
|
||||
*
|
||||
* @param Delimiter
|
||||
* Pointer to the null-terminated wide string identifying delimiters.
|
||||
*
|
||||
* @param SavePtr
|
||||
* Pointer to an object used to store routine internal state.
|
||||
*
|
||||
* @return Pointer to the beginning of the next token or NULL if there are no more tokens.
|
||||
*
|
||||
* @since: XT 1.0
|
||||
*/
|
||||
PWCHAR
|
||||
RtlWideStringTokenize(IN PWCHAR String,
|
||||
IN CONST PWCHAR Delimiter,
|
||||
IN OUT PWCHAR *SavePtr)
|
||||
{
|
||||
PWCHAR Span, Token;
|
||||
WCHAR Char, SpanChar;
|
||||
|
||||
/* Check if there is anything to tokenize */
|
||||
if(String == NULL && (String = *SavePtr) == NULL)
|
||||
{
|
||||
/* Empty string given */
|
||||
return (NULL);
|
||||
}
|
||||
|
||||
/* Check non-delimiter characters */
|
||||
Char = *String++;
|
||||
if(Char == L'\0')
|
||||
{
|
||||
*SavePtr = NULL;
|
||||
return (NULL);
|
||||
}
|
||||
Token = String - 1;
|
||||
|
||||
/* Scan token for delimiters */
|
||||
for(;;)
|
||||
{
|
||||
Char = *String++;
|
||||
Span = (WCHAR *)Delimiter;
|
||||
do
|
||||
{
|
||||
if((SpanChar = *Span++) == Char)
|
||||
{
|
||||
if(Char == L'\0')
|
||||
{
|
||||
String = NULL;
|
||||
}
|
||||
else
|
||||
{
|
||||
String[-1] = L'\0';
|
||||
}
|
||||
/* Store pointer to the next token */
|
||||
*SavePtr = String;
|
||||
|
||||
/* Return token */
|
||||
return Token;
|
||||
}
|
||||
}
|
||||
while(SpanChar != L'\0');
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user