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(<<-EOS)
  # lines start with '#' are comments
  A = sys_number                # here's a comment, too
  A >= 0x40000000 ? dead : next # 'next' is a keyword, denote the next instruction
  A == read ? ok : next         # custom defined label 'dead' and 'ok'
  A == 1 ? ok : next            # SYS_write = 1 on amd64
  return ERRNO(1)
  dead:
  return KILL
  ok:
  return ALLOW
EOS
#=> <raw binary bytes>

Parameters:

  • str (String)
  • filename (String) (defaults to: '-')

    Only used for error messages.

  • arch (Symbol?) (defaults to: nil)

Returns:

  • (String)

    Raw BPF 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