Files
sdk/tests/ffi/callback_unwind_error_test.dart
Ryan Macnak cb59df7acf [vm, ffi] Better handle errors that are not unhandled exceptions during FFI callbacks.
Before this change, an error reaching an FFI callback would attempt to execute the normal invocation stub from the beginning in the FFI callback's frame, which quickly crashes. After this change, the runtime recognizes this marker use of the invocation stub and returns to the FFI callback function instead.

TEST=ffi/unwind
Bug: https://github.com/dart-lang/sdk/issues/39487
Change-Id: I477cfcfc236e6cf518ebfe52860ba49e466ebf8b
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/409562
Reviewed-by: Daco Harkes <dacoharkes@google.com>
Commit-Queue: Ryan Macnak <rmacnak@google.com>
2025-02-19 09:40:34 -08:00

46 lines
1.0 KiB
Dart

// Copyright (c) 2023, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
// SharedObjects=ffi_test_functions
import "dart:ffi";
import "dart:isolate";
import "callback_tests_utils.dart";
typedef Type = Int32 Function(Int32, Int32);
int unwindError(int x, int y) {
print("unwindError($x, $y)");
Isolate.current.kill(priority: Isolate.immediate);
return x + y;
}
final testcases = [
CallbackTest("UnwindError", Pointer.fromFunction<Type>(unwindError, 42)),
];
void child(_) {
testcases.forEach((t) => t.run());
throw "Should not be reached";
}
void main() {
var onExit = new RawReceivePort();
var onError = new RawReceivePort();
onExit.handler = ((msg) {
print("Child exited");
onExit.close();
onError.close();
});
onError.handler = ((msg) {
throw "Child error: $msg";
});
Isolate.spawn(
child,
null,
onError: onError.sendPort,
onExit: onExit.sendPort,
);
}