#pragma alloc_text (PAGE, function_name)

#pramga alloc_text(PAGE, foo) void foo(){ return; } 

This code is commonly used in device drivers.
The foo function will be replaced whenever the system is needed.

Questions.

  • Does it work in user space code? Will the function also be unloaded?
  • Without pragma, I mean, by default, do all kernel-level functions allocate non-paged memory?
  • Does the PE loader execute where the functions are distributed?
+4
source share
2 answers

By default, user-mode programs are loaded. Unusually, you need something else. It seems that the device driver requirement should be resident to handle interrupts or such things. User mode programs do not.

+2
source

If you compile a simple hello world driver, you will see that the "Cannot use pages" flag will be set in the PE (Portable Executable) section called ".text". So yes, by default, all driver code is in this section, if you do not mark it as accessible for the page, which will lead to its completion in the "PAGE" section, and not in the ".text" section.

+2
source

Source: https://habr.com/ru/post/1341500/


All Articles