InsertHeadList - NtDoc

Native API online documentation, based on the System Informer (formerly Process Hacker) phnt headers
#ifndef _NTRTL_H

FORCEINLINE
VOID
NTAPI_INLINE
InsertHeadList(
    _Inout_ PLIST_ENTRY ListHead,
    _Inout_ __drv_aliasesMem PLIST_ENTRY Entry
    )
{
    PLIST_ENTRY NextEntry;

    NextEntry = ListHead->Flink;

#if !defined(NO_LIST_ENTRY_CHECKS)
    RtlCheckListEntry(ListHead);

    if (NextEntry->Blink != ListHead) 
    {
        RtlFatalListEntryError((PVOID)ListHead, (PVOID)NextEntry, (PVOID)NextEntry->Blink);
    }
#endif

    Entry->Flink = NextEntry;
    Entry->Blink = ListHead;
    NextEntry->Blink = Entry;
    ListHead->Flink = Entry;
}

#endif

View code on GitHub
// wdm.h

VOID InsertHeadList(
  [in, out] PLIST_ENTRY                  ListHead,
  [in, out] __drv_aliasesMem PLIST_ENTRY Entry
);

View the official Windows Driver Kit DDI reference

NtDoc

This function is documented in Windows Driver Kit.

Windows Driver Kit DDI reference (nf-wdm-insertheadlist)

InsertHeadList function

Description

The InsertHeadList routine inserts an entry at the head of a doubly linked list of LIST_ENTRY structures.

Parameters

ListHead [in, out]

Pointer to the LIST_ENTRY structure that represents the head of the list.

Entry [in, out]

Pointer to a LIST_ENTRY structure that represents the entry to be inserted into the list.

Remarks

InsertHeadList updates ListHead->Flink to point to Entry. It updates Entry->Flink to point to the old first entry in the list, and sets Entry->Blink to ListHead. The Blink field of the original first entry is also updated to point to Entry.

For information about using this routine when implementing a doubly linked list, see Singly and Doubly Linked Lists.

Callers of InsertHeadList can be running at any IRQL. If InsertHeadList is called at IRQL >= DISPATCH_LEVEL, the storage for ListHead and the list entries must be resident.

See also

ExInterlockedInsertHeadList

InitializeListHead

InsertTailList

IsListEmpty

RemoveHeadList

RemoveTailList