title: How to set memory region's protection in kernel mode under Windows 7
body: <p>Essentially I am looking for a function that could do for kernel mode what <code>VirtualProtect</code> does for user mode.</p>
  
  <p>I am allocating memory using a logic exemplified by the following simplified code.</p>
  
  <pre><code>    PMDL mdl = MmAllocatePagesForMdl    
      (
          LowAddress,
          HighAddress,
          SkipAddress,
          size
      );
  
      ULONG flags = NormalPagePriority | MdlMappingNoExecute | MdlMappingNoWrite;
      PVOID ptr = MmGetSystemAddressForMdlSafe
      (
          mdl, 
          flags
      );
  </code></pre>
  
  <p>The <code>MdlMappingNoExecute</code> and <code>MdlMappingNoWrite</code> flags will have effect only on Win8+. 
  <br>Moreover, using only <code>MmGetSystemAddressForMdlSafe</code> I cannot assign for example <strong><code>NoAccess</code></strong> protection for the memory region.</p>
  
  <p>Are there any additional or alternative API-s I could use so that I can modify the page protection of the allocated memory? 
  <br>A hack would do too since currently this functionality would not be in use in production code.</p>