Commit d30af614 authored by Clemens Hammacher's avatar Clemens Hammacher Committed by Commit Bot

[wasm] Use correct types for instance fields

Memory size, mask and function table size are 32-bit values in wasm.
There is no relation to pointer size. Hence, replace uintptr_t by
uint32_t.
These fields are already being loaded as uint32_t in wasm-compiler.cc,
causing problems on big endian systems.

R=mstarzinger@chromium.org

Change-Id: Ie03b552934262d5fa8de9998abdd7409e60af690
Reviewed-on: https://chromium-review.googlesource.com/1005154
Commit-Queue: Clemens Hammacher <clemensh@chromium.org>
Reviewed-by: 's avatarMichael Starzinger <mstarzinger@chromium.org>
Cr-Commit-Position: refs/heads/master@{#52568}
parent c5969868
......@@ -102,15 +102,15 @@ void WasmGlobalObject::SetF64(double value) {
// WasmInstanceObject
PRIMITIVE_ACCESSORS(WasmInstanceObject, memory_start, byte*, kMemoryStartOffset)
PRIMITIVE_ACCESSORS(WasmInstanceObject, memory_size, uintptr_t,
PRIMITIVE_ACCESSORS(WasmInstanceObject, memory_size, uint32_t,
kMemorySizeOffset)
PRIMITIVE_ACCESSORS(WasmInstanceObject, memory_mask, uintptr_t,
PRIMITIVE_ACCESSORS(WasmInstanceObject, memory_mask, uint32_t,
kMemoryMaskOffset)
PRIMITIVE_ACCESSORS(WasmInstanceObject, imported_function_targets, Address*,
kImportedFunctionTargetsOffset)
PRIMITIVE_ACCESSORS(WasmInstanceObject, globals_start, byte*,
kGlobalsStartOffset)
PRIMITIVE_ACCESSORS(WasmInstanceObject, indirect_function_table_size, uintptr_t,
PRIMITIVE_ACCESSORS(WasmInstanceObject, indirect_function_table_size, uint32_t,
kIndirectFunctionTableSizeOffset)
PRIMITIVE_ACCESSORS(WasmInstanceObject, indirect_function_table_sig_ids,
uint32_t*, kIndirectFunctionTableSigIdsOffset)
......
......@@ -78,8 +78,8 @@ class WasmInstanceNativeAllocations {
// Resizes the indirect function table.
void resize_indirect_function_table(Isolate* isolate,
Handle<WasmInstanceObject> instance,
size_t new_size) {
size_t old_size = instance->indirect_function_table_size();
uint32_t new_size) {
uint32_t old_size = instance->indirect_function_table_size();
void* new_sig_ids = nullptr;
void* new_targets = nullptr;
Handle<FixedArray> new_instances;
......@@ -109,7 +109,7 @@ class WasmInstanceNativeAllocations {
reinterpret_cast<Address*>(new_targets));
instance->set_indirect_function_table_instances(*new_instances);
for (size_t j = old_size; j < new_size; j++) {
for (uint32_t j = old_size; j < new_size; j++) {
IndirectFunctionTableEntry(*instance, static_cast<int>(j)).clear();
}
}
......@@ -702,8 +702,8 @@ bool ImportedFunctionEntry::is_js_receiver_entry() {
}
bool WasmInstanceObject::EnsureIndirectFunctionTableWithMinimumSize(
Handle<WasmInstanceObject> instance, size_t minimum_size) {
uintptr_t old_size = instance->indirect_function_table_size();
Handle<WasmInstanceObject> instance, uint32_t minimum_size) {
uint32_t old_size = instance->indirect_function_table_size();
if (old_size >= minimum_size) return false; // Nothing to do.
Isolate* isolate = instance->GetIsolate();
......@@ -714,14 +714,14 @@ bool WasmInstanceObject::EnsureIndirectFunctionTableWithMinimumSize(
return true;
}
void WasmInstanceObject::SetRawMemory(byte* mem_start, size_t mem_size) {
void WasmInstanceObject::SetRawMemory(byte* mem_start, uint32_t mem_size) {
DCHECK_LE(mem_size, wasm::kV8MaxWasmMemoryPages * wasm::kWasmPageSize);
uint64_t mem_size64 = mem_size;
uint64_t mem_mask64 = base::bits::RoundUpToPowerOfTwo64(mem_size) - 1;
uint32_t mem_size64 = mem_size;
uint32_t mem_mask64 = base::bits::RoundUpToPowerOfTwo32(mem_size) - 1;
DCHECK_LE(mem_size, mem_mask64 + 1);
set_memory_start(mem_start);
set_memory_size(static_cast<uintptr_t>(mem_size64));
set_memory_mask(static_cast<uintptr_t>(mem_mask64));
set_memory_size(mem_size64);
set_memory_mask(mem_mask64);
}
WasmModuleObject* WasmInstanceObject::module_object() {
......
......@@ -270,37 +270,38 @@ class WasmInstanceObject : public JSObject {
DECL_OPTIONAL_ACCESSORS(managed_native_allocations, Foreign)
DECL_OPTIONAL_ACCESSORS(managed_indirect_patcher, Foreign)
DECL_PRIMITIVE_ACCESSORS(memory_start, byte*)
DECL_PRIMITIVE_ACCESSORS(memory_size, uintptr_t)
DECL_PRIMITIVE_ACCESSORS(memory_mask, uintptr_t)
DECL_PRIMITIVE_ACCESSORS(memory_size, uint32_t)
DECL_PRIMITIVE_ACCESSORS(memory_mask, uint32_t)
DECL_PRIMITIVE_ACCESSORS(imported_function_targets, Address*)
DECL_PRIMITIVE_ACCESSORS(globals_start, byte*)
DECL_PRIMITIVE_ACCESSORS(indirect_function_table_size, uintptr_t)
DECL_PRIMITIVE_ACCESSORS(indirect_function_table_size, uint32_t)
DECL_PRIMITIVE_ACCESSORS(indirect_function_table_sig_ids, uint32_t*)
DECL_PRIMITIVE_ACCESSORS(indirect_function_table_targets, Address*)
// Layout description.
#define WASM_INSTANCE_OBJECT_FIELDS(V) \
V(kCompiledModuleOffset, kPointerSize) \
V(kExportsObjectOffset, kPointerSize) \
V(kMemoryObjectOffset, kPointerSize) \
V(kGlobalsBufferOffset, kPointerSize) \
V(kDebugInfoOffset, kPointerSize) \
V(kTableObjectOffset, kPointerSize) \
V(kFunctionTablesOffset, kPointerSize) \
V(kImportedFunctionInstancesOffset, kPointerSize) \
V(kImportedFunctionCallablesOffset, kPointerSize) \
V(kIndirectFunctionTableInstancesOffset, kPointerSize) \
V(kManagedNativeAllocationsOffset, kPointerSize) \
V(kManagedIndirectPatcherOffset, kPointerSize) \
V(kFirstUntaggedOffset, 0) /* marker */ \
V(kMemoryStartOffset, kPointerSize) /* untagged */ \
V(kMemorySizeOffset, kPointerSize) /* untagged */ \
V(kMemoryMaskOffset, kPointerSize) /* untagged */ \
V(kImportedFunctionTargetsOffset, kPointerSize) /* untagged */ \
V(kGlobalsStartOffset, kPointerSize) /* untagged */ \
V(kIndirectFunctionTableSizeOffset, kPointerSize) /* untagged */ \
V(kIndirectFunctionTableSigIdsOffset, kPointerSize) /* untagged */ \
V(kIndirectFunctionTableTargetsOffset, kPointerSize) /* untagged */ \
#define WASM_INSTANCE_OBJECT_FIELDS(V) \
V(kCompiledModuleOffset, kPointerSize) \
V(kExportsObjectOffset, kPointerSize) \
V(kMemoryObjectOffset, kPointerSize) \
V(kGlobalsBufferOffset, kPointerSize) \
V(kDebugInfoOffset, kPointerSize) \
V(kTableObjectOffset, kPointerSize) \
V(kFunctionTablesOffset, kPointerSize) \
V(kImportedFunctionInstancesOffset, kPointerSize) \
V(kImportedFunctionCallablesOffset, kPointerSize) \
V(kIndirectFunctionTableInstancesOffset, kPointerSize) \
V(kManagedNativeAllocationsOffset, kPointerSize) \
V(kManagedIndirectPatcherOffset, kPointerSize) \
V(kFirstUntaggedOffset, 0) /* marker */ \
V(kMemoryStartOffset, kPointerSize) /* untagged */ \
V(kMemorySizeOffset, kUInt32Size) /* untagged */ \
V(kMemoryMaskOffset, kUInt32Size) /* untagged */ \
V(kImportedFunctionTargetsOffset, kPointerSize) /* untagged */ \
V(kGlobalsStartOffset, kPointerSize) /* untagged */ \
V(kIndirectFunctionTableSigIdsOffset, kPointerSize) /* untagged */ \
V(kIndirectFunctionTableTargetsOffset, kPointerSize) /* untagged */ \
V(kIndirectFunctionTableSizeOffset, kUInt32Size) /* untagged */ \
V(k64BitArchPaddingOffset, kPointerSize - kUInt32Size) /* padding */ \
V(kSize, 0)
DEFINE_FIELD_OFFSET_CONSTANTS(JSObject::kHeaderSize,
......@@ -311,11 +312,11 @@ class WasmInstanceObject : public JSObject {
V8_EXPORT_PRIVATE wasm::WasmModule* module();
static bool EnsureIndirectFunctionTableWithMinimumSize(
Handle<WasmInstanceObject> instance, size_t minimum_size);
Handle<WasmInstanceObject> instance, uint32_t minimum_size);
bool has_indirect_function_table();
void SetRawMemory(byte* mem_start, size_t mem_size);
void SetRawMemory(byte* mem_start, uint32_t mem_size);
// Get the debug info associated with the given wasm object.
// If no debug info exists yet, it is created automatically.
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment