#pragma alloc_text(PAGE) 代码未页对齐
我面临着 WinXP 32 位 DDK(一个相当旧的版本:3590)的(可能)问题。我的驱动程序包含一些未初始化的静态变量(我想它们应该分配给 .bss 部分)和可分页代码部分中的一些函数(用 #pragma alloc_page(PAGE, func) 标记)。可分页代码收集在单独的目标文件中。我发现链接器似乎将静态数据和可分页代码分配到内核地址空间中的同一页(即变量位于 0xEFFCB0A0,函数位于 0xEFFCB600 - 使用 Windbg 进行验证)。静态变量在中断环境中使用,因此它们的页面必须在内存中锁定。但如果同一页面包含可交换代码,恐怕变量会突然消失。链接器的映射正确报告可分页代码位于不同的部分(“PAGE”)中,但偏移量(“Rva+Base”)位于包含静态信息的页面的中间。
如何强制链接器/加载器将单独的页面分配给可分页代码?是否有一些“#pragma”来强制部分对齐属性?我做错了什么吗?
PS:驱动程序加载器肯定足够聪明,可以将包含变量和代码的页面从分页池中取出,但由于该页面包含变量,因此它必须是可写的。我希望可执行代码位于只读页面中。内核模式下错误的数组访问仍然很难调试...
PPS:在我的函数之前和之后添加了 4096 个“nop”...好吧,它有效...没有什么更好的建议吗?
I'm facing a (possible) problem with DDK (a quite old version: 3590) for WinXP 32 bit. My driver contains some static variables not inizialized (they should be assigned to .bss section, I suppose) and some functions in a pageable code section (marked with #pragma alloc_page(PAGE, func)). The pageable code is collected in a separate object file. I have discovered that the linker seems to assign the statics and the pageable code to the same page in the kernel address space (i.e. the variable is at 0xEFFCB0A0 and the function is at 0xEFFCB600 - verified with windbg). The static variables are used in an interrupt environment, so their pages must be locked in memory. But if the same page contains swappable code I am afraid the variables can suddenly disappear. The linker's map reports correctly that the pageable code is in a different section ("PAGE"), but the offset ("Rva+Base") is in the middle of a page that contains the statics.
How can I force the linker/loader to assign separate pages to the pageable code? Is there some "#pragma" to force the section alignment attibute? Am I doing something wrong?
PS: The driver loader is surely smart enough to put the page containg both variables and code out of the paged pool, but since the page contains variables it must be writable. I'd prefer that the executable code was in a read-only page. Wrong array accesses in kernel mode are yet so difficult to debug...
PPS: Added 4096 "nop"s before and after my function... ok, it works... nothing better to suggest?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
将全局变量放在自己的数据段中:
来源: data_seg 上的 MSDN 链接
默认情况下,您的部分将使用读/写标志创建,而不是分页标志。
您可以指定其他部分选项:
来源:/SECTION 上的 MSDN 链接
或您可以将链接器选项放在
SOURCES
文件中:注意:如果您正在构建库,请改用
LIBRARIAN_FLAGS
Place your globals in their own data segment:
source: MSDN link on data_seg
By default your section will be created with read/write, and not paged flags.
You can specify additional section options:
source: MSDN link on /SECTION
or you can place your linker options in the
SOURCES
file:NOTE: if you are building a library, use
LIBRARIAN_FLAGS
instead