KasperskyOS Community Edition 1.3

Managing processes (low-level API task_api.h)

The API is defined in the header file sysroot-*-kos/include/coresrv/task/task_api.h from the KasperskyOS SDK.

Main capabilities of the API:

  • Create, start, and terminate processes.
  • Handle exceptions.
  • Get information about processes, including information about the reasons for their termination.
  • Define priorities and scheduler classes for initial threads of processes.

Information about API functions is provided in the table below.

The libkos library also provides a high-level API for process management. This API is defined in the header file sysroot-*-kos/include/kos/task.h from the KasperskyOS SDK. It is recommended to use this specific API. The low-level API should be used only if the high-level API does not have sufficient capabilities.

Creating and starting processes

To create a process, call the KnTaskCreate() or KnTaskCreateEx() function. These functions create an "empty" process, which is a process in whose memory the ELF image of the program is not loaded. Before starting this process, complete the following steps:

  1. Create a seed value by calling the KosRandomGenerate() function, which is declared in the header file sysroot-*-kos/include/kos/random/random_api.h from the KasperskyOS SDK.

    This step is required for completion of the next step.

  2. Define the seed value by calling the KnTaskReseedAslr() function.

    This step is required for address space layout randomization. Address Space Layout Randomization (ASLR) is the use of random addresses for the location of data structures (ELF image, dynamic libraries, stack and heap) in process memory to make it harder to exploit vulnerabilities associated with a conventional process address space structure that is known by a hacker in advance.

    The KnTaskReseedAslr() function defines the seed value of the random number generator that is used to automatically select the base address of an allocated virtual memory region in functions such as KnVmAllocate(), KnPmmMdlMap(), KnIoDmaMap(), and KnTaskVmReserve(). The stack and heap are created in the process and dynamic libraries are loaded into the process memory by the operating system using the KnVmAllocate() function. The addr parameter is set to zero so that the address of the allocated virtual memory region is selected automatically (as a random value).

  3. Wipe the seed value created at step 1 from memory.

    This step is required for security purposes. To complete this step, use the RtlRandomMemSanitize() function, which is declared in the header file sysroot-*-kos/include/rtl/random.h from the KasperskyOS SDK.

  4. Load ELF image segments into process memory by using the KnTaskLoadSeg() function.

    In the loadAddr field of the seg parameter, specify the load address of the ELF image segment. To ensure ASLR support (as a supplement to step 2), the load address of the ELF image segment specified in the ELF file must be increased by the ELF image load offset. The ELF image load offset must be a random value. The KnElfCreateVmSegEx() function declared in the header file sysroot-*-kos/include/coresrv/elf/elf_api.h from the KasperskyOS SDK generates the random offset for loading the ELF image and calculates the load addresses of ELF image segments according to this offset.

    As a result of this step, MDL buffers that contain ELF image segments will be mapped to virtual memory of the process.

  5. [Optional] Load the symbol table .symtab and string table .strtab into process memory by calling the KnTaskLoadElfSyms() function.

    The load addresses of ELF image segments containing the symbol table .symtab and string table .strtab must be calculated just like the load addresses of other ELF image segments. This calculation is performed by the KnElfCreateVmSegEx() function declared in the header file sysroot-*-kos/include/coresrv/elf/elf_api.h from the KasperskyOS SDK.

    The kernel uses the symbol table .symtab and string table .strtab to get the names of functions for generating stack backtrace data (call stack information).

  6. Define the program entry point and the ELF image load offset by calling the KnTaskSetInitialState() function.

    The program entry point is the sum of the address specified in the e_entry field of the ELF image header and the ELF image load offset. The KnElfCreateVmSegEx() function declared in the header file sysroot-*-kos/include/coresrv/elf/elf_api.h from the KasperskyOS SDK generates a random offset for loading the ELF image and calculates the address of the program entry point according to this offset.

  7. [Optional] Load the ELF image header into process memory by calling the KnTaskSetElfHdr() function.

    This step must be completed if data from the ELF image header must be available in the created process.

The handle of a process can be transferred to another process via IPC.

By default, the initial thread of a process is a standard thread whose priority can take values ranging from 0 to 15. (For details about thread scheduler classes, see Managing threads (low-level API thread_api.h).) To change the scheduler class and/or priority of the initial thread of a process, call the KnTaskSetInitialPolicy() function. To change the priority of the initial thread of a process, call the KnTaskSetInitialThreadPriority() function. The KnTaskSetInitialPolicy() and KnTaskSetInitialThreadPriority() functions can be used after the program entry point is defined. These functions can also be used after starting the process.

To start the process, call the KnTaskResume() function. A running process cannot be stopped.

Before a process is started, it receives data from its parent process via a static connection page. A static connection page (SCP) is a set of structures containing data for statically creating IPC channels, startup parameters, and environment variables of a program. A parent process writes data to the SCP of a child process by calling the KnTaskSetEnv() function. When a child process is started, it reads data from the SCP by calling the KnTaskGetEnv() function, then it deletes the SCP by calling the KnTaskFreeEnv() function. All three functions do not need to be explicitly called because their calls are made by the libkos library.

Terminating processes

Process termination includes the following:

  • Terminating all threads of the process.
  • Freeing the memory of the process.
  • Freeing system resources and user resources that are exclusively owned by the process.

    When a process is terminated, all the handles that it owns are closed. If a closed handle was the only handle of a resource, this resource is freed.

A process can be terminated for the following reasons:

  • On its own initiative.

    The KnTaskExit() function is called, or all threads of the process are terminated.

  • By external request.

    The KnTaskTerminate() function is called.

  • As a result of an unhandled exception (crash).

    By calling the KnTaskPanic() function, a process can purposefully initiate an exception that cannot be handled and leads to the process terminating. This assures that the process can terminate itself. (For example, if the process contains threads attached to interrupts, the KnTaskExit() cannot terminate the process, while the KnTaskPanic() function can.)

The exit codes of processes are defined by the developer of the KasperskyOS-based solution. These codes must be specified in the status parameter of the KnTaskExit() function. If a process was terminated due to the termination of all its threads, the exit code of this process will be the exit code of its initial thread. To get the exit code of a process that was terminated on its own initiative, call the KnTaskGetExitCode() function.

To get information regarding the reason for process termination, call the KnTaskGetExitStatus() function. This function determines whether a process was terminated on its own initiative, by external request, or unexpectedly.

To get information about an unhandled exception that led to an unexpected termination of a process, call the KnTaskGetExceptionInfo() function. This information includes the exception code and the context of the thread in which this exception occurred.

If the process was created by calling the KnTaskCreateEx() function with the TaskExceptionFreezesTask flag in the flags parameter, an unhandled exception will cause this process to switch to a "frozen" state instead of terminating. When a process is switched to a "frozen" state, its threads are terminated as a result of the unhandled exception but its resources are not freed, which means that you can get information about this process. To get the context of a thread that is part of a frozen process, call the KnTaskGetThreadContext() function. To get information about the virtual memory region that belongs to a frozen process, call the KnTaskGetNextVmRegion() function. This information includes the base address and size of the virtual memory region, and the access rights to this virtual memory region. Before a process switches to the frozen state, stack backtrace data (call stack information) is printed for the thread in which the unhandled exception occurred. To terminate a frozen process, call the KnTaskTerminateAfterFreezing() function.

To ensure that the kernel object describing a process is deleted after this process is terminated, each of its handles must be closed or revoked in all processes that own these handles before or after termination of this process. To do so, use the KnHandleClose() and/or KnHandleRevoke() functions that are declared in the header file sysroot-*-kos/include/coresrv/handle/handle_api.h from the KasperskyOS SDK.

Handling exceptions

To register an exception handling function, call the KnTaskSetExceptionHandler() function. This function deregisters the previous exception handling function and returns its ID. By saving this ID, you can subsequently register the previous exception handling function again.

An exception handling function is called when an exception occurs in any process thread. If the exception is successfully handled, this function returns a value other than zero. Otherwise it returns zero. The input parameter of the exception handling function is a structure containing information about the exception. The type of this structure is defined in the header file sysroot-*-kos/include/thread/tcbpage.h from the KasperskyOS SDK.

If an exception handling function registered at the process level failed to successfully handle an exception, the exception handling function registered at the level of the thread in which the exception occurred will be called. (For details about handling exceptions at the thread level, see Managing threads (low-level API thread_api.h)).

Reserving memory in a child process

The API includes the KnTaskVmReserve() and KnTaskVmFree() functions, which reserve and free virtual memory regions, respectively, in a child process that does not yet have a defined program entry point. These functions comprise only a part of the functionality intended to increase control of the parent process over the virtual address space of a child process. This functionality is currently under development.

Getting the GSI address

Global system information (GSI) is a structure containing system information, such as the timer count since the kernel started, the timer counts per second, the number of processors (processor cores) in active state, and processor cache data. The type of structure is defined in the header file sysroot-*-kos/include/task/pcbpage.h from the KasperskyOS SDK. The KnTaskGetGsi() function gets the GSI address. This function is intended for use by the libc library.

Getting the PCB address

A process control block (PCB) is a structure containing process information that is used by the kernel to manage this process. The type of structure is defined in the header file sysroot-*-kos/include/task/pcbpage.h from the KasperskyOS SDK. The KnTaskGetPcb() function gets the PCB address. This function is intended for use by the libc library.

Information about API functions

task_api.h functions

Function

Information about the function

KnTaskCreate()

Purpose

Creates a process.

Parameters

  • [in] name – pointer to the process name.
  • [in] eiid – pointer to the process class name.
  • [in] path – parameter that must have the value RTL_NULL.
  • [in,optional] stackSize – thread stack limit (in bytes) used by default when creating process threads. If 0 is specified, the stack will be 1 MB by default.
  • [in] priority – priority of the initial thread. The parameter type is defined in the header file sysroot-*-kos/include/coresrv/thread/thread_api.h from the KasperskyOS SDK.
  • [out] outHandle – pointer to the process handle.

Returned values

If successful, the function returns rcOk, otherwise it returns an error code.

KnTaskCreateEx()

Purpose

Creates a process.

Parameters

  • [in] name – pointer to the process name.
  • [in] eiid – pointer to the process class name.
  • [in] path – parameter that must have the value RTL_NULL.
  • [in,optional] stackSize – thread stack limit (in bytes) used by default when creating process threads. If 0 is specified, the stack will be 1 MB by default.
  • [in] priority – priority of the initial thread. The parameter type is defined in the header file sysroot-*-kos/include/coresrv/thread/thread_api.h from the KasperskyOS SDK.
  • [in] flags – flags defining the parameters for creating the process.
  • [out] outHandle – pointer to the process handle.

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 flags:

  • TaskExceptionTerminatesTask – the process is terminated as a result of an unhandled exception.
  • TaskExceptionFreezesTask – the process switches to the "frozen" state as a result of an unhandled exception. This flag cannot be specified together with the TaskExceptionTerminatesTask flag.
  • TaskEmpty – creates an "empty" process. This mandatory flag must be set.

KnTaskGetGsi()

Purpose

Gets the GSI address for the calling process.

Parameters

N/A

Returned values

Pointer to the GSI. The data type for GSI storage is defined in the header file sysroot-*-kos/include/task/pcbpage.h from the KasperskyOS SDK.

KnTaskGetPcb()

Purpose

Gets the address of the process control block (PCB) for the calling process.

Parameters

N/A

Returned values

Pointer to the PCB. The data type for PCB storage is defined in the header file sysroot-*-kos/include/task/pcbpage.h from the KasperskyOS SDK.

KnTaskGetEnv()

Purpose

Gets the SCP address of the calling process.

Parameters

  • [out] envSize – pointer to the size of the SCP (in bytes).

Returned values

Pointer to the SCP, or RTL_NULL if the process does not have an SCP.

KnTaskSetEnv()

Purpose

Writes data to the SCP of a process.

Parameters

  • [in] task – process handle.
  • [in] env – pointer to the buffer containing data to be written to the SCP.
  • [in] envSize – size (in bytes) of the data to be written to the SCP.

Returned values

If successful, the function returns rcOk, otherwise it returns an error code.

KnTaskFreeEnv()

Purpose

Deletes the SCP of the calling process.

Parameters

N/A

Returned values

If successful, the function returns rcOk, otherwise it returns an error code.

KnTaskSetElfHdr()

Purpose

Writes the ELF image header to the PCB of a process.

Parameters

  • [in] h – process handle.
  • [in] hdrData – pointer to the buffer containing the ELF image header.
  • [in] hdrSize – size (in bytes) of the ELF image header.

Returned values

If successful, the function returns rcOk, otherwise it returns an error code.

KnTaskResume()

Purpose

Starts a process.

Parameters

  • [in] task – process handle.

Returned values

If successful, the function returns rcOk, otherwise it returns an error code.

KnTaskExit()

Purpose

Terminates the calling process.

Parameters

  • [in] status – exit code of the process.

Returned values

Error code.

Additional information

Does not terminate the process as long as it contains threads attached to interrupts.

KnTaskTerminate()

Purpose

Terminates a process.

Parameters

  • [in] task – process handle.

Returned values

If successful, the function returns rcOk, otherwise it returns an error code.

KnTaskGetExitStatus()

Purpose

Gets information about the reason for process termination.

Parameters

  • [in] task – handle of the terminated process.
  • [out] status – pointer to the value indicating the reason for process termination. The data type for storing this value is defined in the header file sysroot-*-kos/include/task/pcbpage.h from the KasperskyOS SDK.

Returned values

If successful, the function returns rcOk, otherwise it returns an error code.

Additional information

You can use the status parameters to get the following values:

  • TaskExitUnexpected – the process terminated unexpectedly.
  • TaskExitNormal – the process terminated on its own initiative.
  • TaskExitTerminated – the process was terminated by an external request.

KnTaskGetExceptionInfo()

Purpose

Gets information about an unhandled exception that led to an unexpected termination of a process.

Parameters

  • [in] task – handle of the unexpectedly terminated process.
  • [out] excType – pointer to an exception code that is non-specific for any processor architecture. The data type for storing this code is defined in the header file sysroot-*-kos/include/hal/exc_codes.h from the KasperskyOS SDK.
  • [out] excNo – pointer to an exception code that is specific to the utilized processor architecture. The data type for storing this code is defined in the header file sysroot-*-kos/include/hal/exc_codes.h from the KasperskyOS SDK.
  • [out] exceptionContext – pointer to the structure containing the context of the thread in which the exception occurred. The type of structure is defined in the header file sysroot-*-kos/include/hal/*/frame.h from the KasperskyOS SDK.

Returned values

If successful, the function returns rcOk, otherwise it returns an error code.

KnTaskGetThreadContext()

Purpose

Gets the context of a thread that is part of a frozen process.

Parameters

  • [in] task – handle of the frozen process.
  • [in] index – thread index. It is used to enumerate threads. Enumeration starts with zero. A thread in which an unhandled exception occurred has a zero index.
  • [out] context – pointer to the structure containing the thread ID (TID) and context of the thread. The type of structure is defined in the header file sysroot-*-kos/include/thread/context.h from the KasperskyOS SDK.

Returned values

If successful, the function returns rcOk, otherwise it returns an error code.

KnTaskGetNextVmRegion()

Purpose

Gets information about the virtual memory region that belongs to a frozen process.

Parameters

  • [in] task – handle of the frozen process.
  • [in] after – address that is followed by the virtual memory region.
  • [out] next – pointer to the base address of the virtual memory region.
  • [out] size – pointer to the size of the virtual memory region (in bytes).
  • [out] flags – pointer to the flags indicating the parameters of the virtual memory region. The flags are defined in the header file sysroot-*-kos/include/vmm/flags.h from the KasperskyOS SDK.
  • [out] outHandle – pointer to the handle of the MDL buffer mapped to the virtual memory region. The KnTaskGetNextVmRegion() function creates an MDL buffer from physical memory mapped to a virtual memory region (even if there is already an MDL buffer mapped to this virtual memory region).

Returned values

If successful, the function returns rcOk, otherwise it returns an error code.

KnTaskTerminateAfterFreezing()

Purpose

Terminates a frozen process.

Parameters

  • [in] task – handle of the frozen process.

Returned values

If successful, the function returns rcOk, otherwise it returns an error code.

KnTaskGetExitCode()

Purpose

Gets the exit code of a process that terminated on its own initiative.

Parameters

  • [in] task – handle of the terminated process.
  • [out] exitCode – pointer to the process exit code.

Returned values

If successful, the function returns rcOk, otherwise it returns an error code.

KnTaskGetId()

Purpose

Gets the process ID (PID) for the calling process.

Parameters

N/A

Returned values

Process ID. The ID type is defined in the header file sysroot-*-kos/include/task/pidtype.h from the KasperskyOS SDK.

KnTaskGetName()

Purpose

Gets the name of a calling process.

Parameters

  • [out] name – pointer to the buffer used to store the process name.
  • [in] msize – size of the buffer used to store the process name (in bytes).

Returned values

If successful, the function returns rcOk, otherwise it returns an error code.

KnTaskGetPath()

Purpose

Gets the name of the executable file (in ROMFS) that was used to create the calling process.

Parameters

  • [out] path – pointer to the buffer used to store the executable file name.
  • [in] msize – size (in bytes) of the buffer used to store the name of the executable file.

Returned values

If successful, the function returns rcOk, otherwise it returns an error code.

KnTaskGetInitialThreadPriority()

Purpose

Gets the priority of the initial thread of a process.

Parameters

  • [in] task – process handle.
  • [out] priority – pointer to the priority of the initial thread of the process. The data type for storing the priority of a thread is defined in the header file sysroot-*-kos/include/coresrv/thread/thread_api.h from the KasperskyOS SDK.

Returned values

If successful, the function returns rcOk, otherwise it returns an error code.

KnTaskSetInitialThreadPriority()

Purpose

Defines the priority of the initial thread of a process.

Parameters

  • [in] task – process handle.
  • [in] priority – priority of the initial thread of a process. The parameter type is defined in the header file sysroot-*-kos/include/coresrv/thread/thread_api.h from the KasperskyOS SDK.

Returned values

If successful, the function returns rcOk, otherwise it returns an error code.

KnTaskSetExceptionHandler()

Purpose

Registers the exception handling function for the calling process.

Parameters

  • [in,optional] handler – ID of the exception handling function, or RTL_NULL to deregister the previously registered function without registering a new one. The parameter type is defined in the header file sysroot-*-kos/include/task/pcbpage.h from the KasperskyOS SDK.

Returned values

ID of the previously registered exception handling function if one exists, otherwise RTL_NULL. The type of returned value is defined in the header file sysroot-*-kos/include/task/pcbpage.h from the KasperskyOS SDK.

KnTaskLoadSeg()

Purpose

Loads an ELF image segment into process memory.

Parameters

  • [in] h – process handle.
  • [in] seg – pointer to the structure describing the ELF image segment. If the loadAddr field of this structure is set equal to 0, the ELF image segment load address will be selected automatically. The type of structure is defined in the header file sysroot-*-kos/include/coresrv/vmm/vmm_types.h from the KasperskyOS SDK.
  • [out] actual – pointer to the load address of the ELF image segment.

Returned values

If successful, the function returns rcOk, otherwise it returns an error code.

KnTaskVmReserve()

Purpose

Reserves a virtual memory region in a process.

Parameters

  • [in] task – process handle.
  • [in,optional] hint – page-aligned, preferred base address of the virtual memory region, or RTL_NULL to select this address automatically.
  • [in] size – size of the virtual memory region in bytes.
  • [in] flags – flags defining the parameters of the virtual memory region. The flags are defined in the header file sysroot-*-kos/include/vmm/flags.h from the KasperskyOS SDK.
  • [out] addr – pointer to the base address of the reserved virtual memory region.

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 flags:

  • VMM_FLAG_LOCKED – commits the virtual memory region while allocating the entire required volume of physical memory. When the KnTaskVmReserve() function is called with this flag, the memory is not committed. This flag affects subsequent commitment-related actions taken on the reserved virtual memory region.
  • VMM_FLAG_READ, VMM_FLAG_WRITE, VMM_FLAG_EXECUTE and VMM_FLAG_RWX_MASK – flags defining the access rights to the virtual memory region.
  • VMM_FLAG_LOW_GUARD, VMM_FLAG_HIGH_GUARD – adds a protected page to the beginning and end of the virtual memory region, respectively. The size of the protected page is not included in the size of the virtual memory region.

Permissible combinations of flags defining the access rights to the virtual memory region:

  • VMM_FLAG_READ – read access.
  • VMM_FLAG_READ | VMM_FLAG_WRITE – read-and-write access.
  • VMM_FLAG_READ | VMM_FLAG_EXECUTE – read-and-execute access.
  • VMM_FLAG_RWX_MASK or VMM_FLAG_READ | VMM_FLAG_WRITE | VMM_FLAG_EXECUTE – read/write/execute access.

KnTaskVmFree()

Purpose

Frees the virtual memory region that was reserved by calling the KnTaskVmReserve() function.

Parameters

  • [in] task – process handle.
  • [in] base – page-aligned base address of the virtual memory region.
  • [in] size – size of the virtual memory region in bytes.

Returned values

If successful, the function returns rcOk, otherwise it returns an error code.

KnTaskSetInitialState()

Purpose

Defines the program entry point and the ELF image load offset.

Parameters

  • [in] h – process handle.
  • [in] state – pointer to the structure containing the address of the program entry point and the ELF image load offset (in bytes).

Returned values

If successful, the function returns rcOk, otherwise it returns an error code.

KnTaskLoadElfSyms()

Purpose

Loads the symbol table .symtab and string table .strtab into process memory.

Parameters

  • [in] h – process handle.
  • [in] symTabSeg – pointer to the structure describing the ELF image segment with the symbol table .symtab. The type of structure is defined in the header file sysroot-*-kos/include/coresrv/vmm/vmm_types.h from the KasperskyOS SDK.
  • [in] symTabSize – size of the symbol table .symtab (in bytes).
  • [in] strTabSeg – pointer to the structure describing the ELF image segment with the string table .strtab. The type of structure is defined in the header file sysroot-*-kos/include/coresrv/vmm/vmm_types.h from the KasperskyOS SDK.
  • [in] strTabSize – size of the string table .strtab (in bytes).

Returned values

If successful, the function returns rcOk, otherwise it returns an error code.

KnTaskSetInitialPolicy()

Purpose

Defines the scheduler class and priority of the initial thread of a process.

Parameters

  • [in] task – process handle.
  • [in] policy – scheduler class of the initial thread of the process. The parameter type is defined in the header file sysroot-*-kos/include/thread/tidtype.h from the KasperskyOS SDK.
  • [in] priority – priority of the initial thread of a process. The parameter type is defined in the header file sysroot-*-kos/include/coresrv/thread/thread_api.h from the KasperskyOS SDK.
  • [in,optional] param – pointer to the parameters of the initial thread scheduler class, or RTL_NULL. The data type for storing these parameters is defined in the header file sysroot-*-kos/include/coresrv/thread/thread_api.h from the KasperskyOS SDK.

Returned values

If successful, the function returns rcOk, otherwise it returns an error code.

Additional information

In the param parameter, you can specify RTL_NULL if you need to define the default parameters for the scheduler class of the initial thread of the process.

In the param parameter, you must specify RTL_NULL if the scheduler class of the initial thread of the process does not have any parameters.

KnTaskReseedAslr()

Purpose

Defines the seed value for ASLR support in the defined process.

Parameters

  • [in] task – process handle.
  • [in] seed – pointer to the buffer containing the seed value of the random number generator.
  • [in] seedSize – size (in bytes) of the buffer containing the seed value of the random number generator.

Returned values

If successful, the function returns rcOk, otherwise it returns an error code.

KnTaskGetElfSyms()

Purpose

Gets the addresses and sizes of the symbol table .symtab and string table .strtab for the calling process.

Parameters

  • [out] relocBase – pointer to the ELF image load offset (in bytes). Add the ELF image load offset to the address of a symbol from the symbol table .symtab to get the address of this symbol in process memory.
  • [out] syms – pointer to the address of the symbol table .symtab.
  • [out] symsCnt – pointer to the size of the symbol table .symtab (in bytes).
  • [out] strs – pointer to the address of the string table .strtab.
  • [out] strsCnt – pointer to the size of the string table .strtab (in bytes).

Returned values

If successful, the function returns rcOk, otherwise it returns an error code.

Additional information

If the symbol table .symtab and string table .strtab are not loaded into process memory by calling the KnTaskLoadElfSyms() function, the KnTaskGetElfSyms() function returns rcOk (if there are no other errors). In this case, the received addresses of the tables have RTL_NULL values, and the received sizes of the tables are zero.

The function is intended for a mechanism that displays stack backtrace data and runs in a process and not in the kernel. This mechanism is currently under development.

KnTaskGetIdByHandle()

Purpose

Gets the process ID (PID).

Parameters

  • [in] task – process handle.
  • [out] taskId – pointer to the process ID. The ID type is defined in the header file sysroot-*-kos/include/task/pidtype.h from the KasperskyOS SDK.

Returned values

If successful, the function returns rcOk, otherwise it returns an error code.

KnTaskPanic()

Purpose

Initiates an exception that cannot be handled and leads to the process terminating.

Parameters

N/A

Returned values

N/A

KnTaskTransferResource()

Purpose

Transfers a handle to a process that is not yet running.

Parameters

  • [in] task – process handle.
  • [in] srcHandle – transferred handle.
  • [in] srcBadge – handle of the resource transfer context object.
  • [in] dstRights – permissions mask of the descendant of the transferred handle.
  • [out] outDstHandle – pointer to the descendant of the transferred handle (from the handle space of the process that received the handle).

Returned values

If successful, the function returns rcOk, otherwise it returns an error code.

Additional information

In contrast to the KosTaskTransferResource() function from the API task.h, the KnTaskTransferResource() function does not copy the value of the descendant of the transferred handle to the SCP of the process to which the handle was transferred. The KosTaskTransferResource() function does this so that the process that received the descendant of the transferred handle can find it by calling the KosTaskLookupResource() function from the API task.h.