diff --git a/sdk/xtdk/hlfuncs.h b/sdk/xtdk/hlfuncs.h index 0dce06d..93011a7 100644 --- a/sdk/xtdk/hlfuncs.h +++ b/sdk/xtdk/hlfuncs.h @@ -28,4 +28,37 @@ HlInitializeComPort(IN OUT PCPPORT Port, IN PUCHAR PortAddress, IN ULONG BaudRate); +XTCLINK +XTAPI +UCHAR +HlReadRegister8(IN PVOID Register); + +XTCLINK +XTAPI +USHORT +HlReadRegister16(IN PVOID Register); + +XTCLINK +XTAPI +ULONG +HlReadRegister32(IN PVOID Register); + +XTCLINK +XTAPI +VOID +HlWriteRegister8(IN PVOID Register, + IN UCHAR Value); + +XTCLINK +XTAPI +VOID +HlWriteRegister16(IN PVOID Register, + IN USHORT Value); + +XTCLINK +XTAPI +VOID +HlWriteRegister32(IN PVOID Register, + IN ULONG Value); + #endif /* __XTDK_HLFUNCS_H */ diff --git a/sdk/xtdk/rtlfuncs.h b/sdk/xtdk/rtlfuncs.h index 3773663..3673671 100644 --- a/sdk/xtdk/rtlfuncs.h +++ b/sdk/xtdk/rtlfuncs.h @@ -15,326 +15,363 @@ #include -/* Routines used by XTLDR */ -XTCDECL -VOID -RtlInitializeListHead(IN PLIST_ENTRY ListHead); - -XTCDECL -VOID -RtlInsertHeadList(IN OUT PLIST_ENTRY ListHead, - IN PLIST_ENTRY Entry); - -XTCDECL -VOID -RtlInsertTailList(IN OUT PLIST_ENTRY ListHead, - IN PLIST_ENTRY Entry); - -XTAPI -UCHAR -RtlReadRegisterByte(IN VOLATILE PVOID Register); - -XTAPI -ULONG -RtlReadRegisterLong(IN VOLATILE PVOID Register); - -XTAPI -USHORT -RtlReadRegisterShort(IN VOLATILE PVOID Register); - - -XTCDECL -VOID -RtlRemoveEntryList(IN PLIST_ENTRY Entry); - - /* Runtime Library routines forward references */ +XTCLINK XTAPI VOID RtlClearAllBits(IN PRTL_BITMAP BitMap); +XTCLINK XTAPI VOID RtlClearBit(IN PRTL_BITMAP BitMap, IN ULONG_PTR Bit); +XTCLINK XTAPI VOID RtlClearBits(IN PRTL_BITMAP BitMap, IN ULONG_PTR StartingIndex, IN ULONG_PTR Length); +XTCLINK XTAPI ULONG RtlClearSetBits(IN PRTL_BITMAP BitMap, IN ULONG_PTR Length, IN ULONG_PTR Index); +XTCLINK XTAPI BOOLEAN RtlCompareGuids(IN PGUID Guid1, IN PGUID Guid2); +XTCLINK XTAPI SIZE_T RtlCompareMemory(IN PCVOID LeftBuffer, IN PCVOID RightBuffer, IN SIZE_T Length); +XTCLINK XTAPI SIZE_T RtlCompareString(IN PCSTR String1, IN PCSTR String2, IN SIZE_T Length); +XTCLINK XTAPI SIZE_T RtlCompareStringInsensitive(IN PCSTR String1, IN PCSTR String2, IN SIZE_T Length); +XTCLINK XTAPI SIZE_T RtlCompareWideString(IN PCWSTR String1, IN PCWSTR String2, IN SIZE_T Length); +XTCLINK XTAPI SIZE_T RtlCompareWideStringInsensitive(IN PCWSTR String1, IN PCWSTR String2, IN SIZE_T Length); +XTCLINK XTAPI PCHAR RtlConcatenateString(OUT PCHAR Destination, IN PCHAR Source, IN SIZE_T Count); +XTCLINK XTAPI PWCHAR RtlConcatenateWideString(OUT PWCHAR Destination, IN PWCHAR Source, IN SIZE_T Count); +XTCLINK XTAPI LARGE_INTEGER RtlConvertToLargeInteger32(IN LONG Value); +XTCLINK XTAPI LARGE_INTEGER RtlConvertToLargeIntegerUnsigned32(IN ULONG Value); +XTCLINK XTAPI VOID RtlCopyMemory(OUT PVOID Destination, IN PCVOID Source, IN SIZE_T Length); +XTCLINK XTAPI VOID RtlCopyString(IN PCHAR Destination, IN PCSTR Source, IN ULONG Length); +XTCLINK XTAPI VOID RtlCopyWideString(IN PWCHAR Destination, IN PCWSTR Source, IN ULONG Length); +XTCLINK XTAPI LARGE_INTEGER RtlDivideLargeInteger(IN LARGE_INTEGER Dividend, IN ULONG Divisor, OUT PULONG Remainder); +XTCLINK XTAPI ULONG_PTR RtlFindClearBits(IN PRTL_BITMAP BitMap, IN ULONG_PTR Length, IN ULONG_PTR Index); +XTCLINK XTAPI ULONG_PTR RtlFindSetBits(IN PRTL_BITMAP BitMap, IN ULONG_PTR Length, IN ULONG_PTR Index); +XTCLINK XTAPI PCSTR RtlFindString(IN PCSTR Source, IN PCSTR Search); +XTCLINK XTAPI PCSTR RtlFindStringInsensitive(IN PCSTR Source, IN PCSTR Search); +XTCLINK XTAPI PCWSTR RtlFindWideString(IN PCWSTR Source, IN PCWSTR Search); +XTCLINK XTAPI PCWSTR RtlFindWideStringInsensitive(IN PCWSTR Source, IN PCWSTR Search); +XTCLINK XTAPI XTSTATUS RtlFormatWideString(IN PRTL_PRINT_CONTEXT Context, IN PCWSTR Format, IN VA_LIST ArgumentList); +XTCLINK XTAPI VOID RtlInitializeBitMap(IN PRTL_BITMAP BitMap, IN PULONG_PTR Buffer, IN ULONG Size); +XTCLINK +XTCDECL +VOID +RtlInitializeListHead(IN PLIST_ENTRY ListHead); + +XTCLINK +XTCDECL +VOID +RtlInsertHeadList(IN OUT PLIST_ENTRY ListHead, + IN PLIST_ENTRY Entry); + +XTCLINK +XTCDECL +VOID +RtlInsertTailList(IN OUT PLIST_ENTRY ListHead, + IN PLIST_ENTRY Entry); + +XTCLINK +XTCDECL +BOOLEAN +RtlListEmpty(IN PLIST_ENTRY ListHead); + +XTCLINK +XTCDECL +BOOLEAN +RtlListLoop(IN PLIST_ENTRY ListHead); + +XTCLINK XTAPI VOID RtlMoveMemory(OUT PVOID Destination, IN PCVOID Source, IN SIZE_T Length); +XTCLINK XTAPI LARGE_INTEGER RtlMultiplyLargeInteger(IN LARGE_INTEGER Multiplicand, IN LONG Multiplier); +XTCLINK +XTCDECL +VOID +RtlRemoveEntryList(IN PLIST_ENTRY Entry); + +XTCLINK XTAPI VOID RtlReverseString(IN OUT PCHAR String, IN ULONG Length); +XTCLINK XTAPI VOID RtlReverseWideString(IN OUT PWCHAR String, IN ULONG Length); +XTCLINK XTAPI BOOLEAN RtlSameMemory(IN PCVOID LeftBuffer, IN PCVOID RightBuffer, IN SIZE_T Length); +XTCLINK XTAPI VOID RtlSetAllBits(IN PRTL_BITMAP BitMap); +XTCLINK XTAPI VOID RtlSetBit(IN PRTL_BITMAP BitMap, IN ULONG_PTR Bit); +XTCLINK XTAPI VOID RtlSetBits(IN PRTL_BITMAP BitMap, IN ULONG_PTR StartingIndex, IN ULONG_PTR Length); +XTCLINK XTAPI ULONG RtlSetClearBits(IN PRTL_BITMAP BitMap, IN ULONG_PTR Length, IN ULONG_PTR Index); +XTCLINK XTAPI VOID RtlSetMemory(OUT PVOID Destination, IN UCHAR Byte, IN SIZE_T Length); +XTCLINK XTAPI SIZE_T RtlStringLength(IN PCSTR String, IN SIZE_T MaxLength); +XTCLINK XTAPI SIZE_T RtlStringToWideString(OUT PWCHAR Destination, IN PCSTR *Source, IN SIZE_T Length); +XTCLINK XTAPI BOOLEAN RtlTestBit(IN PRTL_BITMAP BitMap, IN ULONG_PTR Bit); +XTCLINK XTAPI PCHAR RtlTokenizeString(IN PCHAR String, IN PCSTR Delimiter, IN OUT PCHAR *SavePtr); +XTCLINK XTAPI PWCHAR RtlTokenizeWideString(IN PWCHAR String, IN PCWSTR Delimiter, IN OUT PWCHAR *SavePtr); +XTCLINK XTAPI CHAR RtlToLowerCharacter(IN CHAR Character); +XTCLINK XTAPI WCHAR RtlToLowerWideCharacter(IN WCHAR Character); +XTCLINK XTAPI CHAR RtlToUpperCharacter(IN CHAR Character); +XTCLINK XTAPI WCHAR RtlToUpperWideCharacter(IN WCHAR Character); +XTCLINK XTAPI PCHAR RtlTrimLeftString(IN PCHAR String); +XTCLINK XTAPI PWCHAR RtlTrimLeftWideString(IN PWCHAR String); +XTCLINK XTAPI PCHAR RtlTrimRightString(IN PCHAR String); +XTCLINK XTAPI PWCHAR RtlTrimRightWideString(IN PWCHAR String); +XTCLINK XTAPI PCHAR RtlTrimString(IN PCHAR String); +XTCLINK XTAPI PWCHAR RtlTrimWideString(IN PWCHAR String); +XTCLINK XTAPI SIZE_T RtlWideStringLength(IN PCWSTR String, IN SIZE_T MaxLength); -XTAPI -VOID -RtlWriteRegisterByte(IN VOLATILE PVOID Register, - IN UCHAR Value); - -XTAPI -VOID -RtlWriteRegisterLong(IN VOLATILE PVOID Register, - IN ULONG Value); - -XTAPI -VOID -RtlWriteRegisterShort(IN VOLATILE PVOID Register, - IN USHORT Value); - +XTCLINK XTAPI VOID RtlZeroMemory(OUT PVOID Destination, diff --git a/sdk/xtdk/rtltypes.h b/sdk/xtdk/rtltypes.h index 5c9dce6..505f1e6 100644 --- a/sdk/xtdk/rtltypes.h +++ b/sdk/xtdk/rtltypes.h @@ -56,17 +56,17 @@ typedef XTSTATUS (*PWRITE_WIDE_CHARACTER)(IN WCHAR Character); /* Variable types enumeration list */ typedef enum _RTL_VARIABLE_TYPE { - Unknown, - AnsiString, - Boolean, - Char, - Float, - Guid, - Integer, - String, - UnicodeString, - WideChar, - WideString + TypeUnknown, + TypeAnsiString, + TypeBoolean, + TypeChar, + TypeFloat, + TypeGuid, + TypeInteger, + TypeString, + TypeUnicodeString, + TypeWideChar, + TypeWideString } RTL_VARIABLE_TYPE, *PRTL_VARIABLE_TYPE; /* Bit Map structure definition */ diff --git a/xtoskrnl/CMakeLists.txt b/xtoskrnl/CMakeLists.txt index 48a1719..14918b1 100644 --- a/xtoskrnl/CMakeLists.txt +++ b/xtoskrnl/CMakeLists.txt @@ -33,9 +33,11 @@ list(APPEND XTOSKRNL_SOURCE ${XTOSKRNL_SOURCE_DIR}/ex/rundown.cc ${XTOSKRNL_SOURCE_DIR}/hl/acpi.c ${XTOSKRNL_SOURCE_DIR}/hl/cport.c + ${XTOSKRNL_SOURCE_DIR}/hl/exports.cc ${XTOSKRNL_SOURCE_DIR}/hl/fbdev.c ${XTOSKRNL_SOURCE_DIR}/hl/globals.c ${XTOSKRNL_SOURCE_DIR}/hl/init.c + ${XTOSKRNL_SOURCE_DIR}/hl/ioreg.cc ${XTOSKRNL_SOURCE_DIR}/hl/${ARCH}/cpu.c ${XTOSKRNL_SOURCE_DIR}/hl/${ARCH}/pic.c ${XTOSKRNL_SOURCE_DIR}/hl/${ARCH}/ioport.c @@ -73,19 +75,19 @@ list(APPEND XTOSKRNL_SOURCE ${XTOSKRNL_SOURCE_DIR}/mm/${ARCH}/pages.c ${XTOSKRNL_SOURCE_DIR}/mm/${ARCH}/pmap.c ${XTOSKRNL_SOURCE_DIR}/po/idle.c - ${XTOSKRNL_SOURCE_DIR}/rtl/atomic.c - ${XTOSKRNL_SOURCE_DIR}/rtl/bitmap.c - ${XTOSKRNL_SOURCE_DIR}/rtl/byteswap.c - ${XTOSKRNL_SOURCE_DIR}/rtl/globals.c - ${XTOSKRNL_SOURCE_DIR}/rtl/guid.c - ${XTOSKRNL_SOURCE_DIR}/rtl/ioreg.c - ${XTOSKRNL_SOURCE_DIR}/rtl/math.c - ${XTOSKRNL_SOURCE_DIR}/rtl/memory.c - ${XTOSKRNL_SOURCE_DIR}/rtl/plist.c - ${XTOSKRNL_SOURCE_DIR}/rtl/string.c - ${XTOSKRNL_SOURCE_DIR}/rtl/widestr.c - ${XTOSKRNL_SOURCE_DIR}/rtl/${ARCH}/dispatch.c - ${XTOSKRNL_SOURCE_DIR}/rtl/${ARCH}/exsup.c) + ${XTOSKRNL_SOURCE_DIR}/rtl/${ARCH}/dispatch.cc + ${XTOSKRNL_SOURCE_DIR}/rtl/${ARCH}/exsup.cc + ${XTOSKRNL_SOURCE_DIR}/rtl/atomic.cc + ${XTOSKRNL_SOURCE_DIR}/rtl/bitmap.cc + ${XTOSKRNL_SOURCE_DIR}/rtl/data.cc + ${XTOSKRNL_SOURCE_DIR}/rtl/endian.cc + ${XTOSKRNL_SOURCE_DIR}/rtl/exports.cc + ${XTOSKRNL_SOURCE_DIR}/rtl/guid.cc + ${XTOSKRNL_SOURCE_DIR}/rtl/llist.cc + ${XTOSKRNL_SOURCE_DIR}/rtl/math.cc + ${XTOSKRNL_SOURCE_DIR}/rtl/memory.cc + ${XTOSKRNL_SOURCE_DIR}/rtl/string.cc + ${XTOSKRNL_SOURCE_DIR}/rtl/widestr.cc) # Set module definition SPEC file set_specfile(xtoskrnl.spec xtoskrnl.exe) diff --git a/xtoskrnl/hl/exports.cc b/xtoskrnl/hl/exports.cc new file mode 100644 index 0000000..3adda12 --- /dev/null +++ b/xtoskrnl/hl/exports.cc @@ -0,0 +1,130 @@ +/** + * PROJECT: ExectOS + * COPYRIGHT: See COPYING.md in the top level directory + * FILE: xtoskrnl/hl/exports.cc + * DESCRIPTION: C-compatible API wrappers for exported kernel functions + * DEVELOPERS: Aiken Harris + */ + +#include + + +/** + * Reads an 8-bit data from a specified register address. + * + * @param Register + * Supplies a pointer to register address holding data to read. + * + * @return This routine returns a value at the specified register. + * + * @since XT 1.0 + */ +XTCLINK +XTAPI +UCHAR +HlReadRegister8(IN PVOID Register) +{ + return HL::IoRegister::ReadRegister8(Register); +} + +/** + * Reads a 16-bit data from a specified register address. + * + * @param Register + * Supplies a pointer to register address holding data to read. + * + * @return This routine returns a value at the specified register. + * + * @since XT 1.0 + */ +XTCLINK +XTAPI +USHORT +HlReadRegister16(IN PVOID Register) +{ + return HL::IoRegister::ReadRegister16(Register); +} + +/** + * Reads a 32-bit data from a specified register address. + * + * @param Register + * Supplies a pointer to register address holding data to read. + * + * @return This routine returns a value at the specified register. + * + * @since XT 1.0 + */ +XTCLINK +XTAPI +ULONG +HlReadRegister32(IN PVOID Register) +{ + return HL::IoRegister::ReadRegister32(Register); +} + +/** + * Writes an 8-bit value into a specified register address. + * + * @param Register + * Supplies a pointer to register address where data will be written. + * + * @param Value + * Supplies a new value that will be stored into a register. + * + * @return This routine does not return any value. + * + * @since XT 1.0 + */ +XTCLINK +XTAPI +VOID +HlWriteRegister8(IN PVOID Register, + IN UCHAR Value) +{ + HL::IoRegister::WriteRegister8(Register, Value); +} + +/** + * Writes a 16-bit value into a specified register address. + * + * @param Register + * Supplies a pointer to register address where data will be written. + * + * @param Value + * Supplies a new value that will be stored into a register. + * + * @return This routine does not return any value. + * + * @since XT 1.0 + */ +XTCLINK +XTAPI +VOID +HlWriteRegister16(IN PVOID Register, + IN USHORT Value) +{ + HL::IoRegister::WriteRegister16(Register, Value); +} + +/** + * Writes a 32-bit value into a specified register address. + * + * @param Register + * Supplies a pointer to register address where data will be written. + * + * @param Value + * Supplies a new value that will be stored into a register. + * + * @return This routine does not return any value. + * + * @since XT 1.0 + */ +XTCLINK +XTAPI +VOID +HlWriteRegister32(IN PVOID Register, + IN ULONG Value) +{ + HL::IoRegister::WriteRegister32(Register, Value); +} diff --git a/xtoskrnl/rtl/ioreg.c b/xtoskrnl/hl/ioreg.cc similarity index 53% rename from xtoskrnl/rtl/ioreg.c rename to xtoskrnl/hl/ioreg.cc index 76dd0f5..f104019 100644 --- a/xtoskrnl/rtl/ioreg.c +++ b/xtoskrnl/hl/ioreg.cc @@ -1,73 +1,73 @@ /** * PROJECT: ExectOS * COPYRIGHT: See COPYING.md in the top level directory - * FILE: xtoskrnl/rtl/ioreg.c - * DESCRIPTION: I/O registers related routines + * FILE: xtoskrnl/hl/ioreg.cc + * DESCRIPTION: Basic I/O registers access functionality * DEVELOPERS: Rafal Kupiec */ -#include +#include /** - * Reads a byte from a specified register address. + * Reads an 8-bit data from a specified register address. * * @param Register * Supplies a pointer to register address holding data to read. * - * @return This routine returns UCHAR byte read from the register. + * @return This routine returns a value at the specified register. * * @since XT 1.0 */ XTAPI UCHAR -RtlReadRegisterByte(IN VOLATILE PVOID Register) +HL::IoRegister::ReadRegister8(IN PVOID Register) { return *((VOLATILE PUCHAR)Register); } /** - * Reads a byte from a specified register address. + * Reads a 16-bit data from a specified register address. * * @param Register * Supplies a pointer to register address holding data to read. * - * @return This routine returns ULONG byte read from the register. - * - * @since XT 1.0 - */ -XTAPI -ULONG -RtlReadRegisterLong(IN VOLATILE PVOID Register) -{ - return *((VOLATILE PULONG)Register); -} - -/** - * Reads a byte from a specified register address. - * - * @param Register - * Supplies a pointer to register address holding data to read. - * - * @return This routine returns USHORT byte read from the register. + * @return This routine returns a value at the specified register. * * @since XT 1.0 */ XTAPI USHORT -RtlReadRegisterShort(IN VOLATILE PVOID Register) +HL::IoRegister::ReadRegister16(IN PVOID Register) { return *((VOLATILE PUSHORT)Register); } /** - * Writes a byte into a specified register address. + * Reads a 32-bit data from a specified register address. + * + * @param Register + * Supplies a pointer to register address holding data to read. + * + * @return This routine returns a value at the specified register. + * + * @since XT 1.0 + */ +XTAPI +ULONG +HL::IoRegister::ReadRegister32(IN PVOID Register) +{ + return *((VOLATILE PULONG)Register); +} + +/** + * Writes an 8-bit value into a specified register address. * * @param Register * Supplies a pointer to register address where data will be written. * * @param Value - * Supplies a new UCHAR value that will be stored into a register. + * Supplies a new value that will be stored into a register. * * @return This routine does not return any value. * @@ -75,20 +75,20 @@ RtlReadRegisterShort(IN VOLATILE PVOID Register) */ XTAPI VOID -RtlWriteRegisterByte(IN VOLATILE PVOID Register, - IN UCHAR Value) +HL::IoRegister::WriteRegister8(IN PVOID Register, + IN UCHAR Value) { *((VOLATILE PUCHAR)Register) = Value; } /** - * Writes a byte into a specified register address. + * Writes a 16-bit value into a specified register address. * * @param Register * Supplies a pointer to register address where data will be written. * * @param Value - * Supplies a new ULONG value that will be stored into a register. + * Supplies a new value that will be stored into a register. * * @return This routine does not return any value. * @@ -96,29 +96,29 @@ RtlWriteRegisterByte(IN VOLATILE PVOID Register, */ XTAPI VOID -RtlWriteRegisterLong(IN VOLATILE PVOID Register, - IN ULONG Value) -{ - *((VOLATILE PULONG)Register) = Value; -} - -/** - * Writes a byte into a specified register address. - * - * @param Register - * Supplies a pointer to register address where data will be written. - * - * @param Value - * Supplies a new USHORT value that will be stored into a register. - * - * @return This routine does not return any value. - * - * @since XT 1.0 - */ -XTAPI -VOID -RtlWriteRegisterShort(IN VOLATILE PVOID Register, - IN USHORT Value) +HL::IoRegister::WriteRegister16(IN PVOID Register, + IN USHORT Value) { *((VOLATILE PUSHORT)Register) = Value; } + +/** + * Writes a 32-bit value into a specified register address. + * + * @param Register + * Supplies a pointer to register address where data will be written. + * + * @param Value + * Supplies a new value that will be stored into a register. + * + * @return This routine does not return any value. + * + * @since XT 1.0 + */ +XTAPI +VOID +HL::IoRegister::WriteRegister32(IN PVOID Register, + IN ULONG Value) +{ + *((VOLATILE PULONG)Register) = Value; +} diff --git a/xtoskrnl/includes/ar.hh b/xtoskrnl/includes/ar.hh index d01dbb9..be59534 100644 --- a/xtoskrnl/includes/ar.hh +++ b/xtoskrnl/includes/ar.hh @@ -2,7 +2,7 @@ * PROJECT: ExectOS * COPYRIGHT: See COPYING.md in the top level directory * FILE: xtoskrnl/includes/ar.hh - * DESCRIPTION: + * DESCRIPTION: Architecture Library * DEVELOPERS: Aiken Harris */ diff --git a/xtoskrnl/includes/ex.hh b/xtoskrnl/includes/ex.hh index 0762412..747bd2f 100644 --- a/xtoskrnl/includes/ex.hh +++ b/xtoskrnl/includes/ex.hh @@ -2,7 +2,7 @@ * PROJECT: ExectOS * COPYRIGHT: See COPYING.md in the top level directory * FILE: xtoskrnl/includes/ex.hh - * DESCRIPTION: + * DESCRIPTION: Kernel Executive * DEVELOPERS: Aiken Harris */ diff --git a/xtoskrnl/includes/rtl.hh b/xtoskrnl/includes/rtl.hh new file mode 100644 index 0000000..a35ca99 --- /dev/null +++ b/xtoskrnl/includes/rtl.hh @@ -0,0 +1,25 @@ +/** + * PROJECT: ExectOS + * COPYRIGHT: See COPYING.md in the top level directory + * FILE: xtoskrnl/includes/rtl.hh + * DESCRIPTION: Runtime Library + * DEVELOPERS: Aiken Harris + */ + +#ifndef __XTOSKRNL_RTL_HH +#define __XTOSKRNL_RTL_HH + +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#endif /* __XTOSKRNL_RTL_HH */ diff --git a/xtoskrnl/includes/rtl/atomic.hh b/xtoskrnl/includes/rtl/atomic.hh new file mode 100644 index 0000000..f3b9150 --- /dev/null +++ b/xtoskrnl/includes/rtl/atomic.hh @@ -0,0 +1,97 @@ +/** + * PROJECT: ExectOS + * COPYRIGHT: See COPYING.md in the top level directory + * FILE: xtoskrnl/includes/rtl/atomic.hh + * DESCRIPTION: Atomic operations support + * DEVELOPERS: Aiken Harris + */ + +#ifndef __XTOSKRNL_RTL_ATOMIC_HH +#define __XTOSKRNL_RTL_ATOMIC_HH + +#include + + +/* Runtime Library */ +namespace RTL +{ + class Atomic + { + public: + STATIC XTFASTCALL CHAR And8(IN PCHAR Address, + IN CHAR Mask); + STATIC XTFASTCALL SHORT And16(IN PSHORT Address, + IN SHORT Mask); + STATIC XTFASTCALL LONG And32(IN PLONG Address, + IN LONG Mask); + STATIC XTFASTCALL LONG_PTR And64(IN PLONG_PTR Address, + IN LONG_PTR Mask); + STATIC XTFASTCALL UCHAR BitTestAndSet(IN PLONG Base, + IN LONG Offset); + STATIC XTFASTCALL UCHAR BitTestAndSet64(IN PLONGLONG Base, + IN LONGLONG Offset); + STATIC XTFASTCALL CHAR CompareExchange8(IN PCHAR Address, + IN CHAR Comperand, + IN CHAR Exchange); + STATIC XTFASTCALL SHORT CompareExchange16(IN PSHORT Address, + IN SHORT Comperand, + IN SHORT Exchange); + STATIC XTFASTCALL LONG CompareExchange32(IN PLONG Address, + IN LONG Comperand, + IN LONG Exchange); + STATIC XTFASTCALL LONG_PTR CompareExchange64(IN PLONG_PTR Address, + IN LONG_PTR Comperand, + IN LONG_PTR Exchange); + STATIC XTFASTCALL PVOID CompareExchangePointer(IN PVOID *Address, + IN PVOID Comperand, + IN PVOID Exchange); + STATIC XTFASTCALL CHAR Decrement8(IN PCHAR Address); + STATIC XTFASTCALL SHORT Decrement16(IN PSHORT Address); + STATIC XTFASTCALL LONG Decrement32(IN PLONG Address); + STATIC XTFASTCALL LONG_PTR Decrement64(IN PLONG_PTR Address); + STATIC XTFASTCALL CHAR Exchange8(IN PCHAR Address, + IN CHAR Exchange); + STATIC XTFASTCALL SHORT Exchange16(IN PSHORT Address, + IN SHORT Exchange); + STATIC XTFASTCALL LONG Exchange32(IN PLONG Address, + IN LONG Exchange); + STATIC XTFASTCALL LONG_PTR Exchange64(IN PLONG_PTR Address, + IN LONG_PTR Exchange); + STATIC XTFASTCALL CHAR ExchangeAdd8(IN PCHAR Address, + IN CHAR Value); + STATIC XTFASTCALL SHORT ExchangeAdd16(IN PSHORT Address, + IN SHORT Value); + STATIC XTFASTCALL LONG ExchangeAdd32(IN PLONG Address, + IN LONG Value); + STATIC XTFASTCALL LONG_PTR ExchangeAdd64(IN PLONG_PTR Address, + IN LONG_PTR Value); + STATIC XTFASTCALL PVOID ExchangePointer(IN PVOID *Address, + IN PVOID Exchange); + STATIC XTFASTCALL PSINGLE_LIST_ENTRY FlushSingleList(IN PSINGLE_LIST_HEADER Header); + STATIC XTFASTCALL CHAR Increment8(IN PCHAR Address); + STATIC XTFASTCALL SHORT Increment16(IN PSHORT Address); + STATIC XTFASTCALL LONG Increment32(IN PLONG Address); + STATIC XTFASTCALL LONG_PTR Increment64(IN PLONG_PTR Address); + STATIC XTFASTCALL CHAR Or8(IN PCHAR Address, + IN CHAR Mask); + STATIC XTFASTCALL SHORT Or16(IN PSHORT Address, + IN SHORT Mask); + STATIC XTFASTCALL LONG Or32(IN PLONG Address, + IN LONG Mask); + STATIC XTFASTCALL LONG_PTR Or64(IN PLONG_PTR Address, + IN LONG_PTR Mask); + STATIC XTFASTCALL XTFASTCALL PSINGLE_LIST_ENTRY PopEntrySingleList(IN PSINGLE_LIST_HEADER Header); + STATIC XTFASTCALL PSINGLE_LIST_ENTRY PushEntrySingleList(IN PSINGLE_LIST_HEADER Header, + IN PSINGLE_LIST_ENTRY Entry); + STATIC XTFASTCALL CHAR Xor8(IN PCHAR Address, + IN CHAR Mask); + STATIC XTFASTCALL SHORT Xor16(IN PSHORT Address, + IN SHORT Mask); + STATIC XTFASTCALL LONG Xor32(IN PLONG Address, + IN LONG Mask); + STATIC XTFASTCALL LONG_PTR Xor64(IN PLONG_PTR Address, + IN LONG_PTR Mask); + }; +} + +#endif /* __XTOSKRNL_RTL_ATOMIC_HH */ diff --git a/xtoskrnl/includes/rtl/bitmap.hh b/xtoskrnl/includes/rtl/bitmap.hh new file mode 100644 index 0000000..933cce1 --- /dev/null +++ b/xtoskrnl/includes/rtl/bitmap.hh @@ -0,0 +1,64 @@ +/** + * PROJECT: ExectOS + * COPYRIGHT: See COPYING.md in the top level directory + * FILE: xtoskrnl/includes/rtl/bitmap.hh + * DESCRIPTION: Bit maps support + * DEVELOPERS: Aiken Harris + */ + +#ifndef __XTOSKRNL_RTL_BITMAP_HH +#define __XTOSKRNL_RTL_BITMAP_HH + +#include + + +/* Runtime Library */ +namespace RTL +{ + class BitMap + { + public: + STATIC XTAPI VOID ClearAllBits(IN PRTL_BITMAP BitMap); + STATIC XTAPI VOID ClearBit(IN PRTL_BITMAP BitMap, + IN ULONG_PTR Bit); + STATIC XTAPI VOID ClearBits(IN PRTL_BITMAP BitMap, + IN ULONG_PTR StartingIndex, + IN ULONG_PTR Length); + STATIC XTAPI ULONG ClearSetBits(IN PRTL_BITMAP BitMap, + IN ULONG_PTR Length, + IN ULONG_PTR Index); + STATIC XTAPI VOID DumpBitMap(IN PRTL_BITMAP BitMap); + STATIC XTAPI ULONG_PTR FindClearBits(IN PRTL_BITMAP BitMap, + IN ULONG_PTR Length, + IN ULONG_PTR Index); + STATIC XTAPI ULONG_PTR FindSetBits(IN PRTL_BITMAP BitMap, + IN ULONG_PTR Length, + IN ULONG_PTR Index); + STATIC XTAPI VOID InitializeBitMap(IN PRTL_BITMAP BitMap, + IN PULONG_PTR Buffer, + IN ULONG Size); + STATIC XTAPI VOID SetAllBits(IN PRTL_BITMAP BitMap); + STATIC XTAPI VOID SetBit(IN PRTL_BITMAP BitMap, + IN ULONG_PTR Bit); + STATIC XTAPI VOID SetBits(IN PRTL_BITMAP BitMap, + IN ULONG_PTR StartingIndex, + IN ULONG_PTR Length); + STATIC XTAPI ULONG SetClearBits(IN PRTL_BITMAP BitMap, + IN ULONG_PTR Length, + IN ULONG_PTR Index); + STATIC XTAPI BOOLEAN TestBit(IN PRTL_BITMAP BitMap, + IN ULONG_PTR Bit); + + private: + STATIC XTAPI ULONG_PTR CountBits(IN PRTL_BITMAP BitMap, + IN ULONG_PTR Length, + IN ULONG_PTR StartingIndex, + IN BOOLEAN SetBits); + STATIC XTAPI ULONG_PTR FindBits(IN PRTL_BITMAP BitMap, + IN ULONG_PTR Length, + IN ULONG_PTR StartingIndex, + IN BOOLEAN SetBits); + }; +} + +#endif /* __XTOSKRNL_RTL_BITMAP_HH */ diff --git a/xtoskrnl/includes/rtl/dispatch.hh b/xtoskrnl/includes/rtl/dispatch.hh new file mode 100644 index 0000000..171306d --- /dev/null +++ b/xtoskrnl/includes/rtl/dispatch.hh @@ -0,0 +1,26 @@ +/** + * PROJECT: ExectOS + * COPYRIGHT: See COPYING.md in the top level directory + * FILE: xtoskrnl/includes/rtl/dispatch.hh + * DESCRIPTION: Dispatching support + * DEVELOPERS: Aiken Harris + */ + +#ifndef __XTOSKRNL_RTL_DISPATCH_HH +#define __XTOSKRNL_RTL_DISPATCH_HH + +#include + + +/* Runtime Library */ +namespace RTL +{ + class Dispatcher + { + public: + STATIC XTAPI VOID GetStackLimits(OUT PULONG_PTR StackBase, + OUT PULONG_PTR StackLimit); + }; +} + +#endif /* __XTOSKRNL_RTL_DISPATCH_HH */ diff --git a/xtoskrnl/includes/rtl/endian.hh b/xtoskrnl/includes/rtl/endian.hh new file mode 100644 index 0000000..94adaa3 --- /dev/null +++ b/xtoskrnl/includes/rtl/endian.hh @@ -0,0 +1,27 @@ +/** + * PROJECT: ExectOS + * COPYRIGHT: See COPYING.md in the top level directory + * FILE: xtoskrnl/includes/rtl/endian.hh + * DESCRIPTION: Endian conversion routines + * DEVELOPERS: Aiken Harris + */ + +#ifndef __XTOSKRNL_RTL_ENDIAN_HH +#define __XTOSKRNL_RTL_ENDIAN_HH + +#include + + +/* Runtime Library */ +namespace RTL +{ + class Endianness + { + public: + STATIC XTAPI USHORT SwapByte16(IN USHORT Source); + STATIC XTAPI ULONG SwapByte32(IN ULONG Source); + STATIC XTAPI ULONGLONG SwapByte64(IN ULONGLONG Source); + }; +} + +#endif /* __XTOSKRNL_RTL_ENDIAN_HH */ diff --git a/xtoskrnl/includes/rtl/guid.hh b/xtoskrnl/includes/rtl/guid.hh new file mode 100644 index 0000000..f27f287 --- /dev/null +++ b/xtoskrnl/includes/rtl/guid.hh @@ -0,0 +1,26 @@ +/** + * PROJECT: ExectOS + * COPYRIGHT: See COPYING.md in the top level directory + * FILE: xtoskrnl/includes/rtl/gui.hh + * DESCRIPTION: Endian conversion routines + * DEVELOPERS: Aiken Harris + */ + +#ifndef __XTOSKRNL_RTL_GUID_HH +#define __XTOSKRNL_RTL_GUID_HH + +#include + + +/* Runtime Library */ +namespace RTL +{ + class Guid + { + public: + STATIC XTAPI BOOLEAN CompareGuids(IN PGUID Guid1, + IN PGUID Guid2); + }; +} + +#endif /* __XTOSKRNL_RTL_GUID_HH */ diff --git a/xtoskrnl/includes/rtl/llist.hh b/xtoskrnl/includes/rtl/llist.hh new file mode 100644 index 0000000..dc0e6ab --- /dev/null +++ b/xtoskrnl/includes/rtl/llist.hh @@ -0,0 +1,33 @@ +/** + * PROJECT: ExectOS + * COPYRIGHT: See COPYING.md in the top level directory + * FILE: xtoskrnl/includes/rtl/llist.hh + * DESCRIPTION: Linked list manipulation routines + * DEVELOPERS: Aiken Harris + */ + +#ifndef __XTOSKRNL_RTL_LLIST_HH +#define __XTOSKRNL_RTL_LLIST_HH + +#include + + +/* Runtime Library */ +namespace RTL +{ + class LinkedList + { + public: + STATIC XTCDECL VOID InitializeListHead(IN PLIST_ENTRY ListHead); + STATIC XTCDECL VOID InitializeListHead32(IN PLIST_ENTRY32 ListHead); + STATIC XTCDECL VOID InsertHeadList(IN OUT PLIST_ENTRY ListHead, + IN PLIST_ENTRY Entry); + STATIC XTCDECL VOID InsertTailList(IN OUT PLIST_ENTRY ListHead, + IN PLIST_ENTRY Entry); + STATIC XTCDECL BOOLEAN ListEmpty(IN PLIST_ENTRY ListHead); + STATIC XTCDECL BOOLEAN ListLoop(IN PLIST_ENTRY ListHead); + STATIC XTCDECL VOID RemoveEntryList(IN PLIST_ENTRY Entry); + }; +} + +#endif /* __XTOSKRNL_RTL_LLIST_HH */ diff --git a/xtoskrnl/includes/rtl/math.hh b/xtoskrnl/includes/rtl/math.hh new file mode 100644 index 0000000..78e773c --- /dev/null +++ b/xtoskrnl/includes/rtl/math.hh @@ -0,0 +1,51 @@ +/** + * PROJECT: ExectOS + * COPYRIGHT: See COPYING.md in the top level directory + * FILE: xtoskrnl/includes/rtl/math.hh + * DESCRIPTION: Kernel math support + * DEVELOPERS: Aiken Harris + */ + +#ifndef __XTOSKRNL_RTL_MATH_HH +#define __XTOSKRNL_RTL_MATH_HH + +#include + + +/* Runtime Library */ +namespace RTL +{ + class Math + { + public: + STATIC XTAPI LARGE_INTEGER ConvertToLargeInteger32(IN LONG Value); + STATIC XTAPI LARGE_INTEGER ConvertToLargeIntegerUnsigned32(IN ULONG Value); + STATIC XTAPI INT CountLeadingZeroes32(IN ULONG Value); + STATIC XTAPI INT CountLeadingZeroes64(IN ULONGLONG Value); + STATIC XTAPI INT CountTrailingZeroes32(IN ULONG Value); + STATIC XTAPI INT CountTrailingZeroes64(IN ULONGLONG Value); + STATIC XTAPI LONGLONG Divide32(IN LONG Dividend, + IN LONG Divisor, + OUT PLONG Remainder); + STATIC XTAPI LONGLONG Divide64(IN LONGLONG Dividend, + IN LONGLONG Divisor, + OUT PLONGLONG Remainder); + STATIC XTAPI ULONGLONG DivideUnsigned32(IN ULONG Dividend, + IN ULONG Divisor, + OUT PULONG Remainder); + STATIC XTAPI ULONGLONG DivideUnsigned64(IN ULONGLONG Dividend, + IN ULONGLONG Divisor, + OUT PULONGLONG Remainder); + STATIC XTAPI LARGE_INTEGER DivideLargeInteger(IN LARGE_INTEGER Dividend, + IN ULONG Divisor, + OUT PULONG Remainder); + STATIC XTAPI LONG GetBaseExponent(IN DOUBLE Value, + OUT PDOUBLE PowerOfTen); + STATIC XTAPI BOOLEAN InfiniteDouble(IN DOUBLE Value); + STATIC XTAPI LARGE_INTEGER MultiplyLargeInteger(IN LARGE_INTEGER Multiplicand, + IN LONG Multiplier); + STATIC XTAPI BOOLEAN NanDouble(IN DOUBLE Value); + }; +} + +#endif /* __XTOSKRNL_RTL_MATH_HH */ diff --git a/xtoskrnl/includes/rtl/memory.hh b/xtoskrnl/includes/rtl/memory.hh new file mode 100644 index 0000000..77a2c62 --- /dev/null +++ b/xtoskrnl/includes/rtl/memory.hh @@ -0,0 +1,41 @@ +/** + * PROJECT: ExectOS + * COPYRIGHT: See COPYING.md in the top level directory + * FILE: xtoskrnl/includes/rtl/memory.hh + * DESCRIPTION: Memory related routines + * DEVELOPERS: Aiken Harris + */ + +#ifndef __XTOSKRNL_RTL_MEMORY_HH +#define __XTOSKRNL_RTL_MEMORY_HH + +#include + + +/* Runtime Library */ +namespace RTL +{ + class Memory + { + public: + STATIC XTAPI SIZE_T CompareMemory(IN PCVOID LeftBuffer, + IN PCVOID RightBuffer, + IN SIZE_T Length); + STATIC XTAPI VOID CopyMemory(OUT PVOID Destination, + IN PCVOID Source, + IN SIZE_T Length); + STATIC XTAPI VOID MoveMemory(OUT PVOID Destination, + IN PCVOID Source, + IN SIZE_T Length); + STATIC XTAPI BOOLEAN SameMemory(IN PCVOID LeftBuffer, + IN PCVOID RightBuffer, + IN SIZE_T Length); + STATIC XTAPI VOID SetMemory(OUT PVOID Destination, + IN UCHAR Byte, + IN SIZE_T Length); + STATIC XTAPI VOID ZeroMemory(OUT PVOID Destination, + IN SIZE_T Length); + }; +} + +#endif /* __XTOSKRNL_RTL_MEMORY_HH */ diff --git a/xtoskrnl/includes/rtl/string.hh b/xtoskrnl/includes/rtl/string.hh new file mode 100644 index 0000000..8d1ca18 --- /dev/null +++ b/xtoskrnl/includes/rtl/string.hh @@ -0,0 +1,55 @@ +/** + * PROJECT: ExectOS + * COPYRIGHT: See COPYING.md in the top level directory + * FILE: xtoskrnl/includes/rtl/string.hh + * DESCRIPTION: String support + * DEVELOPERS: Aiken Harris + */ + +#ifndef __XTOSKRNL_RTL_STRING_HH +#define __XTOSKRNL_RTL_STRING_HH + +#include + + +/* Runtime Library */ +namespace RTL +{ + class String + { + public: + STATIC XTAPI SIZE_T CompareString(IN PCSTR String1, + IN PCSTR String2, + IN SIZE_T Length); + STATIC XTAPI SIZE_T CompareStringInsensitive(IN PCSTR String1, + IN PCSTR String2, + IN SIZE_T Length); + STATIC XTAPI PCHAR ConcatenateString(OUT PCHAR Destination, + IN PCHAR Source, + IN SIZE_T Count); + STATIC XTAPI VOID CopyString(IN PCHAR Destination, + IN PCSTR Source, + IN ULONG Length); + STATIC XTAPI PCSTR FindString(IN PCSTR Source, + IN PCSTR Search); + STATIC XTAPI PCSTR FindStringInsensitive(IN PCSTR Source, + IN PCSTR Search); + STATIC XTAPI VOID ReverseString(IN OUT PCHAR String, + IN ULONG Length); + STATIC XTAPI SIZE_T StringLength(IN PCSTR String, + IN SIZE_T MaxLength); + STATIC XTAPI SIZE_T StringToWideString(OUT PWCHAR Destination, + IN PCSTR *Source, + IN SIZE_T Length); + STATIC XTAPI PCHAR TokenizeString(IN PCHAR String, + IN PCSTR Delimiter, + IN OUT PCHAR *SavePtr); + STATIC XTAPI CHAR ToLowerCharacter(IN CHAR Character); + STATIC XTAPI CHAR ToUpperCharacter(IN CHAR Character); + STATIC XTAPI PCHAR TrimLeftString(IN PCHAR String); + STATIC XTAPI PCHAR TrimRightString(IN PCHAR String); + STATIC XTAPI PCHAR TrimString(IN PCHAR String); + }; +} + +#endif /* __XTOSKRNL_RTL_STRING_HH */ diff --git a/xtoskrnl/includes/rtl/widestr.hh b/xtoskrnl/includes/rtl/widestr.hh new file mode 100644 index 0000000..66175fe --- /dev/null +++ b/xtoskrnl/includes/rtl/widestr.hh @@ -0,0 +1,87 @@ +/** + * PROJECT: ExectOS + * COPYRIGHT: See COPYING.md in the top level directory + * FILE: xtoskrnl/includes/rtl/widestr.hh + * DESCRIPTION: Wide string support + * DEVELOPERS: Aiken Harris + */ + +#ifndef __XTOSKRNL_RTL_WIDESTR_HH +#define __XTOSKRNL_RTL_WIDESTR_HH + +#include + + +/* Runtime Library */ +namespace RTL +{ + class WideString + { + public: + STATIC XTAPI SIZE_T CompareWideString(IN PCWSTR String1, + IN PCWSTR String2, + IN SIZE_T Length); + STATIC XTAPI SIZE_T CompareWideStringInsensitive(IN PCWSTR String1, + IN PCWSTR String2, + IN SIZE_T Length); + STATIC XTAPI PWCHAR ConcatenateWideString(OUT PWCHAR Destination, + IN PWCHAR Source, + IN SIZE_T Count); + STATIC XTAPI VOID CopyWideString(IN PWCHAR Destination, + IN PCWSTR Source, + IN ULONG Length); + STATIC XTAPI PCWSTR FindWideString(IN PCWSTR Source, + IN PCWSTR Search); + STATIC XTAPI PCWSTR FindWideStringInsensitive(IN PCWSTR Source, + IN PCWSTR Search); + STATIC XTAPI XTSTATUS FormatWideString(IN PRTL_PRINT_CONTEXT Context, + IN PCWSTR Format, + IN VA_LIST ArgumentList); + STATIC XTAPI VOID ReverseWideString(IN OUT PWCHAR String, + IN ULONG Length); + STATIC XTAPI PWCHAR TokenizeWideString(IN PWCHAR String, + IN PCWSTR Delimiter, + IN OUT PWCHAR *SavePtr); + STATIC XTAPI WCHAR ToLowerWideCharacter(IN WCHAR Character); + STATIC XTAPI WCHAR ToUpperWideCharacter(IN WCHAR Character); + STATIC XTAPI PWCHAR TrimLeftWideString(IN PWCHAR String); + STATIC XTAPI PWCHAR TrimRightWideString(IN PWCHAR String); + STATIC XTAPI PWCHAR TrimWideString(IN PWCHAR String); + STATIC XTAPI SIZE_T WideStringLength(IN PCWSTR String, + IN SIZE_T MaxLength); + + private: + STATIC XTAPI XTSTATUS FormatArgumentSpecifier(IN PRTL_PRINT_CONTEXT Context, + IN PCWSTR Format, + IN PVA_LIST ArgumentList, + IN OUT PULONG Index); + STATIC XTAPI ULONGLONG GetArgument(IN PVA_LIST ArgumentList, + IN ULONG ArgumentNumber, + IN LONG ArgumentSize); + STATIC XTAPI ULONGLONG GetSpecifierValue(IN PWCHAR *Format); + STATIC XTAPI XTSTATUS WriteWideCharacter(IN PRTL_PRINT_CONTEXT Context, + IN WCHAR Character); + STATIC XTCDECL XTSTATUS WriteCustomValue(IN PRTL_PRINT_CONTEXT Context, + IN PCWSTR Format, + IN ...); + STATIC XTAPI XTSTATUS WriteDoubleValue(IN PRTL_PRINT_CONTEXT Context, + IN PRTL_PRINT_FORMAT_PROPERTIES FormatProperties, + IN DOUBLE Value); + STATIC XTAPI XTSTATUS WriteHexDoubleValue(IN PRTL_PRINT_CONTEXT Context, + IN PRTL_PRINT_FORMAT_PROPERTIES FormatProperties, + IN DOUBLE Double); + STATIC XTAPI XTSTATUS WriteIntegerValue(IN PRTL_PRINT_CONTEXT Context, + IN PRTL_PRINT_FORMAT_PROPERTIES FormatProperties, + IN ULONGLONG Integer); + STATIC XTAPI XTSTATUS WriteStringValue(PRTL_PRINT_CONTEXT Context, + PRTL_PRINT_FORMAT_PROPERTIES FormatProperties, + PCSTR String, + SIZE_T StringLength); + STATIC XTAPI XTSTATUS WriteValue(PRTL_PRINT_CONTEXT Context, + PRTL_PRINT_FORMAT_PROPERTIES FormatProperties, + PCWSTR String, + SIZE_T StringLength); + }; +} + +#endif /* __XTOSKRNL_RTL_WIDESTR_HH */ diff --git a/xtoskrnl/includes/xtos.hh b/xtoskrnl/includes/xtos.hh index b3e0ded..8a23158 100644 --- a/xtoskrnl/includes/xtos.hh +++ b/xtoskrnl/includes/xtos.hh @@ -28,4 +28,6 @@ extern "C" { #include #include +#include #include +#include diff --git a/xtoskrnl/rtl/amd64/dispatch.c b/xtoskrnl/rtl/amd64/dispatch.cc similarity index 79% rename from xtoskrnl/rtl/amd64/dispatch.c rename to xtoskrnl/rtl/amd64/dispatch.cc index 61c664e..281bc11 100644 --- a/xtoskrnl/rtl/amd64/dispatch.c +++ b/xtoskrnl/rtl/amd64/dispatch.cc @@ -1,12 +1,12 @@ /** * PROJECT: ExectOS * COPYRIGHT: See COPYING.md in the top level directory - * FILE: xtoskrnl/rtl/amd64/dispatch.c + * FILE: xtoskrnl/rtl/amd64/dispatch.cc * DESCRIPTION: Dispatching support for AMD64 architecture * DEVELOPERS: Rafal Kupiec */ -#include +#include /** @@ -24,8 +24,8 @@ */ XTAPI VOID -RtlGetStackLimits(OUT PULONG_PTR StackBase, - OUT PULONG_PTR StackLimit) +RTL::Dispatcher::GetStackLimits(OUT PULONG_PTR StackBase, + OUT PULONG_PTR StackLimit) { PKTHREAD Thread = KeGetCurrentThread(); *StackBase = (ULONG_PTR)Thread->StackBase; diff --git a/xtoskrnl/rtl/amd64/exsup.c b/xtoskrnl/rtl/amd64/exsup.cc similarity index 90% rename from xtoskrnl/rtl/amd64/exsup.c rename to xtoskrnl/rtl/amd64/exsup.cc index b861b86..ecf9f79 100644 --- a/xtoskrnl/rtl/amd64/exsup.c +++ b/xtoskrnl/rtl/amd64/exsup.cc @@ -1,14 +1,15 @@ /** * PROJECT: ExectOS * COPYRIGHT: See COPYING.md in the top level directory - * FILE: xtoskrnl/rtl/amd64/exsup.c + * FILE: xtoskrnl/rtl/amd64/exsup.cc * DESCRIPTION: Exception handling for AMD64 architecture * DEVELOPERS: Rafal Kupiec */ -#include +#include +XTCLINK XTAPI EXCEPTION_DISPOSITION __C_specific_handler(IN PEXCEPTION_RECORD ExceptionRecord, @@ -22,6 +23,7 @@ __C_specific_handler(IN PEXCEPTION_RECORD ExceptionRecord, return ExceptionContinueExecution; } +XTCLINK XTCDECL INT _except_handler3(PEXCEPTION_RECORD ExceptionRecord, diff --git a/xtoskrnl/rtl/atomic.c b/xtoskrnl/rtl/atomic.cc similarity index 81% rename from xtoskrnl/rtl/atomic.c rename to xtoskrnl/rtl/atomic.cc index 46b2fe8..b1d576c 100644 --- a/xtoskrnl/rtl/atomic.c +++ b/xtoskrnl/rtl/atomic.cc @@ -1,12 +1,12 @@ /** * PROJECT: ExectOS * COPYRIGHT: See COPYING.md in the top level directory - * FILE: xtoskrnl/rtl/atomic.c + * FILE: xtoskrnl/rtl/atomic.cc * DESCRIPTION: Atomic operations support * DEVELOPERS: Rafal Kupiec */ -#include +#include /** @@ -24,8 +24,8 @@ */ XTFASTCALL CHAR -RtlAtomicAnd8(IN VOLATILE PCHAR Address, - IN CHAR Mask) +RTL::Atomic::And8(IN PCHAR Address, + IN CHAR Mask) { return __sync_fetch_and_and(Address, Mask); } @@ -45,8 +45,8 @@ RtlAtomicAnd8(IN VOLATILE PCHAR Address, */ XTFASTCALL SHORT -RtlAtomicAnd16(IN VOLATILE PSHORT Address, - IN SHORT Mask) +RTL::Atomic::And16(IN PSHORT Address, + IN SHORT Mask) { return __sync_fetch_and_and(Address, Mask); } @@ -66,8 +66,8 @@ RtlAtomicAnd16(IN VOLATILE PSHORT Address, */ XTFASTCALL LONG -RtlAtomicAnd32(IN VOLATILE PLONG Address, - IN LONG Mask) +RTL::Atomic::And32(IN PLONG Address, + IN LONG Mask) { return __sync_fetch_and_and(Address, Mask); } @@ -87,8 +87,8 @@ RtlAtomicAnd32(IN VOLATILE PLONG Address, */ XTFASTCALL LONG_PTR -RtlAtomicAnd64(IN VOLATILE PLONG_PTR Address, - IN LONG_PTR Mask) +RTL::Atomic::And64(IN PLONG_PTR Address, + IN LONG_PTR Mask) { return __sync_fetch_and_and(Address, Mask); } @@ -108,8 +108,8 @@ RtlAtomicAnd64(IN VOLATILE PLONG_PTR Address, */ XTFASTCALL UCHAR -RtlAtomicBitTestAndSet(IN VOLATILE PLONG Base, - IN LONG Offset) +RTL::Atomic::BitTestAndSet(IN PLONG Base, + IN LONG Offset) { return (__atomic_fetch_or(Base, 1l << Offset, __ATOMIC_SEQ_CST) >> Offset) & 1; } @@ -129,8 +129,8 @@ RtlAtomicBitTestAndSet(IN VOLATILE PLONG Base, */ XTFASTCALL UCHAR -RtlAtomicBitTestAndSet64(IN VOLATILE PLONGLONG Base, - IN LONGLONG Offset) +RTL::Atomic::BitTestAndSet64(IN PLONGLONG Base, + IN LONGLONG Offset) { return (__atomic_fetch_or(Base, 1ll << Offset, __ATOMIC_SEQ_CST) >> Offset) & 1; } @@ -153,9 +153,9 @@ RtlAtomicBitTestAndSet64(IN VOLATILE PLONGLONG Base, */ XTFASTCALL CHAR -RtlAtomicCompareExchange8(IN VOLATILE PCHAR Address, - IN CHAR Comperand, - IN CHAR Exchange) +RTL::Atomic::CompareExchange8(IN PCHAR Address, + IN CHAR Comperand, + IN CHAR Exchange) { return __sync_val_compare_and_swap(Address, Comperand, Exchange); } @@ -178,9 +178,9 @@ RtlAtomicCompareExchange8(IN VOLATILE PCHAR Address, */ XTFASTCALL SHORT -RtlAtomicCompareExchange16(IN VOLATILE PSHORT Address, - IN SHORT Comperand, - IN SHORT Exchange) +RTL::Atomic::CompareExchange16(IN PSHORT Address, + IN SHORT Comperand, + IN SHORT Exchange) { return __sync_val_compare_and_swap(Address, Comperand, Exchange); } @@ -203,9 +203,9 @@ RtlAtomicCompareExchange16(IN VOLATILE PSHORT Address, */ XTFASTCALL LONG -RtlAtomicCompareExchange32(IN VOLATILE PLONG Address, - IN LONG Comperand, - IN LONG Exchange) +RTL::Atomic::CompareExchange32(IN PLONG Address, + IN LONG Comperand, + IN LONG Exchange) { return __sync_val_compare_and_swap(Address, Comperand, Exchange); } @@ -228,9 +228,9 @@ RtlAtomicCompareExchange32(IN VOLATILE PLONG Address, */ XTFASTCALL LONG_PTR -RtlAtomicCompareExchange64(IN VOLATILE PLONG_PTR Address, - IN LONG_PTR Comperand, - IN LONG_PTR Exchange) +RTL::Atomic::CompareExchange64(IN PLONG_PTR Address, + IN LONG_PTR Comperand, + IN LONG_PTR Exchange) { return __sync_val_compare_and_swap(Address, Comperand, Exchange); } @@ -253,9 +253,9 @@ RtlAtomicCompareExchange64(IN VOLATILE PLONG_PTR Address, */ XTFASTCALL PVOID -RtlAtomicCompareExchangePointer(IN VOLATILE PVOID *Address, - IN PVOID Comperand, - IN PVOID Exchange) +RTL::Atomic::CompareExchangePointer(IN PVOID *Address, + IN PVOID Comperand, + IN PVOID Exchange) { return (PVOID)__sync_val_compare_and_swap(Address, Comperand, Exchange); } @@ -272,7 +272,7 @@ RtlAtomicCompareExchangePointer(IN VOLATILE PVOID *Address, */ XTFASTCALL CHAR -RtlAtomicDecrement8(IN VOLATILE PCHAR Address) +RTL::Atomic::Decrement8(IN PCHAR Address) { return __sync_sub_and_fetch(Address, 1); } @@ -289,7 +289,7 @@ RtlAtomicDecrement8(IN VOLATILE PCHAR Address) */ XTFASTCALL SHORT -RtlAtomicDecrement16(IN VOLATILE PSHORT Address) +RTL::Atomic::Decrement16(IN PSHORT Address) { return __sync_sub_and_fetch(Address, 1); } @@ -306,7 +306,7 @@ RtlAtomicDecrement16(IN VOLATILE PSHORT Address) */ XTFASTCALL LONG -RtlAtomicDecrement32(IN VOLATILE PLONG Address) +RTL::Atomic::Decrement32(IN PLONG Address) { return __sync_sub_and_fetch(Address, 1); } @@ -323,7 +323,7 @@ RtlAtomicDecrement32(IN VOLATILE PLONG Address) */ XTFASTCALL LONG_PTR -RtlAtomicDecrement64(IN VOLATILE PLONG_PTR Address) +RTL::Atomic::Decrement64(IN PLONG_PTR Address) { return __sync_sub_and_fetch(Address, 1); } @@ -343,8 +343,8 @@ RtlAtomicDecrement64(IN VOLATILE PLONG_PTR Address) */ XTFASTCALL CHAR -RtlAtomicExchange8(IN VOLATILE PCHAR Address, - IN CHAR Exchange) +RTL::Atomic::Exchange8(IN PCHAR Address, + IN CHAR Exchange) { return __sync_lock_test_and_set(Address, Exchange); } @@ -364,8 +364,8 @@ RtlAtomicExchange8(IN VOLATILE PCHAR Address, */ XTFASTCALL SHORT -RtlAtomicExchange16(IN VOLATILE PSHORT Address, - IN SHORT Exchange) +RTL::Atomic::Exchange16(IN PSHORT Address, + IN SHORT Exchange) { return __sync_lock_test_and_set(Address, Exchange); } @@ -385,8 +385,8 @@ RtlAtomicExchange16(IN VOLATILE PSHORT Address, */ XTFASTCALL LONG -RtlAtomicExchange32(IN VOLATILE PLONG Address, - IN LONG Exchange) +RTL::Atomic::Exchange32(IN PLONG Address, + IN LONG Exchange) { return __sync_lock_test_and_set(Address, Exchange); } @@ -406,8 +406,8 @@ RtlAtomicExchange32(IN VOLATILE PLONG Address, */ XTFASTCALL LONG_PTR -RtlAtomicExchange64(IN VOLATILE PLONG_PTR Address, - IN LONG_PTR Exchange) +RTL::Atomic::Exchange64(IN PLONG_PTR Address, + IN LONG_PTR Exchange) { return __sync_lock_test_and_set(Address, Exchange); } @@ -427,8 +427,8 @@ RtlAtomicExchange64(IN VOLATILE PLONG_PTR Address, */ XTFASTCALL CHAR -RtlAtomicExchangeAdd8(IN VOLATILE PCHAR Address, - IN CHAR Value) +RTL::Atomic::ExchangeAdd8(IN PCHAR Address, + IN CHAR Value) { return __sync_fetch_and_add(Address, Value); } @@ -448,8 +448,8 @@ RtlAtomicExchangeAdd8(IN VOLATILE PCHAR Address, */ XTFASTCALL SHORT -RtlAtomicExchangeAdd16(IN VOLATILE PSHORT Address, - IN SHORT Value) +RTL::Atomic::ExchangeAdd16(IN PSHORT Address, + IN SHORT Value) { return __sync_fetch_and_add(Address, Value); } @@ -469,8 +469,8 @@ RtlAtomicExchangeAdd16(IN VOLATILE PSHORT Address, */ XTFASTCALL LONG -RtlAtomicExchangeAdd32(IN VOLATILE PLONG Address, - IN LONG Value) +RTL::Atomic::ExchangeAdd32(IN PLONG Address, + IN LONG Value) { return __sync_fetch_and_add(Address, Value); } @@ -490,8 +490,8 @@ RtlAtomicExchangeAdd32(IN VOLATILE PLONG Address, */ XTFASTCALL LONG_PTR -RtlAtomicExchangeAdd64(IN VOLATILE PLONG_PTR Address, - IN LONG_PTR Value) +RTL::Atomic::ExchangeAdd64(IN PLONG_PTR Address, + IN LONG_PTR Value) { return __sync_fetch_and_add(Address, Value); } @@ -511,8 +511,8 @@ RtlAtomicExchangeAdd64(IN VOLATILE PLONG_PTR Address, */ XTFASTCALL PVOID -RtlAtomicExchangePointer(IN VOLATILE PVOID *Address, - IN PVOID Exchange) +RTL::Atomic::ExchangePointer(IN PVOID *Address, + IN PVOID Exchange) { __sync_synchronize(); return (PVOID)__sync_lock_test_and_set(Address, Exchange); @@ -530,9 +530,9 @@ RtlAtomicExchangePointer(IN VOLATILE PVOID *Address, */ XTFASTCALL PSINGLE_LIST_ENTRY -RtlAtomicFlushSingleList(IN PSINGLE_LIST_HEADER Header) +RTL::Atomic::FlushSingleList(IN PSINGLE_LIST_HEADER Header) { - return (PSINGLE_LIST_ENTRY)RtlAtomicExchange64((PLONG_PTR)&Header->Alignment, (LONGLONG)NULL); + return (PSINGLE_LIST_ENTRY)Exchange64((PLONG_PTR)&Header->Alignment, (LONGLONG)NULL); } /** @@ -547,7 +547,7 @@ RtlAtomicFlushSingleList(IN PSINGLE_LIST_HEADER Header) */ XTFASTCALL CHAR -RtlAtomicIncrement8(IN VOLATILE PCHAR Address) +RTL::Atomic::Increment8(IN PCHAR Address) { return __sync_add_and_fetch(Address, 1); } @@ -564,7 +564,7 @@ RtlAtomicIncrement8(IN VOLATILE PCHAR Address) */ XTFASTCALL SHORT -RtlAtomicIncrement16(IN VOLATILE PSHORT Address) +RTL::Atomic::Increment16(IN PSHORT Address) { return __sync_add_and_fetch(Address, 1); } @@ -581,7 +581,7 @@ RtlAtomicIncrement16(IN VOLATILE PSHORT Address) */ XTFASTCALL LONG -RtlAtomicIncrement32(IN VOLATILE PLONG Address) +RTL::Atomic::Increment32(IN PLONG Address) { return __sync_add_and_fetch(Address, 1); } @@ -598,7 +598,7 @@ RtlAtomicIncrement32(IN VOLATILE PLONG Address) */ XTFASTCALL LONG_PTR -RtlAtomicIncrement64(IN VOLATILE PLONG_PTR Address) +RTL::Atomic::Increment64(IN PLONG_PTR Address) { return __sync_add_and_fetch(Address, 1); } @@ -618,8 +618,8 @@ RtlAtomicIncrement64(IN VOLATILE PLONG_PTR Address) */ XTFASTCALL CHAR -RtlAtomicOr8(IN VOLATILE PCHAR Address, - IN CHAR Mask) +RTL::Atomic::Or8(IN PCHAR Address, + IN CHAR Mask) { return __sync_fetch_and_or(Address, Mask); } @@ -639,8 +639,8 @@ RtlAtomicOr8(IN VOLATILE PCHAR Address, */ XTFASTCALL SHORT -RtlAtomicOr16(IN VOLATILE PSHORT Address, - IN SHORT Mask) +RTL::Atomic::Or16(IN PSHORT Address, + IN SHORT Mask) { return __sync_fetch_and_or(Address, Mask); } @@ -660,8 +660,8 @@ RtlAtomicOr16(IN VOLATILE PSHORT Address, */ XTFASTCALL LONG -RtlAtomicOr32(IN VOLATILE PLONG Address, - IN LONG Mask) +RTL::Atomic::Or32(IN PLONG Address, + IN LONG Mask) { return __sync_fetch_and_or(Address, Mask); } @@ -681,8 +681,8 @@ RtlAtomicOr32(IN VOLATILE PLONG Address, */ XTFASTCALL LONG_PTR -RtlAtomicOr64(IN VOLATILE PLONG_PTR Address, - IN LONG_PTR Mask) +RTL::Atomic::Or64(IN PLONG_PTR Address, + IN LONG_PTR Mask) { return __sync_fetch_and_or(Address, Mask); } @@ -699,12 +699,12 @@ RtlAtomicOr64(IN VOLATILE PLONG_PTR Address, */ XTFASTCALL PSINGLE_LIST_ENTRY -RtlAtomicPopEntrySingleList(IN PSINGLE_LIST_HEADER Header) +RTL::Atomic::PopEntrySingleList(IN PSINGLE_LIST_HEADER Header) { PSINGLE_LIST_ENTRY ListHead, FirstEntry, NextEntry; /* Save header and first entry */ - ListHead = (PVOID)Header; + ListHead = (PSINGLE_LIST_ENTRY)Header; FirstEntry = ListHead->Next; do { @@ -712,16 +712,16 @@ RtlAtomicPopEntrySingleList(IN PSINGLE_LIST_HEADER Header) if(!FirstEntry) { /* Empty list */ - return NULL; + return nullptr; } /* Update link */ NextEntry = FirstEntry; /* Compare and exchange */ - FirstEntry = (PVOID)RtlAtomicCompareExchange64((PLONG_PTR)ListHead, - (LONG_PTR)FirstEntry->Next, - (LONG_PTR)FirstEntry); + FirstEntry = (PSINGLE_LIST_ENTRY)CompareExchange64((PLONG_PTR)ListHead, + (LONG_PTR)FirstEntry->Next, + (LONG_PTR)FirstEntry); } while(FirstEntry != NextEntry); /* Return removed element */ @@ -743,14 +743,14 @@ RtlAtomicPopEntrySingleList(IN PSINGLE_LIST_HEADER Header) */ XTFASTCALL PSINGLE_LIST_ENTRY -RtlAtomicPushEntrySingleList(IN PSINGLE_LIST_HEADER Header, - IN PSINGLE_LIST_ENTRY Entry) +RTL::Atomic::PushEntrySingleList(IN PSINGLE_LIST_HEADER Header, + IN PSINGLE_LIST_ENTRY Entry) { PSINGLE_LIST_ENTRY ListHead, ListEntry, FirstEntry, NextEntry; /* Save header and new entry */ - ListHead = (PVOID)Header; - ListEntry = (PVOID)Entry; + ListHead = (PSINGLE_LIST_ENTRY)Header; + ListEntry = Entry; /* Save next link in new first element */ FirstEntry = ListHead->Next; @@ -761,9 +761,9 @@ RtlAtomicPushEntrySingleList(IN PSINGLE_LIST_HEADER Header, NextEntry = FirstEntry; /* Compare and exchange */ - FirstEntry = (PVOID)RtlAtomicCompareExchange64((PLONG_PTR)ListHead, - (LONG_PTR)ListEntry, - (LONG_PTR)FirstEntry); + FirstEntry = (PSINGLE_LIST_ENTRY)CompareExchange64((PLONG_PTR)ListHead, + (LONG_PTR)ListEntry, + (LONG_PTR)FirstEntry); } while(FirstEntry != NextEntry); /* Return original first element */ @@ -785,8 +785,8 @@ RtlAtomicPushEntrySingleList(IN PSINGLE_LIST_HEADER Header, */ XTFASTCALL CHAR -RtlAtomicXor8(IN VOLATILE PCHAR Address, - IN CHAR Mask) +RTL::Atomic::Xor8(IN PCHAR Address, + IN CHAR Mask) { return __sync_fetch_and_xor(Address, Mask); } @@ -806,8 +806,8 @@ RtlAtomicXor8(IN VOLATILE PCHAR Address, */ XTFASTCALL SHORT -RtlAtomicXor16(IN VOLATILE PSHORT Address, - IN SHORT Mask) +RTL::Atomic::Xor16(IN PSHORT Address, + IN SHORT Mask) { return __sync_fetch_and_xor(Address, Mask); } @@ -827,8 +827,8 @@ RtlAtomicXor16(IN VOLATILE PSHORT Address, */ XTFASTCALL LONG -RtlAtomicXor32(IN VOLATILE PLONG Address, - IN LONG Mask) +RTL::Atomic::Xor32(IN PLONG Address, + IN LONG Mask) { return __sync_fetch_and_xor(Address, Mask); } @@ -848,8 +848,8 @@ RtlAtomicXor32(IN VOLATILE PLONG Address, */ XTFASTCALL LONG_PTR -RtlAtomicXor64(IN VOLATILE PLONG_PTR Address, - IN LONG_PTR Mask) +RTL::Atomic::Xor64(IN PLONG_PTR Address, + IN LONG_PTR Mask) { return __sync_fetch_and_xor(Address, Mask); } diff --git a/xtoskrnl/rtl/bitmap.c b/xtoskrnl/rtl/bitmap.cc similarity index 82% rename from xtoskrnl/rtl/bitmap.c rename to xtoskrnl/rtl/bitmap.cc index 8eec4ea..e2f31c6 100644 --- a/xtoskrnl/rtl/bitmap.c +++ b/xtoskrnl/rtl/bitmap.cc @@ -1,12 +1,12 @@ /** * PROJECT: ExectOS * COPYRIGHT: See COPYING.md in the top level directory - * FILE: xtoskrnl/rtl/bitmap.c + * FILE: xtoskrnl/rtl/bitmap.cc * DESCRIPTION: Bit maps support related routines * DEVELOPERS: Rafal Kupiec */ -#include +#include /** @@ -21,10 +21,10 @@ */ XTAPI VOID -RtlClearAllBits(IN PRTL_BITMAP BitMap) +RTL::BitMap::ClearAllBits(IN PRTL_BITMAP BitMap) { /* Clear all bits */ - RtlSetMemory(BitMap->Buffer, 0, ((BitMap->Size + BITS_PER_LONG - 1) / BITS_PER_LONG) * sizeof(ULONG_PTR)); + RTL::Memory::SetMemory(BitMap->Buffer, 0, ((BitMap->Size + BITS_PER_LONG - 1) / BITS_PER_LONG) * sizeof(ULONG_PTR)); } /** @@ -42,8 +42,8 @@ RtlClearAllBits(IN PRTL_BITMAP BitMap) */ XTAPI VOID -RtlClearBit(IN PRTL_BITMAP BitMap, - IN ULONG_PTR Bit) +RTL::BitMap::ClearBit(IN PRTL_BITMAP BitMap, + IN ULONG_PTR Bit) { /* Check if bit is in range */ if(Bit >= BitMap->Size) @@ -74,9 +74,9 @@ RtlClearBit(IN PRTL_BITMAP BitMap, */ XTAPI VOID -RtlClearBits(IN PRTL_BITMAP BitMap, - IN ULONG_PTR StartingIndex, - IN ULONG_PTR Length) +RTL::BitMap::ClearBits(IN PRTL_BITMAP BitMap, + IN ULONG_PTR StartingIndex, + IN ULONG_PTR Length) { ULONG_PTR BitOffset, Mask; PULONG_PTR Buffer; @@ -118,7 +118,7 @@ RtlClearBits(IN PRTL_BITMAP BitMap, } /* Clear remaining bits */ - RtlSetMemory(Buffer, 0, Length >> 3); + RTL::Memory::SetMemory(Buffer, 0, Length >> 3); /* Look for any remaining bits to clear */ Buffer += Length / BITS_PER_LONG; @@ -148,26 +148,85 @@ RtlClearBits(IN PRTL_BITMAP BitMap, */ XTAPI ULONG -RtlClearSetBits(IN PRTL_BITMAP BitMap, - IN ULONG_PTR Length, - IN ULONG_PTR Index) +RTL::BitMap::ClearSetBits(IN PRTL_BITMAP BitMap, + IN ULONG_PTR Length, + IN ULONG_PTR Index) { ULONG_PTR StartingIndex; /* Find set bits */ - StartingIndex = RtlFindSetBits(BitMap, Length, Index); + StartingIndex = FindSetBits(BitMap, Length, Index); /* Check if set bits were found */ if(StartingIndex != MAXULONG_PTR) { /* Clear bits */ - RtlClearBits(BitMap, StartingIndex, Length); + ClearBits(BitMap, StartingIndex, Length); } /* Return position of bits found */ return StartingIndex; } +/** + * Counts the number of either set or clear bits in the contiguous region of the bit map. + * + * @param BitMap + * Supplies a pointer to the bit map. + * + * @param Length + * Supplies the maximum length (number of bits) to count. + * + * @param StartingIndex + * Supplies the starting index of the first bit to count. + * + * @param SetBits + * Specifies whether count bits that are set or clear. + * + * @return This routine returns the number of equal bits found in the contiguous region. + * + * @since XT 1.0 + */ +XTAPI +ULONG_PTR +RTL::BitMap::CountBits(IN PRTL_BITMAP BitMap, + IN ULONG_PTR Length, + IN ULONG_PTR StartingIndex, + IN BOOLEAN SetBits) +{ + PULONG_PTR Buffer, BufferEnd; + ULONG_PTR BitOffset, Size; + ULONGLONG Value; + + /* Get pointers to first and last bytes to check */ + Buffer = &BitMap->Buffer[StartingIndex / BITS_PER_LONG]; + BufferEnd = Buffer + ((Length + BITS_PER_LONG - 1) / BITS_PER_LONG); + + /* Get offset and value */ + BitOffset = StartingIndex & (BITS_PER_LONG - 1); + Value = (SetBits ? ~*Buffer : *Buffer) >> BitOffset << BitOffset; + + /* Find first bit set until the end of the buffer */ + while(!Value && Buffer + 1 < BufferEnd) + { + /* Advance buffer pointer and get value */ + Value = SetBits ? ~*(++Buffer) : *(++Buffer); + } + + /* Check if value found */ + if(!Value) + { + /* No bits found, return length */ + return Length; + } + + /* Calculate size */ + Size = ((Buffer - BitMap->Buffer) * BITS_PER_LONG) - StartingIndex + (ULONG_PTR)RTL::Math::CountTrailingZeroes64(Value); + + /* Return whatever is smaller */ + return Size > Length ? Length : Size; +} + /** * Dumps the contents of the bit map. * @@ -180,7 +239,7 @@ RtlClearSetBits(IN PRTL_BITMAP BitMap, */ XTAPI VOID -RtlDumpBitMap(IN PRTL_BITMAP BitMap) +RTL::BitMap::DumpBitMap(IN PRTL_BITMAP BitMap) { ULONG_PTR Index; @@ -194,6 +253,99 @@ RtlDumpBitMap(IN PRTL_BITMAP BitMap) } } +/** + * Searches the bit map for a contiguous region of either set or clear bits. + * + * @param BitMap + * Supplies a pointer to the bit map. + * + * @param Length + * Supplies the length (number of equal bits) to look for. + * + * @param StartingIndex + * Supplies the starting index of the first bit to start the search at a given position. + * + * @param SetBits + * Specifies whether count bits that are set or clear. + * + * @return This routine returns the bit map index position of the contiguous region found, or MAXULONG_PTR if not found. + * + * @since XT 1.0 + */ +XTAPI +ULONG_PTR +RTL::BitMap::FindBits(IN PRTL_BITMAP BitMap, + IN ULONG_PTR Length, + IN ULONG_PTR StartingIndex, + IN BOOLEAN SetBits) +{ + ULONG_PTR BitMapEnd, BitOffset, Size; + ULONG Tries; + + /* Validate length */ + if(Length > BitMap->Size) + { + /* Length exceeds bit map size, return MAXULONG_PTR */ + return (ULONG_PTR)-1; + } + else if(!Length) + { + /* Length not specified, return starting index */ + return StartingIndex; + } + + /* Check if starting index is in range of bit map size */ + if(StartingIndex >= BitMap->Size) + { + /* Starting index exceeds bit map size, start from the beginning */ + StartingIndex = 0; + } + + /* Try from starting index */ + BitOffset = StartingIndex; + BitMapEnd = BitMap->Size; + + /* At least two tries are required */ + Tries = (StartingIndex != 0) + 2; + while(Tries) + { + /* Find until the end of the bit map */ + while(BitOffset + Length < BitMapEnd) + { + /* Increment offset */ + BitOffset += CountBits(BitMap, BitMap->Size - BitOffset, BitOffset, (BOOLEAN)!SetBits); + if(BitOffset + Length > BitMapEnd) + { + /* No match found, break loop execution */ + break; + } + + /* Count bits in the contiguous region and check if match found */ + Size = CountBits(BitMap, Length, BitOffset, SetBits); + if(Size >= Length) + { + /* Match found, return offset */ + return BitOffset; + } + + /* Increment offset */ + BitOffset += Size; + } + + /* Try again if possible */ + Tries--; + if(Tries) + { + /* Restart from the beginning up to the starting index */ + BitOffset = 0; + BitMapEnd = StartingIndex; + } + } + + /* No match found, return MAXULONG_PTR */ + return (ULONG_PTR)-1; +} + /** * Searches the bit map for a contiguous region of clear bits. * @@ -212,12 +364,12 @@ RtlDumpBitMap(IN PRTL_BITMAP BitMap) */ XTAPI ULONG_PTR -RtlFindClearBits(IN PRTL_BITMAP BitMap, - IN ULONG_PTR Length, - IN ULONG_PTR Index) +RTL::BitMap::FindClearBits(IN PRTL_BITMAP BitMap, + IN ULONG_PTR Length, + IN ULONG_PTR Index) { /* Find clear bits */ - return RtlpFindBits(BitMap, Length, Index, FALSE); + return FindBits(BitMap, Length, Index, FALSE); } /** @@ -238,12 +390,12 @@ RtlFindClearBits(IN PRTL_BITMAP BitMap, */ XTAPI ULONG_PTR -RtlFindSetBits(IN PRTL_BITMAP BitMap, - IN ULONG_PTR Length, - IN ULONG_PTR Index) +RTL::BitMap::FindSetBits(IN PRTL_BITMAP BitMap, + IN ULONG_PTR Length, + IN ULONG_PTR Index) { /* Find set bits */ - return RtlpFindBits(BitMap, Length, Index, TRUE); + return FindBits(BitMap, Length, Index, TRUE); } /** @@ -264,9 +416,9 @@ RtlFindSetBits(IN PRTL_BITMAP BitMap, */ XTAPI VOID -RtlInitializeBitMap(IN PRTL_BITMAP BitMap, - IN PULONG_PTR Buffer, - IN ULONG Size) +RTL::BitMap::InitializeBitMap(IN PRTL_BITMAP BitMap, + IN PULONG_PTR Buffer, + IN ULONG Size) { /* Initialize bit map */ BitMap->Buffer = Buffer; @@ -285,10 +437,10 @@ RtlInitializeBitMap(IN PRTL_BITMAP BitMap, */ XTAPI VOID -RtlSetAllBits(IN PRTL_BITMAP BitMap) +RTL::BitMap::SetAllBits(IN PRTL_BITMAP BitMap) { /* Set all bits */ - RtlSetMemory(BitMap->Buffer, 0xFF, ((BitMap->Size + BITS_PER_LONG - 1) / BITS_PER_LONG) * sizeof(ULONG_PTR)); + RTL::Memory::SetMemory(BitMap->Buffer, 0xFF, ((BitMap->Size + BITS_PER_LONG - 1) / BITS_PER_LONG) * sizeof(ULONG_PTR)); } /** @@ -306,8 +458,8 @@ RtlSetAllBits(IN PRTL_BITMAP BitMap) */ XTAPI VOID -RtlSetBit(IN PRTL_BITMAP BitMap, - IN ULONG_PTR Bit) +RTL::BitMap::SetBit(IN PRTL_BITMAP BitMap, + IN ULONG_PTR Bit) { /* Check if bit is in range */ if(Bit >= BitMap->Size) @@ -338,9 +490,9 @@ RtlSetBit(IN PRTL_BITMAP BitMap, */ XTAPI VOID -RtlSetBits(IN PRTL_BITMAP BitMap, - IN ULONG_PTR StartingIndex, - IN ULONG_PTR Length) +RTL::BitMap::SetBits(IN PRTL_BITMAP BitMap, + IN ULONG_PTR StartingIndex, + IN ULONG_PTR Length) { ULONG_PTR BitOffset, Mask; PULONG_PTR Buffer; @@ -382,7 +534,7 @@ RtlSetBits(IN PRTL_BITMAP BitMap, } /* Set remaining bits */ - RtlSetMemory(Buffer, 0xFF, Length >> 3); + RTL::Memory::SetMemory(Buffer, 0xFF, Length >> 3); /* Look for any remaining bits to set */ Buffer += Length / BITS_PER_LONG; @@ -412,20 +564,20 @@ RtlSetBits(IN PRTL_BITMAP BitMap, */ XTAPI ULONG -RtlSetClearBits(IN PRTL_BITMAP BitMap, - IN ULONG_PTR Length, - IN ULONG_PTR Index) +RTL::BitMap::SetClearBits(IN PRTL_BITMAP BitMap, + IN ULONG_PTR Length, + IN ULONG_PTR Index) { ULONG_PTR StartingIndex; /* Find clear bits */ - StartingIndex = RtlFindClearBits(BitMap, Length, Index); + StartingIndex = FindClearBits(BitMap, Length, Index); /* Check if clear bits were found */ if(StartingIndex != MAXULONG_PTR) { /* Set bits */ - RtlSetBits(BitMap, StartingIndex, Length); + SetBits(BitMap, StartingIndex, Length); } /* Return position of bits found */ @@ -447,8 +599,8 @@ RtlSetClearBits(IN PRTL_BITMAP BitMap, */ XTAPI BOOLEAN -RtlTestBit(IN PRTL_BITMAP BitMap, - IN ULONG_PTR Bit) +RTL::BitMap::TestBit(IN PRTL_BITMAP BitMap, + IN ULONG_PTR Bit) { /* Check if bit is in range */ if(Bit >= BitMap->Size) @@ -460,155 +612,3 @@ RtlTestBit(IN PRTL_BITMAP BitMap, /* Test specified bit and return result */ return ((BitMap->Buffer[Bit / BITS_PER_LONG] >> (Bit & (BITS_PER_LONG - 1))) & 1) ? TRUE : FALSE; } - -/** - * Counts the number of either set or clear bits in the contiguous region of the bit map. - * - * @param BitMap - * Supplies a pointer to the bit map. - * - * @param Length - * Supplies the maximum length (number of bits) to count. - * - * @param StartingIndex - * Supplies the starting index of the first bit to count. - * - * @param SetBits - * Specifies whether count bits that are set or clear. - * - * @return This routine returns the number of equal bits found in the contiguous region. - * - * @since XT 1.0 - */ -XTAPI -ULONG_PTR -RtlpCountBits(IN PRTL_BITMAP BitMap, - IN ULONG_PTR Length, - IN ULONG_PTR StartingIndex, - IN BOOLEAN SetBits) -{ - PULONG_PTR Buffer, BufferEnd; - ULONG_PTR BitOffset, Size; - ULONGLONG Value; - - /* Get pointers to first and last bytes to check */ - Buffer = &BitMap->Buffer[StartingIndex / BITS_PER_LONG]; - BufferEnd = Buffer + ((Length + BITS_PER_LONG - 1) / BITS_PER_LONG); - - /* Get offset and value */ - BitOffset = StartingIndex & (BITS_PER_LONG - 1); - Value = (SetBits ? ~*Buffer : *Buffer) >> BitOffset << BitOffset; - - /* Find first bit set until the end of the buffer */ - while(!Value && Buffer + 1 < BufferEnd) - { - /* Advance buffer pointer and get value */ - Value = SetBits ? ~*(++Buffer) : *(++Buffer); - } - - /* Check if value found */ - if(!Value) - { - /* No bits found, return length */ - return Length; - } - - /* Calculate size */ - Size = ((Buffer - BitMap->Buffer) * BITS_PER_LONG) - StartingIndex + (ULONG_PTR)RtlCountTrailingZeroes64(Value); - - /* Return whatever is smaller */ - return Size > Length ? Length : Size; -} - -/** - * Searches the bit map for a contiguous region of either set or clear bits. - * - * @param BitMap - * Supplies a pointer to the bit map. - * - * @param Length - * Supplies the length (number of equal bits) to look for. - * - * @param StartingIndex - * Supplies the starting index of the first bit to start the search at a given position. - * - * @param SetBits - * Specifies whether count bits that are set or clear. - * - * @return This routine returns the bit map index position of the contiguous region found, or MAXULONG_PTR if not found. - * - * @since XT 1.0 - */ -XTAPI -ULONG_PTR -RtlpFindBits(IN PRTL_BITMAP BitMap, - IN ULONG_PTR Length, - IN ULONG_PTR StartingIndex, - IN BOOLEAN SetBits) -{ - ULONG_PTR BitMapEnd, BitOffset, Size; - ULONG Tries; - - /* Validate length */ - if(Length > BitMap->Size) - { - /* Length exceeds bit map size, return MAXULONG_PTR */ - return (ULONG_PTR)-1; - } - else if(!Length) - { - /* Length not specified, return starting index */ - return StartingIndex; - } - - /* Check if starting index is in range of bit map size */ - if(StartingIndex >= BitMap->Size) - { - /* Starting index exceeds bit map size, start from the beginning */ - StartingIndex = 0; - } - - /* Try from starting index */ - BitOffset = StartingIndex; - BitMapEnd = BitMap->Size; - - /* At least two tries are required */ - Tries = (StartingIndex != 0) + 2; - while(Tries) - { - /* Find until the end of the bit map */ - while(BitOffset + Length < BitMapEnd) - { - /* Increment offset */ - BitOffset += RtlpCountBits(BitMap, BitMap->Size - BitOffset, BitOffset, !SetBits); - if(BitOffset + Length > BitMapEnd) - { - /* No match found, break loop execution */ - break; - } - - /* Count bits in the contiguous region and check if match found */ - Size = RtlpCountBits(BitMap, Length, BitOffset, SetBits); - if(Size >= Length) - { - /* Match found, return offset */ - return BitOffset; - } - - /* Increment offset */ - BitOffset += Size; - } - - /* Try again if possible */ - Tries--; - if(Tries) - { - /* Restart from the beginning up to the starting index */ - BitOffset = 0; - BitMapEnd = StartingIndex; - } - } - - /* No match found, return MAXULONG_PTR */ - return (ULONG_PTR)-1; -} diff --git a/xtoskrnl/rtl/globals.c b/xtoskrnl/rtl/data.cc similarity index 64% rename from xtoskrnl/rtl/globals.c rename to xtoskrnl/rtl/data.cc index c452dd5..b862c89 100644 --- a/xtoskrnl/rtl/globals.c +++ b/xtoskrnl/rtl/data.cc @@ -1,8 +1,8 @@ /** * PROJECT: ExectOS * COPYRIGHT: See COPYING.md in the top level directory - * FILE: xtoskrnl/rtl/globals.c - * DESCRIPTION: Kernel runtime library global variables + * FILE: xtoskrnl/rtl/data.cc + * DESCRIPTION: Runtime Library global and static data * DEVELOPERS: Rafal Kupiec */ @@ -10,4 +10,4 @@ /* This is required for floating numbers to keep LLVM happy */ -int _fltused = 0xFEEDBULL; +XTCLINK INT _fltused = 0xFEEDBULL; diff --git a/xtoskrnl/rtl/byteswap.c b/xtoskrnl/rtl/endian.cc similarity index 88% rename from xtoskrnl/rtl/byteswap.c rename to xtoskrnl/rtl/endian.cc index 6984565..2eb6c48 100644 --- a/xtoskrnl/rtl/byteswap.c +++ b/xtoskrnl/rtl/endian.cc @@ -1,12 +1,12 @@ /** * PROJECT: ExectOS * COPYRIGHT: See COPYING.md in the top level directory - * FILE: xtoskrnl/rtl/byteswap.c + * FILE: xtoskrnl/rtl/endian.cc * DESCRIPTION: Endian conversion routines * DEVELOPERS: Rafal Kupiec */ -#include +#include /** @@ -21,7 +21,7 @@ */ XTFASTCALL USHORT -RtlByteSwap16(IN USHORT Source) +RTL::Endianness::SwapByte16(IN USHORT Source) { return (USHORT)(((Source >> 8) & 0x00FF) | ((Source << 8) & 0xFF00)); @@ -39,7 +39,7 @@ RtlByteSwap16(IN USHORT Source) */ XTFASTCALL ULONG -RtlByteSwap32(IN ULONG Source) +RTL::Endianness::SwapByte32(IN ULONG Source) { return (ULONG)(((Source >> 24) & 0x000000FF) | ((Source >> 8) & 0x0000FF00) | @@ -59,7 +59,7 @@ RtlByteSwap32(IN ULONG Source) */ XTFASTCALL ULONGLONG -RtlByteSwap64(IN ULONGLONG Source) +RTL::Endianness::SwapByte64(IN ULONGLONG Source) { return (ULONGLONG)(((Source >> 56) & 0x00000000000000FF) | ((Source >> 40) & 0x000000000000FF00) | diff --git a/xtoskrnl/rtl/exports.cc b/xtoskrnl/rtl/exports.cc new file mode 100644 index 0000000..34c3f71 --- /dev/null +++ b/xtoskrnl/rtl/exports.cc @@ -0,0 +1,1310 @@ +/** + * PROJECT: ExectOS + * COPYRIGHT: See COPYING.md in the top level directory + * FILE: xtoskrnl/rtl/exports.cc + * DESCRIPTION: C-compatible API wrappers for exported kernel functions + * DEVELOPERS: Aiken Harris + */ + +#include + + +/** + * Clears all bits in the bit map. + * + * @param BitMap + * Supplies a pointer to the bit map. + * + * @return This routine does not return any value. + * + * @since NT 3.5 + */ +XTCLINK +XTAPI +VOID +RtlClearAllBits(IN PRTL_BITMAP BitMap) +{ + RTL::BitMap::ClearAllBits(BitMap); +} + +/** + * Clears a single bit in the bit map. + * + * @param BitMap + * Supplies a pointer to the bit map. + * + * @param Bit + * Specifies the number of the bit to be cleared. + * + * @return This routine does not return any value. + * + * @since NT 5.1 + */ +XTCLINK +XTAPI +VOID +RtlClearBit(IN PRTL_BITMAP BitMap, + IN ULONG_PTR Bit) +{ + RTL::BitMap::ClearBit(BitMap, Bit); +} + +/** + * Clears a specified set of bits within a bit map. + * + * @param BitMap + * Supplies a pointer to the bit map. + * + * @param StartingIndex + * Supplies the starting index of the first bit to clear. + * + * @param Length + * Supplies the length (number of bits) to clear. + * + * @return This routine does not return any value. + * + * @since NT 3.5 + */ +XTCLINK +XTAPI +VOID +RtlClearBits(IN PRTL_BITMAP BitMap, + IN ULONG_PTR StartingIndex, + IN ULONG_PTR Length) +{ + RTL::BitMap::ClearBits(BitMap, StartingIndex, Length); +} + +/** + * Searches the bit map for a contiguous region of set bits and clears them. + * + * @param BitMap + * Supplies a pointer to the bit map. + * + * @param Length + * Supplies the length of contiguous region (number of set bits) to look for. + * + * @param Index + * Supplies the index of the first bit to start the search at a given position. + * + * @return This routine returns the bit map index position of the contiguous region found, or MAXULONG_PTR if not found. + * + * @since XT 1.0 + */ +XTCLINK +XTAPI +ULONG +RtlClearSetBits(IN PRTL_BITMAP BitMap, + IN ULONG_PTR Length, + IN ULONG_PTR Index) +{ + return RTL::BitMap::ClearSetBits(BitMap, Length, Index); +} + +/** + * Compares two GUIDs (Globally Unique Identifiers). + * + * @param Guid1 + * Supplies the first GUID to compare. + * + * @param Guid2 + * Supplies the second GUID to compare. + * + * @return This routine returns TRUE if the provided GUIDs are equal, or FALSE otherwise. + * + * @since XT 1.0 + */ +XTAPI +BOOLEAN +RtlCompareGuids(IN PGUID Guid1, + IN PGUID Guid2) +{ + return RTL::Guid::CompareGuids(Guid1, Guid2); +} + +/** + * 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 + */ +XTCLINK +XTAPI +SIZE_T +RtlCompareMemory(IN PCVOID LeftBuffer, + IN PCVOID RightBuffer, + IN SIZE_T Length) +{ + return RTL::Memory::CompareMemory(LeftBuffer, RightBuffer, Length); +} + +/** + * Compares at most specified number of characters of two C strings. + * + * @param String1 + * String to be compared. + * + * @param String2 + * String to be compared. + * + * @param Length + * Maximum number of characters to compare. If no limit set, it compares whole strings. + * + * @return Integral value indicating the relationship between the strings. + * + * @since XT 1.0 + */ +XTCLINK +XTAPI +SIZE_T +RtlCompareString(IN PCSTR String1, + IN PCSTR String2, + IN SIZE_T Length) +{ + return RTL::String::CompareString(String1, String2, Length); +} + +/** + * Compares at most specified number of characters of two C strings, while ignoring differences in case. + * + * @param String1 + * String to be compared. + * + * @param String2 + * String to be compared. + * + * @param Length + * Maximum number of characters to compare. If no limit set, it compares whole strings. + * + * @return Integral value indicating the relationship between the strings. + * + * @since XT 1.0 + */ +XTCLINK +XTAPI +SIZE_T +RtlCompareStringInsensitive(IN PCSTR String1, + IN PCSTR String2, + IN SIZE_T Length) +{ + return RTL::String::CompareStringInsensitive(String1, String2, Length); +} + +/** + * 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. If no limit set, it compares whole wide strings. + * + * @return Integral value indicating the relationship between the wide strings. + * + * @since XT 1.0 + */ +XTCLINK +XTAPI +SIZE_T +RtlCompareWideString(IN PCWSTR String1, + IN PCWSTR String2, + IN SIZE_T Length) +{ + return RTL::WideString::CompareWideString(String1, String2, Length); +} + +/** + * Compares at most specified number of characters of two C wide strings, while ignoring differences in case. + * + * @param String1 + * Wide string to be compared. + * + * @param String2 + * Wide string to be compared. + * + * @param Length + * Maximum number of characters to compare. If no limit set, it compares whole wide strings. + * + * @return Integral value indicating the relationship between the wide strings. + * + * @since XT 1.0 + */ +XTCLINK +XTAPI +SIZE_T +RtlCompareWideStringInsensitive(IN PCWSTR String1, + IN PCWSTR String2, + IN SIZE_T Length) +{ + return RTL::WideString::CompareWideStringInsensitive(String1, String2, Length); +} + +/** + * Appends a copy of the source string to the end of the destination string. + * + * @param Destination + * Supplies a pointer to the null-terminated string to append to. + * + * @param Source + * Supplies a pointer to the null-terminated string to copy from. + * + * @param Count + * Sets a maximum number of characters to copy. If no limit set, appends whole string. + * + * @return This routine returns a copy of a destination string. + * + * @since XT 1.0 + */ +XTCLINK +XTAPI +PCHAR +RtlConcatenateString(OUT PCHAR Destination, + IN PCHAR Source, + IN SIZE_T Count) +{ + return RTL::String::ConcatenateString(Destination, Source, Count); +} + +/** + * Appends a copy of the source wide string to the end of the destination wide string. + * + * @param Destination + * Supplies a pointer to the null-terminated wide string to append to. + * + * @param Source + * Supplies a pointer to the null-terminated wide string to copy from. + * + * @param Count + * Sets a maximum number of wide characters to copy. If no limit set, appends whole wide string. + * + * @return This routine returns a copy of a destination wide string. + * + * @since XT 1.0 + */ +XTCLINK +XTAPI +PWCHAR +RtlConcatenateWideString(OUT PWCHAR Destination, + IN PWCHAR Source, + IN SIZE_T Count) +{ + return RTL::WideString::ConcatenateWideString(Destination, Source, Count); +} + +/** + * Converts the 32-bit signed value to a large integer. + * + * @param Value + * Supplies the value to convert. + * + * @return This routine returns the large integer representation of the given value. + * + * @since XT 1.0 + */ +XTCLINK +XTAPI +LARGE_INTEGER +RtlConvertToLargeInteger32(IN LONG Value) +{ + return RTL::Math::ConvertToLargeInteger32(Value); +} + +/** + * Converts the 32-bit unsigned value to a large integer. + * + * @param Value + * Supplies the value to convert. + * + * @return This routine returns the large integer representation of the given value. + * + * @since XT 1.0 + */ +XTCLINK +XTAPI +LARGE_INTEGER +RtlConvertToLargeIntegerUnsigned32(IN ULONG Value) +{ + return RTL::Math::ConvertToLargeIntegerUnsigned32(Value); +} + +/** + * 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 This routine does not return any value. + * + * @since NT 3.5 + */ +XTCLINK +XTAPI +VOID +RtlCopyMemory(OUT PVOID Destination, + IN PCVOID Source, + IN SIZE_T Length) +{ + RTL::Memory::CopyMemory(Destination, Source, Length); +} + +/** + * Copies a string from a buffer into another buffer, ensuring that the destination string is NULL-terminated. + * + * @param Destination + * Supplies a pointer to the destination buffer. + * + * @param Source + * Supplies a pointer to the source buffer. + * + * @param Length + * Supplies the length of the string to copy. + * + * @return This routine does not return any value. + * + * @since XT 1.0 + */ +XTCLINK +XTAPI +VOID +RtlCopyString(IN PCHAR Destination, + IN PCSTR Source, + IN ULONG Length) +{ + RTL::String::CopyString(Destination, Source, Length); +} + +/** + * Copies a wide string from a buffer into another buffer, ensuring that the destination string is NULL-terminated. + * + * @param Destination + * Supplies a pointer to the destination buffer. + * + * @param Source + * Supplies a pointer to the source buffer. + * + * @param Length + * Supplies the length of the wide string to copy. + * + * @return This routine does not return any value. + * + * @since XT 1.0 + */ +XTCLINK +XTAPI +VOID +RtlCopyWideString(IN PWCHAR Destination, + IN PCWSTR Source, + IN ULONG Length) +{ + RTL::WideString::CopyWideString(Destination, Source, Length); +} + +/** + * Divides a signed large integer by a 32-bit divisor. + * + * @param Dividend + * Supplies a large integer to be divided. + * + * @param Divisor + * Supplies a 32-bit divisor. + * + * @param Remainder + * Supplies a pointer that receives the divide remainder. + * + * @return This routine returns the quotient. + * + * @since XT 1.0 + */ +XTCLINK +XTAPI +LARGE_INTEGER +RtlDivideLargeInteger(IN LARGE_INTEGER Dividend, + IN ULONG Divisor, + OUT PULONG Remainder) +{ + return RTL::Math::DivideLargeInteger(Dividend, Divisor, Remainder); +} + +/** + * Searches the bit map for a contiguous region of clear bits. + * + * @param BitMap + * Supplies a pointer to the bit map. + * + * @param Length + * Supplies the length of contiguous region (number of clear bits) to look for. + * + * @param Index + * Supplies the index of the first bit to start the search at a given position. + * + * @return This routine returns the bit map index position of the contiguous region found, or MAXULONG_PTR if not found. + * + * @since NT 3.5 + */ +XTCLINK +XTAPI +ULONG_PTR +RtlFindClearBits(IN PRTL_BITMAP BitMap, + IN ULONG_PTR Length, + IN ULONG_PTR Index) +{ + return RTL::BitMap::FindClearBits(BitMap, Length, Index); +} + +/** + * Searches the bit map for a contiguous region of set bits. + * + * @param BitMap + * Supplies a pointer to the bit map. + * + * @param Length + * Supplies the length of contiguous region (number of set bits) to look for. + * + * @param Index + * Supplies the index of the first bit to start the search at a given position. + * + * @return This routine returns the bit map index position of the contiguous region found, or MAXULONG_PTR if not found. + * + * @since NT 3.5 + */ +XTCLINK +XTAPI +ULONG_PTR +RtlFindSetBits(IN PRTL_BITMAP BitMap, + IN ULONG_PTR Length, + IN ULONG_PTR Index) +{ + return RTL::BitMap::FindSetBits(BitMap, Length, Index); +} + +/** + * Finds the first occurrence of the search string in the source string. + * + * @param Source + * Supplies a pointer to the source string. + * + * @param Search + * Supplies a pointer to the search string. + * + * @return This routine returns a pointer to the first occurrence of the search string in the source string. + * + * @since XT 1.0 + */ +XTCLINK +XTAPI +PCSTR +RtlFindString(IN PCSTR Source, + IN PCSTR Search) +{ + return RTL::String::FindString(Source, Search); +} + +/** + * Finds the first case-insensitive occurrence of the search string in the source string. + * + * @param Source + * Supplies a pointer to the source string. + * + * @param Search + * Supplies a pointer to the search string. + * + * @return This routine returns a pointer to the first occurrence of the search string in the source string. + * + * @since XT 1.0 + */ +XTCLINK +XTAPI +PCSTR +RtlFindStringInsensitive(IN PCSTR Source, + IN PCSTR Search) +{ + return RTL::String::FindStringInsensitive(Source, Search); +} + +/** + * Finds the first occurrence of the search wide string in the source wide string. + * + * @param Source + * Supplies a pointer to the source wide string. + * + * @param Search + * Supplies a pointer to the search wide string. + * + * @return This routine returns a pointer to the first occurrence of the search wide string in the source wide string. + * + * @since XT 1.0 + */ +XTCLINK +XTAPI +PCWSTR +RtlFindWideString(IN PCWSTR Source, + IN PCWSTR Search) +{ + return RTL::WideString::FindWideString(Source, Search); +} + +/** + * Finds the first case-insensitive occurrence of the search wide string in the source wide string. + * + * @param Source + * Supplies a pointer to the source wide string. + * + * @param Search + * Supplies a pointer to the search wide string. + * + * @return This routine returns a pointer to the first occurrence of the search wide string in the source wide string. + * + * @since XT 1.0 + */ +XTCLINK +XTAPI +PCWSTR +RtlFindWideStringInsensitive(IN PCWSTR Source, + IN PCWSTR Search) +{ + return RTL::WideString::FindWideStringInsensitive(Source, Search); +} + +/** + * Initializes a bit map. + * + * @param BitMap + * Supplies a pointer to the bit map to initialize. + * + * @param Buffer + * Supplies a pointer to the buffer that will be used as a bit map. + * + * @param Size + * Supplies a size of the bit map. + * + * @return This routine does not return any value. + * + * @since NT 3.5 + */ +XTCLINK +XTAPI +VOID +RtlInitializeBitMap(IN PRTL_BITMAP BitMap, + IN PULONG_PTR Buffer, + IN ULONG Size) +{ + RTL::BitMap::InitializeBitMap(BitMap, Buffer, Size); +} + +/** + * 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 + */ +XTCLINK +XTCDECL +VOID +RtlInitializeListHead(IN PLIST_ENTRY ListHead) +{ + RTL::LinkedList::InitializeListHead(ListHead); +} + +/** + * This routine inserts an entry at the head of a doubly 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 + */ +XTCLINK +XTCDECL +VOID +RtlInsertHeadList(IN OUT PLIST_ENTRY ListHead, + IN PLIST_ENTRY Entry) +{ + RTL::LinkedList::InsertHeadList(ListHead, Entry); +} + +/** + * This routine inserts an entry at the tail of a doubly 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 + */ +XTCLINK +XTCDECL +VOID +RtlInsertTailList(IN OUT PLIST_ENTRY ListHead, + IN PLIST_ENTRY Entry) +{ + RTL::LinkedList::InsertTailList(ListHead, Entry); +} + +/** + * Indicates whether a doubly linked list structure is empty, or not initialized at all. + * + * @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 + */ +XTCLINK +XTCDECL +BOOLEAN +RtlListEmpty(IN PLIST_ENTRY ListHead) +{ + return RTL::LinkedList::ListEmpty(ListHead); +} + +/** + * This routine detects a loop in a doubly linked list. + * + * @param ListHead + * Pointer to a structure that represents the head of the list. + * + * @return TRUE if linked list contains a loop or FALSE otherwise. + * + * @since XT 1.0 + */ +XTCLINK +XTCDECL +BOOLEAN +RtlListLoop(IN PLIST_ENTRY ListHead) +{ + return RTL::LinkedList::ListLoop(ListHead); +} + +/** + * 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 + */ +XTCLINK +XTAPI +VOID +RtlMoveMemory(OUT PVOID Destination, + IN PCVOID Source, + IN SIZE_T Length) +{ + RTL::Memory::MoveMemory(Destination, Source, Length); +} + +/** + * Multiplies a signed large integer by a signed integer. + * + * @param Multiplicand + * Supplies a large integer to be multiplied. + * + * @param Multiplier + * Supplies an integer by which the large integer is multiplied. + * + * @return This routine returns the result of the multiplication. + * + * @since XT 1.0 + */ +XTCLINK +XTAPI +LARGE_INTEGER +RtlMultiplyLargeInteger(IN LARGE_INTEGER Multiplicand, + IN LONG Multiplier) +{ + return RTL::Math::MultiplyLargeInteger(Multiplicand, Multiplier); +} + +/** + * This routine removes an entry from a doubly linked list. + * + * @param Entry + * Pointer to the entry that will be removed from the list. + * + * @return This routine does not return any value. + * + * @since XT 1.0 + */ +XTCLINK +XTCDECL +VOID +RtlRemoveEntryList(IN PLIST_ENTRY Entry) +{ + RTL::LinkedList::RemoveEntryList(Entry); +} + +/** + * Reverses a characters order in a string. It modifies the original, input variable. + * + * @param String + * Supplies a pointer to the string to reverse. + * + * @param Length + * Supplies the length of the string to reverse. + * + * @return This routine does not return any value. + * + * @since XT 1.0 + */ +XTCLINK +XTAPI +VOID +RtlReverseString(IN OUT PCHAR String, + IN ULONG Length) +{ + RTL::String::ReverseString(String, Length); +} + +/** + * Reverses a characters order in a wide string. It modifies the original, input variable. + * + * @param String + * Supplies a pointer to the wide string to reverse. + * + * @param Length + * Supplies the length of the wide string to reverse. + * + * @return This routine does not return any value. + * + * @since XT 1.0 + */ +XTCLINK +XTAPI +VOID +RtlReverseWideString(IN OUT PWCHAR String, + IN ULONG Length) +{ + RTL::WideString::ReverseWideString(String, Length); +} + +/** + * 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 Returns TRUE if both buffers are equal up to the specified length, or FALSE otherwise. + * + * @since XT 1.0 + */ +XTCLINK +XTAPI +BOOLEAN +RtlSameMemory(IN PCVOID LeftBuffer, + IN PCVOID RightBuffer, + IN SIZE_T Length) +{ + return RTL::Memory::SameMemory(LeftBuffer, RightBuffer, Length); +} + +/** + * Sets all bits in the bit map. + * + * @param BitMap + * Supplies a pointer to the bit map. + * + * @return This routine does not return any value. + * + * @since NT 3.5 + */ +XTCLINK +XTAPI +VOID +RtlSetAllBits(IN PRTL_BITMAP BitMap) +{ + RTL::BitMap::SetAllBits(BitMap); +} + +/** + * Sets a single bit in the bit map. + * + * @param BitMap + * Supplies a pointer to the bit map. + * + * @param Bit + * Specifies the number of the bit to be set. + * + * @return This routine does not return any value. + * + * @since NT 5.1 + */ +XTCLINK +XTAPI +VOID +RtlSetBit(IN PRTL_BITMAP BitMap, + IN ULONG_PTR Bit) +{ + RTL::BitMap::SetBit(BitMap, Bit); +} + +/** + * Sets a specified set of bits within a bit map. + * + * @param BitMap + * Supplies a pointer to the bit map. + * + * @param StartingIndex + * Supplies the starting index of the first bit to set. + * + * @param Length + * Supplies the length (number of bits) to set. + * + * @return This routine does not return any value. + * + * @since NT 3.5 + */ +XTCLINK +XTAPI +VOID +RtlSetBits(IN PRTL_BITMAP BitMap, + IN ULONG_PTR StartingIndex, + IN ULONG_PTR Length) +{ + RTL::BitMap::SetBits(BitMap, StartingIndex, Length); +} + +/** + * Searches the bit map for a contiguous region of clear bits and sets them. + * + * @param BitMap + * Supplies a pointer to the bit map. + * + * @param Length + * Supplies the length of contiguous region (number of clear bits) to look for. + * + * @param Index + * Supplies the index of the first bit to start the search at a given position. + * + * @return This routine returns the bit map index position of the contiguous region found, or MAXULONG_PTR if not found. + * + * @since XT 1.0 + */ +XTCLINK +XTAPI +ULONG +RtlSetClearBits(IN PRTL_BITMAP BitMap, + IN ULONG_PTR Length, + IN ULONG_PTR Index) +{ + return RTL::BitMap::SetClearBits(BitMap, Length, Index); +} + +/** + * 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 + */ +XTCLINK +XTAPI +VOID +RtlSetMemory(OUT PVOID Destination, + IN UCHAR Byte, + IN SIZE_T Length) +{ + RTL::Memory::SetMemory(Destination, Byte, Length); +} + +/** + * Calculates the length of a given string. + * + * @param String + * Pointer to the null-terminated string to be examined. + * + * @param MaxLength + * Maximum number of characters to examine. If no limit set, it examines whole string. + * + * @return The length of the null-terminated string. + * + * @since: XT 1.0 + */ +XTCLINK +XTAPI +SIZE_T +RtlStringLength(IN PCSTR String, + IN SIZE_T MaxLength) +{ + return RTL::String::StringLength(String, MaxLength); +} + +/** + * Converts a multibyte character string to its wide character representation. + * + * @param Destination + * Pointer to wide character array where the wide string will be stored + * + * @param Source + * Pointer to the first element of a multibyte string to convert. + * + * @param Length + * Number of characters in the source string. + * + * @return Returns the number of wide characters written to the destination array on success, or -1 on error. + * + * @since XT 1.0 + */ +XTCLINK +XTAPI +SIZE_T +RtlStringToWideString(OUT PWCHAR Destination, + IN PCSTR *Source, + IN SIZE_T Length) +{ + return RTL::String::StringToWideString(Destination, Source, Length); +} + +/** + * Tests a state of a single bit in the bit map. + * + * @param BitMap + * Supplies a pointer to the bit map. + * + * @param Bit + * Specifies the number of the bit to be tested. + * + * @return This routine returns TRUE when bit is set, or FALSE otherwise. + * + * @since NT 5.1 + */ +XTCLINK +XTAPI +BOOLEAN +RtlTestBit(IN PRTL_BITMAP BitMap, + IN ULONG_PTR Bit) +{ + return RTL::BitMap::TestBit(BitMap, Bit); +} + +/** + * Finds the next token in a null-terminated string. + * + * @param String + * Pointer to the null-terminated string to tokenize. + * + * @param Delimiter + * Pointer to the null-terminated 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 + */ +XTCLINK +XTAPI +PCHAR +RtlTokenizeString(IN PCHAR String, + IN PCSTR Delimiter, + IN OUT PCHAR *SavePtr) +{ + return RTL::String::TokenizeString(String, Delimiter, SavePtr); +} + +/** + * 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 + */ +XTCLINK +XTAPI +PWCHAR +RtlTokenizeWideString(IN PWCHAR String, + IN PCWSTR Delimiter, + IN OUT PWCHAR *SavePtr) +{ + return RTL::WideString::TokenizeWideString(String, Delimiter, SavePtr); +} + +/** + * Converts a character to lowercase. + * + * @param Character + * Character to be converted. + * + * @return Converted character or original character if it was not uppercase. + * + * @since XT 1.0 + */ +XTCLINK +XTAPI +CHAR +RtlToLowerCharacter(IN CHAR Character) +{ + return RTL::String::ToLowerCharacter(Character); +} + +/** + * Converts a wide character to lowercase. + * + * @param Character + * Wide character to be converted. + * + * @return Converted wide character or original character if it was not uppercase. + * + * @since XT 1.0 + */ +XTCLINK +XTAPI +WCHAR +RtlToLowerWideCharacter(IN WCHAR Character) +{ + return RTL::WideString::ToLowerWideCharacter(Character); +} + +/** + * Converts a character to uppercase. + * + * @param Character + * Character to be converted. + * + * @return Converted character or original character if it was not lowercase. + * + * @since XT 1.0 + */ +XTCLINK +XTAPI +CHAR +RtlToUpperCharacter(IN CHAR Character) +{ + return RTL::String::ToUpperCharacter(Character); +} + +/** + * Converts a wide character to uppercase. + * + * @param Character + * Wide character to be converted. + * + * @return Converted wide character or original character if it was not lowercase. + * + * @since XT 1.0 + */ +XTCLINK +XTAPI +WCHAR +RtlToUpperWideCharacter(IN WCHAR Character) +{ + return RTL::WideString::ToUpperWideCharacter(Character); +} + +/** + * Removes certain characters from a beginning of the string. + * + * @param String + * Pointer to the null-terminated string to be trimmed. + * + * @return This routine returns a pointer to the left-trimmed string. + * + * @since XT 1.0 + */ +XTCLINK +XTAPI +PCHAR +RtlTrimLeftString(IN PCHAR String) +{ + return RTL::String::TrimLeftString(String); +} + +/** + * Removes certain characters from a beginning of the wide string. + * + * @param String + * Pointer to the null-terminated wide string to be trimmed. + * + * @return This routine returns a pointer to the left-trimmed wide string. + * + * @since XT 1.0 + */ +XTCLINK +XTAPI +PWCHAR +RtlTrimLeftWideString(IN PWCHAR String) +{ + return RTL::WideString::TrimLeftWideString(String); +} + +/** + * Removes certain characters from the end of the string. + * + * @param String + * Pointer to the null-terminated string to be trimmed. + * + * @return This routine returns a pointer to the right-trimmed string. + * + * @since XT 1.0 + */ +XTCLINK +XTAPI +PCHAR +RtlTrimRightString(IN PCHAR String) +{ + return RTL::String::TrimRightString(String); +} + +/** + * Removes certain characters from the end of the wide string. + * + * @param String + * Pointer to the null-terminated wide string to be trimmed. + * + * @return This routine returns a pointer to the right-trimmed wide string. + * + * @since XT 1.0 + */ +XTCLINK +XTAPI +PWCHAR +RtlTrimRightWideString(IN PWCHAR String) +{ + return RTL::WideString::TrimRightWideString(String); +} + +/** + * Removes certain characters from the beginning and the end of the string. + * + * @param String + * Pointer to the null-terminated string to be trimmed. + * + * @return This routine returns a pointer to the trimmed string. + * + * @since XT 1.0 + */ +XTCLINK +XTAPI +PCHAR +RtlTrimString(IN PCHAR String) +{ + return RTL::String::TrimLeftString(RTL::String::TrimRightString(String)); +} + +/** + * Removes certain characters from the beginning and the end of the wide string. + * + * @param String + * Pointer to the null-terminated wide string to be trimmed. + * + * @return This routine returns a pointer to the trimmed wide string. + * + * @since XT 1.0 + */ +XTCLINK +XTAPI +PWCHAR +RtlTrimWideString(IN PWCHAR String) +{ + return RTL::WideString::TrimWideString(String); +} + +/** + * Calculates the length of a given wide string. + * + * @param String + * Pointer to the null-terminated wide string to be examined. + * + * @param MaxLength + * Maximum number of wide characters to examine. If no limit set, it examines whole string. + * + * @return The length of the null-terminated wide string. + * + * @since: XT 1.0 + */ +XTCLINK +XTAPI +SIZE_T +RtlWideStringLength(IN PCWSTR String, + IN SIZE_T MaxLength) +{ + return RTL::WideString::WideStringLength(String, MaxLength); +} + +/** + * 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 + */ +XTCLINK +XTAPI +VOID +RtlZeroMemory(OUT PVOID Destination, + IN SIZE_T Length) +{ + RTL::Memory::ZeroMemory(Destination, Length); +} diff --git a/xtoskrnl/rtl/guid.c b/xtoskrnl/rtl/guid.cc similarity index 70% rename from xtoskrnl/rtl/guid.c rename to xtoskrnl/rtl/guid.cc index 4919b73..3585f5f 100644 --- a/xtoskrnl/rtl/guid.c +++ b/xtoskrnl/rtl/guid.cc @@ -1,12 +1,12 @@ /** * PROJECT: ExectOS * COPYRIGHT: See COPYING.md in the top level directory - * FILE: xtoskrnl/rtl/guid.c + * FILE: xtoskrnl/rtl/guid.cc * DESCRIPTION: GUID manipulation routines * DEVELOPERS: Rafal Kupiec */ -#include +#include /** @@ -24,8 +24,8 @@ */ XTAPI BOOLEAN -RtlCompareGuids(IN PGUID Guid1, - IN PGUID Guid2) +RTL::Guid::CompareGuids(IN PGUID Guid1, + IN PGUID Guid2) { PUINT Guid1Ptr, Guid2Ptr; @@ -34,6 +34,6 @@ RtlCompareGuids(IN PGUID Guid1, Guid2Ptr = (PUINT)Guid2; /* Compare GUIDs */ - return(Guid1Ptr[0] == Guid2Ptr[0] && Guid1Ptr[1] == Guid2Ptr[1] && - Guid1Ptr[2] == Guid2Ptr[2] && Guid1Ptr[3] == Guid2Ptr[3]); + return (BOOLEAN)(Guid1Ptr[0] == Guid2Ptr[0] && Guid1Ptr[1] == Guid2Ptr[1] && + Guid1Ptr[2] == Guid2Ptr[2] && Guid1Ptr[3] == Guid2Ptr[3]); } diff --git a/xtoskrnl/rtl/i686/dispatch.c b/xtoskrnl/rtl/i686/dispatch.cc similarity index 80% rename from xtoskrnl/rtl/i686/dispatch.c rename to xtoskrnl/rtl/i686/dispatch.cc index 0c8ac96..5b7008e 100644 --- a/xtoskrnl/rtl/i686/dispatch.c +++ b/xtoskrnl/rtl/i686/dispatch.cc @@ -1,12 +1,12 @@ /** * PROJECT: ExectOS * COPYRIGHT: See COPYING.md in the top level directory - * FILE: xtoskrnl/rtl/i686/dispatch.c + * FILE: xtoskrnl/rtl/i686/dispatch.cc * DESCRIPTION: Dispatching support for i686 architecture * DEVELOPERS: Rafal Kupiec */ -#include +#include /** @@ -24,8 +24,8 @@ */ XTAPI VOID -RtlGetStackLimits(OUT PULONG_PTR StackBase, - OUT PULONG_PTR StackLimit) +RTL::Dispatcher::GetStackLimits(OUT PULONG_PTR StackBase, + OUT PULONG_PTR StackLimit) { PKTHREAD Thread = KeGetCurrentThread(); *StackBase = (ULONG_PTR)Thread->StackBase - sizeof(FX_SAVE_AREA); diff --git a/xtoskrnl/rtl/i686/exsup.c b/xtoskrnl/rtl/i686/exsup.cc similarity index 90% rename from xtoskrnl/rtl/i686/exsup.c rename to xtoskrnl/rtl/i686/exsup.cc index e9398ce..b9a3b3a 100644 --- a/xtoskrnl/rtl/i686/exsup.c +++ b/xtoskrnl/rtl/i686/exsup.cc @@ -1,14 +1,15 @@ /** * PROJECT: ExectOS * COPYRIGHT: See COPYING.md in the top level directory - * FILE: xtoskrnl/rtl/i686/exsup.c + * FILE: xtoskrnl/rtl/i686/exsup.cc * DESCRIPTION: Exception handling for i686 architecture * DEVELOPERS: Rafal Kupiec */ -#include +#include +XTCLINK XTCDECL EXCEPTION_DISPOSITION __C_specific_handler(IN PEXCEPTION_RECORD ExceptionRecord, @@ -22,6 +23,7 @@ __C_specific_handler(IN PEXCEPTION_RECORD ExceptionRecord, return ExceptionContinueExecution; } +XTCLINK XTCDECL INT _except_handler3(PEXCEPTION_RECORD ExceptionRecord, diff --git a/xtoskrnl/rtl/plist.c b/xtoskrnl/rtl/llist.cc similarity index 83% rename from xtoskrnl/rtl/plist.c rename to xtoskrnl/rtl/llist.cc index e63483c..99fa8a6 100644 --- a/xtoskrnl/rtl/plist.c +++ b/xtoskrnl/rtl/llist.cc @@ -1,12 +1,12 @@ /** * PROJECT: ExectOS * COPYRIGHT: See COPYING.md in the top level directory - * FILE: xtoskrnl/rtl/plist.c + * FILE: xtoskrnl/rtl/llist.cc * DESCRIPTION: Linked list manipulation routines * DEVELOPERS: Rafal Kupiec */ -#include +#include /** @@ -21,7 +21,7 @@ */ XTCDECL VOID -RtlInitializeListHead(IN PLIST_ENTRY ListHead) +RTL::LinkedList::InitializeListHead(IN PLIST_ENTRY ListHead) { ListHead->Blink = ListHead; ListHead->Flink = ListHead; @@ -39,7 +39,7 @@ RtlInitializeListHead(IN PLIST_ENTRY ListHead) */ XTCDECL VOID -RtlInitializeListHead32(IN PLIST_ENTRY32 ListHead) +RTL::LinkedList::InitializeListHead32(IN PLIST_ENTRY32 ListHead) { ListHead->Blink = PtrToUlong(ListHead); ListHead->Flink = PtrToUlong(ListHead); @@ -60,8 +60,8 @@ RtlInitializeListHead32(IN PLIST_ENTRY32 ListHead) */ XTCDECL VOID -RtlInsertHeadList(IN OUT PLIST_ENTRY ListHead, - IN PLIST_ENTRY Entry) +RTL::LinkedList::InsertHeadList(IN OUT PLIST_ENTRY ListHead, + IN PLIST_ENTRY Entry) { Entry->Flink = ListHead->Flink; Entry->Blink = ListHead; @@ -84,8 +84,8 @@ RtlInsertHeadList(IN OUT PLIST_ENTRY ListHead, */ XTCDECL VOID -RtlInsertTailList(IN OUT PLIST_ENTRY ListHead, - IN PLIST_ENTRY Entry) +RTL::LinkedList::InsertTailList(IN OUT PLIST_ENTRY ListHead, + IN PLIST_ENTRY Entry) { Entry->Flink = ListHead; Entry->Blink = ListHead->Blink; @@ -105,9 +105,9 @@ RtlInsertTailList(IN OUT PLIST_ENTRY ListHead, */ XTCDECL BOOLEAN -RtlListEmpty(IN PLIST_ENTRY ListHead) +RTL::LinkedList::ListEmpty(IN PLIST_ENTRY ListHead) { - return (((ListHead->Flink == NULL) && (ListHead->Blink == NULL)) || (ListHead->Flink == ListHead)); + return (BOOLEAN)(((ListHead->Flink == NULL) && (ListHead->Blink == NULL)) || (ListHead->Flink == ListHead)); } /** @@ -122,7 +122,7 @@ RtlListEmpty(IN PLIST_ENTRY ListHead) */ XTCDECL BOOLEAN -RtlListLoop(IN PLIST_ENTRY ListHead) +RTL::LinkedList::ListLoop(IN PLIST_ENTRY ListHead) { PLIST_ENTRY SlowEntry, FastEntry; @@ -168,7 +168,7 @@ RtlListLoop(IN PLIST_ENTRY ListHead) */ XTCDECL VOID -RtlRemoveEntryList(IN PLIST_ENTRY Entry) +RTL::LinkedList::RemoveEntryList(IN PLIST_ENTRY Entry) { Entry->Flink->Blink = Entry->Blink; Entry->Blink->Flink = Entry->Flink; diff --git a/xtoskrnl/rtl/math.c b/xtoskrnl/rtl/math.cc similarity index 89% rename from xtoskrnl/rtl/math.c rename to xtoskrnl/rtl/math.cc index f6003b4..78e2eaa 100644 --- a/xtoskrnl/rtl/math.c +++ b/xtoskrnl/rtl/math.cc @@ -1,12 +1,12 @@ /** * PROJECT: ExectOS * COPYRIGHT: See COPYING.md in the top level directory - * FILE: xtoskrnl/rtl/math.c + * FILE: xtoskrnl/rtl/math.cc * DESCRIPTION: Kernel math support * DEVELOPERS: Rafal Kupiec */ -#include +#include /** @@ -21,7 +21,7 @@ */ XTAPI LARGE_INTEGER -RtlConvertToLargeInteger32(IN LONG Value) +RTL::Math::ConvertToLargeInteger32(IN LONG Value) { LARGE_INTEGER LargeInt; @@ -42,7 +42,7 @@ RtlConvertToLargeInteger32(IN LONG Value) */ XTAPI LARGE_INTEGER -RtlConvertToLargeIntegerUnsigned32(IN ULONG Value) +RTL::Math::ConvertToLargeIntegerUnsigned32(IN ULONG Value) { LARGE_INTEGER LargeInt; @@ -63,7 +63,7 @@ RtlConvertToLargeIntegerUnsigned32(IN ULONG Value) */ XTAPI INT -RtlCountLeadingZeroes32(IN ULONG Value) +RTL::Math::CountLeadingZeroes32(IN ULONG Value) { /* Return a number of leading zero bits */ return __builtin_clzl(Value); @@ -81,7 +81,7 @@ RtlCountLeadingZeroes32(IN ULONG Value) */ XTAPI INT -RtlCountLeadingZeroes64(IN ULONGLONG Value) +RTL::Math::CountLeadingZeroes64(IN ULONGLONG Value) { /* Return a number of leading zero bits */ return __builtin_clzll(Value); @@ -99,7 +99,7 @@ RtlCountLeadingZeroes64(IN ULONGLONG Value) */ XTAPI INT -RtlCountTrailingZeroes32(IN ULONG Value) +RTL::Math::CountTrailingZeroes32(IN ULONG Value) { /* Return a number of trailing zero bits */ return __builtin_ctzl(Value); @@ -117,7 +117,7 @@ RtlCountTrailingZeroes32(IN ULONG Value) */ XTAPI INT -RtlCountTrailingZeroes64(IN ULONGLONG Value) +RTL::Math::CountTrailingZeroes64(IN ULONGLONG Value) { /* Return a number of trailing zero bits */ return __builtin_ctzll(Value); @@ -141,9 +141,9 @@ RtlCountTrailingZeroes64(IN ULONGLONG Value) */ XTAPI LONGLONG -RtlDivide32(IN LONG Dividend, - IN LONG Divisor, - OUT PLONG Remainder) +RTL::Math::Divide32(IN LONG Dividend, + IN LONG Divisor, + OUT PLONG Remainder) { LONG Quotient; @@ -179,9 +179,9 @@ RtlDivide32(IN LONG Dividend, */ XTAPI LONGLONG -RtlDivide64(IN LONGLONG Dividend, - IN LONGLONG Divisor, - OUT PLONGLONG Remainder) +RTL::Math::Divide64(IN LONGLONG Dividend, + IN LONGLONG Divisor, + OUT PLONGLONG Remainder) { LONGLONG DividendSign, DivisorSign, Quotient, UDividend, UDivisor; @@ -193,7 +193,7 @@ RtlDivide64(IN LONGLONG Dividend, /* Calculate the quotient */ DividendSign ^= DivisorSign; - Quotient = (RtlDivideUnsigned64(UDividend, UDivisor, NULL) ^ DividendSign) - DividendSign; + Quotient = (DivideUnsigned64(UDividend, UDivisor, nullptr) ^ DividendSign) - DividendSign; /* Make sure a pointer to remainder provided */ if(Remainder) @@ -224,9 +224,9 @@ RtlDivide64(IN LONGLONG Dividend, */ XTAPI ULONGLONG -RtlDivideUnsigned32(IN ULONG Dividend, - IN ULONG Divisor, - OUT PULONG Remainder) +RTL::Math::DivideUnsigned32(IN ULONG Dividend, + IN ULONG Divisor, + OUT PULONG Remainder) { /* Make sure a pointer to remainder provided */ if(Remainder) @@ -257,9 +257,9 @@ RtlDivideUnsigned32(IN ULONG Dividend, */ XTAPI ULONGLONG -RtlDivideUnsigned64(IN ULONGLONG Dividend, - IN ULONGLONG Divisor, - OUT PULONGLONG Remainder) +RTL::Math::DivideUnsigned64(IN ULONGLONG Dividend, + IN ULONGLONG Divisor, + OUT PULONGLONG Remainder) { ULARGE_INTEGER DividendParts, DivisorParts, QuotientParts, RemainderParts; LONGLONG Difference; @@ -312,7 +312,7 @@ RtlDivideUnsigned64(IN ULONGLONG Dividend, if(DivisorParts.u.HighPart != 0) { /* Divisor is 64-bit value, calculate the shift count */ - Shift = RtlCountLeadingZeroes32(DivisorParts.u.HighPart) - RtlCountLeadingZeroes32(DividendParts.u.HighPart); + Shift = CountLeadingZeroes32(DivisorParts.u.HighPart) - CountLeadingZeroes32(DividendParts.u.HighPart); /* Check if shift count exceeds 32-bits */ if(Shift > ((sizeof(ULONG) * BITS_PER_BYTE) - 1)) @@ -349,8 +349,8 @@ RtlDivideUnsigned64(IN ULONGLONG Dividend, { /* Divisor is 32-bit value, calculate the shift count */ Shift = (sizeof(ULONG) * BITS_PER_BYTE) + 1 + - RtlCountLeadingZeroes32(DivisorParts.u.LowPart) - - RtlCountLeadingZeroes32(DividendParts.u.HighPart); + CountLeadingZeroes32(DivisorParts.u.LowPart) - + CountLeadingZeroes32(DividendParts.u.HighPart); /* Check if shift is 32-bit */ if(Shift == (sizeof(ULONG) * BITS_PER_BYTE)) @@ -401,7 +401,7 @@ RtlDivideUnsigned64(IN ULONGLONG Dividend, } /* Calculate the shift count */ - Shift = RtlCountLeadingZeroes32(DivisorParts.u.HighPart) - RtlCountLeadingZeroes32(DividendParts.u.HighPart); + Shift = CountLeadingZeroes32(DivisorParts.u.HighPart) - CountLeadingZeroes32(DividendParts.u.HighPart); /* Check if shift exceeds 32-bits */ if(Shift > ((sizeof(ULONG) * BITS_PER_BYTE) - 2)) @@ -485,9 +485,9 @@ RtlDivideUnsigned64(IN ULONGLONG Dividend, */ XTAPI LARGE_INTEGER -RtlDivideLargeInteger(IN LARGE_INTEGER Dividend, - IN ULONG Divisor, - OUT PULONG Remainder) +RTL::Math::DivideLargeInteger(IN LARGE_INTEGER Dividend, + IN ULONG Divisor, + OUT PULONG Remainder) { LONGLONG DividendSign, UDividend; LARGE_INTEGER LargeInt; @@ -497,7 +497,7 @@ RtlDivideLargeInteger(IN LARGE_INTEGER Dividend, UDividend = (Dividend.QuadPart ^ DividendSign) - DividendSign; /* Calculate the quotient */ - LargeInt.QuadPart = (RtlDivideUnsigned64(UDividend, Divisor, NULL) ^ DividendSign) - DividendSign; + LargeInt.QuadPart = (DivideUnsigned64(UDividend, Divisor, nullptr) ^ DividendSign) - DividendSign; /* Make sure a pointer to remainder provided */ if(Remainder) @@ -525,8 +525,8 @@ RtlDivideLargeInteger(IN LARGE_INTEGER Dividend, */ XTAPI LONG -RtlGetBaseExponent(IN DOUBLE Value, - OUT PDOUBLE PowerOfTen) +RTL::Math::GetBaseExponent(IN DOUBLE Value, + OUT PDOUBLE PowerOfTen) { LONG BaseExponent, CurrentExponent, Exponent; ULONG ExponentShift, ExponentMask; @@ -612,7 +612,7 @@ RtlGetBaseExponent(IN DOUBLE Value, */ XTCDECL BOOLEAN -RtlInfiniteDouble(IN DOUBLE Value) +RTL::Math::InfiniteDouble(IN DOUBLE Value) { /* DOUBLE argument in IEEE 754 standard format */ union @@ -631,7 +631,7 @@ RtlInfiniteDouble(IN DOUBLE Value) Var.Double = &Value; /* Return TRUE if it is infinite, or FALSE otherwise */ - return ((Var.DoubleS->Exponent & 0x7FF) == 0x7FF); + return (BOOLEAN)((Var.DoubleS->Exponent & 0x7FF) == 0x7FF); } /** @@ -649,8 +649,8 @@ RtlInfiniteDouble(IN DOUBLE Value) */ XTAPI LARGE_INTEGER -RtlMultiplyLargeInteger(IN LARGE_INTEGER Multiplicand, - IN LONG Multiplier) +RTL::Math::MultiplyLargeInteger(IN LARGE_INTEGER Multiplicand, + IN LONG Multiplier) { LARGE_INTEGER LargeInt; @@ -671,7 +671,7 @@ RtlMultiplyLargeInteger(IN LARGE_INTEGER Multiplicand, */ XTCDECL BOOLEAN -RtlNanDouble(IN DOUBLE Value) +RTL::Math::NanDouble(IN DOUBLE Value) { /* DOUBLE argument in IEEE 754 standard format */ union @@ -690,5 +690,5 @@ RtlNanDouble(IN DOUBLE Value) Var.Double = &Value; /* Return TRUE if it is NaN, or FALSE otherwise */ - return (Var.DoubleS->Exponent == 0x7FF && (Var.DoubleS->MantissaHigh != 0 || Var.DoubleS->MantissaLow != 0)); + return (BOOLEAN)(Var.DoubleS->Exponent == 0x7FF && (Var.DoubleS->MantissaHigh != 0 || Var.DoubleS->MantissaLow != 0)); } diff --git a/xtoskrnl/rtl/memory.c b/xtoskrnl/rtl/memory.cc similarity index 82% rename from xtoskrnl/rtl/memory.c rename to xtoskrnl/rtl/memory.cc index 3d59f01..0244e78 100644 --- a/xtoskrnl/rtl/memory.c +++ b/xtoskrnl/rtl/memory.cc @@ -1,12 +1,12 @@ /** * PROJECT: ExectOS * COPYRIGHT: See COPYING.md in the top level directory - * FILE: xtoskrnl/rtl/memory.c + * FILE: xtoskrnl/rtl/memory.cc * DESCRIPTION: Memory related routines * DEVELOPERS: Rafal Kupiec */ -#include +#include /** @@ -27,9 +27,9 @@ */ XTAPI SIZE_T -RtlCompareMemory(IN PCVOID LeftBuffer, - IN PCVOID RightBuffer, - IN SIZE_T Length) +RTL::Memory::CompareMemory(IN PCVOID LeftBuffer, + IN PCVOID RightBuffer, + IN SIZE_T Length) { SIZE_T Bytes = 0; @@ -73,9 +73,9 @@ RtlCompareMemory(IN PCVOID LeftBuffer, */ XTAPI VOID -RtlCopyMemory(OUT PVOID Destination, - IN PCVOID Source, - IN SIZE_T Length) +RTL::Memory::CopyMemory(OUT PVOID Destination, + IN PCVOID Source, + IN SIZE_T Length) { PCHAR DestinationBytes = (PCHAR)Destination; PCCHAR SourceBytes = (PCHAR)Source; @@ -106,9 +106,9 @@ RtlCopyMemory(OUT PVOID Destination, */ XTAPI VOID -RtlMoveMemory(OUT PVOID Destination, - IN PCVOID Source, - IN SIZE_T Length) +RTL::Memory::MoveMemory(OUT PVOID Destination, + IN PCVOID Source, + IN SIZE_T Length) { PCHAR DestinationBytes = (PCHAR)Destination; PCHAR SourceBytes = (PCHAR)Source; @@ -154,11 +154,11 @@ RtlMoveMemory(OUT PVOID Destination, */ XTAPI BOOLEAN -RtlSameMemory(IN PCVOID LeftBuffer, - IN PCVOID RightBuffer, - IN SIZE_T Length) +RTL::Memory::SameMemory(IN PCVOID LeftBuffer, + IN PCVOID RightBuffer, + IN SIZE_T Length) { - return (RtlCompareMemory(LeftBuffer, RightBuffer, Length) == Length) ? TRUE : FALSE; + return (CompareMemory(LeftBuffer, RightBuffer, Length) == Length) ? TRUE : FALSE; } /** @@ -179,9 +179,9 @@ RtlSameMemory(IN PCVOID LeftBuffer, */ XTAPI VOID -RtlSetMemory(OUT PVOID Destination, - IN UCHAR Byte, - IN SIZE_T Length) +RTL::Memory::SetMemory(OUT PVOID Destination, + IN UCHAR Byte, + IN SIZE_T Length) { PCHAR DestinationBytes = (PCHAR)Destination; @@ -207,9 +207,9 @@ RtlSetMemory(OUT PVOID Destination, */ XTAPI VOID -RtlZeroMemory(OUT PVOID Destination, - IN SIZE_T Length) +RTL::Memory::ZeroMemory(OUT PVOID Destination, + IN SIZE_T Length) { /* Fill the buffer with zeroes */ - RtlSetMemory(Destination, 0, Length); + SetMemory(Destination, 0, Length); } diff --git a/xtoskrnl/rtl/string.c b/xtoskrnl/rtl/string.cc similarity index 88% rename from xtoskrnl/rtl/string.c rename to xtoskrnl/rtl/string.cc index bec887a..45ad2ed 100644 --- a/xtoskrnl/rtl/string.c +++ b/xtoskrnl/rtl/string.cc @@ -1,12 +1,12 @@ /** * PROJECT: ExectOS * COPYRIGHT: See COPYING.md in the top level directory - * FILE: xtoskrnl/rtl/string.c + * FILE: xtoskrnl/rtl/string.cc * DESCRIPTION: String support * DEVELOPERS: Rafal Kupiec */ -#include +#include /** @@ -27,9 +27,9 @@ */ XTAPI SIZE_T -RtlCompareString(IN PCSTR String1, - IN PCSTR String2, - IN SIZE_T Length) +RTL::String::CompareString(IN PCSTR String1, + IN PCSTR String2, + IN SIZE_T Length) { SIZE_T Index; @@ -79,9 +79,9 @@ RtlCompareString(IN PCSTR String1, */ XTAPI SIZE_T -RtlCompareStringInsensitive(IN PCSTR String1, - IN PCSTR String2, - IN SIZE_T Length) +RTL::String::CompareStringInsensitive(IN PCSTR String1, + IN PCSTR String2, + IN SIZE_T Length) { CHAR Character1; CHAR Character2; @@ -146,9 +146,9 @@ RtlCompareStringInsensitive(IN PCSTR String1, */ XTAPI PCHAR -RtlConcatenateString(OUT PCHAR Destination, - IN PCHAR Source, - IN SIZE_T Count) +RTL::String::ConcatenateString(OUT PCHAR Destination, + IN PCHAR Source, + IN SIZE_T Count) { PCHAR DestString = Destination; @@ -205,9 +205,9 @@ RtlConcatenateString(OUT PCHAR Destination, */ XTAPI VOID -RtlCopyString(IN PCHAR Destination, - IN PCSTR Source, - IN ULONG Length) +RTL::String::CopyString(IN PCHAR Destination, + IN PCSTR Source, + IN ULONG Length) { ULONG Index; @@ -244,8 +244,8 @@ RtlCopyString(IN PCHAR Destination, */ XTAPI PCSTR -RtlFindString(IN PCSTR Source, - IN PCSTR Search) +RTL::String::FindString(IN PCSTR Source, + IN PCSTR Search) { PCSTR CurrentSource; PCSTR CurrentSearch; @@ -254,7 +254,7 @@ RtlFindString(IN PCSTR Source, if(!Source || !Search) { /* Invalid input parameters, return NULL */ - return NULL; + return nullptr; } /* Check if search string is empty */ @@ -288,7 +288,7 @@ RtlFindString(IN PCSTR Source, } /* No match found, return NULL */ - return NULL; + return nullptr; } /** @@ -306,8 +306,8 @@ RtlFindString(IN PCSTR Source, */ XTAPI PCSTR -RtlFindStringInsensitive(IN PCSTR Source, - IN PCSTR Search) +RTL::String::FindStringInsensitive(IN PCSTR Source, + IN PCSTR Search) { PCSTR CurrentSource; PCSTR CurrentSearch; @@ -316,7 +316,7 @@ RtlFindStringInsensitive(IN PCSTR Source, if(!Source || !Search) { /* Invalid input parameters, return NULL */ - return NULL; + return nullptr; } /* Check if search string is empty */ @@ -335,7 +335,7 @@ RtlFindStringInsensitive(IN PCSTR Source, /* Check if the substring matches starting at the current position */ while(*CurrentSource != '\0' && *CurrentSearch != '\0' && - RtlToLowerCharacter(*CurrentSource) == RtlToLowerCharacter(*CurrentSearch)) + ToLowerCharacter(*CurrentSource) == ToLowerCharacter(*CurrentSearch)) { /* Go to the next character */ CurrentSource++; @@ -351,7 +351,7 @@ RtlFindStringInsensitive(IN PCSTR Source, } /* No match found, return NULL */ - return NULL; + return nullptr; } /** @@ -369,8 +369,8 @@ RtlFindStringInsensitive(IN PCSTR Source, */ XTAPI VOID -RtlReverseString(IN OUT PCHAR String, - IN ULONG Length) +RTL::String::ReverseString(IN OUT PCHAR String, + IN ULONG Length) { UCHAR TempChar; ULONG Index; @@ -400,8 +400,8 @@ RtlReverseString(IN OUT PCHAR String, */ XTAPI SIZE_T -RtlStringLength(IN PCSTR String, - IN SIZE_T MaxLength) +RTL::String::StringLength(IN PCSTR String, + IN SIZE_T MaxLength) { SIZE_T Length; @@ -445,9 +445,9 @@ RtlStringLength(IN PCSTR String, */ XTAPI SIZE_T -RtlStringToWideString(OUT PWCHAR Destination, - IN PCSTR *Source, - IN SIZE_T Length) +RTL::String::StringToWideString(OUT PWCHAR Destination, + IN PCSTR *Source, + IN SIZE_T Length) { PCSTR LocalSource = *Source; SIZE_T Count = Length; @@ -466,7 +466,7 @@ RtlStringToWideString(OUT PWCHAR Destination, if((*Destination = *LocalSource) == 0) { /* End of string reached */ - LocalSource = NULL; + LocalSource = nullptr; break; } @@ -505,9 +505,9 @@ RtlStringToWideString(OUT PWCHAR Destination, */ XTAPI PCHAR -RtlTokenizeString(IN PCHAR String, - IN PCSTR Delimiter, - IN OUT PCHAR *SavePtr) +RTL::String::TokenizeString(IN PCHAR String, + IN PCSTR Delimiter, + IN OUT PCHAR *SavePtr) { PCHAR Span, Token; CHAR Char, SpanChar; @@ -516,15 +516,15 @@ RtlTokenizeString(IN PCHAR String, if(String == NULL && (String = *SavePtr) == NULL) { /* Empty string given */ - return NULL; + return nullptr; } /* Check non-delimiter characters */ Char = *String++; if(Char == '\0') { - *SavePtr = NULL; - return NULL; + *SavePtr = nullptr; + return nullptr; } Token = String - 1; @@ -542,7 +542,7 @@ RtlTokenizeString(IN PCHAR String, if(Char == '\0') { /* End of string reached, no more tokens */ - String = NULL; + String = nullptr; } else { @@ -573,7 +573,7 @@ RtlTokenizeString(IN PCHAR String, */ XTAPI CHAR -RtlToLowerCharacter(IN CHAR Character) +RTL::String::ToLowerCharacter(IN CHAR Character) { /* Check if character is uppercase */ if(Character >= 'A' && Character <= 'Z') @@ -598,7 +598,7 @@ RtlToLowerCharacter(IN CHAR Character) */ XTAPI CHAR -RtlToUpperCharacter(IN CHAR Character) +RTL::String::ToUpperCharacter(IN CHAR Character) { /* Check if character is lowercase */ if(Character >= 'a' && Character <= 'z') @@ -623,7 +623,7 @@ RtlToUpperCharacter(IN CHAR Character) */ XTAPI PCHAR -RtlTrimLeftString(IN PCHAR String) +RTL::String::TrimLeftString(IN PCHAR String) { PCHAR Start; @@ -653,12 +653,12 @@ RtlTrimLeftString(IN PCHAR String) */ XTAPI PCHAR -RtlTrimRightString(IN PCHAR String) +RTL::String::TrimRightString(IN PCHAR String) { PCHAR End; /* Find end of the string */ - End = String + RtlStringLength(String, 0); + End = String + StringLength(String, 0); /* Skip all trailing whitespaces */ while((End != String) && (*End == ' ' || *End == '\n' || *End == '\t' || *End == '\r' || *End == '\v' || *End == '\f')) @@ -686,7 +686,7 @@ RtlTrimRightString(IN PCHAR String) */ XTAPI PCHAR -RtlTrimString(IN PCHAR String) +RTL::String::TrimString(IN PCHAR String) { - return RtlTrimLeftString(RtlTrimRightString(String)); + return TrimLeftString(TrimRightString(String)); } diff --git a/xtoskrnl/rtl/widestr.c b/xtoskrnl/rtl/widestr.cc similarity index 87% rename from xtoskrnl/rtl/widestr.c rename to xtoskrnl/rtl/widestr.cc index da5a21b..7051ebc 100644 --- a/xtoskrnl/rtl/widestr.c +++ b/xtoskrnl/rtl/widestr.cc @@ -1,12 +1,12 @@ /** * PROJECT: ExectOS * COPYRIGHT: See COPYING.md in the top level directory - * FILE: xtoskrnl/rtl/widestr.c + * FILE: xtoskrnl/rtl/widestr.cc * DESCRIPTION: Wide string support * DEVELOPERS: Rafal Kupiec */ -#include +#include /** @@ -27,9 +27,9 @@ */ XTAPI SIZE_T -RtlCompareWideString(IN PCWSTR String1, - IN PCWSTR String2, - IN SIZE_T Length) +RTL::WideString::CompareWideString(IN PCWSTR String1, + IN PCWSTR String2, + IN SIZE_T Length) { SIZE_T Index; @@ -79,9 +79,9 @@ RtlCompareWideString(IN PCWSTR String1, */ XTAPI SIZE_T -RtlCompareWideStringInsensitive(IN PCWSTR String1, - IN PCWSTR String2, - IN SIZE_T Length) +RTL::WideString::CompareWideStringInsensitive(IN PCWSTR String1, + IN PCWSTR String2, + IN SIZE_T Length) { WCHAR Character1; WCHAR Character2; @@ -146,9 +146,9 @@ RtlCompareWideStringInsensitive(IN PCWSTR String1, */ XTAPI PWCHAR -RtlConcatenateWideString(OUT PWCHAR Destination, - IN PWCHAR Source, - IN SIZE_T Count) +RTL::WideString::ConcatenateWideString(OUT PWCHAR Destination, + IN PWCHAR Source, + IN SIZE_T Count) { PWCHAR DestString = Destination; @@ -203,12 +203,11 @@ RtlConcatenateWideString(OUT PWCHAR Destination, * * @since XT 1.0 */ - XTAPI VOID -RtlCopyWideString(IN PWCHAR Destination, - IN PCWSTR Source, - IN ULONG Length) +RTL::WideString::CopyWideString(IN PWCHAR Destination, + IN PCWSTR Source, + IN ULONG Length) { ULONG Index; @@ -245,8 +244,8 @@ RtlCopyWideString(IN PWCHAR Destination, */ XTAPI PCWSTR -RtlFindWideString(IN PCWSTR Source, - IN PCWSTR Search) +RTL::WideString::FindWideString(IN PCWSTR Source, + IN PCWSTR Search) { PCWSTR CurrentSource; PCWSTR CurrentSearch; @@ -255,7 +254,7 @@ RtlFindWideString(IN PCWSTR Source, if(!Source || !Search) { /* Invalid input parameters, return NULL */ - return NULL; + return nullptr; } /* Check if search string is empty */ @@ -289,7 +288,7 @@ RtlFindWideString(IN PCWSTR Source, } /* No match found, return NULL */ - return NULL; + return nullptr; } /** @@ -307,8 +306,8 @@ RtlFindWideString(IN PCWSTR Source, */ XTAPI PCWSTR -RtlFindWideStringInsensitive(IN PCWSTR Source, - IN PCWSTR Search) +RTL::WideString::FindWideStringInsensitive(IN PCWSTR Source, + IN PCWSTR Search) { PCWSTR CurrentSource; PCWSTR CurrentSearch; @@ -317,7 +316,7 @@ RtlFindWideStringInsensitive(IN PCWSTR Source, if(!Source || !Search) { /* Invalid input parameters, return NULL */ - return NULL; + return nullptr; } /* Check if search string is empty */ @@ -336,7 +335,7 @@ RtlFindWideStringInsensitive(IN PCWSTR Source, /* Check if the substring matches starting at the current position */ while(*CurrentSource != L'\0' && *CurrentSearch != L'\0' && - RtlToLowerWideCharacter(*CurrentSource) == RtlToLowerWideCharacter(*CurrentSearch)) + ToLowerWideCharacter(*CurrentSource) == ToLowerWideCharacter(*CurrentSearch)) { /* Go to the next character */ CurrentSource++; @@ -352,359 +351,7 @@ RtlFindWideStringInsensitive(IN PCWSTR Source, } /* No match found, return NULL */ - return NULL; -} - -/** - * Formats a wide string according to the given printf-alike format string. - * - * @param Context - * Supplies a pointer to the print context structure. - * - * @param Format - * Supplies a pointer to the printf-alike format string. - * - * @param ArgumentList - * Supplies a list of arguments to the format string. - * - * @return This routine returns a status code. - * - * @since XT 1.0 - */ -XTAPI -XTSTATUS -RtlFormatWideString(IN PRTL_PRINT_CONTEXT Context, - IN PCWSTR Format, - IN VA_LIST ArgumentList) -{ - VA_LIST LocalArgumentList; - XTSTATUS Status; - ULONG Index; - - /* Make sure, that we have valid context and write routine */ - if(Context == NULL || Context->WriteWideCharacter == NULL) - { - /* Invalid context or write routine not set */ - return FALSE; - } - - /* Check format string pointer */ - if(Format == NULL) - { - /* Write null string */ - Format = L"(null)"; - } - - /* Make a copy of the argument list */ - VA_COPY(LocalArgumentList, ArgumentList); - - /* Iterate through format string */ - Index = 0; - while(Format[Index] != L'\0') - { - /* Look for format specifier */ - if(Format[Index] == L'%') - { - /* Handle format along with arguments */ - Status = RtlpFormatWideStringArgumentSpecifier(Context, Format, &LocalArgumentList, &Index); - } - else - { - /* Write wide character and increase string index */ - Status = RtlpWriteWideCharacter(Context, Format[Index]); - Index++; - } - - /* Make sure character written successfully */ - if(Status != STATUS_SUCCESS) - { - /* Return status code */ - return Status; - } - } - - /* Clean up the argument list */ - VA_END(LocalArgumentList); - - /* Return success */ - return STATUS_SUCCESS; -} - -/** - * Reverses a characters order in a wide string. It modifies the original, input variable. - * - * @param String - * Supplies a pointer to the wide string to reverse. - * - * @param Length - * Supplies the length of the wide string to reverse. - * - * @return This routine does not return any value. - * - * @since XT 1.0 - */ -XTAPI -VOID -RtlReverseWideString(IN OUT PWCHAR String, - IN ULONG Length) -{ - WCHAR TempChar; - ULONG Index; - - /* Iterate through the string */ - for(Index = 0; Index < (Length / 2); Index++) - { - /* Swap characters */ - TempChar = String[Index]; - String[Index] = String[Length - Index - 1]; - String[Length - Index - 1] = TempChar; - } -} - -/** - * 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 - */ -XTAPI -PWCHAR -RtlTokenizeWideString(IN PWCHAR String, - IN PCWSTR 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 = (PWCHAR)Delimiter; - do - { - /* Check if delimiter found */ - if((SpanChar = *Span++) == Char) - { - /* Check if end of string reached */ - if(Char == L'\0') - { - /* End of string reached, no more tokens */ - String = NULL; - } - else - { - /* Terminate token */ - String[-1] = L'\0'; - } - - /* Store pointer to the next token */ - *SavePtr = String; - - /* Return token */ - return Token; - } - } - while(SpanChar != L'\0'); - } -} - -/** - * Converts a wide character to lowercase. - * - * @param Character - * Wide character to be converted. - * - * @return Converted wide character or original character if it was not uppercase. - * - * @since XT 1.0 - */ -XTAPI -WCHAR -RtlToLowerWideCharacter(IN WCHAR Character) -{ - /* Check if wide character is uppercase */ - if(Character >= L'A' && Character <= L'Z') - { - /* Convert wide character to lowercase */ - return (WCHAR)(Character + (L'a' - L'A')); - } - - /* Return original wide character */ - return Character; -} - -/** - * Converts a wide character to uppercase. - * - * @param Character - * Wide character to be converted. - * - * @return Converted wide character or original character if it was not lowercase. - * - * @since XT 1.0 - */ -XTAPI -WCHAR -RtlToUpperWideCharacter(IN WCHAR Character) -{ - /* Check if wide character is lowercase */ - if(Character >= L'a' && Character <= L'z') - { - /* Convert wide character to uppercase */ - return (WCHAR)(Character - (L'a' - L'A')); - } - - /* Return original wide character */ - return Character; -} - -/** - * Removes certain characters from a beginning of the wide string. - * - * @param String - * Pointer to the null-terminated wide string to be trimmed. - * - * @return This routine returns a pointer to the left-trimmed wide string. - * - * @since XT 1.0 - */ -XTAPI -PWCHAR -RtlTrimLeftWideString(IN PWCHAR String) -{ - PWCHAR Start; - - /* Initialize pointer */ - Start = String; - - /* Skip all leading whitespaces */ - while(*Start == L' ' || *Start == L'\n' || *Start == L'\t' || *Start == L'\r' || *Start == L'\v' || *Start == L'\f') - { - /* Advance to the next character */ - Start++; - } - - /* Return left-trimmed string */ - return Start; -} - -/** - * Removes certain characters from the end of the wide string. - * - * @param String - * Pointer to the null-terminated wide string to be trimmed. - * - * @return This routine returns a pointer to the right-trimmed wide string. - * - * @since XT 1.0 - */ -XTAPI -PWCHAR -RtlTrimRightWideString(IN PWCHAR String) -{ - PWCHAR End; - - /* Find end of the string */ - End = String + RtlWideStringLength(String, 0); - - /* Skip all trailing whitespaces */ - while((End != String) && (*End == L' ' || *End == L'\n' || *End == L'\t' || *End == L'\r' || *End == L'\v' || *End == L'\f')) - { - /* Move to the previous character */ - End--; - } - - /* Terminate the string */ - *End = 0; - - /* Return right-trimmed string */ - return String; -} - -/** - * Removes certain characters from the beginning and the end of the wide string. - * - * @param String - * Pointer to the null-terminated wide string to be trimmed. - * - * @return This routine returns a pointer to the trimmed wide string. - * - * @since XT 1.0 - */ -XTAPI -PWCHAR -RtlTrimWideString(IN PWCHAR String) -{ - return RtlTrimLeftWideString(RtlTrimRightWideString(String)); -} - -/** - * Calculates the length of a given wide string. - * - * @param String - * Pointer to the null-terminated wide string to be examined. - * - * @param MaxLength - * Maximum number of wide characters to examine. If no limit set, it examines whole string. - * - * @return The length of the null-terminated wide string. - * - * @since: XT 1.0 - */ -XTAPI -SIZE_T -RtlWideStringLength(IN PCWSTR String, - IN SIZE_T MaxLength) -{ - SIZE_T Length; - - /* Check if NULL pointer passed */ - if(String == NULL) - { - return 0; - } - - /* Iterate through the wide string */ - for(Length = 0; ; Length++) - { - - /* Check if NULL found or max length limit reached */ - if((Length != 0 && Length == MaxLength) || !String[Length]) - { - /* Finish examination */ - break; - } - } - - /* Return wide string length */ - return Length; + return nullptr; } /** @@ -728,10 +375,10 @@ RtlWideStringLength(IN PCWSTR String, */ XTAPI XTSTATUS -RtlpFormatWideStringArgumentSpecifier(IN PRTL_PRINT_CONTEXT Context, - IN PCWSTR Format, - IN PVA_LIST ArgumentList, - IN OUT PULONG Index) +RTL::WideString::FormatArgumentSpecifier(IN PRTL_PRINT_CONTEXT Context, + IN PCWSTR Format, + IN PVA_LIST ArgumentList, + IN OUT PULONG Index) { RTL_PRINT_FORMAT_PROPERTIES FormatProperties; PUNICODE_STRING UnicodeStrArg; @@ -742,7 +389,7 @@ RtlpFormatWideStringArgumentSpecifier(IN PRTL_PRINT_CONTEXT Context, LARGE_DOUBLE FloatArg; PCWSTR FormatIndex; ULONG ArgPosition; - PWCHAR WideStrArg; + PCWSTR WideStrArg; ULONGLONG IntArg; XTSTATUS Status; PGUID GuidArg; @@ -754,7 +401,7 @@ RtlpFormatWideStringArgumentSpecifier(IN PRTL_PRINT_CONTEXT Context, ArgPosition = 0; /* Initialize format properties */ - RtlZeroMemory(&FormatProperties, sizeof(RTL_PRINT_FORMAT_PROPERTIES)); + RTL::Memory::ZeroMemory(&FormatProperties, sizeof(RTL_PRINT_FORMAT_PROPERTIES)); FormatProperties.IntegerSize = sizeof(INT); FormatProperties.Precision = -1; @@ -766,7 +413,7 @@ RtlpFormatWideStringArgumentSpecifier(IN PRTL_PRINT_CONTEXT Context, if((*FormatIndex >= L'1') && (*FormatIndex <= L'9')) { /* POSIX extension found, read its value */ - SpecifierValue = RtlpGetWideStringSpecifierValue((PWSTR*)&FormatIndex); + SpecifierValue = GetSpecifierValue((PWSTR*)&FormatIndex); /* Make sure parameter field ends with '$' character */ if(*FormatIndex == L'$') @@ -852,7 +499,7 @@ RtlpFormatWideStringArgumentSpecifier(IN PRTL_PRINT_CONTEXT Context, else if((*FormatIndex >= L'1') && (*FormatIndex <= L'9')) { /* Read a numeric width value */ - FormatProperties.FieldWidth = RtlpGetWideStringSpecifierValue((PWSTR*)&FormatIndex); + FormatProperties.FieldWidth = GetSpecifierValue((PWSTR*)&FormatIndex); } /* Check if field width is set to negative value */ @@ -879,7 +526,7 @@ RtlpFormatWideStringArgumentSpecifier(IN PRTL_PRINT_CONTEXT Context, else if((*FormatIndex >= L'0') && (*FormatIndex <= L'9')) { /* Read a numeric precision value */ - FormatProperties.Precision = RtlpGetWideStringSpecifierValue((PWSTR*)&FormatIndex); + FormatProperties.Precision = GetSpecifierValue((PWSTR*)&FormatIndex); } else { @@ -1000,156 +647,157 @@ RtlpFormatWideStringArgumentSpecifier(IN PRTL_PRINT_CONTEXT Context, { case L'a': /* Double argument as hexadecimal number (lowercase) */ - FormatProperties.VariableType = Float; + FormatProperties.VariableType = TypeFloat; FormatProperties.Flags |= PFL_SCI_FORMAT; FormatProperties.Radix = 16; break; case L'A': /* Double argument as hexadecimal number (uppercase) */ - FormatProperties.VariableType = Float; + FormatProperties.VariableType = TypeFloat; FormatProperties.Flags |= PFL_SCI_FORMAT | PFL_UPPERCASE; FormatProperties.Radix = 16; break; case L'b': /* XTOS extension: Boolean argument (lowercase) */ - FormatProperties.VariableType = Boolean; + FormatProperties.VariableType = TypeBoolean; break; case L'B': /* XTOS extension: Boolean argument (uppercase) */ - FormatProperties.VariableType = Boolean; + FormatProperties.VariableType = TypeBoolean; FormatProperties.Flags |= PFL_UPPERCASE; break; case L'c': /* Character argument */ - FormatProperties.VariableType = Char; + FormatProperties.VariableType = TypeChar; break; case L'C': /* Wide character argument */ - FormatProperties.VariableType = WideChar; + FormatProperties.VariableType = TypeWideChar; break; case L'd': case L'i': /* Signed integer argument as decimal number */ - FormatProperties.VariableType = Integer; + FormatProperties.VariableType = TypeInteger; FormatProperties.Flags &= ~PFL_UNSIGNED; FormatProperties.Radix = 10; break; case L'e': /* Double argument in scientific notation (lowercase) */ - FormatProperties.VariableType = Float; + FormatProperties.VariableType = TypeFloat; FormatProperties.Flags |= PFL_SCI_FORMAT; break; case L'E': /* Double argument in scientific notation (uppercase) */ - FormatProperties.VariableType = Float; + FormatProperties.VariableType = TypeFloat; FormatProperties.Flags |= PFL_SCI_FORMAT | PFL_UPPERCASE; break; case L'f': /* Double argument as floating point number (lowercase) */ - FormatProperties.VariableType = Float; + FormatProperties.VariableType = TypeFloat; FormatProperties.Flags |= PFL_FLOAT_FORMAT; break; case L'F': /* Double argument as floating point number (uppercase) */ - FormatProperties.VariableType = Float; + FormatProperties.VariableType = TypeFloat; FormatProperties.Flags |= PFL_FLOAT_FORMAT | PFL_UPPERCASE; break; case L'g': /* Double argument as either floating point number or in scientific notation (lowercase) */ - FormatProperties.VariableType = Float; + FormatProperties.VariableType = TypeFloat; FormatProperties.Flags |= PFL_DIGIT_PRECISION; break; case L'G': /* Double argument as either floating point number or in scientific notation (uppercase) */ - FormatProperties.VariableType = Float; + FormatProperties.VariableType = TypeFloat; FormatProperties.Flags |= PFL_DIGIT_PRECISION | PFL_UPPERCASE; break; case L'n': /* Write number of characters written so far into an integer pointer parameter */ - FormatProperties.VariableType = Integer; + FormatProperties.VariableType = TypeInteger; FormatProperties.IntegerSize = sizeof(PVOID); break; case L'o': /* Unsigned integer argument as octal number */ - FormatProperties.VariableType = Integer; + FormatProperties.VariableType = TypeInteger; FormatProperties.Radix = 8; break; case L'p': /* Pointer argument as hexadecimal number (lowercase) */ - FormatProperties.VariableType = Integer; + FormatProperties.VariableType = TypeInteger; FormatProperties.IntegerSize = sizeof(UINT_PTR); FormatProperties.Flags |= PFL_PRINT_RADIX; FormatProperties.Radix = 16; break; case L'P': /* XTOS extension: Pointer argument as hexadecimal number (uppercase) */ - FormatProperties.VariableType = Integer; + FormatProperties.VariableType = TypeInteger; FormatProperties.IntegerSize = sizeof(UINT_PTR); FormatProperties.Flags |= PFL_PRINT_RADIX | PFL_UPPERCASE; FormatProperties.Radix = 16; break; case L's': /* String argument */ - FormatProperties.VariableType = String; + FormatProperties.VariableType = TypeString; break; case L'S': /* Wide string argument */ - FormatProperties.VariableType = WideString; + FormatProperties.VariableType = TypeWideString; break; case L'u': /* Unsigned integer argument as decimal number */ - FormatProperties.VariableType = Integer; + FormatProperties.VariableType = TypeInteger; FormatProperties.Radix = 10; break; case L'v': /* XTOS extension: UUID/GUID argument (lowercase) */ - FormatProperties.VariableType = Guid; + FormatProperties.VariableType = TypeGuid; break; case L'V': /* XTOS extension: UUID/GUID argument (uppercase) */ - FormatProperties.VariableType = Guid; + FormatProperties.VariableType = TypeGuid; FormatProperties.Flags |= PFL_UPPERCASE; break; case L'x': /* Unsigned integer argument as hexadecimal number (lowercase) */ - FormatProperties.VariableType = Integer; + FormatProperties.VariableType = TypeInteger; FormatProperties.Radix = 16; break; case L'X': /* Unsigned integer argument as hexadecimal number (uppercase) */ - FormatProperties.VariableType = Integer; + FormatProperties.VariableType = TypeInteger; FormatProperties.Flags |= PFL_UPPERCASE; FormatProperties.Radix = 16; break; case L'Z': /* MSVC extension: ANSI/Unicode string argument */ - FormatProperties.VariableType = (FormatProperties.Flags & PFL_WIDE_CHARACTER) ? UnicodeString : AnsiString; + FormatProperties.VariableType = (FormatProperties.Flags & PFL_WIDE_CHARACTER) ? TypeUnicodeString + : TypeAnsiString; break; case L'%': /* Print '%' character */ - FormatProperties.VariableType = Unknown; + FormatProperties.VariableType = TypeUnknown; WideCharArg = L'%'; break; default: /* Unknown format specifier, print '?' character */ - FormatProperties.VariableType = Unknown; + FormatProperties.VariableType = TypeUnknown; WideCharArg = L'?'; break; } /* Finally, write the formatted argument */ - if(FormatProperties.VariableType == Unknown) + if(FormatProperties.VariableType == TypeUnknown) { /* Write defined wide character */ - Status = RtlpWriteWideStringValue(Context, &FormatProperties, &WideCharArg, 1); + Status = WriteValue(Context, &FormatProperties, &WideCharArg, 1); } - if(FormatProperties.VariableType == Boolean) + if(FormatProperties.VariableType == TypeBoolean) { /* Boolean type */ if(ArgPosition != 0) { /* Get argument value from specified argument position */ - IntArg = RtlpGetWideStringArgument(&ArgumentsCopy, ArgPosition, FormatProperties.IntegerSize); + IntArg = GetArgument(&ArgumentsCopy, ArgPosition, FormatProperties.IntegerSize); } else { @@ -1170,15 +818,15 @@ RtlpFormatWideStringArgumentSpecifier(IN PRTL_PRINT_CONTEXT Context, } /* Write formatted boolean string */ - Status = RtlpWriteWideStringValue(Context, &FormatProperties, WideStrArg, RtlWideStringLength(WideStrArg, 0)); + Status = WriteValue(Context, &FormatProperties, WideStrArg, WideStringLength(WideStrArg, 0)); } - else if(FormatProperties.VariableType == Guid) + else if(FormatProperties.VariableType == TypeGuid) { /* GUID type */ if(ArgPosition != 0) { /* Get argument value from specified argument position */ - IntArg = RtlpGetWideStringArgument(&ArgumentsCopy, ArgPosition, sizeof(PGUID)); + IntArg = GetArgument(&ArgumentsCopy, ArgPosition, sizeof(PGUID)); GuidArg = (PGUID)(UINT_PTR)IntArg; } else @@ -1202,19 +850,19 @@ RtlpFormatWideStringArgumentSpecifier(IN PRTL_PRINT_CONTEXT Context, WideStrArg = L"%08x-%04x-%04x-%02x%02x-%02x%02x%02x%02x%02x%02x"; } /* Write formatted GUID string */ - Status = RtlpWriteWideStringCustomValue(Context, WideStrArg, GuidArg->Data1, GuidArg->Data2, GuidArg->Data3, - GuidArg->Data4[0], GuidArg->Data4[1], GuidArg->Data4[2], - GuidArg->Data4[3], GuidArg->Data4[4], GuidArg->Data4[5], - GuidArg->Data4[6], GuidArg->Data4[7]); + Status = WriteCustomValue(Context, WideStrArg, GuidArg->Data1, GuidArg->Data2, GuidArg->Data3, + GuidArg->Data4[0], GuidArg->Data4[1], GuidArg->Data4[2], + GuidArg->Data4[3], GuidArg->Data4[4], GuidArg->Data4[5], + GuidArg->Data4[6], GuidArg->Data4[7]); } } - else if(FormatProperties.VariableType == Char) + else if(FormatProperties.VariableType == TypeChar) { /* Character type */ if(ArgPosition != 0) { /* Get argument value from specified argument position */ - CharArg = (UCHAR)RtlpGetWideStringArgument(&ArgumentsCopy, ArgPosition, sizeof(UCHAR)); + CharArg = (UCHAR)GetArgument(&ArgumentsCopy, ArgPosition, sizeof(UCHAR)); } else { @@ -1223,15 +871,15 @@ RtlpFormatWideStringArgumentSpecifier(IN PRTL_PRINT_CONTEXT Context, } /* Write formatted character */ - Status = RtlpWriteWideStringStringValue(Context, &FormatProperties, &CharArg, 1); + Status = WriteStringValue(Context, &FormatProperties, &CharArg, 1); } - else if(FormatProperties.VariableType == WideChar) + else if(FormatProperties.VariableType == TypeWideChar) { /* Wide character type */ if(ArgPosition != 0) { /* Get argument value from specified argument position */ - WideCharArg = (WCHAR)RtlpGetWideStringArgument(&ArgumentsCopy, ArgPosition, sizeof(WCHAR)); + WideCharArg = (WCHAR)GetArgument(&ArgumentsCopy, ArgPosition, sizeof(WCHAR)); } else { @@ -1240,15 +888,15 @@ RtlpFormatWideStringArgumentSpecifier(IN PRTL_PRINT_CONTEXT Context, } /* Write formatted wide character */ - Status = RtlpWriteWideStringValue(Context, &FormatProperties, &WideCharArg, 1); + Status = WriteValue(Context, &FormatProperties, &WideCharArg, 1); } - else if(FormatProperties.VariableType == Float) + else if(FormatProperties.VariableType == TypeFloat) { /* Float/Double type */ if(ArgPosition != 0) { /* Get argument value from specified argument position */ - FloatArg.QuadPart = RtlpGetWideStringArgument(&ArgumentsCopy, ArgPosition, sizeof(ULONGLONG)); + FloatArg.QuadPart = GetArgument(&ArgumentsCopy, ArgPosition, sizeof(ULONGLONG)); } else { @@ -1264,15 +912,15 @@ RtlpFormatWideStringArgumentSpecifier(IN PRTL_PRINT_CONTEXT Context, } /* Write formatted double value */ - Status = RtlpWriteWideStringDoubleValue(Context, &FormatProperties, FloatArg.DoublePart); + Status = WriteDoubleValue(Context, &FormatProperties, FloatArg.DoublePart); } - else if(FormatProperties.VariableType == Integer) + else if(FormatProperties.VariableType == TypeInteger) { /* Integer type */ if(ArgPosition != 0) { /* Get argument value from specified argument position */ - IntArg = RtlpGetWideStringArgument(&ArgumentsCopy, ArgPosition, FormatProperties.IntegerSize); + IntArg = GetArgument(&ArgumentsCopy, ArgPosition, FormatProperties.IntegerSize); /* Convert to required integer size */ switch(FormatProperties.IntegerSize) @@ -1328,16 +976,16 @@ RtlpFormatWideStringArgumentSpecifier(IN PRTL_PRINT_CONTEXT Context, else { /* Write formatted integer value */ - Status = RtlpWriteWideStringIntegerValue(Context, &FormatProperties, IntArg); + Status = WriteIntegerValue(Context, &FormatProperties, IntArg); } } - else if(FormatProperties.VariableType == String) + else if(FormatProperties.VariableType == TypeString) { /* String type */ if(ArgPosition != 0) { /* Get argument value from specified argument position */ - IntArg = RtlpGetWideStringArgument(&ArgumentsCopy, ArgPosition, sizeof(PCHAR)); + IntArg = GetArgument(&ArgumentsCopy, ArgPosition, sizeof(PCHAR)); StrArg = (PCHAR)(UINT_PTR)IntArg; } else @@ -1347,16 +995,16 @@ RtlpFormatWideStringArgumentSpecifier(IN PRTL_PRINT_CONTEXT Context, } /* Write formatted string value */ - Status = RtlpWriteWideStringStringValue(Context, &FormatProperties, StrArg, RtlStringLength(StrArg, 0)); + Status = WriteStringValue(Context, &FormatProperties, StrArg, RTL::String::StringLength(StrArg, 0)); } - else if(FormatProperties.VariableType == WideString) + else if(FormatProperties.VariableType == TypeWideString) { /* Wide string type */ if(ArgPosition != 0) { /* Get argument value from specified argument position */ - IntArg = RtlpGetWideStringArgument(&ArgumentsCopy, ArgPosition, sizeof(PWCHAR)); - WideStrArg = (PWCHAR)(UINT_PTR)IntArg; + IntArg = GetArgument(&ArgumentsCopy, ArgPosition, sizeof(PWCHAR)); + WideStrArg = (PCWSTR)(UINT_PTR)IntArg; } else { @@ -1365,15 +1013,15 @@ RtlpFormatWideStringArgumentSpecifier(IN PRTL_PRINT_CONTEXT Context, } /* Write formatted wide string value */ - Status = RtlpWriteWideStringValue(Context, &FormatProperties, WideStrArg, RtlWideStringLength(WideStrArg, 0)); + Status = WriteValue(Context, &FormatProperties, WideStrArg, RtlWideStringLength(WideStrArg, 0)); } - else if(FormatProperties.VariableType == AnsiString ) + else if(FormatProperties.VariableType == TypeAnsiString ) { /* ANSI string type */ if(ArgPosition != 0) { /* Get argument value from specified argument position */ - IntArg = RtlpGetWideStringArgument(&ArgumentsCopy, ArgPosition, sizeof(PANSI_STRING)); + IntArg = GetArgument(&ArgumentsCopy, ArgPosition, sizeof(PANSI_STRING)); AnsiStrArg = (PANSI_STRING)(UINT_PTR)IntArg; } else @@ -1386,16 +1034,16 @@ RtlpFormatWideStringArgumentSpecifier(IN PRTL_PRINT_CONTEXT Context, if(AnsiStrArg != NULL) { /* Write formatted ANSI string value */ - Status = RtlpWriteWideStringStringValue(Context, &FormatProperties, AnsiStrArg->Buffer, AnsiStrArg->Length); + Status = WriteStringValue(Context, &FormatProperties, AnsiStrArg->Buffer, AnsiStrArg->Length); } } - else if(FormatProperties.VariableType == UnicodeString) + else if(FormatProperties.VariableType == TypeUnicodeString) { /* Unicode string type */ if(ArgPosition != 0) { /* Get argument value from specified argument position */ - IntArg = RtlpGetWideStringArgument(&ArgumentsCopy, ArgPosition, sizeof(PUNICODE_STRING)); + IntArg = GetArgument(&ArgumentsCopy, ArgPosition, sizeof(PUNICODE_STRING)); UnicodeStrArg = (PUNICODE_STRING)(UINT_PTR)IntArg; } else @@ -1408,7 +1056,7 @@ RtlpFormatWideStringArgumentSpecifier(IN PRTL_PRINT_CONTEXT Context, if(UnicodeStrArg != NULL) { /* Write formatted UNICODE string value */ - Status = RtlpWriteWideStringValue(Context, &FormatProperties, UnicodeStrArg->Buffer, UnicodeStrArg->Length); + Status = WriteValue(Context, &FormatProperties, UnicodeStrArg->Buffer, UnicodeStrArg->Length); } } @@ -1422,6 +1070,81 @@ RtlpFormatWideStringArgumentSpecifier(IN PRTL_PRINT_CONTEXT Context, return Status; } +/** + * Formats a wide string according to the given printf-alike format string. + * + * @param Context + * Supplies a pointer to the print context structure. + * + * @param Format + * Supplies a pointer to the printf-alike format string. + * + * @param ArgumentList + * Supplies a list of arguments to the format string. + * + * @return This routine returns a status code. + * + * @since XT 1.0 + */ +XTAPI +XTSTATUS +RTL::WideString::FormatWideString(IN PRTL_PRINT_CONTEXT Context, + IN PCWSTR Format, + IN VA_LIST ArgumentList) +{ + VA_LIST LocalArgumentList; + XTSTATUS Status; + ULONG Index; + + /* Make sure, that we have valid context and write routine */ + if(Context == NULL || Context->WriteWideCharacter == NULL) + { + /* Invalid context or write routine not set */ + return FALSE; + } + + /* Check format string pointer */ + if(Format == NULL) + { + /* Write null string */ + Format = L"(null)"; + } + + /* Make a copy of the argument list */ + VA_COPY(LocalArgumentList, ArgumentList); + + /* Iterate through format string */ + Index = 0; + while(Format[Index] != L'\0') + { + /* Look for format specifier */ + if(Format[Index] == L'%') + { + /* Handle format along with arguments */ + Status = FormatArgumentSpecifier(Context, Format, &LocalArgumentList, &Index); + } + else + { + /* Write wide character and increase string index */ + Status = WriteWideCharacter(Context, Format[Index]); + Index++; + } + + /* Make sure character written successfully */ + if(Status != STATUS_SUCCESS) + { + /* Return status code */ + return Status; + } + } + + /* Clean up the argument list */ + VA_END(LocalArgumentList); + + /* Return success */ + return STATUS_SUCCESS; +} + /** * Gets the positional argument by scanning the argument list. * @@ -1436,9 +1159,9 @@ RtlpFormatWideStringArgumentSpecifier(IN PRTL_PRINT_CONTEXT Context, */ XTAPI ULONGLONG -RtlpGetWideStringArgument(IN PVA_LIST ArgumentList, - IN ULONG ArgumentNumber, - IN LONG ArgumentSize) +RTL::WideString::GetArgument(IN PVA_LIST ArgumentList, + IN ULONG ArgumentNumber, + IN LONG ArgumentSize) { VA_LIST ArgumentsCopy; ULONGLONG Value; @@ -1494,7 +1217,7 @@ RtlpGetWideStringArgument(IN PVA_LIST ArgumentList, */ XTAPI ULONGLONG -RtlpGetWideStringSpecifierValue(IN PWCHAR *Format) +RTL::WideString::GetSpecifierValue(IN PWCHAR *Format) { ULONG Count; PWCHAR Fmt; @@ -1523,6 +1246,284 @@ RtlpGetWideStringSpecifierValue(IN PWCHAR *Format) return 0; } +/** + * Reverses a characters order in a wide string. It modifies the original, input variable. + * + * @param String + * Supplies a pointer to the wide string to reverse. + * + * @param Length + * Supplies the length of the wide string to reverse. + * + * @return This routine does not return any value. + * + * @since XT 1.0 + */ +XTAPI +VOID +RTL::WideString::ReverseWideString(IN OUT PWCHAR String, + IN ULONG Length) +{ + WCHAR TempChar; + ULONG Index; + + /* Iterate through the string */ + for(Index = 0; Index < (Length / 2); Index++) + { + /* Swap characters */ + TempChar = String[Index]; + String[Index] = String[Length - Index - 1]; + String[Length - Index - 1] = TempChar; + } +} + +/** + * 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 + */ +XTAPI +PWCHAR +RTL::WideString::TokenizeWideString(IN PWCHAR String, + IN PCWSTR 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 nullptr; + } + + /* Check non-delimiter characters */ + Char = *String++; + if(Char == L'\0') + { + *SavePtr = nullptr; + return nullptr; + } + Token = String - 1; + + /* Scan token for delimiters */ + for(;;) + { + Char = *String++; + Span = (PWCHAR)Delimiter; + do + { + /* Check if delimiter found */ + if((SpanChar = *Span++) == Char) + { + /* Check if end of string reached */ + if(Char == L'\0') + { + /* End of string reached, no more tokens */ + String = nullptr; + } + else + { + /* Terminate token */ + String[-1] = L'\0'; + } + + /* Store pointer to the next token */ + *SavePtr = String; + + /* Return token */ + return Token; + } + } + while(SpanChar != L'\0'); + } +} + +/** + * Converts a wide character to lowercase. + * + * @param Character + * Wide character to be converted. + * + * @return Converted wide character or original character if it was not uppercase. + * + * @since XT 1.0 + */ +XTAPI +WCHAR +RTL::WideString::ToLowerWideCharacter(IN WCHAR Character) +{ + /* Check if wide character is uppercase */ + if(Character >= L'A' && Character <= L'Z') + { + /* Convert wide character to lowercase */ + return (WCHAR)(Character + (L'a' - L'A')); + } + + /* Return original wide character */ + return Character; +} + +/** + * Converts a wide character to uppercase. + * + * @param Character + * Wide character to be converted. + * + * @return Converted wide character or original character if it was not lowercase. + * + * @since XT 1.0 + */ +XTAPI +WCHAR +RTL::WideString::ToUpperWideCharacter(IN WCHAR Character) +{ + /* Check if wide character is lowercase */ + if(Character >= L'a' && Character <= L'z') + { + /* Convert wide character to uppercase */ + return (WCHAR)(Character - (L'a' - L'A')); + } + + /* Return original wide character */ + return Character; +} + +/** + * Removes certain characters from a beginning of the wide string. + * + * @param String + * Pointer to the null-terminated wide string to be trimmed. + * + * @return This routine returns a pointer to the left-trimmed wide string. + * + * @since XT 1.0 + */ +XTAPI +PWCHAR +RTL::WideString::TrimLeftWideString(IN PWCHAR String) +{ + PWCHAR Start; + + /* Initialize pointer */ + Start = String; + + /* Skip all leading whitespaces */ + while(*Start == L' ' || *Start == L'\n' || *Start == L'\t' || *Start == L'\r' || *Start == L'\v' || *Start == L'\f') + { + /* Advance to the next character */ + Start++; + } + + /* Return left-trimmed string */ + return Start; +} + +/** + * Removes certain characters from the end of the wide string. + * + * @param String + * Pointer to the null-terminated wide string to be trimmed. + * + * @return This routine returns a pointer to the right-trimmed wide string. + * + * @since XT 1.0 + */ +XTAPI +PWCHAR +RTL::WideString::TrimRightWideString(IN PWCHAR String) +{ + PWCHAR End; + + /* Find end of the string */ + End = String + RtlWideStringLength(String, 0); + + /* Skip all trailing whitespaces */ + while((End != String) && (*End == L' ' || *End == L'\n' || *End == L'\t' || + *End == L'\r' || *End == L'\v' || *End == L'\f')) + { + /* Move to the previous character */ + End--; + } + + /* Terminate the string */ + *End = 0; + + /* Return right-trimmed string */ + return String; +} + +/** + * Removes certain characters from the beginning and the end of the wide string. + * + * @param String + * Pointer to the null-terminated wide string to be trimmed. + * + * @return This routine returns a pointer to the trimmed wide string. + * + * @since XT 1.0 + */ +XTAPI +PWCHAR +RTL::WideString::TrimWideString(IN PWCHAR String) +{ + return RtlTrimLeftWideString(RtlTrimRightWideString(String)); +} + +/** + * Calculates the length of a given wide string. + * + * @param String + * Pointer to the null-terminated wide string to be examined. + * + * @param MaxLength + * Maximum number of wide characters to examine. If no limit set, it examines whole string. + * + * @return The length of the null-terminated wide string. + * + * @since: XT 1.0 + */ +XTAPI +SIZE_T +RTL::WideString::WideStringLength(IN PCWSTR String, + IN SIZE_T MaxLength) +{ + SIZE_T Length; + + /* Check if NULL pointer passed */ + if(String == NULL) + { + return 0; + } + + /* Iterate through the wide string */ + for(Length = 0; ; Length++) + { + + /* Check if NULL found or max length limit reached */ + if((Length != 0 && Length == MaxLength) || !String[Length]) + { + /* Finish examination */ + break; + } + } + + /* Return wide string length */ + return Length; +} + /** * Writes a wide character to the destination provided by the print context. * @@ -1538,8 +1539,8 @@ RtlpGetWideStringSpecifierValue(IN PWCHAR *Format) */ XTAPI XTSTATUS -RtlpWriteWideCharacter(IN PRTL_PRINT_CONTEXT Context, - IN WCHAR Character) +RTL::WideString::WriteWideCharacter(IN PRTL_PRINT_CONTEXT Context, + IN WCHAR Character) { XTSTATUS Status; @@ -1569,9 +1570,9 @@ RtlpWriteWideCharacter(IN PRTL_PRINT_CONTEXT Context, */ XTCDECL XTSTATUS -RtlpWriteWideStringCustomValue(IN PRTL_PRINT_CONTEXT Context, - IN PCWSTR Format, - IN ...) +RTL::WideString::WriteCustomValue(IN PRTL_PRINT_CONTEXT Context, + IN PCWSTR Format, + IN ...) { VA_LIST Arguments; XTSTATUS Status; @@ -1580,7 +1581,7 @@ RtlpWriteWideStringCustomValue(IN PRTL_PRINT_CONTEXT Context, VA_START(Arguments, Format); /* Format and print the string to the desired output */ - Status = RtlFormatWideString(Context, Format, Arguments); + Status = FormatWideString(Context, Format, Arguments); /* Clean up the va_list */ VA_END(Arguments); @@ -1591,9 +1592,9 @@ RtlpWriteWideStringCustomValue(IN PRTL_PRINT_CONTEXT Context, XTAPI XTSTATUS -RtlpWriteWideStringDoubleValue(IN PRTL_PRINT_CONTEXT Context, - IN PRTL_PRINT_FORMAT_PROPERTIES FormatProperties, - IN DOUBLE Value) +RTL::WideString::WriteDoubleValue(IN PRTL_PRINT_CONTEXT Context, + IN PRTL_PRINT_FORMAT_PROPERTIES FormatProperties, + IN DOUBLE Value) { LONG CurrentExponent, DigitCount, Exponent, Precision, PrecisionIndex, SignificantDigits; WCHAR Character, Digit, ExponentCharacter, SignCharacter; @@ -1601,7 +1602,7 @@ RtlpWriteWideStringDoubleValue(IN PRTL_PRINT_CONTEXT Context, WCHAR Buffer[MAX_DOUBLE_STRING_SIZE]; BOOLEAN NegativeValue, WriteExponent; DOUBLE RoundingAmount, TenPower; - PWCHAR NonNumberString; + PCWSTR NonNumberString; LARGE_DOUBLE Parts; XTSTATUS Status; @@ -1627,10 +1628,10 @@ RtlpWriteWideStringDoubleValue(IN PRTL_PRINT_CONTEXT Context, } /* Determine whether the value is infinite or nan */ - if(RtlInfiniteDouble(Value)) + if(RTL::Math::InfiniteDouble(Value)) { /* Check if the value is nan */ - if(RtlNanDouble(Value)) + if(RTL::Math::NanDouble(Value)) { /* Set non-number string depending on the selection of upper or lowercase */ if(FormatProperties->Flags & PFL_UPPERCASE) @@ -1683,15 +1684,15 @@ RtlpWriteWideStringDoubleValue(IN PRTL_PRINT_CONTEXT Context, } /* Copy string to buffer and write it to wide string context */ - RtlCopyWideString(Buffer + Index, NonNumberString, sizeof(Buffer) - Index); - return RtlpWriteWideStringValue(Context, FormatProperties, Buffer, RtlWideStringLength(Buffer, 0)); + CopyWideString(Buffer + Index, NonNumberString, sizeof(Buffer) - Index); + return WriteValue(Context, FormatProperties, Buffer, WideStringLength(Buffer, 0)); } /* Check whether we need to handle hexadecimal format */ if(FormatProperties->Radix == 16) { /* Handle it as hex value */ - return RtlpWriteWideStringHexDoubleValue(Context, FormatProperties, Value); + return WriteHexDoubleValue(Context, FormatProperties, Value); } /* Check if the value is negative */ @@ -1703,11 +1704,11 @@ RtlpWriteWideStringDoubleValue(IN PRTL_PRINT_CONTEXT Context, } /* Calculate the exponent */ - Exponent = RtlGetBaseExponent(Value, &TenPower); + Exponent = RTL::Math::GetBaseExponent(Value, &TenPower); RoundingAmount = 0.5; /* Determine whether or not to write the exponent */ - WriteExponent = (FormatProperties->Flags & PFL_SCI_FORMAT); + WriteExponent = (BOOLEAN)(FormatProperties->Flags & PFL_SCI_FORMAT); if((WriteExponent == FALSE) && !(FormatProperties->Flags & PFL_FLOAT_FORMAT)) { if((Exponent < DOUBLE_SCIENTIFIC_PRECISION) || (Exponent >= Precision)) @@ -1960,7 +1961,7 @@ RtlpWriteWideStringDoubleValue(IN PRTL_PRINT_CONTEXT Context, if(SignCharacter != 0) { /* Write the sign character */ - Status = RtlpWriteWideCharacter(Context, SignCharacter); + Status = WriteWideCharacter(Context, SignCharacter); if(Status != STATUS_SUCCESS) { /* Failed to write the character, return status code */ @@ -1991,7 +1992,7 @@ RtlpWriteWideStringDoubleValue(IN PRTL_PRINT_CONTEXT Context, for(FieldIndex = 0; FieldIndex < FieldCount; FieldIndex++) { /* Write the leading character */ - Status = RtlpWriteWideCharacter(Context, Character); + Status = WriteWideCharacter(Context, Character); if(Status != STATUS_SUCCESS) { /* Failed to write the character, return status code */ @@ -2007,7 +2008,7 @@ RtlpWriteWideStringDoubleValue(IN PRTL_PRINT_CONTEXT Context, if(SignCharacter != 0) { /* Write the sign character */ - Status = RtlpWriteWideCharacter(Context, SignCharacter); + Status = WriteWideCharacter(Context, SignCharacter); if(Status != STATUS_SUCCESS) { /* Failed to write the character, return status code */ @@ -2033,7 +2034,7 @@ RtlpWriteWideStringDoubleValue(IN PRTL_PRINT_CONTEXT Context, } /* Write the digit */ - Status = RtlpWriteWideCharacter(Context, Digit); + Status = WriteWideCharacter(Context, Digit); if(Status != STATUS_SUCCESS) { /* Failed to write the character, return status code */ @@ -2051,7 +2052,7 @@ RtlpWriteWideStringDoubleValue(IN PRTL_PRINT_CONTEXT Context, if((Precision != 0) || (FormatProperties->Flags & PFL_PRINT_RADIX)) { /* Write the radix character */ - Status = RtlpWriteWideCharacter(Context, L'.'); + Status = WriteWideCharacter(Context, L'.'); if(Status != STATUS_SUCCESS) { /* Failed to write the character, return status code */ @@ -2076,7 +2077,7 @@ RtlpWriteWideStringDoubleValue(IN PRTL_PRINT_CONTEXT Context, } /* Write the digit */ - Status = RtlpWriteWideCharacter(Context, Digit); + Status = WriteWideCharacter(Context, Digit); if(Status != STATUS_SUCCESS) { /* Failed to write the character, return status code */ @@ -2097,7 +2098,7 @@ RtlpWriteWideStringDoubleValue(IN PRTL_PRINT_CONTEXT Context, } /* Write the exponent string */ - Status = RtlpWriteWideStringCustomValue(Context, L"%C%+0.2d", ExponentCharacter, Exponent); + Status = WriteCustomValue(Context, L"%C%+0.2d", ExponentCharacter, Exponent); if(Status != STATUS_SUCCESS) { /* Failed to write the characters, return status code */ @@ -2127,7 +2128,7 @@ RtlpWriteWideStringDoubleValue(IN PRTL_PRINT_CONTEXT Context, } /* Write the digit */ - Status = RtlpWriteWideCharacter(Context, Digit); + Status = WriteWideCharacter(Context, Digit); if(Status != STATUS_SUCCESS) { /* Failed to write the character, return status code */ @@ -2148,7 +2149,7 @@ RtlpWriteWideStringDoubleValue(IN PRTL_PRINT_CONTEXT Context, else { /* Exponent is negative, write '0' */ - Status = RtlpWriteWideCharacter(Context, L'0'); + Status = WriteWideCharacter(Context, L'0'); if(Status != STATUS_SUCCESS) { /* Failed to write the character, return status code */ @@ -2163,7 +2164,7 @@ RtlpWriteWideStringDoubleValue(IN PRTL_PRINT_CONTEXT Context, if((Precision != 0) || (FormatProperties->Flags & PFL_PRINT_RADIX)) { /* Write the radix character */ - Status = RtlpWriteWideCharacter(Context, L'.'); + Status = WriteWideCharacter(Context, L'.'); if(Status != STATUS_SUCCESS) { /* Failed to write the character, return status code */ @@ -2193,7 +2194,7 @@ RtlpWriteWideStringDoubleValue(IN PRTL_PRINT_CONTEXT Context, } /* Write the digit */ - Status = RtlpWriteWideCharacter(Context, Digit); + Status = WriteWideCharacter(Context, Digit); if(Status != STATUS_SUCCESS) { /* Failed to write the character, return status code */ @@ -2209,7 +2210,7 @@ RtlpWriteWideStringDoubleValue(IN PRTL_PRINT_CONTEXT Context, for(FieldIndex = 0; FieldIndex < FieldCount; FieldIndex++) { /* Fill the remaining space with spaces */ - Status = RtlpWriteWideCharacter(Context, L' '); + Status = WriteWideCharacter(Context, L' '); if(Status != STATUS_SUCCESS) { /* Failed to write the character, return status code */ @@ -2239,9 +2240,9 @@ RtlpWriteWideStringDoubleValue(IN PRTL_PRINT_CONTEXT Context, */ XTAPI XTSTATUS -RtlpWriteWideStringHexDoubleValue(IN PRTL_PRINT_CONTEXT Context, - IN PRTL_PRINT_FORMAT_PROPERTIES FormatProperties, - IN DOUBLE Double) +RTL::WideString::WriteHexDoubleValue(IN PRTL_PRINT_CONTEXT Context, + IN PRTL_PRINT_FORMAT_PROPERTIES FormatProperties, + IN DOUBLE Double) { LONG AbsoluteExponent, Exponent, FieldCount, Index, NumberLength; WCHAR Character, Digit, ExponentCharacter, IntegerValue; @@ -2462,7 +2463,7 @@ RtlpWriteWideStringHexDoubleValue(IN PRTL_PRINT_CONTEXT Context, while(PrefixSize--) { /* Write the prefix character */ - Status = RtlpWriteWideCharacter(Context, Prefix[PrefixIndex]); + Status = WriteWideCharacter(Context, Prefix[PrefixIndex]); if(Status != STATUS_SUCCESS) { /* Failed to write character, return error code */ @@ -2483,7 +2484,7 @@ RtlpWriteWideStringHexDoubleValue(IN PRTL_PRINT_CONTEXT Context, while(FieldCount) { /* Write the field character */ - Status = RtlpWriteWideCharacter(Context, Character); + Status = WriteWideCharacter(Context, Character); if(Status != STATUS_SUCCESS) { /* Failed to write character, return error code */ @@ -2499,7 +2500,7 @@ RtlpWriteWideStringHexDoubleValue(IN PRTL_PRINT_CONTEXT Context, for(PrefixIndex = 0; PrefixIndex < PrefixSize; PrefixIndex++) { /* Write the prefix character */ - Status = RtlpWriteWideCharacter(Context, Prefix[PrefixIndex]); + Status = WriteWideCharacter(Context, Prefix[PrefixIndex]); if(Status != STATUS_SUCCESS) { /* Failed to write character, return error code */ @@ -2508,7 +2509,7 @@ RtlpWriteWideStringHexDoubleValue(IN PRTL_PRINT_CONTEXT Context, } /* Write the integer value */ - Status = RtlpWriteWideCharacter(Context, IntegerValue); + Status = WriteWideCharacter(Context, IntegerValue); if(Status != STATUS_SUCCESS) { /* Failed to write character, return error code */ @@ -2519,7 +2520,7 @@ RtlpWriteWideStringHexDoubleValue(IN PRTL_PRINT_CONTEXT Context, if((FormatProperties->Flags & PFL_PRINT_RADIX) || (Precision != 0)) { /* Write the radix character */ - Status = RtlpWriteWideCharacter(Context, L'.'); + Status = WriteWideCharacter(Context, L'.'); if(Status != STATUS_SUCCESS) { /* Failed to write character, return error code */ @@ -2543,7 +2544,7 @@ RtlpWriteWideStringHexDoubleValue(IN PRTL_PRINT_CONTEXT Context, } /* Write the precision character */ - Status = RtlpWriteWideCharacter(Context, Digit); + Status = WriteWideCharacter(Context, Digit); if(Status != STATUS_SUCCESS) { /* Failed to write character, return error code */ @@ -2552,7 +2553,7 @@ RtlpWriteWideStringHexDoubleValue(IN PRTL_PRINT_CONTEXT Context, } /* Write the exponent characters */ - Status = RtlpWriteWideStringCustomValue(Context, L"%C%+d", ExponentCharacter, Exponent); + Status = WriteCustomValue(Context, L"%C%+d", ExponentCharacter, Exponent); if(Status != STATUS_SUCCESS) { /* Failed to write character, return error code */ @@ -2563,7 +2564,7 @@ RtlpWriteWideStringHexDoubleValue(IN PRTL_PRINT_CONTEXT Context, while(FieldCount) { /* Write the field character */ - Status = RtlpWriteWideCharacter(Context, L' '); + Status = WriteWideCharacter(Context, L' '); if(Status != STATUS_SUCCESS) { /* Failed to write character, return error code */ @@ -2596,9 +2597,9 @@ RtlpWriteWideStringHexDoubleValue(IN PRTL_PRINT_CONTEXT Context, */ XTAPI XTSTATUS -RtlpWriteWideStringIntegerValue(IN PRTL_PRINT_CONTEXT Context, - IN PRTL_PRINT_FORMAT_PROPERTIES FormatProperties, - IN ULONGLONG Integer) +RTL::WideString::WriteIntegerValue(IN PRTL_PRINT_CONTEXT Context, + IN PRTL_PRINT_FORMAT_PROPERTIES FormatProperties, + IN ULONGLONG Integer) { LONG BufferIndex, FieldLength, IntegerLength, PrecisionLength, PrefixIndex, PrefixLength; WCHAR Buffer[MAX_INTEGER_STRING_SIZE]; @@ -2649,13 +2650,13 @@ RtlpWriteWideStringIntegerValue(IN PRTL_PRINT_CONTEXT Context, } /* Initialize the buffer */ - RtlZeroMemory(Buffer, sizeof(Buffer)); + RTL::Memory::ZeroMemory(Buffer, sizeof(Buffer)); /* Convert the integer into a reversed wide string */ do { /* Get the next digit */ - NextInteger = RtlDivideUnsigned64(Integer, FormatProperties->Radix, &Remainder); + NextInteger = RTL::Math::DivideUnsigned64(Integer, FormatProperties->Radix, &Remainder); /* Convert the digit into a character */ Character = (WCHAR)Remainder; @@ -2689,7 +2690,7 @@ RtlpWriteWideStringIntegerValue(IN PRTL_PRINT_CONTEXT Context, while(Integer > 0); /* Reverse the string representation of the integer */ - RtlReverseWideString(Buffer, IntegerLength); + ReverseWideString(Buffer, IntegerLength); } /* Handle the sign decoration */ @@ -2763,7 +2764,7 @@ RtlpWriteWideStringIntegerValue(IN PRTL_PRINT_CONTEXT Context, Character = L'0'; for(PrefixIndex = 0; PrefixIndex < PrefixLength; PrefixIndex++) { - Status = RtlpWriteWideCharacter(Context, Prefix[PrefixIndex]); + Status = WriteWideCharacter(Context, Prefix[PrefixIndex]); if(Status != STATUS_SUCCESS) { /* Failed to write character, return status code */ @@ -2778,7 +2779,7 @@ RtlpWriteWideStringIntegerValue(IN PRTL_PRINT_CONTEXT Context, /* Write additional field width characters */ while(FieldLength > 0) { - Status = RtlpWriteWideCharacter(Context, Character); + Status = WriteWideCharacter(Context, Character); if(Status != STATUS_SUCCESS) { /* Failed to write character, return status code */ @@ -2793,7 +2794,7 @@ RtlpWriteWideStringIntegerValue(IN PRTL_PRINT_CONTEXT Context, /* Write the prefix characters */ for(PrefixIndex = 0; PrefixIndex < PrefixLength; PrefixIndex++) { - Status = RtlpWriteWideCharacter(Context, Prefix[PrefixIndex]); + Status = WriteWideCharacter(Context, Prefix[PrefixIndex]); if(Status != STATUS_SUCCESS) { /* Failed to write character, return status code */ @@ -2804,7 +2805,7 @@ RtlpWriteWideStringIntegerValue(IN PRTL_PRINT_CONTEXT Context, /* Fill the precision characters with '0' */ while(PrecisionLength > 0) { - Status = RtlpWriteWideCharacter(Context, L'0'); + Status = WriteWideCharacter(Context, L'0'); if(Status != STATUS_SUCCESS) { /* Failed to write character, return status code */ @@ -2818,7 +2819,7 @@ RtlpWriteWideStringIntegerValue(IN PRTL_PRINT_CONTEXT Context, /* Write the actual integer value */ for(BufferIndex = 0; BufferIndex < IntegerLength; BufferIndex++) { - Status = RtlpWriteWideCharacter(Context, Buffer[BufferIndex]); + Status = WriteWideCharacter(Context, Buffer[BufferIndex]); if(Status != STATUS_SUCCESS) { /* Failed to write character, return status code */ @@ -2829,7 +2830,7 @@ RtlpWriteWideStringIntegerValue(IN PRTL_PRINT_CONTEXT Context, /* Write additional field width with ' ' characters */ while(FieldLength > 0) { - Status = RtlpWriteWideCharacter(Context, L' '); + Status = WriteWideCharacter(Context, L' '); if(Status != STATUS_SUCCESS) { /* Failed to write character, return status code */ @@ -2865,10 +2866,10 @@ RtlpWriteWideStringIntegerValue(IN PRTL_PRINT_CONTEXT Context, */ XTAPI XTSTATUS -RtlpWriteWideStringStringValue(PRTL_PRINT_CONTEXT Context, - PRTL_PRINT_FORMAT_PROPERTIES FormatProperties, - PCHAR String, - SIZE_T StringLength) +RTL::WideString::WriteStringValue(PRTL_PRINT_CONTEXT Context, + PRTL_PRINT_FORMAT_PROPERTIES FormatProperties, + PCSTR String, + SIZE_T StringLength) { WCHAR WideCharacter[2]; ULONG PaddingLength; @@ -2903,7 +2904,7 @@ RtlpWriteWideStringStringValue(PRTL_PRINT_CONTEXT Context, while(PaddingLength > 0) { /* Write space */ - Status = RtlpWriteWideCharacter(Context, L' '); + Status = WriteWideCharacter(Context, L' '); if(Status != STATUS_SUCCESS) { /* Failed to write character, return status code */ @@ -2923,7 +2924,7 @@ RtlpWriteWideStringStringValue(PRTL_PRINT_CONTEXT Context, WideCharacter[1] = 0; /* Write wide character */ - Status = RtlpWriteWideCharacter(Context, *WideCharacter); + Status = WriteWideCharacter(Context, *WideCharacter); if(Status != STATUS_SUCCESS) { /* Failed to write character, return status code */ @@ -2939,7 +2940,7 @@ RtlpWriteWideStringStringValue(PRTL_PRINT_CONTEXT Context, while(PaddingLength > 0) { /* Write space */ - Status = RtlpWriteWideCharacter(Context, L' '); + Status = WriteWideCharacter(Context, L' '); if(Status != STATUS_SUCCESS) { /* Failed to write character, return status code */ @@ -2975,10 +2976,10 @@ RtlpWriteWideStringStringValue(PRTL_PRINT_CONTEXT Context, */ XTAPI XTSTATUS -RtlpWriteWideStringValue(PRTL_PRINT_CONTEXT Context, - PRTL_PRINT_FORMAT_PROPERTIES FormatProperties, - PWCHAR String, - SIZE_T StringLength) +RTL::WideString::WriteValue(PRTL_PRINT_CONTEXT Context, + PRTL_PRINT_FORMAT_PROPERTIES FormatProperties, + PCWSTR String, + SIZE_T StringLength) { ULONG PaddingLength; XTSTATUS Status; @@ -3013,7 +3014,7 @@ RtlpWriteWideStringValue(PRTL_PRINT_CONTEXT Context, while(PaddingLength > 0) { /* Write space */ - Status = RtlpWriteWideCharacter(Context, L' '); + Status = WriteWideCharacter(Context, L' '); if(Status != STATUS_SUCCESS) { /* Failed to write character, return status code */ @@ -3029,7 +3030,7 @@ RtlpWriteWideStringValue(PRTL_PRINT_CONTEXT Context, while(StringLength != 0) { /* Write wide character */ - Status = RtlpWriteWideCharacter(Context, *String); + Status = WriteWideCharacter(Context, *String); if(Status != STATUS_SUCCESS) { /* Failed to write character, return status code */ @@ -3045,7 +3046,7 @@ RtlpWriteWideStringValue(PRTL_PRINT_CONTEXT Context, while(PaddingLength > 0) { /* Write space */ - Status = RtlpWriteWideCharacter(Context, L' '); + Status = WriteWideCharacter(Context, L' '); if(Status != STATUS_SUCCESS) { /* Failed to write character, return status code */ @@ -3059,3 +3060,17 @@ RtlpWriteWideStringValue(PRTL_PRINT_CONTEXT Context, /* Return success */ return STATUS_SUCCESS; } + + + + +/* TEMPORARY FOR COMPATIBILITY WITH C CODE */ +XTCLINK +XTAPI +XTSTATUS +RtlFormatWideString(IN PRTL_PRINT_CONTEXT Context, + IN PCWSTR Format, + IN VA_LIST ArgumentList) +{ + return RTL::WideString::FormatWideString(Context, Format, ArgumentList); +}