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

Commit 83e66f79 authored by Tri Vo's avatar Tri Vo Committed by Gerrit Code Review
Browse files

Merge changes I9e4cbf11,I41cde13a

* changes:
  trusty: Allow fuzzing without coverage
  trusty: Fix up error messages
parents 3e455e3a 19eccb4f
Loading
Loading
Loading
Loading
+10 −3
Original line number Diff line number Diff line
@@ -29,6 +29,7 @@
#include <trusty/coverage/record.h>
#include <trusty/coverage/tipc.h>
#include <trusty/tipc.h>
#include <iostream>

#define COVERAGE_CLIENT_PORT "com.android.trusty.coverage.client"

@@ -122,7 +123,9 @@ Result<void> CoverageRecord::Open() {

    int fd = tipc_connect(tipc_dev_.c_str(), COVERAGE_CLIENT_PORT);
    if (fd < 0) {
        return ErrnoError() << "failed to connect to Trusty coverarge server: ";
        // Don't error out to support fuzzing builds without coverage, e.g. for repros.
        std::cerr << "WARNING!!! Failed to connect to Trusty coverarge server." << std::endl;
        return {};
    }
    coverage_srv_fd_.reset(fd);

@@ -130,7 +133,7 @@ Result<void> CoverageRecord::Open() {
    req.open_args.uuid = uuid_;
    auto ret = Rpc(&req, -1, &resp);
    if (!ret.ok()) {
        return Error() << "failed to open coverage client: ";
        return Error() << "failed to open coverage client: " << ret.error();
    }
    record_len_ = resp.open_args.record_len;
    shm_len_ = RoundPageUp(record_len_);
@@ -153,13 +156,17 @@ Result<void> CoverageRecord::Open() {
    req.share_record_args.shm_len = shm_len_;
    ret = Rpc(&req, dma_buf, &resp);
    if (!ret.ok()) {
        return Error() << "failed to send shared memory: ";
        return Error() << "failed to send shared memory: " << ret.error();
    }

    shm_ = shm;
    return {};
}

bool CoverageRecord::IsOpen() {
    return shm_;
}

void CoverageRecord::ResetFullRecord() {
    auto header_region = GetRegionBounds(COV_START);
    if (!header_region.ok()) {
+1 −0
Original line number Diff line number Diff line
@@ -47,6 +47,7 @@ class CoverageRecord {

    ~CoverageRecord();
    Result<void> Open();
    bool IsOpen();
    void ResetFullRecord();
    void ResetCounts();
    void ResetPCs();
+12 −0
Original line number Diff line number Diff line
@@ -41,6 +41,10 @@ namespace trusty {
namespace fuzz {

ExtraCounters::ExtraCounters(coverage::CoverageRecord* record) : record_(record) {
    if (!record_->IsOpen()) {
        return;
    }

    assert(fuzzer::ExtraCountersBegin());
    assert(fuzzer::ExtraCountersEnd());

@@ -51,10 +55,18 @@ ExtraCounters::ExtraCounters(coverage::CoverageRecord* record) : record_(record)
}

ExtraCounters::~ExtraCounters() {
    if (!record_->IsOpen()) {
        return;
    }

    Flush();
}

void ExtraCounters::Reset() {
    if (!record_->IsOpen()) {
        return;
    }

    record_->ResetCounts();
    fuzzer::ClearExtraCounters();
}
+1 −1
Original line number Diff line number Diff line
@@ -113,7 +113,7 @@ Result<void> TrustyApp::Write(const void* buf, size_t len) {
    int rc = write(ta_fd_, buf, len);
    alarm(0);
    if (rc < 0) {
        return Error() << "failed to read TIPC message from TA: ";
        return Error() << "failed to write TIPC message to TA: ";
    }

    return {};