src/os_cpu/linux_x86/vm/bytes_linux_x86.inline.hpp

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

author
dsimms
date
Wed, 25 Sep 2013 13:58:13 +0200
changeset 5781
899ecf76b570
parent 2314
f95d63e2154a
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 #ifndef OS_CPU_LINUX_X86_VM_BYTES_LINUX_X86_INLINE_HPP
stefank@2314 26 #define OS_CPU_LINUX_X86_VM_BYTES_LINUX_X86_INLINE_HPP
stefank@2314 27
duke@435 28 #include <byteswap.h>
duke@435 29
duke@435 30 // Efficient swapping of data bytes from Java byte
duke@435 31 // ordering to native byte ordering and vice versa.
duke@435 32 inline u2 Bytes::swap_u2(u2 x) {
duke@435 33 #ifdef AMD64
duke@435 34 return bswap_16(x);
duke@435 35 #else
duke@435 36 u2 ret;
duke@435 37 __asm__ __volatile__ (
duke@435 38 "movw %0, %%ax;"
duke@435 39 "xchg %%al, %%ah;"
duke@435 40 "movw %%ax, %0"
duke@435 41 :"=r" (ret) // output : register 0 => ret
duke@435 42 :"0" (x) // input : x => register 0
duke@435 43 :"ax", "0" // clobbered registers
duke@435 44 );
duke@435 45 return ret;
duke@435 46 #endif // AMD64
duke@435 47 }
duke@435 48
duke@435 49 inline u4 Bytes::swap_u4(u4 x) {
duke@435 50 #ifdef AMD64
duke@435 51 return bswap_32(x);
duke@435 52 #else
duke@435 53 u4 ret;
duke@435 54 __asm__ __volatile__ (
duke@435 55 "bswap %0"
duke@435 56 :"=r" (ret) // output : register 0 => ret
duke@435 57 :"0" (x) // input : x => register 0
duke@435 58 :"0" // clobbered register
duke@435 59 );
duke@435 60 return ret;
duke@435 61 #endif // AMD64
duke@435 62 }
duke@435 63
duke@435 64 #ifdef AMD64
duke@435 65 inline u8 Bytes::swap_u8(u8 x) {
dcubed@485 66 #ifdef SPARC_WORKS
dcubed@485 67 // workaround for SunStudio12 CR6615391
dcubed@485 68 __asm__ __volatile__ (
dcubed@485 69 "bswapq %0"
dcubed@485 70 :"=r" (x) // output : register 0 => x
dcubed@485 71 :"0" (x) // input : x => register 0
dcubed@485 72 :"0" // clobbered register
dcubed@485 73 );
dcubed@485 74 return x;
dcubed@485 75 #else
duke@435 76 return bswap_64(x);
dcubed@485 77 #endif
duke@435 78 }
duke@435 79 #else
duke@435 80 // Helper function for swap_u8
duke@435 81 inline u8 Bytes::swap_u8_base(u4 x, u4 y) {
duke@435 82 return (((u8)swap_u4(x))<<32) | swap_u4(y);
duke@435 83 }
duke@435 84
duke@435 85 inline u8 Bytes::swap_u8(u8 x) {
duke@435 86 return swap_u8_base(*(u4*)&x, *(((u4*)&x)+1));
duke@435 87 }
duke@435 88 #endif // !AMD64
stefank@2314 89
stefank@2314 90 #endif // OS_CPU_LINUX_X86_VM_BYTES_LINUX_X86_INLINE_HPP

mercurial