From d1f1cdda8c24dd8800aaa04c19c19bad7d02639d Mon Sep 17 00:00:00 2001 From: Christopher James Halse Rogers Date: Fri, 6 Sep 2024 11:20:00 +1000 Subject: [PATCH 01/18] mir::SharedLibrary: Add a stable Handle for SharedLibrary It can be useful to know if two `SharedLibrary` instances refer to the same DSO. The new `SharedLibrary::Handle` implements such a comparable handle. This works because `dlopen` guarantees that loading an already-loaded DSO returns the same handle. --- include/common/mir/shared_library.h | 17 ++++++++++++++++- src/common/sharedlibrary/shared_library.cpp | 16 ++++++++++++++++ src/common/symbols.map | 6 +++++- 3 files changed, 37 insertions(+), 2 deletions(-) diff --git a/include/common/mir/shared_library.h b/include/common/mir/shared_library.h index 13c5b05da67..dd783d669da 100644 --- a/include/common/mir/shared_library.h +++ b/include/common/mir/shared_library.h @@ -17,6 +17,7 @@ #ifndef MIR_SHARED_LIBRARY_H_ #define MIR_SHARED_LIBRARY_H_ +#include #include namespace mir @@ -49,6 +50,21 @@ class SharedLibrary (void*&)result = load_symbol(function_name.c_str(), version.c_str()); return result; } + + class Handle + { + public: + auto operator<=>(Handle const& rhs) const -> std::strong_ordering; + auto operator==(Handle const& rhs) const -> bool = default; + auto operator!=(Handle const& rhs) const -> bool = default; + private: + friend class SharedLibrary; + + Handle(void* handle); + void* handle; + }; + + auto get_handle() const -> Handle; private: void* const so; void* load_symbol(char const* function_name) const; @@ -58,5 +74,4 @@ class SharedLibrary }; } - #endif /* MIR_SHARED_LIBRARY_H_ */ diff --git a/src/common/sharedlibrary/shared_library.cpp b/src/common/sharedlibrary/shared_library.cpp index ec41047c023..a76e9b010e4 100644 --- a/src/common/sharedlibrary/shared_library.cpp +++ b/src/common/sharedlibrary/shared_library.cpp @@ -15,6 +15,7 @@ */ #include "mir/shared_library.h" +#include #ifdef MIR_DONT_USE_DLVSYM #include @@ -74,3 +75,18 @@ void* mir::SharedLibrary::load_symbol(char const* function_name, char const* ver } #endif } + +auto mir::SharedLibrary::get_handle() const -> Handle +{ + return Handle{so}; +} + +mir::SharedLibrary::Handle::Handle(void* handle) + : handle{handle} +{ +} + +auto mir::SharedLibrary::Handle::operator<=>(Handle const& rhs) const -> std::strong_ordering +{ + return handle <=> rhs.handle; +} diff --git a/src/common/symbols.map b/src/common/symbols.map index 3f73ccc844e..eb0b74ed64d 100644 --- a/src/common/symbols.map +++ b/src/common/symbols.map @@ -325,6 +325,9 @@ global: mir::SharedLibrary::?SharedLibrary*; mir::SharedLibrary::SharedLibrary*; mir::SharedLibrary::load_symbol*; + mir::SharedLibrary::get_handle*; + mir::SharedLibrary::Handle::?Handle*; + mir::SharedLibrary::Handle::operator*; mir::SharedLibraryProberReport::?SharedLibraryProberReport*; mir::SharedLibraryProberReport::SharedLibraryProberReport*; mir::SharedLibraryProberReport::operator*; @@ -500,6 +503,7 @@ global: typeinfo?for?mir::NonBlockingExecutor; typeinfo?for?mir::PosixRWMutex; typeinfo?for?mir::SharedLibrary; + typeinfo?for?mir::SharedLibrary::Handle; typeinfo?for?mir::SharedLibraryProberReport; typeinfo?for?mir::Signal; typeinfo?for?mir::ThreadPoolExecutor; @@ -695,4 +699,4 @@ MIR_COMMON_2.18 { MirTouchpadConfig::disable_with_external_mouse*; mir::event_type_to_c_str*; }; -} MIR_COMMON_2.17; \ No newline at end of file +} MIR_COMMON_2.17; From 99aa10ad3024133d6db0c7c53d78d5f8085ab682 Mon Sep 17 00:00:00 2001 From: Christopher James Halse Rogers Date: Mon, 9 Sep 2024 11:52:35 +1000 Subject: [PATCH 02/18] Configuration: Split options into global and per-module configuration. This lets each module define its own options, without needing the option names to be unique across all modules. Also organises the module-specific options into their own sections at the end of the help text. --- include/platform/mir/options/configuration.h | 21 +- .../mir/options/default_configuration.h | 48 ++++- include/platform/mir/options/program_option.h | 2 +- .../server/mir/default_server_configuration.h | 8 +- .../options/default_configuration.cpp | 195 +++++++++++++++++- src/platform/options/program_option.cpp | 21 +- src/server/default_server_configuration.cpp | 11 +- src/server/graphics/default_configuration.cpp | 10 +- src/server/graphics/platform_probe.cpp | 58 +++--- src/server/graphics/platform_probe.h | 12 +- src/server/server.cpp | 2 +- .../server_configuration_options.cpp | 34 +++ .../command_line_server_configuration.cpp | 1 - .../graphics/test_platform_prober.cpp | 75 ++++--- .../options/test_program_option.cpp | 22 -- 15 files changed, 399 insertions(+), 121 deletions(-) diff --git a/include/platform/mir/options/configuration.h b/include/platform/mir/options/configuration.h index f4af7a7af28..f37a2bbf5be 100644 --- a/include/platform/mir/options/configuration.h +++ b/include/platform/mir/options/configuration.h @@ -23,6 +23,8 @@ namespace mir { +class SharedLibrary; + namespace options { extern char const* const arw_server_socket_opt; @@ -66,17 +68,24 @@ extern char const* const auto_console; extern char const* const vt_option_name; -class Configuration +class OptionsProvider { public: - virtual std::shared_ptr the_options() const = 0; + /** + * The options not associated with a specific loaded module + */ + virtual std::shared_ptr global_options() const = 0; + /** + * All options, including those added by the specified module + */ + virtual auto the_options_for(SharedLibrary const& module) const -> std::shared_ptr = 0; protected: + OptionsProvider() = default; + virtual ~OptionsProvider() = default; - Configuration() = default; - virtual ~Configuration() = default; - Configuration(Configuration const&) = delete; - Configuration& operator=(Configuration const&) = delete; + OptionsProvider(OptionsProvider const&) = delete; + OptionsProvider& operator=(OptionsProvider const&) = delete; }; } } diff --git a/include/platform/mir/options/default_configuration.h b/include/platform/mir/options/default_configuration.h index cb3c9d3ace5..6315d921c15 100644 --- a/include/platform/mir/options/default_configuration.h +++ b/include/platform/mir/options/default_configuration.h @@ -19,15 +19,15 @@ #include "mir/options/configuration.h" #include "mir/options/program_option.h" +#include "mir/shared_library.h" #include #include namespace mir { -class SharedLibrary; namespace options { -class DefaultConfiguration : public Configuration +class DefaultConfiguration : public OptionsProvider { public: DefaultConfiguration(int argc, char const* argv[]); @@ -54,7 +54,8 @@ class DefaultConfiguration : public Configuration void add_platform_options(); // accessed via the base interface, when access to add_options() has been "lost" - std::shared_ptr the_options() const override; + std::shared_ptr global_options() const override; + auto the_options_for(SharedLibrary const& module) const -> std::shared_ptr