2018-01-19 23:25:48 +01:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2018 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.
|
|
|
|
*/
|
|
|
|
|
2018-11-06 23:12:05 +01:00
|
|
|
#include "builtins.h"
|
|
|
|
#include "first_stage_init.h"
|
2018-01-19 23:25:48 +01:00
|
|
|
#include "init.h"
|
2018-11-06 23:12:05 +01:00
|
|
|
#include "selinux.h"
|
|
|
|
#include "subcontext.h"
|
|
|
|
#include "ueventd.h"
|
|
|
|
|
|
|
|
#include <android-base/logging.h>
|
|
|
|
|
|
|
|
#if __has_feature(address_sanitizer)
|
|
|
|
#include <sanitizer/asan_interface.h>
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#if __has_feature(address_sanitizer)
|
|
|
|
// Load asan.options if it exists since these are not yet in the environment.
|
|
|
|
// Always ensure detect_container_overflow=0 as there are false positives with this check.
|
|
|
|
// Always ensure abort_on_error=1 to ensure we reboot to bootloader for development builds.
|
|
|
|
extern "C" const char* __asan_default_options() {
|
|
|
|
return "include_if_exists=/system/asan.options:detect_container_overflow=0:abort_on_error=1";
|
|
|
|
}
|
|
|
|
|
|
|
|
__attribute__((no_sanitize("address", "memory", "thread", "undefined"))) extern "C" void
|
|
|
|
__sanitizer_report_error_summary(const char* summary) {
|
|
|
|
LOG(ERROR) << "Init (error summary): " << summary;
|
|
|
|
}
|
|
|
|
|
|
|
|
__attribute__((no_sanitize("address", "memory", "thread", "undefined"))) static void
|
|
|
|
AsanReportCallback(const char* str) {
|
|
|
|
LOG(ERROR) << "Init: " << str;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
using namespace android::init;
|
2018-01-19 23:25:48 +01:00
|
|
|
|
|
|
|
int main(int argc, char** argv) {
|
2018-11-06 23:12:05 +01:00
|
|
|
#if __has_feature(address_sanitizer)
|
|
|
|
__asan_set_error_report_callback(AsanReportCallback);
|
|
|
|
#endif
|
2020-07-07 00:26:49 +02:00
|
|
|
// Boost prio which will be restored later
|
|
|
|
setpriority(PRIO_PROCESS, 0, -20);
|
2018-11-06 23:12:05 +01:00
|
|
|
if (!strcmp(basename(argv[0]), "ueventd")) {
|
|
|
|
return ueventd_main(argc, argv);
|
|
|
|
}
|
|
|
|
|
2019-01-05 02:31:28 +01:00
|
|
|
if (argc > 1) {
|
|
|
|
if (!strcmp(argv[1], "subcontext")) {
|
|
|
|
android::base::InitLogging(argv, &android::base::KernelLogger);
|
2019-07-23 01:05:36 +02:00
|
|
|
const BuiltinFunctionMap& function_map = GetBuiltinFunctionMap();
|
2018-11-06 23:12:05 +01:00
|
|
|
|
2019-01-05 02:31:28 +01:00
|
|
|
return SubcontextMain(argc, argv, &function_map);
|
|
|
|
}
|
2018-11-06 23:12:05 +01:00
|
|
|
|
2019-01-05 02:31:28 +01:00
|
|
|
if (!strcmp(argv[1], "selinux_setup")) {
|
|
|
|
return SetupSelinux(argv);
|
|
|
|
}
|
2018-11-06 23:12:05 +01:00
|
|
|
|
2019-01-05 02:31:28 +01:00
|
|
|
if (!strcmp(argv[1], "second_stage")) {
|
|
|
|
return SecondStageMain(argc, argv);
|
|
|
|
}
|
2018-11-06 23:12:05 +01:00
|
|
|
}
|
|
|
|
|
2019-01-05 02:31:28 +01:00
|
|
|
return FirstStageMain(argc, argv);
|
2018-01-19 23:25:48 +01:00
|
|
|
}
|