https://cloud.tencent.com/developer/article/1875879

    1. #include <ntddk.h>
    2. typedef struct _TestListEntry {
    3. ULONG m_ulDataA;
    4. ULONG m_ulDataB;
    5. LIST_ENTRY m_ListEntry;
    6. ULONG m_ulDataC;
    7. ULONG m_ulDataD;
    8. }TestListEntry,*PTestListEntry;
    9. VOID Unload(IN PDRIVER_OBJECT DriverObject) {
    10. if (DriverObject!=NULL)
    11. {
    12. KdPrint(("driver unload \r\n"));
    13. DbgPrint("hello kernel currentProcessId = 0x%p\n", PsGetCurrentProcessId());
    14. }
    15. return;
    16. }
    17. NTSTATUS DriverEntry(IN PDRIVER_OBJECT DriverObject,IN PUNICODE_STRING RegisteryPath) {
    18. DriverObject->DriverUnload = Unload;
    19. KdBreakPoint();
    20. //link list;
    21. LIST_ENTRY ListHeader = { 0 };
    22. InitializeListHead(&ListHeader);
    23. TestListEntry EntryA = { 0 };
    24. EntryA.m_ulDataA = 'A';
    25. TestListEntry EntryB = { 0 };
    26. EntryB.m_ulDataA = 'B';
    27. TestListEntry EntryC = { 0 };
    28. EntryC.m_ulDataA = 'C';
    29. InsertHeadList(&ListHeader,&EntryB.m_ListEntry);
    30. InsertHeadList(&ListHeader, &EntryA.m_ListEntry);
    31. InsertTailList(&ListHeader, &EntryC.m_ListEntry);
    32. //Heander->A->B->C
    33. //遍历
    34. //flink 从前往后
    35. DbgPrint("FLINK BROSWER\n");
    36. PLIST_ENTRY pListEnrty = NULL;
    37. pListEnrty = ListHeader.Flink;
    38. while (pListEnrty!=&ListHeader)
    39. {
    40. PTestListEntry pTestEnrty = CONTAINING_RECORD(pListEnrty, TestListEntry, m_ListEntry);
    41. DbgPrint("listPtr = %p,Enrty = %p,Tag = %c\n",pListEnrty,pTestEnrty,(CHAR)pTestEnrty->m_ulDataA);
    42. pListEnrty = pListEnrty->Flink;
    43. }
    44. //blink 从后往前
    45. DbgPrint("remove node\n");
    46. //
    47. //RemoveHeadList();
    48. //RemoveTailList();
    49. //RemoveEntryList();
    50. //IsListEmpty();
    51. return STATUS_SUCCESS;
    52. }