|
|
@@ -135,12 +135,8 @@ static int global_deref_ir_post(const struct func *func, struct node *n,
|
|
135
|
135
|
be overwritten, so skip the load. */
|
|
136
|
136
|
return 0;
|
|
137
|
137
|
|
|
138
|
|
- ir_emit_insn(prog->ir, MOV, BPF_REG_1, BPF_REG_BP);
|
|
139
|
|
- ir_emit_insn(prog->ir, ALU_IMM(BPF_ADD, dst->stack), BPF_REG_1, 0);
|
|
140
|
|
- ir_emit_insn(prog->ir, MOV_IMM((int32_t)dst->size), BPF_REG_2, 0);
|
|
141
|
138
|
ir_emit_sym_to_reg(prog->ir, BPF_REG_3, ptr->sym);
|
|
142
|
|
- ir_emit_insn(prog->ir, CALL(BPF_FUNC_probe_read), 0, 0);
|
|
143
|
|
- /* TODO if (r0) exit(r0); */
|
|
|
139
|
+ ir_emit_read_to_sym(prog->ir, n->sym, BPF_REG_3);
|
|
144
|
140
|
return 0;
|
|
145
|
141
|
}
|
|
146
|
142
|
|
|
|
@@ -232,6 +228,7 @@ static int global_map_ir_post(const struct func *func, struct node *n,
|
|
232
|
228
|
ssize_t stack = map->sym->irs.stack;
|
|
233
|
229
|
size_t offset;
|
|
234
|
230
|
struct tfield *f;
|
|
|
231
|
+ int16_t lmiss, lhit;
|
|
235
|
232
|
|
|
236
|
233
|
arg = map->next;
|
|
237
|
234
|
tfields_foreach(f, ktype->sou.fields) {
|
|
|
@@ -239,6 +236,31 @@ static int global_map_ir_post(const struct func *func, struct node *n,
|
|
239
|
236
|
ir_emit_sym_to_stack(prog->ir, stack + offset, arg->sym);
|
|
240
|
237
|
arg = arg->next;
|
|
241
|
238
|
}
|
|
|
239
|
+
|
|
|
240
|
+ if (n->sym->irs.hint.lval)
|
|
|
241
|
+ /* map[key] = val, whatever is in our storage now it
|
|
|
242
|
+ will be overwritten, so skip the load. */
|
|
|
243
|
+ return 0;
|
|
|
244
|
+
|
|
|
245
|
+ n->sym->irs.hint.stack = 1;
|
|
|
246
|
+ ir_init_sym(prog->ir, n->sym);
|
|
|
247
|
+
|
|
|
248
|
+ ir_emit_ldmap(prog->ir, BPF_REG_1, map->sym);
|
|
|
249
|
+ ir_emit_insn(prog->ir, MOV, BPF_REG_2, BPF_REG_BP);
|
|
|
250
|
+ ir_emit_insn(prog->ir, ALU_IMM(BPF_ADD, stack), BPF_REG_BP, 0);
|
|
|
251
|
+ ir_emit_insn(prog->ir, CALL(BPF_FUNC_map_lookup_elem), 0, 0);
|
|
|
252
|
+
|
|
|
253
|
+ lmiss = ir_alloc_label(prog->ir);
|
|
|
254
|
+ lhit = ir_alloc_label(prog->ir);
|
|
|
255
|
+
|
|
|
256
|
+ ir_emit_insn(prog->ir, JMP_IMM(BPF_JEQ, 0, lmiss), BPF_REG_0, 0);
|
|
|
257
|
+ ir_emit_read_to_sym(prog->ir, n->sym, BPF_REG_0);
|
|
|
258
|
+ ir_emit_insn(prog->ir, JMP(BPF_JA, lhit), 0, 0);
|
|
|
259
|
+
|
|
|
260
|
+ ir_emit_label(prog->ir, lmiss);
|
|
|
261
|
+ ir_emit_bzero(prog->ir, n->sym->irs.stack, n->sym->irs.size);
|
|
|
262
|
+
|
|
|
263
|
+ ir_emit_label(prog->ir, lhit);
|
|
242
|
264
|
return 0;
|
|
243
|
265
|
}
|
|
244
|
266
|
|