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

.by_name(hash) ⇒ {Symbol => Object}

hash, looked up so that an +x32_+-prefixed name falls back to the unprefixed one and an unknown name gives nil.

Parameters:

  • hash ({Symbol => Object})

Returns:

  • ({Symbol => Object})


210
211
212
213
214
215
216
217
# File 'lib/seccomp-tools/const.rb', line 210

def by_name(hash)
  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

.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_arg_bits ⇒ {Symbol => Array<Integer>}

Helper for loading syscall argument widths from generated sys_arg.rb.

Returns:

  • ({Symbol => Array<Integer>}) —

    Syscall name to how many bits of each 64-bit argument slot the kernel reads, in argument order. Lookups fall back like load_args.



196
197
198
# File 'lib/seccomp-tools/const.rb', line 196

def load_arg_bits
  by_name(prototypes.transform_values(&:values))
end

.load_args ⇒ {Symbol => Array<String>}

Helper for loading syscall argument names 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
# File 'lib/seccomp-tools/const.rb', line 187

def load_args
  by_name(prototypes.transform_values { |args| args.keys.map(&:to_s) })
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

.prototypes ⇒ {Symbol => {Symbol => Integer}}

The prototypes in sys_arg.rb, as syscall name to an ordered {argument name => bits}.

Returns:

  • ({Symbol => {Symbol => Integer}})


202
203
204
# File 'lib/seccomp-tools/const.rb', line 202

def prototypes
  @prototypes ||= instance_eval(File.read(File.join(__dir__, 'consts', 'sys_arg.rb')))
end