Rizin
unix-like reverse engineering framework and cli tools
utils.h File Reference
#include <stdint.h>
#include <stdio.h>
#include "libqnxr.h"
#include "gdb_signals.h"

Go to the source code of this file.

Macros

#define LONGEST   st64
 
#define ULONGEST   ut64
 
#define ARRAY_SIZE(a)   (sizeof(a) / sizeof((a)[0]))
 
#define EXTRACT_SIGNED_INTEGER(addr, len)    extract_signed_integer((const ut8 *)addr, len, 0)
 
#define EXTRACT_UNSIGNED_INTEGER(addr, len)    extract_unsigned_integer((const ut8 *)addr, len, 0)
 

Functions

int errnoconvert (int x)
 
enum target_signal target_signal_from_nto (int sig)
 
LONGEST extract_signed_integer (const ut8 *addr, int len, int be)
 
ULONGEST extract_unsigned_integer (const ut8 *addr, int len, int be)
 
int i386nto_regset_id (int regno)
 
int i386nto_reg_offset (int regnum)
 
int i386nto_register_area (int regno, int regset, unsigned *off)
 
ptid_t ptid_build (st32 pid, st64 tid)
 

Macro Definition Documentation

◆ ARRAY_SIZE

#define ARRAY_SIZE (   a)    (sizeof(a) / sizeof((a)[0]))

Definition at line 17 of file utils.h.

◆ EXTRACT_SIGNED_INTEGER

#define EXTRACT_SIGNED_INTEGER (   addr,
  len 
)     extract_signed_integer((const ut8 *)addr, len, 0)

Definition at line 20 of file utils.h.

◆ EXTRACT_UNSIGNED_INTEGER

#define EXTRACT_UNSIGNED_INTEGER (   addr,
  len 
)     extract_unsigned_integer((const ut8 *)addr, len, 0)

Definition at line 22 of file utils.h.

◆ LONGEST

#define LONGEST   st64

Definition at line 13 of file utils.h.

◆ ULONGEST

#define ULONGEST   ut64

Definition at line 14 of file utils.h.

Function Documentation

◆ errnoconvert()

int errnoconvert ( int  x)

Definition at line 131 of file utils.c.

131  {
132  return x;
133 }
int x
Definition: mipsasm.c:20

References x.

Referenced by nto_send().

◆ extract_signed_integer()

LONGEST extract_signed_integer ( const ut8 addr,
int  len,
int  be 
)

Definition at line 137 of file utils.c.

137  {
138  LONGEST retval;
139  const ut8 *p;
140  const ut8 *startaddr = addr;
141  const ut8 *endaddr = startaddr + len;
142 
143  if (len > (int)sizeof(LONGEST))
144  eprintf(
145  "This operation is not available on integers of more than %d byte(s)\n",
146  (int)sizeof(LONGEST));
147 
148  /* Start at the most significant end of the integer, and work towards
149  the least significant. */
150  if (be) {
151  p = startaddr;
152  /* Do the sign extension once at the start. */
153  retval = ((LONGEST)*p ^ 0x80) - 0x80;
154  for (++p; p < endaddr; p++)
155  retval = (retval << 8) | *p;
156  } else {
157  p = endaddr - 1;
158  /* Do the sign extension once at the start. */
159  retval = ((LONGEST)*p ^ 0x80) - 0x80;
160  for (--p; p >= startaddr; --p)
161  retval = (retval << 8) | *p;
162  }
163  return retval;
164 }
size_t len
Definition: 6502dis.c:15
uint8_t ut8
Definition: lh5801.h:11
void * p
Definition: libc.cpp:67
#define eprintf(x, y...)
Definition: rlcc.c:7
#define LONGEST
Definition: utils.h:13
static int addr
Definition: z80asm.c:58

References addr, eprintf, len, LONGEST, and p.

◆ extract_unsigned_integer()

ULONGEST extract_unsigned_integer ( const ut8 addr,
int  len,
int  be 
)

Definition at line 167 of file utils.c.

167  {
168  ULONGEST retval;
169  const ut8 *p;
170  const ut8 *startaddr = addr;
171  const ut8 *endaddr = startaddr + len;
172 
173  if (len > (int)sizeof(LONGEST))
174  eprintf(
175  "This operation is not available on integers of more than %d byte(s)\n",
176  (int)sizeof(LONGEST));
177 
178  /* Start at the most significant end of the integer, and work towards
179  the least significant. */
180  retval = 0;
181  if (be) {
182  for (p = startaddr; p < endaddr; ++p)
183  retval = (retval << 8) | *p;
184  } else {
185  for (p = endaddr - 1; p >= startaddr; --p)
186  retval = (retval << 8) | *p;
187  }
188  return retval;
189 }
#define ULONGEST
Definition: utils.h:14

References addr, eprintf, len, LONGEST, p, and ULONGEST.

◆ i386nto_reg_offset()

int i386nto_reg_offset ( int  regnum)

Definition at line 204 of file utils.c.

204  {
205  if (regnum >= 0 && regnum < ARRAY_SIZE(i386nto_gregset_reg_offset))
206  return i386nto_gregset_reg_offset[regnum];
207 
208  return -1;
209 }
#define ARRAY_SIZE(a)
static int i386nto_gregset_reg_offset[]
Definition: utils.c:59

References ARRAY_SIZE, and i386nto_gregset_reg_offset.

Referenced by i386nto_register_area().

◆ i386nto_register_area()

int i386nto_register_area ( int  regno,
int  regset,
unsigned off 
)

◆ i386nto_regset_id()

int i386nto_regset_id ( int  regno)

Definition at line 191 of file utils.c.

191  {
192  if (regno == -1)
193  return NTO_REG_END;
194  if (regno < I386_NUM_GREGS)
195  return NTO_REG_GENERAL;
196  if (regno < I386_NUM_GREGS + I386_NUM_FREGS)
197  return NTO_REG_FLOAT;
198  if (regno < I386_SSE_NUM_REGS)
199  return NTO_REG_FLOAT; /* We store xmm registers in fxsave_area. */
200 
201  return -1;
202 }
#define I386_NUM_FREGS
Definition: utils.c:10
#define I386_SSE_NUM_REGS
Definition: utils.c:15
#define I386_NUM_GREGS
Definition: utils.c:9
@ NTO_REG_FLOAT
Definition: utils.c:33
@ NTO_REG_GENERAL
Definition: utils.c:32
@ NTO_REG_END
Definition: utils.c:36

References I386_NUM_FREGS, I386_NUM_GREGS, I386_SSE_NUM_REGS, NTO_REG_END, NTO_REG_FLOAT, and NTO_REG_GENERAL.

Referenced by qnxr_read_registers(), and qnxr_write_register().

◆ ptid_build()

ptid_t ptid_build ( st32  pid,
st64  tid 
)

Definition at line 301 of file utils.c.

301  {
302  ptid_t ptid;
303  ptid.pid = pid;
304  ptid.tid = tid;
305 
306  return ptid;
307 }
static static fork const void static count static fd const char const char static newpath char char char static envp time_t static t const char static mode static whence const char static dir time_t static t unsigned static seconds const char struct utimbuf static buf static inc pid
Definition: sflib.h:64
Definition: libqnxr.h:30
st32 pid
Definition: libqnxr.h:31
st64 tid
Definition: libqnxr.h:32

References pid, ptid_t::pid, and ptid_t::tid.

Referenced by nto_parse_notify(), and qnxr_attach().

◆ target_signal_from_nto()

enum target_signal target_signal_from_nto ( int  sig)

Definition at line 585 of file sigutil.c.

596  {
597  int i;
598  if (sig == 0)
599  return 0;
600 
601  for (i = 0; i != ARRAY_SIZE(sig_map); i++) {
602  if (sig_map[i].nto_sig == sig)
603  return sig_map[i].gdb_sig;
604  }
605 
606  if (sig >= NTO_SIGRTMIN && sig <= NTO_SIGRTMAX)
608  return target_signal_from_host(sig);
609 }
lzma_index ** i
Definition: index.h:629
@ TARGET_SIGNAL_REALTIME_41
Definition: gdb_signals.h:112
#define NTO_SIGRTMAX
Definition: sigutil.c:45
enum target_signal target_signal_from_host(int hostsig)
Definition: sigutil.c:89
static struct @604 sig_map[]
int nto_sig
Definition: sigutil.c:51
#define NTO_SIGRTMIN
Definition: sigutil.c:44

References do_target_signal_to_host().