From owner-svn-soc-all@FreeBSD.ORG Wed Aug 13 13:57:03 2014 Return-Path: Delivered-To: svn-soc-all@FreeBSD.org Received: from mx1.freebsd.org (mx1.freebsd.org [8.8.178.115]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTPS id A5DC5EA8 for ; Wed, 13 Aug 2014 13:57:03 +0000 (UTC) Received: from socsvn.freebsd.org (socsvn.freebsd.org [IPv6:2001:1900:2254:206a::50:2]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id 8578A2A6B for ; Wed, 13 Aug 2014 13:57:03 +0000 (UTC) Received: from socsvn.freebsd.org ([127.0.1.124]) by socsvn.freebsd.org (8.14.9/8.14.9) with ESMTP id s7DDv3Ov020132 for ; Wed, 13 Aug 2014 13:57:03 GMT (envelope-from dpl@FreeBSD.org) Received: (from www@localhost) by socsvn.freebsd.org (8.14.9/8.14.9/Submit) id s7DDv3bB020129 for svn-soc-all@FreeBSD.org; Wed, 13 Aug 2014 13:57:03 GMT (envelope-from dpl@FreeBSD.org) Date: Wed, 13 Aug 2014 13:57:03 GMT Message-Id: <201408131357.s7DDv3bB020129@socsvn.freebsd.org> X-Authentication-Warning: socsvn.freebsd.org: www set sender to dpl@FreeBSD.org using -f From: dpl@FreeBSD.org To: svn-soc-all@FreeBSD.org Subject: socsvn commit: r272364 - soc2014/dpl/netmap-ipfwjit/sys/netpfil/ipfw MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-soc-all@freebsd.org X-Mailman-Version: 2.1.18-1 Precedence: list List-Id: SVN commit messages for the entire Summer of Code repository List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 13 Aug 2014 13:57:03 -0000 Author: dpl Date: Wed Aug 13 13:57:02 2014 New Revision: 272364 URL: http://svnweb.FreeBSD.org/socsvn/?view=rev&rev=272364 Log: Finished allocating and initializing variables. Modified: soc2014/dpl/netmap-ipfwjit/sys/netpfil/ipfw/jit.cc Modified: soc2014/dpl/netmap-ipfwjit/sys/netpfil/ipfw/jit.cc ============================================================================== --- soc2014/dpl/netmap-ipfwjit/sys/netpfil/ipfw/jit.cc Wed Aug 13 13:55:48 2014 (r272363) +++ soc2014/dpl/netmap-ipfwjit/sys/netpfil/ipfw/jit.cc Wed Aug 13 13:57:02 2014 (r272364) @@ -18,6 +18,7 @@ extern "C" { #include #include +#include #include #include @@ -55,8 +56,12 @@ BasicBlock *entry; BasicBlock *pullup_failed; BasicBlock *startrules; + BasicBlock *check_tag; // JIT Compiled Vars + // These are the function arguments. + Value *argsptr; + Value *chainptr; // Loop control. Value *match; Value *l; @@ -169,6 +174,17 @@ void setEnv(struct ip_fw_args *args, struct ip_fw_chain *chain) { + // Get function arguments. + // (struct ip_fw_args *, struct ip_fw_chain *) + auto& arglist = func->getArgumentList(); + + // Error + if (arglist.size() != 2) + err(1, "Compilation error: no correct parameters\n"); + + argsptr = &arglist.front(); + chainptr = &arglist.back(); + // Get Type objects int8Ty = Type::getInt8Ty(con); int16Ty = Type::getInt16Ty(con); @@ -206,8 +222,35 @@ #ifdef __FreeBSD__ ucredPtrTy = PointerType::get(ucredTy, 0); #endif + // Get Function defs from bitcode. + // All of them are auxiliary functions. + inspect_pkt = mod->getFunction("inspect_pkt"); + is_icmp_query = mod->getFunction("is_icmp_query"); + flags_match = mod->getFunction("flags_match"); + ipopts_match = mod->getFunction("ipopts_match"); + tcpopts_match = mod->getFunction("tcpopts_match"); + iface_match = mod->getFunction("iface_match"); + verify_path = mod->getFunction("verify_path"); - // Allocate vars. +#ifdef INET6 + icmp6type_match = mod->getFunction("icmp6type_match"); + search_ip6_addr_net = mod->getFunction("search_ip6_addr_net"); + flow6id_match = mod->getFunction("flow6id_match"); + verify_path6 = mod->getFunction("verify_path6"); + is_icmp6_query = mod->getFunction("is_icmp6_query"); + send_reject6 = mod->getFunction("send_reject6"); +#endif /* INET6 */ + + send_reject = mod->getFunction("send_reject"); + check_uidgid = mod->getFunction("check_uidgid"); + set_match = mod->getFunction("set_match"); + jump_fast = mod->getFunction("jump_fast"); + } + + // Allocate and initialize vars. + void + allocaAndInit(struct ip_fw_args *args, struct ip_fw_chain *chain) + { match = irb.CreateAlloca(int32Ty); l = irb.CreateAlloca(int32Ty); done = irb.CreateAlloca(int32Ty); @@ -217,11 +260,13 @@ retval = irb.CreateAlloca(int32Ty); irb.CreateStore(ConstantInt::get(int32Ty, 0), retval); - m = irb.CreateAlloca(mbufPtrTy); // Init: args->m - // XXX m = args->m + // m = args->m (idx: 0) + m = irb.CreateAlloca(mbufPtrTy); + irb.CreateStore(irb.CreateInBoundsGEP(argsptr, ConstantInt::get(int32Ty, 0)), m); + // ip = (struct ip *)((m)->m_data) (idx: 2) ip = irb.CreateAlloca(ipPtrTy); - // XXX ip = (struct ip *)((m)->m_data); + irb.CreateStore(irb.CreateBitCast(irb.CreateInBoundsGEP(argsptr, ConstantInt::get(int32Ty, 2)), ipPtrTy), ip); #ifdef __FreeBSD__ ucred = irb.CreateAlloca(ucredPtrTy); // Init: NULL if type ucred. @@ -244,26 +289,33 @@ ip6f_mf = irb.CreateAlloca(int16Ty); irb.CreateStore(ConstantInt::get(int16Ty, 0), ip6f_mf); + // proto = args->f_id.proto = 0 + // proto = 0; proto = irb.CreateAlloca(int8Ty); irb.CreateStore(ConstantInt::get(int8Ty, 0), proto); - // XXX proto = args->f_id.proto = 0 + // args->f_id.proto = 0 (idx: 6, 5) + irb.CreateStore(ConstantInt::get(int8Ty, 0), irb.CreateInBoundsGEP(argsptr, {ConstantInt::get(int32Ty, 6), ConstantInt::get(int32Ty, 5)} )); src_port = irb.CreateAlloca(int16Ty); irb.CreateStore(ConstantInt::get(int16Ty, 0), src_port); dst_port = irb.CreateAlloca(int16Ty); irb.CreateStore(ConstantInt::get(int16Ty, 0), dst_port); + //src_ip.s_addr = 0; src_ip = irb.CreateAlloca(in_addrTy); - dst_ip = irb.CreateAlloca(in_addrTy); - // XXX + irb.CreateStore(ConstantInt::get(int32Ty, 0), irb.CreateInBoundsGEP(src_ip, ConstantInt::get(int32Ty, 0))); //dst_ip.s_addr = 0; - //src_ip.s_addr = 0; + dst_ip = irb.CreateAlloca(in_addrTy); + irb.CreateStore(ConstantInt::get(int32Ty, 0), irb.CreateInBoundsGEP(dst_ip, ConstantInt::get(int32Ty, 0))); iplen = irb.CreateAlloca(int16Ty); irb.CreateStore(ConstantInt::get(int16Ty, 0), iplen); + // pktlen = m->m_pkthdr.len; + // m_pkthdr is the 6th element (idx: 5) + // len is the 2nd element (idx: 1) pktlen = irb.CreateAlloca(int32Ty); - //XXX pktlen = m->m_pkthdr.len; + irb.CreateStore(ConstantInt::get(int32Ty, 0), irb.CreateInBoundsGEP(m, {ConstantInt::get(int32Ty, 5), ConstantInt::get(int32Ty, 1)} )); etype = irb.CreateAlloca(int16Ty); irb.CreateStore(ConstantInt::get(int32Ty, 0), etype); @@ -286,30 +338,6 @@ irb.CreateStore(ConstantInt::get(int8Ty, 0), icmp6_type); ext_hd = irb.CreateAlloca(int16Ty); irb.CreateStore(ConstantInt::get(int16Ty, 0), ext_hd); - - // Get Function defs from bitcode. - // All of them are auxiliary functions. - inspect_pkt = mod->getFunction("inspect_pkt"); - is_icmp_query = mod->getFunction("is_icmp_query"); - flags_match = mod->getFunction("flags_match"); - ipopts_match = mod->getFunction("ipopts_match"); - tcpopts_match = mod->getFunction("tcpopts_match"); - iface_match = mod->getFunction("iface_match"); - verify_path = mod->getFunction("verify_path"); - -#ifdef INET6 - icmp6type_match = mod->getFunction("icmp6type_match"); - search_ip6_addr_net = mod->getFunction("search_ip6_addr_net"); - flow6id_match = mod->getFunction("flow6id_match"); - verify_path6 = mod->getFunction("verify_path6"); - is_icmp6_query = mod->getFunction("is_icmp6_query"); - send_reject6 = mod->getFunction("send_reject6"); -#endif /* INET6 */ - - send_reject = mod->getFunction("send_reject"); - check_uidgid = mod->getFunction("check_uidgid"); - set_match = mod->getFunction("set_match"); - jump_fast = mod->getFunction("jump_fast"); } void @@ -354,19 +382,18 @@ printfFunc = mod->getFunction("printf"); - // Create first BasicBlocks. + // Create statics BasicBlocks. entry = BasicBlock::Create(con, "entry", func); pullup_failed = BasicBlock::Create(con, "pullup_failed", func); + check_tag = BasicBlock::Create(con, "check_tag", func); startrules = BasicBlock::Create(con, "startrules", func); - // Create the code related to the pullup_failed Basic Block. emit_pullup_failed(); - - // Set the IRBuilder to insert instructions after the entry BB. - irb.SetInsertPoint(entry); + emit_check_tag(); // Get struct types, and store vars - setEnv(args, chain); + setEnv(); + allocaAndInit(args, chain); } ~ipfwJIT() { @@ -393,7 +420,7 @@ { // If it returns one, goto pullup_failed. // Else, goto starrules. - irb.CreateCondBr(irb.CreateICmpEQ(irb.CreateCall(inspect_pkt), ConstantInt::get(int32Ty, 1)), pullup_failed, startrules); + irb.CreateCondBr(irb.CreateICmpEQ(irb.CreateCall(inspect_pkt, {argsptr, ip, m, src_ip, dst_ip, src_port, dst_port, etype, ext_hd, iplen, pktlen, is_ipv4, is_ipv6, hlen, proto, icmp6_type, ip6f_mf, offset, ulp}), ConstantInt::get(int32Ty, 1)), pullup_failed, startrules); return (0); }