Avoid use of deprecated Xml_node methods

Issue #3755
This commit is contained in:
Norman Feske
2020-05-06 19:06:25 +02:00
parent d22b95ded3
commit be65c4acd2
16 changed files with 196 additions and 212 deletions

View File

@ -38,6 +38,8 @@ class Boot_module_provider
enum { MODULE_NAME_MAX_LEN = 48 };
typedef Genode::String<MODULE_NAME_MAX_LEN> Name;
public:
/**
@ -83,17 +85,13 @@ class Boot_module_provider
* attribute of the 'rom' node. If no 'label' argument is
* provided, use the 'name' attribute as file name.
*/
char name[MODULE_NAME_MAX_LEN];
try {
mod_node.attribute("label").value(name, sizeof(name));
} catch (Xml_node::Nonexistent_attribute) {
mod_node.attribute("name").value(name, sizeof(name));
}
Name const label = mod_node.has_attribute("label")
? mod_node.attribute_value("label", Name())
: mod_node.attribute_value("name", Name());
/*
* Open ROM session
*/
Rom_connection rom(env, name);
Rom_connection rom(env, label.string());
Dataspace_capability ds = rom.dataspace();
Genode::size_t const src_len = Dataspace_client(ds).size();
@ -117,18 +115,14 @@ class Boot_module_provider
env.rm().detach(src);
return src_len;
} else if (mod_node.has_type("inline")) {
/*
* Determine ROM file name, which is specified as 'name'
* attribute of the 'rom' node.
*/
char name[MODULE_NAME_MAX_LEN];
mod_node.attribute("name").value(name, sizeof(name));
/*
* Copy inline content directly to destination buffer
*/
Genode::memcpy(dst, mod_node.content_addr(), mod_node.content_size());
mod_node.with_raw_content([&] (char const *ptr, size_t size) {
Genode::memcpy(dst, ptr, size); });
return mod_node.content_size();
}
@ -177,10 +171,9 @@ class Boot_module_provider
Genode::size_t cmd_len = 0;
char name[MODULE_NAME_MAX_LEN];
mod_node.attribute("name").value(name, sizeof(name));
Name const name = mod_node.attribute_value("name", Name());
Genode::size_t const name_len = Genode::strlen(name);
Genode::size_t const name_len = Genode::strlen(name.string());
/*
* Check if destination buffer can hold the name including
@ -190,7 +183,7 @@ class Boot_module_provider
return 0;
/* copy name to command line */
strncpy(&dst[cmd_len], name, name_len + 1);
strncpy(&dst[cmd_len], name.string(), name_len + 1);
cmd_len += name_len;
/* check if name fills entire destination buffer */
@ -199,8 +192,10 @@ class Boot_module_provider
return cmd_len;
}
try {
Xml_node::Attribute cmdline_attr = mod_node.attribute("cmdline");
if (mod_node.has_attribute("cmdline")) {
typedef String<256> Cmdline;
Cmdline const cmdline = mod_node.attribute_value("cmdline", Cmdline());
/* add single space between name and arguments */
dst[cmd_len++] = ' ';
@ -210,7 +205,7 @@ class Boot_module_provider
}
/* copy 'cmdline' attribute to destination buffer */
cmdline_attr.value(&dst[cmd_len], dst_len - cmd_len);
Genode::strncpy(&dst[cmd_len], cmdline.string(), dst_len - cmd_len);
/*
* The string returned by the 'value' function is
@ -219,7 +214,7 @@ class Boot_module_provider
*/
return Genode::strlen(dst);
} catch (Xml_node::Nonexistent_attribute) { }
}
return cmd_len;
}

View File

@ -1242,18 +1242,18 @@ class Machine : public StaticReceiver<Machine>
Xml_node node = machine_node.sub_node();
for (;; node = node.next()) {
enum { MODEL_NAME_MAX_LEN = 32 };
char name[MODEL_NAME_MAX_LEN];
node.type_name(name, sizeof(name));
typedef String<32> Model_name;
Model_name const name = node.type();
if (verbose)
Genode::log("device: ", (char const *)name);
Genode::log("device: ", name);
Device_model_info *dmi = device_model_registry()->lookup(name);
Device_model_info *dmi = device_model_registry()->lookup(name.string());
if (!dmi) {
Genode::error("configuration error: device model '",
(char const *)name, "' does not exist");
name, "' does not exist");
throw Config_error();
}
@ -1267,15 +1267,11 @@ class Machine : public StaticReceiver<Machine>
argv[i] = ~0UL;
for (int i = 0; dmi->arg_names[i] && (i < MAX_ARGS); i++) {
try {
Xml_node::Attribute arg = node.attribute(dmi->arg_names[i]);
arg.value(&argv[i]);
if (node.has_attribute(dmi->arg_names[i])) {
argv[i] = node.attribute_value(dmi->arg_names[i], ~0UL);
if (verbose)
Genode::log(" arg[", i, "]: ", Genode::Hex(argv[i]));
}
catch (Xml_node::Nonexistent_attribute) { }
}
/*

View File

@ -120,6 +120,16 @@ static void inline cpuid(unsigned *eax, unsigned *ebx, unsigned *ecx, unsigned *
asm volatile ("cpuid" : "+a" (*eax), "+d" (*edx), "+b" (*ebx), "+c"(*ecx) :: "memory");
}
static unsigned cpu_attribute_value(Genode::Xml_node const &cpu, char const *attribute)
{
if (!cpu.has_attribute(attribute)) {
Genode::error("missing cpu attribute ", attribute);
throw Genode::Exception();
}
return cpu.attribute_value(attribute, 0U);
}
void Component::construct(Genode::Env &env)
{
using namespace Genode;
@ -141,15 +151,13 @@ void Component::construct(Genode::Env &env)
try {
Xml_node const cpus = platform_info.xml().sub_node("hardware").sub_node("cpus");
cpus.for_each_sub_node("cpu", [&] (Xml_node cpu) {
uint8_t family = 0, model = 0, stepping = 0, platform = 0;
unsigned id = 0, patch = 0;
cpu.attribute("id").value(&id);
cpu.attribute("family").value(&family);
cpu.attribute("model").value(&model);
cpu.attribute("stepping").value(&stepping);
cpu.attribute("platform").value(&platform);
cpu.attribute("patch").value(&patch);
unsigned const id = cpu_attribute_value(cpu, "id");
uint8_t const family = cpu_attribute_value(cpu, "family");
uint8_t const model = cpu_attribute_value(cpu, "model");
uint8_t const stepping = cpu_attribute_value(cpu, "stepping");
uint8_t const platform = cpu_attribute_value(cpu, "platform");
unsigned const patch = cpu_attribute_value(cpu, "patch");
String<9> name(Hex(family, Hex::OMIT_PREFIX, Hex::PAD), "-",
Hex(model, Hex::OMIT_PREFIX, Hex::PAD), "-",

View File

@ -262,18 +262,25 @@ void Libc::Component::construct(Libc::Env &env)
/* make Genode environment accessible via the global 'genode_env()' */
genode_env_ptr = &env;
try {
{
using namespace Genode;
Attached_rom_dataspace config(env, "config");
Xml_node::Attribute vbox_file = config.xml().attribute("vbox_file");
vbox_file.value(c_vbox_file, sizeof(c_vbox_file));
Xml_node::Attribute vm_name = config.xml().attribute("vm_name");
vm_name.value(c_vbox_vmname, sizeof(c_vbox_vmname));
} catch (...) {
Genode::error("missing attributes in configuration, minimum requirements: ");
Genode::error(" <config vbox_file=\"...\" vm_name=\"...\">" );
throw;
Attached_rom_dataspace config_ds(env, "config");
Xml_node const config = config_ds.xml();
if (!config.has_attribute("vbox_file") || !config.has_attribute("vm_name")) {
error("missing attributes in configuration, minimum requirements: ");
error(" <config vbox_file=\"...\" vm_name=\"...\">" );
throw Exception();
}
typedef String<128> Name;
Name const vbox_file = config.attribute_value("vbox_file", Name());
Genode::strncpy(c_vbox_file, vbox_file.string(), sizeof(c_vbox_file));
Name const vm_name = config.attribute_value("vm_name", Name());
Genode::strncpy(c_vbox_vmname, vm_name.string(), sizeof(c_vbox_vmname));
}
/* enable stdout/stderr for VBox Log infrastructure */

View File

@ -721,9 +721,12 @@ uint64_t genode_cpu_hz()
if (!cpu_freq) {
try {
platform_rom().sub_node("tsc").attribute("freq_khz").value(&cpu_freq);
platform_rom().with_sub_node("tsc", [&] (Genode::Xml_node const &tsc) {
cpu_freq = tsc.attribute_value("freq_khz", cpu_freq); });
cpu_freq *= 1000ULL;
} catch (...) {
} catch (...) { }
if (cpu_freq == 0) {
Genode::error("could not read out CPU frequency");
Genode::Lock lock;
lock.lock();

View File

@ -693,9 +693,12 @@ uint64_t genode_cpu_hz()
if (!cpu_freq) {
try {
platform_rom().sub_node("tsc").attribute("freq_khz").value(&cpu_freq);
platform_rom().with_sub_node("tsc", [&] (Genode::Xml_node const &tsc) {
cpu_freq = tsc.attribute_value("freq_khz", cpu_freq); });
cpu_freq *= 1000ULL;
} catch (...) {
} catch (...) { }
if (cpu_freq == 0) {
Genode::error("could not read out CPU frequency");
Genode::Lock lock;
lock.lock();