Skip to content

Commit 36ca52f

Browse files
Fix gate replacement for non-EPT backends.
1 parent 9970ccc commit 36ca52f

3 files changed

Lines changed: 75 additions & 58 deletions

File tree

kraft/app/app.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -837,18 +837,22 @@ def simple_replace(template_path, path, marker, shstack_enabled=True):
837837
add_local_linkerscript(lib, fulldiff=fulldiff)
838838

839839
# then generate cocci files dynamically from the template
840-
gr_rule_template = get_sec_rule("gatereplacer.cocci.in")
840+
if is_ept:
841+
gr_rule_template = get_sec_rule("gatereplacer_ept.cocci.in")
842+
else:
843+
gr_rule_template = get_sec_rule("gatereplacer.cocci.in")
841844
if FCALLS_enabled:
842845
cb_rule_template = get_sec_rule("rmcallbacks.cocci.in")
843846
else:
844847
cb_rule_template = get_sec_rule("callbackreplacer.cocci.in")
848+
845849
gr_rule_template = gr_rule_template.replace("{{ comp_cur_nb }}",
846850
str(lib.compartment.number))
851+
ept_rpc_id_prefix = "_RPC_ID_" if is_ept else ""
847852
cb_rule_template = cb_rule_template.replace("{{ comp_cur_nb }}",
848853
str(lib.compartment.number))
849854
gr_rule = ""
850855

851-
ept_rpc_id_prefix = "_RPC_ID_" if is_ept else ""
852856
if (is_ept):
853857
rpc_id_gen_template = get_sec_rule("rpc_id_gen.cocci.in")
854858
rpc_id_gen_template = rpc_id_gen_template.replace("{{ filename }}",
Lines changed: 4 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -1,65 +1,13 @@
1-
@gatereplacer_return0_{{ rule_nr }}@
2-
identifier func;
3-
expression ret, lname;
4-
fresh identifier func_id = "{{ ept_id_prefix }}" ## func;
5-
@@
6-
- flexos_gate_r({{ lib_dest_name }}, ret, func);
7-
+ {{ gate_r }}({{ comp_cur_nb }}, {{ comp_dest_nb }}, ret, func_id);
8-
9-
@script:python@
10-
func_name << gatereplacer_return0_{{ rule_nr }}.func;
11-
@@
12-
fname = str(func_name)
13-
if fname not in entries:
14-
entries[fname] = entry_cnt
15-
entry_cnt += 1
16-
171
@gatereplacer_return{{ rule_nr }}@
18-
identifier func;
192
expression list EL;
203
expression ret, lname;
21-
fresh identifier func_id = "{{ ept_id_prefix }}" ## func;
22-
@@
23-
- flexos_gate_r({{ lib_dest_name }}, ret, func, EL);
24-
+ {{ gate_r }}({{ comp_cur_nb }}, {{ comp_dest_nb }}, ret, func_id, EL);
25-
26-
@script:python@
27-
func_name << gatereplacer_return{{ rule_nr }}.func;
284
@@
29-
fname = str(func_name)
30-
if fname not in entries:
31-
entries[fname] = entry_cnt
32-
entry_cnt += 1
33-
34-
@gatereplacer_noreturn0_{{ rule_nr }}@
35-
identifier func;
36-
expression lname;
37-
fresh identifier func_id = "{{ ept_id_prefix }}" ## func;
38-
@@
39-
- flexos_gate({{ lib_dest_name }}, func);
40-
+ {{ gate }}({{ comp_cur_nb }}, {{ comp_dest_nb }}, func_id);
41-
42-
@script:python@
43-
func_name << gatereplacer_noreturn0_{{ rule_nr }}.func;
44-
@@
45-
fname = str(func_name)
46-
if fname not in entries:
47-
entries[fname] = entry_cnt
48-
entry_cnt += 1
5+
- flexos_gate_r({{ lib_dest_name }}, ret, EL);
6+
+ {{ gate_r }}({{ comp_cur_nb }}, {{ comp_dest_nb }}, ret, EL);
497

508
@gatereplacer_noreturn{{ rule_nr }}@
51-
identifier func;
529
expression list EL;
5310
expression lname;
54-
fresh identifier func_id = "{{ ept_id_prefix }}" ## func;
55-
@@
56-
- flexos_gate({{ lib_dest_name }}, func, EL);
57-
+ {{ gate }}({{ comp_cur_nb }}, {{ comp_dest_nb }}, func_id, EL);
58-
59-
@script:python@
60-
func_name << gatereplacer_noreturn{{ rule_nr }}.func;
6111
@@
62-
fname = str(func_name)
63-
if fname not in entries:
64-
entries[fname] = entry_cnt
65-
entry_cnt += 1
12+
- flexos_gate({{ lib_dest_name }}, EL);
13+
+ {{ gate }}({{ comp_cur_nb }}, {{ comp_dest_nb }}, EL);
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
@gatereplacer_return0_{{ rule_nr }}@
2+
identifier func;
3+
expression ret, lname;
4+
fresh identifier func_id = "{{ ept_id_prefix }}" ## func;
5+
@@
6+
- flexos_gate_r({{ lib_dest_name }}, ret, func);
7+
+ {{ gate_r }}({{ comp_cur_nb }}, {{ comp_dest_nb }}, ret, func_id);
8+
9+
@script:python@
10+
func_name << gatereplacer_return0_{{ rule_nr }}.func;
11+
@@
12+
fname = str(func_name)
13+
if fname not in entries:
14+
entries[fname] = entry_cnt
15+
entry_cnt += 1
16+
17+
@gatereplacer_return{{ rule_nr }}@
18+
identifier func;
19+
expression list EL;
20+
expression ret, lname;
21+
fresh identifier func_id = "{{ ept_id_prefix }}" ## func;
22+
@@
23+
- flexos_gate_r({{ lib_dest_name }}, ret, func, EL);
24+
+ {{ gate_r }}({{ comp_cur_nb }}, {{ comp_dest_nb }}, ret, func_id, EL);
25+
26+
@script:python@
27+
func_name << gatereplacer_return{{ rule_nr }}.func;
28+
@@
29+
fname = str(func_name)
30+
if fname not in entries:
31+
entries[fname] = entry_cnt
32+
entry_cnt += 1
33+
34+
@gatereplacer_noreturn0_{{ rule_nr }}@
35+
identifier func;
36+
expression lname;
37+
fresh identifier func_id = "{{ ept_id_prefix }}" ## func;
38+
@@
39+
- flexos_gate({{ lib_dest_name }}, func);
40+
+ {{ gate }}({{ comp_cur_nb }}, {{ comp_dest_nb }}, func_id);
41+
42+
@script:python@
43+
func_name << gatereplacer_noreturn0_{{ rule_nr }}.func;
44+
@@
45+
fname = str(func_name)
46+
if fname not in entries:
47+
entries[fname] = entry_cnt
48+
entry_cnt += 1
49+
50+
@gatereplacer_noreturn{{ rule_nr }}@
51+
identifier func;
52+
expression list EL;
53+
expression lname;
54+
fresh identifier func_id = "{{ ept_id_prefix }}" ## func;
55+
@@
56+
- flexos_gate({{ lib_dest_name }}, func, EL);
57+
+ {{ gate }}({{ comp_cur_nb }}, {{ comp_dest_nb }}, func_id, EL);
58+
59+
@script:python@
60+
func_name << gatereplacer_noreturn{{ rule_nr }}.func;
61+
@@
62+
fname = str(func_name)
63+
if fname not in entries:
64+
entries[fname] = entry_cnt
65+
entry_cnt += 1

0 commit comments

Comments
 (0)