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:


8
9
10
11
# File 'lib/heapinfo/libc.rb', line 8

def initialize(*args)
  super
  @offset = {}
end

Class Method Details

.find(maps, name, bits, ld_name, dumper) ⇒ 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.

  • 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.

Returns:


36
37
38
39
40
41
42
# File 'lib/heapinfo/libc.rb', line 36

def self.find(maps, name, bits, ld_name, dumper)
  obj = super(maps, name)
  obj.size_t = bits / 8
  obj.__send__(:ld_name=, ld_name)
  obj.__send__(:dumper=, dumper)
  obj
end

Instance Method Details

#main_arenaHeapInfo::Arena

Get the main_arena of libc.

Returns:


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

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)

15
16
17
18
19
# File 'lib/heapinfo/libc.rb', line 15

def main_arena_offset
  return @offset[:main_arena] if @offset[:main_arena]
  return nil unless exhaust_search :main_arena
  @offset[:main_arena]
end