From aa0a98bd43b73cbe19d8b183d7f4da4d60bdbdb5 Mon Sep 17 00:00:00 2001 From: Norman Feske Date: Fri, 5 Mar 2021 17:59:46 +0100 Subject: [PATCH] base-foc/hw: avoid use of placement new operator Fixes #2106 --- .../src/include/base/internal/cap_alloc.h | 8 +++---- .../include/base/internal/capability_data.h | 1 - repos/base-hw/src/test/cpu_scheduler/test.cc | 22 ++++++++++--------- repos/base-hw/src/test/double_list/test.cc | 5 ++--- 4 files changed, 18 insertions(+), 18 deletions(-) diff --git a/repos/base-foc/src/include/base/internal/cap_alloc.h b/repos/base-foc/src/include/base/internal/cap_alloc.h index eb2414b576..e45ef07224 100644 --- a/repos/base-foc/src/include/base/internal/cap_alloc.h +++ b/repos/base-foc/src/include/base/internal/cap_alloc.h @@ -86,7 +86,7 @@ class Genode::Cap_index_allocator_tpl : public Cap_index_allocator /* if we found a fitting hole, initialize the objects */ if (j == cnt) { for (j = 0; j < cnt; j++) - new (&_indices[i+j]) T(); + construct_at(&_indices[i+j]); return &_indices[i]; } } @@ -102,14 +102,14 @@ class Genode::Cap_index_allocator_tpl : public Cap_index_allocator * construct the Cap_index pointer from the given * address in capability space */ - T * const obj = reinterpret_cast(kcap_to_idx(addr)); + T * const obj_ptr = reinterpret_cast(kcap_to_idx(addr)); - if (obj < &_indices[0] || obj >= &_indices[SZ]) { + if (obj_ptr < &_indices[0] || obj_ptr >= &_indices[SZ]) { ASSERT(0, "cap index out of bounds"); throw Index_out_of_bounds(); } - return new (obj) T(); + return construct_at(obj_ptr); } void free(Cap_index* idx, size_t cnt) override diff --git a/repos/base-foc/src/include/base/internal/capability_data.h b/repos/base-foc/src/include/base/internal/capability_data.h index 566fe093a3..fcea106e2e 100644 --- a/repos/base-foc/src/include/base/internal/capability_data.h +++ b/repos/base-foc/src/include/base/internal/capability_data.h @@ -48,7 +48,6 @@ class Genode::Native_capability::Data : public Avl_node uint8_t dec(); addr_t kcap() const; - void* operator new (__SIZE_TYPE__, Data* idx) { return idx; } void operator delete (void* idx) { memset(idx, 0, sizeof(Data)); } diff --git a/repos/base-hw/src/test/cpu_scheduler/test.cc b/repos/base-hw/src/test/cpu_scheduler/test.cc index dcd486597e..66ff0d7286 100644 --- a/repos/base-hw/src/test/cpu_scheduler/test.cc +++ b/repos/base-hw/src/test/cpu_scheduler/test.cc @@ -11,6 +11,8 @@ * under the terms of the GNU Affero General Public License version 3. */ +/* Genode includes */ +#include #include /* core includes */ @@ -22,10 +24,10 @@ using Genode::size_t; using Genode::addr_t; +using Genode::construct_at; using Kernel::Cpu_share; using Kernel::Cpu_scheduler; -void * operator new(__SIZE_TYPE__, void * p) { return p; } struct Data { @@ -73,15 +75,15 @@ void create(unsigned const id) Cpu_share * const s = share(id); void * const p = (void *)s; switch (id) { - case 1: new (p) Cpu_share(2, 230); break; - case 2: new (p) Cpu_share(0, 170); break; - case 3: new (p) Cpu_share(3, 110); break; - case 4: new (p) Cpu_share(1, 90); break; - case 5: new (p) Cpu_share(3, 120); break; - case 6: new (p) Cpu_share(3, 0); break; - case 7: new (p) Cpu_share(2, 180); break; - case 8: new (p) Cpu_share(2, 100); break; - case 9: new (p) Cpu_share(2, 0); break; + case 1: construct_at(p, 2, 230); break; + case 2: construct_at(p, 0, 170); break; + case 3: construct_at(p, 3, 110); break; + case 4: construct_at(p, 1, 90); break; + case 5: construct_at(p, 3, 120); break; + case 6: construct_at(p, 3, 0); break; + case 7: construct_at(p, 2, 180); break; + case 8: construct_at(p, 2, 100); break; + case 9: construct_at(p, 2, 0); break; default: return; } data()->scheduler.insert(*s); diff --git a/repos/base-hw/src/test/double_list/test.cc b/repos/base-hw/src/test/double_list/test.cc index c10ca24a3e..ae88aeb153 100644 --- a/repos/base-hw/src/test/double_list/test.cc +++ b/repos/base-hw/src/test/double_list/test.cc @@ -12,6 +12,7 @@ */ /* base includes */ +#include #include #include @@ -27,8 +28,6 @@ using Genode::size_t; using Kernel::Double_list; using Kernel::Double_list_item; -void * operator new(__SIZE_TYPE__, void * p) { return p; } - struct Item_load { char volatile x = 0, y = 0, z = 0; }; @@ -53,7 +52,7 @@ struct Data Data() { for (unsigned i = 0; i < nr_of_items; i++) { - new (&items[i]) Item(i + 1); } + Genode::construct_at(&items[i], i + 1); } } };