Starting a process using the KasperskyOS API

August 2, 2023

ID app_static_start

This example uses the EntityInitEx() and EntityRun() functions to run an executable file from the solution image.

Below is the code of the GpMgrOpenSession() function, which starts the server process, connects it to the client process and initializes IPC transport. The executable file of the new process must be contained in the ROMFS storage of the solution.

#define CONNECT_RETRY 150 /* Number of connection attempts */

#define CONNECT_DELAY 10 /* Delay (ms) between attempts */

/**

* The "classname" parameter defines the class name of the started process,

* the "server" parameter defines a unique name for the process, and the "service" parameter contains the service name

* that is used when dynamically creating a channel.

* Output parameter "transport" contains the initialized transport

* if an IPC channel to the client was successfully created.

*/

Retcode GpMgrOpenSession(const char *classname, const char *server,

const char *service, NkKosTransport *transport)

{

Retcode rc;

Entity *e;

EntityInfo tae_info;

Handle endpoint;

rtl_uint32_t riid;

int count = CONNECT_RETRY;

/* Initializes the process description structure. */

rtl_memset(&tae_info, 0, sizeof(tae_info));

tae_info.eiid = classname;

tae_info.args[0] = server;

tae_info.args[1] = service;

/* Creates a process named "server" with the tae_info description.

* The third parameter is equal to RTL_NULL, therefore the name of the started

* binary file matches the class name from the tae_info description.

* The created process is in the stopped state. */

if ((e = EntityInitEx(&tae_info, server, RTL_NULL)) == NK_NULL)

{

rtl_printf("Cannot init entity '%s'\n", tae_info.eiid);

return rcFail;

}

/* Starts the process. */

if ((rc = EntityRun(e)) != rcOk)

{

rtl_printf("Cannot launch entity %" RTL_PRId32 "\n", rc);

EntityFree(e);

return rc;

}

/* Dynamically creates an IPC channel. */

while ((rc = KnCmConnect(server, service, INFINITE_TIMEOUT, &endpoint, &riid) ==

rcResourceNotFound && count--)

{

KnSleep(CONNECT_DELAY);

}

if (rc != rcOk)

{

rtl_printf("Cannot connect to server %" RTL_PRId32 "\n", rc);

return rc;

}

/* Initializes IPC transport. */

NkKosTransport_Init(transport, endpoint, NK_NULL, 0);

...

return rcOk;

}

To enable a process to start other processes, the solution security policy must allow this process to use the following core endpoints: Handle, Task and VMM (their descriptions are in the directory kl\core\).

Did you find this article helpful?
What can we do better?
Thank you for your feedback! You're helping us improve.
Thank you for your feedback! You're helping us improve.