解释#ifdef ALLOC_PRAGMA代码段的原理
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.
解释#ifdef ALLOC_PRAGMA代码段的原理的更多相关文章
- 静态库动态库的编译、链接, binutils工具集, 代码段\数据段\bss段解释
#1. 如何使用静态库 制作静态库 (1)gcc *.c -c -I../include得到o文件 (2) ar rcs libMyTest.a *.o 将所有.o文件打包为静态库,r将文件插入静态库 ...
- Visual Studio Code 添加设置代码段(snippet)
从VSCode发布以来就在关注,最近已经更新到版本0.10.8,已经支持了插件功能.日常使用编辑器已经由Sublime Text迁移到了VSCode.使用中遇到了这个问题,在网上也没搜到解决方案.记录 ...
- 【转】 BSS段 数据段 代码段 堆栈 指针 vs 引用
原文:http://blog.csdn.net/godspirits/article/details/2953721 BSS段 数据段 代码段 堆栈 (转+) 声明:大部分来自于维基百科,自由的百科全 ...
- VisualStudio自定义代码段_方法二
1.在项目中新增一个xml文件为vcoo.snippet,然后右键“插入代码段”,选择Snippet即可: 2.修改代码片段内容后保存: 3.VS菜单中选择“工具”-“代码段管理器”导入这个snipp ...
- 数据段描述符和代码段描述符(一)——《x86汇编语言:从实模式到保护模式》读书笔记10
一.段描述符的分类 在上一篇博文中已经说过,为了使用段,我们必须要创建段描述符.80X86中有各种各样的段描述符,下图展示了它们的分类. 看了上图,你也许会说:天啊,怎么这么多段描述符啊!我可怎么记住 ...
- 【Arcgis android】 离线编辑实现及一些代码段
Arcgis android 离线编辑实现及一些代码段 底图添加 private String path="file:///mnt/sdcard/data/chinasimple.tpk&q ...
- Linux从头学03:如何告诉 CPU,代码段、数据段、栈段在内存中什么位置?
作 者:道哥,10+年的嵌入式开发老兵. 公众号:[IOT物联网小镇],专注于:C/C++.Linux操作系统.应用程序设计.物联网.单片机和嵌入式开发等领域. 公众号回复[书籍],获取 Linux. ...
- WPF自定义RoutedEvent事件代码段
今天在写东西的时候,发现常用的代码段里没有RoutedEvent的,因此,写了一个代码段,方便以后使用,顺便记录一下,如何做代码段. 1.在项目中新建一个XML文件,将扩展名修改为snippet. 2 ...
- JavaScript代码段整理笔记系列(二)
上篇介绍了15个常用代码段,本篇将把剩余的15个补齐,希望对大家有所帮助!!! 16.检测Shift.Alt.Ctrl键: event.shiftKey; //检测Shift event.altKey ...
随机推荐
- Unix网络编程 之 基本套接字调用(一)
Unix/Linux支持伯克利风格的套接字编程,它同一时候支持面向连接和面向无连接类型的套接字. 套接字最经常使用的一些系统调用: socket() bind() connect() listen() ...
- windows 中安装及使用 SSH Key
转自 简书技术博客:https://www.jianshu.com/p/a3b4f61d4747 联系管理员开通ssh功能: 重新创建环境: 下载工具包到本地机器wsCli 0.4 解压后,把相应的w ...
- 常用代码之四:创建jason,jason转换为字符串,字符串转换回jason,c#反序列化jason字符串的几个代码片段
1.创建jason,并JSON.stringify()将之转换为字符串. 直接使用var customer={}, 然后直接customer.属性就可以直接赋值了. 也可以var customer = ...
- Navicat for SQL Server(SQLServer数据库管理)
Navicat for SQL Server 是一套专为 Mircosoft SQL Server设计的强大数据库管理及开发工具.它可以用于 SQL Server 2000.2005 及 2008R2 ...
- 有关 WCF 的一些错误处理
错误消息: System.ServiceModel.EndpointNotFoundException: 无法调度消息,因为终结点地址"net.tcp://localhost/xxx.svc ...
- 关于 ASP.NET 中的 Bundle 的补充说明(草稿)
一直以来,都认为 Bundle 有可能会不正确的压缩,而导致脚本出错,所以一直将这个功能处于禁用状态. 突然发现,其实只是自己使用的不对... 目前发现 Bundle 会导致的错误分两种情况: 1.路 ...
- 使用FiddlerCore来截取替换Http请求中的网页内容
做过测试的应该都知道Fiddler,它可以很方便截取Internet上的网页替换成本地的,或者修改其中的一部分内容后呈现.简单地说就是可能监测所有HTTP连接,设置断点,胡乱修改.是测试调试的一件利器 ...
- html5+css3 权威指南阅读笔记(三)---表单及其它新增和改良元素
一.新增元素及属性 1.表单内元素的form属性. html5: <form id="testForm"> <input type=text> </f ...
- Android xUtils3源代码解析之网络模块
本文已授权微信公众号<非著名程序猿>原创首发,转载请务必注明出处. xUtils3源代码解析系列 一. Android xUtils3源代码解析之网络模块 二. Android xUtil ...
- GitBash: 右键添加 Git Bash Here 菜单
步骤: 1.通过在“运行”中输入‘regedit’,打开注册表. 2.找到[HKEY_CLASSES_ROOT\Directory\Background]. 3.在[Background]下如果没有[ ...