C (or asm): how to execute c-code stored in memory (copied from shortcuts)

I am trying to "embed" my virtual machine by copying code segments from C code between tags to memory allocated by malloc. So I have Ops defined using start and end labels, and I want to copy the instruction defined by the following code to the buffer and then execute (Im not sure if this is possible)

OP_PUSH0_START:
    sp += 4; *sp = 0; // I WANT THE INSTRUCTIONS OF THIS LINE COPIED TO THE BUFFER
OP_PUSH0_END:

to do this, I thought the following code snippet would work

void * ptr0 = &&OP_PUSH0_START;
void * ptr1 = &&OP_PUSH0_END;
while(ptr0 < ptr1)
{
    buf[c++] = *ptr0;
    ptr0++;
}
goto buf; //jump to start of buffer

but I can not read it without receiving a memory error

I would welcome any links or any suggestions on how to achieve this.

+5
source share
2 answers

- . goto , - .

. .

, , CPU. . Windows Linux /// , .

, , Windows.

+2

Alexey , jit-.

C, x86

AsmJIT library - " " x86/x64, .

jit- LuaJIT. ARM/x86/PowerPC/MIPS.

" " C, , .

+1

All Articles