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

Go to the source code of this file.

Macros

#define I386_NUM_GREGS   16
 
#define I386_NUM_FREGS   16
 
#define I386_NUM_XREGS   9
 
#define NUM_GPREGS   13
 
#define I386_SSE_NUM_REGS   (I386_NUM_GREGS + I386_NUM_FREGS + I386_NUM_XREGS)
 
#define I387_NUM_XMM_REGS   8
 
#define I387_ST0_REGNUM   I386_ST0_REGNUM
 
#define I387_FCTRL_REGNUM   (I387_ST0_REGNUM + 8)
 
#define I387_FSTAT_REGNUM   (I387_FCTRL_REGNUM + 1)
 
#define I387_FTAG_REGNUM   (I387_FCTRL_REGNUM + 2)
 
#define I387_FISEG_REGNUM   (I387_FCTRL_REGNUM + 3)
 
#define I387_FIOFF_REGNUM   (I387_FCTRL_REGNUM + 4)
 
#define I387_FOSEG_REGNUM   (I387_FCTRL_REGNUM + 5)
 
#define I387_FOOFF_REGNUM   (I387_FCTRL_REGNUM + 6)
 
#define I387_FOP_REGNUM   (I387_FCTRL_REGNUM + 7)
 
#define I387_XMM0_REGNUM   (I387_ST0_REGNUM + 16)
 
#define I387_MXCSR_REGNUM   (I387_XMM0_REGNUM + I387_NUM_XMM_REGS)
 
#define NTO_ENAMETOOLONG   78
 
#define NTO_ELIBACC   83
 
#define NTO_ELIBBAD   84
 
#define NTO_ELIBSCN   85
 
#define NTO_ELIBMAX   86
 
#define NTO_ELIBEXEC   87
 
#define NTO_EILSEQ   88
 
#define NTO_ENOSYS   89
 

Enumerations

enum  {
  NTO_REG_GENERAL , NTO_REG_FLOAT , NTO_REG_SYSTEM , NTO_REG_ALT ,
  NTO_REG_END
}
 
enum  i386_regnum {
  I386_EAX_REGNUM , I386_ECX_REGNUM , I386_EDX_REGNUM , I386_EBX_REGNUM ,
  I386_ESP_REGNUM , I386_EBP_REGNUM , I386_ESI_REGNUM , I386_EDI_REGNUM ,
  I386_EIP_REGNUM , I386_EFLAGS_REGNUM , I386_CS_REGNUM , I386_SS_REGNUM ,
  I386_DS_REGNUM , I386_ES_REGNUM , I386_FS_REGNUM , I386_GS_REGNUM ,
  I386_ST0_REGNUM
}
 

Functions

int errnoconvert (int x)
 
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, ut32 *off)
 
ptid_t ptid_build (st32 pid, st64 tid)
 
int ptid_equal (ptid_t ptid1, ptid_t ptid2)
 

Variables

static int i386nto_gregset_reg_offset []
 

Macro Definition Documentation

◆ I386_NUM_FREGS

#define I386_NUM_FREGS   16

Definition at line 10 of file utils.c.

◆ I386_NUM_GREGS

#define I386_NUM_GREGS   16

Definition at line 9 of file utils.c.

◆ I386_NUM_XREGS

#define I386_NUM_XREGS   9

Definition at line 11 of file utils.c.

◆ I386_SSE_NUM_REGS

#define I386_SSE_NUM_REGS   (I386_NUM_GREGS + I386_NUM_FREGS + I386_NUM_XREGS)

Definition at line 15 of file utils.c.

◆ I387_FCTRL_REGNUM

#define I387_FCTRL_REGNUM   (I387_ST0_REGNUM + 8)

Definition at line 19 of file utils.c.

◆ I387_FIOFF_REGNUM

#define I387_FIOFF_REGNUM   (I387_FCTRL_REGNUM + 4)

Definition at line 23 of file utils.c.

◆ I387_FISEG_REGNUM

#define I387_FISEG_REGNUM   (I387_FCTRL_REGNUM + 3)

Definition at line 22 of file utils.c.

◆ I387_FOOFF_REGNUM

#define I387_FOOFF_REGNUM   (I387_FCTRL_REGNUM + 6)

Definition at line 25 of file utils.c.

◆ I387_FOP_REGNUM

#define I387_FOP_REGNUM   (I387_FCTRL_REGNUM + 7)

Definition at line 26 of file utils.c.

◆ I387_FOSEG_REGNUM

#define I387_FOSEG_REGNUM   (I387_FCTRL_REGNUM + 5)

Definition at line 24 of file utils.c.

◆ I387_FSTAT_REGNUM

#define I387_FSTAT_REGNUM   (I387_FCTRL_REGNUM + 1)

Definition at line 20 of file utils.c.

◆ I387_FTAG_REGNUM

#define I387_FTAG_REGNUM   (I387_FCTRL_REGNUM + 2)

Definition at line 21 of file utils.c.

◆ I387_MXCSR_REGNUM

#define I387_MXCSR_REGNUM   (I387_XMM0_REGNUM + I387_NUM_XMM_REGS)

Definition at line 28 of file utils.c.

◆ I387_NUM_XMM_REGS

#define I387_NUM_XMM_REGS   8

Definition at line 17 of file utils.c.

◆ I387_ST0_REGNUM

#define I387_ST0_REGNUM   I386_ST0_REGNUM

Definition at line 18 of file utils.c.

◆ I387_XMM0_REGNUM

#define I387_XMM0_REGNUM   (I387_ST0_REGNUM + 16)

Definition at line 27 of file utils.c.

◆ NTO_EILSEQ

#define NTO_EILSEQ   88

Definition at line 84 of file utils.c.

◆ NTO_ELIBACC

#define NTO_ELIBACC   83

Definition at line 79 of file utils.c.

◆ NTO_ELIBBAD

#define NTO_ELIBBAD   84

Definition at line 80 of file utils.c.

◆ NTO_ELIBEXEC

#define NTO_ELIBEXEC   87

Definition at line 83 of file utils.c.

◆ NTO_ELIBMAX

#define NTO_ELIBMAX   86

Definition at line 82 of file utils.c.

◆ NTO_ELIBSCN

#define NTO_ELIBSCN   85

Definition at line 81 of file utils.c.

◆ NTO_ENAMETOOLONG

#define NTO_ENAMETOOLONG   78

Definition at line 78 of file utils.c.

◆ NTO_ENOSYS

#define NTO_ENOSYS   89

Definition at line 85 of file utils.c.

◆ NUM_GPREGS

#define NUM_GPREGS   13

Definition at line 13 of file utils.c.

Enumeration Type Documentation

◆ anonymous enum

anonymous enum
Enumerator
NTO_REG_GENERAL 
NTO_REG_FLOAT 
NTO_REG_SYSTEM 
NTO_REG_ALT 
NTO_REG_END 

Definition at line 31 of file utils.c.

31  {
37 };
@ NTO_REG_FLOAT
Definition: utils.c:33
@ NTO_REG_SYSTEM
Definition: utils.c:34
@ NTO_REG_ALT
Definition: utils.c:35
@ NTO_REG_GENERAL
Definition: utils.c:32
@ NTO_REG_END
Definition: utils.c:36

◆ i386_regnum

Enumerator
I386_EAX_REGNUM 
I386_ECX_REGNUM 
I386_EDX_REGNUM 
I386_EBX_REGNUM 
I386_ESP_REGNUM 
I386_EBP_REGNUM 
I386_ESI_REGNUM 
I386_EDI_REGNUM 
I386_EIP_REGNUM 
I386_EFLAGS_REGNUM 
I386_CS_REGNUM 
I386_SS_REGNUM 
I386_DS_REGNUM 
I386_ES_REGNUM 
I386_FS_REGNUM 
I386_GS_REGNUM 
I386_ST0_REGNUM 

Definition at line 39 of file utils.c.

39  {
40  I386_EAX_REGNUM, /* %eax */
41  I386_ECX_REGNUM, /* %ecx */
42  I386_EDX_REGNUM, /* %edx */
43  I386_EBX_REGNUM, /* %ebx */
44  I386_ESP_REGNUM, /* %esp */
45  I386_EBP_REGNUM, /* %ebp */
46  I386_ESI_REGNUM, /* %esi */
47  I386_EDI_REGNUM, /* %edi */
48  I386_EIP_REGNUM, /* %eip */
49  I386_EFLAGS_REGNUM, /* %eflags */
50  I386_CS_REGNUM, /* %cs */
51  I386_SS_REGNUM, /* %ss */
52  I386_DS_REGNUM, /* %ds */
53  I386_ES_REGNUM, /* %es */
54  I386_FS_REGNUM, /* %fs */
55  I386_GS_REGNUM, /* %gs */
56  I386_ST0_REGNUM /* %st(0) */
57 };
@ I386_EFLAGS_REGNUM
Definition: utils.c:49
@ I386_ESI_REGNUM
Definition: utils.c:46
@ I386_ST0_REGNUM
Definition: utils.c:56
@ I386_FS_REGNUM
Definition: utils.c:54
@ I386_ECX_REGNUM
Definition: utils.c:41
@ I386_GS_REGNUM
Definition: utils.c:55
@ I386_EIP_REGNUM
Definition: utils.c:48
@ I386_EBP_REGNUM
Definition: utils.c:45
@ I386_ES_REGNUM
Definition: utils.c:53
@ I386_CS_REGNUM
Definition: utils.c:50
@ I386_EAX_REGNUM
Definition: utils.c:40
@ I386_SS_REGNUM
Definition: utils.c:51
@ I386_EDX_REGNUM
Definition: utils.c:42
@ I386_ESP_REGNUM
Definition: utils.c:44
@ I386_EBX_REGNUM
Definition: utils.c:43
@ I386_DS_REGNUM
Definition: utils.c:52
@ I386_EDI_REGNUM
Definition: utils.c:47

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,
ut32 off 
)

Definition at line 211 of file utils.c.

211  {
212  *off = 0;
213  if (regset == NTO_REG_GENERAL) {
214  if (regno == -1)
215  return NUM_GPREGS * 4;
216 
217  *off = i386nto_reg_offset(regno);
218  if (*off == -1)
219  return 0;
220  return 4;
221  } else if (regset == NTO_REG_FLOAT) {
222  ut32 off_adjust, regsize, regset_size, regno_base;
223  /* The following are flags indicating number in our fxsave_area. */
224  int first_four = (regno >= I387_FCTRL_REGNUM && regno <= I387_FISEG_REGNUM);
225  int second_four = (regno > I387_FISEG_REGNUM && regno <= I387_FOP_REGNUM);
226  int st_reg = (regno >= I387_ST0_REGNUM && regno < I387_ST0_REGNUM + 8);
227  int xmm_reg = (regno >= I387_XMM0_REGNUM && regno < I387_MXCSR_REGNUM);
228 #if 0
229  if (nto_cpuinfo_valid && nto_cpuinfo_flags | X86_CPU_FXSR)
230  {
231 #endif
232  regset_size = 512;
233  /* fxsave_area structure. */
234  if (first_four) {
235  /* fpu_control_word, fpu_status_word, fpu_tag_word, fpu_operand
236 registers. */
237  regsize = 2; /* Two bytes each. */
238  off_adjust = 0;
239  regno_base = I387_FCTRL_REGNUM;
240  } else if (second_four) {
241  /* fpu_ip, fpu_cs, fpu_op, fpu_ds registers. */
242  regsize = 4;
243  off_adjust = 8;
244  regno_base = I387_FISEG_REGNUM + 1;
245  } else if (st_reg) {
246  /* ST registers. */
247  regsize = 16;
248  off_adjust = 32;
249  regno_base = I387_ST0_REGNUM;
250  } else if (xmm_reg) {
251  /* XMM registers. */
252  regsize = 16;
253  off_adjust = 160;
254  regno_base = I387_XMM0_REGNUM;
255  } else if (regno == I387_MXCSR_REGNUM) {
256  regsize = 4;
257  off_adjust = 24;
258  regno_base = I387_MXCSR_REGNUM;
259  } else {
260  /* Whole regset. */
261  off_adjust = 0;
262  regno_base = 0;
263  regsize = regset_size;
264  }
265 #if 0
266  }
267  else
268  {
269  regset_size = 108;
270  /* fsave_area structure. */
271  if (first_four || second_four)
272  {
273  /* fpu_control_word, ... , fpu_ds registers. */
274  regsize = 4;
275  off_adjust = 0;
276  regno_base = I387_FCTRL_REGNUM;
277  }
278  else if (st_reg)
279  {
280  /* One of ST registers. */
281  regsize = 10;
282  off_adjust = 7 * 4;
283  regno_base = I387_ST0_REGNUM;
284  }
285  else
286  {
287  /* Whole regset. */
288  off_adjust = 0;
289  regno_base = 0;
290  regsize = regset_size;
291  }
292  }
293 #endif
294 
295  *off = (regno != -1) ? off_adjust + (regno - regno_base) * regsize : 0;
296  return regsize;
297  }
298  return -1;
299 }
uint32_t ut32
int off
Definition: pal.c:13
#define I387_FISEG_REGNUM
Definition: utils.c:22
#define I387_XMM0_REGNUM
Definition: utils.c:27
int i386nto_reg_offset(int regnum)
Definition: utils.c:204
#define NUM_GPREGS
Definition: utils.c:13
#define I387_FCTRL_REGNUM
Definition: utils.c:19
#define I387_MXCSR_REGNUM
Definition: utils.c:28
#define I387_ST0_REGNUM
Definition: utils.c:18
#define I387_FOP_REGNUM
Definition: utils.c:26

References i386nto_reg_offset(), I387_FCTRL_REGNUM, I387_FISEG_REGNUM, I387_FOP_REGNUM, I387_MXCSR_REGNUM, I387_ST0_REGNUM, I387_XMM0_REGNUM, NTO_REG_FLOAT, NTO_REG_GENERAL, NUM_GPREGS, and 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

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

◆ ptid_equal()

int ptid_equal ( ptid_t  ptid1,
ptid_t  ptid2 
)

Definition at line 309 of file utils.c.

309  {
310  return ptid1.pid == ptid2.pid && ptid1.tid == ptid2.tid;
311 }

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

Referenced by rz_debug_qnx_wait().

Variable Documentation

◆ i386nto_gregset_reg_offset

int i386nto_gregset_reg_offset[]
static
Initial value:
= {
7 * 4,
6 * 4,
5 * 4,
4 * 4,
11 * 4,
2 * 4,
1 * 4,
0 * 4,
8 * 4,
10 * 4,
9 * 4,
12 * 4,
-1
}

Definition at line 59 of file utils.c.

Referenced by i386nto_reg_offset().