dlopen from memory?

后端 未结 4 834
故里飘歌
故里飘歌 2020-11-27 04:30

I\'m looking for a way to load generated object code directly from memory.

I understand that if I write it to a file, I can call dlopen to dynamically load its symbo

4条回答
  •  误落风尘
    2020-11-27 04:58

    I don't see why you'd be considering dlopen, since that will require a lot more nonportable code to generate the right object format on disk (e.g. ELF) for loading. If you already know how to generate machine code for your architecture, just mmap memory with PROT_READ|PROT_WRITE|PROT_EXEC and put your code there, then assign the address to a function pointer and call it. Very simple.

提交回复
热议问题