Commit 499b4956 authored by Mark Brand's avatar Mark Brand Committed by Commit Bot

MojoLPM: Remove re-entrancy and use of RunUntilIdle.

The existing example fuzzer code used RunUntilIdle to avoid runloop
recursion issues caused by re-entrancy in the scheduling of fuzzer
tasks. This change removes the re-entrancy and refactors out the use
of RunUntilIdle, working towards refactoring out the common code
duplication between fuzzers that's currently necessary.

Bug: 1076336
Change-Id: I3729d20264638c00c14c3a8149395e3f22e90089
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2329531
Commit-Queue: Mark Brand <markbrand@google.com>
Reviewed-by: default avatarScott Violet <sky@chromium.org>
Cr-Commit-Position: refs/heads/master@{#799545}
parent ed3fbbd4
......@@ -6,7 +6,7 @@ actions {
}
}
actions {
code_cache_host_call {
code_cache_host_remote_action {
id: 1
m_did_generate_cacheable_metadata {
m_cache_type: CodeCacheType_kJavascript
......
......@@ -6,7 +6,7 @@ actions {
}
}
actions {
code_cache_host_call {
code_cache_host_remote_action {
id: 1
m_did_generate_cacheable_metadata {
m_cache_type: CodeCacheType_kJavascript
......
// Copyright 2020 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// Message format for the MojoLPM fuzzer for the CodeCacheHost interface.
syntax = "proto2";
package content.fuzzing.code_cache_host.proto;
import "third_party/blink/public/mojom/loader/code_cache.mojom.mojolpm.proto";
message NewCodeCacheHost {
// Bind a new CodeCacheHost remote
message NewCodeCacheHostAction {
enum OriginId {
ORIGIN_A = 0;
ORIGIN_B = 1;
......@@ -17,7 +24,10 @@ message NewCodeCacheHost {
required OriginId origin_id = 3;
}
message RunUntilIdle {
// Run the specific sequence for (an indeterminate) period. This is not
// intended to create a specific ordering, but to allow the fuzzer to delay a
// later task until previous tasks have completed.
message RunThreadAction {
enum ThreadId {
IO = 0;
UI = 1;
......@@ -26,18 +36,23 @@ message RunUntilIdle {
required ThreadId id = 1;
}
// Actions that can be performed by the fuzzer.
message Action {
oneof action {
NewCodeCacheHost new_code_cache_host = 1;
RunUntilIdle run_until_idle = 2;
mojolpm.blink.mojom.CodeCacheHost.RemoteCall code_cache_host_call = 3;
NewCodeCacheHostAction new_code_cache_host = 1;
RunThreadAction run_thread = 2;
mojolpm.blink.mojom.CodeCacheHost.RemoteAction
code_cache_host_remote_action = 3;
}
}
// Sequence provides a level of indirection which allows Testcase to compactly
// express repeated sequences of actions.
message Sequence {
repeated uint32 action_indexes = 1 [packed = true];
}
// Testcase is the top-level message type interpreted by the fuzzer.
message Testcase {
repeated Action actions = 1;
repeated Sequence sequences = 2;
......
......@@ -93,7 +93,6 @@ class {{interface.name}}Impl : public {{mojom_type}} {
{%- if method.response_parameters != None %}
mojolpm::GetContext()->AddInstance<{{mojom_type}}::{{method.name}}Callback>(std::move(callback));
{%- endif %}
mojolpm::GetContext()->NextAction();
}
{%- endfor %}
};
......@@ -251,16 +250,16 @@ bool ToProto(::mojo::PendingAssociatedReceiver<{{mojom_type}}>&& input,
{%- set mojom_type = interface|get_qualified_name_for_kind(flatten_nested_kind=True) %}
{%- set proto_type = "::mojolpm" ~ (interface|get_qualified_name_for_kind(flatten_nested_kind=True)) %}
{%- if interface.methods %}
bool HandleRemoteCall(const {{proto_type}}::RemoteCall& input) {
bool HandleRemoteAction(const {{proto_type}}::RemoteAction& input) {
bool result = true;
switch (input.method_case()) {
{%- for method in interface.methods %}
case {{proto_type}}::RemoteCall::k{{("m_" ~ method.name)|under_to_camel(digits_split=True)}}: {
case {{proto_type}}::RemoteAction::k{{("m_" ~ method.name)|under_to_camel(digits_split=True)}}: {
result = HandleRemoteCall(input.id(), input.{{("m" ~ method.name)|camel_to_under}}());
} break;
{%- endfor %}
case {{proto_type}}::RemoteCall::kReset: {
case {{proto_type}}::RemoteAction::kReset: {
mojolpm::GetContext()->GetAndRemoveInstance<::mojo::Remote<{{mojom_type}}>>(input.id());
} break;
......@@ -272,16 +271,16 @@ bool HandleRemoteCall(const {{proto_type}}::RemoteCall& input) {
return result;
}
bool HandleAssociatedRemoteCall(const {{proto_type}}::AssociatedRemoteCall& input) {
bool HandleAssociatedRemoteAction(const {{proto_type}}::AssociatedRemoteAction& input) {
bool result = true;
switch (input.method_case()) {
{%- for method in interface.methods %}
case {{proto_type}}::AssociatedRemoteCall::k{{("m_" ~ method.name)|under_to_camel(digits_split=True)}}: {
case {{proto_type}}::AssociatedRemoteAction::k{{("m_" ~ method.name)|under_to_camel(digits_split=True)}}: {
result = HandleAssociatedRemoteCall(input.id(), input.{{("m" ~ method.name)|camel_to_under}}());
} break;
{%- endfor %}
case {{proto_type}}::AssociatedRemoteCall::kReset: {
case {{proto_type}}::AssociatedRemoteAction::kReset: {
mojolpm::GetContext()->GetAndRemoveInstance<::mojo::AssociatedRemote<{{mojom_type}}>>(input.id());
} break;
......@@ -293,12 +292,12 @@ bool HandleAssociatedRemoteCall(const {{proto_type}}::AssociatedRemoteCall& inpu
return result;
}
bool HandleResponse(
const {{proto_type}}::ReceiverResponse& input) {
bool HandleReceiverAction(
const {{proto_type}}::ReceiverAction& input) {
bool result = true;
switch (input.response_case()) {
{%- for method in interface.methods %}
case {{proto_type}}::ReceiverResponse::k{{("m_" ~ method.name ~ "_response")|under_to_camel(digits_split=True)}}: {
case {{proto_type}}::ReceiverAction::k{{("m_" ~ method.name ~ "_response")|under_to_camel(digits_split=True)}}: {
result = HandleResponse(input.id(), input.{{("m" ~ method.name ~ "_response")|camel_to_under}}());
} break;
{%- endfor %}
......@@ -326,7 +325,6 @@ static void {{interface.name}}_{{method.name}}Callback(
{{ util.add_instance(kind, 'param_' ~ name, False) }}
{%- endfor %}
mojolpmdbg("{{interface.name}}.{{method.name}}Callback\n");
mojolpm::GetContext()->NextAction();
}{{"\n"-}}
{%- endif %}
template <typename T>
......
......@@ -177,14 +177,14 @@ bool ToProto(
{%- set mojom_type = interface|get_qualified_name_for_kind(flatten_nested_kind=True) %}
{%- set proto_type = "::mojolpm" ~ (interface|get_qualified_name_for_kind(flatten_nested_kind=True)) %}
{%- if interface.methods %}
bool HandleRemoteCall(
const {{proto_type}}::RemoteCall& input);
bool HandleRemoteAction(
const {{proto_type}}::RemoteAction& input);
bool HandleAssociatedRemoteCall(
const {{proto_type}}::AssociatedRemoteCall& input);
bool HandleAssociatedRemoteAction(
const {{proto_type}}::AssociatedRemoteAction& input);
bool HandleResponse(
const {{proto_type}}::ReceiverResponse& response);{{"\n"-}}
bool HandleReceiverAction(
const {{proto_type}}::ReceiverAction& input);{{"\n"-}}
{%- for method in interface.methods %}
bool HandleRemoteCall(
uint32_t instance_id,
......
......@@ -316,7 +316,7 @@ message {{interface.name}} {
{%- endfor%}
{%- if interface.methods|length %}
message RemoteCall {
message RemoteAction {
required uint32 id = 1;
oneof method {
......@@ -327,7 +327,7 @@ message {{interface.name}} {
}
}
message AssociatedRemoteCall {
message AssociatedRemoteAction {
required uint32 id = 1;
oneof method {
......@@ -338,7 +338,7 @@ message {{interface.name}} {
}
}
message ReceiverResponse {
message ReceiverAction {
required uint32 id = 1;
oneof response {
......
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