From 1ccd9a2fdb22e7a16fb1a6c56c7dff9cb6dd4873 Mon Sep 17 00:00:00 2001 From: Norman Feske Date: Thu, 19 Oct 2017 13:22:22 +0200 Subject: [PATCH] rom_filter: expand target buffer on demand The ROM filter did not handle the situation where the generated content exceeds the size of the initially allocated dataspace for the target buffer. This patch wraps the XML generation in a retry loop that expands the buffer as needed. --- repos/os/src/server/rom_filter/main.cc | 23 +++++++++++++++++------ 1 file changed, 17 insertions(+), 6 deletions(-) diff --git a/repos/os/src/server/rom_filter/main.cc b/repos/os/src/server/rom_filter/main.cc index 271e16c7e5..fb1c953383 100644 --- a/repos/os/src/server/rom_filter/main.cc +++ b/repos/os/src/server/rom_filter/main.cc @@ -15,6 +15,7 @@ #include #include #include +#include #include #include #include @@ -329,12 +330,22 @@ void Rom_filter::Main::_evaluate() Node_type_name const node_type = output.attribute_value("node", Node_type_name("")); - /* generate output */ - Xml_generator xml(_xml_ds->local_addr(), - _xml_ds->size(), node_type.string(), - [&] () { _evaluate_node(output, xml); }); - - _xml_output_len = xml.used(); + /* + * Generate output, expand dataspace on demand + */ + enum { UPGRADE = 4096, NUM_ATTEMPTS = ~0L }; + Genode::retry( + [&] () { + Xml_generator xml(_xml_ds->local_addr(), + _xml_ds->size(), node_type.string(), + [&] () { _evaluate_node(output, xml); }); + _xml_output_len = xml.used(); + }, + [&] () { + Genode::log("UPGRADING XML DATASPACE"); + _xml_ds.construct(_env.ram(), _env.rm(), _xml_ds->size() + UPGRADE); + }, + NUM_ATTEMPTS); } catch (Xml_node::Nonexistent_sub_node) { }