NXVmRegisterExitHandler

Registers a function to be called when the virtual machine (VM) exits or unloads.

Library:LibC
Classification:NKS
Service:NKS Virtual Machine

Syntax

  #include <nks/vm.h>
   
  int NXVmRegisterExitHandler (
     void   (*cleanup) (void *),
     void    *arg);
  

Parameters

cleanup

(IN) Points to the address of the function to be invoked at program exit.

arg

(IN) Points to the parameter to pass to the handler when it starts.

Return Values

If successful, returns zero; otherwise, returns an error:

Decimal

Hex

Constant

Description

5

0x05

NX_ENOMEM

Insufficient memory to perform registration.

105

0x69

NX_ENOCONTEXT

The calling thread has no NKS context.

Remarks

NXVmRegisterExitHandler associates a cleanup function with the calling application's VM so that the registered function gets called when the application exits. The value in arg is passed to it.

Subsequent calls result in chaining the cleanup handler to the next most recent. The order of invocation of these handlers is last-in, first-out (LIFO).

The cleanup function should be used for true cleanup needs of applications and libraries and not for common housekeeping chores.

Do not spend more time in cleanup functions than is absolutely necessary. While a function may block, it may be pulled from execution if it takes too long (this is an arbitrary time limit).

Cleanup handlers are called whenever the application unloads, regardless of the condition that caused the unload.

See Also

NXVmUnregisterExitHandler