diff --git a/repos/libports/lib/symbols/libc b/repos/libports/lib/symbols/libc index fcda9beecf..240c90235e 100644 --- a/repos/libports/lib/symbols/libc +++ b/repos/libports/lib/symbols/libc @@ -975,8 +975,9 @@ _ZN4Libc19Select_handler_baseD2Ev T _ZN4Libc10resume_allEv T _ZN4Libc7PthreadC2ERN6Genode6ThreadEPv T _ZN4Libc7suspendERNS_15Suspend_functorEm T -_ZN4Libc14pthread_createEPP7pthreadPFPvS3_ES3_mPKcPN6Genode11Cpu_sessionENS8_8Affinity8LocationE T -_ZN4Libc14pthread_createEPP7pthreadRN6Genode6ThreadEPv T +_ZN4Libc14pthread_createEPP7pthreadPKP12pthread_attrPFPvS7_ES7_PKc T +_ZN4Libc26pthread_create_from_threadEPP7pthreadRN6Genode6ThreadEPv T +_ZN4Libc27pthread_create_from_sessionEPP7pthreadPFPvS3_ES3_mPKcPN6Genode11Cpu_sessionENS8_8Affinity8LocationE T # # Libc plugin interface diff --git a/repos/libports/src/lib/libc/internal/thread_create.h b/repos/libports/src/lib/libc/internal/thread_create.h index ec8dd40d9a..8b610cc0bb 100644 --- a/repos/libports/src/lib/libc/internal/thread_create.h +++ b/repos/libports/src/lib/libc/internal/thread_create.h @@ -27,12 +27,19 @@ namespace Libc { - int pthread_create(pthread_t *thread, - void *(*start_routine) (void *), void *arg, - size_t stack_size, char const * name, - Cpu_session * cpu, Affinity::Location location); + int pthread_create_from_session(pthread_t *thread, + void *(*start_routine) (void *), + void *arg, + size_t stack_size, + char const * name, + Cpu_session * cpu, + Affinity::Location location); - int pthread_create(pthread_t *, Thread &, void *stack_address); + int pthread_create_from_thread(pthread_t *, Thread &, void *stack_address); + + int pthread_create(pthread_t *thread, pthread_attr_t const *attr, + void *(*start_routine) (void *), void *arg, + char const *name); } #endif /* _LIBC__INTERNAL__THREAD_CREATE_H_ */ diff --git a/repos/libports/src/lib/libc/pthread_create.cc b/repos/libports/src/lib/libc/pthread_create.cc index f569f29ac9..afd0270653 100644 --- a/repos/libports/src/lib/libc/pthread_create.cc +++ b/repos/libports/src/lib/libc/pthread_create.cc @@ -84,10 +84,13 @@ static unsigned pthread_id() } -int Libc::pthread_create(pthread_t *thread, - void *(*start_routine) (void *), void *arg, - size_t stack_size, char const * name, - Cpu_session * cpu, Affinity::Location location) +int Libc::pthread_create_from_session(pthread_t *thread, + void *(*start_routine) (void *), + void *arg, + size_t stack_size, + char const *name, + Cpu_session *cpu, + Affinity::Location location) { Libc::Allocator alloc { }; pthread_t thread_obj = new (alloc) @@ -104,7 +107,7 @@ int Libc::pthread_create(pthread_t *thread, } -int Libc::pthread_create(pthread_t *thread, Thread &t, void *stack_address) +int Libc::pthread_create_from_thread(pthread_t *thread, Thread &t, void *stack_address) { Libc::Allocator alloc { }; @@ -118,41 +121,48 @@ int Libc::pthread_create(pthread_t *thread, Thread &t, void *stack_address) } -extern "C" +int Libc::pthread_create(pthread_t *thread, const pthread_attr_t *attr, + void *(*start_routine) (void *), void *arg, + char const *name) { - int pthread_create(pthread_t *thread, const pthread_attr_t *attr, - void *(*start_routine) (void *), void *arg) - { - if (!_cpu_session || !start_routine || !thread) - return EINVAL; + if (!_cpu_session || !start_routine || !thread) + return EINVAL; - size_t const stack_size = (attr && *attr && (*attr)->stack_size) - ? (*attr)->stack_size - : Libc::Component::stack_size(); + size_t const stack_size = (attr && *attr && (*attr)->stack_size) + ? (*attr)->stack_size + : Libc::Component::stack_size(); - using Genode::Affinity; + using Genode::Affinity; - unsigned const id { pthread_id() }; - unsigned const cpu = (id < sizeof(_id_cpu_map) / sizeof(_id_cpu_map[0])) ? _id_cpu_map[id] : 0; + unsigned const id { pthread_id() }; + unsigned const cpu = (id < sizeof(_id_cpu_map) / sizeof(_id_cpu_map[0])) ? _id_cpu_map[id] : 0; - Genode::String<32> const pthread_name { "pthread.", id }; - Affinity::Space space { _cpu_session->affinity_space() }; - Affinity::Location location { space.location_of_index(cpu) }; + Genode::String<32> const pthread_name { "pthread.", id }; + Affinity::Space space { _cpu_session->affinity_space() }; + Affinity::Location location { space.location_of_index(cpu) }; - if (_verbose) - Genode::log("create ", pthread_name, " -> cpu ", cpu); + if (_verbose) + Genode::log("create ", pthread_name, " -> cpu ", cpu); - int result = Libc::pthread_create(thread, start_routine, arg, stack_size, - pthread_name.string(), _cpu_session, - location); + int result = + Libc::pthread_create_from_session(thread, start_routine, arg, + stack_size, + name ? : pthread_name.string(), + _cpu_session, location); - if ((result == 0) && attr && *attr && - ((*attr)->detach_state == PTHREAD_CREATE_DETACHED)) - pthread_detach(*thread); + if ((result == 0) && attr && *attr && + ((*attr)->detach_state == PTHREAD_CREATE_DETACHED)) + pthread_detach(*thread); - return result; - } - - typeof(pthread_create) _pthread_create - __attribute__((alias("pthread_create"))); + return result; } + + +extern "C" int pthread_create(pthread_t *thread, const pthread_attr_t *attr, + void *(*start_routine) (void *), void *arg) +{ + return Libc::pthread_create(thread, attr, start_routine, arg, nullptr); +} + + +extern "C" typeof(pthread_create) _pthread_create __attribute__((alias("pthread_create"))); diff --git a/repos/ports/src/virtualbox5/devxhci.cc b/repos/ports/src/virtualbox5/devxhci.cc index 8ec1cc5d68..c128628d08 100644 --- a/repos/ports/src/virtualbox5/devxhci.cc +++ b/repos/ports/src/virtualbox5/devxhci.cc @@ -456,7 +456,7 @@ struct Usb_ep : Genode::Entrypoint void _handle_pthread_registration() { Genode::Thread *myself = Genode::Thread::myself(); - if (!myself || Libc::pthread_create(&_pthread, *myself, &myself)) { + if (!myself || Libc::pthread_create_from_thread(&_pthread, *myself, &myself)) { Genode::error("USB passthough will not work - thread for " "pthread registration invalid"); } diff --git a/repos/ports/src/virtualbox5/generic/sup_vmm.cc b/repos/ports/src/virtualbox5/generic/sup_vmm.cc index e4fcd18fd0..d394bd7903 100644 --- a/repos/ports/src/virtualbox5/generic/sup_vmm.cc +++ b/repos/ports/src/virtualbox5/generic/sup_vmm.cc @@ -793,8 +793,8 @@ bool create_emt_vcpu(pthread_t * thread, ::size_t stack_size, vcpu_handler_list().insert(vcpu_handler); - Libc::pthread_create(thread, start_routine, arg, - stack_size, name, cpu_connection, location); + Libc::pthread_create_from_session(thread, start_routine, arg, + stack_size, name, cpu_connection, location); return true; } diff --git a/repos/ports/src/virtualbox5/network.cpp b/repos/ports/src/virtualbox5/network.cpp index 4da50a441d..efbee88777 100644 --- a/repos/ports/src/virtualbox5/network.cpp +++ b/repos/ports/src/virtualbox5/network.cpp @@ -186,7 +186,7 @@ class Nic_client void _handle_pthread_registration() { Genode::Thread *myself = Genode::Thread::myself(); - if (!myself || Libc::pthread_create(&_pthread, *myself, &myself)) { + if (!myself || Libc::pthread_create_from_thread(&_pthread, *myself, &myself)) { Genode::error("network will not work - thread for pthread " "registration invalid"); return; diff --git a/repos/ports/src/virtualbox5/thread.cc b/repos/ports/src/virtualbox5/thread.cc index 358c2a7a89..55f06fd452 100644 --- a/repos/ports/src/virtualbox5/thread.cc +++ b/repos/ports/src/virtualbox5/thread.cc @@ -127,9 +127,9 @@ static int create_thread(pthread_t *thread, const pthread_attr_t *attr, bool const rtthread_timer = rtthread->enmType == RTTHREADTYPE_TIMER; if (rtthread_timer) { - return Libc::pthread_create(thread, start_routine, arg, - stack_size, rtthread->szName, nullptr, - Genode::Affinity::Location()); + return Libc::pthread_create_from_session(thread, start_routine, arg, + stack_size, rtthread->szName, nullptr, + Genode::Affinity::Location()); } else { using namespace Genode; @@ -137,9 +137,9 @@ static int create_thread(pthread_t *thread, const pthread_attr_t *attr, return cpu->retry_with_upgrade(Ram_quota{8*1024}, Cap_quota{2}, [&] () { - return Libc::pthread_create(thread, start_routine, arg, - stack_size, rtthread->szName, cpu, - Genode::Affinity::Location()); + return Libc::pthread_create_from_session(thread, start_routine, arg, + stack_size, rtthread->szName, cpu, + Genode::Affinity::Location()); }); } diff --git a/repos/ports/src/virtualbox6/devxhci.cc b/repos/ports/src/virtualbox6/devxhci.cc index 3cfadf9b08..4b98432808 100644 --- a/repos/ports/src/virtualbox6/devxhci.cc +++ b/repos/ports/src/virtualbox6/devxhci.cc @@ -438,7 +438,7 @@ struct Usb_ep : Genode::Entrypoint void _handle_pthread_registration() { Genode::Thread *myself = Genode::Thread::myself(); - if (!myself || Libc::pthread_create(&_pthread, *myself, &myself)) { + if (!myself || Libc::pthread_create_from_thread(&_pthread, *myself, &myself)) { Genode::error("USB passthough will not work - thread for " "pthread registration invalid"); } diff --git a/repos/ports/src/virtualbox6/network.cc b/repos/ports/src/virtualbox6/network.cc index cb49234e91..6a221d3ef2 100644 --- a/repos/ports/src/virtualbox6/network.cc +++ b/repos/ports/src/virtualbox6/network.cc @@ -201,7 +201,7 @@ class Nic_client void _handle_pthread_registration() { Genode::Thread *myself = Genode::Thread::myself(); - if (!myself || Libc::pthread_create(&_pthread, *myself, &myself)) { + if (!myself || Libc::pthread_create_from_thread(&_pthread, *myself, &myself)) { Genode::error("network will not work - thread for pthread " "registration invalid"); return;