Alex Rivera | Logout

Allocate executable ram in c on linux

Asked 2010-06-26T22:47:07.743
14

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 function?

Edit
Report

1 Answer

19

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.

answered 2010-06-26T22:51:19.447

Your Answer