[vm] Give the native call wrappers C linkage.

This avoids undefined behavior.

Cf. 18aa7d3678

TEST=ci
Change-Id: I2dd82517177ee812b3cd3ae4b1c748de129ec665
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/432720
Reviewed-by: Alexander Aprelev <aam@google.com>
Commit-Queue: Ryan Macnak <rmacnak@google.com>
This commit is contained in:
Ryan Macnak
2025-06-03 10:36:23 -07:00
committed by Commit Queue
parent 5c1f5cadb2
commit 13779dea53
2 changed files with 26 additions and 33 deletions
+26 -28
View File
@@ -111,9 +111,14 @@ void NativeEntry::MaybePropagateError(NativeArguments* arguments) {
}
}
extern "C" void DRT_BootstrapNativeCall(Dart_NativeArguments args,
Dart_NativeFunction func) {
CHECK_STACK_ALIGNMENT;
NativeEntry::BootstrapNativeCallWrapper(args, func);
}
uword NativeEntry::BootstrapNativeCallWrapperEntry() {
uword entry =
reinterpret_cast<uword>(NativeEntry::BootstrapNativeCallWrapper);
uword entry = reinterpret_cast<uword>(DRT_BootstrapNativeCall);
#if defined(USING_SIMULATOR)
entry = Simulator::RedirectExternalReference(
entry, Simulator::kNativeCallWrapper,
@@ -124,7 +129,6 @@ uword NativeEntry::BootstrapNativeCallWrapperEntry() {
void NativeEntry::BootstrapNativeCallWrapper(Dart_NativeArguments args,
Dart_NativeFunction func) {
CHECK_STACK_ALIGNMENT;
if (func == LinkNativeCall) {
func(args);
return;
@@ -151,8 +155,14 @@ void NativeEntry::BootstrapNativeCallWrapper(Dart_NativeArguments args,
}
}
extern "C" void DRT_NoScopeNativeCall(Dart_NativeArguments args,
Dart_NativeFunction func) {
CHECK_STACK_ALIGNMENT;
NativeEntry::NoScopeNativeCallWrapper(args, func);
}
uword NativeEntry::NoScopeNativeCallWrapperEntry() {
uword entry = reinterpret_cast<uword>(NativeEntry::NoScopeNativeCallWrapper);
uword entry = reinterpret_cast<uword>(DRT_NoScopeNativeCall);
#if defined(USING_SIMULATOR)
entry = Simulator::RedirectExternalReference(
entry, Simulator::kNativeCallWrapper,
@@ -163,13 +173,6 @@ uword NativeEntry::NoScopeNativeCallWrapperEntry() {
void NativeEntry::NoScopeNativeCallWrapper(Dart_NativeArguments args,
Dart_NativeFunction func) {
CHECK_STACK_ALIGNMENT;
NoScopeNativeCallWrapperNoStackCheck(args, func);
}
void NativeEntry::NoScopeNativeCallWrapperNoStackCheck(
Dart_NativeArguments args,
Dart_NativeFunction func) {
NativeArguments* arguments = reinterpret_cast<NativeArguments*>(args);
// Tell MemorySanitizer 'arguments' is initialized by generated code.
MSAN_UNPOISON(arguments, sizeof(*arguments));
@@ -183,9 +186,14 @@ void NativeEntry::NoScopeNativeCallWrapperNoStackCheck(
ASSERT(thread->execution_state() == Thread::kThreadInGenerated);
}
extern "C" void DRT_AutoScopeNativeCall(Dart_NativeArguments args,
Dart_NativeFunction func) {
CHECK_STACK_ALIGNMENT;
NativeEntry::AutoScopeNativeCallWrapper(args, func);
}
uword NativeEntry::AutoScopeNativeCallWrapperEntry() {
uword entry =
reinterpret_cast<uword>(NativeEntry::AutoScopeNativeCallWrapper);
uword entry = reinterpret_cast<uword>(DRT_AutoScopeNativeCall);
#if defined(USING_SIMULATOR)
entry = Simulator::RedirectExternalReference(
entry, Simulator::kNativeCallWrapper,
@@ -196,13 +204,6 @@ uword NativeEntry::AutoScopeNativeCallWrapperEntry() {
void NativeEntry::AutoScopeNativeCallWrapper(Dart_NativeArguments args,
Dart_NativeFunction func) {
CHECK_STACK_ALIGNMENT;
AutoScopeNativeCallWrapperNoStackCheck(args, func);
}
void NativeEntry::AutoScopeNativeCallWrapperNoStackCheck(
Dart_NativeArguments args,
Dart_NativeFunction func) {
NativeArguments* arguments = reinterpret_cast<NativeArguments*>(args);
// Tell MemorySanitizer 'arguments' is initialized by generated code.
MSAN_UNPOISON(arguments, sizeof(*arguments));
@@ -249,8 +250,9 @@ static NativeFunction ResolveNativeFunction(Zone* zone,
}
uword NativeEntry::LinkNativeCallEntry() {
uword entry = reinterpret_cast<uword>(NativeEntry::LinkNativeCall);
return entry;
// This one does not need a simulator redirect because it is always called
// through BootstrapNativeCallWrapper, not directly from generated code.
return reinterpret_cast<uword>(NativeEntry::LinkNativeCall);
}
void NativeEntry::LinkNativeCall(Dart_NativeArguments args) {
@@ -322,14 +324,10 @@ void NativeEntry::LinkNativeCall(Dart_NativeArguments args) {
NativeEntry::BootstrapNativeCallWrapper(
args, reinterpret_cast<Dart_NativeFunction>(target_function));
} else if (is_auto_scope) {
// Because this call is within a compilation unit, Clang doesn't respect
// the ABI alignment here.
NativeEntry::AutoScopeNativeCallWrapperNoStackCheck(
NativeEntry::AutoScopeNativeCallWrapper(
args, reinterpret_cast<Dart_NativeFunction>(target_function));
} else {
// Because this call is within a compilation unit, Clang doesn't respect
// the ABI alignment here.
NativeEntry::NoScopeNativeCallWrapperNoStackCheck(
NativeEntry::NoScopeNativeCallWrapper(
args, reinterpret_cast<Dart_NativeFunction>(target_function));
}
}
-5
View File
@@ -118,11 +118,6 @@ class NativeEntry : public AllStatic {
static void LinkNativeCall(Dart_NativeArguments args);
private:
static void NoScopeNativeCallWrapperNoStackCheck(Dart_NativeArguments args,
Dart_NativeFunction func);
static void AutoScopeNativeCallWrapperNoStackCheck(Dart_NativeArguments args,
Dart_NativeFunction func);
static void MaybePropagateError(NativeArguments* arguments);
};