|
1 | 1 | import { |
2 | 2 | BpfState, |
3 | 3 | BpfValue, |
| 4 | + getMemSlotDependencies, |
4 | 5 | initialBpfState, |
5 | 6 | processRawLines, |
6 | 7 | VerifierLogState, |
@@ -659,4 +660,26 @@ Func#123 ('my_global_func') is global and assumed valid. |
659 | 660 | expect(s.values.get("r6")?.value).toBe("42"); |
660 | 661 | }); |
661 | 662 | }); |
| 663 | + |
| 664 | + describe("tracks side effect dependencies", () => { |
| 665 | + const rawLog = ` |
| 666 | +3: (85) call bpf_obj_new_impl#54651 ; R0_w=ptr_or_null_node_data(id=2,ref_obj_id=2) refs=2 |
| 667 | +4: (bf) r6 = r0 ; R0_w=ptr_or_null_node_data(id=2,ref_obj_id=2) R6_w=ptr_or_null_node_data(id=2,ref_obj_id=2) refs=2 |
| 668 | +6: (15) if r6 == 0x0 goto pc+104 ; R6_w=ptr_node_data(ref_obj_id=2) refs=2 |
| 669 | +42: (85) call bpf_rbtree_add_impl#54894 ; R0_w=scalar() R6=ptr_node_data(non_own_ref) R7=2 R8=ptr_node_data(ref_obj_id=4) R9=ptr_node_data(ref_obj_id=6) R10=fp0 refs=4,6 |
| 670 | +99: (55) if r0 != 0x0 goto pc+13 113: R0_w=ptr_node_data(non_own_ref,off=16) R6=scalar() R7=5 R8=scalar() R9=scalar() R10=fp0 |
| 671 | +117: (18) r1 = 0xff434b28008e3de8 ; R1_w=map_value(map=.data.A,ks=4,vs=72,off=16) |
| 672 | +119: (85) call bpf_spin_unlock#94 ; |
| 673 | +120: (79) r7 = *(u64 *)(r6 +8) |
| 674 | +`; |
| 675 | + const logState = getVerifierLogState(rawLog); |
| 676 | + it("120: (79) r7 = *(u64 *)(r6 +8)", () => { |
| 677 | + const idx = 7; |
| 678 | + const s = logState.bpfStates[idx]; |
| 679 | + expect(s.idx).toBe(7); |
| 680 | + expect(s.pc).toBe(120); |
| 681 | + const r6Deps = getMemSlotDependencies(logState, idx, "r6"); |
| 682 | + expect(r6Deps).toEqual(new Set<number>([4, 3, 2, 1, 0])); |
| 683 | + }); |
| 684 | + }); |
662 | 685 | }); |
0 commit comments