Home | History | Annotate | Line # | Download | only in net
bpfjit.h revision 1.1.6.1
      1  1.1.6.1  rmind /*	$NetBSD: bpfjit.h,v 1.1.6.1 2014/05/18 17:46:12 rmind Exp $	*/
      2      1.1  alnsn 
      3      1.1  alnsn /*-
      4      1.1  alnsn  * Copyright (c) 2011-2012 Alexander Nasonov.
      5      1.1  alnsn  * All rights reserved.
      6      1.1  alnsn  *
      7      1.1  alnsn  * Redistribution and use in source and binary forms, with or without
      8      1.1  alnsn  * modification, are permitted provided that the following conditions
      9      1.1  alnsn  * are met:
     10      1.1  alnsn  *
     11      1.1  alnsn  * 1. Redistributions of source code must retain the above copyright
     12      1.1  alnsn  *    notice, this list of conditions and the following disclaimer.
     13      1.1  alnsn  * 2. Redistributions in binary form must reproduce the above copyright
     14      1.1  alnsn  *    notice, this list of conditions and the following disclaimer in
     15      1.1  alnsn  *    the documentation and/or other materials provided with the
     16      1.1  alnsn  *    distribution.
     17      1.1  alnsn  *
     18      1.1  alnsn  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
     19      1.1  alnsn  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
     20      1.1  alnsn  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
     21      1.1  alnsn  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE
     22      1.1  alnsn  * COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
     23      1.1  alnsn  * INCIDENTAL, SPECIAL, EXEMPLARY OR CONSEQUENTIAL DAMAGES (INCLUDING,
     24      1.1  alnsn  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
     25      1.1  alnsn  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
     26      1.1  alnsn  * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
     27      1.1  alnsn  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
     28      1.1  alnsn  * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     29      1.1  alnsn  * SUCH DAMAGE.
     30      1.1  alnsn  */
     31      1.1  alnsn 
     32      1.1  alnsn #ifndef _NET_BPFJIT_H_
     33      1.1  alnsn #define _NET_BPFJIT_H_
     34      1.1  alnsn 
     35      1.1  alnsn #ifndef _KERNEL
     36      1.1  alnsn #include <stddef.h>
     37      1.1  alnsn #include <stdint.h>
     38      1.1  alnsn #endif
     39      1.1  alnsn 
     40      1.1  alnsn #include <sys/types.h>
     41      1.1  alnsn 
     42      1.1  alnsn #ifdef __linux
     43      1.1  alnsn #include <pcap-bpf.h>
     44      1.1  alnsn #else
     45      1.1  alnsn #include <net/bpf.h>
     46      1.1  alnsn #endif
     47      1.1  alnsn 
     48      1.1  alnsn /*
     49      1.1  alnsn  * RETURN value and arguments of a function generated by sljit have sljit_uw
     50      1.1  alnsn  * type which can have a greater width than arguments below. In such cases,
     51      1.1  alnsn  * we rely on the fact that calling conventions use same registers for
     52      1.1  alnsn  * smaller types.
     53      1.1  alnsn  * SLJIT_MOV_UI is passed to sljit_emit_return() to make sure that the
     54      1.1  alnsn  * return value is truncated to unsigned int.
     55      1.1  alnsn  */
     56  1.1.6.1  rmind typedef unsigned int (*bpfjit_func_t)(const uint8_t *,
     57      1.1  alnsn     unsigned int, unsigned int);
     58      1.1  alnsn 
     59  1.1.6.1  rmind bpfjit_func_t bpfjit_generate_code(bpf_ctx_t *, struct bpf_insn *, size_t);
     60  1.1.6.1  rmind void bpfjit_free_code(bpfjit_func_t);
     61      1.1  alnsn 
     62      1.1  alnsn #ifdef _KERNEL
     63  1.1.6.1  rmind struct bpfjit_ops {
     64  1.1.6.1  rmind 	bpfjit_func_t (*bj_generate_code)(bpf_ctx_t *, struct bpf_insn *, size_t);
     65  1.1.6.1  rmind 	void (*bj_free_code)(bpfjit_func_t);
     66      1.1  alnsn };
     67      1.1  alnsn 
     68      1.1  alnsn extern struct bpfjit_ops bpfjit_module_ops;
     69      1.1  alnsn #endif
     70      1.1  alnsn 
     71      1.1  alnsn #endif /* !_NET_BPFJIT_H_ */
     72