Rizin
unix-like reverse engineering framework and cli tools
rz_skyline.h File Reference
#include "rz_vector.h"
#include "rz_util/rz_itv.h"

Go to the source code of this file.

Classes

struct  rz_skyline_item_t
 
struct  rz_skyline_t
 

Typedefs

typedef struct rz_skyline_item_t RzSkylineItem
 
typedef struct rz_skyline_t RzSkyline
 

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)
 
static void rz_skyline_init (RzSkyline *skyline)
 
static void rz_skyline_fini (RzSkyline *skyline)
 
static void rz_skyline_clear (RzSkyline *skyline)
 
static const RzSkylineItemrz_skyline_get_item (RzSkyline *skyline, ut64 addr)
 
static void * rz_skyline_get (RzSkyline *skyline, ut64 addr)
 
static void * rz_skyline_get_intersect (RzSkyline *skyline, ut64 addr, ut64 len)
 
static bool rz_skyline_contains (RzSkyline *skyline, ut64 addr)
 

Typedef Documentation

◆ RzSkyline

typedef struct rz_skyline_t RzSkyline

◆ RzSkylineItem

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_clear()

static void rz_skyline_clear ( RzSkyline skyline)
inlinestatic

Definition at line 29 of file rz_skyline.h.

29  {
30  rz_return_if_fail(skyline);
31  rz_vector_clear(&skyline->v);
32 }
#define rz_return_if_fail(expr)
Definition: rz_assert.h:100
RZ_API void rz_vector_clear(RzVector *vec)
Definition: vector.c:68

References rz_return_if_fail, rz_vector_clear(), and rz_skyline_t::v.

Referenced by io_map_calculate_skyline(), rz_core_disasm_pde(), rz_io_cache_invalidate(), rz_io_cache_reset(), and rz_io_map_fini().

◆ rz_skyline_contains()

static bool rz_skyline_contains ( RzSkyline skyline,
ut64  addr 
)
inlinestatic

Definition at line 51 of file rz_skyline.h.

51  {
52  rz_return_val_if_fail(skyline, false);
53  return (bool)rz_skyline_get_item(skyline, addr);
54 }
static const RzSkylineItem * rz_skyline_get_item(RzSkyline *skyline, ut64 addr)
Definition: rz_skyline.h:34
static int addr
Definition: z80asm.c:58

References addr, rz_return_val_if_fail, and rz_skyline_get_item().

Referenced by rz_io_cache_at().

◆ rz_skyline_fini()

static void rz_skyline_fini ( RzSkyline skyline)
inlinestatic

Definition at line 24 of file rz_skyline.h.

24  {
25  rz_return_if_fail(skyline);
26  rz_vector_fini(&skyline->v);
27 }
RZ_API void rz_vector_fini(RzVector *vec)
Definition: vector.c:61

References rz_return_if_fail, rz_vector_fini(), and rz_skyline_t::v.

Referenced by rz_io_cache_fini().

◆ rz_skyline_get()

static void* rz_skyline_get ( RzSkyline skyline,
ut64  addr 
)
inlinestatic

Definition at line 39 of file rz_skyline.h.

39  {
40  rz_return_val_if_fail(skyline, NULL);
41  const RzSkylineItem *item = rz_skyline_get_item(skyline, addr);
42  return item ? item->user : NULL;
43 }

References addr, NULL, rz_return_val_if_fail, rz_skyline_get_item(), and rz_skyline_item_t::user.

Referenced by rz_io_map_get().

◆ rz_skyline_get_intersect()

static void* rz_skyline_get_intersect ( RzSkyline skyline,
ut64  addr,
ut64  len 
)
inlinestatic

Definition at line 45 of file rz_skyline.h.

45  {
46  rz_return_val_if_fail(skyline, NULL);
47  const RzSkylineItem *item = rz_skyline_get_item_intersect(skyline, addr, len);
48  return item ? item->user : NULL;
49 }
size_t len
Definition: 6502dis.c:15
RZ_API const RzSkylineItem * rz_skyline_get_item_intersect(RzSkyline *skyline, ut64 addr, ut64 len)
Definition: skyline.c:60

References addr, len, NULL, rz_return_val_if_fail, rz_skyline_get_item_intersect(), and rz_skyline_item_t::user.

◆ rz_skyline_get_item()

static const RzSkylineItem* rz_skyline_get_item ( RzSkyline skyline,
ut64  addr 
)
inlinestatic

Definition at line 34 of file rz_skyline.h.

34  {
35  rz_return_val_if_fail(skyline, NULL);
36  return rz_skyline_get_item_intersect(skyline, addr, 1);
37 }

References addr, NULL, rz_return_val_if_fail, and rz_skyline_get_item_intersect().

Referenced by rz_skyline_contains(), and rz_skyline_get().

◆ 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 }
lzma_index ** i
Definition: index.h:629
#define CMP_END_GTE_PART(addr, part)
Definition: skyline.c:9

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().

◆ rz_skyline_init()

static void rz_skyline_init ( RzSkyline skyline)
inlinestatic

Definition at line 19 of file rz_skyline.h.

19  {
20  rz_return_if_fail(skyline);
21  rz_vector_init(&skyline->v, sizeof(RzSkylineItem), NULL, NULL);
22 }
RZ_API void rz_vector_init(RzVector *vec, size_t elem_size, RzVectorFree free, void *free_user)
Definition: vector.c:33

References NULL, rz_return_if_fail, rz_vector_init(), and rz_skyline_t::v.

Referenced by rz_io_cache_init(), and rz_io_init().