LenxWei / lunatik-ng

Linux Kernel Lua Scripting Engine

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

lunatik-ng

This repository contains the ongoing effort of porting the Lunatik Lua engine to current Linux kernels. There are a few differences between the original lunatik and lunatik-ng:

  • Lunatik-ng works on x86_64
  • It is memory-leak free
  • It can be built as loadable modules
  • A few interfaces to the kernel are provided by default:
    • buffer for allocating memory regions in kernel space
    • crypto which provides bindings to the SHA1 implementation in the kernel (a more advanced interface to the kernel which allows selection of the cipher is in the works) and the random number generator.
    • printk as a direct binding to the kernels printk
    • type and gc_count as bindings to parts of the default Lua library

Uses

This work originated as part of the research project Towards Dynamic Scripted pNFS Layouts (pdf). It is used there to provide "flexible, script based file layouts that describe a logical file's mapping to its storage locations by an interpreted script instead of a fixed mapping".

Try it out

  • Grab the latest Linux kernel tarball from kernel.org (e.g. from here)
  • Extract it to some_folder
  • Copy the contents of this directory structure to some_folder: cp -R this_folder some_folder
  • Build the kernel as usual, make sure to check Library functions -> Lunatik Lua engine
  • The patches add syscall #359 to the kernel. The syscall has the following prototype: SYS_LUA (const char *code, size_t code_sz, char *result, size_t result_sz)
  • To make sure lunatik is working, you can execute the following lua code via the syscall: return type({ 123 }) which should place the string number in result.

Known Bugs

  • Modifying tables with constructs such as buf = { 123 }; buf = foo(buf) may or may not cause the kernel to BUG(). A variant code path that does not expose this bug is contained, which code path disables asynchronous execution of Lua code. This problem is currently investigated.

The buffer library

Calling buffer.new(x) returns a new buffer object of size x. The buffer object represents a char * of length x. Modifying and reading the buffer follows the familiar table interface:

buf = buffer.new(16)
buf[1]  = 100
buf[16] = 255

Buffer objects are used and returned by some of the provided bindings, such as crypto.sha1 and crypto.random.

The Crypto library

The crypto library contains two functions, crypto.sha1 and crypto.random. crypto.random(x) returns a buffer object of size x filled with random data. The function is an almost direct mapping to the kernel's get_random_bytes function.

crypto.sha1(x) returns a buffer of size 20 bytes (one SHA1 hash) and takes as its parameter x a buffer of data to be hashed. At the moment, the size of x is limited to PAGE_SZ, which is 4Kb on most x86 machines.

About

Linux Kernel Lua Scripting Engine


Languages

Language:C 90.0%Language:C++ 7.1%Language:Makefile 2.2%Language:Assembly 0.5%Language:Shell 0.2%