summaryrefslogtreecommitdiffstats
path: root/sys/i386
diff options
context:
space:
mode:
authorjkim <jkim@FreeBSD.org>2009-11-20 18:49:20 +0000
committerjkim <jkim@FreeBSD.org>2009-11-20 18:49:20 +0000
commit052bc52af74a5ae4eb6c288f7377bef9d10902cf (patch)
treebe30a4b8f4550e5c133425f045691a115092525c /sys/i386
parentca5edf0fbf82952a5abaa900be8d00c8562ca803 (diff)
downloadFreeBSD-src-052bc52af74a5ae4eb6c288f7377bef9d10902cf.zip
FreeBSD-src-052bc52af74a5ae4eb6c288f7377bef9d10902cf.tar.gz
- Allocate scratch memory on stack instead of pre-allocating it with
the filter as we do from bpf_filter()[1]. - Revert experimental use of contigmalloc(9)/contigfree(9). It has no performance benefit over malloc(9)/free(9)[2]. Requested by: rwatson[1] Pointed out by: rwatson, jhb, alc[2]
Diffstat (limited to 'sys/i386')
-rw-r--r--sys/i386/i386/bpf_jit_machdep.c37
-rw-r--r--sys/i386/i386/bpf_jit_machdep.h7
2 files changed, 27 insertions, 17 deletions
diff --git a/sys/i386/i386/bpf_jit_machdep.c b/sys/i386/i386/bpf_jit_machdep.c
index 2b40b19..8e51f7b 100644
--- a/sys/i386/i386/bpf_jit_machdep.c
+++ b/sys/i386/i386/bpf_jit_machdep.c
@@ -53,7 +53,7 @@ __FBSDID("$FreeBSD$");
#include <i386/i386/bpf_jit_machdep.h>
-bpf_filter_func bpf_jit_compile(struct bpf_insn *, u_int, size_t *, int *);
+bpf_filter_func bpf_jit_compile(struct bpf_insn *, u_int, size_t *);
/*
* emit routine to update the jump table
@@ -97,7 +97,7 @@ emit_code(bpf_bin_stream *stream, u_int value, u_int len)
* Function that does the real stuff
*/
bpf_filter_func
-bpf_jit_compile(struct bpf_insn *prog, u_int nins, size_t *size, int *mem)
+bpf_jit_compile(struct bpf_insn *prog, u_int nins, size_t *size)
{
bpf_bin_stream stream;
struct bpf_insn *ins;
@@ -111,10 +111,9 @@ bpf_jit_compile(struct bpf_insn *prog, u_int nins, size_t *size, int *mem)
/* Allocate the reference table for the jumps */
#ifdef _KERNEL
- stream.refs = (u_int *)malloc((nins + 1) * sizeof(u_int),
- M_BPFJIT, M_NOWAIT);
+ stream.refs = malloc((nins + 1) * sizeof(u_int), M_BPFJIT, M_NOWAIT);
#else
- stream.refs = (u_int *)malloc((nins + 1) * sizeof(u_int));
+ stream.refs = malloc((nins + 1) * sizeof(u_int));
#endif
if (stream.refs == NULL)
return (NULL);
@@ -139,6 +138,7 @@ bpf_jit_compile(struct bpf_insn *prog, u_int nins, size_t *size, int *mem)
/* create the procedure header */
PUSH(EBP);
MOVrd(ESP, EBP);
+ SUBib(BPF_MEMWORDS * sizeof(uint32_t), ESP);
PUSH(EDI);
PUSH(ESI);
PUSH(EBX);
@@ -310,14 +310,16 @@ bpf_jit_compile(struct bpf_insn *prog, u_int nins, size_t *size, int *mem)
break;
case BPF_LD|BPF_MEM:
- MOVid((uintptr_t)mem, ECX);
- MOVid(ins->k * 4, ESI);
+ MOVrd(EBP, ECX);
+ MOVid(((int)ins->k - BPF_MEMWORDS) *
+ sizeof(uint32_t), ESI);
MOVobd(ECX, ESI, EAX);
break;
case BPF_LDX|BPF_MEM:
- MOVid((uintptr_t)mem, ECX);
- MOVid(ins->k * 4, ESI);
+ MOVrd(EBP, ECX);
+ MOVid(((int)ins->k - BPF_MEMWORDS) *
+ sizeof(uint32_t), ESI);
MOVobd(ECX, ESI, EDX);
break;
@@ -327,14 +329,16 @@ bpf_jit_compile(struct bpf_insn *prog, u_int nins, size_t *size, int *mem)
* be optimized if the previous instruction
* was already of this type
*/
- MOVid((uintptr_t)mem, ECX);
- MOVid(ins->k * 4, ESI);
+ MOVrd(EBP, ECX);
+ MOVid(((int)ins->k - BPF_MEMWORDS) *
+ sizeof(uint32_t), ESI);
MOVomd(EAX, ECX, ESI);
break;
case BPF_STX:
- MOVid((uintptr_t)mem, ECX);
- MOVid(ins->k * 4, ESI);
+ MOVrd(EBP, ECX);
+ MOVid(((int)ins->k - BPF_MEMWORDS) *
+ sizeof(uint32_t), ESI);
MOVomd(EDX, ECX, ESI);
break;
@@ -513,13 +517,12 @@ bpf_jit_compile(struct bpf_insn *prog, u_int nins, size_t *size, int *mem)
}
#ifdef _KERNEL
- stream.ibuf = (char *)contigmalloc(stream.cur_ip, M_BPFJIT,
- M_NOWAIT, 0, ~0UL, 16, 0);
+ stream.ibuf = malloc(stream.cur_ip, M_BPFJIT, M_NOWAIT);
if (stream.ibuf == NULL)
break;
#else
- stream.ibuf = (char *)mmap(NULL, stream.cur_ip,
- PROT_READ | PROT_WRITE, MAP_ANON, -1, 0);
+ stream.ibuf = mmap(NULL, stream.cur_ip, PROT_READ | PROT_WRITE,
+ MAP_ANON, -1, 0);
if (stream.ibuf == MAP_FAILED) {
stream.ibuf = NULL;
break;
diff --git a/sys/i386/i386/bpf_jit_machdep.h b/sys/i386/i386/bpf_jit_machdep.h
index 0ec94d2..7e6f2b0 100644
--- a/sys/i386/i386/bpf_jit_machdep.h
+++ b/sys/i386/i386/bpf_jit_machdep.h
@@ -203,6 +203,13 @@ typedef void (*emit_func)(bpf_bin_stream *stream, u_int value, u_int n);
emitm(&stream, i32, 4); \
} while (0)
+/* subl i8,r32 */
+#define SUBib(i8, r32) do { \
+ emitm(&stream, 0x83, 1); \
+ emitm(&stream, (29 << 3) | (r32 & 0x7), 1); \
+ emitm(&stream, i8, 1); \
+} while (0)
+
/* mull r32 */
#define MULrd(r32) do { \
emitm(&stream, 0xf7, 1); \
OpenPOWER on IntegriCloud