Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 3f4c4957 authored by Tomasz Wasilczyk's avatar Tomasz Wasilczyk Committed by Gerrit Code Review
Browse files

Merge "Binder: Split OS to Android and Unix part, abstract GetThreadId out" into main

parents ed27e9e9 0d9dec20
Loading
Loading
Loading
Loading
+3 −1
Original line number Diff line number Diff line
@@ -118,7 +118,8 @@ cc_defaults {
    ],

    srcs: [
        "OS.cpp",
        "OS_android.cpp",
        "OS_unix_base.cpp",
        "RpcTransportRaw.cpp",
    ],

@@ -249,6 +250,7 @@ cc_library_shared {

    srcs: [
        // Trusty-specific files
        "OS_android.cpp",
        "trusty/logging.cpp",
        "trusty/OS.cpp",
        "trusty/RpcServerTrusty.cpp",
+4 −2
Original line number Diff line number Diff line
@@ -23,7 +23,7 @@
#include <binder/RpcTransport.h>
#include <utils/Errors.h>

namespace android {
namespace android::binder::os {

android::base::Result<void> setNonBlocking(android::base::borrowed_fd fd);

@@ -41,4 +41,6 @@ ssize_t receiveMessageFromSocket(
        const RpcTransportFd& socket, iovec* iovs, int niovs,
        std::vector<std::variant<base::unique_fd, base::borrowed_fd>>* ancillaryFds);

} // namespace android
uint64_t GetThreadId();

} // namespace android::binder::os
+31 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2023 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.
 */

#include "OS.h"

#include <android-base/threads.h>

namespace android::binder::os {

uint64_t GetThreadId() {
#ifdef BINDER_RPC_SINGLE_THREADED
    return 0;
#else
    return base::GetThreadId();
#endif
}

} // namespace android::binder::os
+2 −2
Original line number Diff line number Diff line
@@ -24,7 +24,7 @@
using android::base::ErrnoError;
using android::base::Result;

namespace android {
namespace android::binder::os {

// Linux kernel supports up to 253 (from SCM_MAX_FD) for unix sockets.
constexpr size_t kMaxFdsPerMsg = 253;
@@ -162,4 +162,4 @@ ssize_t receiveMessageFromSocket(
    return TEMP_FAILURE_RETRY(recvmsg(socket.fd.get(), &msg, MSG_NOSIGNAL));
}

} // namespace android
} // namespace android::binder::os
+5 −5
Original line number Diff line number Diff line
@@ -621,7 +621,7 @@ status_t Parcel::appendFrom(const Parcel* parcel, size_t offset, size_t len) {
                // To match kernel binder behavior, we always dup, even if the
                // FD was unowned in the source parcel.
                int newFd = -1;
                if (status_t status = dupFileDescriptor(oldFd, &newFd); status != OK) {
                if (status_t status = binder::os::dupFileDescriptor(oldFd, &newFd); status != OK) {
                    ALOGW("Failed to duplicate file descriptor %d: %s", oldFd, strerror(-status));
                }
                rpcFields->mFds->emplace_back(base::unique_fd(newFd));
@@ -1513,7 +1513,7 @@ status_t Parcel::writeFileDescriptor(int fd, bool takeOwnership) {
status_t Parcel::writeDupFileDescriptor(int fd)
{
    int dupFd;
    if (status_t err = dupFileDescriptor(fd, &dupFd); err != OK) {
    if (status_t err = binder::os::dupFileDescriptor(fd, &dupFd); err != OK) {
        return err;
    }
    status_t err = writeFileDescriptor(dupFd, true /*takeOwnership*/);
@@ -1532,7 +1532,7 @@ status_t Parcel::writeParcelFileDescriptor(int fd, bool takeOwnership)
status_t Parcel::writeDupParcelFileDescriptor(int fd)
{
    int dupFd;
    if (status_t err = dupFileDescriptor(fd, &dupFd); err != OK) {
    if (status_t err = binder::os::dupFileDescriptor(fd, &dupFd); err != OK) {
        return err;
    }
    status_t err = writeParcelFileDescriptor(dupFd, true /*takeOwnership*/);
@@ -2345,7 +2345,7 @@ status_t Parcel::readUniqueFileDescriptor(base::unique_fd* val) const
    }

    int dupFd;
    if (status_t err = dupFileDescriptor(got, &dupFd); err != OK) {
    if (status_t err = binder::os::dupFileDescriptor(got, &dupFd); err != OK) {
        return BAD_VALUE;
    }

@@ -2367,7 +2367,7 @@ status_t Parcel::readUniqueParcelFileDescriptor(base::unique_fd* val) const
    }

    int dupFd;
    if (status_t err = dupFileDescriptor(got, &dupFd); err != OK) {
    if (status_t err = binder::os::dupFileDescriptor(got, &dupFd); err != OK) {
        return BAD_VALUE;
    }

Loading