Skip to content

Commit b12e2ce

Browse files
sjindel-googlecommit-bot@chromium.org
authored andcommitted
[vm] Make FFI code protection test wait for helper to terminate before continuing.
Addresses #37779 Change-Id: I3ee7ec890be9c859737e8676a00047e46643e050 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/112258 Commit-Queue: Samir Jindel <sjindel@google.com> Reviewed-by: Martin Kustermann <kustermann@google.com>
1 parent aac8204 commit b12e2ce

File tree

2 files changed

+19
-11
lines changed

2 files changed

+19
-11
lines changed

runtime/bin/ffi_test/ffi_test_functions.cc

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -560,23 +560,28 @@ DART_EXPORT void* UnprotectCodeOtherThread(void* isolate,
560560
return nullptr;
561561
}
562562

563-
DART_EXPORT int UnprotectCode() {
563+
DART_EXPORT void* UnprotectCode() {
564564
std::mutex mutex;
565565
std::condition_variable cvar;
566566
std::unique_lock<std::mutex> lock(mutex); // locks the mutex
567-
std::thread helper(UnprotectCodeOtherThread, Dart_CurrentIsolate(), &cvar,
568-
&mutex);
567+
std::thread* helper = new std::thread(UnprotectCodeOtherThread,
568+
Dart_CurrentIsolate(), &cvar, &mutex);
569569

570-
helper.detach();
571570
cvar.wait(lock);
572571

573-
return 0;
572+
return helper;
573+
}
574+
575+
DART_EXPORT void WaitForHelper(void* helper) {
576+
std::thread* thread = reinterpret_cast<std::thread*>(helper);
577+
thread->join();
574578
}
575579
#else
576580
// Our version of VSC++ doesn't support std::thread yet.
577-
DART_EXPORT int UnprotectCode() {
578-
return 0;
581+
DART_EXPORT void* UnprotectCode() {
582+
return nullptr;
579583
}
584+
DART_EXPORT void WaitForHelper(void* helper) {}
580585
#endif
581586

582587
////////////////////////////////////////////////////////////////////////////////

tests/ffi/function_gc_test.dart

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -110,10 +110,13 @@ void testRegress37069() {
110110
regress37069(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11);
111111
}
112112

113-
final unprotectCode = ffiTestFunctions
114-
.lookupFunction<NativeNullaryOp32, NullaryOp>("UnprotectCode");
113+
final unprotectCode = ffiTestFunctions.lookupFunction<
114+
ffi.Pointer<ffi.Void> Function(),
115+
ffi.Pointer<ffi.Void> Function()>("UnprotectCode");
116+
final waitForHelper = ffiTestFunctions.lookupFunction<
117+
ffi.Void Function(ffi.Pointer<ffi.Void>),
118+
void Function(ffi.Pointer<ffi.Void>)>("UnprotectCode");
115119

116120
void testWriteProtection() {
117-
int result = unprotectCode();
118-
Expect.equals(result, 0);
121+
waitForHelper(unprotectCode());
119122
}

0 commit comments

Comments
 (0)