diff options
-rw-r--r-- | src/internal/global_nodestruct.hpp | 38 | ||||
-rwxr-xr-x | src/internal/internal.cpp | 4 | ||||
-rw-r--r-- | src/internal/naive_policy_checker.hpp | 13 | ||||
-rw-r--r-- | src/internal/xml_parser.cpp | 8 | ||||
-rwxr-xr-x | src/internal/xml_parser.hpp | 4 |
5 files changed, 48 insertions, 19 deletions
diff --git a/src/internal/global_nodestruct.hpp b/src/internal/global_nodestruct.hpp new file mode 100644 index 0000000..6bc7fe7 --- /dev/null +++ b/src/internal/global_nodestruct.hpp @@ -0,0 +1,38 @@ +/* + * Copyright (c) 2015-2019 Samsung Electronics Co., Ltd All Rights Reserved + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. +*/ + +/** + * \file + * \ingroup Implementation + */ + + +#ifndef GLOBAL_NODESTRUCT_HPP +#define GLOBAL_NODESTRUCT_HPP + +/** Declare a global variable that is constructed (via gcc's __attribute__((constructor))) but never destroyed. */ +#define DCL_NODESTRUCT_GLOBAL(TYPE,NAME)\ + namespace detail_NODESTRUCT_GLOBAL { alignas(TYPE) extern uint8_t NAME[sizeof(TYPE)]; }\ + /* awkwardly written to silence gcc's -Wstrict-aliasing because _Pragma("GCC diagnostic ignored \"-Wstrict-aliasing\"") is bugged */\ + static inline TYPE &NAME() { auto p = static_cast<void*>(&detail_NODESTRUCT_GLOBAL::NAME[0]); return *reinterpret_cast<TYPE*>(p); }\ + namespace detailInit_NODESTRUCT_GLOBAL { __attribute__((constructor)) static void NAME() { new(&::NAME()) TYPE(); } } + +/** Define a global variable that is constructed (via gcc's __attribute__((constructor))) but never destroyed. */ +#define DEF_NODESTRUCT_GLOBAL(TYPE,NAME)\ + namespace detail_NODESTRUCT_GLOBAL { alignas(TYPE) uint8_t NAME[sizeof(TYPE)]; } + + +#endif // GLOBAL_NODESTRUCT_HPP diff --git a/src/internal/internal.cpp b/src/internal/internal.cpp index 8100483..78b8dc1 100755 --- a/src/internal/internal.cpp +++ b/src/internal/internal.cpp @@ -35,7 +35,7 @@ static const char* get_str(const char* const szstr) { int __internal_init(bool bus_type, const char* const config_name) { policy_checker().clearDb(bus_type); - auto err = ldp_xml_parser::static_parser.parsePolicy(bus_type, get_str(config_name)); + auto err = static_parser().parsePolicy(bus_type, get_str(config_name)); if (tslog::enabled()) memory_dump(bus_type); return err; @@ -64,7 +64,7 @@ void __internal_init_flush_logs() void __internal_init_sup_group(bool bus_type, uid_t uid, gid_t gid) { - ldp_xml_parser::static_parser.updateGroupPolicy(bus_type, uid, gid); + static_parser().updateGroupPolicy(bus_type, uid, gid); } void __internal_enter() diff --git a/src/internal/naive_policy_checker.hpp b/src/internal/naive_policy_checker.hpp index d4379cc..c15eab0 100644 --- a/src/internal/naive_policy_checker.hpp +++ b/src/internal/naive_policy_checker.hpp @@ -25,6 +25,7 @@ #include "policy.hpp" #include "naive_policy_db.hpp" +#include "global_nodestruct.hpp" namespace ldp_xml_parser { @@ -170,18 +171,6 @@ namespace ldp_xml_parser }; } -/** Declare a global variable that is constructed (via gcc's __attribute__((constructor))) but never destroyed. */ -#define DCL_NODESTRUCT_GLOBAL(TYPE,NAME)\ - namespace detail_NODESTRUCT_GLOBAL { alignas(TYPE) extern uint8_t NAME[sizeof(TYPE)]; }\ - /* awkwardly written to silence gcc's -Wstrict-aliasing because _Pragma("GCC diagnostic ignored \"-Wstrict-aliasing\"") is bugged */\ - static inline TYPE &NAME() { auto p = static_cast<void*>(&detail_NODESTRUCT_GLOBAL::NAME[0]); return *reinterpret_cast<TYPE*>(p); }\ - namespace detailInit_NODESTRUCT_GLOBAL { __attribute__((constructor)) static void NAME() { new(&::NAME()) TYPE(); } } - -/** Define a global variable that is constructed (via gcc's __attribute__((constructor))) but never destroyed. */ -#define DEF_NODESTRUCT_GLOBAL(TYPE,NAME)\ - namespace detail_NODESTRUCT_GLOBAL { alignas(TYPE) uint8_t NAME[sizeof(TYPE)]; } - - DCL_NODESTRUCT_GLOBAL(ldp_xml_parser::NaivePolicyChecker, policy_checker) #endif diff --git a/src/internal/xml_parser.cpp b/src/internal/xml_parser.cpp index 25cc199..03d6a13 100644 --- a/src/internal/xml_parser.cpp +++ b/src/internal/xml_parser.cpp @@ -49,7 +49,7 @@ void parseAssert(bool condition) { void start_element_handler(void *data, const char *el, const char **attr) { (void)data; - XmlParser& parser = static_parser; + XmlParser& parser = static_parser(); try { parser.elementStart(el, attr); } catch (...) { @@ -60,7 +60,7 @@ void start_element_handler(void *data, const char *el, const char **attr) { void end_element_handler(void *data, const char *el) { (void)data; - XmlParser& parser = static_parser; + XmlParser& parser = static_parser(); try { parser.elementEnd(el); } catch (...) { @@ -71,7 +71,7 @@ void end_element_handler(void *data, const char *el) { void text_handler(void *data, const char *text, int len) { (void)data; - XmlParser& parser = static_parser; + XmlParser& parser = static_parser(); try { parser.text(text, len); } catch (...) { @@ -297,4 +297,4 @@ void XmlParser::getIncludedFiles(const std::string& parent_dir, const std::strin } } -ldp_xml_parser::XmlParser ldp_xml_parser::static_parser; +DEF_NODESTRUCT_GLOBAL(ldp_xml_parser::XmlParser, static_parser); diff --git a/src/internal/xml_parser.hpp b/src/internal/xml_parser.hpp index 3cf7899..2369c61 100755 --- a/src/internal/xml_parser.hpp +++ b/src/internal/xml_parser.hpp @@ -24,6 +24,7 @@ #include <set> #include <boost/noncopyable.hpp> #include "policy.hpp" +#include "global_nodestruct.hpp" namespace ldp_xml_parser { @@ -81,7 +82,8 @@ namespace ldp_xml_parser std::vector<std::string> included_files; }; - extern XmlParser static_parser; } //namespace +DCL_NODESTRUCT_GLOBAL(ldp_xml_parser::XmlParser, static_parser) + #endif |