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