MFamd64: Correctly check unsignedness of all registers used

for load instructions with direct or indirect offsets.
This commit is contained in:
Jung-uk Kim 2008-08-18 21:17:47 +00:00
parent 69e08c86a5
commit 520ba9d94a
2 changed files with 70 additions and 38 deletions

View File

@ -174,11 +174,13 @@ bpf_jit_compile(struct bpf_insn *prog, u_int nins, int *mem)
break;
case BPF_LD|BPF_W|BPF_ABS:
MOVid(ins->k, ECX);
MOVrd(ECX, ESI);
ADDib(sizeof(int32_t), ECX);
CMPrd(EDI, ECX);
JBEb(7);
MOVid(ins->k, ESI);
CMPrd(EDI, ESI);
JAb(12);
MOVrd(EDI, ECX);
SUBrd(ESI, ECX);
CMPid(sizeof(int32_t), ECX);
JAEb(7);
ZEROrd(EAX);
POP(EBX);
POP(ESI);
@ -190,11 +192,13 @@ bpf_jit_compile(struct bpf_insn *prog, u_int nins, int *mem)
case BPF_LD|BPF_H|BPF_ABS:
ZEROrd(EAX);
MOVid(ins->k, ECX);
MOVrd(ECX, ESI);
ADDib(sizeof(int16_t), ECX);
CMPrd(EDI, ECX);
JBEb(5);
MOVid(ins->k, ESI);
CMPrd(EDI, ESI);
JAb(12);
MOVrd(EDI, ECX);
SUBrd(ESI, ECX);
CMPid(sizeof(int16_t), ECX);
JAEb(5);
POP(EBX);
POP(ESI);
POP(EDI);
@ -205,14 +209,14 @@ bpf_jit_compile(struct bpf_insn *prog, u_int nins, int *mem)
case BPF_LD|BPF_B|BPF_ABS:
ZEROrd(EAX);
MOVid(ins->k, ECX);
CMPrd(EDI, ECX);
JBEb(5);
MOVid(ins->k, ESI);
CMPrd(EDI, ESI);
JBb(5);
POP(EBX);
POP(ESI);
POP(EDI);
LEAVE_RET();
MOVobb(EBX, ECX, AL);
MOVobb(EBX, ESI, AL);
break;
case BPF_LD|BPF_W|BPF_LEN:
@ -224,12 +228,18 @@ bpf_jit_compile(struct bpf_insn *prog, u_int nins, int *mem)
break;
case BPF_LD|BPF_W|BPF_IND:
MOVid(ins->k, ECX);
ADDrd(EDX, ECX);
MOVrd(ECX, ESI);
ADDib(sizeof(int32_t), ECX);
CMPrd(EDI, ECX);
JBEb(7);
CMPrd(EDI, EDX);
JAb(27);
MOVid(ins->k, ESI);
MOVrd(EDI, ECX);
SUBrd(EDX, ECX);
CMPrd(ESI, ECX);
JBb(14);
ADDrd(EDX, ESI);
MOVrd(EDI, ECX);
SUBrd(ESI, ECX);
CMPid(sizeof(int32_t), ECX);
JAEb(7);
ZEROrd(EAX);
POP(EBX);
POP(ESI);
@ -241,12 +251,18 @@ bpf_jit_compile(struct bpf_insn *prog, u_int nins, int *mem)
case BPF_LD|BPF_H|BPF_IND:
ZEROrd(EAX);
MOVid(ins->k, ECX);
ADDrd(EDX, ECX);
MOVrd(ECX, ESI);
ADDib(sizeof(int16_t), ECX);
CMPrd(EDI, ECX);
JBEb(5);
CMPrd(EDI, EDX);
JAb(27);
MOVid(ins->k, ESI);
MOVrd(EDI, ECX);
SUBrd(EDX, ECX);
CMPrd(ESI, ECX);
JBb(14);
ADDrd(EDX, ESI);
MOVrd(EDI, ECX);
SUBrd(ESI, ECX);
CMPid(sizeof(int16_t), ECX);
JAEb(5);
POP(EBX);
POP(ESI);
POP(EDI);
@ -257,28 +273,32 @@ bpf_jit_compile(struct bpf_insn *prog, u_int nins, int *mem)
case BPF_LD|BPF_B|BPF_IND:
ZEROrd(EAX);
MOVid(ins->k, ECX);
ADDrd(EDX, ECX);
CMPrd(EDI, ECX);
JBEb(5);
CMPrd(EDI, EDX);
JAEb(13);
MOVid(ins->k, ESI);
MOVrd(EDI, ECX);
SUBrd(EDX, ECX);
CMPrd(ESI, ECX);
JAb(5);
POP(EBX);
POP(ESI);
POP(EDI);
LEAVE_RET();
MOVobb(EBX, ECX, AL);
ADDrd(EDX, ESI);
MOVobb(EBX, ESI, AL);
break;
case BPF_LDX|BPF_MSH|BPF_B:
MOVid(ins->k, ECX);
CMPrd(EDI, ECX);
JBEb(7);
MOVid(ins->k, ESI);
CMPrd(EDI, ESI);
JBb(7);
ZEROrd(EAX);
POP(EBX);
POP(ESI);
POP(EDI);
LEAVE_RET();
ZEROrd(EDX);
MOVobb(EBX, ECX, DL);
MOVobb(EBX, ESI, DL);
ANDib(0x0f, DL);
SHLib(2, EDX);
break;

View File

@ -331,15 +331,27 @@ typedef void (*emit_func)(bpf_bin_stream *stream, u_int value, u_int n);
} \
} while (0)
/* jb off8 */
#define JBb(off8) do { \
emitm(&stream, 0x72, 1); \
emitm(&stream, off8, 1); \
} while (0)
/* jae off8 */
#define JAEb(off8) do { \
emitm(&stream, 0x73, 1); \
emitm(&stream, off8, 1); \
} while (0)
/* jne off8 */
#define JNEb(off8) do { \
emitm(&stream, 0x75, 1); \
emitm(&stream, off8, 1); \
} while (0)
/* jbe off8 */
#define JBEb(off8) do { \
emitm(&stream, 0x76, 1); \
/* ja off8 */
#define JAb(off8) do { \
emitm(&stream, 0x77, 1); \
emitm(&stream, off8, 1); \
} while (0)