Module Name:    src
Committed By:   alnsn
Date:           Thu May 22 13:35:45 UTC 2014

Modified Files:
        src/sys/net: bpfjit.c

Log Message:
Some small changes in preparation for a bigger change.

- typedef for ABC variables and MAX_ABC_LENGTH constant,
- cast pc->k to uint32_t in more places,
- whitespaces.


To generate a diff of this commit:
cvs rdiff -u -r1.7 -r1.8 src/sys/net/bpfjit.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/net/bpfjit.c
diff -u src/sys/net/bpfjit.c:1.7 src/sys/net/bpfjit.c:1.8
--- src/sys/net/bpfjit.c:1.7	Thu May 15 22:20:08 2014
+++ src/sys/net/bpfjit.c	Thu May 22 13:35:45 2014
@@ -1,4 +1,4 @@
-/*	$NetBSD: bpfjit.c,v 1.7 2014/05/15 22:20:08 alnsn Exp $	*/
+/*	$NetBSD: bpfjit.c,v 1.8 2014/05/22 13:35:45 alnsn Exp $	*/
 
 /*-
  * Copyright (c) 2011-2014 Alexander Nasonov.
@@ -31,9 +31,9 @@
 
 #include <sys/cdefs.h>
 #ifdef _KERNEL
-__KERNEL_RCSID(0, "$NetBSD: bpfjit.c,v 1.7 2014/05/15 22:20:08 alnsn Exp $");
+__KERNEL_RCSID(0, "$NetBSD: bpfjit.c,v 1.8 2014/05/22 13:35:45 alnsn Exp $");
 #else
-__RCSID("$NetBSD: bpfjit.c,v 1.7 2014/05/15 22:20:08 alnsn Exp $");
+__RCSID("$NetBSD: bpfjit.c,v 1.8 2014/05/22 13:35:45 alnsn Exp $");
 #endif
 
 #include <sys/types.h>
@@ -94,6 +94,9 @@ typedef unsigned int bpfjit_init_mask_t;
 #define BJ_INIT_ABIT    BJ_INIT_MBIT(BPF_MEMWORDS)
 #define BJ_INIT_XBIT    BJ_INIT_MBIT(BPF_MEMWORDS + 1)
 
+typedef uint32_t bpfjit_abc_length_t;
+#define MAX_ABC_LENGTH UINT32_MAX
+
 struct bpfjit_stack
 {
 	uint32_t mem[BPF_MEMWORDS];
@@ -130,11 +133,11 @@ struct bpfjit_jump_data {
 	/*
 	 * Length calculated by Array Bounds Check Elimination (ABC) pass.
 	 */
-	uint32_t abc_length;
+	bpfjit_abc_length_t abc_length;
 	/*
 	 * Length checked by the last out-of-bounds check.
 	 */
-	uint32_t checked_length;
+	bpfjit_abc_length_t checked_length;
 };
 
 /*
@@ -145,14 +148,14 @@ struct bpfjit_read_pkt_data {
 	/*
 	 * Length calculated by Array Bounds Check Elimination (ABC) pass.
 	 */
-	uint32_t abc_length;
+	bpfjit_abc_length_t abc_length;
 	/*
 	 * If positive, emit "if (buflen < check_length) return 0"
 	 * out-of-bounds check.
 	 * We assume that buflen is never equal to UINT32_MAX (otherwise,
 	 * we'd need a special bool variable to emit unconditional "return 0").
 	 */
-	uint32_t check_length;
+	bpfjit_abc_length_t check_length;
 };
 
 /*
@@ -876,10 +879,10 @@ emit_division(struct sljit_compiler* com
  * be set to a safe length required to read a packet.
  */
 static bool
-read_pkt_insn(const struct bpf_insn *pc, uint32_t *length)
+read_pkt_insn(const struct bpf_insn *pc, bpfjit_abc_length_t *length)
 {
 	bool rv;
-	uint32_t width;
+	bpfjit_abc_length_t width;
 
 	switch (BPF_CLASS(pc->code)) {
 	default:
@@ -1067,7 +1070,7 @@ optimize_pass1(const struct bpf_insn *in
 
 		case BPF_JMP:
 			/* Initialize abc_length for ABC pass. */
-			insn_dat[i].u.jdata.abc_length = UINT32_MAX;
+			insn_dat[i].u.jdata.abc_length = MAX_ABC_LENGTH;
 
 			if (BPF_OP(insns[i].code) == BPF_JA) {
 				jt = jf = insns[i].k;
@@ -1123,7 +1126,7 @@ optimize_pass2(const struct bpf_insn *in
 	const struct bpf_insn *pc;
 	struct bpfjit_insn_data *pd;
 	size_t i;
-	uint32_t length, abc_length = 0;
+	bpfjit_abc_length_t length, abc_length = 0;
 
 	for (i = insn_count; i != 0; i--) {
 		pc = &insns[i-1];
@@ -1163,7 +1166,7 @@ optimize_pass3(const struct bpf_insn *in
 {
 	struct bpfjit_jump *jmp;
 	size_t i;
-	uint32_t length, checked_length = 0;
+	bpfjit_abc_length_t checked_length = 0;
 
 	for (i = 0; i < insn_count; i++) {
 		if (insn_dat[i].unreachable)
@@ -1176,7 +1179,7 @@ optimize_pass3(const struct bpf_insn *in
 
 		if (BPF_CLASS(insns[i].code) == BPF_JMP) {
 			insn_dat[i].u.jdata.checked_length = checked_length;
-		} else if (read_pkt_insn(&insns[i], &length)) {
+		} else if (read_pkt_insn(&insns[i], NULL)) {
 			struct bpfjit_read_pkt_data *rdata =
 			    &insn_dat[i].u.rdata;
 			rdata->check_length = 0;
@@ -1427,7 +1430,7 @@ bpfjit_generate_code(bpf_ctx_t *bc, stru
 			    SLJIT_IMM,
 			    insn_dat[i].u.rdata.check_length);
 			if (jump == NULL)
-		  		goto fail;
+				goto fail;
 #ifdef _KERNEL
 			to_mchain_jump = jump;
 #else
@@ -1458,7 +1461,7 @@ bpfjit_generate_code(bpf_ctx_t *bc, stru
 
 			/* BPF_LD+BPF_MEM          A <- M[k] */
 			if (pc->code == (BPF_LD|BPF_MEM)) {
-				if (pc->k >= BPF_MEMWORDS)
+				if ((uint32_t)pc->k >= BPF_MEMWORDS)
 					goto fail;
 				status = sljit_emit_op1(compiler,
 				    SLJIT_MOV_UI,
@@ -1530,7 +1533,7 @@ bpfjit_generate_code(bpf_ctx_t *bc, stru
 			if (mode == BPF_MEM) {
 				if (BPF_SIZE(pc->code) != BPF_W)
 					goto fail;
-				if (pc->k >= BPF_MEMWORDS)
+				if ((uint32_t)pc->k >= BPF_MEMWORDS)
 					goto fail;
 				status = sljit_emit_op1(compiler,
 				    SLJIT_MOV_UI,
@@ -1556,8 +1559,10 @@ bpfjit_generate_code(bpf_ctx_t *bc, stru
 			continue;
 
 		case BPF_ST:
-			if (pc->code != BPF_ST || pc->k >= BPF_MEMWORDS)
+			if (pc->code != BPF_ST ||
+			    (uint32_t)pc->k >= BPF_MEMWORDS) {
 				goto fail;
+			}
 
 			status = sljit_emit_op1(compiler,
 			    SLJIT_MOV_UI,
@@ -1571,8 +1576,10 @@ bpfjit_generate_code(bpf_ctx_t *bc, stru
 			continue;
 
 		case BPF_STX:
-			if (pc->code != BPF_STX || pc->k >= BPF_MEMWORDS)
+			if (pc->code != BPF_STX ||
+			    (uint32_t)pc->k >= BPF_MEMWORDS) {
 				goto fail;
+			}
 
 			status = sljit_emit_op1(compiler,
 			    SLJIT_MOV_UI,
@@ -1619,7 +1626,7 @@ bpfjit_generate_code(bpf_ctx_t *bc, stru
 			if (src == BPF_X) {
 				jump = sljit_emit_cmp(compiler,
 				    SLJIT_C_EQUAL|SLJIT_INT_OP,
-				    BJ_XREG, 0, 
+				    BJ_XREG, 0,
 				    SLJIT_IMM, 0);
 				if (jump == NULL)
 					goto fail;

Reply via email to