-/*
- * PROJECT: ReactOS Native Headers
- * FILE: include/ndk/rtlfuncs.h
- * PURPOSE: Prototypes for Runtime Library Functions not defined in DDK/IFS
- * PROGRAMMER: Alex Ionescu (alex@relsoft.net)
- * UPDATE HISTORY:
- * Created 06/10/04
- */
+/*++ NDK Version: 0095
+
+Copyright (c) Alex Ionescu. All rights reserved.
+
+Header Name:
+
+ rtlfuncs.h
+
+Abstract:
+
+ Function definitions for the Run-Time Library
+
+Author:
+
+ Alex Ionescu (alex.ionescu@reactos.com) 06-Oct-2004
+
+--*/
+
#ifndef _RTLFUNCS_H
#define _RTLFUNCS_H
-/* DEPENDENCIES **************************************************************/
+//
+// Dependencies
+//
#include <ntnls.h>
#include "extypes.h"
#include "rtltypes.h"
-/* MACROS ********************************************************************/
+#ifdef NTOS_MODE_USER
-/* FIXME: Eventually move the ones in rtltypes.h here... */
+//
+// List Functions
+//
+FORCEINLINE
+VOID
+InitializeListHead(
+ IN PLIST_ENTRY ListHead
+)
+{
+ ListHead->Flink = ListHead->Blink = ListHead;
+}
-/*
- * Splay Tree Macros
- */
-#define RtlIsLeftChild(Links) \
- (RtlLeftChild(RtlParent(Links)) == (PRTL_SPLAY_LINKS)(Links))
+FORCEINLINE
+VOID
+InsertHeadList(
+ IN PLIST_ENTRY ListHead,
+ IN PLIST_ENTRY Entry
+)
+{
+ PLIST_ENTRY OldFlink;
+ OldFlink = ListHead->Flink;
+ Entry->Flink = OldFlink;
+ Entry->Blink = ListHead;
+ OldFlink->Blink = Entry;
+ ListHead->Flink = Entry;
+}
-#define RtlRightChild(Links) \
- (PRTL_SPLAY_LINKS)(Links)->RightChild
+FORCEINLINE
+VOID
+InsertTailList(
+ IN PLIST_ENTRY ListHead,
+ IN PLIST_ENTRY Entry
+)
+{
+ PLIST_ENTRY OldBlink;
+ OldBlink = ListHead->Blink;
+ Entry->Flink = ListHead;
+ Entry->Blink = OldBlink;
+ OldBlink->Flink = Entry;
+ ListHead->Blink = Entry;
+}
-#define RtlIsRoot(Links) \
- (RtlParent(Links) == (PRTL_SPLAY_LINKS)(Links))
+BOOLEAN
+FORCEINLINE
+IsListEmpty(
+ IN const LIST_ENTRY * ListHead
+)
+{
+ return (BOOLEAN)(ListHead->Flink == ListHead);
+}
-#define RtlLeftChild(Links) \
- (PRTL_SPLAY_LINKS)(Links)->LeftChild
+FORCEINLINE
+PSINGLE_LIST_ENTRY
+PopEntryList(
+ PSINGLE_LIST_ENTRY ListHead
+)
+{
+ PSINGLE_LIST_ENTRY FirstEntry;
+ FirstEntry = ListHead->Next;
+ if (FirstEntry != NULL) {
+ ListHead->Next = FirstEntry->Next;
+ }
-#define RtlParent(Links) \
- (PRTL_SPLAY_LINKS)(Links)->Parent
+ return FirstEntry;
+}
-#define RtlInitializeSplayLinks(Links) \
- PRTL_SPLAY_LINKS _SplayLinks; \
- _SplayLinks = (PRTL_SPLAY_LINKS)(Links); \
- _SplayLinks->Parent = _SplayLinks; \
- _SplayLinks->LeftChild = NULL; \
- _SplayLinks->RightChild = NULL;
+FORCEINLINE
+VOID
+PushEntryList(
+ PSINGLE_LIST_ENTRY ListHead,
+ PSINGLE_LIST_ENTRY Entry
+)
+{
+ Entry->Next = ListHead->Next;
+ ListHead->Next = Entry;
+}
-#define RtlInsertAsLeftChild(ParentLinks,ChildLinks) \
- PRTL_SPLAY_LINKS _SplayParent; \
- PRTL_SPLAY_LINKS _SplayChild; \
- _SplayParent = (PRTL_SPLAY_LINKS)(ParentLinks); \
- _SplayChild = (PRTL_SPLAY_LINKS)(ChildLinks); \
- _SplayParent->LeftChild = _SplayChild; \
- _SplayChild->Parent = _SplayParent;
+FORCEINLINE
+BOOLEAN
+RemoveEntryList(
+ IN PLIST_ENTRY Entry)
+{
+ PLIST_ENTRY OldFlink;
+ PLIST_ENTRY OldBlink;
+
+ OldFlink = Entry->Flink;
+ OldBlink = Entry->Blink;
+ OldFlink->Blink = OldBlink;
+ OldBlink->Flink = OldFlink;
+ return (BOOLEAN)(OldFlink == OldBlink);
+}
-#define RtlInsertAsRightChild(ParentLinks,ChildLinks) \
- PRTL_SPLAY_LINKS _SplayParent; \
- PRTL_SPLAY_LINKS _SplayChild; \
- _SplayParent = (PRTL_SPLAY_LINKS)(ParentLinks); \
- _SplayChild = (PRTL_SPLAY_LINKS)(ChildLinks); \
- _SplayParent->RightChild = _SplayChild; \
- _SplayChild->Parent = _SplayParent;
+FORCEINLINE
+PLIST_ENTRY
+RemoveHeadList(
+ IN PLIST_ENTRY ListHead)
+{
+ PLIST_ENTRY Flink;
+ PLIST_ENTRY Entry;
+
+ Entry = ListHead->Flink;
+ Flink = Entry->Flink;
+ ListHead->Flink = Flink;
+ Flink->Blink = ListHead;
+ return Entry;
+}
-/* PROTOTYPES ****************************************************************/
+FORCEINLINE
+PLIST_ENTRY
+RemoveTailList(
+ IN PLIST_ENTRY ListHead)
+{
+ PLIST_ENTRY Blink;
+ PLIST_ENTRY Entry;
+
+ Entry = ListHead->Blink;
+ Blink = Entry->Blink;
+ ListHead->Blink = Blink;
+ Blink->Flink = ListHead;
+ return Entry;
+}
-/*
- * Splay Tree Functions
- */
+//
+// LUID Macros
+//
+#define RtlEqualLuid(L1, L2) (((L1)->HighPart == (L2)->HighPart) && \
+ ((L1)->LowPart == (L2)->LowPart))
+
+#endif
+
+//
+// RTL Splay Tree Functions
+//
NTSYSAPI
PRTL_SPLAY_LINKS
NTAPI
NTAPI
RtlRealPredecessor(PRTL_SPLAY_LINKS Links);
-/*
- * Error and Exception Functions
- */
+#define RtlIsLeftChild(Links) \
+ (RtlLeftChild(RtlParent(Links)) == (PRTL_SPLAY_LINKS)(Links))
+
+#define RtlIsRightChild(Links) \
+ (RtlRightChild(RtlParent(Links)) == (PRTL_SPLAY_LINKS)(Links))
+
+#define RtlRightChild(Links) \
+ ((PRTL_SPLAY_LINKS)(Links))->RightChild
+
+#define RtlIsRoot(Links) \
+ (RtlParent(Links) == (PRTL_SPLAY_LINKS)(Links))
+
+#define RtlLeftChild(Links) \
+ ((PRTL_SPLAY_LINKS)(Links))->LeftChild
+
+#define RtlParent(Links) \
+ ((PRTL_SPLAY_LINKS)(Links))->Parent
+
+#define RtlInitializeSplayLinks(Links) \
+ { \
+ PRTL_SPLAY_LINKS _SplayLinks; \
+ _SplayLinks = (PRTL_SPLAY_LINKS)(Links); \
+ _SplayLinks->Parent = _SplayLinks; \
+ _SplayLinks->LeftChild = NULL; \
+ _SplayLinks->RightChild = NULL; \
+ }
+
+#define RtlInsertAsLeftChild(ParentLinks,ChildLinks) \
+ { \
+ PRTL_SPLAY_LINKS _SplayParent; \
+ PRTL_SPLAY_LINKS _SplayChild; \
+ _SplayParent = (PRTL_SPLAY_LINKS)(ParentLinks); \
+ _SplayChild = (PRTL_SPLAY_LINKS)(ChildLinks); \
+ _SplayParent->LeftChild = _SplayChild; \
+ _SplayChild->Parent = _SplayParent; \
+ }
+
+#define RtlInsertAsRightChild(ParentLinks,ChildLinks) \
+ { \
+ PRTL_SPLAY_LINKS _SplayParent; \
+ PRTL_SPLAY_LINKS _SplayChild; \
+ _SplayParent = (PRTL_SPLAY_LINKS)(ParentLinks); \
+ _SplayChild = (PRTL_SPLAY_LINKS)(ChildLinks); \
+ _SplayParent->RightChild = _SplayChild; \
+ _SplayChild->Parent = _SplayParent; \
+ }
+
+//
+// Error and Exception Functions
+//
NTSYSAPI
PVOID
NTAPI
IN PVOID ReturnValue
);
-/*
- * Heap Functions
- */
-
+//
+// Heap Functions
+//
NTSYSAPI
PVOID
NTAPI
#define RtlGetProcessHeap() (NtCurrentPeb()->ProcessHeap)
-
-/*
- * Security Functions
- */
+//
+// Security Functions
+//
NTSYSAPI
NTSTATUS
NTAPI
IN HANDLE Token
);
-/*
- * Single-Character Functions
- */
+//
+// Single-Character Functions
+//
NTSYSAPI
NTSTATUS
NTAPI
PULONG Value
);
-#if (defined(_M_IX86) && (_MSC_FULL_VER > 13009037)) || ((defined(_M_AMD64) || defined(_M_IA64)) && (_MSC_FULL_VER > 13009175))
+//
+// Byte Swap Functions
+//
+#if (defined(_M_IX86) && (_MSC_FULL_VER > 13009037)) || \
+ ((defined(_M_AMD64) || \
+ defined(_M_IA64)) && (_MSC_FULL_VER > 13009175))
+
unsigned short __cdecl _byteswap_ushort(unsigned short);
unsigned long __cdecl _byteswap_ulong (unsigned long);
unsigned __int64 __cdecl _byteswap_uint64(unsigned __int64);
#define RtlUshortByteSwap(_x) _byteswap_ushort((USHORT)(_x))
#define RtlUlongByteSwap(_x) _byteswap_ulong((_x))
#define RtlUlonglongByteSwap(_x) _byteswap_uint64((_x))
+
#else
USHORT
#endif
-/*
- * Unicode->Ansi String Functions
- */
+//
+// Unicode->Ansi String Functions
+//
NTSYSAPI
ULONG
NTAPI
RtlxUnicodeStringToAnsiSize(IN PCUNICODE_STRING UnicodeString);
#ifdef NTOS_MODE_USER
+
#define RtlUnicodeStringToAnsiSize(STRING) ( \
NLS_MB_CODE_PAGE_TAG ? \
RtlxUnicodeStringToAnsiSize(STRING) : \
((STRING)->Length + sizeof(UNICODE_NULL)) / sizeof(WCHAR) \
)
+
#endif
NTSYSAPI
BOOLEAN AllocateDestinationString
);
-/*
- * Unicode->OEM String Functions
- */
+//
+// Unicode->OEM String Functions
+//
NTSYSAPI
NTSTATUS
NTAPI
RtlxUnicodeStringToOemSize(IN PCUNICODE_STRING UnicodeString);
#ifdef NTOS_MODE_USER
-#define RtlUnicodeStringToOemSize(STRING) ( \
- NLS_MB_OEM_CODE_PAGE_TAG ? \
- RtlxUnicodeStringToOemSize(STRING) : \
- ((STRING)->Length + sizeof(UNICODE_NULL)) / sizeof(WCHAR) \
+
+#define RtlUnicodeStringToOemSize(STRING) ( \
+ NLS_MB_OEM_CODE_PAGE_TAG ? \
+ RtlxUnicodeStringToOemSize(STRING) : \
+ ((STRING)->Length + sizeof(UNICODE_NULL)) / sizeof(WCHAR) \
)
-#define RtlUnicodeStringToCountedOemSize(STRING) ( \
- (ULONG)(RtlUnicodeStringToOemSize(STRING) - sizeof(ANSI_NULL)) \
+
+#define RtlUnicodeStringToCountedOemSize(STRING) ( \
+ (ULONG)(RtlUnicodeStringToOemSize(STRING) - sizeof(ANSI_NULL)) \
)
+
#endif
NTSYSAPI
ULONG UnicodeSize
);
-/*
- * Unicode->MultiByte String Functions
- */
+//
+// Unicode->MultiByte String Functions
+//
NTSYSAPI
NTSTATUS
NTAPI
NTAPI
RtlxOemStringToUnicodeSize(IN PCOEM_STRING OemString);
-/*
- * OEM to Unicode Functions
- */
-#ifdef NTOS_MODE_USER
-#define RtlOemStringToUnicodeSize(STRING) ( \
- NLS_MB_OEM_CODE_PAGE_TAG ? \
- RtlxOemStringToUnicodeSize(STRING) : \
- ((STRING)->Length + sizeof(ANSI_NULL)) * sizeof(WCHAR) \
-)
-#define RtlOemStringToCountedUnicodeSize(STRING) ( \
- (ULONG)(RtlOemStringToUnicodeSize(STRING) - sizeof(UNICODE_NULL)) \
-)
-#endif
-
+//
+// OEM to Unicode Functions
+//
NTSYSAPI
NTSTATUS
NTAPI
ULONG BytesInOemString
);
-/*
- * Ansi->Unicode String Functions
- */
+#ifdef NTOS_MODE_USER
+
+#define RtlOemStringToUnicodeSize(STRING) ( \
+ NLS_MB_OEM_CODE_PAGE_TAG ? \
+ RtlxOemStringToUnicodeSize(STRING) : \
+ ((STRING)->Length + sizeof(ANSI_NULL)) * sizeof(WCHAR) \
+)
+
+#define RtlOemStringToCountedUnicodeSize(STRING) ( \
+ (ULONG)(RtlOemStringToUnicodeSize(STRING) - sizeof(UNICODE_NULL)) \
+)
+
+#endif
+
+//
+// Ansi->Unicode String Functions
+//
NTSYSAPI
ULONG
NTAPI
);
#ifdef NTOS_MODE_USER
-#define RtlAnsiStringToUnicodeSize(STRING) ( \
- NLS_MB_CODE_PAGE_TAG ? \
- RtlxAnsiStringToUnicodeSize(STRING) : \
- ((STRING)->Length + sizeof(ANSI_NULL)) * sizeof(WCHAR) \
+
+#define RtlAnsiStringToUnicodeSize(STRING) ( \
+ NLS_MB_CODE_PAGE_TAG ? \
+ RtlxAnsiStringToUnicodeSize(STRING) : \
+ ((STRING)->Length + sizeof(ANSI_NULL)) * sizeof(WCHAR) \
)
+
#endif
NTSYSAPI
IN PCSZ Source
);
-/*
- * Unicode String Functions
- */
+//
+// Unicode String Functions
+//
NTSYSAPI
NTSTATUS
NTAPI
);
#ifdef NTOS_MODE_USER
+
NTSYSAPI
NTSTATUS
NTAPI
IN PCUNICODE_STRING UniSource,
IN BOOLEAN AllocateDestinationString
);
+
#endif
NTSYSAPI
ULONG *Flags
);
+NTSYSAPI
+BOOLEAN
+NTAPI
+RtlPrefixString(
+ PCANSI_STRING String1,
+ PCANSI_STRING String2,
+ BOOLEAN CaseInsensitive
+);
+
NTSYSAPI
BOOLEAN
NTAPI
PULONG Value
);
-/*
- * Ansi String Functions
- */
+//
+// Ansi String Functions
+//
NTSYSAPI
VOID
NTAPI
PCSZ SourceString
);
-/*
- * OEM String Functions
- */
+//
+// OEM String Functions
+//
NTSYSAPI
VOID
NTAPI
RtlFreeOemString(IN POEM_STRING OemString);
-/*
- * MultiByte->Unicode String Functions
- */
+//
+// MultiByte->Unicode String Functions
+//
NTSYSAPI
NTSTATUS
NTAPI
ULONG MbSize
);
-/*
- * Atom Functions
- */
+//
+// Atom Functions
+//
NTSYSAPI
NTSTATUS
NTAPI
IN OUT PULONG NameLength OPTIONAL
);
+NTSYSAPI
+NTSTATUS
+NTAPI
+RtlPinAtomInAtomTable(
+ IN PRTL_ATOM_TABLE AtomTable,
+ IN RTL_ATOM Atom
+);
+
NTSYSAPI
NTSTATUS
NTAPI
OUT PRTL_ATOM Atom
);
-/*
- * Memory Functions
- */
+//
+// Memory Functions
+//
NTSYSAPI
VOID
NTAPI
IN ULONG Fill
);
-/*
- * Process Management Functions
- */
+//
+// Process Management Functions
+//
NTSYSAPI
VOID
NTAPI
IN BOOLEAN IsWinlogon
);
-/*
- * Environment/Path Functions
- */
+static __inline
+struct _PEB*
+NtCurrentPeb(VOID)
+{
+ struct _PEB *pPeb;
+
+#if defined(__GNUC__)
+
+ __asm__ __volatile__
+ (
+ "movl %%fs:0x30, %0\n" /* fs:30h == Teb->Peb */
+ : "=r" (pPeb) /* can't have two memory operands */
+ : /* no inputs */
+ );
+
+#elif defined(_MSC_VER)
+
+ __asm mov eax, fs:0x30;
+ __asm mov pPeb, eax
+
+#else
+#error Unknown compiler for inline assembler
+#endif
+
+ return pPeb;
+}
+
+//
+// Environment/Path Functions
+//
NTSYSAPI
NTSTATUS
NTAPI
PUNICODE_STRING Value
);
-/*
- * Critical Section/Resource Functions
- */
+//
+// Critical Section/Resource Functions
+//
NTSYSAPI
NTSTATUS
NTAPI
IN PRTL_RESOURCE Resource
);
-/*
- * Compression Functions
- */
+//
+// Compression Functions
+//
NTSYSAPI
NTSTATUS
NTAPI
OUT PULONG CompressFragmentWorkSpaceSize
);
-/*
- * Debug Info Functions
- */
+//
+// Debug Info Functions
+//
NTSYSAPI
-PDEBUG_BUFFER
+PRTL_DEBUG_BUFFER
NTAPI
RtlCreateQueryDebugBuffer(
IN ULONG Size,
NTSYSAPI
NTSTATUS
NTAPI
-RtlDestroyQueryDebugBuffer(IN PDEBUG_BUFFER DebugBuffer);
+RtlDestroyQueryDebugBuffer(IN PRTL_DEBUG_BUFFER DebugBuffer);
NTSYSAPI
NTSTATUS
RtlQueryProcessDebugInformation(
IN ULONG ProcessId,
IN ULONG DebugInfoClassMask,
- IN OUT PDEBUG_BUFFER DebugBuffer
+ IN OUT PRTL_DEBUG_BUFFER DebugBuffer
);
-/*
- * Bitmap Functions
- */
+//
+// Bitmap Functions
+//
NTSYSAPI
BOOLEAN
NTAPI
IN ULONG NumberToSet
);
-/*
- * Timer Functions
- */
+//
+// Timer Functions
+//
NTSYSAPI
NTSTATUS
NTAPI
NTAPI
RtlDeleteTimerQueue(HANDLE TimerQueue);
-/*
- * Debug Functions
- */
+//
+// Debug Functions
+//
ULONG
__cdecl
DbgPrint(
NTAPI
DbgBreakPoint(VOID);
-/*
- * Handle Table Functions
- */
+//
+// Handle Table Functions
+//
NTSYSAPI
PRTL_HANDLE_TABLE_ENTRY
NTAPI
OUT PRTL_HANDLE_TABLE_ENTRY *Handle
);
-/*
- * PE Functions
- */
+//
+// PE Functions
+//
NTSYSAPI
NTSTATUS
NTAPI
ULONG Rva
);
-/*
- * Registry Functions
- */
+//
+// Registry Functions
+//
NTSYSAPI
NTSTATUS
NTAPI
ULONG ValueLength
);
-/*
- * NLS Functions
- */
+//
+// NLS Functions
+//
NTSYSAPI
VOID
NTAPI
NTAPI
RtlResetRtlTranslations(IN PNLSTABLEINFO NlsTable);
-/*
- * Misc conversion functions
- */
#if defined(NTOS_MODE_USER) && !defined(NO_RTL_INLINES)
+
+//
+// Misc conversion functions
+//
static __inline
LARGE_INTEGER
NTAPI_INLINE
-RtlConvertLongToLargeInteger(LONG SignedInteger)
+RtlConvertLongToLargeInteger(
+ LONG SignedInteger
+)
{
LARGE_INTEGER Result;
NTAPI_INLINE
RtlEnlargedIntegerMultiply(
LONG Multiplicand,
- LONG Multiplier)
+ LONG Multiplier
+)
{
LARGE_INTEGER Product;
RtlEnlargedUnsignedDivide(
IN ULARGE_INTEGER Dividend,
IN ULONG Divisor,
- IN PULONG Remainder OPTIONAL)
+ IN PULONG Remainder OPTIONAL
+)
{
ULONG Quotient;
NTAPI_INLINE
RtlEnlargedUnsignedMultiply(
ULONG Multiplicand,
- ULONG Multiplier)
+ ULONG Multiplier
+)
{
LARGE_INTEGER Product;
NTAPI
RtlUniform(PULONG Seed);
-/*
- * Network Functions
- */
+//
+// Network Functions
+//
NTSYSAPI
NTSTATUS
NTAPI
OUT PULONG IpAddr
);
-/*
- * Time Functions
- */
+//
+// Time Functions
+//
NTSYSAPI
NTSTATUS
NTAPI
PTIME_FIELDS TimeFields
);
-/*
- * Version Functions
- */
+//
+// Version Functions
+//
NTSYSAPI
NTSTATUS
NTAPI
NTAPI
RtlGetNtProductType(OUT PNT_PRODUCT_TYPE ProductType);
-static __inline struct _PEB* NtCurrentPeb (void)
-{
- struct _PEB * pPeb;
-
-#if defined(__GNUC__)
-
- __asm__ __volatile__
- (
- "movl %%fs:0x30, %0\n" /* fs:30h == Teb->Peb */
- : "=r" (pPeb) /* can't have two memory operands */
- : /* no inputs */
- );
-
-#elif defined(_MSC_VER)
-
- __asm mov eax, fs:0x30;
- __asm mov pPeb, eax
-
-#else
-#error Unknown compiler for inline assembler
-#endif
-
- return pPeb;
-}
#endif