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 included from Glibc

#libc_free, #malloc_assert

Methods inherited from Segment

#coerce, #to_s

Constructor Details

#initialize(*args) ⇒ Libc

Instantiate a HeapInfo::Libc object.

Parameters:



18
19
20
# File 'lib/heapinfo/libc.rb', line 18

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:



63
64
65
66
67
68
69
70
# File 'lib/heapinfo/libc.rb', line 63

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:



30
31
32
33
34
35
# File 'lib/heapinfo/libc.rb', line 30

def main_arena
  return @main_arena.reload! if @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)


24
25
26
# File 'lib/heapinfo/libc.rb', line 24

def main_arena_offset
  info['main_arena_offset']
end

#tcacheHeapInfo::Tcache?

The tcache object.

Returns:



49
50
51
52
# File 'lib/heapinfo/libc.rb', line 49

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.



41
42
43
# File 'lib/heapinfo/libc.rb', line 41

def tcache?
  info['tcache_enable']
end