dart-sdk/tests/ffi/msan_test.dart
Daco Harkes 2e1a56f264 [vm/msan] Fix MemCopyInstr instrumentation
The MemoryCopyInstr on x64 in MSAN mode when forward copying was
unpoisoning at the wrong pointer. The `rep mov` changes the
destination register.

Now we unpoison _before_ the `rep mov` if it's a forward copy, and
_after_ the `rep mov` for backwards copies. This way the destination
register contains the start of the memory in both cases.

TEST=tests/ffi/msan_test.dart

b/266213262
Change-Id: I37688802e63797f650a8242b6ba8b884813ebbd0
Cq-Include-Trybots: luci.dart.try:vm-msan-linux-release-x64-try,vm-aot-msan-linux-release-x64-try,vm-linux-debug-ia32-try
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/361420
Reviewed-by: Tess Strickland <sstrickl@google.com>
Commit-Queue: Daco Harkes <dacoharkes@google.com>
2024-04-08 10:40:23 +00:00

58 lines
1.5 KiB
Dart

// Copyright (c) 2024, 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:typed_data';
import 'package:expect/expect.dart';
import 'package:ffi/ffi.dart';
import 'ffi_test_helpers.dart';
void main() {
testInitMemoryInDart();
testInitMemoryInDart16();
testInitStringInDart();
}
void testInitMemoryInDart() {
final units = Uint8List.fromList([109, 121, 83, 116, 114, 105, 110, 103, 0]);
final pointer = malloc<Uint8>(units.length);
pointer.asTypedList(units.length).setAll(0, units);
print(pointer);
final result = takeString(pointer.cast());
Expect.equals(114, result);
malloc.free(pointer);
}
void testInitMemoryInDart16() {
final units = Uint16List.fromList([
109 + 121 * 256,
83 + 116 * 256,
114 + 105 * 256,
110 + 103 * 256,
0,
]);
final Pointer<Uint16> pointer = malloc<Uint16>(units.length);
pointer.asTypedList(units.length).setAll(0, units);
print(pointer);
final result = takeString(pointer.cast());
Expect.equals(114, result);
malloc.free(pointer);
}
void testInitStringInDart() {
final cString = 'myString'.toNativeUtf8();
final result = takeString(cString);
Expect.equals(114, result);
malloc.free(cString);
}
final takeString = ffiTestFunctions
.lookupFunction<Char Function(Pointer<Utf8>), int Function(Pointer<Utf8>)>(
'TakeString',
);