Brussels / 2 & 3 February 2013


A high level language for low level code

Using Lua to script the Linux kernel ABI

Using Lua to script the Linux kernel ABI

Controlling Linux from a scripting language offers many advantages, in order to learn about how the operating system works, to build embedded systems and test environments and other uses. The ljsyscall project is a project that is working towards this aim using the Lua programming language to implement the Linux kernel ABI.

Linux distributions do a very good job of “just working” out of the box, and hiding what actually goes on, in a complex set of largely compiled code. The original use case to develop ljsyscall came from trying to build small Linux container, virtualised or embedded systems that only needed to do one small thing, where a whole Linux distribution was overkill.

It is also easy to understand what is happening with a scripting language as you can explore it in a REPL, see all the source, and run code easily with no recompile cycle. The code is also easier to understand than C for many people, with simpler string handling, garbage collection, and the provision of higher level data types as abstractions, eg for network interfaces. This makes it a good learning tool for what operating systems actually do.

The code uses the LuaJIT foreign function interface (ffi) which makes it easy to understand as the Lua to C interface is very simple, as well as being very fast as it is just-in-time compiled giving similar performance to native C code. There are extensive tests, and the code works on x86, AMD64 and ARM processors so far.

The code works and already exposes a lot of functionality, including system calls, signals, processes, containers, network interfaces and routing. It is like the busybox application in a scripting language. There is more to implement, such as support for more parts of the netlink protocol. It is being used in some projects now, but a wider audience could help contribute and improve it. You can use it like busybox, or for simple applications, or exploring the system. All code is MIT licensed.


Justin Cormack