Class: HeapInfo::Libc

Inherits:
Segment show all
Includes:
Glibc
Defined in:
lib/heapinfo/libc.rb

Overview

Record libc's base, name, and offsets.

Instance Attribute Summary

Attributes included from Glibc

#size_t

Attributes inherited from Segment

#base, #name

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Segment

#coerce, #to_s

Constructor Details

#initialize(*args) ⇒ Libc

Instantiate a HeapInfo::Libc object.

Parameters:



20
21
22
# File 'lib/heapinfo/libc.rb', line 20

def initialize(*args)
  super
end

Class Method Details

.find(maps, name, **options) ⇒ HeapInfo::Libc

Returns libc segment found in maps.

Parameters:

  • maps (Array)

    See Segment#find for more information.

  • name (String)

    See Segment#find for more information.

  • options (Hash)

    a customizable set of options

Options Hash (**options):

  • bits (Integer)

    Either 64 or 32.

  • ld_name (String)

    The loader's realpath, will be used for running subprocesses.

  • dumper (Proc)

    The memory dumper for fetch more information.

  • method_heap (Proc)

    Method for getting heap segment.

Returns:



68
69
70
71
72
73
74
75
# File 'lib/heapinfo/libc.rb', line 68

def self.find(maps, name, **options)
  super(maps, name).tap do |obj|
    obj.size_t = options[:bits] / 8
    %i[ld_name dumper method_heap].each do |sym|
      obj.__send__("#{sym}=", options[sym])
    end
  end
end

Instance Method Details

#main_arenaHeapInfo::Arena

Get the main_arena of libc.

Returns:



32
33
34
35
36
37
38
39
# File 'lib/heapinfo/libc.rb', line 32

def main_arena
  return @main_arena.reload! if defined? @main_arena

  off = main_arena_offset
  return if off.nil?

  @main_arena = Arena.new(off + base, size_t, dumper)
end

#main_arena_offsetInteger

Get the offset of main_arena in libc.

Returns:

  • (Integer)


26
27
28
# File 'lib/heapinfo/libc.rb', line 26

def main_arena_offset
  info['main_arena_offset']
end

#tcacheHeapInfo::Tcache?

The tcache object.

Returns:



53
54
55
56
57
# File 'lib/heapinfo/libc.rb', line 53

def tcache
  return unless tcache?

  @tcache ||= Tcache.new(tcache_base, size_t, dumper)
end

#tcache?Boolean

Does this glibc support tcache?

Returns:

  • (Boolean)

    true or false.



45
46
47
# File 'lib/heapinfo/libc.rb', line 45

def tcache?
  info['tcache_enable']
end