mirror of
https://github.com/genodelabs/genode.git
synced 2025-02-11 13:35:27 +00:00
timer/nova: prevent potential division by zero
This case triggered with the leitzentrale.run script on Qemu. The frequency value must never initialized with zero. Fixes #3663
This commit is contained in:
parent
87cb10c558
commit
daee1f4cb8
@ -18,6 +18,7 @@
|
|||||||
/* Genode includes */
|
/* Genode includes */
|
||||||
#include <trace/timestamp.h>
|
#include <trace/timestamp.h>
|
||||||
#include <base/attached_rom_dataspace.h>
|
#include <base/attached_rom_dataspace.h>
|
||||||
|
#include <base/log.h>
|
||||||
|
|
||||||
/* local includes */
|
/* local includes */
|
||||||
#include <threaded_time_source.h>
|
#include <threaded_time_source.h>
|
||||||
@ -36,16 +37,24 @@ class Timer::Time_source : public Threaded_time_source
|
|||||||
/* read the tsc frequency from platform info */
|
/* read the tsc frequency from platform info */
|
||||||
static unsigned long _obtain_tsc_khz(Genode::Env &env)
|
static unsigned long _obtain_tsc_khz(Genode::Env &env)
|
||||||
{
|
{
|
||||||
|
unsigned long result = 0;
|
||||||
try {
|
try {
|
||||||
Genode::Attached_rom_dataspace info { env, "platform_info"};
|
Genode::Attached_rom_dataspace info { env, "platform_info"};
|
||||||
|
|
||||||
return info.xml()
|
result = info.xml().sub_node("hardware")
|
||||||
.sub_node("hardware")
|
.sub_node("tsc")
|
||||||
.sub_node("tsc")
|
.attribute_value("freq_khz", 0UL);
|
||||||
.attribute_value("freq_khz", 0UL);
|
|
||||||
} catch (...) { }
|
} catch (...) { }
|
||||||
|
|
||||||
return 0;
|
if (result)
|
||||||
|
return result;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* The returned value must never be zero because it is used as
|
||||||
|
* divisor by '_tsc_to_us'.
|
||||||
|
*/
|
||||||
|
Genode::warning("unable to obtain tsc frequency, asuming 1 GHz");
|
||||||
|
return 1000*1000;
|
||||||
}
|
}
|
||||||
|
|
||||||
Genode::addr_t _sem { ~0UL };
|
Genode::addr_t _sem { ~0UL };
|
||||||
|
Loading…
x
Reference in New Issue
Block a user