diff --git a/init/Android.bp b/init/Android.bp index 181de2e52..2d16f60c9 100644 --- a/init/Android.bp +++ b/init/Android.bp @@ -88,7 +88,6 @@ init_device_sources = [ init_host_sources = [ "check_builtins.cpp", "host_import_parser.cpp", - "host_init_verifier.cpp", ] soong_config_module_type { @@ -321,7 +320,6 @@ cc_binary { visibility: ["//packages/modules/Virtualization/microdroid"], } - soong_config_module_type { name: "init_first_stage_cc_defaults", module_type: "cc_defaults", @@ -614,13 +612,13 @@ cc_defaults { cc_binary { name: "host_init_verifier", defaults: ["init_host_defaults"], - srcs: init_common_sources + init_host_sources, + srcs: ["host_init_verifier.cpp"] + init_common_sources + init_host_sources, } cc_library_host_static { name: "libinit_host", defaults: ["init_host_defaults"], - srcs: init_common_sources, + srcs: init_common_sources + init_host_sources, export_include_dirs: ["."], proto: { export_proto_headers: true, diff --git a/init/check_builtins.cpp b/init/check_builtins.cpp index 461ed2255..97254580c 100644 --- a/init/check_builtins.cpp +++ b/init/check_builtins.cpp @@ -28,9 +28,9 @@ #include #include #include +#include #include "builtin_arguments.h" -#include "host_init_verifier.h" #include "interface_utils.h" #include "property_type.h" #include "rlimit_parser.h" @@ -39,6 +39,9 @@ using android::base::ParseInt; using android::base::StartsWith; +using android::properties::BuildTrie; +using android::properties::PropertyInfoArea; +using android::properties::PropertyInfoEntry; #define ReturnIfAnyArgsEmpty() \ for (const auto& arg : args) { \ @@ -50,6 +53,26 @@ using android::base::StartsWith; namespace android { namespace init { +const PropertyInfoArea* property_info_area; + +Result InitializeHostPropertyInfoArea(const std::vector& property_infos) { + static std::string serialized_contexts; + std::string trie_error; + if (!BuildTrie(property_infos, "u:object_r:default_prop:s0", "string", &serialized_contexts, + &trie_error)) { + return Error() << "Unable to serialize property contexts: " << trie_error; + } + + property_info_area = reinterpret_cast(serialized_contexts.c_str()); + return {}; +} + +static Result check_stub(const BuiltinArguments& args) { + return {}; +} + +#include "generated_stub_builtin_function_map.h" + Result check_chown(const BuiltinArguments& args) { if (!args[1].empty()) { auto uid = DecodeUid(args[1]); diff --git a/init/check_builtins.h b/init/check_builtins.h index dc1b752e7..9b00a7c39 100644 --- a/init/check_builtins.h +++ b/init/check_builtins.h @@ -19,6 +19,10 @@ #include "builtin_arguments.h" #include "result.h" +#include + +#include + namespace android { namespace init { @@ -43,5 +47,8 @@ Result check_umount_all(const BuiltinArguments& args); Result check_wait(const BuiltinArguments& args); Result check_wait_for_prop(const BuiltinArguments& args); +Result InitializeHostPropertyInfoArea( + const std::vector& property_infos); + } // namespace init } // namespace android diff --git a/init/host_init_verifier.cpp b/init/host_init_verifier.cpp index 662185c44..f746ab954 100644 --- a/init/host_init_verifier.cpp +++ b/init/host_init_verifier.cpp @@ -14,8 +14,6 @@ // limitations under the License. // -#include "host_init_verifier.h" - #include #include #include @@ -36,6 +34,7 @@ #include #include #include +#include #include #include "action.h" @@ -57,9 +56,7 @@ using android::base::EndsWith; using android::base::ParseInt; using android::base::ReadFileToString; using android::base::Split; -using android::properties::BuildTrie; using android::properties::ParsePropertyInfoFile; -using android::properties::PropertyInfoArea; using android::properties::PropertyInfoEntry; static std::vector passwd_files; @@ -148,12 +145,6 @@ passwd* getpwnam(const char* login) { // NOLINT: implementing bad function. namespace android { namespace init { -static Result check_stub(const BuiltinArguments& args) { - return {}; -} - -#include "generated_stub_builtin_function_map.h" - void PrintUsage() { fprintf(stdout, R"(usage: host_init_verifier [options] @@ -196,8 +187,6 @@ Result ReadInterfaceInheritanceHierarchy() { return result; } -const PropertyInfoArea* property_info_area; - void HandlePropertyContexts(const std::string& filename, std::vector* property_infos) { auto file_contents = std::string(); @@ -288,16 +277,11 @@ int main(int argc, char** argv) { } SetKnownInterfaces(*interface_inheritance_hierarchy_map); - std::string serialized_contexts; - std::string trie_error; - if (!BuildTrie(property_infos, "u:object_r:default_prop:s0", "string", &serialized_contexts, - &trie_error)) { - LOG(ERROR) << "Unable to serialize property contexts: " << trie_error; + if (auto result = InitializeHostPropertyInfoArea(property_infos); !result.ok()) { + LOG(ERROR) << result.error(); return EXIT_FAILURE; } - property_info_area = reinterpret_cast(serialized_contexts.c_str()); - if (!partition_map.empty()) { std::vector vendor_prefixes; for (const auto& partition : {"vendor", "odm"}) { diff --git a/init/host_init_verifier.h b/init/host_init_verifier.h deleted file mode 100644 index 5d24f2a9b..000000000 --- a/init/host_init_verifier.h +++ /dev/null @@ -1,27 +0,0 @@ -/* - * Copyright (C) 2019 The Android Open Source Project - * - * 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. - */ - -#pragma once - -#include - -namespace android { -namespace init { - -extern const android::properties::PropertyInfoArea* property_info_area; - -} // namespace init -} // namespace android