Rizin
unix-like reverse engineering framework and cli tools
skyline.c File Reference
#include <rz_skyline.h>

Go to the source code of this file.

Macros

#define CMP_BEGIN_GTE_PART(addr, part)    (((addr) > (rz_itv_begin(((RzSkylineItem *)(part))->itv))) - ((addr) < (rz_itv_begin(((RzSkylineItem *)(part))->itv))))
 
#define CMP_END_GTE_PART(addr, part)    (((addr) < (rz_itv_end(((RzSkylineItem *)(part))->itv)) || !rz_itv_end(((RzSkylineItem *)(part))->itv)) ? -1 : 1)
 

Functions

RZ_API bool rz_skyline_add (RzSkyline *skyline, RzInterval itv, void *user)
 
RZ_API const RzSkylineItemrz_skyline_get_item_intersect (RzSkyline *skyline, ut64 addr, ut64 len)
 

Macro Definition Documentation

◆ CMP_BEGIN_GTE_PART

#define CMP_BEGIN_GTE_PART (   addr,
  part 
)     (((addr) > (rz_itv_begin(((RzSkylineItem *)(part))->itv))) - ((addr) < (rz_itv_begin(((RzSkylineItem *)(part))->itv))))

Definition at line 6 of file skyline.c.

◆ CMP_END_GTE_PART

#define CMP_END_GTE_PART (   addr,
  part 
)     (((addr) < (rz_itv_end(((RzSkylineItem *)(part))->itv)) || !rz_itv_end(((RzSkylineItem *)(part))->itv)) ? -1 : 1)

Definition at line 9 of file skyline.c.

Function Documentation

◆ rz_skyline_add()

RZ_API bool rz_skyline_add ( RzSkyline skyline,
RzInterval  itv,
void *  user 
)

Definition at line 12 of file skyline.c.

12  {
13  rz_return_val_if_fail(skyline, false);
14  if (rz_itv_size(itv)) {
15  // Allow intervals whose end overflows to 0, but block if it overflows past that
17  }
18  RzVector *skyline_vec = &skyline->v;
19  RzSkylineItem new_part = { itv, user };
20  const ut64 new_part_end = rz_itv_end(new_part.itv);
21 
22  // `slot` is the index of the first RzSkylineItem with part->itv.addr >= new_part.itv.addr
23  size_t slot;
24  rz_vector_lower_bound(skyline_vec, new_part.itv.addr, slot, CMP_BEGIN_GTE_PART);
25  const bool is_last = slot == rz_vector_len(skyline_vec);
26  bool is_inside_prev_part = false;
27  if (slot) {
28  RzSkylineItem *prev_part = rz_vector_index_ptr(skyline_vec, slot - 1);
29  const ut64 prev_part_end = rz_itv_end(prev_part->itv);
30  if (prev_part_end > rz_itv_begin(new_part.itv)) {
31  prev_part->itv.size = rz_itv_begin(new_part.itv) - rz_itv_begin(prev_part->itv);
32  if (prev_part_end > new_part_end) {
33  RzSkylineItem tail;
34  tail.user = prev_part->user;
35  tail.itv.addr = new_part_end;
36  tail.itv.size = prev_part_end - rz_itv_begin(tail.itv);
37  rz_vector_insert(skyline_vec, slot, &tail);
38  is_inside_prev_part = true;
39  }
40  }
41  }
42  if (!is_last && !is_inside_prev_part) {
43  RzSkylineItem *part = rz_vector_index_ptr(skyline_vec, slot);
44  while (part && rz_itv_include(new_part.itv, part->itv)) {
45  // Remove `part` that fits in `new_part`
46  rz_vector_remove_at(skyline_vec, slot, NULL);
47  part = slot < rz_vector_len(skyline_vec) ? rz_vector_index_ptr(skyline_vec, slot) : NULL;
48  }
49  if (part && rz_itv_overlap(new_part.itv, part->itv)) {
50  // Chop start of last `part` that intersects `new_part`
51  const ut64 oaddr = rz_itv_begin(part->itv);
52  part->itv.addr = new_part_end;
53  part->itv.size -= rz_itv_begin(part->itv) - oaddr;
54  }
55  }
56  rz_vector_insert(skyline_vec, slot, &new_part);
57  return true;
58 }
#define NULL
Definition: cris-opc.c:27
#define rz_return_val_if_fail(expr, val)
Definition: rz_assert.h:108
static bool rz_itv_include(RzInterval itv, RzInterval x)
Definition: rz_itv.h:58
static ut64 rz_itv_begin(RzInterval itv)
Definition: rz_itv.h:34
static ut64 rz_itv_end(RzInterval itv)
Definition: rz_itv.h:42
static bool rz_itv_overlap(RzInterval itv, RzInterval x)
Definition: rz_itv.h:64
static ut64 rz_itv_size(RzInterval itv)
Definition: rz_itv.h:38
#define UT64_ADD_OVFCHK(x, y)
#define rz_vector_lower_bound(vec, x, i, cmp)
Definition: rz_vector.h:190
static void * rz_vector_index_ptr(RzVector *vec, size_t index)
Definition: rz_vector.h:88
RZ_API void rz_vector_remove_at(RzVector *vec, size_t index, void *into)
Definition: vector.c:127
static size_t rz_vector_len(const RzVector *vec)
Definition: rz_vector.h:82
RZ_API void * rz_vector_insert(RzVector *vec, size_t index, void *x)
Definition: vector.c:151
#define CMP_BEGIN_GTE_PART(addr, part)
Definition: skyline.c:6
ut64 addr
Definition: rz_itv.h:15
ut64 size
Definition: rz_itv.h:16
RzInterval itv
Definition: rz_skyline.h:8
RzVector v
Definition: rz_skyline.h:13
ut64(WINAPI *w32_GetEnabledXStateFeatures)()

References rz_interval_t::addr, CMP_BEGIN_GTE_PART, rz_skyline_item_t::itv, NULL, rz_itv_begin(), rz_itv_end(), rz_itv_include(), rz_itv_overlap(), rz_itv_size(), rz_return_val_if_fail, rz_vector_index_ptr(), rz_vector_insert(), rz_vector_len(), rz_vector_lower_bound, rz_vector_remove_at(), rz_interval_t::size, rz_skyline_item_t::user, ut64(), UT64_ADD_OVFCHK, and rz_skyline_t::v.

Referenced by io_map_calculate_skyline(), io_map_new(), rz_core_disasm_pde(), rz_io_cache_invalidate(), rz_io_cache_write(), and rz_io_map_priorize().

◆ rz_skyline_get_item_intersect()

RZ_API const RzSkylineItem* rz_skyline_get_item_intersect ( RzSkyline skyline,
ut64  addr,
ut64  len 
)

Definition at line 60 of file skyline.c.

60  {
61  if (!len) {
62  return NULL;
63  }
64  rz_return_val_if_fail(skyline, NULL);
66  RzVector *skyline_vec = &skyline->v;
67  size_t i, l = rz_vector_len(skyline_vec);
69  if (i == l) {
70  return false;
71  }
72  const RzSkylineItem *item = rz_vector_index_ptr(skyline_vec, i);
73  const ut64 intersect_end = addr + len;
74  return !intersect_end || (item->itv.addr < addr + len) ? item : NULL;
75 }
size_t len
Definition: 6502dis.c:15
lzma_index ** i
Definition: index.h:629
#define CMP_END_GTE_PART(addr, part)
Definition: skyline.c:9
static int addr
Definition: z80asm.c:58

References addr, rz_interval_t::addr, CMP_END_GTE_PART, i, rz_skyline_item_t::itv, len, NULL, rz_return_val_if_fail, rz_vector_index_ptr(), rz_vector_len(), rz_vector_lower_bound, ut64(), UT64_ADD_OVFCHK, and rz_skyline_t::v.

Referenced by rz_io_cache_read(), rz_skyline_get_intersect(), and rz_skyline_get_item().