The API is defined in the header file sysroot-*-kos/include/kos/alloc.h from the KasperskyOS SDK.
The API is intended for allocating and freeing memory. Allocated memory is a committed virtual memory region that can be accessed for read-and-write operations.
Information about API functions is provided in the table below.
alloc.h functions
Function
Information about the function
KosMemAllocEx()
Purpose
Allocates memory.
Parameters
[in] size – size (in bytes) of the allocated memory. If you specify a size of zero, the function returns a pointer that can be passed to the KosMemFree() function.
[in] align – value defining the alignment of the allocated memory. It must be a power of two. The address of allocated memory can be unaligned (align=1) or aligned (align=2,4,...,2^N) to the boundary of a 2^N-byte sequence (for example, two-byte or four-byte).
[in] zeroed – value defining the initialization of the allocated memory (1 – initialize with zeros, 0 – do not initialize).
Returned values
If successful, the function returns the pointer to the allocated memory, otherwise it returns RTL_NULL.
KosMemAlloc()
Purpose
Allocates memory.
Parameters
[in] size – size (in bytes) of the allocated memory. If you specify a size of zero, the function returns a pointer that can be passed to the KosMemFree() function.
Returned values
If successful, the function returns the pointer to the allocated memory, otherwise it returns RTL_NULL.
KosMemZalloc()
Purpose
Allocates memory and initializes it with zeros.
Parameters
[in] size – size (in bytes) of the allocated memory. If you specify a size of zero, the function returns a pointer that can be passed to the KosMemFree() function.
Returned values
If successful, the function returns the pointer to the allocated memory, otherwise it returns RTL_NULL.
KosMemFree()
Purpose
Deallocates memory.
Parameters
[in] ptr – pointer to the freed memory. If you specify RTL_NULL, the function does not perform any actions.
Returned values
N/A
KosMemRealloc()
Purpose
Allocates memory and (optionally) copies the contents of previously allocated memory to the newly allocated memory and frees the previously allocated memory after the copy operation is complete.
Parameters
[in,optional] ptr – pointer to the previously allocated memory, or RTL_NULL if you only need to allocate memory without copying the contents of previously allocated memory.
[in] size – size (in bytes) of the newly allocated memory. The contents of previously allocated memory are copied to the newly allocated memory in whatever amount that can be accommodated in the newly allocated memory. If you specify a size of zero, the function returns a pointer that can be passed to the KosMemFree() function.
Returned values
If successful, the function returns the pointer to the allocated memory, otherwise it returns RTL_NULL.
KosMemReallocEx()
Purpose
Allocates memory and (optionally) copies the contents of previously allocated memory to the newly allocated memory and frees the previously allocated memory after the copy operation is complete.
Parameters
[in,optional] ptr – pointer to the previously allocated memory, or RTL_NULL if you only need to allocate memory without copying the contents of previously allocated memory.
[in] size – size (in bytes) of the newly allocated memory. The contents of previously allocated memory are copied to the newly allocated memory in whatever amount that can be accommodated in the newly allocated memory. If you specify a size of zero, the function returns a pointer that can be passed to the KosMemFree() function.
[in] zeroed – value defining the initialization of the allocated memory (1 – initialize with zeros, 0 – do not initialize). If the ptr parameter is used to pass RTL_NULL and the zeroed parameter is set to 1, the allocated memory will be initialized with zeros. If the size of the newly allocated memory is less than or equal to the size of the previously allocated memory, the value of the zeroed parameter does not affect the contents of the newly allocated memory. If the size of the newly allocated memory is greater than the size of the previously allocated memory, and the zeroed parameter is set to 1, the fragment of newly allocated memory that is not occupied by the contents copied from the previously allocated memory may be initialized with zeros. To ensure that this fragment is initialized with zeros, you must do the following. The memory must be initially allocated by using either the KosMemZalloc() function, the KosMemAllocEx() function with the zeroed parameter set to 1, or the KosMemReallocEx() function with the zeroed parameter set to 1 and the ptr parameter set to RTL_NULL. All subsequent KosMemReallocEx() calls must have the zeroed parameter set to 1.
Returned values
If successful, the function returns the pointer to the allocated memory, otherwise it returns RTL_NULL.
Article ID: libkos_alloc_api, Last review: Feb 20, 2025