diff --git a/reactos/lib/ntdll/makefile b/reactos/lib/ntdll/makefile index 16fa847cd89..91fdb401b1f 100644 --- a/reactos/lib/ntdll/makefile +++ b/reactos/lib/ntdll/makefile @@ -1,4 +1,4 @@ -# $Id: makefile,v 1.107 2004/08/09 18:17:22 jimtabor Exp $ +# $Id: makefile,v 1.108 2004/08/10 12:03:29 ekohl Exp $ PATH_TO_TOP = ../.. @@ -39,7 +39,6 @@ DBG_OBJECTS = \ dbg/brkpoint.o \ dbg/debug.o \ dbg/print.o -# dbg/winedbg.o LDR_OBJECTS = \ ldr/entry.o \ @@ -64,11 +63,10 @@ RTL_OBJECTS = \ rtl/access.o \ rtl/apc.o \ rtl/atom.o \ - rtl/dbgbuffer.o \ - rtl/bitmap.o \ rtl/callback.o \ rtl/crc32.o \ rtl/critical.o \ + rtl/dbgbuffer.o \ rtl/exception.o \ rtl/handle.o \ rtl/intrlck.o \ @@ -87,6 +85,7 @@ RTL_OBJECTS = \ rtl/timerqueue.o \ rtl/libsupp.o + STDIO_OBJECTS = \ stdio/sprintf.o \ stdio/sscanf.o \ diff --git a/reactos/lib/ntdll/rtl/bitmap.c b/reactos/lib/ntdll/rtl/bitmap.c deleted file mode 100644 index 3ece1b631a4..00000000000 --- a/reactos/lib/ntdll/rtl/bitmap.c +++ /dev/null @@ -1,788 +0,0 @@ -/* $Id: bitmap.c,v 1.7 2004/02/02 13:34:01 ekohl Exp $ - * - * COPYRIGHT: See COPYING in the top level directory - * PROJECT: ReactOS kernel - * FILE: lib/ntdll/rtl/bitmap.c - * PURPOSE: Bitmap functions - * UPDATE HISTORY: - * 20/08/99 Created by Eric Kohl - */ - -#include - - -#define NDEBUG -#include - -#define ALIGN(x,align) (((x)+(align)-1) / (align)) - - -/* FUNCTIONS *****************************************************************/ - -/* - * @implemented - */ -VOID -STDCALL -RtlInitializeBitMap ( - PRTL_BITMAP BitMapHeader, - PULONG BitMapBuffer, - ULONG SizeOfBitMap - ) -{ - BitMapHeader->SizeOfBitMap = SizeOfBitMap; - BitMapHeader->Buffer = BitMapBuffer; -} - - -/* - * @implemented - */ -BOOLEAN -STDCALL -RtlAreBitsClear ( - PRTL_BITMAP BitMapHeader, - ULONG StartingIndex, - ULONG Length - ) -{ - ULONG Size = BitMapHeader->SizeOfBitMap; - ULONG Shift; - ULONG Count; - PUCHAR Ptr; - - if (StartingIndex >= Size || - !Length || - (StartingIndex + Length > Size)) - return FALSE; - - Ptr = (PUCHAR)BitMapHeader->Buffer + (StartingIndex / 8); - while (Length) - { - /* get bit shift in current byte */ - Shift = StartingIndex & 7; - - /* get number of bits to check in current byte */ - Count = (Length > 8 - Shift) ? 8 - Shift : Length; - - /* check byte */ - if (*Ptr & (~(0xFF << Count) << Shift)) - return FALSE; - - Ptr++; - Length -= Count; - StartingIndex += Count; - } - - return TRUE; -} - - -/* - * @implemented - */ -BOOLEAN -STDCALL -RtlAreBitsSet ( - PRTL_BITMAP BitMapHeader, - ULONG StartingIndex, - ULONG Length - ) -{ - ULONG Size = BitMapHeader->SizeOfBitMap; - ULONG Shift; - ULONG Count; - PUCHAR Ptr; - UCHAR Check; - - if (StartingIndex >= Size || - !Length || - (StartingIndex + Length > Size)) - return FALSE; - - Ptr = (PUCHAR)BitMapHeader->Buffer + (StartingIndex / 8); - while (Length) - { - /* get bit shift in current byte */ - Shift = StartingIndex & 7; - - /* get number of bits to check in current byte */ - Count = (Length > 8 - Shift) ? 8 - Shift : Length; - - /* bulid check byte */ - Check = ~(0xFF << Count) << Shift; - - /* check byte */ - if ((*Ptr & Check) != Check) - return FALSE; - - Ptr++; - Length -= Count; - StartingIndex += Count; - } - - return TRUE; -} - - -/* - * @implemented - */ -VOID -STDCALL -RtlClearAllBits ( - IN OUT PRTL_BITMAP BitMapHeader - ) -{ - memset (BitMapHeader->Buffer, - 0x00, - ALIGN(BitMapHeader->SizeOfBitMap, 8)); -} - - -/* - * @implemented - */ -VOID -STDCALL -RtlClearBits ( - PRTL_BITMAP BitMapHeader, - ULONG StartingIndex, - ULONG NumberToClear - ) -{ - ULONG Size = BitMapHeader->SizeOfBitMap; - ULONG Count; - ULONG Shift; - PCHAR Ptr; - - if (StartingIndex >= Size || NumberToClear == 0) - return; - - if (StartingIndex + NumberToClear > Size) - NumberToClear = Size - StartingIndex; - - Ptr = (PCHAR)(BitMapHeader->Buffer + (StartingIndex / 8)); - while (NumberToClear) - { - /* bit shift in current byte */ - Shift = StartingIndex & 7; - - /* number of bits to change in current byte */ - Count = (NumberToClear > 8 - Shift ) ? 8 - Shift : NumberToClear; - - /* adjust byte */ - *Ptr &= ~(~(0xFF << Count) << Shift); - - Ptr++; - NumberToClear -= Count; - StartingIndex += Count; - } -} - - -/* - * @implemented - */ -ULONG -STDCALL -RtlFindClearBits ( - PRTL_BITMAP BitMapHeader, - ULONG NumberToFind, - ULONG HintIndex - ) -{ - ULONG Size = BitMapHeader->SizeOfBitMap; - ULONG Index; - ULONG Count; - PCHAR Ptr; - CHAR Mask; - - if (NumberToFind > Size || NumberToFind == 0) - return -1; - - if (HintIndex >= Size) - HintIndex = 0; - - Index = HintIndex; - Ptr = (PCHAR)BitMapHeader->Buffer + (Index / 8); - Mask = 1 << (Index & 7); - - while (HintIndex < Size) - { - /* count clear bits */ - for (Count = 0; Index < Size && ~*Ptr & Mask; Index++) - { - if (++Count >= NumberToFind) - return HintIndex; - Mask <<= 1; - if (Mask == 0) - { - Mask = 1; - Ptr++; - } - } - - /* skip set bits */ - for (; Index < Size && *Ptr & Mask; Index++) - { - Mask <<= 1; - if (Mask == 0) - { - Mask = 1; - Ptr++; - } - } - HintIndex = Index; - } - - return -1; -} - - -/* - * @implemented - */ -ULONG -STDCALL -RtlFindClearBitsAndSet ( - PRTL_BITMAP BitMapHeader, - ULONG NumberToFind, - ULONG HintIndex - ) -{ - ULONG Index; - - Index = RtlFindClearBits (BitMapHeader, - NumberToFind, - HintIndex); - if (Index != (ULONG)-1) - RtlSetBits (BitMapHeader, - Index, - NumberToFind); - - return Index; -} - - -/* - * @unimplemented - */ -ULONG STDCALL -RtlFindClearRuns (PRTL_BITMAP BitMapHeader, - PRTL_BITMAP_RUN RunArray, - ULONG SizeOfRunArray, - BOOLEAN LocateLongestRuns) -{ - return (ULONG)-1; -} - - -ULONG -STDCALL -RtlFindFirstRunClear ( - PRTL_BITMAP BitMapHeader, - PULONG StartingIndex - ) -{ - ULONG Size = BitMapHeader->SizeOfBitMap; - ULONG Index; - ULONG Count; - PCHAR Ptr; - CHAR Mask; - - if (*StartingIndex > Size) - { - *StartingIndex = (ULONG)-1; - return 0; - } - - Index = *StartingIndex; - Ptr = (PCHAR)BitMapHeader->Buffer + (Index / 8); - Mask = 1 << (Index & 7); - - /* skip set bits */ - for (; Index < Size && *Ptr & Mask; Index++) - { - Mask <<= 1; - if (Mask == 0) - { - Mask = 1; - Ptr++; - } - } - - /* return index of first clear bit */ - if (Index >= Size) - { - *StartingIndex = (ULONG)-1; - return 0; - } - else - *StartingIndex = Index; - - /* count clear bits */ - for (Count = 0; Index < Size && ~*Ptr & Mask; Index++) - { - Count++; - Mask <<= 1; - if (Mask == 0) - { - Mask = 1; - Ptr++; - } - } - - return Count; -} - - -ULONG -STDCALL -RtlFindFirstRunSet ( - PRTL_BITMAP BitMapHeader, - PULONG StartingIndex - ) -{ - ULONG Size = BitMapHeader->SizeOfBitMap; - ULONG Index; - ULONG Count; - PCHAR Ptr; - CHAR Mask; - - if (*StartingIndex > Size) - { - *StartingIndex = (ULONG)-1; - return 0; - } - - Index = *StartingIndex; - Ptr = (PCHAR)BitMapHeader->Buffer + (Index / 8); - Mask = 1 << (Index & 7); - - /* skip clear bits */ - for (; Index < Size && ~*Ptr & Mask; Index++) - { - Mask <<= 1; - if (Mask == 0) - { - Mask = 1; - Ptr++; - } - } - - /* return index of first set bit */ - if (Index >= Size) - { - *StartingIndex = (ULONG)-1; - return 0; - } - else - *StartingIndex = Index; - - /* count set bits */ - for (Count = 0; Index < Size && *Ptr & Mask; Index++) - { - Count++; - Mask <<= 1; - if (Mask == 0) - { - Mask = 1; - Ptr++; - } - } - - return Count; -} - - -/* - * @unimplemented - */ -ULONG STDCALL -RtlFindLastBackwardRunClear (IN PRTL_BITMAP BitMapHeader, - IN ULONG FromIndex, - IN PULONG StartingRunIndex) -{ - return (ULONG)-1; -} - - -/* - * @implemented - */ -ULONG -STDCALL -RtlFindLongestRunClear ( - PRTL_BITMAP BitMapHeader, - PULONG StartingIndex - ) -{ - ULONG Size = BitMapHeader->SizeOfBitMap; - PCHAR Ptr = (PCHAR)BitMapHeader->Buffer; - ULONG Index = 0; - ULONG Count; - ULONG Max = 0; - ULONG Start; - ULONG Maxstart = 0; - CHAR Mask = 1; - - while (Index < Size) - { - Start = Index; - - /* count clear bits */ - for (Count = 0; Index < Size && ~*Ptr & Mask; Index++) - { - Count++; - Mask <<= 1; - if (Mask == 0) - { - Mask = 1; - Ptr++; - } - } - - /* skip set bits */ - for (; Index < Size && *Ptr & Mask; Index++) - { - Mask <<= 1; - if (Mask == 0) - { - Mask = 1; - Ptr++; - } - } - - if (Count > Max) - { - Max = Count; - Maxstart = Start; - } - } - - if (StartingIndex) - *StartingIndex = Maxstart; - - return Max; -} - - -/* - * @implemented - */ -ULONG -STDCALL -RtlFindLongestRunSet ( - PRTL_BITMAP BitMapHeader, - PULONG StartingIndex - ) -{ - ULONG Size = BitMapHeader->SizeOfBitMap; - PCHAR Ptr = (PCHAR)BitMapHeader->Buffer; - ULONG Index = 0; - ULONG Count; - ULONG Max = 0; - ULONG Start; - ULONG Maxstart = 0; - CHAR Mask = 1; - - while (Index < Size) - { - Start = Index; - - /* count set bits */ - for (Count = 0; Index < Size && *Ptr & Mask; Index++) - { - Count++; - Mask <<= 1; - if (Mask == 0) - { - Mask = 1; - Ptr++; - } - } - - /* skip clear bits */ - for (; Index < Size && ~*Ptr & Mask; Index++) - { - Mask <<= 1; - if (Mask == 0) - { - Mask = 1; - Ptr++; - } - } - - if (Count > Max) - { - Max = Count; - Maxstart = Start; - } - } - - if (StartingIndex) - *StartingIndex = Maxstart; - - return Max; -} - - -/* - * @unimplemented - */ -ULONG STDCALL -RtlFindNextForwardRunClear (IN PRTL_BITMAP BitMapHeader, - IN ULONG FromIndex, - IN PULONG StartingRunIndex) -{ - return (ULONG)-1; -} - - -/* - * @implemented - */ -ULONG -STDCALL -RtlFindSetBits ( - PRTL_BITMAP BitMapHeader, - ULONG NumberToFind, - ULONG HintIndex - ) -{ - ULONG Size = BitMapHeader->SizeOfBitMap; - ULONG Index; - ULONG Count; - PCHAR Ptr; - CHAR Mask; - - if (NumberToFind > Size || NumberToFind == 0) - return (ULONG)-1; - - if (HintIndex >= Size) - HintIndex = 0; - - Index = HintIndex; - Ptr = (PCHAR)BitMapHeader->Buffer + (Index / 8); - Mask = 1 << (Index & 7); - - while (HintIndex < Size) - { - /* count set bits */ - for (Count = 0; Index < Size && *Ptr & Mask; Index++) - { - if (++Count >= NumberToFind) - return HintIndex; - Mask <<= 1; - if (Mask == 0) - { - Mask = 1; - Ptr++; - } - } - - /* skip clear bits */ - for (; Index < Size && ~*Ptr & Mask; Index++) - { - Mask <<= 1; - if (Mask == 0) - { - Mask = 1; - Ptr++; - } - } - HintIndex = Index; - } - - return (ULONG)-1; -} - - -/* - * @implemented - */ -ULONG -STDCALL -RtlFindSetBitsAndClear ( - PRTL_BITMAP BitMapHeader, - ULONG NumberToFind, - ULONG HintIndex - ) -{ - ULONG Index; - - Index = RtlFindSetBits (BitMapHeader, - NumberToFind, - HintIndex); - if (Index != (ULONG)-1) - RtlClearBits (BitMapHeader, - Index, - NumberToFind); - - return Index; -} - - -/* - * @implemented - */ -ULONG -STDCALL -RtlNumberOfClearBits ( - PRTL_BITMAP BitMapHeader - ) -{ - PCHAR Ptr = (PCHAR)BitMapHeader->Buffer; - ULONG Size = BitMapHeader->SizeOfBitMap; - ULONG Index; - ULONG Count; - CHAR Mask; - - for (Mask = 1, Index = 0, Count = 0; Index < Size; Index++) - { - if (~*Ptr & Mask) - Count++; - - Mask <<= 1; - if (Mask == 0) - { - Mask = 1; - Ptr++; - } - } - - return Count; -} - - -/* - * @implemented - */ -ULONG -STDCALL -RtlNumberOfSetBits ( - PRTL_BITMAP BitMapHeader - ) -{ - PCHAR Ptr = (PCHAR)BitMapHeader->Buffer; - ULONG Size = BitMapHeader->SizeOfBitMap; - ULONG Index; - ULONG Count; - CHAR Mask; - - for (Mask = 1, Index = 0, Count = 0; Index < Size; Index++) - { - if (*Ptr & Mask) - Count++; - - Mask <<= 1; - if (Mask == 0) - { - Mask = 1; - Ptr++; - } - } - - return Count; -} - - -/* - * @implemented - */ -VOID -STDCALL -RtlSetAllBits ( - IN OUT PRTL_BITMAP BitMapHeader - ) -{ - memset (BitMapHeader->Buffer, - 0xFF, - ALIGN(BitMapHeader->SizeOfBitMap, 8)); -} - - -/* - * @implemented - */ -VOID -STDCALL -RtlSetBits ( - PRTL_BITMAP BitMapHeader, - ULONG StartingIndex, - ULONG NumberToSet - ) -{ - ULONG Size = BitMapHeader->SizeOfBitMap; - ULONG Count; - ULONG Shift; - PCHAR Ptr; - - if (StartingIndex >= Size || NumberToSet == 0) - return; - - if (StartingIndex + NumberToSet > Size) - NumberToSet = Size - StartingIndex; - - Ptr = (PCHAR)BitMapHeader->Buffer + (StartingIndex / 8); - while (NumberToSet) - { - /* bit shift in current byte */ - Shift = StartingIndex & 7; - - /* number of bits to change in current byte */ - Count = (NumberToSet > 8 - Shift) ? 8 - Shift : NumberToSet; - - /* adjust byte */ - *Ptr |= ~(0xFF << Count) << Shift; - - Ptr++; - NumberToSet -= Count; - StartingIndex += Count; - } -} - - -/* - * @implemented - */ -CCHAR STDCALL -RtlFindLeastSignificantBit (IN ULONGLONG Set) -{ - int i; - - if (Set == 0ULL) - return -1; - - for (i = 0; i < 64; i++) - { - if (Set & (1 << i)) - return (CCHAR)i; - } - - return -1; -} - - -/* - * @implemented - */ -CCHAR STDCALL -RtlFindMostSignificantBit (IN ULONGLONG Set) -{ - int i; - - if (Set == 0ULL) - return -1; - - for (i = 63; i >= 0; i--) - { - if (Set & (1 << i)) - return (CCHAR)i; - } - - return -1; -} - -/* EOF */ diff --git a/reactos/ntoskrnl/Makefile b/reactos/ntoskrnl/Makefile index 4324c65fad8..b1b9b6268f2 100644 --- a/reactos/ntoskrnl/Makefile +++ b/reactos/ntoskrnl/Makefile @@ -1,4 +1,4 @@ -# $Id: Makefile,v 1.136 2004/08/04 02:27:07 navaraf Exp $ +# $Id: Makefile,v 1.137 2004/08/10 12:05:20 ekohl Exp $ # # ReactOS Operating System # @@ -110,8 +110,6 @@ OBJECTS_NT = \ # Run-Time Library (Rtl) OBJECTS_RTL = \ rtl/atom.o \ - rtl/bit.o \ - rtl/bitmap.o \ rtl/capture.o \ rtl/ctype.o \ rtl/handle.o \ diff --git a/reactos/ntoskrnl/rtl/bit.c b/reactos/ntoskrnl/rtl/bit.c deleted file mode 100644 index ce6925a039d..00000000000 --- a/reactos/ntoskrnl/rtl/bit.c +++ /dev/null @@ -1,74 +0,0 @@ -/* - * ReactOS kernel - * Copyright (C) 2004 ReactOS Team - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. - */ -/* $Id: bit.c,v 1.2 2004/08/07 19:13:27 ion Exp $ - * - * PROJECT: ReactOS kernel - * PURPOSE: Runtime code - * FILE: ntoskrnl/rtl/bit.c - * PROGRAMER: Eric Kohl - */ - -/* INCLUDES *****************************************************************/ - -#include - - -/* FUNCTIONS ****************************************************************/ - -/* - * @implemented - */ -CCHAR STDCALL -RtlFindLeastSignificantBit (IN ULONGLONG Set) -{ - int i; - - if (Set == 0ULL) - return -1; - - for (i = 0; i < 64; i++) - { - if (Set & (1 << i)) - return (CCHAR)i; - } - - return -1; -} - -/* - * @implemented - */ -CCHAR STDCALL -RtlFindMostSignificantBit (IN ULONGLONG Set) -{ - int i; - - if (Set == 0ULL) - return -1; - - for (i = 63; i >= 0; i--) - { - if (Set & (1 << i)) - return (CCHAR)i; - } - - return -1; -} - -/* EOF */ diff --git a/reactos/ntoskrnl/rtl/bitmap.c b/reactos/ntoskrnl/rtl/bitmap.c deleted file mode 100644 index 25d1a15ab4d..00000000000 --- a/reactos/ntoskrnl/rtl/bitmap.c +++ /dev/null @@ -1,780 +0,0 @@ -/* $Id: bitmap.c,v 1.10 2004/08/05 18:17:37 ion Exp $ - * - * COPYRIGHT: See COPYING in the top level directory - * PROJECT: ReactOS kernel - * FILE: ntoskrnl/rtl/bitmap.c - * PURPOSE: Bitmap functions - * UPDATE HISTORY: - * 20/08/99 Created by Eric Kohl - */ - -#include - -#define NDEBUG -#include - -#define ALIGN(x,align) (((x)+(align)-1) / (align)) - -#define MASK(Count, Shift) ((Count) == 32 ? 0xFFFFFFFF : ~(0xFFFFFFFF << (Count)) << (Shift)) - - -/* - * @implemented - */ -VOID -STDCALL -RtlInitializeBitMap ( - PRTL_BITMAP BitMapHeader, - PULONG BitMapBuffer, - ULONG SizeOfBitMap - ) -{ - BitMapHeader->SizeOfBitMap = SizeOfBitMap; - BitMapHeader->Buffer = BitMapBuffer; -} - - -/* - * @implemented - */ -BOOLEAN -STDCALL -RtlAreBitsClear ( - PRTL_BITMAP BitMapHeader, - ULONG StartingIndex, - ULONG Length - ) -{ - ULONG Size = BitMapHeader->SizeOfBitMap; - ULONG Shift; - ULONG Count; - PULONG Ptr; - - if (StartingIndex >= Size || - !Length || - (StartingIndex + Length > Size)) - return FALSE; - - Ptr = (PULONG)BitMapHeader->Buffer + (StartingIndex / 32); - while (Length) - { - /* get bit shift in current dword */ - Shift = StartingIndex & 0x1F; - - /* get number of bits to check in current dword */ - Count = (Length > 32 - Shift) ? 32 - Shift : Length; - - /* check dword */ - if (*Ptr++ & MASK(Count, Shift)) - return FALSE; - - Length -= Count; - StartingIndex += Count; - } - - return TRUE; -} - - -/* - * @implemented - */ -BOOLEAN -STDCALL -RtlAreBitsSet ( - PRTL_BITMAP BitMapHeader, - ULONG StartingIndex, - ULONG Length - ) -{ - ULONG Size = BitMapHeader->SizeOfBitMap; - ULONG Shift; - ULONG Count; - PULONG Ptr; - - if (StartingIndex >= Size || - !Length || - (StartingIndex + Length > Size)) - return FALSE; - - Ptr = (PULONG)BitMapHeader->Buffer + (StartingIndex / 32); - while (Length) - { - /* get bit shift in current dword */ - Shift = StartingIndex & 0x1F; - - /* get number of bits to check in current dword */ - Count = (Length > 32 - Shift) ? 32 - Shift : Length; - - /* check dword */ - if (~*Ptr++ & MASK(Count, Shift)) - return FALSE; - - Length -= Count; - StartingIndex += Count; - } - - return TRUE; -} - - -/* - * @implemented - */ -VOID -STDCALL -RtlClearAllBits ( - IN OUT PRTL_BITMAP BitMapHeader - ) -{ - memset (BitMapHeader->Buffer, - 0x00, - ALIGN(BitMapHeader->SizeOfBitMap, 8)); -} - -/* -* @unimplemented -*/ -VOID -STDCALL -RtlClearBit ( - PRTL_BITMAP BitMapHeader, - ULONG BitNumber - ) -{ - UNIMPLEMENTED; -} - -/* - * @implemented - */ -VOID -STDCALL -RtlClearBits ( - PRTL_BITMAP BitMapHeader, - ULONG StartingIndex, - ULONG NumberToClear - ) -{ - ULONG Size = BitMapHeader->SizeOfBitMap; - ULONG Count; - ULONG Shift; - PULONG Ptr; - - if (StartingIndex >= Size || NumberToClear == 0) - return; - - if (StartingIndex + NumberToClear > Size) - NumberToClear = Size - StartingIndex; - - Ptr = (PULONG)BitMapHeader->Buffer + (StartingIndex / 32); - while (NumberToClear) - { - /* bit shift in current dword */ - Shift = StartingIndex & 0x1F; - - /* number of bits to change in current dword */ - Count = (NumberToClear > 32 - Shift ) ? 32 - Shift : NumberToClear; - - /* adjust dword */ - *Ptr++ &= ~MASK(Count, Shift); - NumberToClear -= Count; - StartingIndex += Count; - } -} - - -/* - * @implemented - */ -ULONG -STDCALL -RtlFindClearBits ( - PRTL_BITMAP BitMapHeader, - ULONG NumberToFind, - ULONG HintIndex - ) -{ - ULONG Size = BitMapHeader->SizeOfBitMap; - ULONG Index; - ULONG Count; - PULONG Ptr; - ULONG Mask; - - if (NumberToFind > Size || NumberToFind == 0) - return -1; - - if (HintIndex >= Size) - HintIndex = 0; - - Index = HintIndex; - Ptr = (PULONG)BitMapHeader->Buffer + (Index / 32); - Mask = 1 << (Index & 0x1F); - - while (HintIndex < Size) - { - /* count clear bits */ - for (Count = 0; Index < Size && ~*Ptr & Mask; Index++) - { - if (++Count >= NumberToFind) - return HintIndex; - Mask <<= 1; - if (Mask == 0) - { - Mask = 1; - Ptr++; - } - } - - /* skip set bits */ - for (; Index < Size && *Ptr & Mask; Index++) - { - Mask <<= 1; - if (Mask == 0) - { - Mask = 1; - Ptr++; - } - } - HintIndex = Index; - } - - return -1; -} - - -/* - * @implemented - */ -ULONG -STDCALL -RtlFindClearBitsAndSet ( - PRTL_BITMAP BitMapHeader, - ULONG NumberToFind, - ULONG HintIndex - ) -{ - ULONG Index; - - Index = RtlFindClearBits (BitMapHeader, - NumberToFind, - HintIndex); - if (Index != (ULONG)-1) - RtlSetBits (BitMapHeader, - Index, - NumberToFind); - - return Index; -} - - -/* - * @implemented - */ -ULONG -STDCALL -RtlFindFirstRunClear ( - PRTL_BITMAP BitMapHeader, - PULONG StartingIndex - ) -{ - ULONG Size = BitMapHeader->SizeOfBitMap; - ULONG Index; - ULONG Count; - PULONG Ptr; - ULONG Mask; - - if (*StartingIndex > Size) - { - *StartingIndex = (ULONG)-1; - return 0; - } - - Index = *StartingIndex; - Ptr = (PULONG)BitMapHeader->Buffer + (Index / 32); - Mask = 1 << (Index & 0x1F); - - /* skip set bits */ - for (; Index < Size && *Ptr & Mask; Index++) - { - Mask <<= 1; - if (Mask == 0) - { - Mask = 1; - Ptr++; - } - } - - /* return index of first clear bit */ - if (Index >= Size) - { - *StartingIndex = (ULONG)-1; - return 0; - } - else - *StartingIndex = Index; - - /* count clear bits */ - for (Count = 0; Index < Size && ~*Ptr & Mask; Index++) - { - Count++; - Mask <<= 1; - if (Mask == 0) - { - Mask = 1; - Ptr++; - } - } - - return Count; -} - -/* -* @unimplemented -*/ -ULONG -STDCALL -RtlFindClearRuns ( - PRTL_BITMAP BitMapHeader, - PRTL_BITMAP_RUN RunArray, - ULONG SizeOfRunArray, - BOOLEAN LocateLongestRuns - ) -{ - UNIMPLEMENTED; - return 0; -} - -/* -* @unimplemented -*/ -ULONG -STDCALL -RtlFindLastBackwardRunClear ( - IN PRTL_BITMAP BitMapHeader, - IN ULONG FromIndex, - IN PULONG StartingRunIndex - ) -{ - UNIMPLEMENTED; - return 0; -} - -/* -* @unimplemented -*/ -ULONG -STDCALL -RtlFindNextForwardRunClear ( - IN PRTL_BITMAP BitMapHeader, - IN ULONG FromIndex, - IN PULONG StartingRunIndex - ) -{ - UNIMPLEMENTED; - return 0; -} - -ULONG -STDCALL -RtlFindFirstRunSet ( - PRTL_BITMAP BitMapHeader, - PULONG StartingIndex - ) -{ - ULONG Size = BitMapHeader->SizeOfBitMap; - ULONG Index; - ULONG Count; - PULONG Ptr; - ULONG Mask; - - if (*StartingIndex > Size) - { - *StartingIndex = (ULONG)-1; - return 0; - } - - Index = *StartingIndex; - Ptr = (PULONG)BitMapHeader->Buffer + (Index / 32); - Mask = 1 << (Index & 0x1F); - - /* skip clear bits */ - for (; Index < Size && ~*Ptr & Mask; Index++) - { - Mask <<= 1; - if (Mask == 0) - { - Mask = 1; - Ptr++; - } - } - - /* return index of first set bit */ - if (Index >= Size) - { - *StartingIndex = (ULONG)-1; - return 0; - } - else - *StartingIndex = Index; - - /* count set bits */ - for (Count = 0; Index < Size && *Ptr & Mask; Index++) - { - Count++; - Mask <<= 1; - if (Mask == 0) - { - Mask = 1; - Ptr++; - } - } - - return Count; -} - - -/* - * @implemented - */ -ULONG -STDCALL -RtlFindLongestRunClear ( - PRTL_BITMAP BitMapHeader, - PULONG StartingIndex - ) -{ - ULONG Size = BitMapHeader->SizeOfBitMap; - PULONG Ptr = (PULONG)BitMapHeader->Buffer; - ULONG Index = 0; - ULONG Count; - ULONG Max = 0; - ULONG Start; - ULONG Maxstart = 0; - ULONG Mask = 1; - - while (Index < Size) - { - Start = Index; - - /* count clear bits */ - for (Count = 0; Index < Size && ~*Ptr & Mask; Index++) - { - Count++; - Mask <<= 1; - if (Mask == 0) - { - Mask = 1; - Ptr++; - } - } - - /* skip set bits */ - for (; Index < Size && *Ptr & Mask; Index++) - { - Mask <<= 1; - if (Mask == 0) - { - Mask = 1; - Ptr++; - } - } - - if (Count > Max) - { - Max = Count; - Maxstart = Start; - } - } - - if (StartingIndex) - *StartingIndex = Maxstart; - - return Max; -} - - -ULONG -STDCALL -RtlFindLongestRunSet ( - PRTL_BITMAP BitMapHeader, - PULONG StartingIndex - ) -{ - ULONG Size = BitMapHeader->SizeOfBitMap; - PULONG Ptr = (PULONG)BitMapHeader->Buffer; - ULONG Index = 0; - ULONG Count; - ULONG Max = 0; - ULONG Start; - ULONG Maxstart = 0; - ULONG Mask = 1; - - while (Index < Size) - { - Start = Index; - - /* count set bits */ - for (Count = 0; Index < Size && *Ptr & Mask; Index++) - { - Count++; - Mask <<= 1; - if (Mask == 0) - { - Mask = 1; - Ptr++; - } - } - - /* skip clear bits */ - for (; Index < Size && ~*Ptr & Mask; Index++) - { - Mask <<= 1; - if (Mask == 0) - { - Mask = 1; - Ptr++; - } - } - - if (Count > Max) - { - Max = Count; - Maxstart = Start; - } - } - - if (StartingIndex) - *StartingIndex = Maxstart; - - return Max; -} - - -/* - * @implemented - */ -ULONG -STDCALL -RtlFindSetBits ( - PRTL_BITMAP BitMapHeader, - ULONG NumberToFind, - ULONG HintIndex - ) -{ - ULONG Size = BitMapHeader->SizeOfBitMap; - ULONG Index; - ULONG Count; - PULONG Ptr; - ULONG Mask; - - if (NumberToFind > Size || NumberToFind == 0) - return (ULONG)-1; - - if (HintIndex >= Size) - HintIndex = 0; - - Index = HintIndex; - Ptr = (PULONG)BitMapHeader->Buffer + (Index / 32); - Mask = 1 << (Index & 0x1F); - - while (HintIndex < Size) - { - /* count set bits */ - for (Count = 0; Index < Size && *Ptr & Mask; Index++) - { - if (++Count >= NumberToFind) - return HintIndex; - Mask <<= 1; - if (Mask == 0) - { - Mask = 1; - Ptr++; - } - } - - /* skip clear bits */ - for (; Index < Size && ~*Ptr & Mask; Index++) - { - Mask <<= 1; - if (Mask == 0) - { - Mask = 1; - Ptr++; - } - } - HintIndex = Index; - } - - return (ULONG)-1; -} - - -/* - * @implemented - */ -ULONG -STDCALL -RtlFindSetBitsAndClear ( - PRTL_BITMAP BitMapHeader, - ULONG NumberToFind, - ULONG HintIndex - ) -{ - ULONG Index; - - Index = RtlFindSetBits (BitMapHeader, - NumberToFind, - HintIndex); - if (Index != (ULONG)-1) - RtlClearBits (BitMapHeader, - Index, - NumberToFind); - - return Index; -} - - -/* - * @implemented - */ -ULONG -STDCALL -RtlNumberOfClearBits ( - PRTL_BITMAP BitMapHeader - ) -{ - PULONG Ptr = (PULONG)BitMapHeader->Buffer; - ULONG Size = BitMapHeader->SizeOfBitMap; - ULONG Index; - ULONG Count; - ULONG Mask; - - for (Mask = 1, Index = 0, Count = 0; Index < Size; Index++) - { - if (~*Ptr & Mask) - Count++; - - Mask <<= 1; - if (Mask == 0) - { - Mask = 1; - Ptr++; - } - } - - return Count; -} - - -/* - * @implemented - */ -ULONG -STDCALL -RtlNumberOfSetBits ( - PRTL_BITMAP BitMapHeader - ) -{ - PULONG Ptr = (PULONG)BitMapHeader->Buffer; - ULONG Size = BitMapHeader->SizeOfBitMap; - ULONG Index; - ULONG Count; - ULONG Mask; - - for (Mask = 1, Index = 0, Count = 0; Index < Size; Index++) - { - if (*Ptr & Mask) - Count++; - - Mask <<= 1; - if (Mask == 0) - { - Mask = 1; - Ptr++; - } - } - - return Count; -} - - -/* - * @implemented - */ -VOID -STDCALL -RtlSetAllBits ( - IN OUT PRTL_BITMAP BitMapHeader - ) -{ - memset (BitMapHeader->Buffer, - 0xFF, - ALIGN(BitMapHeader->SizeOfBitMap, 8)); -} - -/* -* @unimplemented -*/ -VOID -STDCALL -RtlSetBit ( - PRTL_BITMAP BitMapHeader, - ULONG BitNumber - ) -{ - UNIMPLEMENTED; -} - -/* - * @implemented - */ -VOID -STDCALL -RtlSetBits ( - PRTL_BITMAP BitMapHeader, - ULONG StartingIndex, - ULONG NumberToSet - ) -{ - ULONG Size = BitMapHeader->SizeOfBitMap; - ULONG Count; - ULONG Shift; - PULONG Ptr; - - if (StartingIndex >= Size || NumberToSet == 0) - return; - - if (StartingIndex + NumberToSet > Size) - NumberToSet = Size - StartingIndex; - - Ptr = (PULONG)BitMapHeader->Buffer + (StartingIndex / 32); - while (NumberToSet) - { - /* bit shift in current dword */ - Shift = StartingIndex & 0x1F; - - /* number of bits to change in current dword */ - Count = (NumberToSet > 32 - Shift) ? 32 - Shift : NumberToSet; - - /* adjust dword */ - *Ptr++ |= MASK(Count, Shift); - NumberToSet -= Count; - StartingIndex += Count; - } -} - -/* -* @unimplemented -*/ -BOOLEAN -STDCALL -RtlTestBit ( - PRTL_BITMAP BitMapHeader, - ULONG BitNumber - ) -{ - UNIMPLEMENTED; - return FALSE; -} -/* EOF */