Module Name: src
Committed By: alnsn
Date: Wed Jun 25 13:53:40 UTC 2014
Modified Files:
src/sys/net: bpfjit.c
Log Message:
Default initialize external memwords.
This change doesn't affect performance of valid bpf kernel programs
because bpf_filter_ext() checks that all memwords are initialized
explicitly.
To generate a diff of this commit:
cvs rdiff -u -r1.17 -r1.18 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.17 src/sys/net/bpfjit.c:1.18
--- src/sys/net/bpfjit.c:1.17 Wed Jun 25 11:58:15 2014
+++ src/sys/net/bpfjit.c Wed Jun 25 13:53:40 2014
@@ -1,4 +1,4 @@
-/* $NetBSD: bpfjit.c,v 1.17 2014/06/25 11:58:15 alnsn Exp $ */
+/* $NetBSD: bpfjit.c,v 1.18 2014/06/25 13:53:40 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.17 2014/06/25 11:58:15 alnsn Exp $");
+__KERNEL_RCSID(0, "$NetBSD: bpfjit.c,v 1.18 2014/06/25 13:53:40 alnsn Exp $");
#else
-__RCSID("$NetBSD: bpfjit.c,v 1.17 2014/06/25 11:58:15 alnsn Exp $");
+__RCSID("$NetBSD: bpfjit.c,v 1.18 2014/06/25 13:53:40 alnsn Exp $");
#endif
#include <sys/types.h>
@@ -1594,6 +1594,10 @@ bpfjit_generate_code(const bpf_ctx_t *bc
bpf_memword_init_t initmask;
int nscratches, ncopfuncs;
+ /* memory store location for initial zero initialization */
+ sljit_si mem_reg;
+ sljit_sw mem_off;
+
/* a list of jumps to out-of-bound return from a generated function */
struct sljit_jump **ret0;
size_t ret0_size, ret0_maxsize;
@@ -1665,7 +1669,10 @@ bpfjit_generate_code(const bpf_ctx_t *bc
goto fail;
}
- if (extwords != 0) {
+ if (extwords == 0) {
+ mem_reg = SLJIT_MEM1(SLJIT_LOCALS_REG);
+ mem_off = offsetof(struct bpfjit_stack, mem);
+ } else {
/* copy "mem" argument from bpf_args to bpfjit_stack */
status = sljit_emit_op1(compiler,
SLJIT_MOV_P,
@@ -1681,11 +1688,10 @@ bpfjit_generate_code(const bpf_ctx_t *bc
BJ_TMP1REG, 0);
if (status != SLJIT_SUCCESS)
goto fail;
- }
- status = load_buf_buflen(compiler);
- if (status != SLJIT_SUCCESS)
- goto fail;
+ mem_reg = SLJIT_MEM1(BJ_TMP1REG);
+ mem_off = 0;
+ }
/*
* Exclude pre-initialised external memory words but keep
@@ -1703,9 +1709,7 @@ bpfjit_generate_code(const bpf_ctx_t *bc
/* M[i] = 0; */
status = sljit_emit_op1(compiler,
SLJIT_MOV_UI,
- SLJIT_MEM1(SLJIT_LOCALS_REG),
- offsetof(struct bpfjit_stack, mem) +
- i * sizeof(uint32_t),
+ mem_reg, mem_off + i * sizeof(uint32_t),
SLJIT_IMM, 0);
if (status != SLJIT_SUCCESS)
goto fail;
@@ -1732,6 +1736,10 @@ bpfjit_generate_code(const bpf_ctx_t *bc
goto fail;
}
+ status = load_buf_buflen(compiler);
+ if (status != SLJIT_SUCCESS)
+ goto fail;
+
for (i = 0; i < insn_count; i++) {
if (insn_dat[i].unreachable)
continue;