src/os_cpu/linux_x86/vm/assembler_linux_x86.cpp

Wed, 25 Sep 2013 13:58:13 +0200

author
dsimms
date
Wed, 25 Sep 2013 13:58:13 +0200
changeset 5781
899ecf76b570
parent 4318
cd3d6a6b95d9
child 6876
710a3c8b516e
permissions
-rw-r--r--

8023956: Provide a work-around to broken Linux 32 bit "Exec Shield" using CS for NX emulation (crashing with SI_KERNEL)
Summary: Execute some code at a high virtual address value, and keep mapped
Reviewed-by: coleenp, zgu

     1 /*
     2  * Copyright (c) 1999, 2010, Oracle and/or its affiliates. All rights reserved.
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     4  *
     5  * This code is free software; you can redistribute it and/or modify it
     6  * under the terms of the GNU General Public License version 2 only, as
     7  * published by the Free Software Foundation.
     8  *
     9  * This code is distributed in the hope that it will be useful, but WITHOUT
    10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
    11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
    12  * version 2 for more details (a copy is included in the LICENSE file that
    13  * accompanied this code).
    14  *
    15  * You should have received a copy of the GNU General Public License version
    16  * 2 along with this work; if not, write to the Free Software Foundation,
    17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
    18  *
    19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
    20  * or visit www.oracle.com if you need additional information or have any
    21  * questions.
    22  *
    23  */
    25 #include "precompiled.hpp"
    26 #include "asm/macroAssembler.hpp"
    27 #include "asm/macroAssembler.inline.hpp"
    28 #include "runtime/os.hpp"
    29 #include "runtime/threadLocalStorage.hpp"
    31 #ifndef _LP64
    32 void MacroAssembler::int3() {
    33   call(RuntimeAddress(CAST_FROM_FN_PTR(address, os::breakpoint)));
    34 }
    36 #ifdef MINIMIZE_RAM_USAGE
    38 void MacroAssembler::get_thread(Register thread) {
    39   // call pthread_getspecific
    40   // void * pthread_getspecific(pthread_key_t key);
    41   if (thread != rax) push(rax);
    42   push(rcx);
    43   push(rdx);
    45   push(ThreadLocalStorage::thread_index());
    46   call(RuntimeAddress(CAST_FROM_FN_PTR(address, pthread_getspecific)));
    47   increment(rsp, wordSize);
    49   pop(rdx);
    50   pop(rcx);
    51   if (thread != rax) {
    52     mov(thread, rax);
    53     pop(rax);
    54   }
    55 }
    57 #else
    58 void MacroAssembler::get_thread(Register thread) {
    59   movl(thread, rsp);
    60   shrl(thread, PAGE_SHIFT);
    62   ExternalAddress tls_base((address)ThreadLocalStorage::sp_map_addr());
    63   Address index(noreg, thread, Address::times_4);
    64   ArrayAddress tls(tls_base, index);
    66   movptr(thread, tls);
    67 }
    68 #endif // MINIMIZE_RAM_USAGE
    69 #else
    70 void MacroAssembler::int3() {
    71   call(RuntimeAddress(CAST_FROM_FN_PTR(address, os::breakpoint)));
    72 }
    74 void MacroAssembler::get_thread(Register thread) {
    75   // call pthread_getspecific
    76   // void * pthread_getspecific(pthread_key_t key);
    77    if (thread != rax) {
    78      push(rax);
    79    }
    80    push(rdi);
    81    push(rsi);
    82    push(rdx);
    83    push(rcx);
    84    push(r8);
    85    push(r9);
    86    push(r10);
    87    // XXX
    88    mov(r10, rsp);
    89    andq(rsp, -16);
    90    push(r10);
    91    push(r11);
    93    movl(rdi, ThreadLocalStorage::thread_index());
    94    call(RuntimeAddress(CAST_FROM_FN_PTR(address, pthread_getspecific)));
    96    pop(r11);
    97    pop(rsp);
    98    pop(r10);
    99    pop(r9);
   100    pop(r8);
   101    pop(rcx);
   102    pop(rdx);
   103    pop(rsi);
   104    pop(rdi);
   105    if (thread != rax) {
   106        mov(thread, rax);
   107        pop(rax);
   108    }
   109 }
   110 #endif

mercurial