Professional Documents
Culture Documents
Untitled
Untitled
D
BS
Lua
Lua in the NetBSD Kernel
Marc Balmer <mbalmer@NetBSD.org>
Topics
1 The Programming Language Lua
State Manipulation
Calling C from Lua
Calling Lua from C
3 Lua in the NetBSD Kernel
Use Cases
Implementation Overview
Implementation Details
Lua in the NetBSD Kernel
Lua Source
iler
mp
Lua
1001101
0010010
0100011
1011010
Bytecode
Ru
local n
n=n + 1
print(n)
Co
ime
nt
Lua
Lua Source
iler
mp
Lua
1001101
0010010
0100011
1011010
Bytecode
Ru
local n
n=n + 1
print(n)
Co
ime
nt
Lua
Running from C
Tables
Modules
State Manipulation
Calling a C Function
Use Cases
Use Cases
development
Modifying the system behaviour
Configuration of kernel subsystems
Use Cases
Alternatives
Python
Java
Use Cases
Python
Use Cases
Java
Easy to integrate
Difficult object mapping
Memory considerations
Has been used for driver development
Use Cases
Use Cases
NetBSD
Proof that the Lua VM can run in the kernel, lack of
infrastructure
Infrastructure has been added
About to be added to NetBSD -current
Should be part of NetBSD 7
Use Cases
to src/sys/external/mit/lua
Kernel parts will reside under src/sys/lua
The last step will be an update to the latest Lua (5.2.1)
Use Cases
Running in Userland
Use Cases
Locking is an issue
Implementation Overview
Lua
ate
ate
ate
ate
St
Lua
ime
nt
Lua bindings
St
modload(8)
iler
mp
Ru
Kernel
Co
Userland
Lua
Lua
Lua
Lua
St
St
luactl(8)
sysctl(8)
lua(4)
ioctl(2)
sysctl(3)
luac(1)
local n
n=n + 1
print(n)
local n
n=n + 1
print(n)
local n
n=n + 1
print(n)
local n
n=n + 1
print(n)
local n
n=n + 1
print(n)
Filesystem
Implementation Overview
iler
mp
Ru
Kernel
Co
Userland
Lua
ime
nt
Lua
lua(4)
ioctl(2)
sysctl(3)
Filesystem
Implementation Overview
Kernel
luactl(8)
sysctl(8)
lua(4)
ioctl(2)
sysctl(3)
Filesystem
Implementation Overview
Lua States
Userland
Kernel
St
St
ate
ate
ate
ate
St
St
Lua
Lua
Lua
Lua
Filesystem
Implementation Overview
Lua Modules
Userland
modload(8)
Kernel
Lua bindings
Filesystem
Implementation Overview
Lua Users
Userland
Kernel
Kernel subsystems (Users)
Filesystem
Implementation Overview
Kernel
luactl(8)
Filesystem
Implementation Details
,,require
Implementation Details
sysctl(8) Variables
kern.lua.require=1
kern.lua.autoload=1
kern.lua.bytecode=0
kern.lua.maxcount=0
kern.lua.protect=0
Implementation Details
iler
mp
Ru
Kernel
Co
Userland
Lua
ime
nt
lua_Loader
Lua
St
ate
Lua
lua(4)
luactl(8)
ioctl(2)
local n
n=n + 1
print(n)
local n
n=n + 1
print(n)
local n
n=n + 1
print(n)
local n
n=n + 1
print(n)
local n
n=n + 1
print(n)
Filesystem
Implementation Details
Security
predefined bindings
Dangerous code can be disabled at the byte-code level
Implementation Details
D
BS
Lua
Lua in the NetBSD Kernel