MIPS: Fix unaligned memory access in hash calculation

During hash calculation, an array type was reinterpreted
from uint16_[] to uint32_t[]. Uint32 arrays have stricter
alignment requirements and these causes failures of several
tests from the debugger suite.

TEST=debugger/debug/debug-eval-scope

Cq-Include-Trybots: master.tryserver.blink:linux_trusty_blink_rel
Change-Id: I463c7aeb56a1010ddfb0c34f8404f05b75e6c466
Reviewed-on: https://chromium-review.googlesource.com/926341
Commit-Queue: Ivica Bogosavljevic <ivica.bogosavljevic@mips.com>
Reviewed-by: Dmitry Gozman <dgozman@chromium.org>
Cr-Commit-Position: refs/heads/master@{#51398}
This commit is contained in:
Ivica Bogosavljevic 2018-02-20 16:47:46 +01:00 committed by Commit Bot
parent 5a4af7c142
commit d3f2a925ed
2 changed files with 9 additions and 5 deletions

View File

@ -7,6 +7,7 @@ include_rules = [
"+src/base/platform/platform.h",
"+src/conversions.h",
"+src/flags.h",
"+src/utils.h",
"+src/unicode-cache.h",
"+src/inspector",
"+src/tracing",

View File

@ -7,6 +7,7 @@
#include "src/inspector/inspected-context.h"
#include "src/inspector/string-util.h"
#include "src/inspector/wasm-translation.h"
#include "src/utils.h"
namespace v8_inspector {
@ -45,10 +46,11 @@ String16 calculateHash(const String16& str) {
size_t sizeInBytes = sizeof(UChar) * str.length();
data = reinterpret_cast<const uint32_t*>(str.characters16());
for (size_t i = 0; i < sizeInBytes / 4; ++i) {
uint32_t d = v8::internal::ReadUnalignedUInt32(data + i);
#if V8_TARGET_LITTLE_ENDIAN
uint32_t v = data[i];
uint32_t v = d;
#else
uint32_t v = (data[i] << 16) | (data[i] >> 16);
uint32_t v = (d << 16) | (d >> 16);
#endif
uint64_t xi = v * randomOdd[current] & 0x7FFFFFFF;
hashes[current] = (hashes[current] + zi[current] * xi) % prime[current];
@ -57,15 +59,16 @@ String16 calculateHash(const String16& str) {
}
if (sizeInBytes % 4) {
uint32_t v = 0;
const uint8_t* data_8b = reinterpret_cast<const uint8_t*>(data);
for (size_t i = sizeInBytes - sizeInBytes % 4; i < sizeInBytes; ++i) {
v <<= 8;
#if V8_TARGET_LITTLE_ENDIAN
v |= reinterpret_cast<const uint8_t*>(data)[i];
v |= data_8b[i];
#else
if (i % 2) {
v |= reinterpret_cast<const uint8_t*>(data)[i - 1];
v |= data_8b[i - 1];
} else {
v |= reinterpret_cast<const uint8_t*>(data)[i + 1];
v |= data_8b[i + 1];
}
#endif
}