PR_RISCV_SET_ICACHE_FLUSH_CTX(2const) PR_RISCV_SET_ICACHE_FLUSH_CTX(2const) PR_RISCV_SET_ICACHE_FLUSH_CTX - / (icache) (libc -lc) #include /* PR_* */ #include int prctl(PR_RISCV_SET_ICACHE_FLUSH_CTX, unsigned long ctx, unsigned long scope); ctx scope . scope PR_RISCV_SCOPE_PER_PROCESS . . . . . ( scope PR_RISCV_SCOPE_PER_THREAD) . . SMP PR_RISCV_SET_ICACHE_FLUSH_CTX . ctx: PR_RISCV_CTX_SW_FENCEI_ON ( 6.10) fence.i . PR_RISCV_CTX_SW_FENCEI_OFF ( 6.10) fence.i . scope PR_RISCV_SCOPE_PER_PROCESS. fence.i . scope: PR_RISCV_SCOPE_PER_PROCESS ( 6.10) . PR_RISCV_SCOPE_PER_THREAD ( 6.10) . . modify_instruction() get_value() . : cmodx.c #include #include extern int get_value(void); extern void modify_instruction(void); int main(void) { int value = get_value(); printf(" cmodx: %d\n", value); // prctl fence.i prctl(PR_RISCV_SET_ICACHE_FLUSH_CTX, PR_RISCV_CTX_SW_FENCEI_ON, PR_RISCV_SCOPE_PER_PROCESS); modify_instruction(); // prctl fence.i prctl(PR_RISCV_SET_ICACHE_FLUSH_CTX, PR_RISCV_CTX_SW_FENCEI_OFF, PR_RISCV_SCOPE_PER_PROCESS); value = get_value(); printf(" cmodx: %d\n", value); return 0; } : cmodx.S .option norvc .text .global modify_instruction modify_instruction: lw a0, new_insn lui a5,%hi(old_insn) sw a0,%lo(old_insn)(a5) fence.i ret .section modifiable, "awx" .global get_value get_value: li a0, 0 old_insn: addi a0, a0, 0 ret .data new_insn: addi a0, a0, 1 cmodx: 0 cmodx: 1 . RISC-V. 6.10 (RISC-V). prctl(2) 3 . . : . 6.18 8 2026 PR_RISCV_SET_ICACHE_FLUSH_CTX(2const)