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

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

mercurial