Skip to content

Commit

Permalink
clang-format and tidy
Browse files Browse the repository at this point in the history
Signed-off-by: Elazar Gershuni <[email protected]>
  • Loading branch information
elazarg committed Nov 4, 2024
1 parent 481e935 commit 33bd81a
Show file tree
Hide file tree
Showing 6 changed files with 39 additions and 39 deletions.
2 changes: 1 addition & 1 deletion src/asm_syntax.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ struct label_t {
if (stack_frame_prefix.empty()) {
return 1;
}
return 2 + std::count(stack_frame_prefix.begin(), stack_frame_prefix.end(), STACK_FRAME_DELIMITER);
return 2 + std::ranges::count(stack_frame_prefix, STACK_FRAME_DELIMITER);
}

friend std::ostream& operator<<(std::ostream& os, const label_t& label) {
Expand Down
12 changes: 6 additions & 6 deletions src/assertions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,10 @@ class AssertExtractor {
return res;
}

ValidAccess make_valid_access(Reg reg, int32_t offset = {}, Value width = Imm{0}, bool or_null = {},
AccessType access_type = {}) const {
int depth = current_label.has_value() ? current_label.value().call_stack_depth() : 1;
return ValidAccess{ depth, reg, offset, width, or_null, access_type};
ValidAccess make_valid_access(const Reg reg, const int32_t offset = {}, const Value& width = Imm{0},
const bool or_null = {}, const AccessType access_type = {}) const {
const int depth = current_label.has_value() ? current_label.value().call_stack_depth() : 1;
return ValidAccess{depth, reg, offset, width, or_null, access_type};
}

public:
Expand Down Expand Up @@ -207,8 +207,8 @@ class AssertExtractor {
}
} else {
res.emplace_back(TypeConstraint{basereg, TypeGroup::pointer});
res.emplace_back(make_valid_access(basereg, offset, width, false,
ins.is_load ? AccessType::read : AccessType::write));
res.emplace_back(
make_valid_access(basereg, offset, width, false, ins.is_load ? AccessType::read : AccessType::write));
if (!info.type.is_privileged && !ins.is_load) {
if (const auto preg = std::get_if<Reg>(&ins.value)) {
if (width.v != 8) {
Expand Down
22 changes: 11 additions & 11 deletions src/crab/ebpf_domain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -941,15 +941,15 @@ void ebpf_domain_t::havoc_subprogram_stack(const std::string& prefix) {
// Calculate the call stack depth being returned from. Since we're returning
// *to* the given prefix, the current call stack is 2 + the number of
// '/' separators because we need to account for the current frame and the root frame.
int call_stack_depth = 2 + std::count(prefix.begin(), prefix.end(), STACK_FRAME_DELIMITER);
const int call_stack_depth = 2 + std::ranges::count(prefix, STACK_FRAME_DELIMITER);

variable_t r10_stack_offset = reg_pack(R10_STACK_POINTER).stack_offset;
auto intv = m_inv.eval_interval(r10_stack_offset);
const variable_t r10_stack_offset = reg_pack(R10_STACK_POINTER).stack_offset;
const auto intv = m_inv.eval_interval(r10_stack_offset);
if (!intv.is_singleton()) {
return;
}
int64_t stack_offset = intv.singleton()->cast_to<int64_t>();
int32_t stack_start = stack_offset - EBPF_SUBPROGRAM_STACK_SIZE * call_stack_depth;
const int64_t stack_offset = intv.singleton()->cast_to<int64_t>();
const int32_t stack_start = stack_offset - EBPF_SUBPROGRAM_STACK_SIZE * call_stack_depth;
for (const data_kind_t kind : iterate_kinds()) {
stack.havoc(m_inv, kind, stack_start, EBPF_SUBPROGRAM_STACK_SIZE);
}
Expand Down Expand Up @@ -1201,13 +1201,13 @@ void ebpf_domain_t::operator()(const basic_block_t& bb) {
}
}

void ebpf_domain_t::check_access_stack(NumAbsDomain& inv, const linear_expression_t& lb,
const linear_expression_t& ub, int call_stack_depth) const {
void ebpf_domain_t::check_access_stack(NumAbsDomain& inv, const linear_expression_t& lb, const linear_expression_t& ub,
const int call_stack_depth) const {
using namespace crab::dsl_syntax;
variable_t r10_stack_offset = reg_pack(R10_STACK_POINTER).stack_offset;
auto interval = inv.eval_interval(r10_stack_offset);
const variable_t r10_stack_offset = reg_pack(R10_STACK_POINTER).stack_offset;
const auto interval = inv.eval_interval(r10_stack_offset);
if (interval.is_singleton()) {
int64_t stack_offset = interval.singleton()->cast_to<int64_t>();
const int64_t stack_offset = interval.singleton()->cast_to<int64_t>();
require(inv, lb >= stack_offset - EBPF_SUBPROGRAM_STACK_SIZE * call_stack_depth,
"Lower bound must be at least r10.stack_offset - EBPF_SUBPROGRAM_STACK_SIZE * call_stack_depth");
}
Expand Down Expand Up @@ -2054,7 +2054,7 @@ void ebpf_domain_t::do_mem_store(const Mem& b, Type val_type, SValue val_svalue,
int width = b.access.width;
const number_t offset{b.access.offset};
if (b.access.basereg.v == R10_STACK_POINTER) {
auto r10_stack_offset = reg_pack(b.access.basereg).stack_offset;
const auto r10_stack_offset = reg_pack(b.access.basereg).stack_offset;
const auto r10_interval = m_inv.eval_interval(r10_stack_offset);
if (r10_interval.is_singleton()) {
const int32_t stack_offset = r10_interval.singleton()->cast_to<int32_t>();
Expand Down
6 changes: 3 additions & 3 deletions src/test/conformance_check.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,16 +21,16 @@
* @param[in] input String containing hex bytes.
* @return Vector of bytes.
*/
std::vector<uint8_t> base16_decode(const std::string& input) {
std::vector<uint8_t> output;
std::vector<std::byte> base16_decode(const std::string& input) {
std::vector<std::byte> output;
std::stringstream ss(input);
std::string value;
while (std::getline(ss, value, ' ')) {
if (value.empty()) {
continue;
}
try {
output.push_back(std::stoi(value, nullptr, 16));
output.push_back(static_cast<std::byte>(std::stoi(value, nullptr, 16)));
} catch (std::invalid_argument&) {
std::cerr << "base16_decode failed to decode " << value << "\n";
} catch (std::out_of_range&) {
Expand Down
32 changes: 16 additions & 16 deletions src/test/ebpf_yaml.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -269,30 +269,30 @@ std::optional<Failure> run_yaml_test_case(TestCase test_case, bool debug) {
}

template <typename T>
static vector<T> vector_of(const std::vector<uint8_t>& bytes) {
static vector<T> vector_of(const std::vector<std::byte>& bytes) {
auto data = bytes.data();
const auto size = bytes.size();
if ((size % sizeof(T) != 0) || size > std::numeric_limits<uint32_t>::max() || !data) {
if (size % sizeof(T) != 0 || size > std::numeric_limits<uint32_t>::max() || !data) {
throw std::runtime_error("Invalid argument to vector_of");
}
return {reinterpret_cast<const T*>(data), reinterpret_cast<const T*>(data + size)};
}

template <typename TS>
void add_stack_variable(std::set<std::string>& more, int& offset, const std::vector<uint8_t>& memory_bytes) {
template <std::signed_integral TS>
void add_stack_variable(std::set<std::string>& more, int& offset, const std::vector<std::byte>& memory_bytes) {
using TU = std::make_unsigned_t<TS>;
TS svalue;
TU uvalue;
memcpy(&svalue, memory_bytes.data() + offset + memory_bytes.size() - EBPF_TOTAL_STACK_SIZE, sizeof(TS));
memcpy(&uvalue, memory_bytes.data() + offset + memory_bytes.size() - EBPF_TOTAL_STACK_SIZE, sizeof(TU));
more.insert("s[" + std::to_string(offset) + "..." + std::to_string(offset + sizeof(TS) - 1) + "].svalue" + "=" +
std::to_string(svalue));
more.insert("s[" + std::to_string(offset) + "..." + std::to_string(offset + sizeof(TU) - 1) + "].uvalue" + "=" +
std::to_string(uvalue));
offset += sizeof(TS);
constexpr size_t size = sizeof(TS);
static_assert(sizeof(TU) == size);
const auto src = memory_bytes.data() + offset + memory_bytes.size() - EBPF_TOTAL_STACK_SIZE;
const TS svalue{*reinterpret_cast<const TS*>(src)};
const TU uvalue{*reinterpret_cast<const TU*>(src)};
const auto range = "s[" + std::to_string(offset) + "..." + std::to_string(offset + size - 1) + "]";
more.insert(range + ".svalue=" + std::to_string(svalue));
more.insert(range + ".uvalue=" + std::to_string(uvalue));
offset += size;
}

string_invariant stack_contents_invariant(const std::vector<uint8_t>& memory_bytes) {
string_invariant stack_contents_invariant(const std::vector<std::byte>& memory_bytes) {
std::set<std::string> more = {"r1.type=stack",
"r1.stack_offset=" + std::to_string(EBPF_TOTAL_STACK_SIZE - memory_bytes.size()),
"r1.stack_numeric_size=" + std::to_string(memory_bytes.size()),
Expand All @@ -318,8 +318,8 @@ string_invariant stack_contents_invariant(const std::vector<uint8_t>& memory_byt
return string_invariant(more);
}

ConformanceTestResult run_conformance_test_case(const std::vector<uint8_t>& memory_bytes,
const std::vector<uint8_t>& program_bytes, bool debug) {
ConformanceTestResult run_conformance_test_case(const std::vector<std::byte>& memory_bytes,
const std::vector<std::byte>& program_bytes, bool debug) {
ebpf_context_descriptor_t context_descriptor{64, -1, -1, -1};
EbpfProgramType program_type = make_program_type("conformance_check", &context_descriptor);

Expand Down
4 changes: 2 additions & 2 deletions src/test/ebpf_yaml.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ struct ConformanceTestResult {
crab::interval_t r0_value = crab::interval_t::top();
};

ConformanceTestResult run_conformance_test_case(const std::vector<uint8_t>& memory_bytes,
const std::vector<uint8_t>& program_bytes, bool debug);
ConformanceTestResult run_conformance_test_case(const std::vector<std::byte>& memory_bytes,
const std::vector<std::byte>& program_bytes, bool debug);

bool run_yaml(const std::string& path);

0 comments on commit 33bd81a

Please sign in to comment.