博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
解释#ifdef ALLOC_PRAGMA代码段的原理
阅读量:6088 次
发布时间:2019-06-20

本文共 3592 字,大约阅读时间需要 11 分钟。

By default, the kernel loader will load all driver executables and any global data that you may have defined in your driver into nonpaged memory. Therefore, if you want your driver to reside in nonpaged memory, there is nothing further you need to do besides compiling, linking, and loading the driver. 

Furthermore, the kernel loads the entire driver executable (and any associated dynamic link libraries) all at once, before invoking any driver initialization routines. Although it may not make much sense to you at this time, after loading the executable into memory, the kernel loader closes the executable file, allowing a user to delete even the currently executing driver image. 

It is possible to specify to the loader the portions of your driver that you wish to make pageable. This can be done by using the following compiler directive in your driver code:

•ifdef ALLOC_PRAGMA•pragma alloc_text(PAGE, function_namel)•pragma alloc_text(PAGE, function_name2)// You can list additional functions at this point just as the two// functions are listed above ...•endif // ALLOC_PRAGMA

Be careful, though, that you never allow any routine that could possibly be invoked at a high IRQL to be paged out. File system drivers can never allow any code or data to be paged out that might be required to satisfy page fault requests from the NT Virtual Memory Manager.

 It is also possible for a kernel-mode driver to determine at run-time whether certain sections of driver code and/or data should be paged out or locked into memory. To do this, the driver must perform the following actions:

(Note: The functions referenced in a pragma statement must he defined in the same compilation unit as the pragma.)

 • To make a code section pageable, use the following compiler directive in your code:

#ifdef ALLOC_PRAGMA#pragma alloc_text(PAGExxxx, function_namel)#pragma alloc_text(PAGExxxx, function_name2)#endif

where xxxx is an optional, four-character, unique identifier for the driver's pageable section.

 • To make a data section pageable, use the following compiler directive in your code:

#ifdef ALLOC_PRAGMA#pragma data_seg(PAGE)...// Define your pageable data section module here.#pragma data_seg() // Ends the pageable data section.

 • Invoke MmLockPagableCodeSection() and MmLockPagableCodeSectionByHandle( ) to lock code sections that were marked as pageable in memory.

 • Invoke MmLockPagableDataSectionf) and MmLockPagableDataSectionByHandle( ) to lock data sections that were marked as pageable.

 • Invoke MmUnlockPagableImageSection() to unlock any code or datasection that may have been locked using the functions listed above.

 There are two additional routines provided by the VMM that you should be aware of (and look up in the DDK documentation) if you wish to page out the entire driver or reset paging attributes back to their original settings:

MmPageEntireDriver()

This routine will make the entire driver pageable, overriding any section page attributes that were declared earlier using compiler directives.

MmResetDriverPaging()

This function will reset the paging attributes back to the initially declared attributes.

 Finally, to automatically have the Memory Manager discard sections of code that you won't need once the driver has been initialized, use the following compiler directives:

•ifdef ALLOC_PRAGMA•pragma alloc_text(INIT, DriverEntry)•pragma alloc_text(INIT, functionl_called_by_driver_entry)•endif // ALLOC_PRAGMA

 

 Be careful to specify only those functions that can be safely discarded and will never again be required once the driver initialization has been completed.

转载地址:http://cvpwa.baihongyu.com/

你可能感兴趣的文章
MySQL入门12-数据类型
查看>>
Windows Azure 保留已存在的虚拟网络外网IP(云服务)
查看>>
修改字符集
查看>>
HackTheGame 攻略 - 第四关
查看>>
js删除数组元素
查看>>
带空格文件名的处理(find xargs grep ..etc)
查看>>
华为Access、Hybrid和Trunk的区别和设置
查看>>
centos使用docker下安装mysql并配置、nginx
查看>>
关于HTML5的理解
查看>>
需要学的东西
查看>>
Internet Message Access Protocol --- IMAP协议
查看>>
Linux 获取文件夹下的所有文件
查看>>
对 Sea.js 进行配置(一) seajs.config
查看>>
第六周
查看>>
解释一下 P/NP/NP-Complete/NP-Hard 等问题
查看>>
javafx for android or ios ?
查看>>
微软职位内部推荐-Senior Software Engineer II-Sharepoint
查看>>
sql 字符串操作
查看>>
【转】Android布局优化之ViewStub
查看>>
网络安全管理技术作业-SNMP实验报告
查看>>