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

Go to the source code of this file.

Macros

#define BITMAP_TEST   0
 
#define BITWORD_BITS   (sizeof(RBitword) * 8)
 
#define BITWORD_BITS_MASK   (BITWORD_BITS - 1)
 
#define BITWORD_MULT(bit)   (((bit) + (BITWORD_BITS_MASK)) & ~(BITWORD_BITS_MASK))
 
#define BITWORD_TEST(x, y)   (((x) >> (y)) & 1)
 
#define BITMAP_WORD_COUNT(bit)   (BITWORD_MULT(bit) >> BITWORD_BITS_SHIFT)
 

Functions

RZ_API RzBitmaprz_bitmap_new (size_t len)
 
RZ_API void rz_bitmap_set_bytes (RzBitmap *b, const ut8 *buf, int len)
 
RZ_API void rz_bitmap_free (RzBitmap *b)
 
RZ_API void rz_bitmap_set (RzBitmap *b, size_t bit)
 
RZ_API void rz_bitmap_unset (RzBitmap *b, size_t bit)
 
RZ_API int rz_bitmap_test (RzBitmap *b, size_t bit)
 

Macro Definition Documentation

◆ BITMAP_TEST

#define BITMAP_TEST   0

Definition at line 7 of file bitmap.c.

◆ BITMAP_WORD_COUNT

#define BITMAP_WORD_COUNT (   bit)    (BITWORD_MULT(bit) >> BITWORD_BITS_SHIFT)

Definition at line 14 of file bitmap.c.

◆ BITWORD_BITS

#define BITWORD_BITS   (sizeof(RBitword) * 8)

Definition at line 9 of file bitmap.c.

◆ BITWORD_BITS_MASK

#define BITWORD_BITS_MASK   (BITWORD_BITS - 1)

Definition at line 10 of file bitmap.c.

◆ BITWORD_MULT

#define BITWORD_MULT (   bit)    (((bit) + (BITWORD_BITS_MASK)) & ~(BITWORD_BITS_MASK))

Definition at line 11 of file bitmap.c.

◆ BITWORD_TEST

#define BITWORD_TEST (   x,
 
)    (((x) >> (y)) & 1)

Definition at line 12 of file bitmap.c.

Function Documentation

◆ rz_bitmap_free()

RZ_API void rz_bitmap_free ( RzBitmap b)

Definition at line 33 of file bitmap.c.

33  {
34  free(b->bitmap);
35  free(b);
36 }
RZ_API void Ht_() free(HtName_(Ht) *ht)
Definition: ht_inc.c:130
#define b(i)
Definition: sha256.c:42

References b, and free().

Referenced by rz_bin_dmp64_init_bmp_pages().

◆ rz_bitmap_new()

RZ_API RzBitmap* rz_bitmap_new ( size_t  len)

Definition at line 16 of file bitmap.c.

16  {
18  if (!b) {
19  return NULL;
20  }
21  b->length = len;
22  b->bitmap = calloc(BITMAP_WORD_COUNT(len), sizeof(RBitword));
23  return b;
24 }
size_t len
Definition: 6502dis.c:15
#define BITMAP_WORD_COUNT(bit)
Definition: bitmap.c:14
#define NULL
Definition: cris-opc.c:27
void * calloc(size_t number, size_t size)
Definition: malloc.c:102
#define RBitword
Definition: rz_bitmap.h:11
#define RZ_NEW0(x)
Definition: rz_types.h:284

References b, BITMAP_WORD_COUNT, calloc(), len, NULL, RBitword, and RZ_NEW0.

Referenced by rz_bin_dmp64_init_bmp_pages().

◆ rz_bitmap_set()

RZ_API void rz_bitmap_set ( RzBitmap b,
size_t  bit 
)

Definition at line 38 of file bitmap.c.

38  {
39  if (bit < b->length) {
40  b->bitmap[(bit >> BITWORD_BITS_SHIFT)] |=
41  ((RBitword)1 << (bit & BITWORD_BITS_MASK));
42  }
43 }
#define BITWORD_BITS_MASK
Definition: bitmap.c:10
RzCryptoSelector bit
Definition: crypto.c:16
static static sync static getppid static getegid const char static filename char static len const char char static bufsiz static mask static vfork const void static prot static getpgrp const char static swapflags static arg static fd static protocol static who struct sockaddr static addrlen static backlog struct timeval struct timezone static tz const struct iovec static count static mode const void const struct sockaddr static tolen const char static pathname void static offset struct stat static buf void long static basep static whence static length const void static len static semflg const void static shmflg const struct timespec struct timespec static rem const char static group const void length
Definition: sflib.h:133
#define BITWORD_BITS_SHIFT
Definition: rz_bitmap.h:10

References b, bit, BITWORD_BITS_MASK, BITWORD_BITS_SHIFT, length, and RBitword.

◆ rz_bitmap_set_bytes()

RZ_API void rz_bitmap_set_bytes ( RzBitmap b,
const ut8 buf,
int  len 
)

Definition at line 26 of file bitmap.c.

26  {
27  if (b->length < len) {
28  len = b->length;
29  }
30  memcpy(b->bitmap, buf, len);
31 }
voidpf void * buf
Definition: ioapi.h:138
memcpy(mem, inblock.get(), min(CONTAINING_RECORD(inblock.get(), MEMBLOCK, data) ->size, size))

References b, len, and memcpy().

Referenced by rz_bin_dmp64_init_bmp_pages().

◆ rz_bitmap_test()

RZ_API int rz_bitmap_test ( RzBitmap b,
size_t  bit 
)

Definition at line 52 of file bitmap.c.

52  {
53  if (bit < b->length) {
54  RBitword bword = b->bitmap[(bit >> BITWORD_BITS_SHIFT)];
55  return BITWORD_TEST(bword, (bit & BITWORD_BITS_MASK));
56  }
57  return -1;
58 }
#define BITWORD_TEST(x, y)
Definition: bitmap.c:12

References b, bit, BITWORD_BITS_MASK, BITWORD_BITS_SHIFT, BITWORD_TEST, length, and RBitword.

Referenced by rz_bin_dmp64_init_bmp_pages().

◆ rz_bitmap_unset()

RZ_API void rz_bitmap_unset ( RzBitmap b,
size_t  bit 
)

Definition at line 45 of file bitmap.c.

45  {
46  if (bit < b->length) {
47  b->bitmap[(bit >> BITWORD_BITS_SHIFT)] &=
48  ~((RBitword)1 << (bit & BITWORD_BITS_MASK));
49  }
50 }

References b, bit, BITWORD_BITS_MASK, BITWORD_BITS_SHIFT, length, and RBitword.