From 4da52517c16b492dfaea63a9f0ac0b022e99e255 Mon Sep 17 00:00:00 2001 From: Norman Feske Date: Thu, 22 Dec 2016 15:01:19 +0100 Subject: [PATCH] Simpify startup of dynamically linked binaries This patch removes the component_entry_point library, which used to proved a hook for the libc to intercept the call of the 'Component::construct' function. The mechansim has several shortcomings (see the discussion in the associated issue) and was complex. So we eventually discarded the approach in favor of the explicit handling of the startup. A regular Genode component provides a 'Component::construct' function, which is determined by the dynamic linker via a symbol lookup. For the time being, the dynamic linker falls back to looking up a 'main' function if no 'Component::construct' function could be found. The libc provides an implementation of 'Component::construct', which sets up the libc's task handling and finally call the function 'Libc::Component::construct' from the context of the appllication task. This function is expected to be provided by the libc-using application. Consequently, Genode components that use the libc have to implement the 'Libc::Component::construct' function. The new 'posix' library provides an implementation of 'Libc::Component::construct' that calls a main function. Hence, POSIX programs that merely use the POSIX API merely have to add 'posix' to the 'LIBS' declaration in their 'target.mk' file. Their execution starts at 'main'. Issue #2199 --- repos/base-hw/lib/mk/core-hw.inc | 1 - .../base-linux/src/lib/lx_hybrid/lx_hybrid.cc | 17 ---- repos/base/lib/import/import-base.mk | 6 -- repos/base/lib/import/import-ld.mk | 1 - repos/base/lib/mk/component_entry_point.mk | 7 -- repos/base/lib/mk/ld-platform.inc | 2 - repos/base/lib/mk/platform.mk | 1 - repos/base/lib/mk/startup.inc | 2 +- repos/base/lib/symbols/ld | 1 - repos/base/mk/dep_lib.mk | 2 - repos/base/mk/lib.mk | 2 +- repos/base/mk/prg.mk | 15 +--- repos/base/src/ld/genode_dyn.dl | 3 + repos/base/src/ld/genode_dyn.ld | 25 ++++-- repos/base/src/lib/base/component.cc | 4 + repos/base/src/lib/base/entrypoint.cc | 4 +- repos/base/src/lib/ldso/main.cc | 69 ++++++++++++--- repos/base/src/lib/startup/_main.cc | 21 +++++ .../src/lib/startup/component_construct.cc | 88 ------------------- .../src/lib/startup/component_entry_point.cc | 32 ------- repos/dde_linux/src/drivers/wifi/main.cc | 4 +- .../src/test/lxip/http_srv/target.mk | 2 +- .../src/test/lxip/udp_client/target.mk | 2 +- .../src/test/lxip/udp_echo/target.mk | 2 +- repos/gems/src/app/backdrop/target.mk | 2 +- repos/gems/src/app/menu_view/target.mk | 2 +- repos/gems/src/app/mixer_gui_qt/target.mk | 2 +- repos/gems/src/app/themed_decorator/main.cc | 4 +- repos/gems/src/server/file_terminal/target.mk | 2 +- repos/gems/src/server/http_blk/main.cc | 3 +- repos/gems/src/server/tcp_terminal/target.mk | 2 +- repos/gems/src/server/terminal_mux/main.cc | 4 +- .../gems/src/test/decorator_stress/target.mk | 2 +- repos/libports/include/libc/component.h | 48 ++++++++++ repos/libports/lib/import/import-posix.mk | 3 + repos/libports/lib/import/import-qt5.inc | 1 - repos/libports/lib/mk/posix.mk | 5 ++ repos/libports/run/libc_block.run | 2 +- repos/libports/run/libc_ffat_fs.run | 2 +- repos/libports/run/libc_filesystem_test.inc | 2 +- repos/libports/run/libc_pipe.run | 2 +- repos/libports/run/libc_vfs.run | 2 +- repos/libports/run/libc_vfs_fs.run | 2 +- repos/libports/run/libc_vfs_ram.run | 2 +- repos/libports/run/lwip.run | 2 +- repos/libports/run/nic_router.run | 2 +- repos/libports/run/pthread.run | 2 +- repos/libports/run/smartcard.run | 2 +- repos/libports/src/app/acpica/os.cc | 4 +- repos/libports/src/app/avplay/target.mk | 2 +- repos/libports/src/app/eglgears/target.mk | 2 +- repos/libports/src/app/mupdf/target.mk | 2 +- .../app/qt5/examples/calculatorform/target.mk | 2 + .../app/qt5/examples/openglwindow/target.mk | 2 + .../src/app/qt5/examples/previewer/target.mk | 2 + .../src/app/qt5/examples/samegame/target.mk | 2 + .../src/app/qt5/examples/tetrix/target.mk | 2 + .../src/app/qt5/examples/textedit/target.mk | 1 + repos/libports/src/app/qt5/qt_avplay/main.cpp | 5 +- .../libports/src/app/qt5/qt_avplay/target.mk | 1 + .../src/app/qt5/qt_launchpad/main.cpp | 5 +- .../src/app/qt5/qt_quicktest/target.mk | 1 + repos/libports/src/lib/libc/task.cc | 47 +++++----- repos/libports/src/lib/posix/construct.cc | 32 +++++++ repos/libports/src/lib/qt5/qt_main.cc | 15 +--- .../src/server/fuse_fs/exfat/target.mk | 2 +- .../src/server/fuse_fs/ext2/target.mk | 2 +- .../src/server/fuse_fs/fuse_fs_main.cc | 40 +++++---- .../src/server/fuse_fs/ntfs-3g/target.mk | 2 +- repos/libports/src/test/expat/target.mk | 2 +- repos/libports/src/test/ldso/main.cc | 4 +- repos/libports/src/test/libc/target.mk | 2 +- repos/libports/src/test/libc_block/target.mk | 2 +- repos/libports/src/test/libc_ffat/target.mk | 2 +- repos/libports/src/test/libc_pipe/target.mk | 2 +- repos/libports/src/test/libc_resolv/target.mk | 2 +- repos/libports/src/test/libc_vfs/target.mk | 2 +- repos/libports/src/test/libports/main.cc | 4 +- .../src/test/lwip/http_clnt/target.mk | 2 +- .../libports/src/test/lwip/http_srv/target.mk | 2 +- .../src/test/lwip/http_srv_static/target.mk | 2 +- .../libports/src/test/lwip/loopback/target.mk | 2 +- .../lwip/pingpong/client/libc_lwip/target.mk | 2 +- .../test/lwip/pingpong/client/lwip/target.mk | 2 +- .../lwip/pingpong/server/libc_lwip/target.mk | 2 +- .../test/lwip/pingpong/server/lwip/target.mk | 2 +- repos/libports/src/test/moon/target.mk | 2 +- repos/libports/src/test/pthread/target.mk | 2 +- repos/libports/src/test/python/target.mk | 2 +- .../src/test/qt5/qpluginwidget/target.mk | 2 + repos/libports/src/test/rust/target.mk | 3 +- repos/libports/src/test/sdl/target.mk | 2 +- repos/libports/src/test/smartcard/target.mk | 2 +- repos/libports/src/test/stdcxx/target.mk | 2 +- repos/os/src/test/blk/bench/main.cc | 13 +-- repos/os/src/test/blk/bench/target.mk | 2 +- repos/ports/mk/gnu_build.mk | 13 +-- repos/ports/src/app/arora/target.mk | 2 + repos/ports/src/app/dosbox/target.mk | 2 +- repos/ports/src/app/gdb_monitor/main.cc | 4 +- repos/ports/src/app/lighttpd/target.inc | 2 +- repos/ports/src/app/netperf/target.inc | 2 +- repos/ports/src/app/openvpn/main.cc | 25 +++--- repos/ports/src/app/openvpn/target.mk | 2 +- repos/ports/src/noux-pkg/gcc/target.inc | 2 +- repos/ports/src/noux/main.cc | 7 ++ repos/ports/src/test/gdb_monitor/target.mk | 2 +- repos/ports/src/test/libc_noux/target.mk | 2 +- repos/ports/src/test/noux_fork/target.mk | 2 +- repos/ports/src/test/noux_signals/target.mk | 2 +- repos/ports/src/virtualbox/frontend/main.cc | 4 +- repos/ports/src/virtualbox5/frontend/main.cc | 4 +- 112 files changed, 366 insertions(+), 369 deletions(-) delete mode 100644 repos/base/lib/import/import-base.mk delete mode 100644 repos/base/lib/import/import-ld.mk delete mode 100644 repos/base/lib/mk/component_entry_point.mk delete mode 100644 repos/base/src/lib/startup/component_construct.cc delete mode 100644 repos/base/src/lib/startup/component_entry_point.cc create mode 100644 repos/libports/include/libc/component.h create mode 100644 repos/libports/lib/import/import-posix.mk create mode 100644 repos/libports/lib/mk/posix.mk create mode 100644 repos/libports/src/lib/posix/construct.cc diff --git a/repos/base-hw/lib/mk/core-hw.inc b/repos/base-hw/lib/mk/core-hw.inc index 35f56c747..e8c2ffa90 100644 --- a/repos/base-hw/lib/mk/core-hw.inc +++ b/repos/base-hw/lib/mk/core-hw.inc @@ -43,7 +43,6 @@ SRC_CC += env.cc SRC_CC += region_map_support.cc SRC_CC += pager.cc SRC_CC += _main.cc -SRC_CC += component_construct.cc SRC_CC += kernel/cpu_scheduler.cc SRC_CC += kernel/double_list.cc SRC_CC += kernel/init.cc diff --git a/repos/base-linux/src/lib/lx_hybrid/lx_hybrid.cc b/repos/base-linux/src/lib/lx_hybrid/lx_hybrid.cc index cc4211400..5eb93a5ae 100644 --- a/repos/base-linux/src/lib/lx_hybrid/lx_hybrid.cc +++ b/repos/base-linux/src/lib/lx_hybrid/lx_hybrid.cc @@ -78,16 +78,6 @@ namespace Genode { extern void bootstrap_component(); extern void call_global_static_constructors(); - /* - * Hook for intercepting the call of the 'Component::construct' method. By - * hooking this function pointer in a library constructor, the libc is able - * to create a task context for the component code. This context is - * scheduled by the libc in a cooperative fashion, i.e. when the - * component's entrypoint is activated. - */ - - extern void (*call_component_construct)(Genode::Env &) __attribute__((weak)); - /* * This function is normally provided by the cxx library, which is not * used for lx_hybrid programs. For lx_hybrid programs, the exception @@ -96,13 +86,6 @@ namespace Genode { void init_exception_handling(Env &) { } } -static void lx_hybrid_component_construct(Genode::Env &env) -{ - Component::construct(env); -} - -void (*Genode::call_component_construct)(Genode::Env &) = &lx_hybrid_component_construct; - /* * Static constructors are handled by the Linux startup code - so implement * this as empty function. diff --git a/repos/base/lib/import/import-base.mk b/repos/base/lib/import/import-base.mk deleted file mode 100644 index 4f3570c78..000000000 --- a/repos/base/lib/import/import-base.mk +++ /dev/null @@ -1,6 +0,0 @@ -# -# All dynamic executables must be linked to the component entry-point library -# (a trampoline for component startup from ldso), so, enforce the library -# dependency here. -# -LIBS += component_entry_point diff --git a/repos/base/lib/import/import-ld.mk b/repos/base/lib/import/import-ld.mk deleted file mode 100644 index 6eb5ea392..000000000 --- a/repos/base/lib/import/import-ld.mk +++ /dev/null @@ -1 +0,0 @@ -include $(BASE_DIR)/lib/import/import-base.mk diff --git a/repos/base/lib/mk/component_entry_point.mk b/repos/base/lib/mk/component_entry_point.mk deleted file mode 100644 index 75726e055..000000000 --- a/repos/base/lib/mk/component_entry_point.mk +++ /dev/null @@ -1,7 +0,0 @@ -# -# Component entry point (a trampoline for component startup from ldso) -# - -SRC_CC = component_entry_point.cc component_construct.cc - -vpath %.cc $(REP_DIR)/src/lib/startup diff --git a/repos/base/lib/mk/ld-platform.inc b/repos/base/lib/mk/ld-platform.inc index f1ccab2f6..d46d7fdd3 100644 --- a/repos/base/lib/mk/ld-platform.inc +++ b/repos/base/lib/mk/ld-platform.inc @@ -38,8 +38,6 @@ ENTRY_POINT = _start LD_OPT += -T$(DIR)/linker.ld endif -include $(BASE_DIR)/lib/import/import-ld.mk - vpath %.cc $(DIR) # vi:ft=make diff --git a/repos/base/lib/mk/platform.mk b/repos/base/lib/mk/platform.mk index 62e6c21a3..e69de29bb 100644 --- a/repos/base/lib/mk/platform.mk +++ b/repos/base/lib/mk/platform.mk @@ -1 +0,0 @@ -LIBS = component_entry_point diff --git a/repos/base/lib/mk/startup.inc b/repos/base/lib/mk/startup.inc index 3e6da1757..42fe29824 100644 --- a/repos/base/lib/mk/startup.inc +++ b/repos/base/lib/mk/startup.inc @@ -1,5 +1,5 @@ SRC_S += crt0.s -SRC_CC += _main.cc init_main_thread.cc component_construct.cc +SRC_CC += _main.cc init_main_thread.cc REP_INC_DIR += src/include LIBS += syscall diff --git a/repos/base/lib/symbols/ld b/repos/base/lib/symbols/ld index 9ec803b99..ed4df64ea 100644 --- a/repos/base/lib/symbols/ld +++ b/repos/base/lib/symbols/ld @@ -184,7 +184,6 @@ _ZN6Genode18Signal_transmitterC1ENS_10CapabilityINS_14Signal_contextEEE T _ZN6Genode18Signal_transmitterC2ENS_10CapabilityINS_14Signal_contextEEE T _ZN6Genode18server_socket_pairEv T _ZN6Genode20env_session_id_spaceEv T -_ZN6Genode21component_entry_pointERNS_3EnvE T _ZN6Genode25env_stack_area_region_mapE B _ZN6Genode26env_stack_area_ram_sessionE B _ZN6Genode29upgrade_pd_quota_non_blockingEm T diff --git a/repos/base/mk/dep_lib.mk b/repos/base/mk/dep_lib.mk index c742c3c9c..c5abc31e8 100644 --- a/repos/base/mk/dep_lib.mk +++ b/repos/base/mk/dep_lib.mk @@ -106,11 +106,9 @@ endif # ifeq ($(LIBS),) ifneq ($(LIB),platform) -ifneq ($(LIB),component_entry_point) LIBS += platform endif endif -endif # # Check if the requirements of the target are satisfied diff --git a/repos/base/mk/lib.mk b/repos/base/mk/lib.mk index bf5bb5d97..2e20c7b02 100644 --- a/repos/base/mk/lib.mk +++ b/repos/base/mk/lib.mk @@ -159,7 +159,7 @@ $(LIB_RLIB): $(OBJECTS) # ifdef SHARED_LIB ifneq ($(LIB_IS_DYNAMIC_LINKER),yes) -override DEPS := $(filter-out $(BASE_LIBS:=.lib) component_entry_point.lib,$(DEPS)) +override DEPS := $(filter-out $(BASE_LIBS:=.lib),$(DEPS)) endif endif diff --git a/repos/base/mk/prg.mk b/repos/base/mk/prg.mk index b7c0c8d05..f46e22dbe 100644 --- a/repos/base/mk/prg.mk +++ b/repos/base/mk/prg.mk @@ -110,14 +110,8 @@ LD_CMD ?= $(CXX) LD_CMD += $(CXX_LINK_OPT) ifeq ($(SHARED_LIBS),) +FILTER_DEPS := $(DEPS:.lib=) LD_SCRIPTS := $(LD_SCRIPT_STATIC) - -# -# Filter out the component-entry-point library since its not used for static -# binaries -# -FILTER_DEPS := $(filter-out component_entry_point,$(DEPS:.lib=)) - else # @@ -135,13 +129,6 @@ LD_CMD += -Wl,--dynamic-linker=$(DYNAMIC_LINKER).lib.so \ FILTER_DEPS := $(filter-out $(BASE_LIBS),$(DEPS:.lib=)) SHARED_LIBS += $(LIB_CACHE_DIR)/$(DYNAMIC_LINKER)/$(DYNAMIC_LINKER).lib.so - -# -# Link all dynamic executables to the component entry-point library (a -# trampoline for component startup from ldso) -# -FILTER_DEPS += component_entry_point - # # Build program position independent as well # diff --git a/repos/base/src/ld/genode_dyn.dl b/repos/base/src/ld/genode_dyn.dl index 21eab9d30..c063c5617 100644 --- a/repos/base/src/ld/genode_dyn.dl +++ b/repos/base/src/ld/genode_dyn.dl @@ -13,4 +13,7 @@ _ctors_end; _dtors_start; _dtors_end; + _ZN9Component9constructERN6Genode3EnvE; + _ZN9Component10stack_sizeEv; + main; }; diff --git a/repos/base/src/ld/genode_dyn.ld b/repos/base/src/ld/genode_dyn.ld index 8d0e905c1..8c981cf48 100644 --- a/repos/base/src/ld/genode_dyn.ld +++ b/repos/base/src/ld/genode_dyn.ld @@ -11,14 +11,10 @@ * under the terms of the GNU General Public License version 2. */ - /* - * Components don't need to startup with CRT0 as LDSO has done this - * initialization during its own CRT0 already. The component always starts at - * Genode::component_entry_point() as a trampoline to - * call_component_construct(). + * The entry point of dynamically linked components is unused. The dynamic + * linker determines the 'Component::construct' function via a symbol lookup. */ -ENTRY(_ZN6Genode21component_entry_pointERNS_3EnvE) PHDRS { @@ -37,10 +33,21 @@ SECTIONS { _prog_img_beg = .; - /* put entry code at the start of the text segment / raw binary */ - *(.text._ZN6Genode21component_entry_pointERNS_3EnvE) + /* + * The ELF entry point is unused for dynamically linked components. The + * dynamic linker determined the entry point by looking up the symbol of + * the 'Component::construct' function or - if it does not exist - the + * 'main' function (for legacy components). + * + * \deprecated The support for legacy main functions will be removed. + * + * The 'KEEP' directive prevents text that is reachable from one of the + * possible entry points from being garbage collected. + */ + KEEP(*(.text._ZN9Component9constructERN6Genode3EnvE .text.main)) - *(.text .stub .text.* .gnu.linkonce.t.*) + *(.text + .stub .text.* .gnu.linkonce.t.*) /* .gnu.warning sections are handled specially by elf32.em. */ *(.gnu.warning) } : ro =0x0 diff --git a/repos/base/src/lib/base/component.cc b/repos/base/src/lib/base/component.cc index d01720be2..6441a20d1 100644 --- a/repos/base/src/lib/base/component.cc +++ b/repos/base/src/lib/base/component.cc @@ -152,6 +152,10 @@ namespace Genode { } +Genode::size_t Component::stack_size() __attribute__((weak)); +Genode::size_t Component::stack_size() { return 64*1024; } + + /* * We need to execute the constructor of the main entrypoint from a * class called 'Startup' as 'Startup' is a friend of 'Entrypoint'. diff --git a/repos/base/src/lib/base/entrypoint.cc b/repos/base/src/lib/base/entrypoint.cc index b1ff0a4a2..790e8cb53 100644 --- a/repos/base/src/lib/base/entrypoint.cc +++ b/repos/base/src/lib/base/entrypoint.cc @@ -31,8 +31,6 @@ namespace Genode { extern bool inhibit_tracing; void call_global_static_constructors(); void destroy_signal_thread(); - - extern void (*call_component_construct)(Genode::Env &); } @@ -152,7 +150,7 @@ namespace { Genode::call_global_static_constructors(); - Genode::call_component_construct(env); + Component::construct(env); } }; } diff --git a/repos/base/src/lib/ldso/main.cc b/repos/base/src/lib/ldso/main.cc index d6fb5fd32..0efbb24d9 100644 --- a/repos/base/src/lib/ldso/main.cc +++ b/repos/base/src/lib/ldso/main.cc @@ -317,6 +317,20 @@ Linker::Ld &Linker::Ld::linker() } +/* + * Defined in the startup library, passed to legacy main functions. + */ +extern char **genode_argv; +extern int genode_argc; +extern char **genode_envp; + +void genode_exit(int status); + +static int exit_status; + +static void exit_on_suspended() { genode_exit(exit_status); } + + /** * The dynamic binary to load */ @@ -348,16 +362,26 @@ struct Linker::Binary : Root_object, Elf_object Elf::Addr lookup_symbol(char const *name) { - Elf::Sym const *symbol = 0; - - if ((symbol = Elf_object::lookup_symbol(name, Hash_table::hash(name)))) - return reloc_base() + symbol->st_value; - - return 0; + try { + Elf::Addr base = 0; + Elf::Sym const *sym = Linker::lookup_symbol(name, dynamic().dep(), &base); + return base + sym->st_value; + } + catch (Linker::Not_found) { return 0; } } void call_entry_point(Env &env) { + /* apply the component-provided stack size */ + if (Elf::Addr addr = lookup_symbol("_ZN9Component10stack_sizeEv")) { + + /* call 'Component::stack_size()' */ + size_t const stack_size = ((size_t(*)())addr)(); + + /* expand stack according to the component's needs */ + Thread::myself()->stack_size(stack_size); + } + /* call static construtors and register destructors */ Func * const ctors_start = (Func *)lookup_symbol("_ctors_start"); Func * const ctors_end = (Func *)lookup_symbol("_ctors_end"); @@ -367,13 +391,33 @@ struct Linker::Binary : Root_object, Elf_object Func * const dtors_end = (Func *)lookup_symbol("_dtors_end"); for (Func * dtor = dtors_start; dtor != dtors_end; genode_atexit(*dtor++)); - /* call component entry point */ - /* XXX the function type for call_component_construct() is a candidate - * for a base-internal header */ - typedef void (*Entry)(Env &); - Entry const entry = reinterpret_cast(_file->entry); + /* call 'Component::construct' function if present */ + if (Elf::Addr addr = lookup_symbol("_ZN9Component9constructERN6Genode3EnvE")) { + ((void(*)(Env &))addr)(env); + return; + } - entry(env); + /* + * The 'Component::construct' function is missing. This may be the + * case for legacy components that still implement a 'main' function. + * + * \deprecated the handling of legacy 'main' functions will be removed + */ + if (Elf::Addr addr = lookup_symbol("main")) { + warning("using legacy main function, please convert to 'Component::construct'"); + + exit_status = ((int (*)(int, char **, char **))addr)(genode_argc, + genode_argv, + genode_envp); + + /* trigger suspend in the entry point */ + env.ep().schedule_suspend(exit_on_suspended, nullptr); + + /* return to entrypoint and exit via exit_on_suspended() */ + return; + } + + error("dynamic linker: component-entrypoint lookup failed"); } void relocate(Bind bind) override @@ -486,7 +530,6 @@ Elf::Sym const *Linker::lookup_symbol(char const *name, Dependency const &dep, if (binary_ptr && &dep != binary_ptr->first_dep()) { return lookup_symbol(name, *binary_ptr->first_dep(), base, undef, other); } else { - error("LD: could not lookup symbol \"", name, "\""); throw Not_found(); } } diff --git a/repos/base/src/lib/startup/_main.cc b/repos/base/src/lib/startup/_main.cc index e56256c94..c7d7a9334 100644 --- a/repos/base/src/lib/startup/_main.cc +++ b/repos/base/src/lib/startup/_main.cc @@ -250,3 +250,24 @@ extern "C" int _main() /* never reached */ return 0; } + + +static int exit_status; +static void exit_on_suspended() { genode_exit(exit_status); } + + +extern int main(int argc, char **argv, char **envp); + + +void Component::construct(Genode::Env &env) __attribute__((weak)); +void Component::construct(Genode::Env &env) +{ + /* call real main function */ + exit_status = main(genode_argc, genode_argv, genode_envp); + + /* trigger suspend in the entry point */ + env.ep().schedule_suspend(exit_on_suspended, nullptr); + + /* return to entrypoint and exit via exit_on_suspended() */ +} + diff --git a/repos/base/src/lib/startup/component_construct.cc b/repos/base/src/lib/startup/component_construct.cc deleted file mode 100644 index 6613c311b..000000000 --- a/repos/base/src/lib/startup/component_construct.cc +++ /dev/null @@ -1,88 +0,0 @@ -/* - * \brief Startup code for component construction - * \author Christian Helmuth - * \date 2016-01-21 - * - * The component construction code is used by the startup library, which is - * linked to static binaries and ld.lib.so. The code is also used by the - * component_entry_point static library, which is linked to all dynamic - * executables to make the fallback implementation and the - * call_component_construct-hook function pointer available to these binaries. - * - * Note, for dynamic binaries we can't refer to the default implementation in - * ld.lib.so as it is a component itself implementing the Component functions. - */ - -/* - * Copyright (C) 2016 Genode Labs GmbH - * - * This file is part of the Genode OS framework, which is distributed - * under the terms of the GNU General Public License version 2. - */ - -/* Genode includes */ -#include - - -namespace Genode { - - /* - * Hook for intercepting the call of the 'Component::construct' method. By - * hooking this function pointer in a library constructor, the libc is able - * to create a task context for the component code. This context is - * scheduled by the libc in a cooperative fashion, i.e. when the - * component's entrypoint is activated. - */ - - extern void (*call_component_construct)(Genode::Env &) __attribute__((weak)); -} - -static void default_component_construct(Genode::Env &env) -{ - Component::construct(env); -} - -void (*Genode::call_component_construct)(Genode::Env &) = &default_component_construct; - - -/**************************************************** - ** Fallback implementation of Component interface ** - ****************************************************/ - -extern void genode_exit(int status); - -static int exit_status; - -static void exit_on_suspended() { genode_exit(exit_status); } - -/* - * Regular components provide the 'Component' interface as defined in - * base/component.h. This fallback accommodates legacy components that lack the - * implementation of this interface but come with a main function. - */ - -/* - * XXX these symbols reside in the startup library - candidate for - * base-internal header? - */ -extern char **genode_argv; -extern int genode_argc; -extern char **genode_envp; - -extern int main(int argc, char **argv, char **envp); - -void Component::construct(Genode::Env &env) __attribute__((weak)); -void Component::construct(Genode::Env &env) -{ - /* call real main function */ - exit_status = main(genode_argc, genode_argv, genode_envp); - - /* trigger suspend in the entry point */ - env.ep().schedule_suspend(exit_on_suspended, nullptr); - - /* return to entrypoint and exit via exit_on_suspended() */ -} - - -Genode::size_t Component::stack_size() __attribute__((weak)); -Genode::size_t Component::stack_size() { return 64*1024; } diff --git a/repos/base/src/lib/startup/component_entry_point.cc b/repos/base/src/lib/startup/component_entry_point.cc deleted file mode 100644 index 2afd66751..000000000 --- a/repos/base/src/lib/startup/component_entry_point.cc +++ /dev/null @@ -1,32 +0,0 @@ -/* - * \brief Component entry point for dynamic executables - * \author Christian Helmuth - * \date 2016-01-21 - * - * The ELF entry point of dynamic binaries is set to component_entry_point(), - * which calls the call_component_construct-hook function pointer. - */ - -/* - * Copyright (C) 2016 Genode Labs GmbH - * - * This file is part of the Genode OS framework, which is distributed - * under the terms of the GNU General Public License version 2. - */ - -/* Genode includes */ -#include - - -/* FIXME move to base-internal header */ -namespace Genode { - extern void (*call_component_construct)(Env &); -} - -namespace Genode { - - void component_entry_point(Genode::Env &env) - { - call_component_construct(env); - } -} diff --git a/repos/dde_linux/src/drivers/wifi/main.cc b/repos/dde_linux/src/drivers/wifi/main.cc index 589bdf5ca..ff9351b11 100644 --- a/repos/dde_linux/src/drivers/wifi/main.cc +++ b/repos/dde_linux/src/drivers/wifi/main.cc @@ -12,7 +12,7 @@ */ /* Genode includes */ -#include +#include #include #include #include @@ -254,4 +254,4 @@ struct Main }; -void Component::construct(Genode::Env &env) { static Main server(env); } +void Libc::Component::construct(Genode::Env &env) { static Main server(env); } diff --git a/repos/dde_linux/src/test/lxip/http_srv/target.mk b/repos/dde_linux/src/test/lxip/http_srv/target.mk index 37896276b..abb7d1e0a 100644 --- a/repos/dde_linux/src/test/lxip/http_srv/target.mk +++ b/repos/dde_linux/src/test/lxip/http_srv/target.mk @@ -1,3 +1,3 @@ TARGET = test-lxip_http_srv -LIBS = libc libc_lxip +LIBS = posix libc_lxip SRC_CC = main.cc diff --git a/repos/dde_linux/src/test/lxip/udp_client/target.mk b/repos/dde_linux/src/test/lxip/udp_client/target.mk index 42b319351..a74884f2d 100644 --- a/repos/dde_linux/src/test/lxip/udp_client/target.mk +++ b/repos/dde_linux/src/test/lxip/udp_client/target.mk @@ -1,3 +1,3 @@ TARGET = test-lxip_udp_client -LIBS = libc libc_lxip config +LIBS = posix libc_lxip config SRC_CC = main.cc diff --git a/repos/dde_linux/src/test/lxip/udp_echo/target.mk b/repos/dde_linux/src/test/lxip/udp_echo/target.mk index f6803b13c..6154c5c46 100644 --- a/repos/dde_linux/src/test/lxip/udp_echo/target.mk +++ b/repos/dde_linux/src/test/lxip/udp_echo/target.mk @@ -1,3 +1,3 @@ TARGET = test-lxip_udp_echo -LIBS = libc libc_lxip config +LIBS = posix libc_lxip config SRC_CC = main.cc diff --git a/repos/gems/src/app/backdrop/target.mk b/repos/gems/src/app/backdrop/target.mk index 3e087f3f7..dbeb9f828 100644 --- a/repos/gems/src/app/backdrop/target.mk +++ b/repos/gems/src/app/backdrop/target.mk @@ -1,3 +1,3 @@ TARGET = backdrop SRC_CC = main.cc -LIBS = base config libc libpng zlib blit file +LIBS = base config posix libpng zlib blit file diff --git a/repos/gems/src/app/menu_view/target.mk b/repos/gems/src/app/menu_view/target.mk index bd686367e..eb0658b2e 100644 --- a/repos/gems/src/app/menu_view/target.mk +++ b/repos/gems/src/app/menu_view/target.mk @@ -1,6 +1,6 @@ TARGET = menu_view SRC_CC = main.cc -LIBS = base config libc libpng zlib blit file +LIBS = base config posix libpng zlib blit file INC_DIR += $(PRG_DIR) .PHONY: menu_view_styles.tar diff --git a/repos/gems/src/app/mixer_gui_qt/target.mk b/repos/gems/src/app/mixer_gui_qt/target.mk index 4d723d2be..51139a80f 100644 --- a/repos/gems/src/app/mixer_gui_qt/target.mk +++ b/repos/gems/src/app/mixer_gui_qt/target.mk @@ -8,4 +8,4 @@ include $(QT5_REP_DIR)/src/app/qt5/tmpl/target_final.inc main_window.o: main_window.moc -LIBS += config qoost +LIBS += config qoost posix diff --git a/repos/gems/src/app/themed_decorator/main.cc b/repos/gems/src/app/themed_decorator/main.cc index e98784f21..1687d3d72 100644 --- a/repos/gems/src/app/themed_decorator/main.cc +++ b/repos/gems/src/app/themed_decorator/main.cc @@ -13,7 +13,7 @@ /* Genode includes */ #include -#include +#include #include #include #include @@ -317,4 +317,4 @@ void Decorator::Main::_handle_pointer_update() } -void Component::construct(Genode::Env &env) { static Decorator::Main main(env); } +void Libc::Component::construct(Genode::Env &env) { static Decorator::Main main(env); } diff --git a/repos/gems/src/server/file_terminal/target.mk b/repos/gems/src/server/file_terminal/target.mk index 89810dd18..0a4eb6bf1 100644 --- a/repos/gems/src/server/file_terminal/target.mk +++ b/repos/gems/src/server/file_terminal/target.mk @@ -1,3 +1,3 @@ TARGET = file_terminal SRC_CC = main.cc -LIBS = libc +LIBS = posix diff --git a/repos/gems/src/server/http_blk/main.cc b/repos/gems/src/server/http_blk/main.cc index 5fa9eb2ae..c31b40e5d 100644 --- a/repos/gems/src/server/http_blk/main.cc +++ b/repos/gems/src/server/http_blk/main.cc @@ -16,6 +16,7 @@ #include #include #include +#include /* local includes */ #include "http.h" @@ -106,4 +107,4 @@ struct Main }; -void Component::construct(Genode::Env &env) { static Main m(env); } +void Libc::Component::construct(Genode::Env &env) { static Main m(env); } diff --git a/repos/gems/src/server/tcp_terminal/target.mk b/repos/gems/src/server/tcp_terminal/target.mk index cd89857c3..a107693c8 100644 --- a/repos/gems/src/server/tcp_terminal/target.mk +++ b/repos/gems/src/server/tcp_terminal/target.mk @@ -1,3 +1,3 @@ TARGET = tcp_terminal SRC_CC = main.cc -LIBS = libc libc_lwip_nic_dhcp libc_pipe +LIBS = posix libc_lwip_nic_dhcp libc_pipe diff --git a/repos/gems/src/server/terminal_mux/main.cc b/repos/gems/src/server/terminal_mux/main.cc index 14eae6925..c71f2bb6f 100644 --- a/repos/gems/src/server/terminal_mux/main.cc +++ b/repos/gems/src/server/terminal_mux/main.cc @@ -13,7 +13,7 @@ /* Genode includes */ #include -#include +#include #include #include #include @@ -721,4 +721,4 @@ struct Main }; -void Component::construct(Genode::Env &env) { static Main inst(env); } +void Libc::Component::construct(Genode::Env &env) { static Main inst(env); } diff --git a/repos/gems/src/test/decorator_stress/target.mk b/repos/gems/src/test/decorator_stress/target.mk index be38e7f4a..b378eda34 100644 --- a/repos/gems/src/test/decorator_stress/target.mk +++ b/repos/gems/src/test/decorator_stress/target.mk @@ -1,6 +1,6 @@ TARGET = test-decorator_stress SRC_CC = main.cc -LIBS = libc libm +LIBS = posix INC_DIR += $(PRG_DIR) diff --git a/repos/libports/include/libc/component.h b/repos/libports/include/libc/component.h new file mode 100644 index 000000000..c7efb79ca --- /dev/null +++ b/repos/libports/include/libc/component.h @@ -0,0 +1,48 @@ +/* + * \brief Hook functions for bootstrapping a libc-using Genode component + * \author Norman Feske + * \date 2016-12-23 + * + * This interface is implemented by components that use both Genode's API and + * the libc. For such components, the libc provides the 'Component::construct' + * function that takes the precautions needed for letting the application use + * blocking I/O via POSIX functions like 'read' or 'select'. The libc's + * 'Component::construct' function finally passes control to the application by + * calling the application-provided 'Libc::Component::construct' function. + */ + +/* + * Copyright (C) 2016 Genode Labs GmbH + * + * This file is part of the Genode OS framework, which is distributed + * under the terms of the GNU General Public License version 2. + */ + +#ifndef _INCLUDE__LIBC__COMPONENT_H_ +#define _INCLUDE__LIBC__COMPONENT_H_ + +#include +#include + +namespace Genode { struct Env; } + + +/** + * Interface to be provided by the component implementation + */ +namespace Libc { namespace Component { + + /** + * Return stack size of the component's initial entrypoint + */ + Genode::size_t stack_size(); + + /** + * Construct component + * + * \param env interface to the component's execution environment + */ + void construct(Genode::Env &env); +} } + +#endif /* _INCLUDE__LIBC__COMPONENT_H_ */ diff --git a/repos/libports/lib/import/import-posix.mk b/repos/libports/lib/import/import-posix.mk new file mode 100644 index 000000000..de09f882d --- /dev/null +++ b/repos/libports/lib/import/import-posix.mk @@ -0,0 +1,3 @@ +LIBS += libc libm + +include $(call select_from_repositories,lib/import/import-libc.mk) diff --git a/repos/libports/lib/import/import-qt5.inc b/repos/libports/lib/import/import-qt5.inc index 25813fb9d..f16db2aac 100644 --- a/repos/libports/lib/import/import-qt5.inc +++ b/repos/libports/lib/import/import-qt5.inc @@ -105,7 +105,6 @@ include $(call select_from_repositories,lib/import/import-gallium.mk) # custom main() thread stack size support via main() wrapper ifeq ($(findstring -DQT_MAIN_STACK_SIZE, $(CC_CXX_OPT)), -DQT_MAIN_STACK_SIZE) -CC_CXX_OPT += -Dmain=qt_main SRC_CC += qt_main.cc vpath qt_main.cc $(QT5_REP_DIR)/src/lib/qt5 endif diff --git a/repos/libports/lib/mk/posix.mk b/repos/libports/lib/mk/posix.mk new file mode 100644 index 000000000..b43578fa3 --- /dev/null +++ b/repos/libports/lib/mk/posix.mk @@ -0,0 +1,5 @@ +SRC_CC = construct.cc + +LIBS += libc + +vpath construct.cc $(REP_DIR)/src/lib/posix diff --git a/repos/libports/run/libc_block.run b/repos/libports/run/libc_block.run index 29329c8d4..9ef38d6e5 100644 --- a/repos/libports/run/libc_block.run +++ b/repos/libports/run/libc_block.run @@ -100,7 +100,7 @@ install_config $config # generic modules set boot_modules { core init timer - ld.lib.so libc.lib.so + ld.lib.so libc.lib.so libm.lib.so test-libc_block } diff --git a/repos/libports/run/libc_ffat_fs.run b/repos/libports/run/libc_ffat_fs.run index fc6201874..415c05ff9 100644 --- a/repos/libports/run/libc_ffat_fs.run +++ b/repos/libports/run/libc_ffat_fs.run @@ -104,7 +104,7 @@ install_config $config # generic modules set boot_modules { core init timer ffat_fs - ld.lib.so libc.lib.so + ld.lib.so libc.lib.so libm.lib.so test-libc_vfs } diff --git a/repos/libports/run/libc_filesystem_test.inc b/repos/libports/run/libc_filesystem_test.inc index 833069a5f..51a541fa0 100644 --- a/repos/libports/run/libc_filesystem_test.inc +++ b/repos/libports/run/libc_filesystem_test.inc @@ -130,7 +130,7 @@ install_config $config # generic modules set boot_modules { core init timer - ld.lib.so libc.lib.so + ld.lib.so libc.lib.so libm.lib.so } append boot_modules test-libc_$filesystem diff --git a/repos/libports/run/libc_pipe.run b/repos/libports/run/libc_pipe.run index e6ca14578..41bc9a1e2 100644 --- a/repos/libports/run/libc_pipe.run +++ b/repos/libports/run/libc_pipe.run @@ -32,7 +32,7 @@ install_config { build_boot_image { core init test-libc_pipe - ld.lib.so libc.lib.so libc_pipe.lib.so pthread.lib.so + ld.lib.so libc.lib.so libm.lib.so libc_pipe.lib.so pthread.lib.so } append qemu_args " -nographic -m 64 " diff --git a/repos/libports/run/libc_vfs.run b/repos/libports/run/libc_vfs.run index 70056d71c..6c2d4ced8 100644 --- a/repos/libports/run/libc_vfs.run +++ b/repos/libports/run/libc_vfs.run @@ -62,7 +62,7 @@ install_config $config build_boot_image { core init - ld.lib.so libc.lib.so + ld.lib.so libc.lib.so libm.lib.so ram_fs test-libc_vfs } diff --git a/repos/libports/run/libc_vfs_fs.run b/repos/libports/run/libc_vfs_fs.run index 37a43fa65..f30b5e485 100644 --- a/repos/libports/run/libc_vfs_fs.run +++ b/repos/libports/run/libc_vfs_fs.run @@ -65,7 +65,7 @@ install_config $config build_boot_image { core init vfs - ld.lib.so libc.lib.so + ld.lib.so libc.lib.so libm.lib.so test-libc_vfs } diff --git a/repos/libports/run/libc_vfs_ram.run b/repos/libports/run/libc_vfs_ram.run index 15b0cb502..35ba7d476 100644 --- a/repos/libports/run/libc_vfs_ram.run +++ b/repos/libports/run/libc_vfs_ram.run @@ -60,7 +60,7 @@ install_config $config build_boot_image { core init - ld.lib.so libc.lib.so + ld.lib.so libc.lib.so libm.lib.so test-libc_vfs } diff --git a/repos/libports/run/lwip.run b/repos/libports/run/lwip.run index cfcd0be68..cab06d0ba 100644 --- a/repos/libports/run/lwip.run +++ b/repos/libports/run/lwip.run @@ -120,7 +120,7 @@ install_config $config # generic modules set boot_modules { core init timer - ld.lib.so libc.lib.so lwip.lib.so test-lwip_httpsrv + ld.lib.so libc.lib.so libm.lib.so lwip.lib.so test-lwip_httpsrv } # platform-specific modules diff --git a/repos/libports/run/nic_router.run b/repos/libports/run/nic_router.run index 5fcdb5336..39e153010 100644 --- a/repos/libports/run/nic_router.run +++ b/repos/libports/run/nic_router.run @@ -369,7 +369,7 @@ install_config $config # generic modules set boot_modules { - core init timer nic_router nic_bridge ld.lib.so libc.lib.so + core init timer nic_router nic_bridge ld.lib.so libc.lib.so libm.lib.so libc_resolv.lib.so lwip.lib.so lxip.lib.so test-http_clnt test-lwip_httpsrv_static test-lxip_udp_echo test-lxip_udp_client } diff --git a/repos/libports/run/pthread.run b/repos/libports/run/pthread.run index 359cea212..c447da0d5 100644 --- a/repos/libports/run/pthread.run +++ b/repos/libports/run/pthread.run @@ -32,7 +32,7 @@ install_config { build_boot_image { core init test-pthread - ld.lib.so libc.lib.so pthread.lib.so + ld.lib.so libc.lib.so libm.lib.so pthread.lib.so } append qemu_args " -nographic -m 128 " diff --git a/repos/libports/run/smartcard.run b/repos/libports/run/smartcard.run index 1e456f3ce..25c69a9e0 100644 --- a/repos/libports/run/smartcard.run +++ b/repos/libports/run/smartcard.run @@ -109,7 +109,7 @@ install_config $config set boot_modules { core init timer usb_drv test-smartcard ld.lib.so pcsc-lite.lib.so ccid.lib.so libusb.lib.so - libc.lib.so libc_pipe.lib.so pthread.lib.so + libc.lib.so libm.lib.so libc_pipe.lib.so pthread.lib.so Info.plist } diff --git a/repos/libports/src/app/acpica/os.cc b/repos/libports/src/app/acpica/os.cc index 8645ccfd5..488ade5a8 100644 --- a/repos/libports/src/app/acpica/os.cc +++ b/repos/libports/src/app/acpica/os.cc @@ -11,7 +11,7 @@ */ #include -#include +#include #include #include #include @@ -303,4 +303,4 @@ ACPI_STATUS AcpiOsInstallInterruptHandler(UINT32 irq, ACPI_OSD_HANDLER handler, } -void Component::construct(Genode::Env &env) { static Acpica::Main main(env); } +void Libc::Component::construct(Genode::Env &env) { static Acpica::Main main(env); } diff --git a/repos/libports/src/app/avplay/target.mk b/repos/libports/src/app/avplay/target.mk index 7e757a574..b841a2cc6 100644 --- a/repos/libports/src/app/avplay/target.mk +++ b/repos/libports/src/app/avplay/target.mk @@ -3,7 +3,7 @@ include $(REP_DIR)/lib/import/import-av.inc TARGET = avplay SRC_C = avplay.c cmdutils.c libc_dummies.c LIBS += avfilter avformat avcodec avutil avresample swscale -LIBS += sdl libc libm config_args +LIBS += sdl posix config_args CC_WARN += -Wno-parentheses -Wno-switch -Wno-uninitialized \ -Wno-format-zero-length -Wno-pointer-sign diff --git a/repos/libports/src/app/eglgears/target.mk b/repos/libports/src/app/eglgears/target.mk index 241d29b39..9219eee92 100644 --- a/repos/libports/src/app/eglgears/target.mk +++ b/repos/libports/src/app/eglgears/target.mk @@ -1,3 +1,3 @@ TARGET = eglgears SRC_C = eglgears.c -LIBS = libc libm gallium +LIBS = posix gallium diff --git a/repos/libports/src/app/mupdf/target.mk b/repos/libports/src/app/mupdf/target.mk index 140855f1f..99dade20f 100644 --- a/repos/libports/src/app/mupdf/target.mk +++ b/repos/libports/src/app/mupdf/target.mk @@ -2,7 +2,7 @@ MUPDF_DIR := $(call select_from_ports,mupdf)/src/lib/mupdf TARGET := mupdf SRC_C := pdfapp.c SRC_CC := main.cc -LIBS := libc mupdf +LIBS := posix mupdf INC_DIR += $(MUPDF_DIR)/apps vpath pdfapp.c $(MUPDF_DIR)/apps diff --git a/repos/libports/src/app/qt5/examples/calculatorform/target.mk b/repos/libports/src/app/qt5/examples/calculatorform/target.mk index da0862faf..5bc394576 100644 --- a/repos/libports/src/app/qt5/examples/calculatorform/target.mk +++ b/repos/libports/src/app/qt5/examples/calculatorform/target.mk @@ -15,3 +15,5 @@ vpath % $(QMAKE_PROJECT_PATH) include $(QT5_REP_DIR)/src/app/qt5/tmpl/target_defaults.inc include $(QT5_REP_DIR)/src/app/qt5/tmpl/target_final.inc + +LIBS += posix diff --git a/repos/libports/src/app/qt5/examples/openglwindow/target.mk b/repos/libports/src/app/qt5/examples/openglwindow/target.mk index 1878cdc23..a11f1f1b6 100644 --- a/repos/libports/src/app/qt5/examples/openglwindow/target.mk +++ b/repos/libports/src/app/qt5/examples/openglwindow/target.mk @@ -15,3 +15,5 @@ vpath % $(QMAKE_PROJECT_PATH) include $(QT5_REP_DIR)/src/app/qt5/tmpl/target_defaults.inc include $(QT5_REP_DIR)/src/app/qt5/tmpl/target_final.inc + +LIBS += posix diff --git a/repos/libports/src/app/qt5/examples/previewer/target.mk b/repos/libports/src/app/qt5/examples/previewer/target.mk index 6782de693..cd35c6336 100644 --- a/repos/libports/src/app/qt5/examples/previewer/target.mk +++ b/repos/libports/src/app/qt5/examples/previewer/target.mk @@ -15,3 +15,5 @@ vpath % $(QMAKE_PROJECT_PATH) include $(QT5_REP_DIR)/src/app/qt5/tmpl/target_defaults.inc include $(QT5_REP_DIR)/src/app/qt5/tmpl/target_final.inc + +LIBS += posix diff --git a/repos/libports/src/app/qt5/examples/samegame/target.mk b/repos/libports/src/app/qt5/examples/samegame/target.mk index dab4d8d8b..a6d92f707 100644 --- a/repos/libports/src/app/qt5/examples/samegame/target.mk +++ b/repos/libports/src/app/qt5/examples/samegame/target.mk @@ -36,3 +36,5 @@ $(addprefix $(BUILD_BASE_DIR)/bin/qt5_fs/$(TARGET)/, $(SAMEGAME3_RESOURCES)): $( $(addprefix $(BUILD_BASE_DIR)/bin/qt5_fs/$(TARGET)/shared/pics/, $(SAMEGAME_RESOURCES)): $(BUILD_BASE_DIR)/bin/qt5_fs/$(TARGET)/shared/pics $(VERBOSE)ln -sf $(QT5_CONTRIB_DIR)/qtdeclarative/examples/quick/tutorials/samegame/shared/pics/$(notdir $@) $@ + +LIBS += posix diff --git a/repos/libports/src/app/qt5/examples/tetrix/target.mk b/repos/libports/src/app/qt5/examples/tetrix/target.mk index 202cb3f91..62e85d0b9 100644 --- a/repos/libports/src/app/qt5/examples/tetrix/target.mk +++ b/repos/libports/src/app/qt5/examples/tetrix/target.mk @@ -17,3 +17,5 @@ include $(QT5_REP_DIR)/src/app/qt5/tmpl/target_defaults.inc CC_CXX_OPT += -DQT_NO_SCRIPTTOOLS include $(QT5_REP_DIR)/src/app/qt5/tmpl/target_final.inc + +LIBS += posix diff --git a/repos/libports/src/app/qt5/examples/textedit/target.mk b/repos/libports/src/app/qt5/examples/textedit/target.mk index 0488441d9..bd008a205 100644 --- a/repos/libports/src/app/qt5/examples/textedit/target.mk +++ b/repos/libports/src/app/qt5/examples/textedit/target.mk @@ -16,3 +16,4 @@ include $(QT5_REP_DIR)/src/app/qt5/tmpl/target_defaults.inc include $(QT5_REP_DIR)/src/app/qt5/tmpl/target_final.inc +LIBS += posix diff --git a/repos/libports/src/app/qt5/qt_avplay/main.cpp b/repos/libports/src/app/qt5/qt_avplay/main.cpp index 98ccb808c..4e0049618 100644 --- a/repos/libports/src/app/qt5/qt_avplay/main.cpp +++ b/repos/libports/src/app/qt5/qt_avplay/main.cpp @@ -18,8 +18,7 @@ #include "main_window.h" /* Genode includes */ -#include -#include +#include static inline void load_stylesheet() @@ -38,7 +37,7 @@ static inline void load_stylesheet() extern int genode_argc; extern char **genode_argv; -void Component::construct(Genode::Env &env) +void Libc::Component::construct(Genode::Env &env) { QApplication app(genode_argc, genode_argv); diff --git a/repos/libports/src/app/qt5/qt_avplay/target.mk b/repos/libports/src/app/qt5/qt_avplay/target.mk index 07c1bf8aa..6c35907b0 100644 --- a/repos/libports/src/app/qt5/qt_avplay/target.mk +++ b/repos/libports/src/app/qt5/qt_avplay/target.mk @@ -27,3 +27,4 @@ $(BUILD_BASE_DIR)/bin/qt5_fs/$(TARGET)/player_stop.png: $(BUILD_BASE_DIR)/bin/qt $(BUILD_BASE_DIR)/bin/qt5_fs/$(TARGET)/volume.png: $(BUILD_BASE_DIR)/bin/qt5_fs/$(TARGET) $(VERBOSE)ln -sf $(QT5_CONTRIB_DIR)/qtwebkit/Source/WebKit/efl/DefaultTheme/widget/mediacontrol/mutebutton/unmutebutton.png $@ + diff --git a/repos/libports/src/app/qt5/qt_launchpad/main.cpp b/repos/libports/src/app/qt5/qt_launchpad/main.cpp index 199afc36b..5598899c3 100644 --- a/repos/libports/src/app/qt5/qt_launchpad/main.cpp +++ b/repos/libports/src/app/qt5/qt_launchpad/main.cpp @@ -12,7 +12,7 @@ #include /* Genode includes */ -#include +#include #include extern int genode_argc; @@ -56,7 +56,8 @@ struct Qt_launchpad_namespace::Local_env : Genode::Env void close(Parent::Client::Id id) { return genode_env.close(id); } }; -void Component::construct(Genode::Env &env) + +void Libc::Component::construct(Genode::Env &env) { static Qt_launchpad_namespace::Local_env local_env(env); diff --git a/repos/libports/src/app/qt5/qt_quicktest/target.mk b/repos/libports/src/app/qt5/qt_quicktest/target.mk index ddacab428..690f6fa6b 100644 --- a/repos/libports/src/app/qt5/qt_quicktest/target.mk +++ b/repos/libports/src/app/qt5/qt_quicktest/target.mk @@ -6,3 +6,4 @@ include $(QT5_REP_DIR)/src/app/qt5/tmpl/target_defaults.inc include $(QT5_REP_DIR)/src/app/qt5/tmpl/target_final.inc +LIBS += posix diff --git a/repos/libports/src/lib/libc/task.cc b/repos/libports/src/lib/libc/task.cc index 4ca4caa9e..67fd182c0 100644 --- a/repos/libports/src/lib/libc/task.cc +++ b/repos/libports/src/lib/libc/task.cc @@ -19,6 +19,9 @@ #include #include +/* libc includes */ +#include + /* libc-internal includes */ #include #include @@ -41,12 +44,7 @@ } while (0) -namespace Libc { - class Task; - - void (*original_call_component_construct)(Genode::Env &); - void call_component_construct(Genode::Env &env); -} +namespace Libc { class Task; } struct Task_resume @@ -56,9 +54,6 @@ struct Task_resume }; -Genode::size_t Component::stack_size() { - return 32UL * 1024 * sizeof(Genode::addr_t); } - /** * Libc task * @@ -165,7 +160,7 @@ class Libc::Task : public Genode::Rpc_object void Libc::Task::_app_entry(Task *task) { - original_call_component_construct(task->_env); + Libc::Component::construct(task->_env); /* returned from task - switch stack to libc and return to dispatch loop */ _longjmp(task->_libc_task, 1); @@ -190,31 +185,37 @@ namespace Libc { void schedule_suspend(void (*suspended) ()) { + if (!task) { + error("libc task handling not initialized, needed for suspend"); + return; + } task->schedule_suspend(suspended); } } -/**************************** - ** Component-startup hook ** - ****************************/ +/*************************** + ** Component entry point ** + ***************************/ -/* XXX needs base-internal header? */ -namespace Genode { extern void (*call_component_construct)(Genode::Env &); } +Genode::size_t Component::stack_size() { return Libc::Component::stack_size(); } -void Libc::call_component_construct(Genode::Env &env) + +void Component::construct(Genode::Env &env) { /* pass Genode::Env to libc subsystems that depend on it */ - init_dl(env); + Libc::init_dl(env); task = unmanaged_singleton(env); task->run(); } -static void __attribute__((constructor)) libc_task_constructor(void) -{ - /* hook into component startup */ - Libc::original_call_component_construct = Genode::call_component_construct; - Genode::call_component_construct = &Libc::call_component_construct; -} +/** + * Default stack size for libc-using components + */ +Genode::size_t Libc::Component::stack_size() __attribute__((weak)); +Genode::size_t Libc::Component::stack_size() { + return 32UL * 1024 * sizeof(Genode::addr_t); } + + diff --git a/repos/libports/src/lib/posix/construct.cc b/repos/libports/src/lib/posix/construct.cc new file mode 100644 index 000000000..90c347794 --- /dev/null +++ b/repos/libports/src/lib/posix/construct.cc @@ -0,0 +1,32 @@ +/* + * \brief Entry point for POSIX applications + * \author Norman Feske + * \date 2016-12-23 + */ + +/* + * Copyright (C) 2016 Genode Labs GmbH + * + * This file is part of the Genode OS framework, which is distributed + * under the terms of the GNU General Public License version 2. + */ + +/* Genode includes */ +#include + +/* libc includes */ +#include /* for 'exit' */ + +extern char **genode_argv; +extern int genode_argc; +extern char **genode_envp; + + +/* provided by the application */ +extern "C" int main(int argc, char ** argv, char **envp); + + +void Libc::Component::construct(Genode::Env &env) +{ + exit(main(genode_argc, genode_argv, genode_envp)); +} diff --git a/repos/libports/src/lib/qt5/qt_main.cc b/repos/libports/src/lib/qt5/qt_main.cc index ca4c87940..0f520e629 100644 --- a/repos/libports/src/lib/qt5/qt_main.cc +++ b/repos/libports/src/lib/qt5/qt_main.cc @@ -13,19 +13,8 @@ #ifdef QT_MAIN_STACK_SIZE -#include +#include -using namespace Genode; - -extern int qt_main(int argc, char *argv[]); - -#define qt_main main - -int main(int argc, char *argv[]) -{ - Genode::Thread::myself()->stack_size(QT_MAIN_STACK_SIZE); - - return qt_main(argc, argv); -} +Genode::size_t Libc::Component::stack_size() { return QT_MAIN_STACK_SIZE; } #endif /* QT_MAIN_STACK_SIZE */ diff --git a/repos/libports/src/server/fuse_fs/exfat/target.mk b/repos/libports/src/server/fuse_fs/exfat/target.mk index 87ac848e1..c29ebf7ff 100644 --- a/repos/libports/src/server/fuse_fs/exfat/target.mk +++ b/repos/libports/src/server/fuse_fs/exfat/target.mk @@ -6,7 +6,7 @@ SRC_C = $(notdir $(EXFAT_DIR)/fuse/main.c) SRC_CC = fuse_fs_main.cc \ init.cc -LIBS = base config server libc libfuse libexfat +LIBS = config libc libfuse libexfat INC_DIR += $(PRG_DIR)/.. CC_OPT += -Wno-unused-function diff --git a/repos/libports/src/server/fuse_fs/ext2/target.mk b/repos/libports/src/server/fuse_fs/ext2/target.mk index 54143c409..b59802400 100644 --- a/repos/libports/src/server/fuse_fs/ext2/target.mk +++ b/repos/libports/src/server/fuse_fs/ext2/target.mk @@ -9,7 +9,7 @@ SRC_C = $(filter-out $(FILTER_OUT), $(notdir $(wildcard $(FUSE_EXT2_DIR)/*.c))) SRC_CC = fuse_fs_main.cc \ init.cc -LIBS = base config server libc libfuse libext2fs +LIBS = config libc libfuse libext2fs CC_OPT += -DHAVE_CONFIG_H -D_GNU_SOURCE -D_FILE_OFFSET_BITS=64 diff --git a/repos/libports/src/server/fuse_fs/fuse_fs_main.cc b/repos/libports/src/server/fuse_fs/fuse_fs_main.cc index 42bfd82ca..df17ea827 100644 --- a/repos/libports/src/server/fuse_fs/fuse_fs_main.cc +++ b/repos/libports/src/server/fuse_fs/fuse_fs_main.cc @@ -17,10 +17,10 @@ #include #include #include -#include #include #include #include +#include /* libc includes */ #include @@ -41,13 +41,13 @@ class File_system::Session_component : public Session_rpc_object { private: - Server::Entrypoint &_ep; + Genode::Entrypoint &_ep; Allocator &_md_alloc; Directory &_root; Node_handle_registry _handle_registry; bool _writeable; - Signal_rpc_member _process_packet_dispatcher; + Signal_handler _process_packet_handler; /****************************** @@ -115,10 +115,10 @@ class File_system::Session_component : public Session_rpc_object } /** - * Called by signal dispatcher, executed in the context of the main + * Called by signal handler, executed in the context of the main * thread (not serialized with the RPC functions) */ - void _process_packets(unsigned) + void _process_packets() { while (tx_sink()->packet_avail()) { @@ -158,7 +158,7 @@ class File_system::Session_component : public Session_rpc_object * Constructor */ Session_component(size_t tx_buf_size, - Server::Entrypoint &ep, + Genode::Entrypoint &ep, char const *root_dir, bool writeable, Allocator &md_alloc) @@ -168,10 +168,10 @@ class File_system::Session_component : public Session_rpc_object _md_alloc(md_alloc), _root(*new (&_md_alloc) Directory(_md_alloc, root_dir, false)), _writeable(writeable), - _process_packet_dispatcher(_ep, *this, &Session_component::_process_packets) + _process_packet_handler(_ep, *this, &Session_component::_process_packets) { - _tx.sigh_packet_avail(_process_packet_dispatcher); - _tx.sigh_ready_to_ack(_process_packet_dispatcher); + _tx.sigh_packet_avail(_process_packet_handler); + _tx.sigh_ready_to_ack(_process_packet_handler); } /** @@ -408,7 +408,7 @@ class File_system::Root : public Root_component { private: - Server::Entrypoint &_ep; + Genode::Entrypoint &_ep; protected: @@ -501,7 +501,7 @@ class File_system::Root : public Root_component * data-flow signals of packet streams * \param md_alloc meta-data allocator */ - Root(Server::Entrypoint &ep, Allocator &md_alloc) + Root(Genode::Entrypoint &ep, Allocator &md_alloc) : Root_component(&ep.rpc_ep(), &md_alloc), _ep(ep) @@ -511,7 +511,7 @@ class File_system::Root : public Root_component struct File_system::Main { - Server::Entrypoint &ep; + Genode::Entrypoint &ep; /* * Initialize root interface @@ -520,7 +520,7 @@ struct File_system::Main Root fs_root = { ep, sliced_heap }; - Main(Server::Entrypoint &ep) : ep(ep) + Main(Genode::Entrypoint &ep) : ep(ep) { if (!Fuse::init_fs()) { Genode::error("FUSE fs initialization failed"); @@ -539,10 +539,12 @@ struct File_system::Main }; -/********************** - ** Server framework ** - **********************/ +/*************** + ** Component ** + ***************/ + +void Libc::Component::construct(Genode::Env &env) +{ + static File_system::Main inst(env.ep()); +} -char const * Server::name() { return "fuse_fs_ep"; } -Genode::size_t Server::stack_size() { return 16*1024*sizeof(long); } -void Server::construct(Server::Entrypoint &ep) { static File_system::Main inst(ep); } diff --git a/repos/libports/src/server/fuse_fs/ntfs-3g/target.mk b/repos/libports/src/server/fuse_fs/ntfs-3g/target.mk index 93ca75b26..8a68cc465 100644 --- a/repos/libports/src/server/fuse_fs/ntfs-3g/target.mk +++ b/repos/libports/src/server/fuse_fs/ntfs-3g/target.mk @@ -6,7 +6,7 @@ SRC_C := ntfs-3g.c ntfs-3g_common.c SRC_CC := fuse_fs_main.cc \ init.cc -LIBS := base config server libc libfuse libntfs-3g +LIBS := config libc libfuse libntfs-3g CC_OPT := -DHAVE_TIMESPEC -DHAVE_CONFIG_H -DRECORD_LOCKING_NOT_IMPLEMENTED diff --git a/repos/libports/src/test/expat/target.mk b/repos/libports/src/test/expat/target.mk index c81c877fc..25e86d8d2 100644 --- a/repos/libports/src/test/expat/target.mk +++ b/repos/libports/src/test/expat/target.mk @@ -1,3 +1,3 @@ TARGET = test-expat SRC_CC = main.cc -LIBS = expat libc +LIBS = expat posix diff --git a/repos/libports/src/test/ldso/main.cc b/repos/libports/src/test/ldso/main.cc index 93d28fe3c..8567d6657 100644 --- a/repos/libports/src/test/ldso/main.cc +++ b/repos/libports/src/test/ldso/main.cc @@ -15,7 +15,7 @@ #include #include #include -#include +#include #include using namespace Genode; @@ -185,7 +185,7 @@ static void test_shared_object_api(Env &env, Allocator &alloc) /** * Main function of LDSO test */ -void Component::construct(Genode::Env &env) +void Libc::Component::construct(Genode::Env &env) { static Heap heap(env.ram(), env.rm()); diff --git a/repos/libports/src/test/libc/target.mk b/repos/libports/src/test/libc/target.mk index c3d25f0bd..1ec8714bf 100644 --- a/repos/libports/src/test/libc/target.mk +++ b/repos/libports/src/test/libc/target.mk @@ -1,3 +1,3 @@ TARGET = test-libc SRC_CC = main.cc -LIBS = libm libc +LIBS = posix diff --git a/repos/libports/src/test/libc_block/target.mk b/repos/libports/src/test/libc_block/target.mk index a7c277b0d..4d21ddd9e 100644 --- a/repos/libports/src/test/libc_block/target.mk +++ b/repos/libports/src/test/libc_block/target.mk @@ -1,3 +1,3 @@ TARGET = test-libc_block -LIBS = libc +LIBS = posix SRC_CC = main.cc diff --git a/repos/libports/src/test/libc_ffat/target.mk b/repos/libports/src/test/libc_ffat/target.mk index 3b2a9e960..1e58fbbc5 100644 --- a/repos/libports/src/test/libc_ffat/target.mk +++ b/repos/libports/src/test/libc_ffat/target.mk @@ -1,3 +1,3 @@ TARGET = test-libc_ffat -LIBS = libc libc_ffat +LIBS = posix libc_ffat SRC_CC = main.cc diff --git a/repos/libports/src/test/libc_pipe/target.mk b/repos/libports/src/test/libc_pipe/target.mk index 101a63a38..ef5e916f5 100644 --- a/repos/libports/src/test/libc_pipe/target.mk +++ b/repos/libports/src/test/libc_pipe/target.mk @@ -1,3 +1,3 @@ TARGET = test-libc_pipe -LIBS = libc libc_pipe pthread +LIBS = posix libc_pipe pthread SRC_CC = main.cc diff --git a/repos/libports/src/test/libc_resolv/target.mk b/repos/libports/src/test/libc_resolv/target.mk index f28e4bb0c..963a8c993 100644 --- a/repos/libports/src/test/libc_resolv/target.mk +++ b/repos/libports/src/test/libc_resolv/target.mk @@ -1,3 +1,3 @@ TARGET = test-libc_resolv SRC_CC = main.cc -LIBS = libc libc_resolv +LIBS = posix libc_resolv diff --git a/repos/libports/src/test/libc_vfs/target.mk b/repos/libports/src/test/libc_vfs/target.mk index c49e6ca3c..93caeecc0 100644 --- a/repos/libports/src/test/libc_vfs/target.mk +++ b/repos/libports/src/test/libc_vfs/target.mk @@ -1,5 +1,5 @@ TARGET = test-libc_vfs -LIBS = libc +LIBS = posix SRC_CC = main.cc # we re-use the libc_ffat test diff --git a/repos/libports/src/test/libports/main.cc b/repos/libports/src/test/libports/main.cc index 7815a2a4f..5522f6557 100644 --- a/repos/libports/src/test/libports/main.cc +++ b/repos/libports/src/test/libports/main.cc @@ -11,4 +11,6 @@ * under the terms of the GNU General Public License version 2. */ -int main() { } +#include + +void Libc::Component::construct(Genode::Env &) { } diff --git a/repos/libports/src/test/lwip/http_clnt/target.mk b/repos/libports/src/test/lwip/http_clnt/target.mk index 83b0bd07f..ccbba60ff 100644 --- a/repos/libports/src/test/lwip/http_clnt/target.mk +++ b/repos/libports/src/test/lwip/http_clnt/target.mk @@ -1,5 +1,5 @@ TARGET = test-http_clnt -LIBS = lwip libc +LIBS = lwip posix SRC_CC = main.cc INC_DIR += $(REP_DIR)/src/lib/lwip/include diff --git a/repos/libports/src/test/lwip/http_srv/target.mk b/repos/libports/src/test/lwip/http_srv/target.mk index d1ae5055c..cfe186538 100644 --- a/repos/libports/src/test/lwip/http_srv/target.mk +++ b/repos/libports/src/test/lwip/http_srv/target.mk @@ -1,5 +1,5 @@ TARGET = test-lwip_httpsrv -LIBS = lwip libc +LIBS = lwip posix SRC_CC = main.cc INC_DIR += $(REP_DIR)/src/lib/lwip/include diff --git a/repos/libports/src/test/lwip/http_srv_static/target.mk b/repos/libports/src/test/lwip/http_srv_static/target.mk index 38dc61a22..5ff243d16 100644 --- a/repos/libports/src/test/lwip/http_srv_static/target.mk +++ b/repos/libports/src/test/lwip/http_srv_static/target.mk @@ -1,5 +1,5 @@ TARGET = test-lwip_httpsrv_static -LIBS = lwip libc config +LIBS = lwip posix config SRC_CC = main.cc INC_DIR += $(REP_DIR)/src/lib/lwip/include diff --git a/repos/libports/src/test/lwip/loopback/target.mk b/repos/libports/src/test/lwip/loopback/target.mk index 3ef9b05cc..483a5e916 100644 --- a/repos/libports/src/test/lwip/loopback/target.mk +++ b/repos/libports/src/test/lwip/loopback/target.mk @@ -1,3 +1,3 @@ TARGET = test-lwip_loop -LIBS = lwip libc libc_lwip_loopback +LIBS = lwip posix libc_lwip_loopback SRC_CC = main.cc diff --git a/repos/libports/src/test/lwip/pingpong/client/libc_lwip/target.mk b/repos/libports/src/test/lwip/pingpong/client/libc_lwip/target.mk index c4b21f275..bd5879f83 100644 --- a/repos/libports/src/test/lwip/pingpong/client/libc_lwip/target.mk +++ b/repos/libports/src/test/lwip/pingpong/client/libc_lwip/target.mk @@ -1,5 +1,5 @@ TARGET = test-ping_client_libc_lwip -LIBS = base libc lwip libc_lwip_nic_dhcp config_args +LIBS = posix lwip libc_lwip_nic_dhcp config_args SRC_CC = main.cc pingpong.cc vpath main.cc $(PRG_DIR)/.. diff --git a/repos/libports/src/test/lwip/pingpong/client/lwip/target.mk b/repos/libports/src/test/lwip/pingpong/client/lwip/target.mk index 868b597eb..095ab47a8 100644 --- a/repos/libports/src/test/lwip/pingpong/client/lwip/target.mk +++ b/repos/libports/src/test/lwip/pingpong/client/lwip/target.mk @@ -1,5 +1,5 @@ TARGET = test-ping_client_lwip -LIBS = base libc lwip config_args +LIBS = posix lwip config_args SRC_CC = main.cc pingpong.cc INC_DIR += $(REP_DIR)/src/lib/lwip/include diff --git a/repos/libports/src/test/lwip/pingpong/server/libc_lwip/target.mk b/repos/libports/src/test/lwip/pingpong/server/libc_lwip/target.mk index 7d150f8aa..1c14b0cba 100644 --- a/repos/libports/src/test/lwip/pingpong/server/libc_lwip/target.mk +++ b/repos/libports/src/test/lwip/pingpong/server/libc_lwip/target.mk @@ -1,5 +1,5 @@ TARGET = test-ping_server_libc_lwip -LIBS = base libc libc_lwip_nic_dhcp libc_lwip lwip config_args +LIBS = posix libc_lwip_nic_dhcp libc_lwip lwip config_args SRC_CC = main.cc pingpong.cc vpath main.cc $(PRG_DIR)/.. diff --git a/repos/libports/src/test/lwip/pingpong/server/lwip/target.mk b/repos/libports/src/test/lwip/pingpong/server/lwip/target.mk index 3bc9171d7..d74eef17a 100644 --- a/repos/libports/src/test/lwip/pingpong/server/lwip/target.mk +++ b/repos/libports/src/test/lwip/pingpong/server/lwip/target.mk @@ -1,5 +1,5 @@ TARGET = test-ping_server_lwip -LIBS = base libc lwip config_args +LIBS = posix lwip config_args SRC_CC = main.cc pingpong.cc CC_OPT += -DLWIP_NATIVE diff --git a/repos/libports/src/test/moon/target.mk b/repos/libports/src/test/moon/target.mk index 4a833fba7..530b0753b 100644 --- a/repos/libports/src/test/moon/target.mk +++ b/repos/libports/src/test/moon/target.mk @@ -1,3 +1,3 @@ TARGET = test-moon -LIBS = luacxx libc libm +LIBS = luacxx posix SRC_CC = main.cc diff --git a/repos/libports/src/test/pthread/target.mk b/repos/libports/src/test/pthread/target.mk index 7e00299a0..a52d542df 100644 --- a/repos/libports/src/test/pthread/target.mk +++ b/repos/libports/src/test/pthread/target.mk @@ -1,3 +1,3 @@ TARGET = test-pthread SRC_CC = main.cc -LIBS = libc pthread +LIBS = posix pthread diff --git a/repos/libports/src/test/python/target.mk b/repos/libports/src/test/python/target.mk index 76e4a6cff..f8a205553 100644 --- a/repos/libports/src/test/python/target.mk +++ b/repos/libports/src/test/python/target.mk @@ -1,4 +1,4 @@ TARGET = test-python -LIBS = python libc libm +LIBS = python posix REQUIRES = x86 SRC_CC = main.cc diff --git a/repos/libports/src/test/qt5/qpluginwidget/target.mk b/repos/libports/src/test/qt5/qpluginwidget/target.mk index f4f8bd656..f452379dd 100644 --- a/repos/libports/src/test/qt5/qpluginwidget/target.mk +++ b/repos/libports/src/test/qt5/qpluginwidget/target.mk @@ -15,3 +15,5 @@ test-plugin.tar: config.plugin clean: $(VERBOSE)rm test-plugin.tar + +LIBS += posix diff --git a/repos/libports/src/test/rust/target.mk b/repos/libports/src/test/rust/target.mk index e2d9520a4..ba0e632b8 100644 --- a/repos/libports/src/test/rust/target.mk +++ b/repos/libports/src/test/rust/target.mk @@ -1,4 +1,5 @@ TARGET = test-rust SRC_RS = main.rs SRC_CC = printf.cc -LIBS = libcore-rust libcollections-rust base librustc_unicode-rust liballoc-rust liblibc-rust liballoc_system-rust +LIBS = libcore-rust libcollections-rust base librustc_unicode-rust \ + liballoc-rust liblibc-rust liballoc_system-rust posix diff --git a/repos/libports/src/test/sdl/target.mk b/repos/libports/src/test/sdl/target.mk index 4b3e0bf2c..a14e11b26 100644 --- a/repos/libports/src/test/sdl/target.mk +++ b/repos/libports/src/test/sdl/target.mk @@ -1,3 +1,3 @@ TARGET = test-sdl -LIBS = sdl libc +LIBS = sdl posix SRC_CC = main.cc diff --git a/repos/libports/src/test/smartcard/target.mk b/repos/libports/src/test/smartcard/target.mk index bc161a7ad..f5f479677 100644 --- a/repos/libports/src/test/smartcard/target.mk +++ b/repos/libports/src/test/smartcard/target.mk @@ -1,5 +1,5 @@ TARGET = test-smartcard -LIBS = pcsc-lite libc +LIBS = pcsc-lite posix SRC_CC = main.cc vpath main.cc $(PRG_DIR)/.. diff --git a/repos/libports/src/test/stdcxx/target.mk b/repos/libports/src/test/stdcxx/target.mk index 52a763630..c2f516abc 100644 --- a/repos/libports/src/test/stdcxx/target.mk +++ b/repos/libports/src/test/stdcxx/target.mk @@ -1,3 +1,3 @@ TARGET = test-stdcxx SRC_CC = main.cc -LIBS = base stdcxx +LIBS = posix stdcxx diff --git a/repos/os/src/test/blk/bench/main.cc b/repos/os/src/test/blk/bench/main.cc index f60f118c9..6217f6b68 100644 --- a/repos/os/src/test/blk/bench/main.cc +++ b/repos/os/src/test/blk/bench/main.cc @@ -2,6 +2,7 @@ #include #include #include +#include #include @@ -153,13 +154,7 @@ struct Test::Main }; -namespace Server { - - char const *name() { return "block_bench_ep"; }; - Genode::size_t stack_size() { return 16*1024*sizeof(long); } - - void construct(Entrypoint &ep) - { - static Test::Main server(ep); - } +void Libc::Component::construct(Genode::Env &env) +{ + static Test::Main server(env.ep()); } diff --git a/repos/os/src/test/blk/bench/target.mk b/repos/os/src/test/blk/bench/target.mk index cfb1b61bb..8c4e31654 100644 --- a/repos/os/src/test/blk/bench/target.mk +++ b/repos/os/src/test/blk/bench/target.mk @@ -1,3 +1,3 @@ TARGET = test-blk-bench SRC_CC = main.cc -LIBS = base server libc +LIBS = base libc diff --git a/repos/ports/mk/gnu_build.mk b/repos/ports/mk/gnu_build.mk index 2185590ec..b1fca8c15 100644 --- a/repos/ports/mk/gnu_build.mk +++ b/repos/ports/mk/gnu_build.mk @@ -30,7 +30,7 @@ TARGET ?= $(lastword $(subst /, ,$(PRG_DIR))) PKG ?= $(TARGET) -LIBS += libc libm +LIBS += posix PWD = $(shell pwd) @@ -107,18 +107,9 @@ CXXFLAGS += $(COMMON_CFLAGS_CXXFLAGS) # Unfortunately, the use of '--start-group' and '--end-group' does not suffice # in all cases because 'libtool' strips those arguments from the 'LIBS' variable. # -# Furthermore, 'libtool' reorders library names on the command line in a way that -# shared libraries appear before static libraries. This has the unfortunate effect -# that the program's entry symbol 'Genode::component_entry_point' in the static -# library 'component_entry_point.lib.a' is not found anymore. Passing the static -# library names as linker arguments (-Wl,...) works around this problem, because -# 'libtool' keeps command line arguments before the shared library names. -# - LDLIBS_A = $(filter %.a, $(sort $(LINK_ITEMS)) $(EXT_OBJECTS) $(LIBGCC)) LDLIBS_SO = $(filter %.so,$(sort $(LINK_ITEMS)) $(EXT_OBJECTS) $(LIBGCC)) -comma := , -LDLIBS += $(addprefix -Wl$(comma),$(LDLIBS_A)) $(LDLIBS_SO) $(LDLIBS_A) +LDLIBS += $(LDLIBS_A) $(LDLIBS_SO) $(LDLIBS_A) # # Re-configure the Makefile if the Genode build environment changes diff --git a/repos/ports/src/app/arora/target.mk b/repos/ports/src/app/arora/target.mk index 2557d2aa8..e66081420 100644 --- a/repos/ports/src/app/arora/target.mk +++ b/repos/ports/src/app/arora/target.mk @@ -84,3 +84,5 @@ vpath % $(ARORA_PORT_DIR)/src/app/arora/src/useragent vpath % $(ARORA_PORT_DIR)/src/app/arora/src/utils -include $(QT_TMPL_DIR)/target_final.inc + +LIBS += posix diff --git a/repos/ports/src/app/dosbox/target.mk b/repos/ports/src/app/dosbox/target.mk index 3098b69b7..ef0952229 100644 --- a/repos/ports/src/app/dosbox/target.mk +++ b/repos/ports/src/app/dosbox/target.mk @@ -53,5 +53,5 @@ CC_WARN += -Wno-unused-variable -Wno-unused-function -Wno-switch -Wno-unused-val -Wno-sign-compare -Wno-narrowing -Wno-missing-braces -Wno-array-bounds \ -Wno-parentheses -LIBS += libc libm libpng sdl sdl_net stdcxx zlib +LIBS += posix libpng sdl sdl_net stdcxx zlib LIBS += libc_lwip_nic_dhcp config_args diff --git a/repos/ports/src/app/gdb_monitor/main.cc b/repos/ports/src/app/gdb_monitor/main.cc index 17a972bb7..af165f788 100644 --- a/repos/ports/src/app/gdb_monitor/main.cc +++ b/repos/ports/src/app/gdb_monitor/main.cc @@ -11,7 +11,7 @@ * under the terms of the GNU General Public License version 2. */ -#include +#include /* * Suppress messages of libc dummy functions @@ -33,7 +33,7 @@ extern "C" int gdbserver_main(int argc, const char *argv[]); extern Genode::Env *genode_env; -void Component::construct(Genode::Env &env) +void Libc::Component::construct(Genode::Env &env) { genode_env = &env; diff --git a/repos/ports/src/app/lighttpd/target.inc b/repos/ports/src/app/lighttpd/target.inc index 2c71ac049..bbc86052a 100644 --- a/repos/ports/src/app/lighttpd/target.inc +++ b/repos/ports/src/app/lighttpd/target.inc @@ -29,5 +29,5 @@ CC_WARN = -Wall -Wno-unused-variable -Wno-unused-function INC_DIR += $(PRG_DIR) INC_DIR += $(LIGHTTPD_DIR)/src -LIBS += libc libm +LIBS += posix LIBS += zlib config_args diff --git a/repos/ports/src/app/netperf/target.inc b/repos/ports/src/app/netperf/target.inc index 0b4dfcbeb..a37ce6126 100644 --- a/repos/ports/src/app/netperf/target.inc +++ b/repos/ports/src/app/netperf/target.inc @@ -1,7 +1,7 @@ NETPERF_DIR := $(call select_from_ports,netperf)/src/app/netperf -LIBS += base libc libm libc-resolv libc-net libc-nameser libc-isc +LIBS += posix libc-resolv libc-net libc-nameser libc-isc # plug-in to libc LIBS += config_args diff --git a/repos/ports/src/app/openvpn/main.cc b/repos/ports/src/app/openvpn/main.cc index 02679b3a5..b8337c8ac 100644 --- a/repos/ports/src/app/openvpn/main.cc +++ b/repos/ports/src/app/openvpn/main.cc @@ -13,12 +13,12 @@ /* Genode includes */ #include -#include #include #include #include #include #include +#include /* libc includes */ #include @@ -135,7 +135,7 @@ class Openvpn_component : public Tuntap_device, Genode::size_t const rx_buf_size, Genode::Allocator &rx_block_md_alloc, Genode::Ram_session &ram_session, - Server::Entrypoint &ep) + Genode::Entrypoint &ep) : Session_component(tx_buf_size, rx_buf_size, rx_block_md_alloc, ram_session, ep) { char buf[] = { 0x02, 0x00, 0x00, 0x00, 0x00, 0x01 }; @@ -203,7 +203,7 @@ class Root : public Genode::Root_component(&ep.rpc_ep(), &md_alloc), _ep(ep) { } @@ -272,22 +272,21 @@ class Root : public Genode::Root_componentheap() }; - Main(Server::Entrypoint &ep) : ep(ep) + Main(Genode::Entrypoint &ep) : ep(ep) { Genode::env()->parent()->announce(ep.manage(nic_root)); } }; -/********************** - ** Server framework ** - **********************/ +/*************** + ** Component ** + ***************/ -namespace Server { - char const *name() { return "openvpn_ep"; } - Genode::size_t stack_size() { return 16*1024*sizeof(addr_t); } - void construct(Entrypoint &ep) { static Main server(ep); } +void Libc::Component::construct(Genode::Env &env) +{ + static Main server(env.ep()); } diff --git a/repos/ports/src/app/openvpn/target.mk b/repos/ports/src/app/openvpn/target.mk index 0a51cefda..b38cc8b7b 100644 --- a/repos/ports/src/app/openvpn/target.mk +++ b/repos/ports/src/app/openvpn/target.mk @@ -1,7 +1,7 @@ TARGET = openvpn LIBS += libc libc_pipe libc_lwip_nic_dhcp \ - libcrypto libssl config_args server + libcrypto libssl config_args OPENVPN_PORT_DIR := $(call select_from_ports,openvpn) OPENVPN_DIR := $(OPENVPN_PORT_DIR)/src/app/openvpn diff --git a/repos/ports/src/noux-pkg/gcc/target.inc b/repos/ports/src/noux-pkg/gcc/target.inc index dae99f9b7..a630990fb 100644 --- a/repos/ports/src/noux-pkg/gcc/target.inc +++ b/repos/ports/src/noux-pkg/gcc/target.inc @@ -51,7 +51,7 @@ libgmp.a libmpfr.a libmpc.a libc.a: Makefile: dummy_libs -LIBS += libc libm libc_noux stdcxx +LIBS += libc libm posix libc_noux stdcxx include $(REP_DIR)/mk/noux.mk diff --git a/repos/ports/src/noux/main.cc b/repos/ports/src/noux/main.cc index 045b54937..022bcfbde 100644 --- a/repos/ports/src/noux/main.cc +++ b/repos/ports/src/noux/main.cc @@ -31,6 +31,7 @@ #include #include #include +#include /* supported file systems */ #include @@ -1254,3 +1255,9 @@ void Component::construct(Genode::Env &env) log("--- exiting noux ---"); env.parent().exit(exit_value); } + + +/** + * Support for the noux/net version + */ +void Libc::Component::construct(Genode::Env &env) { Component::construct(env); } diff --git a/repos/ports/src/test/gdb_monitor/target.mk b/repos/ports/src/test/gdb_monitor/target.mk index 00b7e5909..1e976ab98 100644 --- a/repos/ports/src/test/gdb_monitor/target.mk +++ b/repos/ports/src/test/gdb_monitor/target.mk @@ -1,5 +1,5 @@ TARGET = test-gdb_monitor SRC_CC = main.cc -LIBS = libc +LIBS = posix CC_OLEVEL = -O0 diff --git a/repos/ports/src/test/libc_noux/target.mk b/repos/ports/src/test/libc_noux/target.mk index a707af66d..09ef4ee2e 100644 --- a/repos/ports/src/test/libc_noux/target.mk +++ b/repos/ports/src/test/libc_noux/target.mk @@ -1,5 +1,5 @@ TARGET = test-libc_noux -LIBS = libc libc_noux +LIBS = posix libc_noux SRC_CC = main.cc # we re-use the libc_ffat test diff --git a/repos/ports/src/test/noux_fork/target.mk b/repos/ports/src/test/noux_fork/target.mk index 9be39c1fa..bdef5a872 100644 --- a/repos/ports/src/test/noux_fork/target.mk +++ b/repos/ports/src/test/noux_fork/target.mk @@ -1,3 +1,3 @@ TARGET = test-noux_fork SRC_CC = test.cc -LIBS = libc libc_noux +LIBS = posix libc_noux diff --git a/repos/ports/src/test/noux_signals/target.mk b/repos/ports/src/test/noux_signals/target.mk index b2c69b574..3d88646da 100644 --- a/repos/ports/src/test/noux_signals/target.mk +++ b/repos/ports/src/test/noux_signals/target.mk @@ -1,3 +1,3 @@ TARGET = test-noux_signals SRC_CC = main.cc -LIBS = libc libc_noux +LIBS = posix libc_noux diff --git a/repos/ports/src/virtualbox/frontend/main.cc b/repos/ports/src/virtualbox/frontend/main.cc index ec3db6b24..04e391bc7 100644 --- a/repos/ports/src/virtualbox/frontend/main.cc +++ b/repos/ports/src/virtualbox/frontend/main.cc @@ -15,7 +15,7 @@ /* Genode includes */ #include -#include +#include #include /* Virtualbox includes */ @@ -207,7 +207,7 @@ Genode::Env &genode_env() } -void Component::construct(Genode::Env &env) +void Libc::Component::construct(Genode::Env &env) { /* make Genode environment accessible via the global 'genode_env()' */ genode_env_ptr = &env; diff --git a/repos/ports/src/virtualbox5/frontend/main.cc b/repos/ports/src/virtualbox5/frontend/main.cc index f7ebc4ff5..da0e2ac1d 100644 --- a/repos/ports/src/virtualbox5/frontend/main.cc +++ b/repos/ports/src/virtualbox5/frontend/main.cc @@ -15,7 +15,7 @@ /* Genode includes */ #include -#include +#include #include /* Virtualbox includes */ @@ -238,7 +238,7 @@ Genode::Env &genode_env() } -void Component::construct(Genode::Env &env) +void Libc::Component::construct(Genode::Env &env) { /* make Genode environment accessible via the global 'genode_env()' */ genode_env_ptr = &env;