Changeset View
Changeset View
Standalone View
Standalone View
head/sys/amd64/amd64/bpf_jit_machdep.c
Show All 38 Lines | |||||
#include <sys/param.h> | #include <sys/param.h> | ||||
#include <sys/systm.h> | #include <sys/systm.h> | ||||
#include <sys/kernel.h> | #include <sys/kernel.h> | ||||
#include <sys/malloc.h> | #include <sys/malloc.h> | ||||
#include <sys/mbuf.h> | #include <sys/mbuf.h> | ||||
#include <sys/socket.h> | #include <sys/socket.h> | ||||
#include <net/if.h> | #include <net/if.h> | ||||
#include <vm/vm.h> | |||||
#include <vm/vm_extern.h> | |||||
#include <vm/vm_kern.h> | |||||
#else | #else | ||||
#include <stdlib.h> | #include <stdlib.h> | ||||
#include <string.h> | #include <string.h> | ||||
#include <sys/mman.h> | #include <sys/mman.h> | ||||
#include <sys/param.h> | #include <sys/param.h> | ||||
#endif | #endif | ||||
#include <sys/types.h> | #include <sys/types.h> | ||||
▲ Show 20 Lines • Show All 542 Lines • ▼ Show 20 Lines | #endif | ||||
ins++; | ins++; | ||||
} | } | ||||
if (pass > 0) | if (pass > 0) | ||||
continue; | continue; | ||||
*size = stream.cur_ip; | *size = stream.cur_ip; | ||||
#ifdef _KERNEL | #ifdef _KERNEL | ||||
/* | stream.ibuf = malloc(*size, M_BPFJIT, M_EXEC | M_NOWAIT); | ||||
* We cannot use malloc(9) because DMAP is mapped as NX. | |||||
*/ | |||||
stream.ibuf = (void *)kmem_malloc(kernel_arena, *size, | |||||
M_NOWAIT); | |||||
if (stream.ibuf == NULL) | if (stream.ibuf == NULL) | ||||
break; | break; | ||||
#else | #else | ||||
stream.ibuf = mmap(NULL, *size, PROT_READ | PROT_WRITE, | stream.ibuf = mmap(NULL, *size, PROT_READ | PROT_WRITE, | ||||
MAP_ANON, -1, 0); | MAP_ANON, -1, 0); | ||||
if (stream.ibuf == MAP_FAILED) { | if (stream.ibuf == MAP_FAILED) { | ||||
stream.ibuf = NULL; | stream.ibuf = NULL; | ||||
break; | break; | ||||
Show All 31 Lines | #ifndef _KERNEL | ||||
if (stream.ibuf != NULL && | if (stream.ibuf != NULL && | ||||
mprotect(stream.ibuf, *size, PROT_READ | PROT_EXEC) != 0) { | mprotect(stream.ibuf, *size, PROT_READ | PROT_EXEC) != 0) { | ||||
munmap(stream.ibuf, *size); | munmap(stream.ibuf, *size); | ||||
stream.ibuf = NULL; | stream.ibuf = NULL; | ||||
} | } | ||||
#endif | #endif | ||||
return ((bpf_filter_func)(void *)stream.ibuf); | return ((bpf_filter_func)(void *)stream.ibuf); | ||||
} | |||||
void | |||||
bpf_jit_free(void *func, size_t size) | |||||
{ | |||||
#ifdef _KERNEL | |||||
kmem_free(kernel_arena, (vm_offset_t)func, size); | |||||
#else | |||||
munmap(func, size); | |||||
#endif | |||||
} | } |