cachepc-linux

Fork of AMDESE/linux with modifications for CachePC side-channel attack
git clone https://git.sinitax.com/sinitax/cachepc-linux
Log | Files | Refs | README | LICENSE | sfeed.txt

atomic_xchg.c (1253B)


      1{
      2	"atomic exchange smoketest - 64bit",
      3	.insns = {
      4		/* val = 3; */
      5		BPF_ST_MEM(BPF_DW, BPF_REG_10, -8, 3),
      6		/* old = atomic_xchg(&val, 4); */
      7		BPF_MOV64_IMM(BPF_REG_1, 4),
      8		BPF_ATOMIC_OP(BPF_DW, BPF_XCHG, BPF_REG_10, BPF_REG_1, -8),
      9		/* if (old != 3) exit(1); */
     10		BPF_JMP_IMM(BPF_JEQ, BPF_REG_1, 3, 2),
     11		BPF_MOV64_IMM(BPF_REG_0, 1),
     12		BPF_EXIT_INSN(),
     13		/* if (val != 4) exit(2); */
     14		BPF_LDX_MEM(BPF_DW, BPF_REG_0, BPF_REG_10, -8),
     15		BPF_JMP_IMM(BPF_JEQ, BPF_REG_0, 4, 2),
     16		BPF_MOV64_IMM(BPF_REG_0, 2),
     17		BPF_EXIT_INSN(),
     18		/* exit(0); */
     19		BPF_MOV64_IMM(BPF_REG_0, 0),
     20		BPF_EXIT_INSN(),
     21	},
     22	.result = ACCEPT,
     23},
     24{
     25	"atomic exchange smoketest - 32bit",
     26	.insns = {
     27		/* val = 3; */
     28		BPF_ST_MEM(BPF_W, BPF_REG_10, -4, 3),
     29		/* old = atomic_xchg(&val, 4); */
     30		BPF_MOV32_IMM(BPF_REG_1, 4),
     31		BPF_ATOMIC_OP(BPF_W, BPF_XCHG, BPF_REG_10, BPF_REG_1, -4),
     32		/* if (old != 3) exit(1); */
     33		BPF_JMP32_IMM(BPF_JEQ, BPF_REG_1, 3, 2),
     34		BPF_MOV32_IMM(BPF_REG_0, 1),
     35		BPF_EXIT_INSN(),
     36		/* if (val != 4) exit(2); */
     37		BPF_LDX_MEM(BPF_W, BPF_REG_0, BPF_REG_10, -4),
     38		BPF_JMP32_IMM(BPF_JEQ, BPF_REG_0, 4, 2),
     39		BPF_MOV32_IMM(BPF_REG_0, 2),
     40		BPF_EXIT_INSN(),
     41		/* exit(0); */
     42		BPF_MOV32_IMM(BPF_REG_0, 0),
     43		BPF_EXIT_INSN(),
     44	},
     45	.result = ACCEPT,
     46},