Skip to content

Commit

Permalink
Use const on all read-only buffers
Browse files Browse the repository at this point in the history
  • Loading branch information
radare committed Dec 11, 2013
1 parent ad89d25 commit f0e4eed
Show file tree
Hide file tree
Showing 25 changed files with 60 additions and 60 deletions.
2 changes: 1 addition & 1 deletion arch/AArch64/AArch64Disassembler.c
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,7 @@ void AArch64_init(MCRegisterInfo *MRI)


static DecodeStatus _getInstruction(MCInst *MI,
unsigned char *code, size_t code_len,
const uint8_t *code, size_t code_len,
uint16_t *Size,
uint64_t Address, MCRegisterInfo *MRI)
{
Expand Down
2 changes: 1 addition & 1 deletion arch/AArch64/AArch64Disassembler.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

void AArch64_init(MCRegisterInfo *MRI);

bool AArch64_getInstruction(csh ud, unsigned char *code, size_t code_len,
bool AArch64_getInstruction(csh ud, const uint8_t *code, size_t code_len,
MCInst *instr, uint16_t *size, uint64_t address, void *info);

#endif
2 changes: 1 addition & 1 deletion arch/AArch64/AArch64InstPrinter.c
Original file line number Diff line number Diff line change
Expand Up @@ -657,7 +657,7 @@ static void printVectorList(MCInst *MI, unsigned OpNum,
#define PRINT_ALIAS_INSTR
#include "AArch64GenAsmWriter.inc"

void AArch64_post_printer(unsigned int insn, cs_insn *pub_insn, char *insn_asm)
void AArch64_post_printer(unsigned int insn, cs_insn *pub_insn, const char *insn_asm)
{
// check if this insn requests write-back
if (strrchr(insn_asm, '!') != NULL)
Expand Down
2 changes: 1 addition & 1 deletion arch/AArch64/AArch64InstPrinter.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,6 @@

void AArch64_printInst(MCInst *MI, SStream *O, void *);

void AArch64_post_printer(unsigned int insn, cs_insn *pub_insn, char *insn_asm);
void AArch64_post_printer(unsigned int insn, cs_insn *pub_insn, const char *insn_asm);

#endif
6 changes: 3 additions & 3 deletions arch/AArch64/mapping.c
Original file line number Diff line number Diff line change
Expand Up @@ -436,7 +436,7 @@ static name_map reg_name_maps[] = {
{ ARM64_REG_Q31_Q0_Q1_Q2, "q31_q0_q1_q2"},
};

char *AArch64_reg_name(csh handle, unsigned int reg)
const char *AArch64_reg_name(csh handle, unsigned int reg)
{
if (reg >= ARM64_REG_MAX)
return NULL;
Expand Down Expand Up @@ -3684,7 +3684,7 @@ static name_map alias_insn_name_maps[] = {
{ ARM64_INS_NEGS, "negs" },
};

char *AArch64_insn_name(csh handle, unsigned int id)
const char *AArch64_insn_name(csh handle, unsigned int id)
{
if (id >= ARM64_INS_MAX)
return NULL;
Expand All @@ -3700,7 +3700,7 @@ char *AArch64_insn_name(csh handle, unsigned int id)
}

// map instruction name to public instruction ID
arm64_reg AArch64_map_insn(char *name)
arm64_reg AArch64_map_insn(const char *name)
{
// NOTE: skip first NULL name in insn_name_maps
int i = name2id(&insn_name_maps[1], ARR_SIZE(insn_name_maps) - 1, name);
Expand Down
6 changes: 3 additions & 3 deletions arch/AArch64/mapping.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,17 @@
#include "../../include/arm64.h"

// return name of regiser in friendly string
char *AArch64_reg_name(csh handle, unsigned int reg);
const char *AArch64_reg_name(csh handle, unsigned int reg);

// given internal insn id, return public instruction info
void AArch64_get_insn_id(cs_insn *insn, unsigned int id);

// given public insn id, return internal instruction ID
unsigned int AArch64_get_insn_id2(unsigned int id);

char *AArch64_insn_name(csh handle, unsigned int id);
const char *AArch64_insn_name(csh handle, unsigned int id);

// map instruction name to public instruction ID
arm64_reg AArch64_map_insn(char *name);
arm64_reg AArch64_map_insn(const char *name);

#endif
8 changes: 4 additions & 4 deletions arch/ARM/ARMDisassembler.c
Original file line number Diff line number Diff line change
Expand Up @@ -435,7 +435,7 @@ void ARM_init(MCRegisterInfo *MRI)
0);
}

static DecodeStatus _ARM_getInstruction(cs_struct *ud, MCInst *MI, unsigned char *code, size_t code_len,
static DecodeStatus _ARM_getInstruction(cs_struct *ud, MCInst *MI, const uint8_t *code, size_t code_len,
uint16_t *Size, uint64_t Address)
{
uint8_t bytes[4];
Expand Down Expand Up @@ -656,7 +656,7 @@ static void UpdateThumbVFPPredicate(cs_struct *ud, MCInst *MI)
}
}

static DecodeStatus _Thumb_getInstruction(cs_struct *ud, MCInst *MI, unsigned char *code, size_t code_len,
static DecodeStatus _Thumb_getInstruction(cs_struct *ud, MCInst *MI, const uint8_t *code, size_t code_len,
uint16_t *Size, uint64_t Address)
{
uint8_t bytes[4];
Expand Down Expand Up @@ -830,7 +830,7 @@ static DecodeStatus _Thumb_getInstruction(cs_struct *ud, MCInst *MI, unsigned ch
return MCDisassembler_Fail;
}

bool Thumb_getInstruction(csh ud, unsigned char *code, size_t code_len, MCInst *instr,
bool Thumb_getInstruction(csh ud, const uint8_t *code, size_t code_len, MCInst *instr,
uint16_t *size, uint64_t address, void *info)
{
DecodeStatus status = _Thumb_getInstruction((cs_struct *)ud, instr, code, code_len, size, address);
Expand All @@ -839,7 +839,7 @@ bool Thumb_getInstruction(csh ud, unsigned char *code, size_t code_len, MCInst *
return status != MCDisassembler_Fail;
}

bool ARM_getInstruction(csh ud, unsigned char *code, size_t code_len, MCInst *instr,
bool ARM_getInstruction(csh ud, const uint8_t *code, size_t code_len, MCInst *instr,
uint16_t *size, uint64_t address, void *info)
{
DecodeStatus status = _ARM_getInstruction((cs_struct *)ud, instr, code, code_len, size, address);
Expand Down
4 changes: 2 additions & 2 deletions arch/ARM/ARMDisassembler.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@

void ARM_init(MCRegisterInfo *MRI);

bool ARM_getInstruction(csh handle, unsigned char *code, size_t code_len, MCInst *instr, uint16_t *size, uint64_t address, void *info);
bool ARM_getInstruction(csh handle, const uint8_t *code, size_t code_len, MCInst *instr, uint16_t *size, uint64_t address, void *info);

bool Thumb_getInstruction(csh handle, unsigned char *code, size_t code_len, MCInst *instr, uint16_t *size, uint64_t address, void *info);
bool Thumb_getInstruction(csh handle, const uint8_t *code, size_t code_len, MCInst *instr, uint16_t *size, uint64_t address, void *info);

uint64_t ARM_getFeatureBits(int mode);

Expand Down
2 changes: 1 addition & 1 deletion arch/ARM/ARMInstPrinter.c
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ static name_map insn_update_flgs[] = {
{ ARM_INS_UMULL, "umulls" },
};

void ARM_post_printer(unsigned int insn, cs_insn *pub_insn, char *insn_asm)
void ARM_post_printer(unsigned int insn, cs_insn *pub_insn, const char *insn_asm)
{
// check if this insn requests write-back
if (strrchr(insn_asm, '!') != NULL) {
Expand Down
2 changes: 1 addition & 1 deletion arch/ARM/ARMInstPrinter.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,6 @@
#include "../../SStream.h"

void ARM_printInst(MCInst *MI, SStream *O, void *Info);
void ARM_post_printer(unsigned int insn, cs_insn *pub_insn, char *mnem);
void ARM_post_printer(unsigned int insn, cs_insn *pub_insn, const char *mnem);

#endif
6 changes: 3 additions & 3 deletions arch/ARM/mapping.c
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ static name_map reg_name_maps[] = {
{ ARM_REG_S31, "s31"},
};

char *ARM_reg_name(csh handle, unsigned int reg)
const char *ARM_reg_name(csh handle, unsigned int reg)
{
if (reg >= ARM_REG_MAX)
return NULL;
Expand Down Expand Up @@ -2763,15 +2763,15 @@ static name_map insn_name_maps[] = {
{ ARM_INS_PUSH, "push" },
};

char *ARM_insn_name(csh handle, unsigned int id)
const char *ARM_insn_name(csh handle, unsigned int id)
{
if (id >= ARM_INS_MAX)
return NULL;

return insn_name_maps[id].name;
}

arm_reg ARM_map_insn(char *name)
arm_reg ARM_map_insn(const char *name)
{
int i = name2id(&insn_name_maps[1], ARR_SIZE(insn_name_maps) - 1, name);

Expand Down
6 changes: 3 additions & 3 deletions arch/ARM/mapping.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,18 @@
#include "../../utils.h"

// return name of regiser in friendly string
char *ARM_reg_name(csh handle, unsigned int reg);
const char *ARM_reg_name(csh handle, unsigned int reg);

// given internal insn id, return public instruction ID
void ARM_get_insn_id(cs_insn *insn, unsigned int id);

// given public insn id, return internal instruction info
unsigned int ARM_get_insn_id2(unsigned int id);

char *ARM_insn_name(csh handle, unsigned int id);
const char *ARM_insn_name(csh handle, unsigned int id);

// map instruction name to instruction ID
arm_reg ARM_map_insn(char *name);
arm_reg ARM_map_insn(const char *name);

// check if this insn is relative branch
bool ARM_rel_branch(unsigned int insn_id);
Expand Down
4 changes: 2 additions & 2 deletions arch/Mips/MipsDisassembler.c
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,7 @@ static DecodeStatus readInstruction32(unsigned char *code, uint32_t *insn, bool
}

static DecodeStatus MipsDisassembler_getInstruction(int mode, MCInst *instr,
unsigned char *code, size_t code_len,
const uint8_t *code, size_t code_len,
uint16_t *Size,
uint64_t Address, bool isBigEndian, MCRegisterInfo *MRI)
{
Expand Down Expand Up @@ -278,7 +278,7 @@ static DecodeStatus MipsDisassembler_getInstruction(int mode, MCInst *instr,
return MCDisassembler_Fail;
}

bool Mips_getInstruction(csh ud, unsigned char *code, size_t code_len, MCInst *instr,
bool Mips_getInstruction(csh ud, const uint8_t *code, size_t code_len, MCInst *instr,
uint16_t *size, uint64_t address, void *info)
{
cs_struct *handle = (cs_struct *)(uintptr_t)ud;
Expand Down
4 changes: 2 additions & 2 deletions arch/Mips/MipsDisassembler.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@

void Mips_init(MCRegisterInfo *MRI);

bool Mips_getInstruction(csh handle, unsigned char *code, size_t code_len,
bool Mips_getInstruction(csh handle, const uint8_t *code, size_t code_len,
MCInst *instr, uint16_t *size, uint64_t address, void *info);

bool Mips64_getInstruction(csh handle, unsigned char *code, size_t code_len,
bool Mips64_getInstruction(csh handle, const uint8_t *code, size_t code_len,
MCInst *instr, uint16_t *size, uint64_t address, void *info);

#endif
6 changes: 3 additions & 3 deletions arch/Mips/mapping.c
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ static name_map reg_name_maps[] = {
{ MIPS_REG_W31, "w31"},
};

char *Mips_reg_name(csh handle, unsigned int reg)
const char *Mips_reg_name(csh handle, unsigned int reg)
{
if (reg >= MIPS_REG_MAX)
return NULL;
Expand Down Expand Up @@ -1917,7 +1917,7 @@ static name_map alias_insn_names[] = {
{ MIPS_INS_NEGU, "negu" },
};

char *Mips_insn_name(csh handle, unsigned int id)
const char *Mips_insn_name(csh handle, unsigned int id)
{
if (id >= MIPS_INS_MAX)
return NULL;
Expand All @@ -1932,7 +1932,7 @@ char *Mips_insn_name(csh handle, unsigned int id)
return insn_name_maps[id].name;
}

mips_reg Mips_map_insn(char *name)
mips_reg Mips_map_insn(const char *name)
{
// handle special alias first
int i;
Expand Down
6 changes: 3 additions & 3 deletions arch/Mips/mapping.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
#include "../../include/mips.h"

// return name of regiser in friendly string
char *Mips_reg_name(csh handle, unsigned int reg);
const char *Mips_reg_name(csh handle, unsigned int reg);

// given internal insn id, return public instruction info
void Mips_get_insn_id(cs_insn *insn, unsigned int id);
Expand All @@ -17,10 +17,10 @@ void Mips_get_insn_id(cs_insn *insn, unsigned int id);
unsigned int Mips_get_insn_id2(unsigned int id);

// given public insn id, return internal insn id
char *Mips_insn_name(csh handle, unsigned int id);
const char *Mips_insn_name(csh handle, unsigned int id);

// map instruction name to instruction ID
mips_reg Mips_map_insn(char *name);
mips_reg Mips_map_insn(const char *name);

// map internal raw register to 'public' register
mips_reg Mips_map_register(unsigned int r);
Expand Down
4 changes: 2 additions & 2 deletions arch/X86/X86Disassembler.c
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
#include "X86GenInstrInfo.inc"

struct reader_info {
unsigned char *code;
const uint8_t *code;
uint64_t size;
uint64_t offset;
};
Expand Down Expand Up @@ -567,7 +567,7 @@ static void update_pub_insn(cs_insn *pub, InternalInstruction *inter)
}

// Public interface for the disassembler
bool X86_getInstruction(csh ud, unsigned char *code, size_t code_len, MCInst *instr, uint16_t *size, uint64_t address, void *_info)
bool X86_getInstruction(csh ud, const uint8_t *code, size_t code_len, MCInst *instr, uint16_t *size, uint64_t address, void *_info)
{
cs_struct *handle = (cs_struct *)(uintptr_t)ud;
InternalInstruction insn;
Expand Down
2 changes: 1 addition & 1 deletion arch/X86/X86Disassembler.h
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@
#undef INSTRUCTION_SPECIFIER_FIELDS
#undef INSTRUCTION_IDS

bool X86_getInstruction(csh handle, unsigned char *code, size_t code_len,
bool X86_getInstruction(csh handle, const uint8_t *code, size_t code_len,
MCInst *instr, uint16_t *size, uint64_t address, void *info);

#endif
8 changes: 4 additions & 4 deletions arch/X86/mapping.c
Original file line number Diff line number Diff line change
Expand Up @@ -301,7 +301,7 @@ static name_map reg_name_maps[] = {
{ X86_REG_R15W, "r15w" },
};

char *X86_reg_name(csh handle, unsigned int reg)
const char *X86_reg_name(csh handle, unsigned int reg)
{
cs_struct *ud = (cs_struct *)handle;

Expand All @@ -318,7 +318,7 @@ char *X86_reg_name(csh handle, unsigned int reg)
return reg_name_maps[reg].name;
}

x86_reg x86_map_regname(char *reg)
x86_reg x86_map_regname(const char *reg)
{
int i = name2id(&reg_name_maps[1], ARR_SIZE(reg_name_maps) - 1, reg);

Expand Down Expand Up @@ -1579,7 +1579,7 @@ static name_map insn_name_maps[] = {
{ X86_INS_XTEST, "xtest" },
};

char *X86_insn_name(csh handle, unsigned int id)
const char *X86_insn_name(csh handle, unsigned int id)
{
if (id >= X86_INS_MAX)
return NULL;
Expand All @@ -1588,7 +1588,7 @@ char *X86_insn_name(csh handle, unsigned int id)
}

// return insn id, given insn mnemonic
x86_reg X86_map_insn(char *name)
x86_reg X86_map_insn(const char *name)
{
int i = name2id(&insn_name_maps[1], ARR_SIZE(insn_name_maps) - 1, name);

Expand Down
8 changes: 4 additions & 4 deletions arch/X86/mapping.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,19 +17,19 @@ x86_reg x86_map_sib_index(int r);
x86_reg x86_map_segment(int r);

// map register name to x86_reg
x86_reg x86_map_regname(char *reg);
x86_reg x86_map_regname(const char *reg);

// return name of regiser in friendly string
char *X86_reg_name(csh handle, unsigned int reg);
const char *X86_reg_name(csh handle, unsigned int reg);

// given internal insn id, return public instruction info
void X86_get_insn_id(cs_insn *insn, unsigned int id);

// return insn name, given insn id
char *X86_insn_name(csh handle, unsigned int id);
const char *X86_insn_name(csh handle, unsigned int id);

// return insn id, given insn mnemonic
x86_reg X86_map_insn(char *mnem);
x86_reg X86_map_insn(const char *mnem);

// given public insn id, return internal insn id
unsigned int X86_get_insn_id2(unsigned int insn_id);
Expand Down
Loading

0 comments on commit f0e4eed

Please sign in to comment.