Spawns an application in a new virtual machine (VM).
#include <nks/vm.h> int NXVmSpawn ( NXNameSpec_t *name, NXExecEnvSpec_t *envSpec, unsigned long flags, NXVmId_t *newVm);
(IN) Specifies the location of the application binary file which runs in the new virtual machine. See NXNameSpec_t.
(IN) Specifies the environment of the new VM. See NXExecEnvSpec_t.
(IN) Specifies one or more of the following flags that modify the spawn behavior:
(OUT) Points to the identifying value of the new virtual machine. If the NX_VM_DETACHED flag is set, it is set to NX_VM_INVALID_ID.
If successful, returns zero; otherwise returns a nonzero error code:
NXVmSpawn creates a new VM and sets an application to run in it.
This spawn interface creates a functional imitation of UNIX-style exec. The start-up (or prelude) code does the I/O redirection wiring, as well as passing argc, argv, and env.
The caller must satisfy all memory needs surrounding the elements communicated through the first two arguments (string pointers in argv, env, and the NXStreamSpec_t fields). After the call completes, this memory is no longer accessed and need not remain valid.
WARNING:The NLM spawned by NXVmSpawn must be a LibC based NLM. You cannot spawn a CLib based NLM with NXVmSpawn.
By default, the spawned VM is not detached and is joinable. A valid identity is returned in newVm. If the new virtual machine is set to be detached, a NULL identity is returned in newVm, and it is impossible for the caller to terminate it.
NKS creates an application thread inside the newly spawned virtual machine which calls into the main routine of the application in the VM. This main thread is not bound to its context and is a joinable thread. The main() thread is special in that if this thread “falls off the bottom” of the main routine, VM exit is initiated even if there are other application threads in the VM. If any other thread “falls off the bottom” of the routine specified at the time of creation of the context hosted by the thread, VM exit is not initiated. If the main thread were to call NXThreadExit, only that thread exits. VM tear down is not initiated in this case except if it is the last application thread in the VM, in which case VM tear down will be initiated. In other words, if the main thread calls NXThreadExit and other applications threads exist in the VM, then the VM is not torn down.The main thread is joinable. When it exits using NXThreadExit, another thread in the VM can perform a join operation on it. When the VM exits and no thread has performed a join operation on the main thread, NKS implicitly performs a join operation on it.
By default the new machine is set to run preemptively.