diff options
author | jkim <jkim@FreeBSD.org> | 2009-11-18 23:40:19 +0000 |
---|---|---|
committer | jkim <jkim@FreeBSD.org> | 2009-11-18 23:40:19 +0000 |
commit | 8e75a7257b6388ab8a5e0e06409511e0d964a863 (patch) | |
tree | b9804425527a596e571e08317ca60dd1863d5347 /sys/amd64 | |
parent | efc247aeb32656ef1e27f5c3451d1fa4b1408294 (diff) | |
download | FreeBSD-src-8e75a7257b6388ab8a5e0e06409511e0d964a863.zip FreeBSD-src-8e75a7257b6388ab8a5e0e06409511e0d964a863.tar.gz |
- Change internal function bpf_jit_compile() to return allocated size of
the generated binary and remove page size limitation for userland.
- Use contigmalloc(9)/contigfree(9) instead of malloc(9)/free(9) to make
sure the generated binary aligns properly and make it physically contiguous.
Diffstat (limited to 'sys/amd64')
-rw-r--r-- | sys/amd64/amd64/bpf_jit_machdep.c | 16 |
1 files changed, 7 insertions, 9 deletions
diff --git a/sys/amd64/amd64/bpf_jit_machdep.c b/sys/amd64/amd64/bpf_jit_machdep.c index a5d3b3d..f985ab8 100644 --- a/sys/amd64/amd64/bpf_jit_machdep.c +++ b/sys/amd64/amd64/bpf_jit_machdep.c @@ -53,7 +53,7 @@ __FBSDID("$FreeBSD$"); #include <amd64/amd64/bpf_jit_machdep.h> -bpf_filter_func bpf_jit_compile(struct bpf_insn *, u_int, int *); +bpf_filter_func bpf_jit_compile(struct bpf_insn *, u_int, size_t *, int *); /* * 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, int *mem) +bpf_jit_compile(struct bpf_insn *prog, u_int nins, size_t *size, int *mem) { bpf_bin_stream stream; struct bpf_insn *ins; @@ -481,23 +481,21 @@ bpf_jit_compile(struct bpf_insn *prog, u_int nins, int *mem) #ifndef _KERNEL if (mprotect(stream.ibuf, stream.cur_ip, PROT_READ | PROT_EXEC) != 0) { - munmap(stream.ibuf, BPF_JIT_MAXSIZE); + munmap(stream.ibuf, stream.cur_ip); stream.ibuf = NULL; } #endif + *size = stream.cur_ip; break; } #ifdef _KERNEL - stream.ibuf = (char *)malloc(stream.cur_ip, M_BPFJIT, M_NOWAIT); + stream.ibuf = (char *)contigmalloc(stream.cur_ip, M_BPFJIT, + M_NOWAIT, 0, ~0ULL, 16, 0); if (stream.ibuf == NULL) break; #else - if (stream.cur_ip > BPF_JIT_MAXSIZE) { - stream.ibuf = NULL; - break; - } - stream.ibuf = (char *)mmap(NULL, BPF_JIT_MAXSIZE, + stream.ibuf = (char *)mmap(NULL, stream.cur_ip, PROT_READ | PROT_WRITE, MAP_ANON, -1, 0); if (stream.ibuf == MAP_FAILED) { stream.ibuf = NULL; |