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
4 changes: 3 additions & 1 deletion doc/design/luaebpf/compiler.md
Original file line number Diff line number Diff line change
Expand Up @@ -292,7 +292,9 @@ what `frame.lua` holds:
`LEN`. A global or an upvalue resolves to the value the body left, a field of a table the
compiler holds to that field's value, read when the function is compiled, and an index into a
map to the map's helpers; a field of the context or of a struct map value goes to `context.lua`
or `map.lua`, and a method call on a proxy is read back by `CALL`.
or `map.lua`, and a method call on a proxy is read back by `CALL`. `CALL` holds a method to the
value past it, the one it was read from: a loop's first pass may have read the method before a
later pass widened that value.
* `arithmetic.lua`: the arithmetic and bitwise opcodes and their forms with a constant, `UNM`,
`BNOT` and `NOT`, with Lua's semantics over 64-bit integers. `MMBIN` and its kin, which the VM
runs only when an operand is not a number, emit nothing, since an operand that is not a number is
Expand Down
5 changes: 5 additions & 0 deletions doc/guide/08-luaebpf.md
Original file line number Diff line number Diff line change
Expand Up @@ -599,6 +599,10 @@ Give the variable one type on every path: `local v = 0`. These are refused too:
* A view read in a function that has assigned the parameter its context or its packet came in: "a
view is read through the context or a packet, which no parameter of the function holds here". A
view keeps the offset it starts at and no packet, and its fields are read through that parameter.
* A method called on a variable that a loop sets to nil, or to another value, after a pass that
called it on the packet: "'getbyte' takes the packet, not a packet that may be nil". Lua raises
on the pass where the variable is not the packet, and the read would go through whatever word the
register holds there.
* A verdict that may be nil: "the verdict may be nil here; test it first". The kernel would read
nil as 0, which is an action.
* A verdict that may be a boolean: "the verdict may be a boolean here; return an action". The
Expand Down Expand Up @@ -641,6 +645,7 @@ Each refusal reads `lunatik: <file>:<line>: <message>`.
| a runtime is called through its method; write 'limits:run(...)' | `limits(1)` | `limits:run(1)` |
| a runtime has no method 'call'; write 'limits:run(...)' | `limits:call(1)` | `limits:run(1)` |
| the function needs 528 bytes of stack, over the 512 eBPF allows | a call into a runtime named by 480 bytes | a shorter name |
| 'getbyte' takes the packet, not a packet that may be nil | `p:getbyte(i)` in a loop that sets `p = nil` | a variable of its own for nil |
| a number that may be nil cannot be compared with a number here | `==` on a variable nil on one path | `local v = 0` |
| a number that may be nil has no truth value in a compiled function | `if v then`, `v` nil on one path | `local v = 0`, then `if v ~= 0 then` |
| the verdict may be nil here; test it first | `return v`, `v` nil on one path | a verdict on every path |
Expand Down
10 changes: 10 additions & 0 deletions emit/call.lua
Original file line number Diff line number Diff line change
Expand Up @@ -156,12 +156,22 @@ local function subprogram(f, pc, ins, state, callee)
end
end

-- the call passes A+1 and the method is lowered for its recv, which a join keeps from a loop's first pass
local function received(f, pc, ins, state, callee)
local recv = state[ins.a + 1]
if not frame.same(recv, callee.recv) then
frame.refuse(f, pc, "'%s' takes the %s, not a %s", callee.name, frame.typename(callee.recv),
frame.typename(recv))
end
end

function call.CALL(f, pc, ins, state)
local callee = state[ins.a]
if ins.b == 0 or ins.c == 0 then
frame.refuse(f, pc, "a call with a variable number of values cannot be compiled")
end
if callee ~= nil and callee.t == METHOD then
received(f, pc, ins, state, callee)
packet.method(f, pc, ins, state, callee)
elseif callee ~= nil and runtime.isproxy(callee.k) then
runtime.call(f, pc, ins, state, callee)
Expand Down
1 change: 1 addition & 0 deletions emit/frame.lua
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,7 @@ local function same(a, b)
end
return a.t == b.t and a.k == b.k and a.map == b.map and a.codec == b.codec
end
frame.same = same

local function copy(state)
local out = {}
Expand Down
Loading