diff options
25 files changed, 177 insertions, 263 deletions
diff --git a/cmds/atrace/atrace.cpp b/cmds/atrace/atrace.cpp index a4b00f8e0c..587d25f9ed 100644 --- a/cmds/atrace/atrace.cpp +++ b/cmds/atrace/atrace.cpp @@ -1467,10 +1467,11 @@ int main(int argc, char **argv) // Reset the trace buffer size to 1. if (traceStop) { - cleanUpVendorTracing(); cleanUpUserspaceTracing(); - if (!onlyUserspace) + if (!onlyUserspace) { + cleanUpVendorTracing(); cleanUpKernelTracing(); + } } return g_traceAborted ? 1 : 0; diff --git a/cmds/bugreport/bugreport.cpp b/cmds/bugreport/bugreport.cpp index 917c8132b7..840ae473bc 100644 --- a/cmds/bugreport/bugreport.cpp +++ b/cmds/bugreport/bugreport.cpp @@ -37,7 +37,7 @@ int main() { property_set("ctl.start", "dumpstate"); // Socket will not be available until service starts. - int s; + int s = -1; for (int i = 0; i < 20; i++) { s = socket_local_client("dumpstate", ANDROID_SOCKET_NAMESPACE_RESERVED, SOCK_STREAM); diff --git a/cmds/bugreportz/main.cpp b/cmds/bugreportz/main.cpp index 74a95b0b57..40346bee1f 100644 --- a/cmds/bugreportz/main.cpp +++ b/cmds/bugreportz/main.cpp @@ -72,7 +72,7 @@ int main(int argc, char* argv[]) { property_set("ctl.start", "dumpstatez"); // Socket will not be available until service starts. - int s; + int s = -1; for (int i = 0; i < 20; i++) { s = socket_local_client("dumpstate", ANDROID_SOCKET_NAMESPACE_RESERVED, SOCK_STREAM); if (s >= 0) break; diff --git a/cmds/dumpstate/DumpstateService.cpp b/cmds/dumpstate/DumpstateService.cpp index ddae9ea8f6..37ba4f906e 100644 --- a/cmds/dumpstate/DumpstateService.cpp +++ b/cmds/dumpstate/DumpstateService.cpp @@ -151,15 +151,15 @@ binder::Status DumpstateService::startBugreport(int32_t calling_uid, signalErrorAndExit(listener, IDumpstateListener::BUGREPORT_ERROR_INVALID_INPUT); } - if (bugreport_fd.get() == -1 || screenshot_fd.get() == -1) { - // TODO(b/111441001): screenshot fd should be optional + std::unique_ptr<Dumpstate::DumpOptions> options = std::make_unique<Dumpstate::DumpOptions>(); + options->Initialize(static_cast<Dumpstate::BugreportMode>(bugreport_mode), bugreport_fd, + screenshot_fd); + + if (bugreport_fd.get() == -1 || (options->do_fb && screenshot_fd.get() == -1)) { MYLOGE("Invalid filedescriptor"); signalErrorAndExit(listener, IDumpstateListener::BUGREPORT_ERROR_INVALID_INPUT); } - std::unique_ptr<Dumpstate::DumpOptions> options = std::make_unique<Dumpstate::DumpOptions>(); - options->Initialize(static_cast<Dumpstate::BugreportMode>(bugreport_mode), bugreport_fd, - screenshot_fd); ds_ = &(Dumpstate::GetInstance()); ds_->SetOptions(std::move(options)); diff --git a/cmds/dumpstate/binder/android/os/IDumpstate.aidl b/cmds/dumpstate/binder/android/os/IDumpstate.aidl index 347856ddcb..cb2d8b8d2c 100644 --- a/cmds/dumpstate/binder/android/os/IDumpstate.aidl +++ b/cmds/dumpstate/binder/android/os/IDumpstate.aidl @@ -73,7 +73,7 @@ interface IDumpstate { * @param callingUid UID of the original application that requested the report. * @param callingPackage package of the original application that requested the report. * @param bugreportFd the file to which the zipped bugreport should be written - * @param screenshotFd the file to which screenshot should be written; optional + * @param screenshotFd the file to which screenshot should be written * @param bugreportMode the mode that specifies other run time options; must be one of above * @param listener callback for updates; optional */ diff --git a/cmds/dumpstate/dumpstate.cpp b/cmds/dumpstate/dumpstate.cpp index 4ac7b689cf..8ba95266b6 100644 --- a/cmds/dumpstate/dumpstate.cpp +++ b/cmds/dumpstate/dumpstate.cpp @@ -94,7 +94,6 @@ using android::os::IDumpstateListener; using android::os::dumpstate::CommandOptions; using android::os::dumpstate::DumpFileToFd; using android::os::dumpstate::DumpstateSectionReporter; -using android::os::dumpstate::GetPidByName; using android::os::dumpstate::PropertiesHelper; typedef Dumpstate::ConsentCallback::ConsentResult UserConsentResult; @@ -421,108 +420,6 @@ static void dump_dev_files(const char *title, const char *driverpath, const char closedir(d); } - - -// dump anrd's trace and add to the zip file. -// 1. check if anrd is running on this device. -// 2. send a SIGUSR1 to its pid which will dump anrd's trace. -// 3. wait until the trace generation completes and add to the zip file. -static bool dump_anrd_trace() { - unsigned int pid; - char buf[50], path[PATH_MAX]; - struct dirent *trace; - struct stat st; - DIR *trace_dir; - int retry = 5; - long max_ctime = 0, old_mtime; - long long cur_size = 0; - const char *trace_path = "/data/misc/anrd/"; - - if (!ds.IsZipping()) { - MYLOGE("Not dumping anrd trace because it's not a zipped bugreport\n"); - return false; - } - - // find anrd's pid if it is running. - pid = GetPidByName("/system/bin/anrd"); - - if (pid > 0) { - if (stat(trace_path, &st) == 0) { - old_mtime = st.st_mtime; - } else { - MYLOGE("Failed to find: %s\n", trace_path); - return false; - } - - // send SIGUSR1 to the anrd to generate a trace. - sprintf(buf, "%u", pid); - if (RunCommand("ANRD_DUMP", {"kill", "-SIGUSR1", buf}, - CommandOptions::WithTimeout(1).Build())) { - MYLOGE("anrd signal timed out. Please manually collect trace\n"); - return false; - } - - while (retry-- > 0 && old_mtime == st.st_mtime) { - sleep(1); - stat(trace_path, &st); - } - - if (retry < 0 && old_mtime == st.st_mtime) { - MYLOGE("Failed to stat %s or trace creation timeout\n", trace_path); - return false; - } - - // identify the trace file by its creation time. - if (!(trace_dir = opendir(trace_path))) { - MYLOGE("Can't open trace file under %s\n", trace_path); - } - while ((trace = readdir(trace_dir))) { - if (strcmp(trace->d_name, ".") == 0 - || strcmp(trace->d_name, "..") == 0) { - continue; - } - sprintf(path, "%s%s", trace_path, trace->d_name); - if (stat(path, &st) == 0) { - if (st.st_ctime > max_ctime) { - max_ctime = st.st_ctime; - sprintf(buf, "%s", trace->d_name); - } - } - } - closedir(trace_dir); - - // Wait until the dump completes by checking the size of the trace. - if (max_ctime > 0) { - sprintf(path, "%s%s", trace_path, buf); - while(true) { - sleep(1); - if (stat(path, &st) == 0) { - if (st.st_size == cur_size) { - break; - } else if (st.st_size > cur_size) { - cur_size = st.st_size; - } else { - return false; - } - } else { - MYLOGE("Cant stat() %s anymore\n", path); - return false; - } - } - // Add to the zip file. - if (!ds.AddZipEntry("anrd_trace.txt", path)) { - MYLOGE("Unable to add anrd_trace file %s to zip file\n", path); - } else { - android::os::UnlinkAndLogOnError(path); - return true; - } - } else { - MYLOGE("Can't stats any trace file under %s\n", trace_path); - } - } - return false; -} - static bool skip_not_stat(const char *path) { static const char stat[] = "/stat"; size_t len = strlen(path); @@ -1380,7 +1277,7 @@ static Dumpstate::RunStatus dumpstate() { /* Dump Bluetooth HCI logs */ ds.AddDir("/data/misc/bluetooth/logs", true); - if (!ds.do_early_screenshot_) { + if (ds.options_->do_fb && !ds.do_early_screenshot_) { MYLOGI("taking late screenshot\n"); ds.TakeScreenshot(); } @@ -1428,7 +1325,6 @@ static Dumpstate::RunStatus dumpstate() { DumpFile("BINDER STATS", "/sys/kernel/debug/binder/stats"); DumpFile("BINDER STATE", "/sys/kernel/debug/binder/state"); - RunDumpsys("WINSCOPE TRACE", {"window", "trace"}); /* Add window and surface trace files. */ if (!PropertiesHelper::IsUserBuild()) { ds.AddDir(WMTRACE_DATA_DIR, false); @@ -1539,9 +1435,6 @@ static Dumpstate::RunStatus dumpstate() { * with the caller. */ static Dumpstate::RunStatus DumpstateDefault() { - // Try to dump anrd trace if the daemon is running. - dump_anrd_trace(); - // Invoking the following dumpsys calls before DumpTraces() to try and // keep the system stats as close to its initial state as possible. RUN_SLOW_FUNCTION_WITH_CONSENT_CHECK(RunDumpsysCritical); @@ -2626,13 +2519,8 @@ Dumpstate::RunStatus Dumpstate::RunInternal(int32_t calling_uid, } if (options_->do_fb && do_early_screenshot_) { - if (screenshot_path_.empty()) { - // should not have happened - MYLOGE("INTERNAL ERROR: skipping early screenshot because path was not set\n"); - } else { - MYLOGI("taking early screenshot\n"); - TakeScreenshot(); - } + MYLOGI("taking early screenshot\n"); + TakeScreenshot(); } if (options_->do_zip_file && zip_file != nullptr) { diff --git a/cmds/dumpstate/tests/dumpstate_smoke_test.cpp b/cmds/dumpstate/tests/dumpstate_smoke_test.cpp index fc3642c912..5bde7db287 100644 --- a/cmds/dumpstate/tests/dumpstate_smoke_test.cpp +++ b/cmds/dumpstate/tests/dumpstate_smoke_test.cpp @@ -208,7 +208,7 @@ class ZippedBugReportContentsTest : public Test { void FileExists(const char* filename, uint32_t minsize, uint32_t maxsize) { ZipEntry entry; - EXPECT_EQ(FindEntry(handle, ZipString(filename), &entry), 0); + EXPECT_EQ(FindEntry(handle, filename, &entry), 0); EXPECT_GT(entry.uncompressed_length, minsize); EXPECT_LT(entry.uncompressed_length, maxsize); } @@ -217,7 +217,7 @@ class ZippedBugReportContentsTest : public Test { TEST_F(ZippedBugReportContentsTest, ContainsMainEntry) { ZipEntry mainEntryLoc; // contains main entry name file - EXPECT_EQ(FindEntry(handle, ZipString("main_entry.txt"), &mainEntryLoc), 0); + EXPECT_EQ(FindEntry(handle, "main_entry.txt", &mainEntryLoc), 0); char* buf = new char[mainEntryLoc.uncompressed_length]; ExtractToMemory(handle, &mainEntryLoc, (uint8_t*)buf, mainEntryLoc.uncompressed_length); @@ -230,7 +230,7 @@ TEST_F(ZippedBugReportContentsTest, ContainsMainEntry) { TEST_F(ZippedBugReportContentsTest, ContainsVersion) { ZipEntry entry; // contains main entry name file - EXPECT_EQ(FindEntry(handle, ZipString("version.txt"), &entry), 0); + EXPECT_EQ(FindEntry(handle, "version.txt", &entry), 0); char* buf = new char[entry.uncompressed_length + 1]; ExtractToMemory(handle, &entry, (uint8_t*)buf, entry.uncompressed_length); diff --git a/cmds/dumpstate/tests/dumpstate_test.cpp b/cmds/dumpstate/tests/dumpstate_test.cpp index 71d15f4761..c5d01fdf25 100644 --- a/cmds/dumpstate/tests/dumpstate_test.cpp +++ b/cmds/dumpstate/tests/dumpstate_test.cpp @@ -664,7 +664,8 @@ TEST_F(DumpstateTest, RunCommandNoTitle) { TEST_F(DumpstateTest, RunCommandWithTitle) { EXPECT_EQ(0, RunCommand("I AM GROOT", {kSimpleCommand})); EXPECT_THAT(err, StrEq("stderr\n")); - // We don't know the exact duration, so we check the prefix and suffix + // The duration may not get output, depending on how long it takes, + // so we just check the prefix. EXPECT_THAT(out, StartsWith("------ I AM GROOT (" + kSimpleCommand + ") ------\nstdout\n")); } @@ -699,7 +700,8 @@ TEST_F(DumpstateTest, RunCommandWithMultipleArgs) { TEST_F(DumpstateTest, RunCommandDryRun) { SetDryRun(true); EXPECT_EQ(0, RunCommand("I AM GROOT", {kSimpleCommand})); - // We don't know the exact duration, so we check the prefix and suffix + // The duration may not get output, depending on how long it takes, + // so we just check the prefix. EXPECT_THAT(out, StartsWith("------ I AM GROOT (" + kSimpleCommand + ") ------\n\t(skipped on dry run)\n")); EXPECT_THAT(err, IsEmpty()); @@ -1037,7 +1039,8 @@ TEST_F(DumpstateTest, DumpFileNotFoundNoTitle) { TEST_F(DumpstateTest, DumpFileNotFoundWithTitle) { EXPECT_EQ(-1, DumpFile("Y U NO EXIST?", "/I/cant/believe/I/exist")); EXPECT_THAT(err, IsEmpty()); - // We don't know the exact duration, so we check the prefix and suffix + // The duration may not get output, depending on how long it takes, + // so we just check the prefix. EXPECT_THAT(out, StartsWith("*** Error dumping /I/cant/believe/I/exist (Y U NO EXIST?): No " "such file or directory\n")); } diff --git a/cmds/installd/dexopt.cpp b/cmds/installd/dexopt.cpp index dbb4f22372..7eee749be9 100644 --- a/cmds/installd/dexopt.cpp +++ b/cmds/installd/dexopt.cpp @@ -2117,14 +2117,20 @@ int dexopt(const char* dex_path, uid_t uid, const char* pkgname, const char* ins // Create a swap file if necessary. unique_fd swap_fd = maybe_open_dexopt_swap_file(out_oat_path); - // Create the app image file if needed. - Dex2oatFileWrapper image_fd = maybe_open_app_image( - out_oat_path, generate_app_image, is_public, uid, is_secondary_dex); - // Open the reference profile if needed. Dex2oatFileWrapper reference_profile_fd = maybe_open_reference_profile( pkgname, dex_path, profile_name, profile_guided, is_public, uid, is_secondary_dex); + if (reference_profile_fd.get() == -1) { + // We don't create an app image without reference profile since there is no speedup from + // loading it in that case and instead will be a small overhead. + generate_app_image = false; + } + + // Create the app image file if needed. + Dex2oatFileWrapper image_fd = maybe_open_app_image( + out_oat_path, generate_app_image, is_public, uid, is_secondary_dex); + unique_fd dex_metadata_fd; if (dex_metadata_path != nullptr) { dex_metadata_fd.reset(TEMP_FAILURE_RETRY(open(dex_metadata_path, O_RDONLY | O_NOFOLLOW))); diff --git a/cmds/installd/tests/Android.bp b/cmds/installd/tests/Android.bp index aa79fdc100..bd45005fd1 100644 --- a/cmds/installd/tests/Android.bp +++ b/cmds/installd/tests/Android.bp @@ -89,6 +89,8 @@ cc_test { "libinstalld", "liblog", "liblogwrap", + "libziparchive", + "libz", ], test_config: "installd_dexopt_test.xml", } diff --git a/cmds/installd/tests/installd_dexopt_test.cpp b/cmds/installd/tests/installd_dexopt_test.cpp index fa2b0d9660..13fd0677e5 100644 --- a/cmds/installd/tests/installd_dexopt_test.cpp +++ b/cmds/installd/tests/installd_dexopt_test.cpp @@ -41,6 +41,7 @@ #include "globals.h" #include "tests/test_utils.h" #include "utils.h" +#include "ziparchive/zip_writer.h" using android::base::ReadFully; using android::base::unique_fd; @@ -195,6 +196,7 @@ protected: std::unique_ptr<std::string> volume_uuid_; std::string package_name_; std::string apk_path_; + std::string empty_dm_file_; std::string app_apk_dir_; std::string app_private_dir_ce_; std::string app_private_dir_de_; @@ -260,6 +262,26 @@ protected: << " : " << error_msg; } + // Create an empty dm file. + empty_dm_file_ = apk_path_ + ".dm"; + { + int fd = open(empty_dm_file_.c_str(), O_WRONLY | O_CREAT, S_IRUSR | S_IWUSR); + if (fd < 0) { + return ::testing::AssertionFailure() << "Could not open " << empty_dm_file_; + } + FILE* file = fdopen(fd, "wb"); + if (file == nullptr) { + return ::testing::AssertionFailure() << "Null file for " << empty_dm_file_ + << " fd=" << fd; + } + ZipWriter writer(file); + // Add vdex to zip. + writer.StartEntry("primary.prof", ZipWriter::kCompress); + writer.FinishEntry(); + writer.Finish(); + close(fd); + } + // Create the app user data. status = service_->createAppData( volume_uuid_, @@ -479,7 +501,7 @@ protected: bool prof_result; ASSERT_BINDER_SUCCESS(service_->prepareAppProfile( package_name_, kTestUserId, kTestAppId, *profile_name_ptr, apk_path_, - /*dex_metadata*/ nullptr, &prof_result)); + dm_path_ptr, &prof_result)); ASSERT_TRUE(prof_result); binder::Status result = service_->dexopt(apk_path_, @@ -645,7 +667,9 @@ TEST_F(DexoptTest, DexoptPrimaryProfileNonPublic) { DEXOPT_BOOTCOMPLETE | DEXOPT_PROFILE_GUIDED | DEXOPT_GENERATE_APP_IMAGE, app_oat_dir_.c_str(), kTestAppGid, - DEX2OAT_FROM_SCRATCH); + DEX2OAT_FROM_SCRATCH, + /*binder_result=*/nullptr, + empty_dm_file_.c_str()); } TEST_F(DexoptTest, DexoptPrimaryProfilePublic) { @@ -655,7 +679,9 @@ TEST_F(DexoptTest, DexoptPrimaryProfilePublic) { DEXOPT_GENERATE_APP_IMAGE, app_oat_dir_.c_str(), kTestAppGid, - DEX2OAT_FROM_SCRATCH); + DEX2OAT_FROM_SCRATCH, + /*binder_result=*/nullptr, + empty_dm_file_.c_str()); } TEST_F(DexoptTest, DexoptPrimaryBackgroundOk) { @@ -665,7 +691,9 @@ TEST_F(DexoptTest, DexoptPrimaryBackgroundOk) { DEXOPT_GENERATE_APP_IMAGE, app_oat_dir_.c_str(), kTestAppGid, - DEX2OAT_FROM_SCRATCH); + DEX2OAT_FROM_SCRATCH, + /*binder_result=*/nullptr, + empty_dm_file_.c_str()); } TEST_F(DexoptTest, ResolveStartupConstStrings) { @@ -684,7 +712,9 @@ TEST_F(DexoptTest, ResolveStartupConstStrings) { DEXOPT_GENERATE_APP_IMAGE, app_oat_dir_.c_str(), kTestAppGid, - DEX2OAT_FROM_SCRATCH); + DEX2OAT_FROM_SCRATCH, + /*binder_result=*/nullptr, + empty_dm_file_.c_str()); run_cmd_and_process_output( "oatdump --header-only --oat-file=" + odex, [&](const std::string& line) { @@ -701,7 +731,9 @@ TEST_F(DexoptTest, ResolveStartupConstStrings) { DEXOPT_GENERATE_APP_IMAGE, app_oat_dir_.c_str(), kTestAppGid, - DEX2OAT_FROM_SCRATCH); + DEX2OAT_FROM_SCRATCH, + /*binder_result=*/nullptr, + empty_dm_file_.c_str()); run_cmd_and_process_output( "oatdump --header-only --oat-file=" + odex, [&](const std::string& line) { diff --git a/include/audiomanager/OWNERS b/include/audiomanager/OWNERS new file mode 100644 index 0000000000..2bd527cc3f --- /dev/null +++ b/include/audiomanager/OWNERS @@ -0,0 +1,2 @@ +elaurent@google.com +jmtrivi@google.com diff --git a/libs/binder/IPCThreadState.cpp b/libs/binder/IPCThreadState.cpp index 9a561cba64..a2d10ab0ab 100644 --- a/libs/binder/IPCThreadState.cpp +++ b/libs/binder/IPCThreadState.cpp @@ -33,6 +33,7 @@ #include <private/binder/binder_module.h> #include <private/binder/Static.h> +#include <atomic> #include <errno.h> #include <inttypes.h> #include <pthread.h> @@ -116,7 +117,7 @@ static const int64_t kWorkSourcePropagatedBitIndex = 32; static const char* getReturnString(uint32_t cmd) { - size_t idx = cmd & 0xff; + size_t idx = cmd & _IOC_NRMASK; if (idx < sizeof(kReturnStrings) / sizeof(kReturnStrings[0])) return kReturnStrings[idx]; else @@ -278,14 +279,14 @@ static const void* printCommand(TextOutput& out, const void* _cmd) } static pthread_mutex_t gTLSMutex = PTHREAD_MUTEX_INITIALIZER; -static bool gHaveTLS = false; +static std::atomic<bool> gHaveTLS(false); static pthread_key_t gTLS = 0; -static bool gShutdown = false; -static bool gDisableBackgroundScheduling = false; +static std::atomic<bool> gShutdown = false; +static std::atomic<bool> gDisableBackgroundScheduling = false; IPCThreadState* IPCThreadState::self() { - if (gHaveTLS) { + if (gHaveTLS.load(std::memory_order_acquire)) { restart: const pthread_key_t k = gTLS; IPCThreadState* st = (IPCThreadState*)pthread_getspecific(k); @@ -293,13 +294,14 @@ restart: return new IPCThreadState; } - if (gShutdown) { + // Racey, heuristic test for simultaneous shutdown. + if (gShutdown.load(std::memory_order_relaxed)) { ALOGW("Calling IPCThreadState::self() during shutdown is dangerous, expect a crash.\n"); return nullptr; } pthread_mutex_lock(&gTLSMutex); - if (!gHaveTLS) { + if (!gHaveTLS.load(std::memory_order_relaxed)) { int key_create_value = pthread_key_create(&gTLS, threadDestructor); if (key_create_value != 0) { pthread_mutex_unlock(&gTLSMutex); @@ -307,7 +309,7 @@ restart: strerror(key_create_value)); return nullptr; } - gHaveTLS = true; + gHaveTLS.store(true, std::memory_order_release); } pthread_mutex_unlock(&gTLSMutex); goto restart; @@ -315,7 +317,7 @@ restart: IPCThreadState* IPCThreadState::selfOrNull() { - if (gHaveTLS) { + if (gHaveTLS.load(std::memory_order_acquire)) { const pthread_key_t k = gTLS; IPCThreadState* st = (IPCThreadState*)pthread_getspecific(k); return st; @@ -325,9 +327,9 @@ IPCThreadState* IPCThreadState::selfOrNull() void IPCThreadState::shutdown() { - gShutdown = true; + gShutdown.store(true, std::memory_order_relaxed); - if (gHaveTLS) { + if (gHaveTLS.load(std::memory_order_acquire)) { // XXX Need to wait for all thread pool threads to exit! IPCThreadState* st = (IPCThreadState*)pthread_getspecific(gTLS); if (st) { @@ -335,18 +337,18 @@ void IPCThreadState::shutdown() pthread_setspecific(gTLS, nullptr); } pthread_key_delete(gTLS); - gHaveTLS = false; + gHaveTLS.store(false, std::memory_order_release); } } void IPCThreadState::disableBackgroundScheduling(bool disable) { - gDisableBackgroundScheduling = disable; + gDisableBackgroundScheduling.store(disable, std::memory_order_relaxed); } bool IPCThreadState::backgroundSchedulingDisabled() { - return gDisableBackgroundScheduling; + return gDisableBackgroundScheduling.load(std::memory_order_relaxed); } sp<ProcessState> IPCThreadState::process() @@ -674,11 +676,11 @@ status_t IPCThreadState::transact(int32_t handle, if ((flags & TF_ONE_WAY) == 0) { if (UNLIKELY(mCallRestriction != ProcessState::CallRestriction::NONE)) { if (mCallRestriction == ProcessState::CallRestriction::ERROR_IF_NOT_ONEWAY) { - ALOGE("Process making non-oneway call but is restricted."); + ALOGE("Process making non-oneway call (code: %u) but is restricted.", code); CallStack::logStack("non-oneway call", CallStack::getCurrent(10).get(), ANDROID_LOG_ERROR); } else /* FATAL_IF_NOT_ONEWAY */ { - LOG_ALWAYS_FATAL("Process may not make oneway calls."); + LOG_ALWAYS_FATAL("Process may not make oneway calls (code: %u).", code); } } diff --git a/libs/binder/IServiceManager.cpp b/libs/binder/IServiceManager.cpp index 4ba6c2a923..0203d41992 100644 --- a/libs/binder/IServiceManager.cpp +++ b/libs/binder/IServiceManager.cpp @@ -36,6 +36,9 @@ namespace android { sp<IServiceManager> defaultServiceManager() { + static Mutex gDefaultServiceManagerLock; + static sp<IServiceManager> gDefaultServiceManager; + if (gDefaultServiceManager != nullptr) return gDefaultServiceManager; { @@ -74,10 +77,13 @@ bool checkCallingPermission(const String16& permission, int32_t* outPid, int32_t bool checkPermission(const String16& permission, pid_t pid, uid_t uid) { + static Mutex gPermissionControllerLock; + static sp<IPermissionController> gPermissionController; + sp<IPermissionController> pc; - gDefaultServiceManagerLock.lock(); + gPermissionControllerLock.lock(); pc = gPermissionController; - gDefaultServiceManagerLock.unlock(); + gPermissionControllerLock.unlock(); int64_t startTime = 0; @@ -101,11 +107,11 @@ bool checkPermission(const String16& permission, pid_t pid, uid_t uid) } // Object is dead! - gDefaultServiceManagerLock.lock(); + gPermissionControllerLock.lock(); if (gPermissionController == pc) { gPermissionController = nullptr; } - gDefaultServiceManagerLock.unlock(); + gPermissionControllerLock.unlock(); } // Need to retrieve the permission controller. @@ -121,9 +127,9 @@ bool checkPermission(const String16& permission, pid_t pid, uid_t uid) } else { pc = interface_cast<IPermissionController>(binder); // Install the new permission controller, and try again. - gDefaultServiceManagerLock.lock(); + gPermissionControllerLock.lock(); gPermissionController = pc; - gDefaultServiceManagerLock.unlock(); + gPermissionControllerLock.unlock(); } } } @@ -142,6 +148,8 @@ public: virtual sp<IBinder> getService(const String16& name) const { + static bool gSystemBootCompleted = false; + sp<IBinder> svc = checkService(name); if (svc != nullptr) return svc; diff --git a/libs/binder/Parcel.cpp b/libs/binder/Parcel.cpp index 753d5b4698..0e8945c03e 100644 --- a/libs/binder/Parcel.cpp +++ b/libs/binder/Parcel.cpp @@ -93,7 +93,7 @@ enum { BLOB_ASHMEM_MUTABLE = 2, }; -void acquire_object(const sp<ProcessState>& proc, +static void acquire_object(const sp<ProcessState>& proc, const flat_binder_object& obj, const void* who, size_t* outAshmemSize) { switch (obj.hdr.type) { @@ -135,12 +135,6 @@ void acquire_object(const sp<ProcessState>& proc, ALOGD("Invalid object type 0x%08x", obj.hdr.type); } -void acquire_object(const sp<ProcessState>& proc, - const flat_binder_object& obj, const void* who) -{ - acquire_object(proc, obj, who, nullptr); -} - static void release_object(const sp<ProcessState>& proc, const flat_binder_object& obj, const void* who, size_t* outAshmemSize) { @@ -189,19 +183,13 @@ static void release_object(const sp<ProcessState>& proc, ALOGE("Invalid object type 0x%08x", obj.hdr.type); } -void release_object(const sp<ProcessState>& proc, - const flat_binder_object& obj, const void* who) -{ - release_object(proc, obj, who, nullptr); -} - inline static status_t finish_flatten_binder( const sp<IBinder>& /*binder*/, const flat_binder_object& flat, Parcel* out) { return out->writeObject(flat, false); } -status_t flatten_binder(const sp<ProcessState>& /*proc*/, +static status_t flatten_binder(const sp<ProcessState>& /*proc*/, const sp<IBinder>& binder, Parcel* out) { flat_binder_object obj; @@ -243,7 +231,7 @@ status_t flatten_binder(const sp<ProcessState>& /*proc*/, return finish_flatten_binder(binder, obj, out); } -status_t flatten_binder(const sp<ProcessState>& /*proc*/, +static status_t flatten_binder(const sp<ProcessState>& /*proc*/, const wp<IBinder>& binder, Parcel* out) { flat_binder_object obj; @@ -299,7 +287,7 @@ inline static status_t finish_unflatten_binder( return NO_ERROR; } -status_t unflatten_binder(const sp<ProcessState>& proc, +static status_t unflatten_binder(const sp<ProcessState>& proc, const Parcel& in, sp<IBinder>* out) { const flat_binder_object* flat = in.readObject(false); @@ -318,7 +306,7 @@ status_t unflatten_binder(const sp<ProcessState>& proc, return BAD_TYPE; } -status_t unflatten_binder(const sp<ProcessState>& proc, +static status_t unflatten_binder(const sp<ProcessState>& proc, const Parcel& in, wp<IBinder>* out) { const flat_binder_object* flat = in.readObject(false); diff --git a/libs/binder/ProcessState.cpp b/libs/binder/ProcessState.cpp index 63f49ddba7..2d156df56b 100644 --- a/libs/binder/ProcessState.cpp +++ b/libs/binder/ProcessState.cpp @@ -40,7 +40,7 @@ #include <sys/stat.h> #include <sys/types.h> -#define BINDER_VM_SIZE ((1 * 1024 * 1024) - sysconf(_SC_PAGE_SIZE) * 2) +#define DEFAULT_BINDER_VM_SIZE ((1 * 1024 * 1024) - sysconf(_SC_PAGE_SIZE) * 2) #define DEFAULT_MAX_BINDER_THREADS 15 #ifdef __ANDROID_VNDK__ @@ -77,7 +77,13 @@ sp<ProcessState> ProcessState::self() if (gProcess != nullptr) { return gProcess; } - gProcess = new ProcessState(kDefaultDriver); + gProcess = new ProcessState(kDefaultDriver, DEFAULT_BINDER_VM_SIZE); + return gProcess; +} + +sp<ProcessState> ProcessState::selfOrNull() +{ + Mutex::Autolock _l(gProcessMutex); return gProcess; } @@ -98,13 +104,19 @@ sp<ProcessState> ProcessState::initWithDriver(const char* driver) driver = "/dev/binder"; } - gProcess = new ProcessState(driver); + gProcess = new ProcessState(driver, DEFAULT_BINDER_VM_SIZE); return gProcess; } -sp<ProcessState> ProcessState::selfOrNull() -{ +sp<ProcessState> ProcessState::initWithMmapSize(size_t mmap_size) { Mutex::Autolock _l(gProcessMutex); + if (gProcess != nullptr) { + LOG_ALWAYS_FATAL_IF(mmap_size != gProcess->getMmapSize(), + "ProcessState already initialized with a different mmap size."); + return gProcess; + } + + gProcess = new ProcessState(kDefaultDriver, mmap_size); return gProcess; } @@ -237,6 +249,10 @@ ssize_t ProcessState::getKernelReferences(size_t buf_count, uintptr_t* buf) return count; } +size_t ProcessState::getMmapSize() { + return mMmapSize; +} + void ProcessState::setCallRestriction(CallRestriction restriction) { LOG_ALWAYS_FATAL_IF(IPCThreadState::selfOrNull(), "Call restrictions must be set before the threadpool is started."); @@ -421,7 +437,7 @@ static int open_driver(const char *driver) return fd; } -ProcessState::ProcessState(const char *driver) +ProcessState::ProcessState(const char *driver, size_t mmap_size) : mDriverName(String8(driver)) , mDriverFD(open_driver(driver)) , mVMStart(MAP_FAILED) @@ -435,11 +451,12 @@ ProcessState::ProcessState(const char *driver) , mBinderContextUserData(nullptr) , mThreadPoolStarted(false) , mThreadPoolSeq(1) + , mMmapSize(mmap_size) , mCallRestriction(CallRestriction::NONE) { if (mDriverFD >= 0) { // mmap the binder, providing a chunk of virtual address space to receive transactions. - mVMStart = mmap(nullptr, BINDER_VM_SIZE, PROT_READ, MAP_PRIVATE | MAP_NORESERVE, mDriverFD, 0); + mVMStart = mmap(nullptr, mMmapSize, PROT_READ, MAP_PRIVATE | MAP_NORESERVE, mDriverFD, 0); if (mVMStart == MAP_FAILED) { // *sigh* ALOGE("Using %s failed: unable to mmap transaction memory.\n", mDriverName.c_str()); @@ -456,7 +473,7 @@ ProcessState::~ProcessState() { if (mDriverFD >= 0) { if (mVMStart != MAP_FAILED) { - munmap(mVMStart, BINDER_VM_SIZE); + munmap(mVMStart, mMmapSize); } close(mDriverFD); } diff --git a/libs/binder/Static.cpp b/libs/binder/Static.cpp index bd0e6f9a11..8625c6f278 100644 --- a/libs/binder/Static.cpp +++ b/libs/binder/Static.cpp @@ -75,13 +75,4 @@ TextOutput& aerr(gStderrTextOutput); Mutex& gProcessMutex = *new Mutex; sp<ProcessState> gProcess; -// ------------ IServiceManager.cpp - -Mutex gDefaultServiceManagerLock; -sp<IServiceManager> gDefaultServiceManager; -#ifndef __ANDROID_VNDK__ -sp<IPermissionController> gPermissionController; -#endif -bool gSystemBootCompleted = false; - } // namespace android diff --git a/libs/binder/include/binder/BpBinder.h b/libs/binder/include/binder/BpBinder.h index 1d4f88113a..78f2e1d831 100644 --- a/libs/binder/include/binder/BpBinder.h +++ b/libs/binder/include/binder/BpBinder.h @@ -67,7 +67,6 @@ public: virtual BpBinder* remoteBinder(); - status_t setConstantData(const void* data, size_t size); void sendObituary(); static uint32_t getBinderProxyCount(uint32_t uid); diff --git a/libs/binder/include/binder/Parcel.h b/libs/binder/include/binder/Parcel.h index e5219a5590..0cdabb0265 100644 --- a/libs/binder/include/binder/Parcel.h +++ b/libs/binder/include/binder/Parcel.h @@ -932,23 +932,6 @@ inline TextOutput& operator<<(TextOutput& to, const Parcel& parcel) return to; } -// --------------------------------------------------------------------------- - -// Generic acquire and release of objects. -void acquire_object(const sp<ProcessState>& proc, - const flat_binder_object& obj, const void* who); -void release_object(const sp<ProcessState>& proc, - const flat_binder_object& obj, const void* who); - -void flatten_binder(const sp<ProcessState>& proc, - const sp<IBinder>& binder, flat_binder_object* out); -void flatten_binder(const sp<ProcessState>& proc, - const wp<IBinder>& binder, flat_binder_object* out); -status_t unflatten_binder(const sp<ProcessState>& proc, - const flat_binder_object& flat, sp<IBinder>* out); -status_t unflatten_binder(const sp<ProcessState>& proc, - const flat_binder_object& flat, wp<IBinder>* out); - }; // namespace android // --------------------------------------------------------------------------- diff --git a/libs/binder/include/binder/ProcessState.h b/libs/binder/include/binder/ProcessState.h index 224cb36807..1622ba2712 100644 --- a/libs/binder/include/binder/ProcessState.h +++ b/libs/binder/include/binder/ProcessState.h @@ -36,6 +36,8 @@ class ProcessState : public virtual RefBase public: static sp<ProcessState> self(); static sp<ProcessState> selfOrNull(); + // Note: don't call self() or selfOrNull() before initWithMmapSize() + static sp<ProcessState> initWithMmapSize(size_t mmapSize); // size in bytes /* initWithDriver() can be used to configure libbinder to use * a different binder driver dev node. It must be called *before* @@ -76,6 +78,7 @@ public: String8 getDriverName(); ssize_t getKernelReferences(size_t count, uintptr_t* buf); + size_t getMmapSize(); enum class CallRestriction { // all calls okay @@ -92,7 +95,7 @@ public: private: friend class IPCThreadState; - explicit ProcessState(const char* driver); + explicit ProcessState(const char* driver, size_t mmap_size); ~ProcessState(); ProcessState(const ProcessState& o); @@ -121,6 +124,8 @@ private: int64_t mStarvationStartTimeMs; mutable Mutex mLock; // protects everything below. + // TODO: mManagesContexts is often accessed without the lock. + // Explain why that's safe. Vector<handle_entry>mHandleToObject; @@ -135,6 +140,7 @@ private: String8 mRootDir; bool mThreadPoolStarted; volatile int32_t mThreadPoolSeq; + const size_t mMmapSize; CallRestriction mCallRestriction; }; diff --git a/libs/binder/include/private/binder/Static.h b/libs/binder/include/private/binder/Static.h index 171be7791e..f8e0ee5f8d 100644 --- a/libs/binder/include/private/binder/Static.h +++ b/libs/binder/include/private/binder/Static.h @@ -21,10 +21,6 @@ #include <binder/IBinder.h> #include <binder/ProcessState.h> -#ifndef __ANDROID_VNDK__ -#include <binder/IPermissionController.h> -#endif -#include <binder/IServiceManager.h> namespace android { @@ -35,12 +31,4 @@ extern Vector<int32_t> gTextBuffers; extern Mutex& gProcessMutex; extern sp<ProcessState> gProcess; -// For IServiceManager.cpp -extern Mutex gDefaultServiceManagerLock; -extern sp<IServiceManager> gDefaultServiceManager; -#ifndef __ANDROID_VNDK__ -extern sp<IPermissionController> gPermissionController; -#endif -extern bool gSystemBootCompleted; - } // namespace android diff --git a/opengl/libs/ETC1/etc1.cpp b/opengl/libs/ETC1/etc1.cpp index 97d10851de..19d428a394 100644 --- a/opengl/libs/ETC1/etc1.cpp +++ b/opengl/libs/ETC1/etc1.cpp @@ -378,34 +378,30 @@ static void etc_encodeBaseColors(etc1_byte* pBaseColors, const etc1_byte* pColors, etc_compressed* pCompressed) { int r1, g1, b1, r2, g2, b2; // 8 bit base colors for sub-blocks bool differential; - { - int r51 = convert8To5(pColors[0]); - int g51 = convert8To5(pColors[1]); - int b51 = convert8To5(pColors[2]); - int r52 = convert8To5(pColors[3]); - int g52 = convert8To5(pColors[4]); - int b52 = convert8To5(pColors[5]); - - r1 = convert5To8(r51); - g1 = convert5To8(g51); - b1 = convert5To8(b51); - - int dr = r52 - r51; - int dg = g52 - g51; - int db = b52 - b51; - - differential = inRange4bitSigned(dr) && inRange4bitSigned(dg) - && inRange4bitSigned(db); - if (differential) { - r2 = convert5To8(r51 + dr); - g2 = convert5To8(g51 + dg); - b2 = convert5To8(b51 + db); - pCompressed->high |= (r51 << 27) | ((7 & dr) << 24) | (g51 << 19) - | ((7 & dg) << 16) | (b51 << 11) | ((7 & db) << 8) | 2; - } - } - - if (!differential) { + int r51 = convert8To5(pColors[0]); + int g51 = convert8To5(pColors[1]); + int b51 = convert8To5(pColors[2]); + int r52 = convert8To5(pColors[3]); + int g52 = convert8To5(pColors[4]); + int b52 = convert8To5(pColors[5]); + + r1 = convert5To8(r51); + g1 = convert5To8(g51); + b1 = convert5To8(b51); + + int dr = r52 - r51; + int dg = g52 - g51; + int db = b52 - b51; + + differential = inRange4bitSigned(dr) && inRange4bitSigned(dg) + && inRange4bitSigned(db); + if (differential) { + r2 = convert5To8(r51 + dr); + g2 = convert5To8(g51 + dg); + b2 = convert5To8(b51 + db); + pCompressed->high |= (r51 << 27) | ((7 & dr) << 24) | (g51 << 19) + | ((7 & dg) << 16) | (b51 << 11) | ((7 & db) << 8) | 2; + } else { int r41 = convert8To4(pColors[0]); int g41 = convert8To4(pColors[1]); int b41 = convert8To4(pColors[2]); diff --git a/services/surfaceflinger/Android.bp b/services/surfaceflinger/Android.bp index 4cd0a13861..9aa4e85e2f 100644 --- a/services/surfaceflinger/Android.bp +++ b/services/surfaceflinger/Android.bp @@ -100,6 +100,10 @@ cc_defaults { lto: { thin: true, }, + // TODO(b/131771163): Fix broken fuzzer support with LTO. + sanitize: { + fuzzer: false, + }, } cc_library_headers { diff --git a/services/surfaceflinger/tests/fakehwc/SFFakeHwc_test.cpp b/services/surfaceflinger/tests/fakehwc/SFFakeHwc_test.cpp index f9e0b6413b..a892a2abd0 100644 --- a/services/surfaceflinger/tests/fakehwc/SFFakeHwc_test.cpp +++ b/services/surfaceflinger/tests/fakehwc/SFFakeHwc_test.cpp @@ -54,10 +54,11 @@ using namespace sftest; namespace { // Mock test helpers +using ::testing::_; +using ::testing::DoAll; using ::testing::Invoke; using ::testing::Return; using ::testing::SetArgPointee; -using ::testing::_; using Transaction = SurfaceComposerClient::Transaction; diff --git a/vulkan/libvulkan/layers_extensions.cpp b/vulkan/libvulkan/layers_extensions.cpp index af1adcff62..5679412732 100644 --- a/vulkan/libvulkan/layers_extensions.cpp +++ b/vulkan/libvulkan/layers_extensions.cpp @@ -388,9 +388,8 @@ void ForEachFileInZip(const std::string& zipname, return; } std::string prefix(dir_in_zip + "/"); - const ZipString prefix_str(prefix.c_str()); void* iter_cookie = nullptr; - if ((err = StartIteration(zip, &iter_cookie, &prefix_str, nullptr)) != 0) { + if ((err = StartIteration(zip, &iter_cookie, prefix, "")) != 0) { ALOGE("failed to iterate entries in apk '%s': %d", zipname.c_str(), err); CloseArchive(zip); @@ -399,11 +398,9 @@ void ForEachFileInZip(const std::string& zipname, ALOGD("searching for layers in '%s!/%s'", zipname.c_str(), dir_in_zip.c_str()); ZipEntry entry; - ZipString name; + std::string name; while (Next(iter_cookie, &entry, &name) == 0) { - std::string filename( - reinterpret_cast<const char*>(name.name) + prefix.length(), - name.name_length - prefix.length()); + std::string filename(name.substr(prefix.length())); // only enumerate direct entries of the directory, not subdirectories if (filename.find('/') != filename.npos) continue; |