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

Go to the source code of this file.

Classes

struct  kd_ioc_t
 

Macros

#define KD_PACKET_UNUSED   0x00000000
 
#define KD_PACKET_DATA   0x30303030
 
#define KD_PACKET_CTRL   0x69696969
 
#define KD_INITIAL_PACKET_ID   0x80800000
 
#define KD_MAX_PAYLOAD   0x480
 
#define KD_PACKET_MAX_SIZE   4000
 
#define KD_RET_OK   0x00000000
 
#define KD_RET_ERR   0xC0000001
 
#define KD_RET_ENOENT   0xC000000F
 
#define KD_MACH_I386   0x014C
 
#define KD_MACH_IA64   0x0200
 
#define KD_MACH_AMD64   0x8664
 
#define KD_MACH_ARM   0x01c0
 
#define KD_MACH_EBC   0x0EBC
 
#define DBGKD_VERS_FLAG_DATA   0x0002
 
#define DBGKD_VERS_FLAG_PTR64   0x0004
 
#define KD_EXC_BKPT   0x80000003
 
#define KDNET_MAGIC   0x4d444247
 
#define KDNET_HMACKEY_SIZE   32
 
#define KDNET_HMAC_SIZE   16
 
#define KDNET_PACKET_TYPE_DATA   0
 
#define KDNET_PACKET_TYPE_CONTROL   1
 
#define KDNET_DATA_SIZE   8
 
#define KDNET_DATA_DIRECTION_MASK   0x80
 
#define KDNET_DATA_PADSIZE_MASK   0x7F
 
#define KDNET_DATA_SEQNO_MASK   0xFFFFFF00
 
#define ASSERT_CONCAT_(a, b)   a##b
 
#define ASSERT_CONCAT(a, b)   ASSERT_CONCAT_(a, b)
 
#define ct_assert(e)   enum { ASSERT_CONCAT(assert_line_, __LINE__) = 1 / (!!(e)) }
 

Typedefs

typedef struct kd_ioc_t kd_ioc_t
 

Enumerations

enum  {
  KD_E_OK = 0 , KD_E_BADCHKSUM = -1 , KD_E_TIMEOUT = -2 , KD_E_MALFORMED = -3 ,
  KD_E_IOERR = -4 , KD_E_BREAK = -5
}
 
enum  KD_PACKET_TYPE {
  KD_PACKET_TYPE_UNUSED = 0 , KD_PACKET_TYPE_STATE_CHANGE32 = 1 , KD_PACKET_TYPE_STATE_MANIPULATE = 2 , KD_PACKET_TYPE_DEBUG_IO = 3 ,
  KD_PACKET_TYPE_ACKNOWLEDGE = 4 , KD_PACKET_TYPE_RESEND = 5 , KD_PACKET_TYPE_RESET = 6 , KD_PACKET_TYPE_STATE_CHANGE64 = 7 ,
  KD_PACKET_TYPE_POLL_BREAKIN = 8 , KD_PACKET_TYPE_TRACE_IO = 9 , KD_PACKET_TYPE_CONTROL_REQUEST = 10 , KD_PACKET_TYPE_FILE_IO = 11
}
 
enum  KD_PACKET_WAIT_STATE_CHANGE {
  DbgKdMinimumStateChange = 0x00003030 , DbgKdExceptionStateChange = 0x00003030 , DbgKdLoadSymbolsStateChange = 0x00003031 , DbgKdCommandStringStateChange = 0x00003032 ,
  DbgKdMaximumStateChange = 0x00003033
}
 
enum  KD_PACKET_MANIPULATE_TYPE {
  DbgKdMinimumManipulate = 0x00003130 , DbgKdReadVirtualMemoryApi = 0x00003130 , DbgKdWriteVirtualMemoryApi = 0x00003131 , DbgKdGetContextApi = 0x00003132 ,
  DbgKdSetContextApi = 0x00003133 , DbgKdWriteBreakPointApi = 0x00003134 , DbgKdRestoreBreakPointApi = 0x00003135 , DbgKdContinueApi = 0x00003136 ,
  DbgKdReadControlSpaceApi = 0x00003137 , DbgKdWriteControlSpaceApi = 0x00003138 , DbgKdReadIoSpaceApi = 0x00003139 , DbgKdWriteIoSpaceApi = 0x0000313A ,
  DbgKdRebootApi = 0x0000313B , DbgKdContinueApi2 = 0x0000313C , DbgKdReadPhysicalMemoryApi = 0x0000313D , DbgKdWritePhysicalMemoryApi = 0x0000313E ,
  DbgKdQuerySpecialCallsApi = 0x0000313F , DbgKdSetSpecialCallApi = 0x00003140 , DbgKdClearSpecialCallsApi = 0x00003141 , DbgKdSetInternalBreakPointApi = 0x00003142 ,
  DbgKdGetInternalBreakPointApi = 0x00003143 , DbgKdReadIoSpaceExtendedApi = 0x00003144 , DbgKdWriteIoSpaceExtendedApi = 0x00003145 , DbgKdGetVersionApi = 0x00003146 ,
  DbgKdWriteBreakPointExApi = 0x00003147 , DbgKdRestoreBreakPointExApi = 0x00003148 , DbgKdCauseBugCheckApi = 0x00003149 , DbgKdSwitchProcessor = 0x00003150 ,
  DbgKdPageInApi = 0x00003151 , DbgKdReadMachineSpecificRegister = 0x00003152 , DbgKdWriteMachineSpecificRegister = 0x00003153 , OldVlm1 = 0x00003154 ,
  OldVlm2 = 0x00003155 , DbgKdSearchMemoryApi = 0x00003156 , DbgKdGetBusDataApi = 0x00003157 , DbgKdSetBusDataApi = 0x00003158 ,
  DbgKdCheckLowMemoryApi = 0x00003159 , DbgKdClearAllInternalBreakpointsApi = 0x0000315A , DbgKdFillMemoryApi = 0x0000315B , DbgKdQueryMemoryApi = 0x0000315C ,
  DbgKdSwitchPartition = 0x0000315D , DbgKdWriteCustomBreakpointApi = 0x0000315E , DbgKdGetContextEx = 0x0000315F , DbgKdSetContextEx = 0x00003160 ,
  DbgKdMaximumManipulate = 0x00003161
}
 
enum  KD_PACKET_FILE_IO_TYPE { DbgKdCreateFileApi = 0x00003430 , DbgKdReadFileApi = 0x00003431 , DbgKdWriteFileApi = 0x00003432 , DbgKdCloseFileApi = 0x00003433 }
 

Functions

 RZ_PACKED (typedef struct kd_req_t { ut32 req;ut16 cpu_level;ut16 cpu;ut32 ret;ut32 pad;union { RZ_PACKED(struct { ut64 addr;ut32 length;ut32 read;}) rz_mem;RZ_PACKED(struct { ut16 major;ut16 minor;ut8 proto_major;ut8 proto_minor;ut16 flags;ut16 machine;ut8 misc[6];ut64 kernel_base;ut64 mod_addr;ut64 dbg_addr;}) rz_ver;struct { ut32 reason;ut32 tf;ut32 dr7;ut32 css;ut32 cse;} rz_cont;struct { ut64 addr;ut32 handle;} rz_set_bp;struct { ut32 handle;} rz_del_bp;struct { ut64 addr;ut32 flags;} rz_set_ibp;struct { ut64 addr;ut32 flags;ut32 calls;} rz_get_ibp;struct { ut32 flags;} rz_ctx;struct { ut32 offset;ut32 count;ut32 copied;} rz_ctx_ex;struct { ut64 addr;ut64 reserved;ut32 address_space;ut32 flags;} rz_query_mem;ut8 raw[40];};ut8 data[];}) kd_req_t
 
 RZ_PACKED (typedef struct kd_stc_64 { ut32 state;ut16 cpu_level;ut16 cpu;ut32 cpu_count;ut32 pad1;ut64 kthread;ut64 pc;union { RZ_PACKED(struct { ut32 code;ut32 flags;ut64 ex_record;ut64 ex_addr;}) exception;RZ_PACKED(struct { ut64 pathsize;ut64 base;ut64 pid;ut32 checksum;ut32 size;ut8 unload;}) load_symbols;};}) kd_stc_64
 
 RZ_PACKED (typedef struct kd_packet_t { ut32 leader;ut16 type;ut16 length;ut32 id;ut32 checksum;ut8 data[];}) kd_packet_t
 
 RZ_PACKED (typedef struct kdnet_packet_t { ut32 magic;ut8 version;ut8 type;}) kdnet_packet_t
 
 ct_assert (sizeof(kd_packet_t)==16)
 
 ct_assert (sizeof(kd_req_t)==56)
 
 ct_assert (sizeof(kd_ioc_t)==64)
 
int kd_send_ctrl_packet (io_desc_t *desc, const ut32 type, const ut32 id)
 
int kd_send_data_packet (io_desc_t *desc, const ut32 type, const ut32 id, const ut8 *req, const int req_len, const ut8 *buf, const ut32 buf_len)
 
int kd_read_packet (io_desc_t *desc, kd_packet_t **p)
 
bool kd_packet_is_valid (const kd_packet_t *p)
 
int kd_packet_is_ack (const kd_packet_t *p)
 
ut32 kd_data_checksum (const ut8 *buf, const ut64 buf_len)
 

Macro Definition Documentation

◆ ASSERT_CONCAT

#define ASSERT_CONCAT (   a,
  b 
)    ASSERT_CONCAT_(a, b)

Definition at line 270 of file kd.h.

◆ ASSERT_CONCAT_

#define ASSERT_CONCAT_ (   a,
  b 
)    a##b

Definition at line 269 of file kd.h.

◆ ct_assert

#define ct_assert (   e)    enum { ASSERT_CONCAT(assert_line_, __LINE__) = 1 / (!!(e)) }

Definition at line 271 of file kd.h.

◆ DBGKD_VERS_FLAG_DATA

#define DBGKD_VERS_FLAG_DATA   0x0002

Definition at line 116 of file kd.h.

◆ DBGKD_VERS_FLAG_PTR64

#define DBGKD_VERS_FLAG_PTR64   0x0004

Definition at line 117 of file kd.h.

◆ KD_EXC_BKPT

#define KD_EXC_BKPT   0x80000003

Definition at line 194 of file kd.h.

◆ KD_INITIAL_PACKET_ID

#define KD_INITIAL_PACKET_ID   0x80800000

Definition at line 100 of file kd.h.

◆ KD_MACH_AMD64

#define KD_MACH_AMD64   0x8664

Definition at line 112 of file kd.h.

◆ KD_MACH_ARM

#define KD_MACH_ARM   0x01c0

Definition at line 113 of file kd.h.

◆ KD_MACH_EBC

#define KD_MACH_EBC   0x0EBC

Definition at line 114 of file kd.h.

◆ KD_MACH_I386

#define KD_MACH_I386   0x014C

Definition at line 110 of file kd.h.

◆ KD_MACH_IA64

#define KD_MACH_IA64   0x0200

Definition at line 111 of file kd.h.

◆ KD_MAX_PAYLOAD

#define KD_MAX_PAYLOAD   0x480

Definition at line 102 of file kd.h.

◆ KD_PACKET_CTRL

#define KD_PACKET_CTRL   0x69696969

Definition at line 98 of file kd.h.

◆ KD_PACKET_DATA

#define KD_PACKET_DATA   0x30303030

Definition at line 97 of file kd.h.

◆ KD_PACKET_MAX_SIZE

#define KD_PACKET_MAX_SIZE   4000

Definition at line 103 of file kd.h.

◆ KD_PACKET_UNUSED

#define KD_PACKET_UNUSED   0x00000000

Definition at line 96 of file kd.h.

◆ KD_RET_ENOENT

#define KD_RET_ENOENT   0xC000000F

Definition at line 108 of file kd.h.

◆ KD_RET_ERR

#define KD_RET_ERR   0xC0000001

Definition at line 107 of file kd.h.

◆ KD_RET_OK

#define KD_RET_OK   0x00000000

Definition at line 106 of file kd.h.

◆ KDNET_DATA_DIRECTION_MASK

#define KDNET_DATA_DIRECTION_MASK   0x80

Definition at line 263 of file kd.h.

◆ KDNET_DATA_PADSIZE_MASK

#define KDNET_DATA_PADSIZE_MASK   0x7F

Definition at line 264 of file kd.h.

◆ KDNET_DATA_SEQNO_MASK

#define KDNET_DATA_SEQNO_MASK   0xFFFFFF00

Definition at line 265 of file kd.h.

◆ KDNET_DATA_SIZE

#define KDNET_DATA_SIZE   8

Definition at line 262 of file kd.h.

◆ KDNET_HMAC_SIZE

#define KDNET_HMAC_SIZE   16

Definition at line 248 of file kd.h.

◆ KDNET_HMACKEY_SIZE

#define KDNET_HMACKEY_SIZE   32

Definition at line 247 of file kd.h.

◆ KDNET_MAGIC

#define KDNET_MAGIC   0x4d444247

Definition at line 246 of file kd.h.

◆ KDNET_PACKET_TYPE_CONTROL

#define KDNET_PACKET_TYPE_CONTROL   1

Definition at line 251 of file kd.h.

◆ KDNET_PACKET_TYPE_DATA

#define KDNET_PACKET_TYPE_DATA   0

Definition at line 250 of file kd.h.

Typedef Documentation

◆ kd_ioc_t

typedef struct kd_ioc_t kd_ioc_t

Enumeration Type Documentation

◆ anonymous enum

anonymous enum
Enumerator
KD_E_OK 
KD_E_BADCHKSUM 
KD_E_TIMEOUT 
KD_E_MALFORMED 
KD_E_IOERR 
KD_E_BREAK 

Definition at line 9 of file kd.h.

9  {
10  KD_E_OK = 0,
11  KD_E_BADCHKSUM = -1,
12  KD_E_TIMEOUT = -2,
13  KD_E_MALFORMED = -3,
14  KD_E_IOERR = -4,
15  KD_E_BREAK = -5,
16 };
@ KD_E_BADCHKSUM
Definition: kd.h:11
@ KD_E_BREAK
Definition: kd.h:15
@ KD_E_IOERR
Definition: kd.h:14
@ KD_E_OK
Definition: kd.h:10
@ KD_E_MALFORMED
Definition: kd.h:13
@ KD_E_TIMEOUT
Definition: kd.h:12

◆ KD_PACKET_FILE_IO_TYPE

Enumerator
DbgKdCreateFileApi 
DbgKdReadFileApi 
DbgKdWriteFileApi 
DbgKdCloseFileApi 

Definition at line 89 of file kd.h.

89  {
90  DbgKdCreateFileApi = 0x00003430,
91  DbgKdReadFileApi = 0x00003431,
92  DbgKdWriteFileApi = 0x00003432,
93  DbgKdCloseFileApi = 0x00003433
94 };
@ DbgKdReadFileApi
Definition: kd.h:91
@ DbgKdCreateFileApi
Definition: kd.h:90
@ DbgKdCloseFileApi
Definition: kd.h:93
@ DbgKdWriteFileApi
Definition: kd.h:92

◆ KD_PACKET_MANIPULATE_TYPE

Enumerator
DbgKdMinimumManipulate 
DbgKdReadVirtualMemoryApi 
DbgKdWriteVirtualMemoryApi 
DbgKdGetContextApi 
DbgKdSetContextApi 
DbgKdWriteBreakPointApi 
DbgKdRestoreBreakPointApi 
DbgKdContinueApi 
DbgKdReadControlSpaceApi 
DbgKdWriteControlSpaceApi 
DbgKdReadIoSpaceApi 
DbgKdWriteIoSpaceApi 
DbgKdRebootApi 
DbgKdContinueApi2 
DbgKdReadPhysicalMemoryApi 
DbgKdWritePhysicalMemoryApi 
DbgKdQuerySpecialCallsApi 
DbgKdSetSpecialCallApi 
DbgKdClearSpecialCallsApi 
DbgKdSetInternalBreakPointApi 
DbgKdGetInternalBreakPointApi 
DbgKdReadIoSpaceExtendedApi 
DbgKdWriteIoSpaceExtendedApi 
DbgKdGetVersionApi 
DbgKdWriteBreakPointExApi 
DbgKdRestoreBreakPointExApi 
DbgKdCauseBugCheckApi 
DbgKdSwitchProcessor 
DbgKdPageInApi 
DbgKdReadMachineSpecificRegister 
DbgKdWriteMachineSpecificRegister 
OldVlm1 
OldVlm2 
DbgKdSearchMemoryApi 
DbgKdGetBusDataApi 
DbgKdSetBusDataApi 
DbgKdCheckLowMemoryApi 
DbgKdClearAllInternalBreakpointsApi 
DbgKdFillMemoryApi 
DbgKdQueryMemoryApi 
DbgKdSwitchPartition 
DbgKdWriteCustomBreakpointApi 
DbgKdGetContextEx 
DbgKdSetContextEx 
DbgKdMaximumManipulate 

Definition at line 41 of file kd.h.

41  {
42  DbgKdMinimumManipulate = 0x00003130,
43  DbgKdReadVirtualMemoryApi = 0x00003130,
44  DbgKdWriteVirtualMemoryApi = 0x00003131,
45  DbgKdGetContextApi = 0x00003132,
46  DbgKdSetContextApi = 0x00003133,
47  DbgKdWriteBreakPointApi = 0x00003134,
48  DbgKdRestoreBreakPointApi = 0x00003135,
49  DbgKdContinueApi = 0x00003136,
50  DbgKdReadControlSpaceApi = 0x00003137,
51  DbgKdWriteControlSpaceApi = 0x00003138,
52  DbgKdReadIoSpaceApi = 0x00003139,
53  DbgKdWriteIoSpaceApi = 0x0000313A,
54  DbgKdRebootApi = 0x0000313B,
55  DbgKdContinueApi2 = 0x0000313C,
56  DbgKdReadPhysicalMemoryApi = 0x0000313D,
57  DbgKdWritePhysicalMemoryApi = 0x0000313E,
58  DbgKdQuerySpecialCallsApi = 0x0000313F,
59  DbgKdSetSpecialCallApi = 0x00003140,
60  DbgKdClearSpecialCallsApi = 0x00003141,
61  DbgKdSetInternalBreakPointApi = 0x00003142,
62  DbgKdGetInternalBreakPointApi = 0x00003143,
63  DbgKdReadIoSpaceExtendedApi = 0x00003144,
64  DbgKdWriteIoSpaceExtendedApi = 0x00003145,
65  DbgKdGetVersionApi = 0x00003146,
66  DbgKdWriteBreakPointExApi = 0x00003147,
67  DbgKdRestoreBreakPointExApi = 0x00003148,
68  DbgKdCauseBugCheckApi = 0x00003149,
69  DbgKdSwitchProcessor = 0x00003150,
70  DbgKdPageInApi = 0x00003151,
73  OldVlm1 = 0x00003154,
74  OldVlm2 = 0x00003155,
75  DbgKdSearchMemoryApi = 0x00003156,
76  DbgKdGetBusDataApi = 0x00003157,
77  DbgKdSetBusDataApi = 0x00003158,
78  DbgKdCheckLowMemoryApi = 0x00003159,
80  DbgKdFillMemoryApi = 0x0000315B,
81  DbgKdQueryMemoryApi = 0x0000315C,
82  DbgKdSwitchPartition = 0x0000315D,
83  DbgKdWriteCustomBreakpointApi = 0x0000315E,
84  DbgKdGetContextEx = 0x0000315F,
85  DbgKdSetContextEx = 0x00003160,
86  DbgKdMaximumManipulate = 0x00003161
87 };
@ DbgKdContinueApi
Definition: kd.h:49
@ DbgKdCauseBugCheckApi
Definition: kd.h:68
@ DbgKdWritePhysicalMemoryApi
Definition: kd.h:57
@ DbgKdMinimumManipulate
Definition: kd.h:42
@ DbgKdGetVersionApi
Definition: kd.h:65
@ DbgKdRestoreBreakPointExApi
Definition: kd.h:67
@ DbgKdWriteVirtualMemoryApi
Definition: kd.h:44
@ DbgKdSetContextEx
Definition: kd.h:85
@ DbgKdWriteMachineSpecificRegister
Definition: kd.h:72
@ DbgKdReadPhysicalMemoryApi
Definition: kd.h:56
@ DbgKdReadIoSpaceExtendedApi
Definition: kd.h:63
@ DbgKdFillMemoryApi
Definition: kd.h:80
@ DbgKdSwitchProcessor
Definition: kd.h:69
@ DbgKdGetContextApi
Definition: kd.h:45
@ DbgKdSetInternalBreakPointApi
Definition: kd.h:61
@ DbgKdGetBusDataApi
Definition: kd.h:76
@ DbgKdWriteControlSpaceApi
Definition: kd.h:51
@ DbgKdRebootApi
Definition: kd.h:54
@ DbgKdReadControlSpaceApi
Definition: kd.h:50
@ DbgKdReadVirtualMemoryApi
Definition: kd.h:43
@ DbgKdGetInternalBreakPointApi
Definition: kd.h:62
@ DbgKdMaximumManipulate
Definition: kd.h:86
@ DbgKdSearchMemoryApi
Definition: kd.h:75
@ DbgKdGetContextEx
Definition: kd.h:84
@ DbgKdWriteBreakPointApi
Definition: kd.h:47
@ DbgKdQueryMemoryApi
Definition: kd.h:81
@ DbgKdClearAllInternalBreakpointsApi
Definition: kd.h:79
@ DbgKdSetContextApi
Definition: kd.h:46
@ DbgKdWriteCustomBreakpointApi
Definition: kd.h:83
@ DbgKdSetBusDataApi
Definition: kd.h:77
@ OldVlm1
Definition: kd.h:73
@ DbgKdContinueApi2
Definition: kd.h:55
@ DbgKdQuerySpecialCallsApi
Definition: kd.h:58
@ DbgKdReadIoSpaceApi
Definition: kd.h:52
@ DbgKdSwitchPartition
Definition: kd.h:82
@ DbgKdCheckLowMemoryApi
Definition: kd.h:78
@ DbgKdClearSpecialCallsApi
Definition: kd.h:60
@ DbgKdWriteIoSpaceExtendedApi
Definition: kd.h:64
@ DbgKdRestoreBreakPointApi
Definition: kd.h:48
@ DbgKdSetSpecialCallApi
Definition: kd.h:59
@ OldVlm2
Definition: kd.h:74
@ DbgKdWriteBreakPointExApi
Definition: kd.h:66
@ DbgKdWriteIoSpaceApi
Definition: kd.h:53
@ DbgKdPageInApi
Definition: kd.h:70
@ DbgKdReadMachineSpecificRegister
Definition: kd.h:71

◆ KD_PACKET_TYPE

Enumerator
KD_PACKET_TYPE_UNUSED 
KD_PACKET_TYPE_STATE_CHANGE32 
KD_PACKET_TYPE_STATE_MANIPULATE 
KD_PACKET_TYPE_DEBUG_IO 
KD_PACKET_TYPE_ACKNOWLEDGE 
KD_PACKET_TYPE_RESEND 
KD_PACKET_TYPE_RESET 
KD_PACKET_TYPE_STATE_CHANGE64 
KD_PACKET_TYPE_POLL_BREAKIN 
KD_PACKET_TYPE_TRACE_IO 
KD_PACKET_TYPE_CONTROL_REQUEST 
KD_PACKET_TYPE_FILE_IO 

Definition at line 18 of file kd.h.

18  {
31 };
@ KD_PACKET_TYPE_STATE_MANIPULATE
Definition: kd.h:21
@ KD_PACKET_TYPE_STATE_CHANGE64
Definition: kd.h:26
@ KD_PACKET_TYPE_RESEND
Definition: kd.h:24
@ KD_PACKET_TYPE_TRACE_IO
Definition: kd.h:28
@ KD_PACKET_TYPE_POLL_BREAKIN
Definition: kd.h:27
@ KD_PACKET_TYPE_DEBUG_IO
Definition: kd.h:22
@ KD_PACKET_TYPE_UNUSED
Definition: kd.h:19
@ KD_PACKET_TYPE_ACKNOWLEDGE
Definition: kd.h:23
@ KD_PACKET_TYPE_STATE_CHANGE32
Definition: kd.h:20
@ KD_PACKET_TYPE_FILE_IO
Definition: kd.h:30
@ KD_PACKET_TYPE_CONTROL_REQUEST
Definition: kd.h:29
@ KD_PACKET_TYPE_RESET
Definition: kd.h:25

◆ KD_PACKET_WAIT_STATE_CHANGE

Enumerator
DbgKdMinimumStateChange 
DbgKdExceptionStateChange 
DbgKdLoadSymbolsStateChange 
DbgKdCommandStringStateChange 
DbgKdMaximumStateChange 

Definition at line 33 of file kd.h.

33  {
34  DbgKdMinimumStateChange = 0x00003030,
35  DbgKdExceptionStateChange = 0x00003030,
36  DbgKdLoadSymbolsStateChange = 0x00003031,
37  DbgKdCommandStringStateChange = 0x00003032,
38  DbgKdMaximumStateChange = 0x00003033
39 };
@ DbgKdMinimumStateChange
Definition: kd.h:34
@ DbgKdCommandStringStateChange
Definition: kd.h:37
@ DbgKdLoadSymbolsStateChange
Definition: kd.h:36
@ DbgKdExceptionStateChange
Definition: kd.h:35
@ DbgKdMaximumStateChange
Definition: kd.h:38

Function Documentation

◆ ct_assert() [1/3]

ct_assert ( sizeof(kd_ioc_t = =64)

◆ ct_assert() [2/3]

ct_assert ( sizeof(kd_packet_t)  = =16)

◆ ct_assert() [3/3]

ct_assert ( sizeof(kd_req_t)  = =56)

◆ kd_data_checksum()

ut32 kd_data_checksum ( const ut8 buf,
const ut64  buf_len 
)

Definition at line 11 of file kd.c.

11  {
12  ut32 i, acc;
13 
14  if (!buf || !buf_len) {
15  return 0;
16  }
17 
18  for (i = acc = 0; i < buf_len; i++) {
19  acc += buf[i];
20  }
21 
22  return acc;
23 }
lzma_index ** i
Definition: index.h:629
static int buf_len
Definition: asm_arc.c:22
uint32_t ut32
voidpf void * buf
Definition: ioapi.h:138

References buf_len, and i.

Referenced by kd_read_packet(), and kd_send_data_packet().

◆ kd_packet_is_ack()

int kd_packet_is_ack ( const kd_packet_t *  p)

Definition at line 158 of file kd.c.

158  {
159  return p->leader == KD_PACKET_CTRL && p->type == KD_PACKET_TYPE_ACKNOWLEDGE;
160 }
#define KD_PACKET_CTRL
Definition: kd.h:98
void * p
Definition: libc.cpp:67

References KD_PACKET_CTRL, KD_PACKET_TYPE_ACKNOWLEDGE, and p.

◆ kd_packet_is_valid()

bool kd_packet_is_valid ( const kd_packet_t *  p)

Definition at line 154 of file kd.c.

154  {
155  return p->leader == KD_PACKET_CTRL || p->leader == KD_PACKET_DATA || p->leader == KD_PACKET_UNUSED;
156 }
#define KD_PACKET_UNUSED
Definition: kd.h:96
#define KD_PACKET_DATA
Definition: kd.h:97

References KD_PACKET_CTRL, KD_PACKET_DATA, KD_PACKET_UNUSED, and p.

Referenced by kd_read_packet().

◆ kd_read_packet()

int kd_read_packet ( io_desc_t desc,
kd_packet_t **  p 
)

Definition at line 80 of file kd.c.

80  {
81  kd_packet_t pkt;
82  ut8 *buf;
83 
84  *p = NULL;
85 
86  if (iob_read(desc, (ut8 *)&pkt, sizeof(kd_packet_t)) <= 0) {
87  return KD_E_IOERR;
88  }
89 
90  if (!kd_packet_is_valid(&pkt)) {
91  KD_DBG eprintf("invalid leader %08x, trying to recover\n", pkt.leader);
92  while (!kd_packet_is_valid(&pkt)) {
94  char sig[4];
95  // Read byte-by-byte searching for the start of a packet
96  int ret;
97  while ((ret = iob_read(desc, (ut8 *)&sig, 1)) > 0) {
98  if (sig[0] == '0' || sig[0] == 'i') {
99  if (iob_read(desc, (ut8 *)&sig + 1, 3) == 3) {
100  if (strncmp(sig, "000", 3) && strncmp(sig, "iii", 3)) {
101  continue;
102  }
103  memcpy(&pkt, sig, sizeof(sig));
104  if (iob_read(desc, (ut8 *)&pkt + 4, sizeof(kd_packet_t) - 4) <= 0) {
105  return KD_E_IOERR;
106  }
107  break;
108  } else {
109  return KD_E_IOERR;
110  }
111  }
112  }
113  if (!ret) {
114  return KD_E_IOERR;
115  }
116  }
117  }
118 
119  buf = malloc(sizeof(kd_packet_t) + pkt.length);
120  if (!buf) {
121  return KD_E_IOERR;
122  }
123  memcpy(buf, &pkt, sizeof(kd_packet_t));
124 
125  if (pkt.length) {
126  iob_read(desc, (ut8 *)buf + sizeof(kd_packet_t), pkt.length);
127  }
128 
129  if (pkt.checksum != kd_data_checksum(buf + sizeof(kd_packet_t), pkt.length)) {
130  KD_DBG eprintf("Checksum mismatch!\n");
131  free(buf);
132  return KD_E_MALFORMED;
133  }
134 
135  if (pkt.leader == KD_PACKET_DATA) {
136  if (desc->iob->type == KD_IO_PIPE) {
137  ut8 trailer;
138  iob_read(desc, (ut8 *)&trailer, 1);
139 
140  if (trailer != 0xAA) {
141  KD_DBG eprintf("Missing trailer 0xAA\n");
142  free(buf);
143  return KD_E_MALFORMED;
144  }
145  }
146  }
148 
149  *p = (kd_packet_t *)buf;
150 
151  return KD_E_OK;
152 }
const char * desc
Definition: bin_vsf.c:19
#define NULL
Definition: cris-opc.c:27
RZ_API void Ht_() free(HtName_(Ht) *ht)
Definition: ht_inc.c:130
ut32 kd_data_checksum(const ut8 *buf, const ut64 buf_len)
Definition: kd.c:11
int kd_send_ctrl_packet(io_desc_t *desc, const ut32 type, const ut32 id)
Definition: kd.c:25
#define KD_DBG
Definition: kd.c:9
bool kd_packet_is_valid(const kd_packet_t *p)
Definition: kd.c:154
uint8_t ut8
Definition: lh5801.h:11
memcpy(mem, inblock.get(), min(CONTAINING_RECORD(inblock.get(), MEMBLOCK, data) ->size, size))
void * malloc(size_t size)
Definition: malloc.c:123
#define eprintf(x, y...)
Definition: rlcc.c:7
int iob_read(io_desc_t *desc, uint8_t *buf, const uint32_t buf_len)
Definition: transport.c:37
#define KD_IO_PIPE
Definition: transport.h:17

References desc, eprintf, free(), iob_read(), kd_data_checksum(), KD_DBG, KD_E_IOERR, KD_E_MALFORMED, KD_E_OK, KD_IO_PIPE, KD_PACKET_DATA, kd_packet_is_valid(), KD_PACKET_TYPE_ACKNOWLEDGE, KD_PACKET_TYPE_RESEND, kd_send_ctrl_packet(), malloc(), memcpy(), NULL, and p.

Referenced by winkd_sync(), and winkd_wait_packet().

◆ kd_send_ctrl_packet()

int kd_send_ctrl_packet ( io_desc_t desc,
const ut32  type,
const ut32  id 
)

Definition at line 25 of file kd.c.

25  {
26  kd_packet_t pkt;
27 
28  pkt.leader = KD_PACKET_CTRL;
29  pkt.length = 0;
30  pkt.checksum = 0;
31  pkt.id = id;
32  pkt.type = type;
33 
34  if (iob_write(desc, (ut8 *)&pkt, sizeof(kd_packet_t)) < 0) {
35  return KD_E_IOERR;
36  }
37 
38  return KD_E_OK;
39 }
int type
Definition: mipsasm.c:17
int id
Definition: op.c:540
int iob_write(io_desc_t *desc, const uint8_t *buf, const uint32_t buf_len)
Definition: transport.c:16

References desc, id, iob_write(), KD_E_IOERR, KD_E_OK, KD_PACKET_CTRL, and type.

Referenced by kd_read_packet(), and winkd_sync().

◆ kd_send_data_packet()

int kd_send_data_packet ( io_desc_t desc,
const ut32  type,
const ut32  id,
const ut8 req,
const int  req_len,
const ut8 buf,
const ut32  buf_len 
)

Definition at line 41 of file kd.c.

42  {
43  kd_packet_t pkt;
44 
45  if (req_len + buf_len > KD_MAX_PAYLOAD) {
46  return KD_E_MALFORMED;
47  }
48 
49  RZ_LOG_DEBUG("==== Send Data ====\n");
50  RZ_LOG_DEBUG("ID: 0x%" PFMT32x "\n", id);
51  RZ_LOG_DEBUG("Type: 0x%" PFMT32x "\n", type);
52 
53  pkt.leader = KD_PACKET_DATA;
54  pkt.length = req_len + buf_len;
55  pkt.checksum = kd_data_checksum(req, req_len) + kd_data_checksum(buf, buf_len);
56  pkt.id = id;
57  pkt.type = type;
58 
59  if (iob_write(desc, (ut8 *)&pkt, sizeof(kd_packet_t)) < 0) {
60  return KD_E_IOERR;
61  }
62 
63  if (iob_write(desc, (ut8 *)req, req_len) < 0) {
64  return KD_E_IOERR;
65  }
66 
67  if (buf && iob_write(desc, (ut8 *)buf, buf_len) < 0) {
68  return KD_E_IOERR;
69  }
70 
71  if (desc->iob->type == KD_IO_PIPE) {
72  if (iob_write(desc, (ut8 *)"\xAA", 1) < 0) {
73  return KD_E_IOERR;
74  }
75  }
76 
77  return KD_E_OK;
78 }
#define PFMT32x
static static sync static getppid static getegid const char static filename char static len const char char static bufsiz static mask static vfork const void static prot static getpgrp const char static swapflags static arg static fd static protocol static who struct sockaddr static addrlen static backlog struct timeval struct timezone static tz const struct iovec static count static mode const void const struct sockaddr static tolen const char static pathname void static offset struct stat static buf void long static basep static whence static length const void static len static semflg const void static shmflg const struct timespec req
Definition: sflib.h:128
#define KD_MAX_PAYLOAD
Definition: kd.h:102
#define RZ_LOG_DEBUG(fmtstr,...)
Definition: rz_log.h:49

References buf_len, desc, id, iob_write(), kd_data_checksum(), KD_E_IOERR, KD_E_MALFORMED, KD_E_OK, KD_IO_PIPE, KD_MAX_PAYLOAD, KD_PACKET_DATA, PFMT32x, req, RZ_LOG_DEBUG, and type.

Referenced by do_io_reply(), winkd_continue(), and winkd_send_state_manipulate_req().

◆ RZ_PACKED() [1/4]

RZ_PACKED ( typedef struct kd_packet_t { ut32 leader;ut16 type;ut16 length;ut32 id;ut32 checksum;ut8 data[];}  )

References id, length, and type.

◆ RZ_PACKED() [2/4]

RZ_PACKED ( typedef struct kd_req_t { ut32 req;ut16 cpu_level;ut16 cpu;ut32 ret;ut32 pad;union { RZ_PACKED(struct { ut64 addr;ut32 length;ut32 read;}) rz_mem;RZ_PACKED(struct { ut16 major;ut16 minor;ut8 proto_major;ut8 proto_minor;ut16 flags;ut16 machine;ut8 misc[6];ut64 kernel_base;ut64 mod_addr;ut64 dbg_addr;}) rz_ver;struct { ut32 reason;ut32 tf;ut32 dr7;ut32 css;ut32 cse;} rz_cont;struct { ut64 addr;ut32 handle;} rz_set_bp;struct { ut32 handle;} rz_del_bp;struct { ut64 addr;ut32 flags;} rz_set_ibp;struct { ut64 addr;ut32 flags;ut32 calls;} rz_get_ibp;struct { ut32 flags;} rz_ctx;struct { ut32 offset;ut32 count;ut32 copied;} rz_ctx_ex;struct { ut64 addr;ut64 reserved;ut32 address_space;ut32 flags;} rz_query_mem;ut8 raw[40];};ut8 data[];}  )

References addr, count, cpu, flags, handle, length, major, minor, pad(), read(), req, reserved, and ut64().

Referenced by RZ_PACKED().

◆ RZ_PACKED() [3/4]

RZ_PACKED ( typedef struct kd_stc_64 { ut32 state;ut16 cpu_level;ut16 cpu;ut32 cpu_count;ut32 pad1;ut64 kthread;ut64 pc;union { RZ_PACKED(struct { ut32 code;ut32 flags;ut64 ex_record;ut64 ex_addr;}) exception;RZ_PACKED(struct { ut64 pathsize;ut64 base;ut64 pid;ut32 checksum;ut32 size;ut8 unload;}) load_symbols;};}  )

References code, cpu, exception, flags, pc, pid, RZ_PACKED(), and ut64().

◆ RZ_PACKED() [4/4]

RZ_PACKED ( typedef struct kdnet_packet_t { ut32 magic;ut8 version;ut8 type;}  )

References type, and version.