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 spacecrypto
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 kernelsprintk
type
andgc_count
as bindings to parts of the default Lua library
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".
- 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 stringnumber
inresult
.
- Modifying tables with constructs such as
buf = { 123 }; buf = foo(buf)
may or may not cause the kernel toBUG()
. 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.
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 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.