class HeapInfo::Fastbin
Class for record fastbin type chunk.
Attributes
fd[R]
@return [Integer] fd
index[RW]
@return [Integer] index
Public Class Methods
new(_size_t, base, *)
click to toggle source
Instantiate a {HeapInfo::Fastbin} object.
@see HeapInfo::Chunk
Calls superclass method
# File lib/heapinfo/arena.rb, line 89 def initialize(_size_t, base, *) super @fd = fd_of(base) end
Public Instance Methods
idx_to_size()
click to toggle source
Mapping index of fastbin to chunk size. @return [Integer] size
# File lib/heapinfo/arena.rb, line 96 def idx_to_size index * size_t * 2 + size_t * 4 end
inspect()
click to toggle source
Pretty inspect. @return [String] fastbin layouts wrapper with color codes.
# File lib/heapinfo/arena.rb, line 110 def inspect title + list.map do |ptr| next "(#{ptr})\n" if ptr.is_a?(Symbol) next " => (nil)\n" if ptr.nil? format(' => %s', Helper.color(format('%#x', ptr))) end.join end
list()
click to toggle source
@return [Array<Integer, Symbol, nil>] single link list of fd
chain.
Last element will be: - +:loop+ if loop detectded - +:invalid+ invalid address detected - +nil+ end with zero address (normal case)
# File lib/heapinfo/arena.rb, line 123 def list dup = {} ptr = @fd ret = [] while ptr != 0 ret << ptr return ret << :loop if dup[ptr] dup[ptr] = true ptr = fd_of(ptr) return ret << :invalid if ptr.nil? end ret << nil end
title()
click to toggle source
For pretty inspect. @return [String] Title with color codes.
# File lib/heapinfo/arena.rb, line 102 def title class_name = Helper.color(Helper.class_name(self), sev: :bin) size_str = index.nil? ? nil : "[#{Helper.color(format('%#x', idx_to_size))}]" "#{class_name}#{size_str}: " end
Private Instance Methods
addr_of(ptr, offset)
click to toggle source
# File lib/heapinfo/arena.rb, line 139 def addr_of(ptr, offset) t = dump(ptr + size_t * offset, size_t) return nil if t.nil? Helper.unpack(size_t, t) end
bk_of(ptr)
click to toggle source
@param [Integer] ptr Get the bk
value of chunk at ptr
. @return [Integer] The bk
.
# File lib/heapinfo/arena.rb, line 153 def bk_of(ptr) addr_of(ptr, 3) end
fd_of(ptr)
click to toggle source
@param [Integer] ptr Get the fd
value of chunk at ptr
. @return [Integer] The fd
.
# File lib/heapinfo/arena.rb, line 147 def fd_of(ptr) addr_of(ptr, 2) end