Skip to content
Permalink
Browse files
8266742: Check W^X state on possible safepoint
Reviewed-by: dholmes, gziemski
  • Loading branch information
AntonKozlov committed May 17, 2021
1 parent 79b3944 commit 3b11d811a274ae1d91fdcc5f01bcd5d159f0543b
Showing with 25 additions and 7 deletions.
  1. +11 −7 src/hotspot/os/bsd/globals_bsd.hpp
  2. +10 −0 src/hotspot/share/runtime/safepointMechanism.inline.hpp
  3. +4 −0 src/hotspot/share/runtime/thread.hpp
@@ -28,13 +28,17 @@
//
// Declare Bsd specific flags. They are not available on other platforms.
//
#define RUNTIME_OS_FLAGS(develop, \
develop_pd, \
product, \
product_pd, \
notproduct, \
range, \
constraint)
#define RUNTIME_OS_FLAGS(develop, \
develop_pd, \
product, \
product_pd, \
notproduct, \
range, \
constraint) \
\
AARCH64_ONLY(develop(bool, AssertWXAtThreadSync, false, \
"Conservatively check W^X thread state at possible safepoint" \
"or handshake"))

// end of RUNTIME_OS_FLAGS

@@ -65,6 +65,16 @@ bool SafepointMechanism::should_process(JavaThread* thread) {
}

void SafepointMechanism::process_if_requested(JavaThread* thread) {

// Macos/aarch64 should be in the right state for safepoint (e.g.
// deoptimization needs WXWrite). Crashes caused by the wrong state rarely
// happens in practice, making such issues hard to find and reproduce.
#if defined(ASSERT) && defined(__APPLE__) && defined(AARCH64)
if (AssertWXAtThreadSync) {
thread->assert_wx_state(WXWrite);
}
#endif

if (local_poll_armed(thread)) {
process_if_requested_slow(thread);
}
@@ -649,6 +649,10 @@ class Thread: public ThreadShadow {
public:
void init_wx();
WXMode enable_wx(WXMode new_state);

void assert_wx_state(WXMode expected) {
assert(_wx_state == expected, "wrong state");
}
#endif // __APPLE__ && AARCH64
};

0 comments on commit 3b11d81

Please sign in to comment.