Module: Seccomp::Arch

Defined in:
lib/seccomp/arch.rb

Overview

Architecture tokens and name conversion.

Class Method Summary collapse

Class Method Details

.allHash<Symbol, Integer>

Returns constants available in the linked header.

Examples:

Arch.all[:x86_64]

Returns:

  • (Hash<Symbol, Integer>)

    constants available in the linked header



10
11
12
13
14
# File 'lib/seccomp/arch.rb', line 10

def all
  @all ||= constants(false).grep_v(:NAMES).to_h do |name|
    [name.to_s.downcase.to_sym, const_get(name)]
  end.freeze
end

.name(token) ⇒ Symbol?

Returns known name.

Examples:

Arch.name(Arch.native)

Parameters:

  • token (Integer)

    architecture token

Returns:

  • (Symbol, nil)

    known name



44
45
46
# File 'lib/seccomp/arch.rb', line 44

def name(token)
  all.key(token) || (token == native ? all.key(native) : nil)
end

.nativeInteger

Returns native runtime architecture token.

Examples:

Arch.native

Returns:

  • (Integer)

    native runtime architecture token



18
19
20
# File 'lib/seccomp/arch.rb', line 18

def native
  LowLevel.arch_native
end

.resolve(value) ⇒ Integer

Returns architecture token.

Examples:

Arch.resolve(:x86_64)

Parameters:

  • value (Symbol, String, Integer)

    architecture

Returns:

  • (Integer)

    architecture token

Raises:

  • (ArgumentError)

    for an unknown name



26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/seccomp/arch.rb', line 26

def resolve(value)
  return value if value.is_a?(Integer)
  unless value.respond_to?(:to_sym)
    raise ArgumentError, "unknown architecture: #{value.inspect}"
  end

  key = value.to_sym
  all.fetch(key) do
    token = LowLevel.arch_resolve_name(value.to_s)
    raise ArgumentError, "unknown architecture: #{value.inspect}" if token.zero?

    token
  end
end