The ChorusOS operating system offers various services which enable an actor to extend its address space dynamically by allocating memory regions. An actor may also shrink its address space by freeing memory regions. A memory area to be allocated or freed is identified by the system through a region descriptor of the following type:
typedef struct { VmAddr startAddr; VmSize size; VmFlags options; VmAddr endAddr; void* opaque1; VmFlags opaque2; } KnRgnDesc;
The startAddr field defines the starting address of the memory region, while the size field defines its length (expressed in bytes). The options field enables low level control over the attributes of the memory region to be allocated. The opaque1 and opaque2 fields should be set to NULL if they are not being used by the application.
The options field consists of a number of flags, of which the following are the most important:
K_WRITABLE notifies the system that the newly created memory region must be writable, otherwise the memory region will be read-only.
K_FILLZERO notifies the system that the content of the memory region to be created must be filled with zeroes upon creation. If this flag is not set, the content of the memory region will be unspecified.
K_ANYWHERE notifies the system that the address used to allocate the region is not critical to the application. An appropriate address will be selected by the system and returned to the application. This avoids the need for the application to find out which addresses are already in use within the actor address space. It also enables memory to be allocated within a library without conflict with an existing address space.
K_SUPERVISOR notifies the system that the memory to be allocated will be part of the supervisor address space rather than part of the user address space. This flag is usually set by actors running in supervisor mode.
Additional options are available on a ChorusOS operating system configured with the virtual memory feature. The most important of these enables control of the swap policy to be applied to the pages of the created memory region:
K_NODEMAND notifies the system that no page fault should ever occur on the memory region referred to in the previous paragraph. Physical pages are allocated to the memory region at creation time and will never be swapped out. Thus, the region is locked in memory.