Print this page
rev 6871 : 8058715: stability issues when being launched as an embedded JVM via JNI
Summary: Use mmap call without MAP_FIXED so we avoid corrupting already allocated memory
Reviewed-by: coleenp, dsimms

Split Split Close
Expand all
Collapse all
          --- old/src/os_cpu/linux_x86/vm/os_linux_x86.cpp
          +++ new/src/os_cpu/linux_x86/vm/os_linux_x86.cpp
↓ open down ↓ 901 lines elided ↑ open up ↑
 902  902     *
 903  903     *   TASK_LIMIT= 3G, main stack base close to TASK_LIMT.
 904  904     *
 905  905     * A few pages south main stack will do it.
 906  906     *
 907  907     * If we are embedded in an app other than launcher (initial != main stack),
 908  908     * we don't have much control or understanding of the address space, just let it slide.
 909  909     */
 910  910    char* hint = (char*) (Linux::initial_thread_stack_bottom() -
 911  911                          ((StackYellowPages + StackRedPages + 1) * page_size));
 912      -  char* codebuf = os::reserve_memory(page_size, hint);
      912 +  char* codebuf = os::attempt_reserve_memory_at(page_size, hint);
 913  913    if ( (codebuf == NULL) || (!os::commit_memory(codebuf, page_size, true)) ) {
 914  914      return; // No matter, we tried, best effort.
 915  915    }
 916  916    if (PrintMiscellaneous && (Verbose || WizardMode)) {
 917  917       tty->print_cr("[CS limit NX emulation work-around, exec code at: %p]", codebuf);
 918  918    }
 919  919  
 920  920    // Some code to exec: the 'ret' instruction
 921  921    codebuf[0] = 0xC3;
 922  922  
 923  923    // Call the code in the codebuf
 924  924    __asm__ volatile("call *%0" : : "r"(codebuf));
 925  925  
 926  926    // keep the page mapped so CS limit isn't reduced.
 927  927  #endif
 928  928  }
    
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX