Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions doc/guide/08-luaebpf.md
Original file line number Diff line number Diff line change
Expand Up @@ -658,6 +658,12 @@ Each refusal reads `lunatik: <file>:<line>: <message>`.
| the map key -1 does not fit 'I4' | a key or a value outside its spec | a value its spec packs |
| module 'byteorder' not found | `require` of a C module | a Lua module under `/lib/modules/lua/`, or the directory `--scripts` names |

Kernel scripts older than the compiler, under `/lib/modules/lua/` or the directory `--scripts` names,
stop a compile at the first table or entry it reads that they do not carry, with no file and line of
the program file: `lunatik: /lib/modules/lua/linux/bpf.lua carries no 'max': the kernel scripts under
/lib/modules/lua predate the compiler`. The directory takes the kernel scripts of the Lunatik the
compiler's release names, or of a later one.

## How a program file becomes a program

```
Expand Down
6 changes: 4 additions & 2 deletions init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -101,8 +101,10 @@ end
-- `<path>: no program declared` when the body hands nothing to a constructor,
-- `<btffile>: <reason>`, `<btffile> carries no BTF header` and `<btffile> is shorter than its
-- BTF header says` when a layout is asked of a file that cannot be read, holds no BTF or is cut
-- short, and `<btffile> is a <order>-endian BTF, for a <order>-endian object` when the BTF a
-- layout was read from is not in the object's byte order
-- short, `<btffile> is a <order>-endian BTF, for a <order>-endian object` when the BTF a
-- layout was read from is not in the object's byte order, and `<script> carries no '<name>': the
-- kernel scripts under <scripts> predate the compiler` when the kernel script at `<script>` does
-- not carry a table or an entry `<name>` the compiler reads, as `func.map_lookup_elem`
function luaebpf.compile(path, btffile, scripts)
local chunk = proto.load(path)
programs.reset()
Expand Down
20 changes: 17 additions & 3 deletions proto.lua
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ local SCRIPTS <const> = "/lib/modules/lua" -- the kernel's LUA_ROOT
local MODULES <const> = "%s/?.lua;%s/?/init.lua" -- the kernel's LUA_PATH_DEFAULT, under a root
local ELSEWHERE <const> = "a compiled function is defined in the program file or a kernel script it requires, " ..
"installed as source"
local PREDATES <const> = "%s carries no '%s': the kernel scripts under %s predate the compiler"

local proto = {}

Expand Down Expand Up @@ -90,17 +91,30 @@ local function search(name)
end
table.insert(package.searchers, search) -- last: a module package.path finds is the CLI's Lua and shadows the kernel's

-- kernel scripts older than the compiler lack what it reads, and a nil stops it at a line of its own
local function strict(path, t, prefix)
for key, value in pairs(t) do
if type(value) == "table" then
strict(path, value, prefix .. key .. ".")
end
end
return setmetatable(t, {__index = function(_, key)
error(string.format(PREDATES, path, prefix .. key, root), 0)
end})
end

---
-- Loads the kernel script named `name`, from `/lib/modules/lua` or the directory `luaebpf.proto.scripts`
-- names, past any module the host's path holds under that name.
-- @function luaebpf.proto.script
-- @tparam string name a module's name, as a kernel script requires it
-- @treturn any what the script returns
-- @treturn table what the script returns
-- @raise the paths searched, where no kernel script carries the name, or what `luaebpf.proto.load`
-- raises
-- raises; and `<path> carries no '<name>': the kernel scripts under <dir> predate the compiler` where
-- a read names what the table does not carry, `<name>` dotted from it, as `func.map_lookup_elem`
function proto.script(name)
local path = assert(package.searchpath(name, string.format(MODULES, root, root)))
return proto.load(path)(name, path)
return strict(path, proto.load(path)(name, path), "")
end

local function renumber(p)
Expand Down
Loading