With the machine code in memory, cast its address to a function pointer. Of course you need to comply with the C calling convention.
On most desktop OSes, you'll need to change memory permissions to mark it executable, e.g. on Windows call VirtualProtect
and on Linux mprotect
.
Binary machine instructions are not cross-platform. You will need to generate different code for each processor architecture.
No driver is needed as long as the code only requires user-level permissions.