Skip to content
This repository has been archived by the owner on Apr 2, 2020. It is now read-only.

Commit

Permalink
[SwiftREPL] Runtime checks for exclusive access should trap.
Browse files Browse the repository at this point in the history
<rdar://problem/33831489>
  • Loading branch information
Davide Italiano committed Jan 7, 2019
1 parent 305face commit d0c9406
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 4 deletions.
20 changes: 20 additions & 0 deletions lit/SwiftREPL/ExclusivityREPL.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
// Runtime checks for exclusive access should be enabled in the REPL.

// RUN: %lldb --repl < %s 2>&1 | FileCheck %s
// CHECK: modification requires exclusive access
// CHECK: Execution interrupted

class C {
var f = 12
}

let c = C()

func doIt(_ p1: inout Int, _ p2: inout Int) { }

let RTLD_DEFAULT = UnsafeMutableRawPointer(bitPattern: -2)
let flagPtr = dlsym(RTLD_DEFAULT, "_swift_disableExclusivityChecking")
let flagValue = flagPtr!.load(as: Bool.self)

print("flagValue is \(flagValue)")
doIt(&c.f, &c.f) // This should trap
12 changes: 8 additions & 4 deletions source/Target/SwiftLanguageRuntime.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3861,8 +3861,10 @@ void SwiftLanguageRuntime::WillStartExecutingUserExpression() {
std::lock_guard<std::mutex> lock(m_active_user_expr_mutex);
Log *log(GetLogIfAnyCategoriesSet(LIBLLDB_LOG_EXPRESSIONS));

if (m_active_user_expr_count == 0 &&
m_dynamic_exclusivity_flag_addr) {
bool in_repl = m_process->GetTarget().GetDebugger().REPLIsActive();

if (m_active_user_expr_count == 0 && m_dynamic_exclusivity_flag_addr &&
!in_repl) {
// We're executing the first user expression. Toggle the flag.
Status error;
TypeSystem *type_system =
Expand Down Expand Up @@ -3924,8 +3926,10 @@ void SwiftLanguageRuntime::DidFinishExecutingUserExpression() {
log->Printf("SwiftLanguageRuntime: finished user expression. "
"Number active: %u", m_active_user_expr_count);

if (m_active_user_expr_count == 0 &&
m_dynamic_exclusivity_flag_addr) {
bool in_repl = m_process->GetTarget().GetDebugger().REPLIsActive();

if (m_active_user_expr_count == 0 && m_dynamic_exclusivity_flag_addr &&
!in_repl) {
Status error;
TypeSystem *type_system =
m_process->GetTarget().GetScratchTypeSystemForLanguage(
Expand Down

0 comments on commit d0c9406

Please sign in to comment.