I am currently working on an interpreter for educational purposes, and I want the interpreter to be able to allocate aligned heap memory.
The instructions of my interpreter may contain addresses to this heap memory, and since I want it to be a little secure I would like to restrict the user to only address memory which was allocated by the interpreter.
So I tried to write my own heap allocator, which works on top of malloc
and realloc
, with the goal to be able to allocate blocks within a contiguous memory region in order to restrict accesses to that single big heap block.
Now a problem arose: Since I use realloc
, the interpreters memory may move around, and the paddings I added in the heap allocator may no longer be correct.
I am a bit lost; Is there a portable way how I could securely give an interpreter aligned memory allocation capabilities?