diff --git a/repos/gems/src/lib/tresor/include/tresor/init/configuration.h b/repos/gems/src/lib/tresor/include/tresor/init/configuration.h index 5ab94ff416..fbfdfa263d 100644 --- a/repos/gems/src/lib/tresor/include/tresor/init/configuration.h +++ b/repos/gems/src/lib/tresor/include/tresor/init/configuration.h @@ -18,9 +18,13 @@ /* base includes */ #include +/* tresor includes */ +#include + namespace Tresor_init { using namespace Genode; + using namespace Tresor; class Configuration; } @@ -36,6 +40,12 @@ class Tresor_init::Configuration uint64_t _ft_nr_of_children { 0 }; uint64_t _ft_nr_of_leafs { 0 }; + static bool _is_power_of_2(uint64_t val) + { + for (; val && (val & 1) == 0; val >>= 1); + return val == 1; + } + public: struct Invalid : Exception { }; @@ -62,15 +72,17 @@ class Tresor_init::Configuration _ft_nr_of_leafs = ft.attribute_value("nr_of_leafs", (uint64_t)0); }); - if (_vbd_nr_of_lvls == 0 || - _vbd_nr_of_children == 0 || - _vbd_nr_of_leafs == 0 || - _ft_nr_of_lvls == 0 || - _ft_nr_of_children == 0 || - _ft_nr_of_leafs == 0) - { - throw Invalid(); - } + ASSERT(_vbd_nr_of_lvls); + ASSERT(_vbd_nr_of_lvls <= TREE_MAX_NR_OF_LEVELS); + ASSERT(_vbd_nr_of_leafs); + ASSERT(_is_power_of_2(_vbd_nr_of_children)); + ASSERT(_vbd_nr_of_children <= NR_OF_T1_NODES_PER_BLK); + ASSERT(_ft_nr_of_lvls); + ASSERT(_ft_nr_of_lvls <= TREE_MAX_NR_OF_LEVELS); + ASSERT(_ft_nr_of_leafs); + ASSERT(_is_power_of_2(_ft_nr_of_children)); + ASSERT(_ft_nr_of_children <= NR_OF_T1_NODES_PER_BLK); + ASSERT(_ft_nr_of_children <= NR_OF_T2_NODES_PER_BLK); } Configuration (Configuration const &other)