Home | History | Annotate | Download | only in bpf

Lines Matching defs:ffi

16 local ffi = require('ffi')
20 local BPF, HELPER = ffi.typeof('struct bpf'), ffi.typeof('struct bpf_func_id')
25 [1] = ffi.typeof('uint8_t'), [2] = ffi.typeof('uint16_t'), [4] = ffi.typeof('uint32_t'), [8] = ffi.typeof('uint64_t'),
42 -- Note: ffi.typeof doesn't accept '?' as template
43 return const_width_type[w] or ffi.typeof(string.format('uint8_t [%d]', w))
50 if not ffi.typeinfo then error('LuaJIT 2.1+ is required for ffi.typeinfo') end
51 local cinfo = ffi.typeinfo(ct)
53 cinfo = ffi.typeinfo(cinfo.sib)
57 local size = math.max(1, ffi.typeinfo(cinfo.sib or ct).size - cinfo.size)
65 if w then x = ffi.cast(const_width_type[w/8], x) end
74 w = w or ffi.sizeof(e.V[a].type)*8
82 w = w or ffi.sizeof(e.V[a].type)*8
90 if ffi.abi('be') then
92 return w and ffi.cast(const_width_type[w/8], x) or x
104 local w = ffi.sizeof(vinfo.__dissector)
108 off = ffi.offsetof(ct, field)
118 e.vreg(ret, 0, true, ffi.typeof('int32_t'))
135 builtins[ffi.new](e, dst, vtype) -- Allocate stack memory
145 local w = ffi.sizeof(vtype)
161 e.vreg(ret, 0, true, ffi.typeof('int32_t'))
166 builtins[ffi.cast] = function (e, dst, ct, x)
167 assert(e.V[ct].const, 'ffi.cast(ctype, x) called with bad ctype')
170 e.V[dst].const.__dissector = ffi.typeof(e.V[ct].const)
172 e.V[dst].type = ffi.typeof(e.V[ct].const)
179 if ffi.typeof(e.V[ct].const) == ffi.typeof('struct pt_regs') then
184 builtins[ffi.new] = function (e, dst, ct, x)
186 ct = ffi.typeof(e.V[ct].const) -- Get ctype from variable
188 assert(not x, 'NYI: ffi.new(ctype, ...) - initializer is not supported')
189 assert(not cdef.isptr(ct, true), 'NYI: ffi.new(ctype, ...) - ctype MUST NOT be a pointer')
192 e.V[dst].const = {__base = e.valloc(ffi.sizeof(ct), true), __dissector = ct}
197 e.V[dst].const.__dissector = ffi.typeof(elem_type)
201 builtins[ffi.copy] = function (e, ret, dst, src)
202 assert(cdef.isptr(e.V[dst].type), 'ffi.copy(dst, src) - dst MUST be a pointer type')
203 assert(cdef.isptr(e.V[src].type), 'ffi.copy(dst, src) - src MUST be a pointer type')
216 else error('ffi.copy(dst, src) - can\'t get stack offset of dst') end
221 e.emit(BPF.ALU64 + BPF.MOV + BPF.K, 2, 0, 0, ffi.sizeof(dst_tname))
232 e.vreg(ret, 0, true, ffi.typeof('int32_t'))
236 error('NYI: ffi.copy(dst, src) - src is backed by BPF map')
238 error('NYI: ffi.copy(dst, src) - src is backed by socket buffer')
242 error('NYI: ffi.copy(dst, src) - src is neither BPF map/socket buffer or probe')
258 e.V[fmt].type = ffi.typeof('char ['..len..']')
265 e.emit(BPF.ALU64 + BPF.MOV + BPF.K, 2, 0, 0, ffi.sizeof(e.V[fmt].type))
276 e.vreg(ret, 0, true, ffi.typeof('int32_t')) -- Return is integer
286 e.vreg(e.tmpvar, 2, true, ffi.typeof('uint64_t'))
287 e.LD_IMM_X(2, BPF.PSEUDO_MAP_FD, map.fd, ffi.sizeof('uint64_t'))
293 e.vreg(e.tmpvar, 3, false, ffi.typeof('uint64_t'))
299 e.emit(BPF.ALU64 + BPF.MOV + BPF.K, 5, 0, 0, ffi.sizeof(e.V[src].type))
302 e.vreg(dst, 0, true, ffi.typeof('int32_t')) -- Return is integer
311 e.vreg(e.tmpvar, 2, false, ffi.typeof('uint64_t'))
320 e.emit(BPF.ALU64 + BPF.MOV + BPF.K, 4, 0, 0, ffi.sizeof(e.V[var].type))
323 e.vreg(dst, 0, true, ffi.typeof('int32_t')) -- Return is integer
333 e.vreg(e.tmpvar, 2, true, ffi.typeof('uint64_t'))
334 e.LD_IMM_X(2, BPF.PSEUDO_MAP_FD, map.fd, ffi.sizeof('uint64_t'))
345 e.vreg(ret, 0, true, ffi.typeof('int32_t'))
367 e.emit(BPF.ALU64 + BPF.MOV + BPF.K, 2, 0, 0, ffi.sizeof(e.V[dst].type))
370 e.vreg(ret, 0, true, ffi.typeof('int32_t'))
388 e.vderef(v, v, {const = {__dissector=ffi.typeof('uint64_t')}})
426 e.vreg(dst, 0, true, vtype or ffi.typeof('uint64_t'))
446 builtins[rand] = function (e, dst) return call_helper(e, dst, HELPER.get_prandom_u32, ffi.typeof('uint32_t')) end