Commit ca3220c6 authored by Bill Budge's avatar Bill Budge Committed by Commit Bot

[wasm] Expose function IsSupportedVersion

- Exposes IsSupportedVersion function which compares serialized
  version to current Wasm version.
- Tweaks the comments on serialization to match the code.

Bug: chromium:719172
Change-Id: I76df9605aee16fd98cd82b54dba2e9acbd56b41b
Reviewed-on: https://chromium-review.googlesource.com/c/1265141Reviewed-by: 's avatarBen Smith <binji@chromium.org>
Commit-Queue: Bill Budge <bbudge@chromium.org>
Cr-Commit-Position: refs/heads/master@{#56420}
parent 466306e9
......@@ -127,14 +127,6 @@ void WriteVersion(Isolate* isolate, Writer* writer) {
writer->Write(FlagList::Hash());
}
bool IsSupportedVersion(Isolate* isolate, const Vector<const byte> version) {
if (version.size() < kVersionSize) return false;
byte current_version[kVersionSize];
Writer writer({current_version, kVersionSize});
WriteVersion(isolate, &writer);
return memcmp(version.start(), current_version, kVersionSize) == 0;
}
// On Intel, call sites are encoded as a displacement. For linking and for
// serialization/deserialization, we want to store/retrieve a tag (the function
// index). On Intel, that means accessing the raw displacement.
......@@ -537,6 +529,14 @@ bool NativeModuleDeserializer::ReadCode(uint32_t fn_index, Reader* reader) {
return true;
}
bool IsSupportedVersion(Isolate* isolate, Vector<const byte> version) {
if (version.size() < kVersionSize) return false;
byte current_version[kVersionSize];
Writer writer({current_version, kVersionSize});
WriteVersion(isolate, &writer);
return memcmp(version.start(), current_version, kVersionSize) == 0;
}
MaybeHandle<WasmModuleObject> DeserializeNativeModule(
Isolate* isolate, Vector<const byte> data, Vector<const byte> wire_bytes) {
if (!IsWasmCodegenAllowed(isolate, isolate->native_context())) {
......
......@@ -11,9 +11,9 @@ namespace v8 {
namespace internal {
namespace wasm {
// Support to serialize WebAssembly {NativeModule} objects. This class intends
// to be thread-safe in that it takes a consistent snapshot of the module state
// at instantiation, allowing other threads to mutate the module concurrently.
// Support for serializing WebAssembly {NativeModule} objects. This class takes
// a snapshot of the module state at instantiation, and other code that modifies
// the module after that won't affect the serialized result.
class WasmSerializer {
public:
WasmSerializer(Isolate* isolate, NativeModule* native_module);
......@@ -31,7 +31,11 @@ class WasmSerializer {
std::vector<WasmCode*> code_table_;
};
// Support to deserialize WebAssembly {NativeModule} objects.
// Support for deserializing WebAssembly {NativeModule} objects.
// Checks the version header of the data against the current version.
bool IsSupportedVersion(Isolate* isolate, Vector<const byte> data);
// Deserializes the given data to create a compiled Wasm module.
MaybeHandle<WasmModuleObject> DeserializeNativeModule(
Isolate* isolate, Vector<const byte> data, Vector<const byte> wire_bytes);
......
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