Debug for Windows

來源:互聯網
上載者:User

1.

NTSTATUS RtlStringCbLength(  _In_       LPCTSTR psz,  _In_       size_t cbMax,  _Out_opt_  size_t *pcb);

cbMax [in]

The maximum number of bytes allowed in the buffer that is pointed to by psz, including the terminating null character.

 

RtlStringCbLength中的cbMax包含最後的'\0',而strlen則不包含。

2.ExAllocatePool

如同C裡面的malloc一樣,核心模式下的ExAllocatePool也是非常重要的.但是一說到ExAllocatePool函數就不得不提ExAllocatePoolWithTag函數.對比一下兩個函數的調用方式:

     PVOID p = ExAllocatePool(Pool_Type, Size);

    PVOID p = ExAllocatePoolWithTag(Pool_Type, Size, Tag);

    在調用ExAllocatePoolWithTag的時候,系統會在要求的記憶體大小的基礎上再額外多分配4個位元組的標籤.這個標籤佔用了開始的4個位元組,位於返回指標所指向地址的前面.這樣,當調試時這個標籤可以協助你識別有問題的記憶體塊.

   在WDM.H(NTDDK.H)中聲明了,記憶體配置函數無條件受預先處理宏POOL_TAGGING控制(POOL_TAGGING被無條件的定義).因此,即便是調用的ExAllocatePool函數,實際執行的卻是:ExAllocatePoolWithTag,其加入的標籤為"mdW",指明是WDM的記憶體塊.

   又或者你強行關閉POOL_TAGGING宏再去調用ExAllocatePool,實際執行的還是ExAllocatePoolWithTag,並帶標籤"enoN".

   因此,建議在分配記憶體時,直接調用ExAllocatePoolWithTag並加上一個自訂的標籤.

 

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.