Migrate RTL subsystem to C++
This commit is contained in:
@@ -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 <belliash@codingworkshop.eu.org>
|
||||
*/
|
||||
|
||||
#include <xtos.h>
|
||||
#include <xtos.hh>
|
||||
|
||||
|
||||
/**
|
||||
@@ -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;
|
@@ -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 <belliash@codingworkshop.eu.org>
|
||||
*/
|
||||
|
||||
#include <xtos.h>
|
||||
#include <xtos.hh>
|
||||
|
||||
|
||||
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,
|
@@ -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 <belliash@codingworkshop.eu.org>
|
||||
*/
|
||||
|
||||
#include <xtos.h>
|
||||
#include <xtos.hh>
|
||||
|
||||
|
||||
/**
|
||||
@@ -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);
|
||||
}
|
@@ -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 <belliash@codingworkshop.eu.org>
|
||||
*/
|
||||
|
||||
#include <xtos.h>
|
||||
#include <xtos.hh>
|
||||
|
||||
|
||||
/**
|
||||
@@ -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;
|
||||
}
|
@@ -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 <belliash@codingworkshop.eu.org>
|
||||
*/
|
||||
|
||||
@@ -10,4 +10,4 @@
|
||||
|
||||
|
||||
/* This is required for floating numbers to keep LLVM happy */
|
||||
int _fltused = 0xFEEDBULL;
|
||||
XTCLINK INT _fltused = 0xFEEDBULL;
|
@@ -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 <belliash@codingworkshop.eu.org>
|
||||
*/
|
||||
|
||||
#include <xtos.h>
|
||||
#include <xtos.hh>
|
||||
|
||||
|
||||
/**
|
||||
@@ -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) |
|
1310
xtoskrnl/rtl/exports.cc
Normal file
1310
xtoskrnl/rtl/exports.cc
Normal file
File diff suppressed because it is too large
Load Diff
@@ -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 <belliash@codingworkshop.eu.org>
|
||||
*/
|
||||
|
||||
#include <xtos.h>
|
||||
#include <xtos.hh>
|
||||
|
||||
|
||||
/**
|
||||
@@ -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]);
|
||||
}
|
@@ -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 <belliash@codingworkshop.eu.org>
|
||||
*/
|
||||
|
||||
#include <xtos.h>
|
||||
#include <xtos.hh>
|
||||
|
||||
|
||||
/**
|
||||
@@ -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);
|
@@ -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 <belliash@codingworkshop.eu.org>
|
||||
*/
|
||||
|
||||
#include <xtos.h>
|
||||
#include <xtos.hh>
|
||||
|
||||
|
||||
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,
|
@@ -1,124 +0,0 @@
|
||||
/**
|
||||
* PROJECT: ExectOS
|
||||
* COPYRIGHT: See COPYING.md in the top level directory
|
||||
* FILE: xtoskrnl/rtl/ioreg.c
|
||||
* DESCRIPTION: I/O registers related routines
|
||||
* DEVELOPERS: Rafal Kupiec <belliash@codingworkshop.eu.org>
|
||||
*/
|
||||
|
||||
#include <xtos.h>
|
||||
|
||||
|
||||
/**
|
||||
* Reads a byte 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.
|
||||
*
|
||||
* @since XT 1.0
|
||||
*/
|
||||
XTAPI
|
||||
UCHAR
|
||||
RtlReadRegisterByte(IN VOLATILE PVOID Register)
|
||||
{
|
||||
return *((VOLATILE PUCHAR)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 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.
|
||||
*
|
||||
* @since XT 1.0
|
||||
*/
|
||||
XTAPI
|
||||
USHORT
|
||||
RtlReadRegisterShort(IN VOLATILE PVOID Register)
|
||||
{
|
||||
return *((VOLATILE PUSHORT)Register);
|
||||
}
|
||||
|
||||
/**
|
||||
* 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 UCHAR value that will be stored into a register.
|
||||
*
|
||||
* @return This routine does not return any value.
|
||||
*
|
||||
* @since XT 1.0
|
||||
*/
|
||||
XTAPI
|
||||
VOID
|
||||
RtlWriteRegisterByte(IN VOLATILE PVOID Register,
|
||||
IN UCHAR Value)
|
||||
{
|
||||
*((VOLATILE PUCHAR)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 ULONG value that will be stored into a register.
|
||||
*
|
||||
* @return This routine does not return any value.
|
||||
*
|
||||
* @since XT 1.0
|
||||
*/
|
||||
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)
|
||||
{
|
||||
*((VOLATILE PUSHORT)Register) = Value;
|
||||
}
|
@@ -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 <belliash@codingworkshop.eu.org>
|
||||
*/
|
||||
|
||||
#include <xtos.h>
|
||||
#include <xtos.hh>
|
||||
|
||||
|
||||
/**
|
||||
@@ -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;
|
@@ -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 <belliash@codingworkshop.eu.org>
|
||||
*/
|
||||
|
||||
#include <xtos.h>
|
||||
#include <xtos.hh>
|
||||
|
||||
|
||||
/**
|
||||
@@ -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));
|
||||
}
|
@@ -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 <belliash@codingworkshop.eu.org>
|
||||
*/
|
||||
|
||||
#include <xtos.h>
|
||||
#include <xtos.hh>
|
||||
|
||||
|
||||
/**
|
||||
@@ -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);
|
||||
}
|
@@ -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 <belliash@codingworkshop.eu.org>
|
||||
*/
|
||||
|
||||
#include <xtos.h>
|
||||
#include <xtos.hh>
|
||||
|
||||
|
||||
/**
|
||||
@@ -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));
|
||||
}
|
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user