From 0dcb526ae5ab092fd5659c16d5f460d092afeda8 Mon Sep 17 00:00:00 2001 From: Norman Feske Date: Tue, 17 Nov 2020 10:55:49 +0100 Subject: [PATCH] base-linux: coding style --- .../src/core/include/core_linux_syscalls.h | 2 +- .../src/core/include/dataspace_component.h | 211 ++++++------- .../core/include/io_mem_session_component.h | 89 +++--- .../base-linux/src/core/include/irq_object.h | 13 +- .../src/core/include/irq_session_component.h | 9 +- .../src/core/include/native_cpu_component.h | 2 +- .../src/core/include/native_pd_component.h | 3 +- repos/base-linux/src/core/include/pager.h | 66 +++-- repos/base-linux/src/core/include/platform.h | 185 ++++++------ .../base-linux/src/core/include/platform_pd.h | 3 +- .../src/core/include/platform_thread.h | 206 +++++++------ .../src/core/include/region_map_component.h | 6 +- .../src/core/native_pd_component.cc | 8 +- repos/base-linux/src/core/platform.cc | 4 +- .../core/spec/linux/dataspace_component.cc | 28 +- .../spec/linux/io_mem_session_component.cc | 42 +-- .../spec/linux/io_port_session_component.cc | 17 +- .../core/spec/linux/irq_session_component.cc | 96 +++--- .../src/core/spec/linux/platform_services.cc | 21 +- .../src/core/spec/pc/dataspace_component.cc | 20 +- .../core/spec/pc/io_mem_session_component.cc | 17 +- .../core/spec/pc/io_port_session_component.cc | 13 +- .../src/core/spec/pc/irq_session_component.cc | 70 +++-- .../src/core/spec/pc/platform_services.cc | 28 +- repos/base-linux/src/core/stack_area.cc | 18 +- .../include/base/internal/local_capability.h | 2 +- .../src/include/base/internal/local_parent.h | 1 - .../src/include/base/internal/native_thread.h | 1 + .../include/base/internal/region_map_mmap.h | 5 +- .../src/include/linux_dataspace/client.h | 40 +-- .../include/linux_dataspace/linux_dataspace.h | 60 ++-- .../src/include/linux_native_cpu/client.h | 1 + .../src/include/linux_native_pd/client.h | 1 + .../base-linux/src/lib/base/child_process.cc | 1 - repos/base-linux/src/lib/base/platform.cc | 32 +- .../src/lib/base/region_map_client.cc | 2 + .../base-linux/src/lib/lx_hybrid/lx_hybrid.cc | 277 +++++++++--------- .../src/lib/seccomp/seccomp_bpf_policy.h | 30 +- .../src/test/lx_hybrid_pthread_ipc/main.cc | 1 - 39 files changed, 832 insertions(+), 799 deletions(-) diff --git a/repos/base-linux/src/core/include/core_linux_syscalls.h b/repos/base-linux/src/core/include/core_linux_syscalls.h index 0dc3ba01db..d5fe2ffe94 100644 --- a/repos/base-linux/src/core/include/core_linux_syscalls.h +++ b/repos/base-linux/src/core/include/core_linux_syscalls.h @@ -79,6 +79,7 @@ inline int lx_iopl(int level) } #endif + /************************************************** ** Functions used by core's io mem session code ** **************************************************/ @@ -261,5 +262,4 @@ inline int lx_read(int fd, void *buf, Genode::size_t count) return lx_syscall(SYS_read, fd, buf, count); } - #endif /* _CORE__INCLUDE__CORE_LINUX_SYSCALLS_H_ */ diff --git a/repos/base-linux/src/core/include/dataspace_component.h b/repos/base-linux/src/core/include/dataspace_component.h index dba193a67f..7da61ae367 100644 --- a/repos/base-linux/src/core/include/dataspace_component.h +++ b/repos/base-linux/src/core/include/dataspace_component.h @@ -28,107 +28,116 @@ #include namespace Genode { - - /** - * Deriving classes can own a dataspace to implement conditional behavior - */ - class Dataspace_owner : Interface { }; - - class Dataspace_component : public Rpc_object - { - private: - - Filename _fname { }; /* filename for mmap */ - size_t const _size; /* size of dataspace in bytes */ - addr_t const _addr; /* meaningless on linux */ - Native_capability _cap; /* capability / file descriptor */ - bool const _writable; /* false if read-only */ - - /* Holds the dataspace owner if a distinction between owner and - * others is necessary on the dataspace, otherwise it is 0 */ - Dataspace_owner const * const _owner; - - static Filename _file_name(const char *args); - size_t _file_size(); - - /* - * Noncopyable - */ - Dataspace_component(Dataspace_component const &); - Dataspace_component &operator = (Dataspace_component const &); - - static Native_capability _fd_to_cap(int const fd) - { - return Capability_space::import(Rpc_destination(Lx_sd{fd}), Rpc_obj_key()); - } - - public: - - /** - * Constructor - */ - Dataspace_component(size_t size, addr_t addr, - Cache_attribute, bool writable, - Dataspace_owner * owner) - : _size(size), _addr(addr), _cap(), _writable(writable), - _owner(owner) { } - - /** - * Default constructor returns invalid dataspace - */ - Dataspace_component() - : _size(0), _addr(0), _cap(), _writable(false), _owner(nullptr) { } - - /** - * This constructor is only provided for compatibility - * reasons and should not be used. - */ - Dataspace_component(size_t size, addr_t, addr_t phys_addr, - Cache_attribute, bool writable, Dataspace_owner *_owner); - - /** - * This constructor is especially used for ROM dataspaces - * - * \param args session parameters containing 'filename' key/value - */ - Dataspace_component(const char *args); - - /** - * Assign file descriptor to dataspace - * - * The file descriptor assigned to the dataspace will be enable - * processes outside of core to mmap the dataspace. - */ - void fd(int fd) { _cap = _fd_to_cap(fd); } - - /** - * Check if dataspace is owned by a specified object - */ - bool owner(Dataspace_owner const &o) const { return _owner == &o; } - - /** - * Detach dataspace from all rm sessions. - */ - void detach_from_rm_sessions() { } - - - /************************* - ** Dataspace interface ** - *************************/ - - size_t size() override { return _size; } - addr_t phys_addr() override { return _addr; } - bool writable() override { return _writable; } - - - /**************************************** - ** Linux-specific dataspace interface ** - ****************************************/ - - Filename fname() override { return _fname; } - - Untyped_capability fd() override { return _cap; } - }; + class Dataspace_owner; + class Dataspace_component; } + +/** + * Deriving classes can own a dataspace to implement conditional behavior + */ +class Genode::Dataspace_owner : Interface { }; + + +class Genode::Dataspace_component : public Rpc_object +{ + private: + + Filename _fname { }; /* filename for mmap */ + size_t const _size; /* size of dataspace in bytes */ + addr_t const _addr; /* meaningless on linux */ + Native_capability _cap; /* capability / file descriptor */ + bool const _writable; /* false if read-only */ + + /* + * Holds the dataspace owner if a distinction between owner and + * others is necessary on the dataspace, otherwise it is 0 + */ + Dataspace_owner const * const _owner; + + static Filename _file_name(const char *args); + size_t _file_size(); + + /* + * Noncopyable + */ + Dataspace_component(Dataspace_component const &); + Dataspace_component &operator = (Dataspace_component const &); + + static Native_capability _fd_to_cap(int const fd) + { + return Capability_space::import(Rpc_destination(Lx_sd{fd}), Rpc_obj_key()); + } + + public: + + /** + * Constructor + */ + Dataspace_component(size_t size, addr_t addr, + Cache_attribute, bool writable, + Dataspace_owner * owner) + : + _size(size), _addr(addr), _cap(), _writable(writable), _owner(owner) + { } + + /** + * Default constructor creates invalid dataspace + */ + Dataspace_component() + : + _size(0), _addr(0), _cap(), _writable(false), _owner(nullptr) + { } + + /** + * This constructor is only provided for compatibility + * reasons and should not be used. + */ + Dataspace_component(size_t size, addr_t, addr_t phys_addr, + Cache_attribute, bool writable, Dataspace_owner *_owner); + + /** + * This constructor is especially used for ROM dataspaces + * + * \param args session parameters containing 'filename' key/value + */ + Dataspace_component(const char *args); + + /** + * Assign file descriptor to dataspace + * + * The file descriptor assigned to the dataspace will be enable + * processes outside of core to mmap the dataspace. + */ + void fd(int fd) { _cap = _fd_to_cap(fd); } + + /** + * Check if dataspace is owned by a specified object + */ + bool owner(Dataspace_owner const &o) const { return _owner == &o; } + + /** + * Detach dataspace from all rm sessions. + */ + void detach_from_rm_sessions() { } + + + /************************* + ** Dataspace interface ** + *************************/ + + size_t size() override { return _size; } + addr_t phys_addr() override { return _addr; } + bool writable() override { return _writable; } + + + /**************************************** + ** Linux-specific dataspace interface ** + ****************************************/ + + Filename fname() override { return _fname; } + + Untyped_capability fd() override { return _cap; } +}; + #endif /* _CORE__INCLUDE__DATASPACE_COMPONENT_H_ */ diff --git a/repos/base-linux/src/core/include/io_mem_session_component.h b/repos/base-linux/src/core/include/io_mem_session_component.h index ea011de8d3..9a37b70440 100644 --- a/repos/base-linux/src/core/include/io_mem_session_component.h +++ b/repos/base-linux/src/core/include/io_mem_session_component.h @@ -22,53 +22,52 @@ /* core includes */ #include -namespace Genode { - - class Io_mem_session_component : public Rpc_object - { - - private: - - Range_allocator &_io_mem_alloc; - Dataspace_component _ds; - Rpc_entrypoint &_ds_ep; - Io_mem_dataspace_capability _ds_cap; - - size_t get_arg_size(const char *); - addr_t get_arg_phys(const char *); - Cache_attribute get_arg_wc(const char *); - - public: - - /** - * Constructor - * - * \param io_mem_alloc MMIO region allocator - * \param ram_alloc RAM allocator that will be checked for - * region collisions - * \param ds_ep entry point to manage the dataspace - * corresponding the io_mem session - * \param args session construction arguments, in - * particular MMIO region base, size and - * caching demands - */ - Io_mem_session_component(Range_allocator &io_mem_alloc, - Range_allocator &ram_alloc, - Rpc_entrypoint &ds_ep, - const char *args); - - /** - * Destructor - */ - ~Io_mem_session_component() { } +namespace Genode { class Io_mem_session_component; } - /***************************** - ** Io-mem session interface ** - *****************************/ +class Genode::Io_mem_session_component : public Rpc_object +{ + private: - Io_mem_dataspace_capability dataspace() override; - }; -} + Range_allocator &_io_mem_alloc; + Dataspace_component _ds; + Rpc_entrypoint &_ds_ep; + Io_mem_dataspace_capability _ds_cap; + + size_t get_arg_size(const char *); + addr_t get_arg_phys(const char *); + Cache_attribute get_arg_wc(const char *); + + public: + + /** + * Constructor + * + * \param io_mem_alloc MMIO region allocator + * \param ram_alloc RAM allocator that will be checked for + * region collisions + * \param ds_ep entry point to manage the dataspace + * corresponding the io_mem session + * \param args session construction arguments, in + * particular MMIO region base, size and + * caching demands + */ + Io_mem_session_component(Range_allocator &io_mem_alloc, + Range_allocator &ram_alloc, + Rpc_entrypoint &ds_ep, + const char *args); + + /** + * Destructor + */ + ~Io_mem_session_component() { } + + + /***************************** + ** Io-mem session interface ** + *****************************/ + + Io_mem_dataspace_capability dataspace() override; +}; #endif /* _CORE__INCLUDE__IO_MEM_SESSION_COMPONENT_H_ */ diff --git a/repos/base-linux/src/core/include/irq_object.h b/repos/base-linux/src/core/include/irq_object.h index d50a49d415..8d8d436a64 100644 --- a/repos/base-linux/src/core/include/irq_object.h +++ b/repos/base-linux/src/core/include/irq_object.h @@ -16,19 +16,16 @@ #include -namespace Genode -{ - class Irq_object; -}; +namespace Genode { class Irq_object; }; + class Genode::Irq_object : public Thread_deprecated<4096> { - private: - Genode::Signal_context_capability _sig_cap; - Genode::Blockade _sync_ack { }; - Genode::Blockade _sync_bootup { }; + Signal_context_capability _sig_cap; + Blockade _sync_ack { }; + Blockade _sync_bootup { }; unsigned const _irq; int _fd; diff --git a/repos/base-linux/src/core/include/irq_session_component.h b/repos/base-linux/src/core/include/irq_session_component.h index 1a56cc967c..cb28ef0ff4 100644 --- a/repos/base-linux/src/core/include/irq_session_component.h +++ b/repos/base-linux/src/core/include/irq_session_component.h @@ -20,9 +20,8 @@ #include #include -namespace Genode { - class Irq_session_component; -} +namespace Genode { class Irq_session_component; } + class Genode::Irq_session_component : public Rpc_object, private List::Element @@ -30,8 +29,10 @@ class Genode::Irq_session_component : public Rpc_object, private: friend class List; + unsigned _irq_number; - Genode::Irq_object _irq_object; + + Irq_object _irq_object; public: diff --git a/repos/base-linux/src/core/include/native_cpu_component.h b/repos/base-linux/src/core/include/native_cpu_component.h index 63e0fd0756..569a8fdf7f 100644 --- a/repos/base-linux/src/core/include/native_cpu_component.h +++ b/repos/base-linux/src/core/include/native_cpu_component.h @@ -20,7 +20,6 @@ #include namespace Genode { - class Cpu_session_component; class Native_cpu_component; } @@ -37,6 +36,7 @@ class Genode::Native_cpu_component : public Rpc_object namespace Genode { - class Dataspace_component; class Pd_session_component; class Native_pd_component; @@ -26,7 +25,7 @@ namespace Genode { class Genode::Native_pd_component : public Rpc_object + Native_pd_component> { private: diff --git a/repos/base-linux/src/core/include/pager.h b/repos/base-linux/src/core/include/pager.h index e0ebfea0f6..c58d8a0bdd 100644 --- a/repos/base-linux/src/core/include/pager.h +++ b/repos/base-linux/src/core/include/pager.h @@ -3,8 +3,6 @@ * \author Norman Feske * \author Christian Helmuth * \date 2006-04-28 - * - * Linux dummies */ /* @@ -26,36 +24,40 @@ #include namespace Genode { - - struct Pager_object - { - Thread_capability _thread_cap { }; - Signal_context_capability _sigh { }; - - virtual ~Pager_object() { } - - void exception_handler(Signal_context_capability sigh) { _sigh = sigh; } - - /** - * Remember thread cap so that rm_session can tell thread that - * rm_client is gone. - */ - Thread_capability thread_cap() const { return _thread_cap; } - void thread_cap(Thread_capability cap) { _thread_cap = cap; } - }; - - struct Pager_entrypoint - { - Pager_entrypoint(Rpc_cap_factory &) { } - - template - auto apply(Pager_capability, FUNC f) -> decltype(f(nullptr)) { - return f(nullptr); } - - Pager_capability manage(Pager_object &) { return Pager_capability(); } - - void dissolve(Pager_object &) { } - }; + struct Pager_object; + struct Pager_entrypoint; } + +struct Genode::Pager_object +{ + Thread_capability _thread_cap { }; + Signal_context_capability _sigh { }; + + virtual ~Pager_object() { } + + void exception_handler(Signal_context_capability sigh) { _sigh = sigh; } + + /** + * Remember thread cap so that rm_session can tell thread that + * rm_client is gone. + */ + Thread_capability thread_cap() const { return _thread_cap; } + void thread_cap(Thread_capability cap) { _thread_cap = cap; } +}; + + +struct Genode::Pager_entrypoint +{ + Pager_entrypoint(Rpc_cap_factory &) { } + + template + auto apply(Pager_capability, FUNC f) -> decltype(f(nullptr)) { + return f(nullptr); } + + Pager_capability manage(Pager_object &) { return Pager_capability(); } + + void dissolve(Pager_object &) { } +}; + #endif /* _CORE__INCLUDE__PAGER_H_ */ diff --git a/repos/base-linux/src/core/include/platform.h b/repos/base-linux/src/core/include/platform.h index 8f4119afbd..7368b88700 100644 --- a/repos/base-linux/src/core/include/platform.h +++ b/repos/base-linux/src/core/include/platform.h @@ -15,16 +15,17 @@ #ifndef _CORE__INCLUDE__PLATFORM_H_ #define _CORE__INCLUDE__PLATFORM_H_ +/* Genode includes */ #include -#include +#include +/* core-local includes */ #include #include #include #include #include -#include /** * List of Unix environment variables, initialized by the startup code @@ -37,9 +38,11 @@ extern char **lx_environ; */ static unsigned long ram_quota_from_env() { + using namespace Genode; + for (char **curr = lx_environ; curr && *curr; curr++) { - Genode::Arg arg = Genode::Arg_string::find_arg(*curr, "GENODE_RAM_QUOTA"); + Arg arg = Arg_string::find_arg(*curr, "GENODE_RAM_QUOTA"); if (arg.valid()) return arg.ulong_value(~0); } @@ -47,113 +50,109 @@ static unsigned long ram_quota_from_env() return ~0; } -namespace Genode { - using namespace Genode; +class Genode::Platform : public Platform_generic +{ + private: - class Platform : public Platform_generic - { - private: + /** + * Allocator for core-internal meta data + */ + Synced_range_allocator _core_mem_alloc; - /** - * Allocator for core-internal meta data - */ - Synced_range_allocator _core_mem_alloc; + Rom_fs _dummy_rom_fs { }; - Rom_fs _dummy_rom_fs { }; + struct Dummy_allocator : Range_allocator + { + void free(void *, size_t) override { ASSERT_NEVER_CALLED; } + bool need_size_for_free() const override { ASSERT_NEVER_CALLED; } + size_t consumed() const override { ASSERT_NEVER_CALLED; } + size_t overhead(size_t) const override { ASSERT_NEVER_CALLED; } + int add_range (addr_t, size_t ) override { ASSERT_NEVER_CALLED; } + int remove_range(addr_t, size_t ) override { ASSERT_NEVER_CALLED; } + void free(void *) override { ASSERT_NEVER_CALLED; } + size_t avail() const override { ASSERT_NEVER_CALLED; } + bool valid_addr(addr_t ) const override { ASSERT_NEVER_CALLED; } + bool alloc(size_t, void **) override { ASSERT_NEVER_CALLED; } - struct Dummy_allocator : Range_allocator + Alloc_return alloc_aligned(size_t, void **, int, addr_t, addr_t) override + { ASSERT_NEVER_CALLED; } + + Alloc_return alloc_addr(size_t, addr_t) override + { ASSERT_NEVER_CALLED; } + + } _dummy_alloc { }; + + /** + * Allocator for pseudo physical memory + */ + struct Pseudo_ram_allocator : Range_allocator + { + bool alloc(size_t, void **out_addr) override { - void free(void *, size_t) override { ASSERT_NEVER_CALLED; } - bool need_size_for_free() const override { ASSERT_NEVER_CALLED; } - size_t consumed() const override { ASSERT_NEVER_CALLED; } - size_t overhead(size_t) const override { ASSERT_NEVER_CALLED; } - int add_range (addr_t, size_t ) override { ASSERT_NEVER_CALLED; } - int remove_range(addr_t, size_t ) override { ASSERT_NEVER_CALLED; } - void free(void *) override { ASSERT_NEVER_CALLED; } - size_t avail() const override { ASSERT_NEVER_CALLED; } - bool valid_addr(addr_t ) const override { ASSERT_NEVER_CALLED; } - bool alloc(size_t, void **) override { ASSERT_NEVER_CALLED; } + *out_addr = 0; + return true; + } - Alloc_return alloc_aligned(size_t, void **, int, addr_t, addr_t) override - { ASSERT_NEVER_CALLED; } - - Alloc_return alloc_addr(size_t, addr_t) override - { ASSERT_NEVER_CALLED; } - - } _dummy_alloc { }; - - /** - * Allocator for pseudo physical memory - */ - struct Pseudo_ram_allocator : Range_allocator + Alloc_return alloc_aligned(size_t, void **out_addr, int, + addr_t, addr_t) override { - bool alloc(size_t, void **out_addr) override - { - *out_addr = 0; - return true; - } + *out_addr = 0; + return Alloc_return::OK; + } - Alloc_return alloc_aligned(size_t, void **out_addr, int, - addr_t, addr_t) override - { - *out_addr = 0; - return Alloc_return::OK; - } + Alloc_return alloc_addr(size_t, addr_t) override + { + return Alloc_return::OK; + } - Alloc_return alloc_addr(size_t, addr_t) override - { - return Alloc_return::OK; - } + int add_range(addr_t, size_t) override { return 0; } + int remove_range(addr_t, size_t) override { return 0; } + void free(void *) override { } + void free(void *, size_t) override { } + size_t avail() const override { return ram_quota_from_env(); } + bool valid_addr(addr_t) const override { return true; } + size_t overhead(size_t) const override { return 0; } + bool need_size_for_free() const override { return true; } - int add_range(addr_t, size_t) override { return 0; } - int remove_range(addr_t, size_t) override { return 0; } - void free(void *) override { } - void free(void *, size_t) override { } - size_t avail() const override { return ram_quota_from_env(); } - bool valid_addr(addr_t) const override { return true; } - size_t overhead(size_t) const override { return 0; } - bool need_size_for_free() const override { return true; } + } _ram_alloc { }; - } _ram_alloc { }; + public: - public: - - /** - * Constructor - */ - Platform(); + /** + * Constructor + */ + Platform(); - /******************************** - ** Generic platform interface ** - ********************************/ + /******************************** + ** Generic platform interface ** + ********************************/ - Range_allocator &core_mem_alloc() override { return _core_mem_alloc; } - Range_allocator &ram_alloc() override { return _ram_alloc; } - Range_allocator &io_mem_alloc() override { return _dummy_alloc; } - Range_allocator &io_port_alloc() override { return _dummy_alloc; } - Range_allocator &irq_alloc() override { return _dummy_alloc; } - Range_allocator ®ion_alloc() override { return _dummy_alloc; } - addr_t vm_start() const override { return 0; } - size_t vm_size() const override { return 0; } - Rom_fs &rom_fs() override { return _dummy_rom_fs; } + Range_allocator &core_mem_alloc() override { return _core_mem_alloc; } + Range_allocator &ram_alloc() override { return _ram_alloc; } + Range_allocator &io_mem_alloc() override { return _dummy_alloc; } + Range_allocator &io_port_alloc() override { return _dummy_alloc; } + Range_allocator &irq_alloc() override { return _dummy_alloc; } + Range_allocator ®ion_alloc() override { return _dummy_alloc; } + addr_t vm_start() const override { return 0; } + size_t vm_size() const override { return 0; } + Rom_fs &rom_fs() override { return _dummy_rom_fs; } - /* - * On Linux, the maximum number of capabilities is primarily - * constrained by the limited number of file descriptors within - * core. Each dataspace and and each thread consumes one - * descriptor. However, all capabilies managed by the same - * entrypoint share the same file descriptor such that the fd - * limit would be an overly pessimistic upper bound. - * - * Hence, we define the limit somewhat arbitrary on Linux and - * accept that scenarios may break when reaching core's fd limit. - */ - size_t max_caps() const override { return 10000; } + /* + * On Linux, the maximum number of capabilities is primarily + * constrained by the limited number of file descriptors within + * core. Each dataspace and and each thread consumes one + * descriptor. However, all capabilies managed by the same + * entrypoint share the same file descriptor such that the fd + * limit would be an overly pessimistic upper bound. + * + * Hence, we define the limit somewhat arbitrary on Linux and + * accept that scenarios may break when reaching core's fd limit. + */ + size_t max_caps() const override { return 10000; } - void wait_for_exit() override; - }; -} + void wait_for_exit() override; +}; #endif /* _CORE__INCLUDE__PLATFORM_H_ */ diff --git a/repos/base-linux/src/core/include/platform_pd.h b/repos/base-linux/src/core/include/platform_pd.h index f61930afdd..6e69925082 100644 --- a/repos/base-linux/src/core/include/platform_pd.h +++ b/repos/base-linux/src/core/include/platform_pd.h @@ -2,8 +2,6 @@ * \brief Linux protection domain facility * \author Norman Feske * \date 2006-06-13 - * - * Pretty dumb. */ /* @@ -24,6 +22,7 @@ namespace Genode { struct Platform_thread; } + struct Genode::Platform_pd { Platform_pd(Allocator &, char const *) { } diff --git a/repos/base-linux/src/core/include/platform_thread.h b/repos/base-linux/src/core/include/platform_thread.h index 40e3600479..4264b1685d 100644 --- a/repos/base-linux/src/core/include/platform_thread.h +++ b/repos/base-linux/src/core/include/platform_thread.h @@ -2,8 +2,6 @@ * \brief Linux thread facility * \author Norman Feske * \date 2006-06-13 - * - * Pretty dumb. */ /* @@ -25,135 +23,133 @@ /* core includes */ #include -namespace Genode { +namespace Genode { class Platform_thread; } - class Platform_thread; - /* - * We hold all Platform_thread objects in a list in order to be able to - * reflect SIGCHLD as exception signals. When a SIGCHILD occurs, we - * determine the PID of the terminated child process via 'wait4'. We use - * the list to find the 'Platform_thread' matching the TID, wherei, in - * turn, we find the exception handler's 'Signal_context_capability'. - */ +/* + * We hold all Platform_thread objects in a list in order to be able to + * reflect SIGCHLD as exception signals. When a SIGCHILD occurs, we + * determine the PID of the terminated child process via 'wait4'. We use + * the list to find the 'Platform_thread' matching the TID, wherei, in + * turn, we find the exception handler's 'Signal_context_capability'. + */ - class Platform_thread : public List::Element - { - private: +class Genode::Platform_thread : public List::Element +{ + private: - struct Registry - { - Mutex _mutex { }; - List _list { }; + struct Registry + { + Mutex _mutex { }; + List _list { }; - void insert(Platform_thread *thread); - void remove(Platform_thread *thread); - - /** - * Trigger exception handler for 'Platform_thread' with matching PID. - */ - void submit_exception(unsigned long pid); - }; + void insert(Platform_thread *thread); + void remove(Platform_thread *thread); /** - * Return singleton instance of 'Platform_thread::Registry' + * Trigger exception handler for 'Platform_thread' with matching PID. */ - static Registry &_registry(); + void submit_exception(unsigned long pid); + }; - unsigned long _tid = -1; - unsigned long _pid = -1; - char _name[32] { }; + /** + * Return singleton instance of 'Platform_thread::Registry' + */ + static Registry &_registry(); - /* - * Dummy pager object that is solely used for storing the - * 'Signal_context_capability' for the thread's exception handler. - */ - Pager_object _pager { }; + unsigned long _tid = -1; + unsigned long _pid = -1; + char _name[32] { }; - public: + /* + * Dummy pager object that is solely used for storing the + * 'Signal_context_capability' for the thread's exception handler. + */ + Pager_object _pager { }; - /** - * Constructor - */ - Platform_thread(size_t, const char *name, unsigned priority, - Affinity::Location, addr_t); + public: - ~Platform_thread(); + /** + * Constructor + */ + Platform_thread(size_t, const char *name, unsigned priority, + Affinity::Location, addr_t); - /** - * Pause this thread - */ - void pause(); + ~Platform_thread(); - /** - * Enable/disable single stepping - */ - void single_step(bool) { } + /** + * Pause this thread + */ + void pause(); - /** - * Resume this thread - */ - void resume(); + /** + * Enable/disable single stepping + */ + void single_step(bool) { } - /** - * Dummy implementation of platform-thread interface - */ - Pager_object &pager() { return _pager; } - void pager(Pager_object &) { } - int start(void *, void *) { return 0; } + /** + * Resume this thread + */ + void resume(); - Thread_state state() - { - warning("Not implemented"); - throw Cpu_thread::State_access_failed(); - } + /** + * Dummy implementation of platform-thread interface + */ + Pager_object &pager() { return _pager; } + void pager(Pager_object &) { } + int start(void *, void *) { return 0; } - void state(Thread_state) - { - warning("Not implemented"); - throw Cpu_thread::State_access_failed(); - } + Thread_state state() + { + warning("Not implemented"); + throw Cpu_thread::State_access_failed(); + } - const char *name() { return _name; } + void state(Thread_state) + { + warning("Not implemented"); + throw Cpu_thread::State_access_failed(); + } - /** - * Set the executing CPU for this thread - * - * SMP is currently not directly supported on Genode/Linux - * (but indirectly by the Linux kernel). - */ - void affinity(Affinity::Location) { } + const char *name() { return _name; } - /** - * Request the affinity of this thread - */ - Affinity::Location affinity() const { return Affinity::Location(); } + /** + * Set the executing CPU for this thread + * + * SMP is currently not directly supported on Genode/Linux + * (but indirectly by the Linux kernel). + */ + void affinity(Affinity::Location) { } - /** - * Register process ID and thread ID of thread - */ - void thread_id(int pid, int tid) { _pid = pid, _tid = tid; } + /** + * Request the affinity of this thread + */ + Affinity::Location affinity() const { return Affinity::Location(); } - /** - * Notify Genode::Signal handler about sigchld - */ - static void submit_exception(int pid) - { - _registry().submit_exception(pid); - } + /** + * Register process ID and thread ID of thread + */ + void thread_id(int pid, int tid) { _pid = pid, _tid = tid; } - /** - * Set CPU quota of the thread to 'quota' - */ - void quota(size_t const) { /* not supported*/ } + /** + * Notify Genode::Signal handler about sigchld + */ + static void submit_exception(int pid) + { + _registry().submit_exception(pid); + } - /** - * Return execution time consumed by the thread - */ - Trace::Execution_time execution_time() const { return { 0, 0 }; } + /** + * Set CPU quota of the thread to 'quota' + */ + void quota(size_t const) { /* not supported*/ } - unsigned long pager_object_badge() const { return 0; } - }; -} + /** + * Return execution time consumed by the thread + */ + Trace::Execution_time execution_time() const { return { 0, 0 }; } + + unsigned long pager_object_badge() const { return 0; } +}; #endif /* _CORE__INCLUDE__PLATFORM_THREAD_H_ */ diff --git a/repos/base-linux/src/core/include/region_map_component.h b/repos/base-linux/src/core/include/region_map_component.h index efdedd90d0..9b9c318d82 100644 --- a/repos/base-linux/src/core/include/region_map_component.h +++ b/repos/base-linux/src/core/include/region_map_component.h @@ -2,8 +2,6 @@ * \brief Core-specific instance of the region-map interface * \author Christian Helmuth * \date 2006-07-17 - * - * Dummies for Linux platform */ /* @@ -75,8 +73,8 @@ struct Genode::Rm_client : Pager_object { Rm_client(Cpu_session_capability, Thread_capability, Region_map_component &, unsigned long, - Affinity::Location, Cpu_session::Name const&, - Session_label const&) + Affinity::Location, Cpu_session::Name const &, + Session_label const &) { } }; diff --git a/repos/base-linux/src/core/native_pd_component.cc b/repos/base-linux/src/core/native_pd_component.cc index 76b3371835..41f4dd6782 100644 --- a/repos/base-linux/src/core/native_pd_component.cc +++ b/repos/base-linux/src/core/native_pd_component.cc @@ -39,10 +39,10 @@ using namespace Genode; */ struct Execve_args { - char const *filename; - char * const *argv; - char * const *envp; - Lx_sd const parent_sd; + char const *filename; + char * const *argv; + char * const *envp; + Lx_sd const parent_sd; Execve_args(char const *filename, char * const *argv, diff --git a/repos/base-linux/src/core/platform.cc b/repos/base-linux/src/core/platform.cc index 0a7ca8ecfb..209962432e 100644 --- a/repos/base-linux/src/core/platform.cc +++ b/repos/base-linux/src/core/platform.cc @@ -27,7 +27,6 @@ /* Linux includes */ #include - using namespace Genode; @@ -88,7 +87,8 @@ static void sigchld_handler(int) Platform::Platform() -: _core_mem_alloc(nullptr) +: + _core_mem_alloc(nullptr) { /* make 'mmap' behave deterministically */ lx_disable_aslr(); diff --git a/repos/base-linux/src/core/spec/linux/dataspace_component.cc b/repos/base-linux/src/core/spec/linux/dataspace_component.cc index ad5c5c2929..72654cf02c 100644 --- a/repos/base-linux/src/core/spec/linux/dataspace_component.cc +++ b/repos/base-linux/src/core/spec/linux/dataspace_component.cc @@ -38,7 +38,7 @@ Linux_dataspace::Filename Dataspace_component::_file_name(const char *args) Linux_dataspace::Filename fname; if (label.last_element().length() > sizeof(fname.buf)) { - Genode::error("file name too long: ", label.last_element()); + error("file name too long: ", label.last_element()); throw Service_denied(); } @@ -52,7 +52,7 @@ Linux_dataspace::Filename Dataspace_component::_file_name(const char *args) } -Genode::size_t Dataspace_component::_file_size() +size_t Dataspace_component::_file_size() { struct stat64 s; if (lx_stat(_fname.buf, &s) < 0) throw Service_denied(); @@ -62,17 +62,21 @@ Genode::size_t Dataspace_component::_file_size() Dataspace_component::Dataspace_component(const char *args) -: _fname(_file_name(args)), - _size(_file_size()), - _addr(0), - _cap(_fd_to_cap(lx_open(_fname.buf, O_RDONLY | LX_O_CLOEXEC, S_IRUSR | S_IXUSR))), - _writable(false), - _owner(0) { } +: + _fname(_file_name(args)), + _size(_file_size()), + _addr(0), + _cap(_fd_to_cap(lx_open(_fname.buf, O_RDONLY | LX_O_CLOEXEC, S_IRUSR | S_IXUSR))), + _writable(false), + _owner(0) +{ } + Dataspace_component::Dataspace_component(size_t size, addr_t, addr_t phys_addr, - Cache_attribute, bool, Dataspace_owner *_owner) : - _size(size), _addr(phys_addr), _cap(), _writable(false), _owner(_owner) + Cache_attribute, bool, Dataspace_owner *_owner) +: + _size(size), _addr(phys_addr), _cap(), _writable(false), _owner(_owner) { - warning("Should only be used for IOMEM and not within Linux."); - _fname.buf[0] = 0; + warning("Should only be used for IOMEM and not within Linux."); + _fname.buf[0] = 0; } diff --git a/repos/base-linux/src/core/spec/linux/io_mem_session_component.cc b/repos/base-linux/src/core/spec/linux/io_mem_session_component.cc index e2f7c7bc83..d871cc0db8 100644 --- a/repos/base-linux/src/core/spec/linux/io_mem_session_component.cc +++ b/repos/base-linux/src/core/spec/linux/io_mem_session_component.cc @@ -11,48 +11,56 @@ * under the terms of the GNU Affero General Public License version 3. */ +/* Genode includes */ #include #include -#include - -#include - #include +/* base-internal includes */ +#include + +/* core-local includes */ +#include using namespace Genode; + size_t Io_mem_session_component::get_arg_size(const char *) { - warning(__func__, " not implemented"); - return 0; + warning(__func__, " not implemented"); + return 0; } addr_t Io_mem_session_component::get_arg_phys(const char *) { - warning(__func__, " not implemented"); - return 0; + warning(__func__, " not implemented"); + return 0; } + Io_mem_session_component::Io_mem_session_component(Range_allocator &io_mem_alloc, Range_allocator &, Rpc_entrypoint &ds_ep, - const char *args) : - _io_mem_alloc(io_mem_alloc), - _ds(0, 0, 0, UNCACHED, true, 0), - _ds_ep(ds_ep), - _ds_cap(Io_mem_dataspace_capability()) + const char *args) +: + _io_mem_alloc(io_mem_alloc), + _ds(0, 0, 0, UNCACHED, true, 0), + _ds_ep(ds_ep), + _ds_cap(Io_mem_dataspace_capability()) { - warning("no io_mem support on Linux (args=\"", args, "\")"); } + warning("no io_mem support on Linux (args=\"", args, "\")"); +} + Cache_attribute Io_mem_session_component::get_arg_wc(const char *) { - warning(__func__, " not implemented"); - return UNCACHED; + warning(__func__, " not implemented"); + return UNCACHED; } + Io_mem_dataspace_capability Io_mem_session_component::dataspace() { - return Io_mem_dataspace_capability(); + return Io_mem_dataspace_capability(); } diff --git a/repos/base-linux/src/core/spec/linux/io_port_session_component.cc b/repos/base-linux/src/core/spec/linux/io_port_session_component.cc index 41ea036da0..25bc3ba57e 100644 --- a/repos/base-linux/src/core/spec/linux/io_port_session_component.cc +++ b/repos/base-linux/src/core/spec/linux/io_port_session_component.cc @@ -11,17 +11,18 @@ * under the terms of the GNU Affero General Public License version 3. */ -#include -#include -#include #include +using namespace Genode; -Genode::Io_port_session_component::Io_port_session_component(Genode::Range_allocator &io_port_alloc, const char *) -: _io_port_alloc(io_port_alloc) + +Io_port_session_component::Io_port_session_component(Range_allocator &io_port_alloc, + const char *) +: + _io_port_alloc(io_port_alloc) { - Genode::warning("IO PORTS are not supported on base linux"); + warning("I/O port access is not supported on base linux"); } -Genode::Io_port_session_component::~Io_port_session_component() -{} + +Io_port_session_component::~Io_port_session_component() { } diff --git a/repos/base-linux/src/core/spec/linux/irq_session_component.cc b/repos/base-linux/src/core/spec/linux/irq_session_component.cc index 20b6532000..57e5c8ec19 100644 --- a/repos/base-linux/src/core/spec/linux/irq_session_component.cc +++ b/repos/base-linux/src/core/spec/linux/irq_session_component.cc @@ -1,7 +1,7 @@ /* - * \brief IRQ session implementation for base-linux + * \brief IRQ session implementation for base-linux * \author Johannes Kliemann - * \date 2018-03-14 + * \date 2018-03-14 * */ @@ -13,68 +13,76 @@ * under the terms of the GNU Affero General Public License version 3. */ +/* Genode includes */ #include #include - #include +/* core-local includes */ #include -Genode::Irq_session_component::Irq_session_component(Genode::Range_allocator &, const char *) +using namespace Genode; + + +Irq_session_component::Irq_session_component(Range_allocator &, const char *) : - _irq_number(0), - _irq_object(_irq_number) + _irq_number(0), _irq_object(_irq_number) { } -Genode::Irq_session_component::~Irq_session_component() + +Irq_session_component::~Irq_session_component() { warning(__func__, " not implemented"); } -void Genode::Irq_session_component::ack_irq() -{ } -void Genode::Irq_session_component::sigh(Genode::Signal_context_capability) -{ } +void Irq_session_component::ack_irq() { } -Genode::Irq_session::Info Genode::Irq_session_component::info() + +void Irq_session_component::sigh(Signal_context_capability) { } + + +Irq_session::Info Irq_session_component::info() { - return { .type = Genode::Irq_session::Info::Type::INVALID, .address = 0, .value = 0 }; + return { .type = Irq_session::Info::Type::INVALID, .address = 0, .value = 0 }; } -Genode::Irq_object::Irq_object(unsigned irq) : + +Irq_object::Irq_object(unsigned irq) +: Thread_deprecated<4096>("irq"), - _sig_cap(Signal_context_capability()), - _irq(irq), - _fd(-1) + _sig_cap(Signal_context_capability()), _irq(irq), _fd(-1) { - Genode::warning(__func__, " not implemented"); -} - -bool Genode::Irq_object::_associate() -{ - Genode::warning(__func__, " not implemented"); - return false; -} - -void Genode::Irq_object::entry() -{ - Genode::warning(__func__, " not implemented"); -} - -void Genode::Irq_object::ack_irq() -{ - Genode::warning(__func__, " not implemented"); -} - -void Genode::Irq_object::start() -{ - Genode::warning(__func__, " not implemented"); -} - -void Genode::Irq_object::sigh(Signal_context_capability) -{ - Genode::warning(__func__, " not implemented"); + warning(__func__, " not implemented"); } +bool Irq_object::_associate() +{ + warning(__func__, " not implemented"); + return false; +} + + +void Irq_object::entry() +{ + warning(__func__, " not implemented"); +} + + +void Irq_object::ack_irq() +{ + warning(__func__, " not implemented"); +} + + +void Irq_object::start() +{ + warning(__func__, " not implemented"); +} + + +void Irq_object::sigh(Signal_context_capability) +{ + warning(__func__, " not implemented"); +} diff --git a/repos/base-linux/src/core/spec/linux/platform_services.cc b/repos/base-linux/src/core/spec/linux/platform_services.cc index f3524d2846..4d579c89d4 100644 --- a/repos/base-linux/src/core/spec/linux/platform_services.cc +++ b/repos/base-linux/src/core/spec/linux/platform_services.cc @@ -16,22 +16,11 @@ #include /* core includes */ -#include -#include #include -#include -#include -/** - * Add x86 specific ioport service - */ - -namespace Genode -{ - void platform_add_local_services(Rpc_entrypoint &, - Sliced_heap &, - Registry &, - Trace::Source_registry &) - { } -} +void Genode::platform_add_local_services(Rpc_entrypoint &, + Sliced_heap &, + Registry &, + Trace::Source_registry &) +{ } diff --git a/repos/base-linux/src/core/spec/pc/dataspace_component.cc b/repos/base-linux/src/core/spec/pc/dataspace_component.cc index d0fa1b51b1..9a314a8966 100644 --- a/repos/base-linux/src/core/spec/pc/dataspace_component.cc +++ b/repos/base-linux/src/core/spec/pc/dataspace_component.cc @@ -61,16 +61,20 @@ Genode::size_t Dataspace_component::_file_size() Dataspace_component::Dataspace_component(const char *args) -: _fname(_file_name(args)), - _size(_file_size()), - _addr(0), - _cap(_fd_to_cap(lx_open(_fname.buf, O_RDONLY | LX_O_CLOEXEC, S_IRUSR | S_IXUSR))), - _writable(false), - _owner(0) { } +: + _fname(_file_name(args)), + _size(_file_size()), + _addr(0), + _cap(_fd_to_cap(lx_open(_fname.buf, O_RDONLY | LX_O_CLOEXEC, S_IRUSR | S_IXUSR))), + _writable(false), + _owner(0) +{ } + Dataspace_component::Dataspace_component(size_t size, addr_t, addr_t phys_addr, - Cache_attribute, bool writable, Dataspace_owner *_owner) : - _size(size), _addr(phys_addr), _cap(), _writable(writable), _owner(_owner) + Cache_attribute, bool writable, Dataspace_owner *_owner) +: + _size(size), _addr(phys_addr), _cap(), _writable(writable), _owner(_owner) { _fname.buf[0] = 0; } diff --git a/repos/base-linux/src/core/spec/pc/io_mem_session_component.cc b/repos/base-linux/src/core/spec/pc/io_mem_session_component.cc index b8e438f9c1..89b0346d33 100644 --- a/repos/base-linux/src/core/spec/pc/io_mem_session_component.cc +++ b/repos/base-linux/src/core/spec/pc/io_mem_session_component.cc @@ -11,17 +11,18 @@ * under the terms of the GNU Affero General Public License version 3. */ +/* Genode includes */ #include #include #include - -#include - #include +/* core-local includes */ +#include using namespace Genode; + size_t Io_mem_session_component::get_arg_size(const char *args) { size_t const size = Arg_string::find_arg(args, "size").ulong_value(0); @@ -38,9 +39,10 @@ addr_t Io_mem_session_component::get_arg_phys(const char *args) return Arg_string::find_arg(args, "base").ulong_value(0); } + Cache_attribute Io_mem_session_component::get_arg_wc(const char *args) { - Arg a = Arg_string::find_arg("wc", args); + Arg const a = Arg_string::find_arg("wc", args); if (a.valid() && a.bool_value(0)) { return WRITE_COMBINED; } else { @@ -58,10 +60,10 @@ Io_mem_session_component::Io_mem_session_component(Range_allocator &io_mem_alloc _ds_ep(ds_ep), _ds_cap(Io_mem_dataspace_capability()) { - int _fd = -1; + int _fd = lx_open("/dev/hwio", O_RDWR | O_SYNC); - _fd = lx_open("/dev/hwio", O_RDWR | O_SYNC); lx_ioctl_iomem(_fd, (unsigned long)get_arg_phys(args), get_arg_size(args)); + if (_fd > 0) { _ds.fd(_fd); } else { @@ -72,7 +74,8 @@ Io_mem_session_component::Io_mem_session_component(Range_allocator &io_mem_alloc _ds_cap = static_cap_cast(static_cap_cast(_ds_ep.manage(&_ds))); } + Io_mem_dataspace_capability Io_mem_session_component::dataspace() { - return _ds_cap; + return _ds_cap; } diff --git a/repos/base-linux/src/core/spec/pc/io_port_session_component.cc b/repos/base-linux/src/core/spec/pc/io_port_session_component.cc index e26f45e286..d6434452a6 100644 --- a/repos/base-linux/src/core/spec/pc/io_port_session_component.cc +++ b/repos/base-linux/src/core/spec/pc/io_port_session_component.cc @@ -11,19 +11,20 @@ * under the terms of the GNU Affero General Public License version 3. */ -#include #include -#include #include +using namespace Genode; -Genode::Io_port_session_component::Io_port_session_component(Genode::Range_allocator &io_port_alloc, const char *args) -: _io_port_alloc(io_port_alloc) + +Io_port_session_component::Io_port_session_component(Range_allocator &io_port_alloc, + const char *args) +: + _io_port_alloc(io_port_alloc) { /* parse for port properties */ _base = Arg_string::find_arg(args, "io_port_base").ulong_value(0); _size = Arg_string::find_arg(args, "io_port_size").ulong_value(0); } -Genode::Io_port_session_component::~Io_port_session_component() -{} +Io_port_session_component::~Io_port_session_component() { } diff --git a/repos/base-linux/src/core/spec/pc/irq_session_component.cc b/repos/base-linux/src/core/spec/pc/irq_session_component.cc index bfd0012d8f..5cfb3bcbc5 100644 --- a/repos/base-linux/src/core/spec/pc/irq_session_component.cc +++ b/repos/base-linux/src/core/spec/pc/irq_session_component.cc @@ -1,8 +1,7 @@ /* - * \brief IRQ session implementation for base-linux + * \brief IRQ session implementation for base-linux * \author Johannes Kliemann - * \date 2018-03-14 - * + * \date 2018-03-14 */ /* @@ -13,15 +12,19 @@ * under the terms of the GNU Affero General Public License version 3. */ +/* Genode includes */ #include #include +/* core-local includes */ #include #include - #include -Genode::Irq_session_component::Irq_session_component(Genode::Range_allocator &, const char *args) +using namespace Genode; + + +Irq_session_component::Irq_session_component(Range_allocator &, const char *args) : _irq_number(Arg_string::find_arg(args, "irq_number").long_value(-1)), _irq_object(_irq_number) @@ -29,90 +32,93 @@ Genode::Irq_session_component::Irq_session_component(Genode::Range_allocator &, _irq_object.start(); } -Genode::Irq_session_component::~Irq_session_component() + +Irq_session_component::~Irq_session_component() { warning(__func__, " not implemented"); } -void Genode::Irq_session_component::ack_irq() + +void Irq_session_component::ack_irq() { _irq_object.ack_irq(); } -void Genode::Irq_session_component::sigh(Genode::Signal_context_capability cap) + +void Irq_session_component::sigh(Signal_context_capability cap) { _irq_object.sigh(cap); } -Genode::Irq_session::Info Genode::Irq_session_component::info() + +Irq_session::Info Irq_session_component::info() { - return { .type = Genode::Irq_session::Info::Type::INVALID, .address = 0, .value = 0 }; + return { .type = Irq_session::Info::Type::INVALID, .address = 0, .value = 0 }; } -Genode::Irq_object::Irq_object(unsigned irq) : +Irq_object::Irq_object(unsigned irq) +: Thread_deprecated<4096>("irq"), - _sig_cap(Signal_context_capability()), - _irq(irq), - _fd(-1) + _sig_cap(Signal_context_capability()), _irq(irq), _fd(-1) { } -bool Genode::Irq_object::_associate() + +bool Irq_object::_associate() { _fd = lx_open("/dev/hwio", O_RDWR | O_SYNC); if (_fd < 0){ - Genode::error("failed to open /dev/hwio"); + error("failed to open /dev/hwio"); return false; } if (lx_ioctl_irq(_fd, _irq) < 0){ - Genode::error("failed to request irq"); + error("failed to request irq"); return false; } return true; } -void Genode::Irq_object::entry() + +void Irq_object::entry() { - if (!_associate()) { + if (!_associate()) error("failed to register IRQ ", _irq); - } _sync_bootup.wakeup(); _sync_ack.block(); while (true) { - if (lx_read(_fd, 0, 0) < 0) { - Genode::warning("failed to read on /dev/hwio"); - } + if (lx_read(_fd, 0, 0) < 0) + warning("failed to read on /dev/hwio"); - if(!_sig_cap.valid()){ + if(!_sig_cap.valid()) continue; - } - Genode::Signal_transmitter(_sig_cap).submit(1); + Signal_transmitter(_sig_cap).submit(1); _sync_ack.block(); } } -void Genode::Irq_object::ack_irq() + +void Irq_object::ack_irq() { _sync_ack.wakeup(); } -void Genode::Irq_object::start() + +void Irq_object::start() { - Genode::Thread::start(); + Thread::start(); _sync_bootup.block(); } -void Genode::Irq_object::sigh(Signal_context_capability cap) + +void Irq_object::sigh(Signal_context_capability cap) { _sig_cap = cap; } - - diff --git a/repos/base-linux/src/core/spec/pc/platform_services.cc b/repos/base-linux/src/core/spec/pc/platform_services.cc index aeb09e7576..a3334c29ee 100644 --- a/repos/base-linux/src/core/spec/pc/platform_services.cc +++ b/repos/base-linux/src/core/spec/pc/platform_services.cc @@ -20,25 +20,19 @@ #include #include #include - #include -/** - * Add x86 specific ioport service - */ -namespace Genode +void Genode::platform_add_local_services(Rpc_entrypoint &, + Sliced_heap &md, + Registry ®, + Trace::Source_registry &) { - void platform_add_local_services(Rpc_entrypoint &, - Sliced_heap &md, - Registry ®, - Trace::Source_registry &) - { - if (!lx_iopl(3)) { - static Io_port_root io_port_root(*core_env().pd_session(), - platform().io_port_alloc(), md); + if (!lx_iopl(3)) { + static Io_port_root io_port_root(*core_env().pd_session(), + platform().io_port_alloc(), md); - static Core_service - io_port_ls(reg, io_port_root); - } - } + static Core_service + + io_port_ls(reg, io_port_root); + } } diff --git a/repos/base-linux/src/core/stack_area.cc b/repos/base-linux/src/core/stack_area.cc index 32bd728285..fc1d6cf1f1 100644 --- a/repos/base-linux/src/core/stack_area.cc +++ b/repos/base-linux/src/core/stack_area.cc @@ -92,18 +92,16 @@ struct Stack_area_ram_allocator : Genode::Ram_allocator /** * Return single instance of the stack-area RM and RAM session */ -namespace Genode { - Region_map *env_stack_area_region_map; - Ram_allocator *env_stack_area_ram_allocator; +Genode::Region_map *Genode::env_stack_area_region_map; +Genode::Ram_allocator *Genode::env_stack_area_ram_allocator; - void init_stack_area() - { - static Stack_area_region_map rm_inst; - env_stack_area_region_map = &rm_inst; +void Genode::init_stack_area() +{ + static Stack_area_region_map rm_inst; + env_stack_area_region_map = &rm_inst; - static Stack_area_ram_allocator ram_inst; - env_stack_area_ram_allocator = &ram_inst; - } + static Stack_area_ram_allocator ram_inst; + env_stack_area_ram_allocator = &ram_inst; } diff --git a/repos/base-linux/src/include/base/internal/local_capability.h b/repos/base-linux/src/include/base/internal/local_capability.h index d3d388914d..7305b8ce25 100644 --- a/repos/base-linux/src/include/base/internal/local_capability.h +++ b/repos/base-linux/src/include/base/internal/local_capability.h @@ -4,7 +4,7 @@ * \author Stefan Kalkowski * \date 2011-05-22 * - * A typed capability is a capability tied to one specifiec RPC interface + * A typed capability is a capability tied to one specifiec RPC interface. */ /* diff --git a/repos/base-linux/src/include/base/internal/local_parent.h b/repos/base-linux/src/include/base/internal/local_parent.h index 00d3363513..21d3b566b3 100644 --- a/repos/base-linux/src/include/base/internal/local_parent.h +++ b/repos/base-linux/src/include/base/internal/local_parent.h @@ -24,7 +24,6 @@ #include namespace Genode { - class Local_session; class Local_parent; } diff --git a/repos/base-linux/src/include/base/internal/native_thread.h b/repos/base-linux/src/include/base/internal/native_thread.h index 120b4f36dd..e921e837f1 100644 --- a/repos/base-linux/src/include/base/internal/native_thread.h +++ b/repos/base-linux/src/include/base/internal/native_thread.h @@ -21,6 +21,7 @@ namespace Genode { struct Native_thread; } + class Genode::Native_thread { private: diff --git a/repos/base-linux/src/include/base/internal/region_map_mmap.h b/repos/base-linux/src/include/base/internal/region_map_mmap.h index 2645128f9f..5224298352 100644 --- a/repos/base-linux/src/include/base/internal/region_map_mmap.h +++ b/repos/base-linux/src/include/base/internal/region_map_mmap.h @@ -37,8 +37,9 @@ class Genode::Region_map_mmap : public Region_map, public Dataspace private: Region_registry _rmap { }; - bool const _sub_rm; /* false if region map is root */ - size_t const _size; + + bool const _sub_rm; /* false if region map is root */ + size_t const _size; /** * Base offset of the RM session diff --git a/repos/base-linux/src/include/linux_dataspace/client.h b/repos/base-linux/src/include/linux_dataspace/client.h index 84c678e4f6..982ca7d3a4 100644 --- a/repos/base-linux/src/include/linux_dataspace/client.h +++ b/repos/base-linux/src/include/linux_dataspace/client.h @@ -19,30 +19,30 @@ #include #include -namespace Genode { - - struct Linux_dataspace_client : Rpc_client - { - explicit Linux_dataspace_client(Dataspace_capability ds) - : Rpc_client(static_cap_cast(ds)) { } +namespace Genode { struct Linux_dataspace_client; } - /********************************* - ** Generic dataspace interface ** - *********************************/ - - size_t size() override { return call(); } - addr_t phys_addr() override { return call(); } - bool writable() override { return call(); } +struct Genode::Linux_dataspace_client : Rpc_client +{ + explicit Linux_dataspace_client(Dataspace_capability ds) + : Rpc_client(static_cap_cast(ds)) { } - /**************************************** - ** Linux-specific dataspace interface ** - ****************************************/ + /********************************* + ** Generic dataspace interface ** + *********************************/ - Filename fname() override { return call(); } - Untyped_capability fd() override { return call(); } - }; -} + size_t size() override { return call(); } + addr_t phys_addr() override { return call(); } + bool writable() override { return call(); } + + + /**************************************** + ** Linux-specific dataspace interface ** + ****************************************/ + + Filename fname() override { return call(); } + Untyped_capability fd() override { return call(); } +}; #endif /* _INCLUDE__LINUX_DATASPACE__CLIENT_H_ */ diff --git a/repos/base-linux/src/include/linux_dataspace/linux_dataspace.h b/repos/base-linux/src/include/linux_dataspace/linux_dataspace.h index d11e349ed4..8803c3afda 100644 --- a/repos/base-linux/src/include/linux_dataspace/linux_dataspace.h +++ b/repos/base-linux/src/include/linux_dataspace/linux_dataspace.h @@ -19,37 +19,37 @@ #include #include -namespace Genode { - - struct Linux_dataspace : Dataspace - { - enum { FNAME_LEN = 64 }; - struct Filename { char buf[FNAME_LEN]; }; - - virtual ~Linux_dataspace() { } - - /** - * Request name of file that represents the dataspace on Linux - * - * This function is used for calling execve on files passed as ROM - * dataspaces. - */ - virtual Filename fname() = 0; - - /** - * Request file descriptor of the dataspace - */ - virtual Untyped_capability fd() = 0; - - /********************* - ** RPC declaration ** - *********************/ +namespace Genode { struct Linux_dataspace; } - GENODE_RPC(Rpc_fname, Filename, fname); - GENODE_RPC(Rpc_fd, Untyped_capability, fd); - GENODE_RPC_INTERFACE_INHERIT(Dataspace, Rpc_fname, Rpc_fd); - }; -} +struct Genode::Linux_dataspace : Dataspace +{ + enum { FNAME_LEN = 64 }; + struct Filename { char buf[FNAME_LEN]; }; + + virtual ~Linux_dataspace() { } + + /** + * Request name of file that represents the dataspace on Linux + * + * This function is used for calling execve on files passed as ROM + * dataspaces. + */ + virtual Filename fname() = 0; + + /** + * Request file descriptor of the dataspace + */ + virtual Untyped_capability fd() = 0; + + /********************* + ** RPC declaration ** + *********************/ + + + GENODE_RPC(Rpc_fname, Filename, fname); + GENODE_RPC(Rpc_fd, Untyped_capability, fd); + GENODE_RPC_INTERFACE_INHERIT(Dataspace, Rpc_fname, Rpc_fd); +}; #endif /* _INCLUDE__LINUX_DATASPACE__LINUX_DATASPACE_H_ */ diff --git a/repos/base-linux/src/include/linux_native_cpu/client.h b/repos/base-linux/src/include/linux_native_cpu/client.h index 92a1028058..1e3c4798c3 100644 --- a/repos/base-linux/src/include/linux_native_cpu/client.h +++ b/repos/base-linux/src/include/linux_native_cpu/client.h @@ -19,6 +19,7 @@ namespace Genode { struct Linux_native_cpu_client; } + struct Genode::Linux_native_cpu_client : Rpc_client { explicit Linux_native_cpu_client(Capability cap) diff --git a/repos/base-linux/src/include/linux_native_pd/client.h b/repos/base-linux/src/include/linux_native_pd/client.h index e75de7de73..79ad406d48 100644 --- a/repos/base-linux/src/include/linux_native_pd/client.h +++ b/repos/base-linux/src/include/linux_native_pd/client.h @@ -19,6 +19,7 @@ namespace Genode { struct Linux_native_pd_client; } + struct Genode::Linux_native_pd_client : Rpc_client { explicit Linux_native_pd_client(Capability cap) diff --git a/repos/base-linux/src/lib/base/child_process.cc b/repos/base-linux/src/lib/base/child_process.cc index 34acee2e81..6dac3e7650 100644 --- a/repos/base-linux/src/lib/base/child_process.cc +++ b/repos/base-linux/src/lib/base/child_process.cc @@ -21,7 +21,6 @@ #include #include - using namespace Genode; diff --git a/repos/base-linux/src/lib/base/platform.cc b/repos/base-linux/src/lib/base/platform.cc index 66fedb793a..d3a94f061b 100644 --- a/repos/base-linux/src/lib/base/platform.cc +++ b/repos/base-linux/src/lib/base/platform.cc @@ -27,10 +27,15 @@ using namespace Genode; extern char _binary_seccomp_bpf_policy_bin_start[]; extern char _binary_seccomp_bpf_policy_bin_end[]; -struct bpf_program { - Genode::uint16_t blk_cnt; - Genode::uint64_t* blks; -}; + +namespace Genode { + + struct Bpf_program + { + uint16_t blk_cnt; + uint64_t *blks; + }; +} void Genode::binary_ready_hook_for_platform() { @@ -40,19 +45,22 @@ void Genode::binary_ready_hook_for_platform() } for (char* i = _binary_seccomp_bpf_policy_bin_start; - i < _binary_seccomp_bpf_policy_bin_end - sizeof(Genode::uint32_t); i++) { - Genode::uint32_t* v = reinterpret_cast(i); + i < _binary_seccomp_bpf_policy_bin_end - sizeof(uint32_t); i++) { + + uint32_t *v = reinterpret_cast(i); if (*v == 0xCAFEAFFE) { *v = lx_getpid(); } } - bpf_program program; - program.blk_cnt = (_binary_seccomp_bpf_policy_bin_end - - _binary_seccomp_bpf_policy_bin_start) / - sizeof(Genode::uint64_t); - program.blks = (Genode::uint64_t*)_binary_seccomp_bpf_policy_bin_start; - Genode::uint64_t flags = SECCOMP_FILTER_FLAG_TSYNC; + Bpf_program program { + .blk_cnt = (uint16_t)((_binary_seccomp_bpf_policy_bin_end - + _binary_seccomp_bpf_policy_bin_start) / + sizeof(uint64_t)), + .blks = (uint64_t *)_binary_seccomp_bpf_policy_bin_start + }; + + uint64_t flags = SECCOMP_FILTER_FLAG_TSYNC; auto ret = lx_seccomp(SECCOMP_SET_MODE_FILTER, flags, &program); if (ret != 0) { error("SECCOMP_SET_MODE_FILTER failed ", ret); diff --git a/repos/base-linux/src/lib/base/region_map_client.cc b/repos/base-linux/src/lib/base/region_map_client.cc index e45c3fbdca..2874c970d4 100644 --- a/repos/base-linux/src/lib/base/region_map_client.cc +++ b/repos/base-linux/src/lib/base/region_map_client.cc @@ -19,8 +19,10 @@ using namespace Genode; + class Capability_invalid : public Genode::Exception {}; + /** * Return pointer to locally implemented region map * 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 d42673ebec..7f7e60b275 100644 --- a/repos/base-linux/src/lib/lx_hybrid/lx_hybrid.cc +++ b/repos/base-linux/src/lib/lx_hybrid/lx_hybrid.cc @@ -79,37 +79,45 @@ static Genode::Env *_env_ptr; namespace Genode { + extern void bootstrap_component(); extern void call_global_static_constructors(); - /* - * This function is normally provided by the cxx library, which is not - * used for lx_hybrid programs. For lx_hybrid programs, the exception - * handling is initialized by the host system's regular startup code. - * - * However, we conveniently use this function to get hold of the - * component's environment and initialize the default log output. - */ - void init_exception_handling(Env &env) - { - _env_ptr = &env; - - init_log(env.parent()); - } + struct Thread_meta_data_created; + struct Thread_meta_data_adopted; } + +/* + * This function is normally provided by the cxx library, which is not + * used for lx_hybrid programs. For lx_hybrid programs, the exception + * handling is initialized by the host system's regular startup code. + * + * However, we conveniently use this function to get hold of the + * component's environment and initialize the default log output. + */ +void Genode::init_exception_handling(Env &env) +{ + _env_ptr = &env; + + init_log(env.parent()); +} + + /* * Static constructors are handled by the Linux startup code - so implement * this as empty function. */ void Genode::call_global_static_constructors() { } + Genode::size_t Component::stack_size() __attribute__((weak)); Genode::size_t Component::stack_size() { return 16UL * 1024 * sizeof(Genode::addr_t); } + /* * Hybrid components are not allowed to implement legacy main(). This enables * us to hook in and bootstrap components as usual. @@ -184,165 +192,164 @@ static pthread_key_t tls_key() } -namespace Genode { +/** + * Meta data tied to the thread via the pthread TLS mechanism + */ +struct Genode::Native_thread::Meta_data +{ + /** + * Linux-specific thread meta data + * + * For non-hybrid programs, this information is located at the + * 'Stack'. But the POSIX threads of hybrid programs have no 'Stack' + * object. So we have to keep the meta data here. + */ + Native_thread native_thread { }; /** - * Meta data tied to the thread via the pthread TLS mechanism + * Filled out by 'thread_start' function in the stack of the new + * thread */ - struct Native_thread::Meta_data + Thread &thread_base; + + /** + * POSIX thread handle + */ + pthread_t pt { }; + + /** + * Constructor + * + * \param thread associated 'Thread' object + */ + Meta_data(Thread *thread) : thread_base(*thread) { - /** - * Linux-specific thread meta data - * - * For non-hybrid programs, this information is located at the - * 'Stack'. But the POSIX threads of hybrid programs have no 'Stack' - * object. So we have to keep the meta data here. - */ - Native_thread native_thread { }; + native_thread.meta_data = this; + } - /** - * Filled out by 'thread_start' function in the stack of the new - * thread - */ - Thread &thread_base; + virtual ~Meta_data() { } - /** - * POSIX thread handle - */ - pthread_t pt { }; + /** + * Used to block the constructor until the new thread has initialized + * 'id' + */ + virtual void wait_for_construction() = 0; + virtual void constructed() = 0; - /** - * Constructor - * - * \param thread associated 'Thread' object - */ - Meta_data(Thread *thread) : thread_base(*thread) - { - native_thread.meta_data = this; - } + /** + * Used to block the new thread until 'start' is called + */ + virtual void wait_for_start() = 0; + virtual void started() = 0; - virtual ~Meta_data() { } + /** + * Used to block the 'join()' function until the 'entry()' is done + */ + virtual void wait_for_join() = 0; + virtual void joined() = 0; +}; + + +/** + * Thread meta data for a thread created by Genode + */ +class Genode::Thread_meta_data_created : public Native_thread::Meta_data +{ + private: /** * Used to block the constructor until the new thread has initialized * 'id' */ - virtual void wait_for_construction() = 0; - virtual void constructed() = 0; + Blockade _construct_lock { }; /** * Used to block the new thread until 'start' is called */ - virtual void wait_for_start() = 0; - virtual void started() = 0; + Blockade _start_lock { }; /** * Used to block the 'join()' function until the 'entry()' is done */ - virtual void wait_for_join() = 0; - virtual void joined() = 0; - }; + Blockade _join_lock { }; - /** - * Thread meta data for a thread created by Genode - */ - class Thread_meta_data_created : public Native_thread::Meta_data - { - private: + public: - /** - * Used to block the constructor until the new thread has initialized - * 'id' - */ - Blockade _construct_lock { }; + Thread_meta_data_created(Thread *thread) + : Native_thread::Meta_data(thread) { } - /** - * Used to block the new thread until 'start' is called - */ - Blockade _start_lock { }; + void wait_for_construction() override + { + _construct_lock.block(); + } - /** - * Used to block the 'join()' function until the 'entry()' is done - */ - Blockade _join_lock { }; + void constructed() override + { + _construct_lock.wakeup(); + } - public: + void wait_for_start() override + { + _start_lock.block(); + } - Thread_meta_data_created(Thread *thread) - : Native_thread::Meta_data(thread) { } + void started() override + { + _start_lock.wakeup(); + } - void wait_for_construction() override - { - _construct_lock.block(); - } + void wait_for_join() override + { + _join_lock.block(); + } - void constructed() override - { - _construct_lock.wakeup(); - } + void joined() override + { + _join_lock.wakeup(); + } +}; - void wait_for_start() override - { - _start_lock.block(); - } - void started() override - { - _start_lock.wakeup(); - } +/** + * Thread meta data for an adopted thread + */ +class Genode::Thread_meta_data_adopted : public Native_thread::Meta_data +{ + public: - void wait_for_join() override - { - _join_lock.block(); - } + Thread_meta_data_adopted(Thread *thread) + : Native_thread::Meta_data(thread) { } - void joined() override - { - _join_lock.wakeup(); - } - }; + void wait_for_construction() override + { + error("wait_for_construction() called for an adopted thread"); + } - /** - * Thread meta data for an adopted thread - */ - class Thread_meta_data_adopted : public Native_thread::Meta_data - { - public: + void constructed() override + { + error("constructed() called for an adopted thread"); + } - Thread_meta_data_adopted(Thread *thread) - : Native_thread::Meta_data(thread) { } + void wait_for_start() override + { + error("wait_for_start() called for an adopted thread"); + } - void wait_for_construction() override - { - error("wait_for_construction() called for an adopted thread"); - } + void started() override + { + error("started() called for an adopted thread"); + } - void constructed() override - { - error("constructed() called for an adopted thread"); - } + void wait_for_join() override + { + error("wait_for_join() called for an adopted thread"); + } - void wait_for_start() override - { - error("wait_for_start() called for an adopted thread"); - } - - void started() override - { - error("started() called for an adopted thread"); - } - - void wait_for_join() override - { - error("wait_for_join() called for an adopted thread"); - } - - void joined() override - { - error("joined() called for an adopted thread"); - } - }; -} + void joined() override + { + error("joined() called for an adopted thread"); + } +}; static void adopt_thread(Native_thread::Meta_data *meta_data) diff --git a/repos/base-linux/src/lib/seccomp/seccomp_bpf_policy.h b/repos/base-linux/src/lib/seccomp/seccomp_bpf_policy.h index bdb002f138..9ec9858e54 100644 --- a/repos/base-linux/src/lib/seccomp/seccomp_bpf_policy.h +++ b/repos/base-linux/src/lib/seccomp/seccomp_bpf_policy.h @@ -19,21 +19,21 @@ #define STR(x) STR2(x) #define INCBIN(name, file) \ - __asm__(".section .rodata\n" \ - ".global incbin_" STR(name) "_start\n" \ - ".type incbin_" STR(name) "_start, @object\n" \ - ".balign 16\n" \ - "incbin_" STR(name) "_start:\n" \ - ".incbin \"" file "\"\n" \ - \ - ".global incbin_" STR(name) "_end\n" \ - ".type incbin_" STR(name) "_end, @object\n" \ - ".balign 1\n" \ - "incbin_" STR(name) "_end:\n" \ - ".byte 0\n" \ - ); \ - extern const __attribute__((aligned(16))) void* incbin_ ## name ## _start; \ - extern const void* incbin_ ## name ## _end; \ + __asm__(".section .rodata\n" \ + ".global incbin_" STR(name) "_start\n" \ + ".type incbin_" STR(name) "_start, @object\n" \ + ".balign 16\n" \ + "incbin_" STR(name) "_start:\n" \ + ".incbin \"" file "\"\n" \ + \ + ".global incbin_" STR(name) "_end\n" \ + ".type incbin_" STR(name) "_end, @object\n" \ + ".balign 1\n" \ + "incbin_" STR(name) "_end:\n" \ + ".byte 0\n" \ + ); \ + extern const __attribute__((aligned(16))) void* incbin_ ## name ## _start; \ + extern const void* incbin_ ## name ## _end; \ INCBIN(seccomp_bpf_policy, "seccomp_bpf_policy.bin"); diff --git a/repos/base-linux/src/test/lx_hybrid_pthread_ipc/main.cc b/repos/base-linux/src/test/lx_hybrid_pthread_ipc/main.cc index 0b4f482c4c..7d75d22619 100644 --- a/repos/base-linux/src/test/lx_hybrid_pthread_ipc/main.cc +++ b/repos/base-linux/src/test/lx_hybrid_pthread_ipc/main.cc @@ -23,7 +23,6 @@ #include - static Genode::Blockade *main_wait_lock() { static Genode::Blockade inst;