Module: SeccompTools::Asm

Defined in:
lib/seccomp-tools/asm/asm.rb,
lib/seccomp-tools/asm/token.rb,
lib/seccomp-tools/asm/scalar.rb,
lib/seccomp-tools/asm/scanner.rb,
lib/seccomp-tools/asm/compiler.rb,
lib/seccomp-tools/asm/sasm.tab.rb,
lib/seccomp-tools/asm/statement.rb

Overview

Assembler of seccomp bpf.

Defined Under Namespace

Modules: Scalar Classes: Compiler, Scanner, SeccompAsmParser, Statement, Token

Class Method Summary collapse

Class Method Details

.asm(str, filename: '-', arch: nil) ⇒ String

Assembler of seccomp bpf.

Examples:

SeccompTools::Asm.asm("  # lines start with '#' are comments\n  A = sys_number                # here's a comment, too\n  A >= 0x40000000 ? dead : next # 'next' is a keyword, denote the next instruction\n  A == read ? ok : next         # custom defined label 'dead' and 'ok'\n  A == 1 ? ok : next            # SYS_write = 1 on amd64\n  return ERRNO(1)\n  dead:\n  return KILL\n  ok:\n  return ALLOW\n")
#=> <raw binary bytes>


32
33
34
35
36
37
# File 'lib/seccomp-tools/asm/asm.rb', line 32

def asm(str, filename: '-', arch: nil)
  filename = nil if filename == '-'
  arch = Util.system_arch if arch.nil?
  compiler = Compiler.new(str, filename, arch)
  compiler.compile!.map(&:asm).join
end