diff --git a/repos/libports/src/lib/libc/rwlock.cc b/repos/libports/src/lib/libc/rwlock.cc index f96238e98..a1ac4ca2e 100644 --- a/repos/libports/src/lib/libc/rwlock.cc +++ b/repos/libports/src/lib/libc/rwlock.cc @@ -17,11 +17,16 @@ #include #include #include +#include /* Libc includes */ #include #include + +static Libc::Allocator object_alloc; + + /* * A reader-preferring implementation of a readers-writer lock as described * in Michael Raynal, "Concurrent Programming: Algorithms, Principles, and @@ -100,7 +105,7 @@ extern "C" { try { Genode::Lock::Guard g(rwlock_init_lock); - *rwlock = new struct pthread_rwlock(); + *rwlock = new (object_alloc) struct pthread_rwlock(); return 0; } catch (...) { return ENOMEM; } } @@ -112,7 +117,7 @@ extern "C" { int pthread_rwlock_destroy(pthread_rwlock_t *rwlock) { - delete *rwlock; + destroy(object_alloc, *rwlock); return 0; } @@ -149,7 +154,7 @@ extern "C" { int pthread_rwlockattr_init(pthread_rwlockattr_t *attr) { - *attr = new struct pthread_rwlockattr(); + *attr = new (object_alloc) struct pthread_rwlockattr(); return 0; } @@ -170,7 +175,7 @@ extern "C" { int pthread_rwlockattr_destroy(pthread_rwlockattr_t *attr) { - delete *attr; + destroy(object_alloc, *attr); return 0; } diff --git a/repos/libports/src/lib/libc/select.cc b/repos/libports/src/lib/libc/select.cc index 924f64c9c..84abffc5b 100644 --- a/repos/libports/src/lib/libc/select.cc +++ b/repos/libports/src/lib/libc/select.cc @@ -201,7 +201,7 @@ static void select_notify() } -static void print(Genode::Output &output, timeval *tv) +static inline void print(Genode::Output &output, timeval *tv) { if (!tv) { print(output, "nullptr"); diff --git a/repos/libports/src/lib/libc/semaphore.cc b/repos/libports/src/lib/libc/semaphore.cc index 90627bf4c..a2ef3c8f0 100644 --- a/repos/libports/src/lib/libc/semaphore.cc +++ b/repos/libports/src/lib/libc/semaphore.cc @@ -15,9 +15,13 @@ #include #include #include +#include using namespace Genode; + +static Libc::Allocator object_alloc; + extern "C" { /* @@ -39,7 +43,7 @@ extern "C" { int sem_destroy(sem_t *sem) { - delete *sem; + destroy(object_alloc, *sem); return 0; } @@ -53,7 +57,7 @@ extern "C" { int sem_init(sem_t *sem, int pshared, unsigned int value) { - *sem = new struct sem(value); + *sem = new (object_alloc) struct sem(value); return 0; } diff --git a/repos/libports/src/lib/libc/thread.cc b/repos/libports/src/lib/libc/thread.cc index 1981345e6..c569e4275 100644 --- a/repos/libports/src/lib/libc/thread.cc +++ b/repos/libports/src/lib/libc/thread.cc @@ -16,6 +16,7 @@ #include #include #include +#include #include #include @@ -28,8 +29,7 @@ using namespace Genode; -void * operator new(__SIZE_TYPE__ size) { return malloc(size); } -void operator delete (void * p) { return free(p); } +static Libc::Allocator object_alloc; static Env *_env_ptr; /* solely needed to spawn the timeout thread for the @@ -172,7 +172,7 @@ extern "C" { { thread->join(retval); - delete thread; + destroy(object_alloc, thread); return 0; } @@ -183,7 +183,7 @@ extern "C" { if (!attr) return EINVAL; - *attr = new pthread_attr; + *attr = new (object_alloc) pthread_attr; return 0; } @@ -194,7 +194,7 @@ extern "C" { if (!attr || !*attr) return EINVAL; - delete *attr; + destroy(object_alloc, *attr); *attr = 0; return 0; @@ -251,7 +251,7 @@ extern "C" { * of the pthread object would also destruct the 'Thread' of the main * thread. */ - static pthread *main = new pthread(*Thread::myself()); + static pthread *main = new (object_alloc) pthread(*Thread::myself()); return main; } @@ -498,7 +498,7 @@ extern "C" { if (!attr) return EINVAL; - *attr = new pthread_mutex_attr; + *attr = new (object_alloc) pthread_mutex_attr; return 0; } @@ -509,7 +509,7 @@ extern "C" { if (!attr || !*attr) return EINVAL; - delete *attr; + destroy(object_alloc, *attr); *attr = 0; return 0; @@ -533,7 +533,7 @@ extern "C" { if (!mutex) return EINVAL; - *mutex = new pthread_mutex(attr); + *mutex = new (object_alloc) pthread_mutex(attr); return 0; } @@ -544,7 +544,7 @@ extern "C" { if ((!mutex) || (*mutex == PTHREAD_MUTEX_INITIALIZER)) return EINVAL; - delete *mutex; + destroy(object_alloc, *mutex); *mutex = PTHREAD_MUTEX_INITIALIZER; return 0; @@ -655,7 +655,7 @@ extern "C" { try { Genode::Lock::Guard g(cond_init_lock); - *cond = new pthread_cond; + *cond = new (object_alloc) pthread_cond; return 0; } catch (...) { return ENOMEM; } } @@ -673,7 +673,7 @@ extern "C" { if (!cond || !*cond) return EINVAL; - delete *cond; + destroy(object_alloc, *cond); *cond = 0; return 0; @@ -854,7 +854,7 @@ extern "C" { * thread to mark the key slot as used. */ if (!key_list[k].first()) { - Key_element *key_element = new Key_element(Thread::myself(), 0); + Key_element *key_element = new (object_alloc) Key_element(Thread::myself(), 0); key_list[k].insert(key_element); *key = k; return 0; @@ -874,7 +874,7 @@ extern "C" { while (Key_element * element = key_list[key].first()) { key_list[key].remove(element); - delete element; + destroy(object_alloc, element); } return 0; @@ -898,7 +898,7 @@ extern "C" { } /* key element does not exist yet - create a new one */ - Key_element *key_element = new Key_element(Thread::myself(), value); + Key_element *key_element = new (object_alloc) Key_element(Thread::myself(), value); key_list[key].insert(key_element); return 0; } @@ -929,7 +929,7 @@ extern "C" { return EINTR; if (!once->mutex) { - pthread_mutex_t p = new pthread_mutex(0); + pthread_mutex_t p = new (object_alloc) pthread_mutex(0); /* be paranoid */ if (!p) return EINTR; @@ -948,7 +948,7 @@ extern "C" { * free our mutex since it is not used. */ if (p) - delete p; + destroy(object_alloc, p); } once->mutex->lock(); diff --git a/repos/libports/src/lib/libc/thread_create.cc b/repos/libports/src/lib/libc/thread_create.cc index f0f891670..7f54e8d29 100644 --- a/repos/libports/src/lib/libc/thread_create.cc +++ b/repos/libports/src/lib/libc/thread_create.cc @@ -14,18 +14,24 @@ * under the terms of the GNU Affero General Public License version 3. */ +#include + #include "thread_create.h" #include "thread.h" #include +static Libc::Allocator object_alloc; + + int Libc::pthread_create(pthread_t *thread, void *(*start_routine) (void *), void *arg, size_t stack_size, char const * name, Genode::Cpu_session * cpu, Genode::Affinity::Location location) { - pthread_t thread_obj = new pthread(start_routine, arg, - stack_size, name, cpu, location); + pthread_t thread_obj = new (object_alloc) + pthread(start_routine, arg, + stack_size, name, cpu, location); if (!thread_obj) return EAGAIN; @@ -39,7 +45,7 @@ int Libc::pthread_create(pthread_t *thread, int Libc::pthread_create(pthread_t *thread, Genode::Thread &t) { - pthread_t thread_obj = new pthread(t); + pthread_t thread_obj = new (object_alloc) pthread(t); if (!thread_obj) return EAGAIN;