Rizin
unix-like reverse engineering framework and cli tools
transport.h File Reference
#include <rz_types.h>
#include <stdint.h>
#include <stdio.h>

Go to the source code of this file.

Classes

struct  io_backend_t
 
struct  io_desc_t
 

Macros

#define eprintf(...)    { fprintf(stderr, ##__VA_ARGS__); }
 
#define HAVE_EPRINTF   1
 
#define KD_IO_PIPE   0
 
#define KD_IO_NET   1
 

Typedefs

typedef struct io_backend_t io_backend_t
 
typedef struct io_desc_t io_desc_t
 

Enumerations

enum  { E_OK = 0 , E_TIMEOUT = -1 , E_ERROR = -2 , E_NOIF = -3 }
 

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)
 

Variables

io_backend_t iob_pipe
 
io_backend_t iob_net
 

Macro Definition Documentation

◆ eprintf

#define eprintf (   ...)     { fprintf(stderr, ##__VA_ARGS__); }

Definition at line 12 of file transport.h.

◆ HAVE_EPRINTF

#define HAVE_EPRINTF   1

Definition at line 14 of file transport.h.

◆ KD_IO_NET

#define KD_IO_NET   1

Definition at line 18 of file transport.h.

◆ KD_IO_PIPE

#define KD_IO_PIPE   0

Definition at line 17 of file transport.h.

Typedef Documentation

◆ io_backend_t

typedef struct io_backend_t io_backend_t

◆ io_desc_t

typedef struct io_desc_t io_desc_t

Enumeration Type Documentation

◆ anonymous enum

anonymous enum
Enumerator
E_OK 
E_TIMEOUT 
E_ERROR 
E_NOIF 

Definition at line 20 of file transport.h.

20  {
21  E_OK = 0,
22  E_TIMEOUT = -1,
23  E_ERROR = -2,
24  E_NOIF = -3,
25 };
@ E_TIMEOUT
Definition: transport.h:22
@ E_NOIF
Definition: transport.h:24
@ E_ERROR
Definition: transport.h:23
@ E_OK
Definition: transport.h:21

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

Variable Documentation

◆ iob_net

io_backend_t iob_net
extern

Definition at line 564 of file iob_net.c.

Referenced by __open().

◆ iob_pipe

io_backend_t iob_pipe
extern

Definition at line 130 of file iob_pipe.c.

Referenced by __open().