From owner-svn-soc-all@FreeBSD.ORG Tue Aug 12 10:37:04 2014 Return-Path: Delivered-To: svn-soc-all@FreeBSD.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTPS id 58700101 for ; Tue, 12 Aug 2014 10:37:04 +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 447B428D3 for ; Tue, 12 Aug 2014 10:37:04 +0000 (UTC) Received: from socsvn.freebsd.org ([127.0.1.124]) by socsvn.freebsd.org (8.14.9/8.14.9) with ESMTP id s7CAb4KD074258 for ; Tue, 12 Aug 2014 10:37:04 GMT (envelope-from dpl@FreeBSD.org) Received: (from www@localhost) by socsvn.freebsd.org (8.14.9/8.14.9/Submit) id s7CAb3if074243 for svn-soc-all@FreeBSD.org; Tue, 12 Aug 2014 10:37:03 GMT (envelope-from dpl@FreeBSD.org) Date: Tue, 12 Aug 2014 10:37:03 GMT Message-Id: <201408121037.s7CAb3if074243@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: r272264 - 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 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: Tue, 12 Aug 2014 10:37:04 -0000 Author: dpl Date: Tue Aug 12 10:37:03 2014 New Revision: 272264 URL: http://svnweb.FreeBSD.org/socsvn/?view=rev&rev=272264 Log: Added the pullup_failed basic block 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 Tue Aug 12 09:48:54 2014 (r272263) +++ soc2014/dpl/netmap-ipfwjit/sys/netpfil/ipfw/jit.cc Tue Aug 12 10:37:03 2014 (r272264) @@ -48,6 +48,11 @@ Type *int32Ty; PointerType *int8PtrTy; + // Basic blocks used + BasicBlock *entry; + BasicBlock *pullup_failed; + BasicBlock *startiter; + // JIT Compiled Vars // Loop control. Value *match; @@ -108,6 +113,9 @@ Function *set_match; Function *jump_fast; + // Not pkg-filtering related funcs. + Function *printf; + // Used structs StructType *ifnetTy; StructType *in_addrTy; @@ -122,7 +130,8 @@ StructType *ucredTy; // Load the bc for JIT compilation. - Module *loadbc(std::string name) + Module * + loadbc(std::string name) { error_code ec = MemoryBuffer::getFile(name, buffer); if (ec) { @@ -141,7 +150,7 @@ } // Create the needed variables to perform pkt filtering. - int + void setEnv(struct ip_fw_args *args, struct ip_fw_chain *chain) { // Get Type objects @@ -265,6 +274,37 @@ return (0); } + void + emit_pullup_failed() + { + GlobalValue *is_verbose, *str; + BasicBlock *print, *ret; + + // VNET_DECLARE(int, fw_verbose); + // #define V_fw_verbose VNET(fw_verbose) + // We should be fine getting that from the Module. + + // pullup_failed: + // if (V_fw_verbose) + // printf("ipfw: pullup failed\n"); + // return (IP_FW_DENY); + + irb.SetInsertPoint(pullup_failed); + is_verbose = mod.getGlobalVariable("fw_verbose"); + str = irb.CreateGlobalString("ipfw: pullup failed\n"); + + // if (V_fw_verbose) + CreateCondBr(CreateICmpEQ(is_verbose, ConstantInt::get(int32Ty, 0)), ret, print); + // printf("ipfw: pullup failed\n"); + irb.SetInsertPoint(print); + irb.CreateCall(printf, str); + irb.CreateBr(ret); + + // return (IP_FW_DENY); + irb.SetInsertPoint(ret); + irb.CreateRet(ConstantInt::get(int32Ty, IP_FW_DENY)); + } + public: ipfwJIT(struct ip_fw_args *args, struct ip_fw_chain *chain): irb(con) { @@ -273,15 +313,22 @@ func = mod->getFunction("ipfw_chk_jit"); func->setLinkage(GlobalValue::ExternalLinkage); - // Create the entry point of the function - BasicBlock *entry = BasicBlock::Create(con, "entry", func); - // Add the entry block to ArrayRef - blocks.push_back(entry); - // Set the IRBuilder to insert instructions after the basic block. + + printf = mod->getFunction("printf"); + + // Create first BasicBlocks. + entry = BasicBlock::Create(con, "entry", func); + pullup_failed = BasicBlock::Create(con, "pullup_failed", func); + startiter = BasicBlock::Create(con, "startiter", 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); + // Get struct types, and store vars setEnv(args, chain); - // Create the code related to the pullup_failed Basic Block. } ~ipfwJIT() {