# HG changeset patch # User dcubed # Date 1236027907 25200 # Node ID 2f716c0acb641e6f7f97dfaf5dce1affad94830d # Parent 70998f2e05ef07766fa33343f039c37a6d9e4cf1 6567360: 3/4 SIGBUS in jvmti RawMonitor magic check for unaligned bad monitor pointer Summary: Change JvmtiEnvBase::is_valid() and JvmtiRawMonitor::is_valid() to fetch the _magic fields via Bytes::get_native_u[248](). Reviewed-by: coleenp, swamyv diff -r 70998f2e05ef -r 2f716c0acb64 src/share/vm/prims/jvmtiEnvBase.cpp --- a/src/share/vm/prims/jvmtiEnvBase.cpp Mon Mar 02 14:03:03 2009 -0700 +++ b/src/share/vm/prims/jvmtiEnvBase.cpp Mon Mar 02 14:05:07 2009 -0700 @@ -94,6 +94,35 @@ } +bool +JvmtiEnvBase::is_valid() { + jint value = 0; + + // This object might not be a JvmtiEnvBase so we can't assume + // the _magic field is properly aligned. Get the value in a safe + // way and then check against JVMTI_MAGIC. + + switch (sizeof(_magic)) { + case 2: + value = Bytes::get_native_u2((address)&_magic); + break; + + case 4: + value = Bytes::get_native_u4((address)&_magic); + break; + + case 8: + value = Bytes::get_native_u8((address)&_magic); + break; + + default: + guarantee(false, "_magic field is an unexpected size"); + } + + return value == JVMTI_MAGIC; +} + + JvmtiEnvBase::JvmtiEnvBase() : _env_event_enable() { _env_local_storage = NULL; _tag_map = NULL; diff -r 70998f2e05ef -r 2f716c0acb64 src/share/vm/prims/jvmtiEnvBase.hpp --- a/src/share/vm/prims/jvmtiEnvBase.hpp Mon Mar 02 14:03:03 2009 -0700 +++ b/src/share/vm/prims/jvmtiEnvBase.hpp Mon Mar 02 14:05:07 2009 -0700 @@ -120,7 +120,7 @@ public: - bool is_valid() { return _magic == JVMTI_MAGIC; } + bool is_valid(); bool is_retransformable() { return _is_retransformable; } diff -r 70998f2e05ef -r 2f716c0acb64 src/share/vm/prims/jvmtiImpl.cpp --- a/src/share/vm/prims/jvmtiImpl.cpp Mon Mar 02 14:03:03 2009 -0700 +++ b/src/share/vm/prims/jvmtiImpl.cpp Mon Mar 02 14:05:07 2009 -0700 @@ -238,6 +238,35 @@ } +bool +JvmtiRawMonitor::is_valid() { + int value = 0; + + // This object might not be a JvmtiRawMonitor so we can't assume + // the _magic field is properly aligned. Get the value in a safe + // way and then check against JVMTI_RM_MAGIC. + + switch (sizeof(_magic)) { + case 2: + value = Bytes::get_native_u2((address)&_magic); + break; + + case 4: + value = Bytes::get_native_u4((address)&_magic); + break; + + case 8: + value = Bytes::get_native_u8((address)&_magic); + break; + + default: + guarantee(false, "_magic field is an unexpected size"); + } + + return value == JVMTI_RM_MAGIC; +} + + // // class JvmtiBreakpoint // diff -r 70998f2e05ef -r 2f716c0acb64 src/share/vm/prims/jvmtiImpl.hpp --- a/src/share/vm/prims/jvmtiImpl.hpp Mon Mar 02 14:03:03 2009 -0700 +++ b/src/share/vm/prims/jvmtiImpl.hpp Mon Mar 02 14:05:07 2009 -0700 @@ -349,7 +349,7 @@ ~JvmtiRawMonitor(); int magic() { return _magic; } const char *get_name() { return _name; } - bool is_valid() { return _magic == JVMTI_RM_MAGIC; } + bool is_valid(); }; // Onload pending raw monitors