Linux kernel on github

lsds/lkl

Use Git or checkout with SVN using the web URL.

Work fast with our official CLI. Learn more.

Launching GitHub Desktop

If nothing happens, download GitHub Desktop and try again.

Launching GitHub Desktop

If nothing happens, download GitHub Desktop and try again.

Launching Xcode

If nothing happens, download Xcode and try again.

Launching Visual Studio Code

Your codespace will open once ready.

There was a problem preparing your codespace, please try again.

This branch is 7970 commits ahead of lkl:master.

Open a pull request to contribute your changes upstream.

Latest commit

Git stats

Files

Failed to load latest commit information.

README.md

LKL (Linux Kernel Library) is aiming to allow reusing the Linux kernel code as extensively as possible with minimal effort and reduced maintenance overhead.

Examples of how LKL can be used are: creating userspace applications (running on Linux and other operating systems) that can read or write Linux filesystems or can use the Linux networking stack, creating kernel drivers for other operating systems that can read Linux filesystems, bootloaders support for reading/writing Linux filesystems, etc.

With LKL, the kernel code is compiled into an object file that can be directly linked by applications. The API offered by LKL is based on the Linux system call interface.

LKL is implemented as an architecture port in arch/lkl. It uses host operations defined by the application or a host library (tools/lkl/lib).

The supported hosts for now are POSIX and Windows userspace applications.

Building LKL, the host library and LKL based tools

will build LKL as a object file, it will install it in tools/lkl/lib together with the headers files in tools/lkl/include then will build the host library, tests and a few of application examples:

tests/boot — a simple applications that uses LKL and exercises the basic LKL APIs

fs2tar — a tool that converts a filesystem image to a tar archive

cptofs/cpfromfs — a tool that copies files to/from a filesystem image

lklfuse — a tool that can mount a filesystem image in userspace, without root priviledges, using FUSE

Building LKL on FreeBSD

Building LKL on Ubuntu

Building LKL for Windows

In order to build LKL for Win32 the mingw cross compiler needs to be installed on the host (e.g. on Ubuntu the following packages are required: binutils-mingw-w64-i686, gcc-mingw-w64-base, gcc-mingw-w64-i686 mingw-w64-common, mingw-w64-i686-dev).

Due to a bug in mingw regarding weak symbols the following patches needs to be applied to mingw-binutils:

and i686-w64-mingw32-gas, i686-w64-mingw32-ld and i686-w64-mingw32-objcopy need to be recompiled.

With that pre-requisites fullfilled you can now build LKL for Win32 with the following command:

Building LKL on Windows

To build on Windows, certain GNU tools need to be installed. These tools can come from several different projects, such as cygwin, unxutils, gnu-win32 or busybox-w32. Below is one minimal/modular set-up based on msys2.

Common build dependencies:

  • MSYS2 (provides GNU bash and many other utilities)
  • Extra utilities from MSYS2/pacman: bc, base-devel
  • No spaces in pathnames (source, prefix, destination. )!
  • Make sure that all utilities are in the PATH.
  • Win64 (and MinGW 64-bit crt) is LLP64, which causes conflicts in size of «long» in the Linux source. Linux (and lkl) can (currently) not be built on LLP64.
  • Cygwin (and msys2) are LP64, like linux.

For MSYS2 (and Cygwin):

Msys2 will install a gcc tool chain as part of the base-devel bundle. Binutils (2.26) is already patched for NT weak externals. Using the msys2 shell, cd to the lkl sources and run:

Install mingw-w64-i686-toolchain via pacman, mingw-w64-i686-binutils (2.26) is already patched for NT weak externals. Start a MinGW Win32 shell (64-bit will not work, see above) and run:

LKL hijack library

LKL hijack library (liblkl-hijack.so) is used to replace system calls used by an application on the fly so that the application can use LKL instead of the kernel of host operating system. LD_PRELOAD is used to dynamically override system calls with this library when you execute a program.

You can usually use this library via a wrapper script.

In order to configure the behavior of LKL, a json file can be used. You can specify json file with environmental variables (LKL_HIJACK_CONFIG_FILE). If there is nothing specified, LKL tries to find with the name ‘lkl-hijack.json’ for the configuration file. You can also use the old-style configuration with environmental variables (e.g., LKL_HIJACK_NET_IFTYPE) but those are overridden if a json file is specified.

The following are the list of keys to describe a JSON file.

Читайте также:  Картридж для lexmark ms415

IPv4 gateway address

key: «gateway» value type: string

the gateway IPv4 address of LKL network stack.

IPv6 gateway address

key: «gateway6» value type: string

the gateway IPv6 address of LKL network stack.

key: «debug» value type: string

Setting it causes some debug information (both from the kernel and the LKL library) to be enabled. If zero’ is specified it is disabled. It is also used as a bit mask to turn on specific debugging facilities. E.g., setting it to «0x100» will cause the LKL kernel to pause after the hijack’ed app exits. This allows one to debug or collect info from the LKL kernel before it quits.

Single CPU pinning

key: «singlecpu» value type: string

Pin LKL kernel threads on to a single host cpu. value «1» pins only LKL kernel threads while value «2» also pins polling threads.

key: «sysctl» value type: string

Configure sysctl values of the booted kernel via the hijack library. Multiple entries can be specified.

Boot command line

key: «boot_cmdline» value type: string

Specify the command line to the kernel boot so that change the configuration on a kernel instance. For instance, you can change the memory size with below.

key: «mount» value type: string

Network Interface Configuration

key: «interfaces» value type: array of objects

This key takes a set of sub-keys to configure a single interface. Each key is defined as follows.

key: «type» value type: string

The interface type in host operating system to connect to LKL. The following example specifies a tap interface.

key: «param» value type: string

Additional configuration parameters for the interface specified by Interface type (type). The parameters depend on the interface type.

Interface MTU size

key: «mtu» value type: string

the MTU size of the interface.

Interface IPv4 address

key: «ip» value type: string

the IPv4 address of the interface. If you want to use DHCP for the IP address assignment, use «boot_cmdline» with «ip=dhcp» option.

Interface IPv4 netmask length

key: «masklen» value type: string

the network mask length of the interface.

Interface IPv4 gateway on routing policy table

key: «ifgateway» value type: string

If you specify this parameter, LKL adds routing policy table. And then LKL creates link local and gateway route on this table. Table SELECTOR is «from» and PREFIX is address you assigned to this interface. Table id is 2 * (interface index). This parameter could be used to configure LKL for mptcp, for example.

Interface IPv6 address

key: «ipv6» value type: string

the IPv6 address of the interface.

Interface IPv6 netmask length

key: «masklen6» value type: string

the network mask length of the interface.

Interface IPv6 gateway on routing policy table

key: «ifgateway6» value type: string

If you specify this parameter, LKL adds routing policy table. And then LKL creates link local and gateway route on this table. Table SELECTOR is «from» and PREFIX is address you assigned to this interface. Table id is 2 * (interface index) + 1. This parameter could be used to configure LKL for mptcp, for example.

Interface MAC address

key: «mac» value type: string

the MAC address of the interface.

Interfac neighbor entries

key: «neigh» value type: string

Add a list of permanent neighbor entries in the form of «ip|mac;ip|mac;. «. ipv6 are supported

Interface qdisc entries

key: «qdisc» value type: string

Add a qdisc entry in the form of «root|type;root|type;. «.

key: «offload» value type: string

Work as a bit mask to enable selective device offload features. E.g., to enable «mergeable RX buffer» (LKL_VIRTIO_NET_F_MRG_RXBUF) + «guest csum» (LKL_VIRTIO_NET_F_GUEST_CSUM) device features, simply set it to 0x8002. See virtio_net.h for a list of offload features and their bit masks.

key: «delay_main» value type: string

The delay before calling main() function of the application after the initialization of LKL. Some subsystems in Linux tree require a certain amount of time before accepting a request from application, such as delivery of address assignment to an network interface. This parameter is used in such case. The value is described as a microsecond value.

Q: How is LKL different from UML?

A: UML prodivides a full OS environment (e.g. user/kernel separation, user processes) and also has requirements (a filesystem, processes, etc.) that makes it hard to use it for standalone applications. UML also relies heavily on Linux hosts. On the other hand LKL is designed to be linked directly with the application and hence does not have user/kernel separation which makes it easier to use it in standalone applications.

Q: How is LKL different from LibOS?

A: LibOS re-implements high-level kernel APIs for timers, softirqs, scheduling, sysctl, SLAB/SLUB, etc. LKL behaves like any arch port, implementing the arch level operations requested by the Linux kernel. LKL also offers a host interface so that support for multiple hosts can be implemented.

Читайте также:  Debian 10 postgresql version

Источник

octaviansoldea/lkl-linux

Use Git or checkout with SVN using the web URL.

Work fast with our official CLI. Learn more.

Launching GitHub Desktop

If nothing happens, download GitHub Desktop and try again.

Launching GitHub Desktop

If nothing happens, download GitHub Desktop and try again.

Launching Xcode

If nothing happens, download Xcode and try again.

Launching Visual Studio Code

Your codespace will open once ready.

There was a problem preparing your codespace, please try again.

This branch is 44577 commits ahead of libos-nuse:master.

Open a pull request to contribute your changes upstream.

Latest commit

Git stats

Files

Failed to load latest commit information.

README.md

LKL (Linux Kernel Library) is aiming to allow reusing the Linux kernel code as extensively as possible with minimal effort and reduced maintenance overhead.

Examples of how LKL can be used are: creating userspace applications (running on Linux and other operating systems) that can read or write Linux filesystems or can use the Linux networking stack, creating kernel drivers for other operating systems that can read Linux filesystems, bootloaders support for reading/writing Linux filesystems, etc.

With LKL, the kernel code is compiled into an object file that can be directly linked by applications. The API offered by LKL is based on the Linux system call interface.

LKL is implemented as an architecture port in arch/lkl. It uses host operations defined by the application or a host library (tools/lkl/lib).

The supported hosts for now are POSIX and Windows userspace applications.

Building LKL, the host library and LKL based tools

will build LKL as a object file, it will install it in tools/lkl/lib together with the headers files in tools/lkl/include then will build the host library, tests and a few of application examples:

tests/boot — a simple applications that uses LKL and exercises the basic LKL APIs

fs2tar — a tool that converts a filesystem image to a tar archive

cptofs/cpfromfs — a tool that copies files to/from a filesystem image

lklfuse — a tool that can mount a filesystem image in userspace, without root priviledges, using FUSE

Building LKL on FreeBSD

Building LKL on Ubuntu

Building LKL for Windows

In order to build LKL for Win32 the mingw cross compiler needs to be installed on the host (e.g. on Ubuntu the following packages are required: binutils-mingw-w64-i686, gcc-mingw-w64-base, gcc-mingw-w64-i686 mingw-w64-common, mingw-w64-i686-dev).

Due to a bug in mingw regarding weak symbols the following patches needs to be applied to mingw-binutils:

and i686-w64-mingw32-gas, i686-w64-mingw32-ld and i686-w64-mingw32-objcopy need to be recompiled.

With that pre-requisites fullfilled you can now build LKL for Win32 with the following command:

Building LKL on Windows

To build on Windows, certain GNU tools need to be installed. These tools can come from several different projects, such as cygwin, unxutils, gnu-win32 or busybox-w32. Below is one minimal/modular set-up based on msys2.

Common build dependencies:

  • MSYS2 (provides GNU bash and many other utilities)
  • Extra utilities from MSYS2/pacman: bc, base-devel
  • No spaces in pathnames (source, prefix, destination. )!
  • Make sure that all utilities are in the PATH.
  • Win64 (and MinGW 64-bit crt) is LLP64, which causes conflicts in size of «long» in the Linux source. Linux (and lkl) can (currently) not be built on LLP64.
  • Cygwin (and msys2) are LP64, like linux.

For MSYS2 (and Cygwin):

Msys2 will install a gcc tool chain as part of the base-devel bundle. Binutils (2.26) is already patched for NT weak externals. Using the msys2 shell, cd to the lkl sources and run:

Install mingw-w64-i686-toolchain via pacman, mingw-w64-i686-binutils (2.26) is already patched for NT weak externals. Start a MinGW Win32 shell (64-bit will not work, see above) and run:

LKL hijack library

LKL hijack library (liblkl-hijack.so) is used to replace system calls used by an application on the fly so that the application can use LKL instead of the kernel of host operating system. LD_PRELOAD is used to dynamically override system calls with this library when you execute a program.

You can usually use this library via a wrapper script.

In order to configure the behavior of LKL, a json file can be used. You can specify json file with environmental variables (LKL_HIJACK_CONFIG_FILE). If there is nothing specified, LKL tries to find with the name ‘lkl-hijack.json’ for the configuration file. You can also use the old-style configuration with environmental variables (e.g., LKL_HIJACK_NET_IFTYPE) but those are overridden if a json file is specified.

The following are the list of keys to describe a JSON file.

IPv4 gateway address

key: «gateway» value type: string

the gateway IPv4 address of LKL network stack.

IPv6 gateway address

Читайте также:  Brother dcp 7057r сбросить счетчик тонера на картридже

key: «gateway6» value type: string

the gateway IPv6 address of LKL network stack.

key: «debug» value type: string

Setting it causes some debug information (both from the kernel and the LKL library) to be enabled. If zero’ is specified it is disabled. It is also used as a bit mask to turn on specific debugging facilities. E.g., setting it to «0x100» will cause the LKL kernel to pause after the hijack’ed app exits. This allows one to debug or collect info from the LKL kernel before it quits.

Single CPU pinning

key: «singlecpu» value type: string

Pin LKL kernel threads on to a single host cpu. value «1» pins only LKL kernel threads while value «2» also pins polling threads.

key: «sysctl» value type: string

Configure sysctl values of the booted kernel via the hijack library. Multiple entries can be specified.

Boot command line

key: «boot_cmdline» value type: string

Specify the command line to the kernel boot so that change the configuration on a kernel instance. For instance, you can change the memory size with below.

key: «mount» value type: string

Network Interface Configuration

key: «interfaces» value type: array of objects

This key takes a set of sub-keys to configure a single interface. Each key is defined as follows.

key: «type» value type: string

The interface type in host operating system to connect to LKL. The following example specifies a tap interface.

key: «param» value type: string

Additional configuration parameters for the interface specified by Interface type (type). The parameters depend on the interface type.

Interface MTU size

key: «mtu» value type: string

the MTU size of the interface.

Interface IPv4 address

key: «ip» value type: string

the IPv4 address of the interface. If you want to use DHCP for the IP address assignment, use «boot_cmdline» with «ip=dhcp» option.

Interface IPv4 netmask length

key: «masklen» value type: string

the network mask length of the interface.

Interface IPv4 gateway on routing policy table

key: «ifgateway» value type: string

If you specify this parameter, LKL adds routing policy table. And then LKL creates link local and gateway route on this table. Table SELECTOR is «from» and PREFIX is address you assigned to this interface. Table id is 2 * (interface index). This parameter could be used to configure LKL for mptcp, for example.

Interface IPv6 address

key: «ipv6» value type: string

the IPv6 address of the interface.

Interface IPv6 netmask length

key: «masklen6» value type: string

the network mask length of the interface.

Interface IPv6 gateway on routing policy table

key: «ifgateway6» value type: string

If you specify this parameter, LKL adds routing policy table. And then LKL creates link local and gateway route on this table. Table SELECTOR is «from» and PREFIX is address you assigned to this interface. Table id is 2 * (interface index) + 1. This parameter could be used to configure LKL for mptcp, for example.

Interface MAC address

key: «mac» value type: string

the MAC address of the interface.

Interfac neighbor entries

key: «neigh» value type: string

Add a list of permanent neighbor entries in the form of «ip|mac;ip|mac;. «. ipv6 are supported

Interface qdisc entries

key: «qdisc» value type: string

Add a qdisc entry in the form of «root|type;root|type;. «.

key: «offload» value type: string

Work as a bit mask to enable selective device offload features. E.g., to enable «mergeable RX buffer» (LKL_VIRTIO_NET_F_MRG_RXBUF) + «guest csum» (LKL_VIRTIO_NET_F_GUEST_CSUM) device features, simply set it to 0x8002. See virtio_net.h for a list of offload features and their bit masks.

key: «delay_main» value type: string

The delay before calling main() function of the application after the initialization of LKL. Some subsystems in Linux tree require a certain amount of time before accepting a request from application, such as delivery of address assignment to an network interface. This parameter is used in such case. The value is described as a microsecond value.

Q: How is LKL different from UML?

A: UML prodivides a full OS environment (e.g. user/kernel separation, user processes) and also has requirements (a filesystem, processes, etc.) that makes it hard to use it for standalone applications. UML also relies heavily on Linux hosts. On the other hand LKL is designed to be linked directly with the application and hence does not have user/kernel separation which makes it easier to use it in standalone applications.

Q: How is LKL different from LibOS?

A: LibOS re-implements high-level kernel APIs for timers, softirqs, scheduling, sysctl, SLAB/SLUB, etc. LKL behaves like any arch port, implementing the arch level operations requested by the Linux kernel. LKL also offers a host interface so that support for multiple hosts can be implemented.

Источник

Поделиться с друзьями
КомпСовет
Adblock
detector