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

Commit 929ec70f authored by Android Build Coastguard Worker's avatar Android Build Coastguard Worker
Browse files

Snap for 8391568 from 840bc7c8 to tm-release

Change-Id: I2d22659d650cbaf330ee8e631400e6397dffb58c
parents 88a23c7a 840bc7c8
Loading
Loading
Loading
Loading
+21 −3
Original line number Diff line number Diff line
@@ -235,7 +235,7 @@ void android_res_cancel(int nsend_fd) __INTRODUCED_IN(29);
 *
 * Available since API level 33.
 */
int android_tag_socket_with_uid(int sockfd, int tag, uid_t uid) __INTRODUCED_IN(33);
int android_tag_socket_with_uid(int sockfd, uint32_t tag, uid_t uid) __INTRODUCED_IN(33);

/*
 * Set the socket tag for traffic statistics on the specified socket.
@@ -245,14 +245,26 @@ int android_tag_socket_with_uid(int sockfd, int tag, uid_t uid) __INTRODUCED_IN(
 * opened by another UID or was previously tagged by another UID. Subsequent
 * calls always replace any existing parameters. The socket tag is kept when the
 * socket is sent to another process using binder IPCs or other mechanisms such
 * as UNIX socket fd passing.
 * as UNIX socket fd passing. The tag is a value defined by the caller and used
 * together with uid for data traffic accounting, so that the function callers
 * can account different types of data usage for a uid.
 *
 * Returns 0 on success, or a negative POSIX error code (see errno.h) on
 * failure.
 *
 * Some possible error codes:
 * -EBADF           Bad socketfd.
 * -EPERM           No permission.
 * -EAFNOSUPPORT    Socket family is neither AF_INET nor AF_INET6.
 * -EPROTONOSUPPORT Socket protocol is neither IPPROTO_UDP nor IPPROTO_TCP.
 * -EMFILE          Too many stats entries.
 * There are still other error codes that may provided by -errno of
 * [getsockopt()](https://man7.org/linux/man-pages/man2/getsockopt.2.html) or by
 * BPF maps read/write sys calls, which are set appropriately.
 *
 * Available since API level 33.
 */
int android_tag_socket(int sockfd, int tag) __INTRODUCED_IN(33);
int android_tag_socket(int sockfd, uint32_t tag) __INTRODUCED_IN(33);

/*
 * Untag a network socket.
@@ -267,6 +279,12 @@ int android_tag_socket(int sockfd, int tag) __INTRODUCED_IN(33);
 * Returns 0 on success, or a negative POSIX error code (see errno.h) on
 * failure.
 *
 * One of possible error code:
 * -EBADF           Bad socketfd.
 * Other error codes are either provided by -errno of
 * [getsockopt()](https://man7.org/linux/man-pages/man2/getsockopt.2.html) or by
 * BPF map element deletion sys call, which are set appropriately.
 *
 * Available since API level 33.
 */
int android_untag_socket(int sockfd) __INTRODUCED_IN(33);
+61 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2022 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 <map>
#include <set>
#include <string>

namespace android {

template <typename T>
std::string constToString(const T& v) {
    return std::to_string(v);
}

/**
 * Convert a set of integral types to string.
 */
template <typename T>
std::string dumpSet(const std::set<T>& v, std::string (*toString)(const T&) = constToString) {
    std::string out;
    for (const T& entry : v) {
        out += out.empty() ? "{" : ", ";
        out += toString(entry);
    }
    return out.empty() ? "{}" : (out + "}");
}

/**
 * Convert a map to string. Both keys and values of the map should be integral type.
 */
template <typename K, typename V>
std::string dumpMap(const std::map<K, V>& map, std::string (*keyToString)(const K&) = constToString,
                    std::string (*valueToString)(const V&) = constToString) {
    std::string out;
    for (const auto& [k, v] : map) {
        if (!out.empty()) {
            out += "\n";
        }
        out += keyToString(k) + ":" + valueToString(v);
    }
    return out;
}

const char* toString(bool value);

} // namespace android
 No newline at end of file
+4 −3
Original line number Diff line number Diff line
@@ -1584,6 +1584,7 @@ status_t Parcel::readOutVectorSizeWithCheck(size_t elmSize, int32_t* size) const
template<class T>
status_t Parcel::readAligned(T *pArg) const {
    static_assert(PAD_SIZE_UNSAFE(sizeof(T)) == sizeof(T));
    static_assert(std::is_trivially_copyable_v<T>);

    if ((mDataPos+sizeof(T)) <= mDataSize) {
        if (mObjectsSize > 0) {
@@ -1595,9 +1596,8 @@ status_t Parcel::readAligned(T *pArg) const {
            }
        }

        const void* data = mData+mDataPos;
        memcpy(pArg, mData + mDataPos, sizeof(T));
        mDataPos += sizeof(T);
        *pArg =  *reinterpret_cast<const T*>(data);
        return NO_ERROR;
    } else {
        return NOT_ENOUGH_DATA;
@@ -1617,10 +1617,11 @@ T Parcel::readAligned() const {
template<class T>
status_t Parcel::writeAligned(T val) {
    static_assert(PAD_SIZE_UNSAFE(sizeof(T)) == sizeof(T));
    static_assert(std::is_trivially_copyable_v<T>);

    if ((mDataPos+sizeof(val)) <= mDataCapacity) {
restart_write:
        *reinterpret_cast<T*>(mData+mDataPos) = val;
        memcpy(mData + mDataPos, &val, sizeof(val));
        return finishWrite(sizeof(val));
    }

+12 −4
Original line number Diff line number Diff line
@@ -313,7 +313,8 @@ status_t RpcState::rpcSend(const sp<RpcSession::RpcConnection>& connection,
                           const sp<RpcSession>& session, const char* what, iovec* iovs, int niovs,
                           const std::function<status_t()>& altPoll) {
    for (int i = 0; i < niovs; i++) {
        LOG_RPC_DETAIL("Sending %s on RpcTransport %p: %s", what, connection->rpcTransport.get(),
        LOG_RPC_DETAIL("Sending %s (part %d of %d) on RpcTransport %p: %s",
                       what, i + 1, niovs, connection->rpcTransport.get(),
                       android::base::HexString(iovs[i].iov_base, iovs[i].iov_len).c_str());
    }

@@ -343,7 +344,8 @@ status_t RpcState::rpcRec(const sp<RpcSession::RpcConnection>& connection,
    }

    for (int i = 0; i < niovs; i++) {
        LOG_RPC_DETAIL("Received %s on RpcTransport %p: %s", what, connection->rpcTransport.get(),
        LOG_RPC_DETAIL("Received %s (part %d of %d) on RpcTransport %p: %s",
                       what, i + 1, niovs, connection->rpcTransport.get(),
                       android::base::HexString(iovs[i].iov_base, iovs[i].iov_len).c_str());
    }
    return OK;
@@ -660,8 +662,14 @@ status_t RpcState::getAndExecuteCommand(const sp<RpcSession::RpcConnection>& con
status_t RpcState::drainCommands(const sp<RpcSession::RpcConnection>& connection,
                                 const sp<RpcSession>& session, CommandType type) {
    uint8_t buf;
    while (connection->rpcTransport->peek(&buf, sizeof(buf)).value_or(0) > 0) {
        status_t status = getAndExecuteCommand(connection, session, type);
    while (true) {
        size_t num_bytes;
        status_t status = connection->rpcTransport->peek(&buf, sizeof(buf), &num_bytes);
        if (status == WOULD_BLOCK) break;
        if (status != OK) return status;
        if (!num_bytes) break;

        status = getAndExecuteCommand(connection, session, type);
        if (status != OK) return status;
    }
    return OK;
+11 −6
Original line number Diff line number Diff line
@@ -24,9 +24,6 @@
#include "FdTrigger.h"
#include "RpcState.h"

using android::base::ErrnoError;
using android::base::Result;

namespace android {

namespace {
@@ -35,12 +32,20 @@ namespace {
class RpcTransportRaw : public RpcTransport {
public:
    explicit RpcTransportRaw(android::base::unique_fd socket) : mSocket(std::move(socket)) {}
    Result<size_t> peek(void *buf, size_t size) override {
    status_t peek(void* buf, size_t size, size_t* out_size) override {
        ssize_t ret = TEMP_FAILURE_RETRY(::recv(mSocket.get(), buf, size, MSG_PEEK));
        if (ret < 0) {
            return ErrnoError() << "recv(MSG_PEEK)";
            int savedErrno = errno;
            if (savedErrno == EAGAIN || savedErrno == EWOULDBLOCK) {
                return WOULD_BLOCK;
            }
        return ret;

            LOG_RPC_DETAIL("RpcTransport peek(): %s", strerror(savedErrno));
            return -savedErrno;
        }

        *out_size = static_cast<size_t>(ret);
        return OK;
    }

    template <typename SendOrReceive>
Loading