How to run a C++ program inside another C++ program?
You will have to write your own compiler.
Consider: No normal OS supports what you want. You want both executables to run inside a single process, yet that process may or may not make OS calls depending on some weirdness inside the process which the OS doesn't understand at all.
This is no longer a problem with your custom compiler, as it simply will not create the offending instructions. It's similar to Java and .Net, which also prevent such OS calls outside their control.
A portable solution: Google Native Client
One possible Linux solution:
- Make AppArmor profile with "hats" (a "hat" is a sandboxing configuration to which the application can switch programmatically with libapparmor),
- have the main application create a "pipe",
- have the main application "fork",
- change into a "hat" corresponding to the child application,
- "exec" the child application,
- the main application and the child application communicate via the "pipe" created earlier.