Class: SeccompTools::Asm::Compiler
- Inherits:
-
Object
- Object
- SeccompTools::Asm::Compiler
- Defined in:
- lib/seccomp-tools/asm/compiler.rb
Overview
Compile seccomp rules.
Constant Summary collapse
- JUMP_DISTANCE_MAX =
The farthest distance of a relative jump in BPF.
255
Instance Method Summary collapse
-
#compile! ⇒ Array<SeccompTools::BPF>
Compiles the processed instructions.
-
#initialize(source, filename, arch) ⇒ Compiler
constructor
Instantiate a Compiler object.
Constructor Details
#initialize(source, filename, arch) ⇒ Compiler
Instantiate a SeccompTools::Asm::Compiler object.
26 27 28 29 30 |
# File 'lib/seccomp-tools/asm/compiler.rb', line 26 def initialize(source, filename, arch) @scanner = Scanner.new(source, arch, filename:) @arch = arch @symbols = {} end |
Instance Method Details
#compile! ⇒ Array<SeccompTools::BPF>
Compiles the processed instructions.
Scans and parses the source, resolves the labels into relative jump distances, then emits one BPF per statement.
49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 |
# File 'lib/seccomp-tools/asm/compiler.rb', line 49 def compile! @scanner.validate! statements = SeccompAsmParser.new(@scanner).parse fixup_symbols(statements) resolve_symbols(statements) statements.map.with_index do |s, idx| @line = idx case s.type when :alu then emit_alu(*s.data) when :assign then emit_assign(*s.data) when :if then emit_cmp(*s.data) when :ret then emit_ret(*s.data) end end end |