Posted on 2008-09-28 10:17
沒(méi)畫完的畫 閱讀(350)
評(píng)論(0) 編輯 收藏 引用 所屬分類:
VC
1. naked function
裸函數(shù), vc特有語(yǔ)法, 一旦在函數(shù)加上 __declspec(naked) 聲明,
編譯器不會(huì)給函數(shù)加上任何優(yōu)化和匯編語(yǔ)句
即, 你需要自己用匯編語(yǔ)句實(shí)現(xiàn)讀取參數(shù)(如果有參數(shù)的話)
到最好還要用 ret 來(lái)返回, 聲明語(yǔ)法
void __declspec(naked) MyNakedFunction()
{
_asm
{
}
}
注: 1. 只能用于聲明函數(shù),不能修飾變量
2. 不能用于函數(shù)前向聲明, 前向聲明時(shí)需要把 __declspec(naked) 去掉, 即寫成 void MyNakedFunction();
在函數(shù)體才加上 __declspec(naked)
From MSDN
Functions declared with the naked attribute are emitted without prolog or epilog code, enabling you to write your own custom prolog/epilog
sequences using the inline assembler. Naked functions are provided as an advanced feature. They enable you to declare a function that is
being called from a context other than C/C++, and thus make different assumptions about where parameters are, or which registers are
preserved. Examples include routines such as interrupt handlers. This feature is particularly useful for writers of virtual device drivers
(VxDs). ers (VxDs).
-------------------------------------------------------------------------------------------------------------------------------------------------