Class: Seccomp::ArgCmp

Inherits:
Object
  • Object
show all
Defined in:
lib/seccomp/arg.rb

Overview

Immutable syscall argument comparison.

Constant Summary collapse

MAX_DATUM =

This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.

Largest accepted unsigned syscall datum.

(1 << 64) - 1
OPERATORS =

This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.

Symbol-to-C-operator lookup.

{
  ne: Compare::NE,
  lt: Compare::LT,
  le: Compare::LE,
  eq: Compare::EQ,
  ge: Compare::GE,
  gt: Compare::GT,
  masked_eq: Compare::MASKED_EQ
}.freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(arg:, op:, datum_a:, datum_b: 0, width: 64) ⇒ void

Examples:

ArgCmp.new(arg: 0, op: :eq, datum_a: 2)

Parameters:

  • arg (Integer)

    argument index from 0 through 5

  • op (Symbol)

    comparison operator

  • datum_a (Integer)

    first comparison datum

  • datum_b (Integer) (defaults to: 0)

    second datum for masked equality

  • width (Integer) (defaults to: 64)

    32 or 64

Raises:

  • (ArgumentError)

    for invalid input



31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/seccomp/arg.rb', line 31

def initialize(arg:, op:, datum_a:, datum_b: 0, width: 64)
  unless arg.is_a?(Integer) && (0..5).cover?(arg)
    raise ArgumentError, "arg must be an Integer between 0 and 5"
  end
  raise ArgumentError, "width must be 32 or 64" unless [32, 64].include?(width)

  @arg = arg
  operator = op.to_sym if op.respond_to?(:to_sym)
  @op = OPERATORS.fetch(operator) { raise ArgumentError, "unknown comparison: #{op.inspect}" }
  @datum_a = datum(datum_a, width)
  @datum_b = datum(datum_b, width)
end

Instance Attribute Details

#argObject (readonly)

Returns the value of attribute arg.



21
22
23
# File 'lib/seccomp/arg.rb', line 21

def arg
  @arg
end

#datum_aObject (readonly)

Returns the value of attribute datum_a.



21
22
23
# File 'lib/seccomp/arg.rb', line 21

def datum_a
  @datum_a
end

#datum_bObject (readonly)

Returns the value of attribute datum_b.



21
22
23
# File 'lib/seccomp/arg.rb', line 21

def datum_b
  @datum_b
end

#opObject (readonly)

Returns the value of attribute op.



21
22
23
# File 'lib/seccomp/arg.rb', line 21

def op
  @op
end

Instance Method Details

#to_aArray<Integer>

Returns low-level comparison tuple.

Examples:

comparison.to_a

Returns:

  • (Array<Integer>)

    low-level comparison tuple



46
47
48
# File 'lib/seccomp/arg.rb', line 46

def to_a
  [arg, op, datum_a, datum_b]
end