title: ReadProcessMemory fails on some Pages (GetLastError()=299)
body: <p>I try to read all commited pages of a process (Win7-64). On most pages it works but it fails for a few pages. I cannot explain why. Here is my test programme (compiled x32, tested in Win7-64):</p>
  
  <pre><code>#include &lt;windows.h&gt;
  
  void main()
  {
      HANDLE hProc = OpenProcess(PROCESS_VM_READ | PROCESS_QUERY_INFORMATION,FALSE,GetCurrentProcessId());
  
      SYSTEM_INFO si;
      ZeroMemory(&amp;si,sizeof(SYSTEM_INFO));
      GetSystemInfo(&amp;si);
  
      char* buf = new char[si.dwPageSize];
  
      for (unsigned i = 0; i &lt; 0x7fff0; i++)
      {
          void* baseOffs = (void*) (i * si.dwPageSize);
          MEMORY_BASIC_INFORMATION mbi;
          ZeroMemory(&amp;mbi,sizeof(MEMORY_BASIC_INFORMATION));
  
          if (VirtualQueryEx(hProc, baseOffs, &amp;mbi, sizeof(MEMORY_BASIC_INFORMATION)) == 0)
          {
              MessageBox(NULL, TEXT("VirtualQueryEx failed"),TEXT(""),MB_OK);
          }
  
          if (mbi.State == MEM_COMMIT)
          {
              SIZE_T numByteWritten = 0;
              if(ReadProcessMemory(hProc, baseOffs,buf,si.dwPageSize,&amp;numByteWritten) == FALSE)
                  OutputDebugString(TEXT("bad\n")); //GetLastError()==ERROR_PARTIALLY_READ; numByteWritten == 0;
              else
                  OutputDebugString(TEXT("good\n"));
  
          }
      }
  
      delete[] buf;
  }
  </code></pre>
  
  <p>I tired to look into the MEMORY_BASIC_INFORMATION for the failing pages but I didn't find anything strange there. Also the number of failing pages varies from run to run (in average about 5). WHat prevents me from reading these pages? Do I need to adjust some privilges in the process token?</p>