diff options
28 files changed, 257 insertions, 129 deletions
diff --git a/cmds/dumpstate/tests/dumpstate_test.cpp b/cmds/dumpstate/tests/dumpstate_test.cpp index e6a7735d60..71d15f4761 100644 --- a/cmds/dumpstate/tests/dumpstate_test.cpp +++ b/cmds/dumpstate/tests/dumpstate_test.cpp @@ -666,8 +666,7 @@ TEST_F(DumpstateTest, RunCommandWithTitle) { EXPECT_THAT(err, StrEq("stderr\n")); // We don't know the exact duration, so we check the prefix and suffix EXPECT_THAT(out, - StartsWith("------ I AM GROOT (" + kSimpleCommand + ") ------\nstdout\n------")); - EXPECT_THAT(out, EndsWith("s was the duration of 'I AM GROOT' ------\n")); + StartsWith("------ I AM GROOT (" + kSimpleCommand + ") ------\nstdout\n")); } TEST_F(DumpstateTest, RunCommandWithLoggingMessage) { @@ -702,8 +701,7 @@ TEST_F(DumpstateTest, RunCommandDryRun) { EXPECT_EQ(0, RunCommand("I AM GROOT", {kSimpleCommand})); // We don't know the exact duration, so we check the prefix and suffix EXPECT_THAT(out, StartsWith("------ I AM GROOT (" + kSimpleCommand + - ") ------\n\t(skipped on dry run)\n------")); - EXPECT_THAT(out, EndsWith("s was the duration of 'I AM GROOT' ------\n")); + ") ------\n\t(skipped on dry run)\n")); EXPECT_THAT(err, IsEmpty()); } @@ -1042,7 +1040,6 @@ TEST_F(DumpstateTest, DumpFileNotFoundWithTitle) { // We don't know the exact duration, so we check the prefix and suffix EXPECT_THAT(out, StartsWith("*** Error dumping /I/cant/believe/I/exist (Y U NO EXIST?): No " "such file or directory\n")); - EXPECT_THAT(out, EndsWith("s was the duration of 'Y U NO EXIST?' ------\n")); } TEST_F(DumpstateTest, DumpFileSingleLine) { @@ -1082,8 +1079,7 @@ TEST_F(DumpstateTest, DumpFileOnDryRun) { EXPECT_THAT(err, IsEmpty()); EXPECT_THAT( out, StartsWith("------ Might as well dump. Dump! (" + kTestDataPath + "single-line.txt:")); - EXPECT_THAT(out, HasSubstr("\n\t(skipped on dry run)\n------")); - EXPECT_THAT(out, EndsWith("s was the duration of 'Might as well dump. Dump!' ------\n")); + EXPECT_THAT(out, HasSubstr("\n\t(skipped on dry run)\n")); } TEST_F(DumpstateTest, DumpFileUpdateProgress) { diff --git a/cmds/installd/dexopt.cpp b/cmds/installd/dexopt.cpp index a5cc0df77e..214c665892 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/OWNERS b/include/OWNERS index 22be776c2a..db52850fe8 100644 --- a/include/OWNERS +++ b/include/OWNERS @@ -1,8 +1,10 @@ alexeykuzmin@google.com dangittik@google.com +jreck@google.com lajos@google.com mathias@google.com michaelwr@google.com +nona@google.com racarr@google.com romainguy@android.com santoscordon@google.com diff --git a/libs/binder/Binder.cpp b/libs/binder/Binder.cpp index f6cc3afc97..96ee29556c 100644 --- a/libs/binder/Binder.cpp +++ b/libs/binder/Binder.cpp @@ -86,6 +86,10 @@ status_t IBinder::shellCommand(const sp<IBinder>& target, int in, int out, int e class BBinder::Extras { public: + // unlocked objects + bool mRequestingSid = false; + + // for below objects Mutex mLock; BpBinder::ObjectManager mObjects; }; @@ -163,19 +167,8 @@ void BBinder::attachObject( const void* objectID, void* object, void* cleanupCookie, object_cleanup_func func) { - Extras* e = mExtras.load(std::memory_order_acquire); - - if (!e) { - e = new Extras; - Extras* expected = nullptr; - if (!mExtras.compare_exchange_strong(expected, e, - std::memory_order_release, - std::memory_order_acquire)) { - delete e; - e = expected; // Filled in by CAS - } - if (e == nullptr) return; // out of memory - } + Extras* e = getOrCreateExtras(); + if (!e) return; // out of memory AutoMutex _l(e->mLock); e->mObjects.attach(objectID, object, cleanupCookie, func); @@ -204,6 +197,30 @@ BBinder* BBinder::localBinder() return this; } +bool BBinder::isRequestingSid() +{ + Extras* e = mExtras.load(std::memory_order_acquire); + + return e && e->mRequestingSid; +} + +void BBinder::setRequestingSid(bool requestingSid) +{ + Extras* e = mExtras.load(std::memory_order_acquire); + + if (!e) { + // default is false. Most things don't need sids, so avoiding allocations when possible. + if (!requestingSid) { + return; + } + + e = getOrCreateExtras(); + if (!e) return; // out of memory + } + + e->mRequestingSid = true; +} + BBinder::~BBinder() { Extras* e = mExtras.load(std::memory_order_relaxed); @@ -267,6 +284,25 @@ status_t BBinder::onTransact( } } +BBinder::Extras* BBinder::getOrCreateExtras() +{ + Extras* e = mExtras.load(std::memory_order_acquire); + + if (!e) { + e = new Extras; + Extras* expected = nullptr; + if (!mExtras.compare_exchange_strong(expected, e, + std::memory_order_release, + std::memory_order_acquire)) { + delete e; + e = expected; // Filled in by CAS + } + if (e == nullptr) return nullptr; // out of memory + } + + return e; +} + // --------------------------------------------------------------------------- enum { diff --git a/libs/binder/Debug.cpp b/libs/binder/Debug.cpp index f38bbb2f32..a1c2a8be08 100644 --- a/libs/binder/Debug.cpp +++ b/libs/binder/Debug.cpp @@ -221,7 +221,11 @@ void printHexData(int32_t indent, const void *buf, size_t length, for (word = 0; word < bytesPerLine; ) { - const size_t startIndex = word+(alignment-(alignment?1:0)); + size_t align_offset = alignment-(alignment?1:0); + if (remain > 0 && (size_t)remain <= align_offset) { + align_offset = remain - 1; + } + const size_t startIndex = word+align_offset; for (index = 0; index < alignment || (alignment == 0 && index < bytesPerLine); index++) { diff --git a/libs/binder/IInterface.cpp b/libs/binder/IInterface.cpp index 6b7729186e..59d51ed94a 100644 --- a/libs/binder/IInterface.cpp +++ b/libs/binder/IInterface.cpp @@ -47,21 +47,3 @@ sp<IBinder> IInterface::asBinder(const sp<IInterface>& iface) // --------------------------------------------------------------------------- }; // namespace android - -extern "C" { - -void _ZN7android10IInterface8asBinderEv(void *retval, void* self) { - ALOGW("deprecated asBinder call, please update your code"); - //ALOGI("self: %p, retval: %p", self, retval); - android::sp<android::IBinder> *ret = new(retval) android::sp<android::IBinder>; - *ret = android::IInterface::asBinder((android::IInterface*)self); -} - -void _ZNK7android10IInterface8asBinderEv(void *retval, void *self) { - ALOGW("deprecated asBinder call, please update your code"); - //ALOGI("self: %p, retval: %p", self, retval); - android::sp<android::IBinder> *ret = new(retval) android::sp<android::IBinder>; - *ret = android::IInterface::asBinder((android::IInterface*)self); -} - -} // extern "C" diff --git a/libs/binder/IPCThreadState.cpp b/libs/binder/IPCThreadState.cpp index 22f6f54e28..4b70e2e004 100644 --- a/libs/binder/IPCThreadState.cpp +++ b/libs/binder/IPCThreadState.cpp @@ -88,7 +88,8 @@ static const char *kReturnStrings[] = { "BR_FINISHED", "BR_DEAD_BINDER", "BR_CLEAR_DEATH_NOTIFICATION_DONE", - "BR_FAILED_REPLY" + "BR_FAILED_REPLY", + "BR_TRANSACTION_SEC_CTX", }; static const char *kCommandStrings[] = { @@ -113,7 +114,7 @@ static const char *kCommandStrings[] = { 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 @@ -363,6 +364,11 @@ pid_t IPCThreadState::getCallingPid() const return mCallingPid; } +const char* IPCThreadState::getCallingSid() const +{ + return mCallingSid; +} + uid_t IPCThreadState::getCallingUid() const { return mCallingUid; @@ -370,6 +376,7 @@ uid_t IPCThreadState::getCallingUid() const int64_t IPCThreadState::clearCallingIdentity() { + // ignore mCallingSid for legacy reasons int64_t token = ((int64_t)mCallingUid<<32) | mCallingPid; clearCaller(); return token; @@ -398,12 +405,14 @@ int32_t IPCThreadState::getLastTransactionBinderFlags() const void IPCThreadState::restoreCallingIdentity(int64_t token) { mCallingUid = (int)(token>>32); + mCallingSid = nullptr; // not enough data to restore mCallingPid = (int)token; } void IPCThreadState::clearCaller() { mCallingPid = getpid(); + mCallingSid = nullptr; // expensive to lookup mCallingUid = getuid(); } @@ -1089,10 +1098,19 @@ status_t IPCThreadState::executeCommand(int32_t cmd) } break; + case BR_TRANSACTION_SEC_CTX: case BR_TRANSACTION: { - binder_transaction_data tr; - result = mIn.read(&tr, sizeof(tr)); + binder_transaction_data_secctx tr_secctx; + binder_transaction_data& tr = tr_secctx.transaction_data; + + if (cmd == (int) BR_TRANSACTION_SEC_CTX) { + result = mIn.read(&tr_secctx, sizeof(tr_secctx)); + } else { + result = mIn.read(&tr, sizeof(tr)); + tr_secctx.secctx = 0; + } + ALOG_ASSERT(result == NO_ERROR, "Not enough command data for brTRANSACTION"); if (result != NO_ERROR) break; @@ -1108,15 +1126,18 @@ status_t IPCThreadState::executeCommand(int32_t cmd) tr.offsets_size/sizeof(binder_size_t), freeBuffer, this); const pid_t origPid = mCallingPid; + const char* origSid = mCallingSid; const uid_t origUid = mCallingUid; const int32_t origStrictModePolicy = mStrictModePolicy; const int32_t origTransactionBinderFlags = mLastTransactionBinderFlags; mCallingPid = tr.sender_pid; + mCallingSid = reinterpret_cast<const char*>(tr_secctx.secctx); mCallingUid = tr.sender_euid; mLastTransactionBinderFlags = tr.flags; - //ALOGI(">>>> TRANSACT from pid %d uid %d\n", mCallingPid, mCallingUid); + // ALOGI(">>>> TRANSACT from pid %d sid %s uid %d\n", mCallingPid, + // (mCallingSid ? mCallingSid : "<N/A>"), mCallingUid); Parcel reply; status_t error; @@ -1148,8 +1169,8 @@ status_t IPCThreadState::executeCommand(int32_t cmd) } mIPCThreadStateBase->popCurrentState(); - //ALOGI("<<<< TRANSACT from pid %d restore pid %d uid %d\n", - // mCallingPid, origPid, origUid); + //ALOGI("<<<< TRANSACT from pid %d restore pid %d sid %s uid %d\n", + // mCallingPid, origPid, (origSid ? origSid : "<N/A>"), origUid); if ((tr.flags & TF_ONE_WAY) == 0) { LOG_ONEWAY("Sending reply to %d!", mCallingPid); @@ -1160,6 +1181,7 @@ status_t IPCThreadState::executeCommand(int32_t cmd) } mCallingPid = origPid; + mCallingSid = origSid; mCallingUid = origUid; mStrictModePolicy = origStrictModePolicy; mLastTransactionBinderFlags = origTransactionBinderFlags; 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 0423264135..9f8c40876e 100644 --- a/libs/binder/Parcel.cpp +++ b/libs/binder/Parcel.cpp @@ -76,14 +76,6 @@ static size_t pad_size(size_t s) { // Note: must be kept in sync with android/os/StrictMode.java's PENALTY_GATHER #define STRICT_MODE_PENALTY_GATHER (0x40 << 16) -// XXX This can be made public if we want to provide -// support for typed data. -struct small_flat_data -{ - uint32_t type; - uint32_t data; -}; - namespace android { static pthread_mutex_t gParcelGlobalAllocSizeLock = PTHREAD_MUTEX_INITIALIZER; @@ -223,7 +215,7 @@ status_t flatten_binder(const sp<ProcessState>& /*proc*/, } if (binder != nullptr) { - IBinder *local = binder->localBinder(); + BBinder *local = binder->localBinder(); if (!local) { BpBinder *proxy = binder->remoteBinder(); if (proxy == nullptr) { @@ -235,6 +227,9 @@ status_t flatten_binder(const sp<ProcessState>& /*proc*/, obj.handle = handle; obj.cookie = 0; } else { + if (local->isRequestingSid()) { + obj.flags |= FLAT_BINDER_FLAG_TXN_SECURITY_CTX; + } obj.hdr.type = BINDER_TYPE_BINDER; obj.binder = reinterpret_cast<uintptr_t>(local->getWeakRefs()); obj.cookie = reinterpret_cast<uintptr_t>(local); diff --git a/libs/binder/ProcessState.cpp b/libs/binder/ProcessState.cpp index 3798b61ab9..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; } @@ -181,8 +193,20 @@ bool ProcessState::becomeContextManager(context_check_func checkFunc, void* user mBinderContextCheckFunc = checkFunc; mBinderContextUserData = userData; - int dummy = 0; - status_t result = ioctl(mDriverFD, BINDER_SET_CONTEXT_MGR, &dummy); + flat_binder_object obj { + .flags = FLAT_BINDER_FLAG_TXN_SECURITY_CTX, + }; + + status_t result = ioctl(mDriverFD, BINDER_SET_CONTEXT_MGR_EXT, &obj); + + // fallback to original method + if (result != 0) { + android_errorWriteLog(0x534e4554, "121035042"); + + int dummy = 0; + result = ioctl(mDriverFD, BINDER_SET_CONTEXT_MGR, &dummy); + } + if (result == 0) { mManagesContexts = true; } else if (result == -1) { @@ -202,15 +226,6 @@ bool ProcessState::becomeContextManager(context_check_func checkFunc, void* user // already be invalid. ssize_t ProcessState::getKernelReferences(size_t buf_count, uintptr_t* buf) { - // TODO: remove these when they are defined by bionic's binder.h - struct binder_node_debug_info { - binder_uintptr_t ptr; - binder_uintptr_t cookie; - __u32 has_strong_ref; - __u32 has_weak_ref; - }; -#define BINDER_GET_NODE_DEBUG_INFO _IOWR('b', 11, struct binder_node_debug_info) - binder_node_debug_info info = {}; uintptr_t* end = buf ? buf + buf_count : nullptr; @@ -234,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."); @@ -418,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) @@ -432,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()); @@ -453,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/Binder.h b/libs/binder/include/binder/Binder.h index c251468bdb..cf3ef84caa 100644 --- a/libs/binder/include/binder/Binder.h +++ b/libs/binder/include/binder/Binder.h @@ -60,6 +60,10 @@ public: virtual BBinder* localBinder(); + bool isRequestingSid(); + // This must be called before the object is sent to another process. Not thread safe. + void setRequestingSid(bool requestSid); + protected: virtual ~BBinder(); @@ -75,6 +79,8 @@ private: class Extras; + Extras* getOrCreateExtras(); + std::atomic<Extras*> mExtras; void* mReserved0; }; diff --git a/libs/binder/include/binder/IPCThreadState.h b/libs/binder/include/binder/IPCThreadState.h index 745f6182f6..a20ef7c410 100644 --- a/libs/binder/include/binder/IPCThreadState.h +++ b/libs/binder/include/binder/IPCThreadState.h @@ -42,6 +42,11 @@ public: status_t clearLastError(); pid_t getCallingPid() const; + // nullptr if unavailable + // + // this can't be restored once it's cleared, and it does not return the + // context of the current process when not in a binder call. + const char* getCallingSid() const; uid_t getCallingUid() const; void setStrictModePolicy(int32_t policy); @@ -51,6 +56,7 @@ public: int32_t getLastTransactionBinderFlags() const; int64_t clearCallingIdentity(); + // Restores PID/UID (not SID) void restoreCallingIdentity(int64_t token); int setupPolling(int* fd); @@ -154,6 +160,7 @@ private: Parcel mOut; status_t mLastError; pid_t mCallingPid; + const char* mCallingSid; uid_t mCallingUid; int32_t mStrictModePolicy; int32_t mLastTransactionBinderFlags; diff --git a/libs/binder/include/binder/Parcel.h b/libs/binder/include/binder/Parcel.h index c9c273acd8..f6560a7f09 100644 --- a/libs/binder/include/binder/Parcel.h +++ b/libs/binder/include/binder/Parcel.h @@ -20,6 +20,8 @@ #include <string> #include <vector> +#include <linux/android/binder.h> + #include <android-base/unique_fd.h> #include <cutils/native_handle.h> #include <utils/Errors.h> @@ -27,7 +29,6 @@ #include <utils/String16.h> #include <utils/Vector.h> #include <utils/Flattenable.h> -#include <linux/android/binder.h> #include <binder/IInterface.h> #include <binder/Parcelable.h> diff --git a/libs/binder/include/binder/ProcessState.h b/libs/binder/include/binder/ProcessState.h index 224cb36807..8a1f7e242e 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); @@ -135,6 +138,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/libs/graphicsenv/Android.bp b/libs/graphicsenv/Android.bp index 4da30e9980..52a41ff675 100644 --- a/libs/graphicsenv/Android.bp +++ b/libs/graphicsenv/Android.bp @@ -22,6 +22,7 @@ cc_library_shared { cflags: ["-Wall", "-Werror"], shared_libs: [ + "libdl_android", "liblog", ], diff --git a/libs/gui/IGraphicBufferProducer.cpp b/libs/gui/IGraphicBufferProducer.cpp index 74ab5ac1c8..60af8b5fc9 100644 --- a/libs/gui/IGraphicBufferProducer.cpp +++ b/libs/gui/IGraphicBufferProducer.cpp @@ -355,7 +355,7 @@ public: data.writeUint32(height); data.writeInt32(static_cast<int32_t>(format)); data.writeUint64(usage); - status_t result = remote()->transact(ALLOCATE_BUFFERS, data, &reply, TF_ONE_WAY); + status_t result = remote()->transact(ALLOCATE_BUFFERS, data, &reply, IBinder::FLAG_ONEWAY); if (result != NO_ERROR) { ALOGE("allocateBuffers failed to transact: %d", result); } diff --git a/libs/gui/ISurfaceComposer.cpp b/libs/gui/ISurfaceComposer.cpp index d2d27e8239..76d242ddb6 100644 --- a/libs/gui/ISurfaceComposer.cpp +++ b/libs/gui/ISurfaceComposer.cpp @@ -504,8 +504,8 @@ public: ALOGE("enableVSyncInjections failed to writeBool: %d", result); return result; } - result = remote()->transact(BnSurfaceComposer::ENABLE_VSYNC_INJECTIONS, - data, &reply, TF_ONE_WAY); + result = remote()->transact(BnSurfaceComposer::ENABLE_VSYNC_INJECTIONS, data, &reply, + IBinder::FLAG_ONEWAY); if (result != NO_ERROR) { ALOGE("enableVSyncInjections failed to transact: %d", result); return result; @@ -525,7 +525,8 @@ public: ALOGE("injectVSync failed to writeInt64: %d", result); return result; } - result = remote()->transact(BnSurfaceComposer::INJECT_VSYNC, data, &reply, TF_ONE_WAY); + result = remote()->transact(BnSurfaceComposer::INJECT_VSYNC, data, &reply, + IBinder::FLAG_ONEWAY); if (result != NO_ERROR) { ALOGE("injectVSync failed to transact: %d", result); return result; diff --git a/services/surfaceflinger/BufferLayerConsumer.cpp b/services/surfaceflinger/BufferLayerConsumer.cpp index 87333d0ffd..ae8ebf0e01 100644 --- a/services/surfaceflinger/BufferLayerConsumer.cpp +++ b/services/surfaceflinger/BufferLayerConsumer.cpp @@ -435,7 +435,9 @@ void BufferLayerConsumer::computeCurrentTransformMatrixLocked() { BLC_LOGD("computeCurrentTransformMatrixLocked: " "mCurrentTextureImage is nullptr"); } - const Rect& cropRect = canUseImageCrop(mCurrentCrop) ? Rect::EMPTY_RECT : mCurrentCrop; + + const Rect& currentCrop = getCurrentCropLocked(); + const Rect& cropRect = canUseImageCrop(currentCrop) ? Rect::EMPTY_RECT : currentCrop; GLConsumer::computeTransformMatrix(mCurrentTransformMatrix, buf, cropRect, mCurrentTransform, mFilteringEnabled); } @@ -490,6 +492,10 @@ sp<GraphicBuffer> BufferLayerConsumer::getCurrentBuffer(int* outSlot) const { Rect BufferLayerConsumer::getCurrentCrop() const { Mutex::Autolock lock(mMutex); + return getCurrentCropLocked(); +} + +Rect BufferLayerConsumer::getCurrentCropLocked() const { return (mCurrentScalingMode == NATIVE_WINDOW_SCALING_MODE_SCALE_CROP) ? GLConsumer::scaleDownCrop(mCurrentCrop, mDefaultWidth, mDefaultHeight) : mCurrentCrop; diff --git a/services/surfaceflinger/BufferLayerConsumer.h b/services/surfaceflinger/BufferLayerConsumer.h index f81cdb1d91..84404c7f0f 100644 --- a/services/surfaceflinger/BufferLayerConsumer.h +++ b/services/surfaceflinger/BufferLayerConsumer.h @@ -274,6 +274,9 @@ private: // mCurrentTextureImage must not be nullptr. void computeCurrentTransformMatrixLocked(); + // See getCurrentCrop, but with mMutex already held. + Rect getCurrentCropLocked() const; + // doFenceWaitLocked inserts a wait command into the RenderEngine command // stream to ensure that it is safe for future RenderEngine commands to // access the current texture buffer. diff --git a/services/surfaceflinger/DisplayDevice.h b/services/surfaceflinger/DisplayDevice.h index 3cf06bceaf..d779ca4609 100644 --- a/services/surfaceflinger/DisplayDevice.h +++ b/services/surfaceflinger/DisplayDevice.h @@ -375,16 +375,21 @@ public: } Rect getSourceCrop() const override { - // use the (projected) logical display viewport by default + // use the projected display viewport by default. if (mSourceCrop.isEmpty()) { return mDevice->getScissor(); } - const int orientation = mDevice->getInstallOrientation(); - if (orientation == DisplayState::eOrientationDefault) { - return mSourceCrop; - } + // Recompute the device transformation for the source crop. + Transform rotation; + Transform translatePhysical; + Transform translateLogical; + Transform scale; + const Rect& viewport = mDevice->getViewport(); + const Rect& scissor = mDevice->getScissor(); + const Rect& frame = mDevice->getFrame(); + const int orientation = mDevice->getInstallOrientation(); // Install orientation is transparent to the callers. Apply it now. uint32_t flags = 0x00; switch (orientation) { @@ -397,10 +402,17 @@ public: case DisplayState::eOrientation270: flags = Transform::ROT_270; break; + default: + break; } - Transform tr; - tr.set(flags, getWidth(), getHeight()); - return tr.transform(mSourceCrop); + rotation.set(flags, getWidth(), getHeight()); + translateLogical.set(-viewport.left, -viewport.top); + translatePhysical.set(scissor.left, scissor.top); + scale.set(frame.getWidth() / float(viewport.getWidth()), 0, 0, + frame.getHeight() / float(viewport.getHeight())); + const Transform finalTransform = + rotation * translatePhysical * scale * translateLogical; + return finalTransform.transform(mSourceCrop); } private: diff --git a/services/surfaceflinger/OWNERS b/services/surfaceflinger/OWNERS index ce0611c755..69d8c89b45 100644 --- a/services/surfaceflinger/OWNERS +++ b/services/surfaceflinger/OWNERS @@ -1,4 +1,6 @@ +adyabr@google.com akrulec@google.com +alecmouri@google.com chaviw@google.com lpy@google.com marissaw@google.com diff --git a/services/vr/virtual_touchpad/Android.bp b/services/vr/virtual_touchpad/Android.bp index 02634811b2..131a306c08 100644 --- a/services/vr/virtual_touchpad/Android.bp +++ b/services/vr/virtual_touchpad/Android.bp @@ -62,7 +62,7 @@ cc_test { service_src = [ "main.cpp", "VirtualTouchpadService.cpp", - "aidl/android/dvr/VirtualTouchpadService.aidl", + "aidl/android/dvr/IVirtualTouchpadService.aidl", ] service_static_libs = [ @@ -99,7 +99,7 @@ cc_binary { client_src = [ "VirtualTouchpadClient.cpp", "DvrVirtualTouchpadClient.cpp", - "aidl/android/dvr/VirtualTouchpadService.aidl", + "aidl/android/dvr/IVirtualTouchpadService.aidl", ] client_shared_libs = [ diff --git a/services/vr/virtual_touchpad/aidl/android/dvr/VirtualTouchpadService.aidl b/services/vr/virtual_touchpad/aidl/android/dvr/IVirtualTouchpadService.aidl index 256203ca6d..89aa44a722 100644 --- a/services/vr/virtual_touchpad/aidl/android/dvr/VirtualTouchpadService.aidl +++ b/services/vr/virtual_touchpad/aidl/android/dvr/IVirtualTouchpadService.aidl @@ -1,7 +1,7 @@ package android.dvr; /** @hide */ -interface VirtualTouchpadService +interface IVirtualTouchpadService { const String SERVICE_NAME = "virtual_touchpad"; diff --git a/vulkan/libvulkan/Android.bp b/vulkan/libvulkan/Android.bp index 206c8eb379..71a120a896 100644 --- a/vulkan/libvulkan/Android.bp +++ b/vulkan/libvulkan/Android.bp @@ -76,6 +76,7 @@ cc_library_shared { "libhardware", "libsync", "libbase", + "libdl_android", "libhidlbase", "libhidltransport", "liblog", |