Module: SeccompTools::Const::Syscall

Defined in:
lib/seccomp-tools/const.rb

Overview

Define syscall numbers for all architectures. Since the list is too long, split it to files in consts/*.rb and load them in this module.

Class Method Summary collapse

Class Method Details

.const_missing(cons) ⇒ {Symbol => Integer}

To dynamically fetch constants from files.

Parameters:

  • cons (Symbol)

    Name of const, an upcased architecture name such as :AMD64.

Returns:

  • ({Symbol => Integer})

    The syscall table of that architecture, mapping name to number.

Raises:

  • (NameError)

    If no syscall table exists for cons.



164
165
166
# File 'lib/seccomp-tools/const.rb', line 164

def const_missing(cons)
  load_const(cons) || super
end

.load_args{Symbol => Array<String>}

Helper for loading syscall prototypes from generated sys_arg.rb.

Returns:

  • ({Symbol => Array<String>})

    Syscall name to its argument names. Lookups of an +x32_+-prefixed name fall back to the unprefixed one, and unknown names give nil.



187
188
189
190
191
192
193
194
195
# File 'lib/seccomp-tools/const.rb', line 187

def load_args
  hash = instance_eval(File.read(File.join(__dir__, 'consts', 'sys_arg.rb')))
  Hash.new do |_h, k|
    next hash[k] if hash[k]
    next hash[k.to_s[4..].to_sym] if k.to_s.start_with?('x32_')

    nil
  end
end

.load_const(cons) ⇒ {Symbol => Integer}?

Load from file and define const value.

Parameters:

  • cons (Symbol)

    Name of const, an upcased architecture name such as :AMD64.

Returns:

  • ({Symbol => Integer}?)

    The syscall table of that architecture, or nil if it has no file under consts/sys_nr/.



174
175
176
177
178
179
180
# File 'lib/seccomp-tools/const.rb', line 174

def load_const(cons)
  arch = cons.to_s.downcase
  filename = File.join(__dir__, 'consts', 'sys_nr', "#{arch}.rb")
  return unless File.exist?(filename)

  const_set(cons, instance_eval(File.read(filename)))
end