Rizin
unix-like reverse engineering framework and cli tools
transport.c File Reference
#include <rz_th.h>
#include "transport.h"

Go to the source code of this file.

Functions

io_desc_tio_desc_new (io_backend_t *iob, void *fp)
 
int iob_write (io_desc_t *desc, const uint8_t *buf, const uint32_t buf_len)
 
int iob_read (io_desc_t *desc, uint8_t *buf, const uint32_t buf_len)
 

Function Documentation

◆ io_desc_new()

io_desc_t* io_desc_new ( io_backend_t iob,
void *  fp 
)

Definition at line 7 of file transport.c.

7  {
9  if (desc) {
10  desc->iob = iob;
11  desc->fp = fp;
12  }
13  return desc;
14 }
const char * desc
Definition: bin_vsf.c:19
#define RZ_NEW0(x)
Definition: rz_types.h:284

References desc, and RZ_NEW0.

Referenced by __open().

◆ iob_read()

int iob_read ( io_desc_t desc,
uint8_t buf,
const uint32_t  buf_len 
)

Definition at line 37 of file transport.c.

37  {
38  uint32_t done;
39  static RzThreadLock *lock = NULL;
40  if (!lock) {
41  lock = rz_th_lock_new(true);
42  }
43  if (!desc || !desc->iob || !desc->fp) {
44  return E_NOIF;
45  }
47  for (done = 0; done < buf_len;) {
48  int ret = desc->iob->read(desc->fp, buf + done, buf_len - done, 100);
49  if (ret < 0) {
50  break;
51  }
52  done += ret;
53  }
55  return done;
56 }
static int buf_len
Definition: asm_arc.c:22
#define NULL
Definition: cris-opc.c:27
struct tab * done
Definition: enough.c:233
voidpf void * buf
Definition: ioapi.h:138
unsigned int uint32_t
Definition: sftypes.h:29
RZ_API void rz_th_lock_leave(RZ_NONNULL RzThreadLock *thl)
Releases a RzThreadLock structure.
Definition: thread_lock.c:75
RZ_API RZ_OWN RzThreadLock * rz_th_lock_new(bool recursive)
Allocates and initialize a RzThreadLock structure.
Definition: thread_lock.c:14
RZ_API void rz_th_lock_enter(RZ_NONNULL RzThreadLock *thl)
Acquires a RzThreadLock structure.
Definition: thread_lock.c:45
@ E_NOIF
Definition: transport.h:24
static void lock(volatile int *lk)
Definition: malloc.c:61

References buf_len, desc, done, E_NOIF, lock(), NULL, rz_th_lock_enter(), rz_th_lock_leave(), and rz_th_lock_new().

Referenced by kd_read_packet().

◆ iob_write()

int iob_write ( io_desc_t desc,
const uint8_t buf,
const uint32_t  buf_len 
)

Definition at line 16 of file transport.c.

16  {
17  uint32_t done;
18  static RzThreadLock *lock = NULL;
19  if (!lock) {
20  lock = rz_th_lock_new(true);
21  }
22  if (!desc || !desc->iob || !desc->fp) {
23  return E_NOIF;
24  }
26  for (done = 0; done < buf_len;) {
27  int ret = desc->iob->write(desc->fp, buf + done, buf_len - done, 100);
28  if (ret < 1) {
29  break;
30  }
31  done += ret;
32  }
34  return done;
35 }

References buf_len, desc, done, E_NOIF, lock(), NULL, rz_th_lock_enter(), rz_th_lock_leave(), and rz_th_lock_new().

Referenced by kd_send_ctrl_packet(), kd_send_data_packet(), winkd_break(), and winkd_sync().