title: Can native code cause memory corruption in Java code in Android?
body: <p>In Android, when we call native code via JNI, can it corrupt the Dalvik VM, and the Java code running inside it?</p>
  
  <p>For example, suppose we have this C method and we call it via JNI:</p>
  
  <pre><code>JNIEXPORT void JNICALL Java_MemoryCorruptor_corruptMemory()
  {
      while (1) {
          char *p = randomAddress();
          *p = randomChar();
      }
  }
  </code></pre>
  
  <p>If the VM just loads the .so files and the native code is running in the <strong>same context/address space</strong> as the VM, then I assume the VM could get corrupted.</p>
  
  <p>On the other hand, if the VM creates a child process to hold the .so files and uses some form of IPC to call methods, then the Java code can't get corrupted by the native code.</p>