Contents
Scripts and compilers
This section contains a description of the scripts, tools and compilers provided in KasperskyOS Community Edition.
Build scripts and tools
KasperskyOS Community Edition includes the following build scripts and tools:
- nk-gen-c
The NK compiler (
nk-gen-c
) generates the set of transport methods and types based on the EDL, CDL and IDL descriptions of applications, components and interfaces. The transport methods and types are needed for generating, sending, receiving and processing IPC messages. - nk-psl-gen-c
The
nk-psl-gen-c
compiler generates the source code of the Kaspersky Security System security module based on the solution security policy file (security.psl
) and the EDL descriptions of applications included in the solution. - einit
The
einit
tool lets you automate the creation of code of theEinit
initializing application. This application is the first to start when KasperskyOS is loaded. Then it starts the other applications and creates channels (connections) between them. - makekss
The
makekss
script creates the Kaspersky Security System security module for the KasperskyOS kernel. - makeimg
The
makeimg
script creates the final boot image of the KasperskyOS-based solution with all applications to be started and the Kaspersky Security System module.
nk-gen-c
The NK compiler (nk-gen-c
) generates the set of transport methods and types based on the EDL, CDL and IDL descriptions of the process classes, components and interfaces. The transport methods and types are needed for generating, sending, receiving and processing IPC messages.
Transport methods and types are generated with fully qualified names. The full name of the process class/component/interface is used as prefixes in names (declared in the corresponding EDL-, CDL- or IDL file) by replacing dots with underscores (_
).
The NK compiler receives the EDL, CDL or IDL file and creates the following files:
H
file containing a declaration and implementation of transport methods and types.D
file that lists the dependencies of the createdC
file. This file can be used for building automation using themake
tool.
Syntax for using the NK compiler:
nk-gen-c [-I PATH][-o PATH][--types][--interface][--client][--server][--extended-errors][--enforce-alignment-check][--help][--version] FILE
Parameters:
FILE
Path to the EDL-, CDL- or IDL description of the process class, component or interface for which you need to generate transport methods and types.
-I PATH
Path to the folder containing auxiliary files required for generating transport methods and types. By default, these files are located in the folder:
/opt/KasperskyOS-Community-Edition-<version>/sysroot-arm-kos/include
.It may also be used for adding other folders to search for the files required for generating the methods and types.
To indicate more than one folder. you can use several
-I
switches.-o PATH
Path to an existing folder where files containing transport methods and types will be created.
-h, --help
Displays the Help text.
--version
Displays the
nk-gen-c
version.--enforce-alignment-check
Enables mandatory alignment checks for queries to memory, even if this check is disabled for the target platform. If these checks are enabled, the NK compiler adds additional alignment checks to the code of the IPC message validators.
By default, memory query alignment check settings are defined for each platform in the file named
system.platform
.--extended-errors
Enables extended error handling in the code of client and server methods.
Selective generation
To reduce the amount of code generated by the NK compiler, you can use selective generation flags. For example, it is convenient to use the --server
flag for applications that implement interfaces, and to use the --client
flag for applications that are clients of the interfaces.
If no selective generation flag is specified, the NK compiler will create all transport types and methods that are possible for the specified file.
Selective generation flags for descriptions of interfaces (IDL files):
--types
The compiler will create only files that contain all constants and types, including redefined (
typedef
), from the input IDL file, and the types from imported IDL files that are used in the types of the input file.However, constants and redefined types from imported IDL files will not be explicitly included in the generated files. If you need to use types from imported files in code, you need to separately generate H-files for each such IDL file.
--interface
The compiler will generate files created with the
--types
flag, and the structures of request and response messages for all methods of this interface.--client
The compiler will generate files created with the
--interface
flag, and the client proxy objects and functions of their initialization for all methods of this interface.--server
The compiler will generate files created with the
--interface
flag, and the types and methods of the dispatcher of this interface.
Selective generation flags for descriptions of components (CDL files) and process classes (EDL files):
--types
The compiler will generate files created with the
--types
flag for all interfaces used in this component/process class.However, only the types that are used in arguments of interface methods will be explicitly included in the generated files.
--interface
The compiler will generate files created with the
--types
flag for this component/process class, and files generated with the--interface
flag for all interfaces used in this component/process class.--client
The compiler will generate files created with the
--interface
flag, and the client proxy objects and functions of their initialization for all interfaces used in this component/process class.--server
The compiler will generate files created with the
--interface
flag, and the types and methods of the dispatcher of this component/process class and the types and methods of dispatchers for all interfaces used in this component/process class.
nk-psl-gen-c
The nk-psl-gen-c
compiler generates the source code of the Kaspersky Security System security module based on the solution security policy file (security.psl) and the EDL descriptions of process classes included in the solution. This code is used by the makekss script.
The nk-psl-gen-c
compiler also lets you generate and run code of test scenarios written in the PAL language for the solution security policy.
Syntax for using the nk-psl-gen-c
compiler:
nk-psl-gen-c [-I PATH][-o PATH][--audit PATH][--tests ARG][--help][--version] FILE
Parameters:
FILE
Path to the PSL description of the solution security policy (
security.psl
)-I,--include-dir PATH
Path to the folder containing auxiliary files required for generating transport methods and types. By default, these files are located in the folder:
/opt/KasperskyOS-Community-Edition-<version>/sysroot-arm-kos/include
.The
nk-psl-gen-c
compiler will require access to all EDL descriptions of process classes listed in the security configuration, and will require access to the CDL- or IDL descriptions of their components and interfaces. To enable thenk-psl-gen-c
compiler to find these descriptions, you need to pass the paths to these descriptions using the-I
switch.To indicate more than one folder. you can use several
-I
switches.-o,--output PATH
Path to the created file containing the security module code.
-t, --tests ARG
Flag for controlling code generation and starting test scenarios for the solution security policy. Possible values:
skip
– code of test scenarios is not generated. This value is used by default if the--tests
flag is not indicated.generate
– code of test scenarios is generated but is not compiled and is not executed.run
– code of test scenarios is generated, compiled using thegcc
compiler, and executed.
-a, --audit PATH
Path to the created file containing the code of the audit decoder.
-h, --help
Displays the Help text.
--version
Displays the
nk-psl-gen-c
version.
einit
The einit
tool lets you automate the creation of code of the Einit initializing application. This application is the first to start when KasperskyOS is loaded. Then it starts the other applications and creates channels (connections) between them.
The einit
tool receives the init description file (init.yaml
by default) and creates a .c file containing the code of the Einit
initializing application. Then the Einit
application must be built using the C compiler that is provided in KasperskyOS Community Edition.
Syntax for using the einit tool:
einit -I PATH -o PATH [--help] FILE
Parameters:
FILE
Path to the
init.yaml
file containing descriptions of process classes and connections.-I PATH
Path to the folder containing auxiliary files required for generating the initializing application. By default, these files are located in the folder:
/opt/KasperskyOS-Community-Edition-<version>/sysroot-arm-kos/include
.-o, --out-file PATH
Path to the created .c file containing the code of the initializing application.
-h, --help
Displays the Help text.
makekss
The makekss
script creates the security module of Kaspersky Security System.
The script calls the nk-psl-gen-c compiler to generate the source code of the security module, then compiles the resulting code by calling the C compiler that is provided in KasperskyOS Community Edition.
The script obtains the file containing a description of the solution security policy (security.psl
by default) and creates the ksm.module
security module file.
Syntax for using the makekss script:
makekss --target=ARCH --module=PATH --with-nk="PATH" --with-nktype="TYPE" --with-nkflags="FLAGS" [--output="PATH"][--help][--with-cc="PATH"][--with-cflags="FLAGS"] FILE
Parameters:
FILE
Path to the security configuration file (
.psl
).--target=ARCH
Architecture for which the build is intended.
--module=-lPATH
Path to the
ksm_kss
library. This key is passed to the C compiler for linking to this library.--with-nk=PATH
Path to the
nk-psl-gen-c
compiler that will be used to generate the source code of the security module. By default, the compiler is located in/opt/KasperskyOS-Community-Edition-<version>/toolchain/bin/nk-psl-gen-c
.--with-nktype="TYPE"
Indicates the type of NK compiler that will be used. To use the
nk-psl-gen-c
compiler, indicate thepsl
type.--with-nkflags="FLAGS"
Parameters used when calling the
nk-psl-gen-c
compiler.The
nk-psl-gen-c
compiler will require access to all EDL descriptions of process classes listed in the security configuration, and will require access to the CDL- or IDL descriptions of their components and interfaces. To enable thenk-psl-gen-c
compiler to find these descriptions, you need to pass the paths to these descriptions in the--with-nkflags
parameter by using the-I
switch of thenk-psl-gen-c
compiler.--output=PATH
Path to the created security module file.
--with-cc=PATH
Path to the C compiler that will be used to build the security module. The compiler provided in KasperskyOS Community Edition is used by default.
--with-cflags=FLAGS
Parameters used when calling the C compiler.
-h, --help
Displays the Help text.
makeimg
The makeimg
script creates the final boot image of the KasperskyOS-based solution with all applications to be started and the Kaspersky Security System module.
The script receives a list of files, including the executable files of all applications that need to be added to ROMFS of the loaded image, and creates the following files:
- Solution image
- Solution image without character tables (
.stripped
) - Solution image with debug character tables (
.dbg.syms
)
Syntax for using the makeimg script:
makeimg --target=ARCH --sys-root=PATH
--with-toolchain=PATH --ldscript=PATH --img-src=PATH
--img-dst=PATH
--with-init=PATH
[--with-extra-asflags=FLAGS][--with-extra-ldflags=FLAGS][--help] FILES
Parameters:
FILES
List of paths to files, including the executable files of all applications that need to be added to romfs.
The security module (
ksm.module
) must be explicitly specified, or else it will not be included in the solution image. TheEinit
application does not need to be indicated because it will be automatically included in the solution image.--target=ARCH
Architecture for which the build is intended.
--sys-root=PATH
Path to the root directory sysroot. By default, this directory is located in
/opt/KasperskyOS-Community-Edition-<version>/sysroot-arm-kos/
.--with-toolchain=PATH
Path to the set of auxiliary tools required for the solution build. By default, these tools are located in
/opt/KasperskyOS-Community-Edition-<version>/toolchain/
.--ldscript=PATH
Path to the linker script required for the solution build. By default, this script is located in
/opt/KasperskyOS-Community-Edition-<version>/libexec/arm-kos/
.--img-src=PATH
Path to the precompiled KasperskyOS kernel not containing the romfs. By default, the kernel is located in
/opt/KasperskyOS-Community-Edition-<version>/libexec/arm-kos/
.--img-dst=PATH
Path to the created image file.
--with-init=PATH
Path to the executable file of the
Einit
initializing application.--with-extra-asflags=FLAGS
Additional flags for the AS Assembler.
--with-extra-ldflags=FLAGS
Additional flags for the LD Linker.
-h, --help
Displays the Help text.
Cross compilers
Properties of KasperskyOS cross compilers
The cross compilers included in KasperskyOS Community Edition support processors that have the arm
architecture.
The KasperskyOS Community Edition toolchain includes the following tools for cross compilation:
- GCC:
arm-kos-gcc
arm-kos-g++
- Binutils:
- AS Assembler:
arm-kos-as
- LD Linker:
arm-kos-ld
- AS Assembler:
In addition to standard macros, an additional macro __KOS__=1
is defined in GCC. Using this macro lets you simplify porting of the software code to KasperskyOS, and also simplifies development of platform-independent applications.
To view the list of standard macros of GCC, run the following command:
echo '' | arm-kos-gcc -dM -E -
Linker operation specifics
When building the executable file of an application, by default the linker links the following libraries in the specified order:
- libc – standard C library.
- libm – library that implements the mathematical functions of the standard C language library.
- libvfs_stubs – library that contains stubs of I/O functions (for example,
open
,socket
,read
,write
). - libkos – library consisting of two parts. The first part provides the C interface for accessing KasperskyOS kernel functions. It is available through the header files in the
coresrv
folder, for example:#include <coresrv/vmm/vmm_api.h>
. The second part of the libkos library is a wrapper over the first part and contains additional synchronization functions:mutex
,semaphore
,event
. Other libraries (including libc) interact with the kernel through the libkos library. - libenv – client library of the subsystem for configuring the environment of applications (environmental variables, arguments of the
main
function, and custom configurations). - libsrvtransport-u – internal library with the implementation of transport of interprocess communication between KasperskyOS kernel services.