Skip to content

Commit d91e566

Browse files
committed
Remove unnecessary changes
Signed-off-by: Dave Thaler <[email protected]>
1 parent e72d697 commit d91e566

File tree

8 files changed

+30
-43
lines changed

8 files changed

+30
-43
lines changed

src/asm_unmarshal.cpp

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -541,9 +541,8 @@ struct Unmarshaller {
541541
}
542542
};
543543

544-
std::variant<InstructionSeq, std::string> unmarshal(const raw_program& raw_prog,const ebpf_verifier_options_t* options, vector<vector<string>>& notes) {
544+
std::variant<InstructionSeq, std::string> unmarshal(const raw_program& raw_prog, vector<vector<string>>& notes) {
545545
global_program_info = raw_prog.info;
546-
thread_local_options = (options != nullptr) ? *options : ebpf_verifier_default_options;
547546
try {
548547
return Unmarshaller{notes, raw_prog.info}.unmarshal(raw_prog.prog, raw_prog.line_info);
549548
} catch (InvalidInstruction& arg) {
@@ -553,9 +552,9 @@ std::variant<InstructionSeq, std::string> unmarshal(const raw_program& raw_prog,
553552
}
554553
}
555554

556-
std::variant<InstructionSeq, std::string> unmarshal(const raw_program& raw_prog, const ebpf_verifier_options_t* options) {
555+
std::variant<InstructionSeq, std::string> unmarshal(const raw_program& raw_prog) {
557556
vector<vector<string>> notes;
558-
return unmarshal(raw_prog, options, notes);
557+
return unmarshal(raw_prog, notes);
559558
}
560559

561560
Call make_call(int imm, const ebpf_platform_t& platform)

src/asm_unmarshal.hpp

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,10 @@
1515
/** Translate a sequence of eBPF instructions (elf binary format) to a sequence
1616
* of Instructions.
1717
*
18-
* \param[in] raw_prog The input program to parse.
19-
* \param[in] options Verifier options.
20-
* \param[out] notes Where errors and warnings are written to.
18+
* \param raw_prog The input program to parse.
19+
* \param notes Where errors and warnings are written to.
2120
* \return a sequence of instruction if successful, an error string otherwise.
2221
*/
23-
std::variant<InstructionSeq, std::string> unmarshal(const raw_program& raw_prog, const ebpf_verifier_options_t* options,
24-
std::vector<std::vector<std::string>>& notes);
25-
std::variant<InstructionSeq, std::string> unmarshal(const raw_program& raw_prog,
26-
const ebpf_verifier_options_t* options);
22+
std::variant<InstructionSeq, std::string> unmarshal(const raw_program& raw_prog, std::vector<std::vector<std::string>>& notes);
23+
std::variant<InstructionSeq, std::string> unmarshal(const raw_program& raw_prog);
2724
Call make_call(int func, const ebpf_platform_t& platform);

src/config.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,5 +12,5 @@ const ebpf_verifier_options_t ebpf_verifier_default_options = {
1212
.strict = false,
1313
.print_line_info = false,
1414
.allow_division_by_zero = true,
15-
.setup_constraints = true
15+
.setup_constraints = true,
1616
};

src/ebpf_yaml.cpp

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -330,24 +330,21 @@ ConformanceTestResult run_conformance_test_case(const std::vector<uint8_t>& memo
330330
platform.callx = true;
331331
raw_prog.info.platform = &platform;
332332

333-
ebpf_verifier_options_t options = ebpf_verifier_default_options;
334-
if (debug) {
335-
options.print_failures = true;
336-
options.print_invariants = true;
337-
options.no_simplify = true;
338-
}
339-
340333
// Convert the raw program section to a set of instructions.
341-
std::variant<InstructionSeq, std::string> prog_or_error = unmarshal(raw_prog, &options);
334+
std::variant<InstructionSeq, std::string> prog_or_error = unmarshal(raw_prog);
342335
if (std::holds_alternative<string>(prog_or_error)) {
343336
std::cerr << "unmarshaling error at " << std::get<string>(prog_or_error) << "\n";
344337
return {};
345338
}
346339

347340
auto& prog = std::get<InstructionSeq>(prog_or_error);
348341

342+
ebpf_verifier_options_t options = ebpf_verifier_default_options;
349343
if (debug) {
350344
print(prog, std::cout, {});
345+
options.print_failures = true;
346+
options.print_invariants = true;
347+
options.no_simplify = true;
351348
}
352349

353350
try {

src/main/check.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ int main(int argc, char** argv) {
146146
raw_program raw_prog = raw_progs.back();
147147

148148
// Convert the raw program section to a set of instructions.
149-
std::variant<InstructionSeq, std::string> prog_or_error = unmarshal(raw_prog, &ebpf_verifier_options);
149+
std::variant<InstructionSeq, std::string> prog_or_error = unmarshal(raw_prog);
150150
if (std::holds_alternative<string>(prog_or_error)) {
151151
std::cout << "unmarshaling error at " << std::get<string>(prog_or_error) << "\n";
152152
return 1;

src/test/test_marshal.cpp

Lines changed: 11 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,11 @@
88

99
// Verify that if we unmarshal an instruction and then re-marshal it,
1010
// we get what we expect.
11-
static void compare_unmarshal_marshal(const ebpf_inst& ins, const ebpf_inst& expected_result,
12-
const ebpf_verifier_options_t* options = nullptr,
13-
const ebpf_platform_t* platform = &g_ebpf_platform_linux) {
11+
static void compare_unmarshal_marshal(const ebpf_inst& ins, const ebpf_inst& expected_result, const ebpf_platform_t* platform = &g_ebpf_platform_linux) {
1412
program_info info{.platform = platform,
1513
.type = platform->get_program_type("unspec", "unspec")};
1614
const ebpf_inst exit{.opcode = INST_OP_EXIT};
17-
InstructionSeq parsed = std::get<InstructionSeq>(unmarshal(raw_program{"", "", {ins, exit, exit}, info}, options));
15+
InstructionSeq parsed = std::get<InstructionSeq>(unmarshal(raw_program{"", "", {ins, exit, exit}, info}));
1816
REQUIRE(parsed.size() == 3);
1917
auto [_, single, _2] = parsed.front();
2018
(void)_; // unused
@@ -32,7 +30,7 @@ static void compare_unmarshal_marshal(const ebpf_inst& ins1, const ebpf_inst& in
3230
program_info info{.platform = &g_ebpf_platform_linux,
3331
.type = g_ebpf_platform_linux.get_program_type("unspec", "unspec")};
3432
const ebpf_inst exit{.opcode = INST_OP_EXIT};
35-
InstructionSeq parsed = std::get<InstructionSeq>(unmarshal(raw_program{"", "", {ins1, ins2, exit, exit}, info}, nullptr));
33+
InstructionSeq parsed = std::get<InstructionSeq>(unmarshal(raw_program{"", "", {ins1, ins2, exit, exit}, info}));
3634
REQUIRE(parsed.size() == 3);
3735
auto [_, single, _2] = parsed.front();
3836
(void)_; // unused
@@ -47,12 +45,10 @@ static void compare_unmarshal_marshal(const ebpf_inst& ins1, const ebpf_inst& in
4745

4846
// Verify that if we marshal an instruction and then unmarshal it,
4947
// we get the original.
50-
static void compare_marshal_unmarshal(const Instruction& ins, bool double_cmd = false,
51-
const ebpf_verifier_options_t* options = nullptr,
52-
const ebpf_platform_t* platform = &g_ebpf_platform_linux) {
48+
static void compare_marshal_unmarshal(const Instruction& ins, bool double_cmd = false, const ebpf_platform_t* platform = &g_ebpf_platform_linux) {
5349
program_info info{.platform = platform,
5450
.type = platform->get_program_type("unspec", "unspec")};
55-
InstructionSeq parsed = std::get<InstructionSeq>(unmarshal(raw_program{"", "", marshal(ins, 0), info}, options));
51+
InstructionSeq parsed = std::get<InstructionSeq>(unmarshal(raw_program{"", "", marshal(ins, 0), info}));
5652
REQUIRE(parsed.size() == 1);
5753
auto [_, single, _2] = parsed.back();
5854
(void)_; // unused
@@ -64,17 +60,15 @@ static void check_marshal_unmarshal_fail(const Instruction& ins, std::string exp
6460
const ebpf_platform_t* platform = &g_ebpf_platform_linux) {
6561
program_info info{.platform = platform,
6662
.type = platform->get_program_type("unspec", "unspec")};
67-
std::string error_message = std::get<std::string>(unmarshal(raw_program{"", "", marshal(ins, 0), info}, nullptr));
63+
std::string error_message = std::get<std::string>(unmarshal(raw_program{"", "", marshal(ins, 0), info}));
6864
REQUIRE(error_message == expected_error_message);
6965
}
7066

71-
static void check_unmarshal_fail(ebpf_inst inst, std::string expected_error_message,
72-
const ebpf_verifier_options_t* options = nullptr,
73-
const ebpf_platform_t* platform = &g_ebpf_platform_linux) {
67+
static void check_unmarshal_fail(ebpf_inst inst, std::string expected_error_message, const ebpf_platform_t* platform = &g_ebpf_platform_linux) {
7468
program_info info{.platform = platform,
7569
.type = platform->get_program_type("unspec", "unspec")};
7670
std::vector<ebpf_inst> insns = {inst};
77-
auto result = unmarshal(raw_program{"", "", insns, info}, options);
71+
auto result = unmarshal(raw_program{"", "", insns, info});
7872
REQUIRE(std::holds_alternative<std::string>(result));
7973
std::string error_message = std::get<std::string>(result);
8074
REQUIRE(error_message == expected_error_message);
@@ -85,7 +79,7 @@ static void check_unmarshal_fail(ebpf_inst inst1, ebpf_inst inst2, std::string e
8579
program_info info{.platform = &g_ebpf_platform_linux,
8680
.type = g_ebpf_platform_linux.get_program_type("unspec", "unspec")};
8781
std::vector<ebpf_inst> insns = {inst1, inst2};
88-
auto result = unmarshal(raw_program{"", "", insns, info}, nullptr);
82+
auto result = unmarshal(raw_program{"", "", insns, info});
8983
REQUIRE(std::holds_alternative<std::string>(result));
9084
std::string error_message = std::get<std::string>(result);
9185
REQUIRE(error_message == expected_error_message);
@@ -187,8 +181,8 @@ TEST_CASE("disasm_marshal", "[disasm][marshal]") {
187181
// Test callx with support.
188182
ebpf_platform_t platform = g_ebpf_platform_linux;
189183
platform.callx = true;
190-
compare_marshal_unmarshal(Callx{8}, false, nullptr, &platform);
191-
check_unmarshal_fail(ebpf_inst{.opcode = /* 0x8d */ INST_OP_CALLX, .src = 11}, "0: Bad register\n", nullptr, &platform);
184+
compare_marshal_unmarshal(Callx{8}, false, &platform);
185+
check_unmarshal_fail(ebpf_inst{.opcode = /* 0x8d */ INST_OP_CALLX, .src = 11}, "0: Bad register\n", &platform);
192186
}
193187

194188
SECTION("Exit") { compare_marshal_unmarshal(Exit{}); }

src/test/test_print.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ void verify_printed_string(const std::string& file)
2727
std::stringstream generated_output;
2828
auto raw_progs = read_elf(std::string(TEST_OBJECT_FILE_DIRECTORY) + file + ".o", "", nullptr, &g_ebpf_platform_linux);
2929
raw_program raw_prog = raw_progs.back();
30-
std::variant<InstructionSeq, std::string> prog_or_error = unmarshal(raw_prog, nullptr);
30+
std::variant<InstructionSeq, std::string> prog_or_error = unmarshal(raw_prog);
3131
REQUIRE(std::holds_alternative<InstructionSeq>(prog_or_error));
3232
auto& program = std::get<InstructionSeq>(prog_or_error);
3333
print(program, generated_output, {});

src/test/test_verify.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ FAIL_LOAD_ELF("invalid", "badsymsize.o", "xdp_redirect_map")
2424
auto raw_progs = read_elf("ebpf-samples/" dirname "/" filename, sectionname, nullptr, &g_ebpf_platform_linux); \
2525
REQUIRE(raw_progs.size() == 1); \
2626
raw_program raw_prog = raw_progs.back(); \
27-
std::variant<InstructionSeq, std::string> prog_or_error = unmarshal(raw_prog, nullptr); \
27+
std::variant<InstructionSeq, std::string> prog_or_error = unmarshal(raw_prog); \
2828
REQUIRE(std::holds_alternative<std::string>(prog_or_error)); \
2929
}
3030

@@ -37,7 +37,7 @@ FAIL_UNMARSHAL("invalid", "invalid-lddw.o", ".text")
3737
auto raw_progs = read_elf("ebpf-samples/" dirname "/" filename, sectionname, nullptr, &g_ebpf_platform_linux); \
3838
REQUIRE(raw_progs.size() == 1); \
3939
raw_program raw_prog = raw_progs.back(); \
40-
std::variant<InstructionSeq, std::string> prog_or_error = unmarshal(raw_prog, options); \
40+
std::variant<InstructionSeq, std::string> prog_or_error = unmarshal(raw_prog); \
4141
REQUIRE(std::holds_alternative<InstructionSeq>(prog_or_error)); \
4242
auto& prog = std::get<InstructionSeq>(prog_or_error); \
4343
bool res = ebpf_verify_program(std::cout, prog, raw_prog.info, options, nullptr); \
@@ -549,15 +549,15 @@ TEST_CASE("multithreading", "[verify][multithreading]") {
549549
auto raw_progs1 = read_elf("ebpf-samples/bpf_cilium_test/bpf_netdev.o", "2/1", nullptr, &g_ebpf_platform_linux);
550550
REQUIRE(raw_progs1.size() == 1);
551551
raw_program raw_prog1 = raw_progs1.back();
552-
std::variant<InstructionSeq, std::string> prog_or_error1 = unmarshal(raw_prog1, options);
552+
std::variant<InstructionSeq, std::string> prog_or_error1 = unmarshal(raw_prog1);
553553
REQUIRE(std::holds_alternative<InstructionSeq>(prog_or_error1));
554554
auto& prog1 = std::get<InstructionSeq>(prog_or_error1);
555555
cfg_t cfg1 = prepare_cfg(prog1, raw_prog1.info, true);
556556

557557
auto raw_progs2 = read_elf("ebpf-samples/bpf_cilium_test/bpf_netdev.o", "2/2", nullptr, &g_ebpf_platform_linux);
558558
REQUIRE(raw_progs2.size() == 1);
559559
raw_program raw_prog2 = raw_progs2.back();
560-
std::variant<InstructionSeq, std::string> prog_or_error2 = unmarshal(raw_prog2, options);
560+
std::variant<InstructionSeq, std::string> prog_or_error2 = unmarshal(raw_prog2);
561561
REQUIRE(std::holds_alternative<InstructionSeq>(prog_or_error2));
562562
auto& prog2 = std::get<InstructionSeq>(prog_or_error2);
563563
cfg_t cfg2 = prepare_cfg(prog2, raw_prog2.info, true);

0 commit comments

Comments
 (0)