Allocate executable ram in c on linux

前端 未结 2 1875
南旧
南旧 2020-12-02 00:16

I want to make a simple just-in-time compiler with c on Linux.

How can I allocate memory such that I can write out raw x86 code to it and execute it as any other fun

2条回答
  •  天涯浪人
    2020-12-02 00:24

    See mprotect(). Once you have filled a (n-)page-sized memory region (allocated with mmap()) with code, change its permissions to disallow writes and allow execution.

提交回复
热议问题