base-foc/hw: avoid use of placement new operator

Fixes #2106
This commit is contained in:
Norman Feske 2021-03-05 17:59:46 +01:00
parent 42f3d2eccd
commit aa0a98bd43
4 changed files with 18 additions and 18 deletions

View File

@ -86,7 +86,7 @@ class Genode::Cap_index_allocator_tpl : public Cap_index_allocator
/* if we found a fitting hole, initialize the objects */ /* if we found a fitting hole, initialize the objects */
if (j == cnt) { if (j == cnt) {
for (j = 0; j < cnt; j++) for (j = 0; j < cnt; j++)
new (&_indices[i+j]) T(); construct_at<T>(&_indices[i+j]);
return &_indices[i]; 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 * construct the Cap_index pointer from the given
* address in capability space * address in capability space
*/ */
T * const obj = reinterpret_cast<T*>(kcap_to_idx(addr)); T * const obj_ptr = reinterpret_cast<T*>(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"); ASSERT(0, "cap index out of bounds");
throw Index_out_of_bounds(); throw Index_out_of_bounds();
} }
return new (obj) T(); return construct_at<T>(obj_ptr);
} }
void free(Cap_index* idx, size_t cnt) override void free(Cap_index* idx, size_t cnt) override

View File

@ -48,7 +48,6 @@ class Genode::Native_capability::Data : public Avl_node<Data>
uint8_t dec(); uint8_t dec();
addr_t kcap() const; addr_t kcap() const;
void* operator new (__SIZE_TYPE__, Data* idx) { return idx; }
void operator delete (void* idx) { memset(idx, 0, sizeof(Data)); } void operator delete (void* idx) { memset(idx, 0, sizeof(Data)); }

View File

@ -11,6 +11,8 @@
* under the terms of the GNU Affero General Public License version 3. * under the terms of the GNU Affero General Public License version 3.
*/ */
/* Genode includes */
#include <util/construct_at.h>
#include <base/component.h> #include <base/component.h>
/* core includes */ /* core includes */
@ -22,10 +24,10 @@
using Genode::size_t; using Genode::size_t;
using Genode::addr_t; using Genode::addr_t;
using Genode::construct_at;
using Kernel::Cpu_share; using Kernel::Cpu_share;
using Kernel::Cpu_scheduler; using Kernel::Cpu_scheduler;
void * operator new(__SIZE_TYPE__, void * p) { return p; }
struct Data struct Data
{ {
@ -73,15 +75,15 @@ void create(unsigned const id)
Cpu_share * const s = share(id); Cpu_share * const s = share(id);
void * const p = (void *)s; void * const p = (void *)s;
switch (id) { switch (id) {
case 1: new (p) Cpu_share(2, 230); break; case 1: construct_at<Cpu_share>(p, 2, 230); break;
case 2: new (p) Cpu_share(0, 170); break; case 2: construct_at<Cpu_share>(p, 0, 170); break;
case 3: new (p) Cpu_share(3, 110); break; case 3: construct_at<Cpu_share>(p, 3, 110); break;
case 4: new (p) Cpu_share(1, 90); break; case 4: construct_at<Cpu_share>(p, 1, 90); break;
case 5: new (p) Cpu_share(3, 120); break; case 5: construct_at<Cpu_share>(p, 3, 120); break;
case 6: new (p) Cpu_share(3, 0); break; case 6: construct_at<Cpu_share>(p, 3, 0); break;
case 7: new (p) Cpu_share(2, 180); break; case 7: construct_at<Cpu_share>(p, 2, 180); break;
case 8: new (p) Cpu_share(2, 100); break; case 8: construct_at<Cpu_share>(p, 2, 100); break;
case 9: new (p) Cpu_share(2, 0); break; case 9: construct_at<Cpu_share>(p, 2, 0); break;
default: return; default: return;
} }
data()->scheduler.insert(*s); data()->scheduler.insert(*s);

View File

@ -12,6 +12,7 @@
*/ */
/* base includes */ /* base includes */
#include <util/construct_at.h>
#include <base/component.h> #include <base/component.h>
#include <base/log.h> #include <base/log.h>
@ -27,8 +28,6 @@ using Genode::size_t;
using Kernel::Double_list; using Kernel::Double_list;
using Kernel::Double_list_item; 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; }; struct Item_load { char volatile x = 0, y = 0, z = 0; };
@ -53,7 +52,7 @@ struct Data
Data() Data()
{ {
for (unsigned i = 0; i < nr_of_items; i++) { for (unsigned i = 0; i < nr_of_items; i++) {
new (&items[i]) Item(i + 1); } Genode::construct_at<Item>(&items[i], i + 1); }
} }
}; };