Preparing ELF image segments to be loaded into process memory
Information about API functions is provided in the table below.
Using the API
MDL buffers are used not only to create shared memory, but also to load ELF image segments into the memory of a new process. (ELF image segments are loaded by the Einit initializing program, for example.)
The KnVmSegInitFromVm() and KnVmSegInitFromBuf() functions create an MDL buffer and put the ELF image segment into it so that this segment can then be loaded into the memory of a new process.
To delete MDL buffers containing ELF image segments, you must terminate the new process whose memory is mapped to these MDL buffers. You also need to complete the following steps before or after termination of this process:
Free the virtual memory regions that are mapped to the MDL buffers in the process that created these MDL buffers.
This step is required only for MDL buffers that were created using the KnVmSegInitFromVm() function.
To complete this step, use the KnVmUnmap() function.
Close the handles of MDL buffers in the process that created these MDL buffers.
To complete this step, use the KnHandleClose() function, which is declared in the header file sysroot-*-kos/include/coresrv/handle/handle_api.h from the KasperskyOS SDK.
Information about API functions
vmm_api.h functions
Function
Information about the function
KnVmSegInitFromVm()
Purpose
Creates an MDL buffer from physical memory that is mapped to the defined virtual memory region containing the ELF image segment.
Parameters
[out] seg – pointer to the structure describing the ELF image segment. This structure contains the handle of the MDL buffer (the h field) and is used to load an ELF image segment into process memory. The type of structure is defined in the header file sysroot-*-kos/include/coresrv/vmm/vmm_types.h from the KasperskyOS SDK.
[in,optional] loadAddr – page-aligned address for loading the ELF image segment into process memory, or 0 to select this address automatically.
[in] addr – page-aligned base address of the virtual memory region.
[in] size – size of the virtual memory region in bytes. It must be a multiple of the memory page size.
[in] flags – flags defining the access rights to the MDL buffer. The parameter type and flags are defined in the header file sysroot-*-kos/include/vmm/flags.h from the KasperskyOS SDK.
Returned values
If successful, the function returns rcOk, otherwise it returns an error code.
Additional information
This function can be used if the defined virtual memory region is allocated with commitment.
In the flags parameter, you can specify the following combinations of flags:
VMM_FLAG_RWX_MASK or VMM_FLAG_READ | VMM_FLAG_WRITE | VMM_FLAG_EXECUTE – read/write/execute access.
KnVmSegInitFromBuf()
Purpose
Creates an MDL buffer and copies the ELF image segment from the defined buffer to the MDL buffer.
Parameters
[out] seg – pointer to the structure describing the ELF image segment. This structure contains the handle of the MDL buffer (the h field) and is used to load an ELF image segment into process memory. The type of structure is defined in the header file sysroot-*-kos/include/coresrv/vmm/vmm_types.h from the KasperskyOS SDK.
[in,optional] loadAddr – page-aligned address for loading the ELF image segment into process memory, or 0 to select this address automatically.
[in] offset – offset (in bytes) in the MDL buffer where writing of the ELF image segment must start.
[in] size – size (in bytes) of the ELF image segment. It must be a multiple of the memory page size.
[in] flags – flags defining the access rights to the MDL buffer. The parameter type and flags are defined in the header file sysroot-*-kos/include/vmm/flags.h from the KasperskyOS SDK.
[in] fileOffset – offset (in bytes) of the segment in the ELF image.
[in] buildId – pointer to the build ID. The linker writes this ID to the ELF image.
[in] buildIdSize – size (in bytes) of the build ID.
[in] buf – pointer to the buffer containing the ELF image segment.
[in] bufSize – size (in bytes) of the buffer containing the ELF image segment.
Returned values
If successful, the function returns rcOk, otherwise it returns an error code.
Additional information
In the flags parameter, you can specify the following combinations of flags: