Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/sys/net Some small changes in preparation for a bigger change.



details:   https://anonhg.NetBSD.org/src/rev/ba17950fd47a
branches:  trunk
changeset: 796143:ba17950fd47a
user:      alnsn <alnsn%NetBSD.org@localhost>
date:      Thu May 22 13:35:45 2014 +0000

description:
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.

diffstat:

 sys/net/bpfjit.c |  45 ++++++++++++++++++++++++++-------------------
 1 files changed, 26 insertions(+), 19 deletions(-)

diffs (171 lines):

diff -r ca59ee6ba82a -r ba17950fd47a sys/net/bpfjit.c
--- a/sys/net/bpfjit.c  Thu May 22 12:31:28 2014 +0000
+++ b/sys/net/bpfjit.c  Thu May 22 13:35:45 2014 +0000
@@ -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 @@
 #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 @@
        /*
         * 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 @@
        /*
         * 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 @@
  * 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 @@
 
                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 @@
        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 @@
 {
        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 @@
 
                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 @@
                            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 @@
 
                        /* 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 @@
                        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 @@
                        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 @@
                        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 @@
                        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;



Home | Main Index | Thread Index | Old Index