Assuming that a VM runs a JIT compiler on otherwise "interpreted" code, such as a line by line interpreter or some form of bytecode/IL code and determines that it can create optimised native code for some part of what is running, what mechanism is actually used to "emit" and then call the emitted code?

If I was writing a normal compiler, I couldsimply write the desired binary to a file, to be run later by the system in whatever manner it usually would be, but how would a JIT compiler do that during runtime, running the new code within the same process that created it? Would it simply write the raw bytes into an array of contiguous memory, cast that memory/arrays pointer as a function pointer, and call it? Or are there some other functions available in low level languages to facilitate this?