aboutsummaryrefslogtreecommitdiff
path: root/sys/amd64
diff options
context:
space:
mode:
authorJung-uk Kim <jkim@FreeBSD.org>2008-08-18 18:59:33 +0000
committerJung-uk Kim <jkim@FreeBSD.org>2008-08-18 18:59:33 +0000
commit3bfea8682f0462c538b640c7e7cbc5272c8c80c4 (patch)
tree63e735d7c3751dfcf9d460fb513fe5fb008d5671 /sys/amd64
parent651eea9aa84f77105398a08c13821619ca1c86ac (diff)
downloadsrc-3bfea8682f0462c538b640c7e7cbc5272c8c80c4.tar.gz
src-3bfea8682f0462c538b640c7e7cbc5272c8c80c4.zip
- Make these files compilable on user land.
- Update copyrights and fix style(9).
Notes
Notes: svn path=/head/; revision=181846
Diffstat (limited to 'sys/amd64')
-rw-r--r--sys/amd64/amd64/bpf_jit_machdep.c32
1 files changed, 28 insertions, 4 deletions
diff --git a/sys/amd64/amd64/bpf_jit_machdep.c b/sys/amd64/amd64/bpf_jit_machdep.c
index 62436b938aa0..90eb7358c2f2 100644
--- a/sys/amd64/amd64/bpf_jit_machdep.c
+++ b/sys/amd64/amd64/bpf_jit_machdep.c
@@ -32,16 +32,20 @@
#include <sys/cdefs.h>
__FBSDID("$FreeBSD$");
+#ifdef _KERNEL
#include "opt_bpf.h"
-
#include <sys/param.h>
#include <sys/systm.h>
#include <sys/kernel.h>
-#include <sys/types.h>
#include <sys/socket.h>
#include <sys/malloc.h>
-
#include <net/if.h>
+#else
+#include <stdlib.h>
+#endif
+
+#include <sys/types.h>
+
#include <net/bpf.h>
#include <net/bpf_jitter.h>
@@ -53,7 +57,7 @@ bpf_filter_func bpf_jit_compile(struct bpf_insn *, u_int, int *);
* emit routine to update the jump table
*/
static void
-emit_length(bpf_bin_stream *stream, u_int value, u_int len)
+emit_length(bpf_bin_stream *stream, __unused u_int value, u_int len)
{
(stream->refs)[stream->bpf_pc] += len;
@@ -108,8 +112,12 @@ bpf_jit_compile(struct bpf_insn *prog, u_int nins, int *mem)
return (NULL);
/* Allocate the reference table for the jumps */
+#ifdef _KERNEL
stream.refs = (u_int *)malloc((nins + 1) * sizeof(u_int),
M_BPFJIT, M_NOWAIT);
+#else
+ stream.refs = (u_int *)malloc((nins + 1) * sizeof(u_int));
+#endif
if (stream.refs == NULL)
return (NULL);
@@ -141,7 +149,11 @@ bpf_jit_compile(struct bpf_insn *prog, u_int nins, int *mem)
switch (ins->code) {
default:
+#ifdef _KERNEL
return (NULL);
+#else
+ abort();
+#endif
case BPF_RET|BPF_K:
MOVid(ins->k, EAX);
@@ -450,11 +462,19 @@ bpf_jit_compile(struct bpf_insn *prog, u_int nins, int *mem)
if (pass == 2)
break;
+#ifdef _KERNEL
stream.ibuf = (char *)malloc(stream.cur_ip, M_BPFJIT, M_NOWAIT);
if (stream.ibuf == NULL) {
free(stream.refs, M_BPFJIT);
return (NULL);
}
+#else
+ stream.ibuf = (char *)malloc(stream.cur_ip);
+ if (stream.ibuf == NULL) {
+ free(stream.refs);
+ return (NULL);
+ }
+#endif
/*
* modify the reference table to contain the offsets and
@@ -475,7 +495,11 @@ bpf_jit_compile(struct bpf_insn *prog, u_int nins, int *mem)
* the reference table is needed only during compilation,
* now we can free it
*/
+#ifdef _KERNEL
free(stream.refs, M_BPFJIT);
+#else
+ free(stream.refs);
+#endif
return ((bpf_filter_func)stream.ibuf);
}