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

Go to the source code of this file.

Classes

struct  buf_mmap_user
 
struct  buf_mmap_priv
 

Functions

static struct buf_mmap_privget_priv_mmap (RzBuffer *b)
 
static bool buf_mmap_init (RzBuffer *b, const void *user)
 
static bool buf_mmap_fini (RzBuffer *b)
 
static bool buf_mmap_resize (RzBuffer *b, ut64 newsize)
 
static ut8buf_mmap_get_whole_buf (RzBuffer *b, ut64 *size)
 

Variables

static const RzBufferMethods buffer_mmap_methods
 

Function Documentation

◆ buf_mmap_fini()

static bool buf_mmap_fini ( RzBuffer b)
static

Definition at line 45 of file buf_mmap.c.

45  {
46  struct buf_mmap_priv *priv = get_priv_mmap(b);
47  rz_file_mmap_free(priv->mmap);
48  RZ_FREE(b->priv);
49  return true;
50 }
static struct buf_mmap_priv * get_priv_mmap(RzBuffer *b)
Definition: buf_mmap.c:19
RZ_API void rz_file_mmap_free(RzMmap *m)
Definition: file.c:995
#define RZ_FREE(x)
Definition: rz_types.h:369
#define b(i)
Definition: sha256.c:42
RzMmap * mmap
Definition: buf_mmap.c:16

References b, get_priv_mmap(), buf_mmap_priv::mmap, rz_file_mmap_free(), and RZ_FREE.

◆ buf_mmap_get_whole_buf()

static ut8* buf_mmap_get_whole_buf ( RzBuffer b,
ut64 size 
)
static

Definition at line 65 of file buf_mmap.c.

65  {
66  struct buf_mmap_priv *priv = get_priv_mmap(b);
67  if (size) {
68  *size = priv->mmap->len;
69  }
70  return priv->mmap->buf;
71 }
voidpf void uLong size
Definition: ioapi.h:138
ut8 * buf
Definition: rz_file.h:11
ut64 len
Definition: rz_file.h:13

References b, rz_mmap_t::buf, get_priv_mmap(), rz_mmap_t::len, and buf_mmap_priv::mmap.

◆ buf_mmap_init()

static bool buf_mmap_init ( RzBuffer b,
const void *  user 
)
static

Definition at line 25 of file buf_mmap.c.

25  {
26  const struct buf_mmap_user *u = (const struct buf_mmap_user *)user;
27  struct buf_mmap_priv *priv = RZ_NEW0(struct buf_mmap_priv);
28  if (!priv) {
29  return false;
30  }
31 
32  priv->mmap = rz_file_mmap(u->filename, u->perm, u->mode, 0);
33  if (!priv->mmap) {
34  free(priv);
35  return false;
36  }
37  priv->bytes_priv.buf = priv->mmap->buf;
38  priv->bytes_priv.length = priv->mmap->len;
39  priv->bytes_priv.offset = 0;
40  b->priv = priv;
41  b->fd = priv->mmap->fd;
42  return true;
43 }
RZ_API void Ht_() free(HtName_(Ht) *ht)
Definition: ht_inc.c:130
RZ_API RzMmap * rz_file_mmap(const char *file, int perm, int mode, ut64 base)
Definition: file.c:972
#define RZ_NEW0(x)
Definition: rz_types.h:284
struct buf_bytes_priv bytes_priv
Definition: buf_mmap.c:15
const char * filename
Definition: buf_mmap.c:7
int fd
Definition: rz_file.h:17

References b, rz_mmap_t::buf, buf_bytes_priv::buf, buf_mmap_priv::bytes_priv, rz_mmap_t::fd, buf_mmap_user::filename, free(), rz_mmap_t::len, buf_bytes_priv::length, buf_mmap_priv::mmap, buf_mmap_user::mode, buf_bytes_priv::offset, buf_mmap_user::perm, rz_file_mmap(), and RZ_NEW0.

◆ buf_mmap_resize()

static bool buf_mmap_resize ( RzBuffer b,
ut64  newsize 
)
static

Definition at line 52 of file buf_mmap.c.

52  {
53  struct buf_mmap_priv *priv = get_priv_mmap(b);
54  if (newsize > priv->mmap->len) {
55  ut8 *t = rz_file_mmap_resize(priv->mmap, newsize);
56  if (!t) {
57  return false;
58  }
59  priv->bytes_priv.buf = t;
60  }
61  priv->bytes_priv.length = newsize;
62  return true;
63 }
uint8_t ut8
Definition: lh5801.h:11
RZ_API void * rz_file_mmap_resize(RzMmap *m, ut64 newsize)
Definition: file.c:1017

References b, buf_bytes_priv::buf, buf_mmap_priv::bytes_priv, get_priv_mmap(), rz_mmap_t::len, buf_bytes_priv::length, buf_mmap_priv::mmap, and rz_file_mmap_resize().

◆ get_priv_mmap()

static struct buf_mmap_priv* get_priv_mmap ( RzBuffer b)
inlinestatic

Definition at line 19 of file buf_mmap.c.

19  {
20  struct buf_mmap_priv *priv = (struct buf_mmap_priv *)b->priv;
21  rz_warn_if_fail(priv);
22  return priv;
23 }
#define rz_warn_if_fail(expr)
Definition: rz_assert.h:35

References b, and rz_warn_if_fail.

Referenced by buf_mmap_fini(), buf_mmap_get_whole_buf(), and buf_mmap_resize().

Variable Documentation

◆ buffer_mmap_methods

const RzBufferMethods buffer_mmap_methods
static
Initial value:
= {
.init = buf_mmap_init,
.fini = buf_mmap_fini,
.read = buf_bytes_read,
.write = buf_bytes_write,
.get_size = buf_bytes_get_size,
.resize = buf_mmap_resize,
.seek = buf_bytes_seek,
.get_whole_buf = buf_mmap_get_whole_buf
}
static st64 buf_bytes_read(RzBuffer *b, ut8 *buf, ut64 len)
Definition: buf_bytes.c:76
static ut64 buf_bytes_get_size(RzBuffer *b)
Definition: buf_bytes.c:97
static st64 buf_bytes_seek(RzBuffer *b, st64 addr, int whence)
Definition: buf_bytes.c:102
static st64 buf_bytes_write(RzBuffer *b, const ut8 *buf, ut64 len)
Definition: buf_bytes.c:84
static bool buf_mmap_init(RzBuffer *b, const void *user)
Definition: buf_mmap.c:25
static bool buf_mmap_resize(RzBuffer *b, ut64 newsize)
Definition: buf_mmap.c:52
static ut8 * buf_mmap_get_whole_buf(RzBuffer *b, ut64 *size)
Definition: buf_mmap.c:65
static bool buf_mmap_fini(RzBuffer *b)
Definition: buf_mmap.c:45

Definition at line 73 of file buf_mmap.c.

Referenced by new_buffer().