General utilities for playing shell games with real machine bytes for both the real machine and the Java virtual machine.
Some machine architectures use little-endian versus big-endian byte ordering, some architectures do not natively support 2-byte or 4-byte or 8-byte word addressing on addesses that are not aligned to those boundaries. The JVM does not care about such things, but must accomodate real machine implementations in a way that they do not complain about it at run time. There area also functions here that provide such support. They typically are embedded in widely-used macros from cfmacros.h and util.h.
Copyright 2005 The Apache Software Foundation or its licensors, as applicable.
Licensed under the Apache License, Version 2.0 ("the License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and limitations under the License.
Definition in file bytegames.c.
#include "arch.h"
#include "jvmcfg.h"
#include "util.h"
Go to the source code of this file.
Data Structures | |
union | eightbyte |
Structure for shuffling eight-byte values. More... | |
union | fourbyte |
Structure for shuffling four-byte values. More... | |
union | twobyte |
Structure for shuffling two-byte values. More... | |
Combine/split support for (jlong) and (jdouble). | |
The combine operation takes two jint words as the MS and LS words of a jlong or jdouble and returns a combined result. This is typically used for retrieving JVM local variables or operand stack parameters. The split operation is the reverse. It takes a jlong or jdouble and extracts two jint words, typically for storage into a JVM local variable or operand stack parameter.
| |
jdouble | bytegames_combine_jdouble (jint msword, jint lsword) |
Combine two jint words into a jdouble. | |
jlong | bytegames_combine_jlong (jint msword, jint lsword) |
Combine two jint words into a jlong. | |
rvoid | bytegames_split_jdouble (jdouble splitdouble, jint *msword, jint *lsword) |
Split a jdouble into two jint words. | |
rvoid | bytegames_split_jlong (jlong splitlong, jint *msword, jint *lsword) |
Split a jlong into two jint words. | |
Unaligned multi-byte access support. | |
Store and retrieve arbitrary 2- and 4-byte values from unaligned addresses without causing SIGSEGV signals by performing 1-byte addressing on these locations.
The 2- and 4-byte functions are typically used for absorbing class file stream data into a ClassFile structure. Of particular interest is classfile_loadclassdata(), where it is used to retrieve many different types of 2- and 4-byte data. The 8-byte functions are used by class_get_constant_field_attribute() for retrieving jlong and jdouble constants. | |
ruint | bytegames_getri4 (ruint *ptr4) |
4-byte version of bytegames_getrs2(), but performs two odd-byte accesses, not just one. | |
rulong | bytegames_getrl8 (rulong *ptr8) |
8-byte version of bytegames_getri4(), but performs four odd-byte accesses, not just one. | |
rushort | bytegames_getrs2 (rushort *ptr2) |
Retrieve any generic 2-byte value (16 bits), whether or not its is aligned on a 2-byte (that is, even address) boundary. | |
rvoid | bytegames_putri4 (ruint *ptr4, ruint val4) |
Store any generic 4-byte value (32 bits), whether or not its is aligned on a 2-byte (that is, even address) boundary. | |
rvoid | bytegames_putrl8 (rulong *ptr8, rulong val8) |
Store any generic 8-byte value (64 bits), whether or not its is aligned on a 2-byte (that is, even address) boundary.This function is the inverse of bytegames_getrl8() above, which see for further explanation. | |
rvoid | bytegames_putrs2 (rushort *ptr2, rushort val2) |
Store any generic 2-byte value (16 bits), whether or not its is aligned on a 2-byte (that is, even address) boundary. | |
Byte swapping support. | |
Swap 2- and 4- and 8-byte values, especially for support of little-endian real machines. Since the Java virtual machine is defined as a big-endian architecture, these functions are supplied to map between the big-endian JVM and a little-endian real machine implementation.
The 2- and 4-byte functions are typically used for swapping class file stream data as it is being absorbed into a ClassFile structure, as well as for other general uses. Of particular interest is classfile_loadclassdata(), where they are used to swap many different types of 2- and 4-byte data. The 8-byte functions are provided for completeness. | |
rulong | bytegames_mix8 (rulong val) |
Mix up 8 bytes for a little-endian machine rushort value to a big-endian Java real machine implementation rushort value in the same way as bytegames_swap8(), but store the words MS first, LS second. | |
rushort | bytegames_swap2 (rushort val) |
Swap 2 bytes for a little-endian machine rushort value to a big-endian Java real machine implementation rushort value. | |
ruint | bytegames_swap4 (ruint val) |
Swap 4 bytes for a little-endian machine ruint value to a big-endian Java real machine implementation ruint value. | |
rulong | bytegames_swap8 (rulong val) |
Swap 8 bytes for a little-endian machine rulong value to a big-endian Java real machine implementation rulong value. | |
Functions | |
static void | bytegames_c_dummy (void) |
Variables | |
static char * | bytegames_c_copyright = "\0" "$URL: https://svn.apache.org/path/name/bytegames.c $ $Id: bytegames.c 0 09/28/2005 dlydick $" " " "Copyright 2005 The Apache Software Foundation or its licensors, as applicable." |
|
Definition at line 54 of file bytegames.c. |
|
Retrieve any generic 2-byte value (16 bits), whether or not its is aligned on a 2-byte (that is, even address) boundary. This function was written to suppress SIGSEGV issues on GCC -m32 binaries on a Solaris 9. Typical usage is in a situation of: rshort *pshort; ... val = *pshort; ... If pshort is at odd address, throw SIGSEGV. Thus convert to: rshort *pshort; ... val = getrs2(pshort); ... No signal this way. This causes two one-byte accesses to happen instead of a single two-byte access, eliminating the cause of SIGSEGV, unless, of course, the pointer is off in the weeds instead of looking at valid memory.
Definition at line 233 of file bytegames.c. References twobyte::_byteval, and twobyte::_usval. |
|
Store any generic 2-byte value (16 bits), whether or not its is aligned on a 2-byte (that is, even address) boundary. This function is the inverse of bytegames_getrs2() above, which see for further explanation.
Definition at line 268 of file bytegames.c. References twobyte::_byteval, and twobyte::_usval. |
|
4-byte version of bytegames_getrs2(), but performs two odd-byte accesses, not just one. This causes four one-byte accesses to happen instead of a single four-byte access, eliminating the cause of SIGSEGV.
Definition at line 302 of file bytegames.c. References fourbyte::_byteval, and fourbyte::_ruival. |
|
Store any generic 4-byte value (32 bits), whether or not its is aligned on a 2-byte (that is, even address) boundary. This function is the inverse of bytegames_getri4() above, which see for further explanation.
Definition at line 339 of file bytegames.c. References fourbyte::_byteval, and fourbyte::_ruival. |
|
8-byte version of bytegames_getri4(), but performs four odd-byte accesses, not just one. This causes eight one-byte accesses to happen instead of a single eight-byte access, eliminating the cause of SIGSEGV.
Definition at line 376 of file bytegames.c. References eightbyte::_byteval, eightbyte::_rulval, and bytegames_swap8(). |
|
Store any generic 8-byte value (64 bits), whether or not its is aligned on a 2-byte (that is, even address) boundary.This function is the inverse of bytegames_getrl8() above, which see for further explanation.
Definition at line 421 of file bytegames.c. References eightbyte::_byteval, eightbyte::_rulval, and bytegames_swap8(). |
|
Swap 2 bytes for a little-endian machine rushort value to a big-endian Java real machine implementation rushort value. Available but not used in big-endian architectures. This routine is mapped for little-endian machines to MACHINE_JSHORT_SWAP().
INPUT BYTE ORDER: (a) (b) rshort: (ab) OUTPUT BYTE ORDER: (b) (a) rshort: (ba)
Definition at line 497 of file bytegames.c. References twobyte::_byteval, and twobyte::_usval. |
|
Swap 4 bytes for a little-endian machine ruint value to a big-endian Java real machine implementation ruint value. Available but not used in big-endian architectures. This routine is mapped for little-endian machines to MACHINE_JINT_SWAP().
INPUT BYTE ORDER: (a) (b) (c) (d) rint: (abcd) OUTPUT BYTE ORDER: (d) (c) (b) (a) rint: (dcba)
Definition at line 539 of file bytegames.c. References fourbyte::_byteval, and fourbyte::_ruival. |
|
Swap 8 bytes for a little-endian machine rulong value to a big-endian Java real machine implementation rulong value. Available but not used in big-endian architectures. This routine is mapped for little-endian machines to MACHINE_JLONG_SWAP().
INPUT BYTE ORDER: (a) (b) (c) (d) (e) (f) (g) (h) rlong: (abcdefgh) OUTPUT BYTE ORDER: (h) (g) (f) (e) (d) (c) (b) (a) rlong: (hgfedcba)
Definition at line 586 of file bytegames.c. References eightbyte::_byteval, and eightbyte::_rulval. Referenced by bytegames_getrl8(), and bytegames_putrl8(). |
|
Mix up 8 bytes for a little-endian machine rushort value to a big-endian Java real machine implementation rushort value in the same way as bytegames_swap8(), but store the words MS first, LS second. Available but not used in big-endian architectures. This routine is mapped for little-endian machines to MACHINE_JLONG_MIX().
INPUT BYTE ORDER: (a) (b) (c) (d) (e) (f) (g) (h) rlong: (abcdefgh) OUTPUT BYTE ORDER: (d) (c) (b) (a) (h) (g) (f) (e) rlong: (dcbahgfe)
Definition at line 643 of file bytegames.c. References eightbyte::_byteval, and eightbyte::_rulval. |
|
Combine two jint words into a jlong. Pass in two sequential words as jint from the JVM stack frame or operand stack or any other appropriate source and return a result as jlong
Definition at line 722 of file bytegames.c. References eightbyte::_intval, and eightbyte::_julval. |
|
Combine two jint words into a jdouble. Pass in two sequential words as jint from the JVM stack frame or operand stack or any other appropriate source and return a result as jdouble.
Definition at line 752 of file bytegames.c. References eightbyte::_intval, and eightbyte::_jdval. |
|
Split a jlong into two jint words. Pass in a jlong and return two words suitable for storing into a JVM stack frame as a pair of local variables or into the operand stack as two sequential words. The first receives the MS word, the second receives the LS word, which should be the next sequential stack frame local variable or operand stack location.
Definition at line 785 of file bytegames.c. References eightbyte::_intval, and eightbyte::_julval. Referenced by native_run_local_return_jlong(), and opcode_run(). |
|
Split a jdouble into two jint words. Pass in a jlong and return two words suitable for storing into a JVM stack frame as a pair of local variables or into the operand stack as two sequential words. The first receives the MS word, the second receives the LS word, which should be the next sequential stack frame local variable or operand stack location.
Definition at line 820 of file bytegames.c. References eightbyte::_intval, and eightbyte::_jdval. Referenced by native_run_local_return_jdouble(), and opcode_run(). |
|
Definition at line 54 of file bytegames.c. |