title: Encrypt a memory page frame using C code
body: <p>I am a bit new to systems programming.This is my setup :</p>
  
  <ol>
  <li><p>I have a test application running inside a vm which is running through qemu  that issues a system call (with virtual address and size as parameters) to the os. So, when we issue this system call, the os from the kernel mode issues a new instruction to be run using qemu. On receiving this instruction, qemu will mark certain 4K physical frames.</p></li>
  <li><p>What I need/require is whenever a certain PTE is marked (using a non-used bit),I need to encrypt the corresponding 4k frames using a randomly generated key.</p></li>
  </ol>
  
  <p>How do I perform this?I know it has to be done by modifying the qemu source code, getting the PTE and then encrypting the appropriate page frame. I get to the point where I find the right PTE.But after that, not able to proceed as to how one can encrypt the page frames.Can anyone please give a pseudo code or any directions? Any help is greatly appreciated.I am pondering over this for more than a week and am essentially clueless.</p>