Add check_builtins to libinit_host

This requires a bit of refactoring: moving things around.

libinit_host is used by host_apex_verifier which needs check_builtins as
well.

Bug: 325565247
Test: atest host-apex-verifier
Test: m out/target/product/vsoc_x86_64/host_init_verifier_output.txt
Change-Id: Ifed54dd2149afbab2bf63f7e42c410c2354895fc
This commit is contained in:
Jooyung Han 2024-02-16 17:23:34 +09:00
parent 1242da780f
commit 39e8be43eb
5 changed files with 36 additions and 51 deletions

View file

@ -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,

View file

@ -28,9 +28,9 @@
#include <android-base/parsedouble.h>
#include <android-base/parseint.h>
#include <android-base/strings.h>
#include <property_info_parser/property_info_parser.h>
#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<void> InitializeHostPropertyInfoArea(const std::vector<PropertyInfoEntry>& 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<const PropertyInfoArea*>(serialized_contexts.c_str());
return {};
}
static Result<void> check_stub(const BuiltinArguments& args) {
return {};
}
#include "generated_stub_builtin_function_map.h"
Result<void> check_chown(const BuiltinArguments& args) {
if (!args[1].empty()) {
auto uid = DecodeUid(args[1]);

View file

@ -19,6 +19,10 @@
#include "builtin_arguments.h"
#include "result.h"
#include <vector>
#include <property_info_serializer/property_info_serializer.h>
namespace android {
namespace init {
@ -43,5 +47,8 @@ Result<void> check_umount_all(const BuiltinArguments& args);
Result<void> check_wait(const BuiltinArguments& args);
Result<void> check_wait_for_prop(const BuiltinArguments& args);
Result<void> InitializeHostPropertyInfoArea(
const std::vector<properties::PropertyInfoEntry>& property_infos);
} // namespace init
} // namespace android

View file

@ -14,8 +14,6 @@
// limitations under the License.
//
#include "host_init_verifier.h"
#include <errno.h>
#include <getopt.h>
#include <pwd.h>
@ -36,6 +34,7 @@
#include <android-base/strings.h>
#include <generated_android_ids.h>
#include <hidl/metadata.h>
#include <property_info_parser/property_info_parser.h>
#include <property_info_serializer/property_info_serializer.h>
#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<std::string> passwd_files;
@ -148,12 +145,6 @@ passwd* getpwnam(const char* login) { // NOLINT: implementing bad function.
namespace android {
namespace init {
static Result<void> 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<InterfaceInheritanceHierarchyMap> ReadInterfaceInheritanceHierarchy() {
return result;
}
const PropertyInfoArea* property_info_area;
void HandlePropertyContexts(const std::string& filename,
std::vector<PropertyInfoEntry>* 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<const PropertyInfoArea*>(serialized_contexts.c_str());
if (!partition_map.empty()) {
std::vector<std::string> vendor_prefixes;
for (const auto& partition : {"vendor", "odm"}) {

View file

@ -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 <property_info_parser/property_info_parser.h>
namespace android {
namespace init {
extern const android::properties::PropertyInfoArea* property_info_area;
} // namespace init
} // namespace android