Example #1
0
// Negation
ref<Constraint> Negation::create(ref<Constraint> c)
{
    if (c->getCType() == CTrue) {
        return _false;
    } else if (c->getCType() == CFalse) {
        return _true;
    } else if (c->getCType() == CNondef) {
        return c;
    } else if (c->getCType() == CNegation) {
        ref<Negation> neg = static_cast<Negation*>(c.get());
        return neg->m_c;
    }

    return new Negation(c);
}
Example #2
0
void ExprSMTLIBPrinter::printConstant(const ref<ConstantExpr> &e) {
  /* Handle simple boolean constants */

  if (e->isTrue()) {
    *p << "true";
    return;
  }

  if (e->isFalse()) {
    *p << "false";
    return;
  }

  /* Handle bitvector constants */

  std::string value;

  /* SMTLIBv2 deduces the bit-width (should be 8-bits in our case)
   * from the length of the string (e.g. zero is #b00000000). LLVM
   * doesn't know about this so we need to pad the printed output
   * with the appropriate number of zeros (zeroPad)
   */
  unsigned int zeroPad = 0;

  switch (cdm) {
  case BINARY:
    e->toString(value, 2);
    *p << "#b";

    zeroPad = e->getWidth() - value.length();

    for (unsigned int count = 0; count < zeroPad; count++)
      *p << "0";

    *p << value;
    break;

  case HEX:
    e->toString(value, 16);
    *p << "#x";

    zeroPad = (e->getWidth() / 4) - value.length();
    for (unsigned int count = 0; count < zeroPad; count++)
      *p << "0";

    *p << value;
    break;

  case DECIMAL:
    e->toString(value, 10);
    *p << "(_ bv" << value << " " << e->getWidth() << ")";
    break;

  default:
    std::cerr << "ExprSMTLIBPrinter::printConstant() : Unexpected Constant "
                 "display mode" << std::endl;
  }
}
Example #3
0
void AES::SetIV(ref<ByteArray> iv)
{
	if (iv->Count() == 16)
		m_iv = iv;
	else
		cdec_throw(CryptoException(EC_CRYPT_InvalidIVSize));
}
void headerField::setValueConst(ref <const headerFieldValue> value)
{
	if (!headerFieldFactory::getInstance()->isValueTypeValid(*this, *value))
		throw exceptions::bad_field_value_type(getName());

	m_value = value->clone().dynamicCast <headerFieldValue>();
}
Example #5
0
void ExprSMTLIBLetPrinter::scan(const ref<Expr> &e) {
  if (isa<ConstantExpr>(e))
    return; // we don't need to scan simple constants

  if (firstEO.insert(e).second) {
    // We've not seen this expression before

    if (const ReadExpr *re = dyn_cast<ReadExpr>(e)) {

      // Attempt to insert array and if array wasn't present before do more
      // things
      if (usedArrays.insert(re->updates.root).second) {

        // check if the array is constant
        if (re->updates.root->isConstantArray())
          haveConstantArray = true;

        // scan the update list
        scanUpdates(re->updates.head);
      }
    }

    // recurse into the children
    Expr *ep = e.get();
    for (unsigned int i = 0; i < ep->getNumKids(); i++)
      scan(ep->getKid(i));
  } else {
    /* We must of seen the expression before. Add it to
     * the set of twoOrMoreOccurances. We don't need to
     * check if the insertion fails.
     */
    twoOrMoreEO.insert(e);
  }
}
Example #6
0
 virtual void get_model(model_ref & mdl) { 
     m_solver->get_model(mdl);
     if (mdl) {
         extend_model(mdl);
         filter_model(mdl);            
     }
 } 
Example #7
0
File: Expr.cpp Project: JianNL/klee
ref<Expr> ExtractExpr::create(ref<Expr> expr, unsigned off, Width w) {
  unsigned kw = expr->getWidth();
  assert(w > 0 && off + w <= kw && "invalid extract");
  
  if (w == kw) {
    return expr;
  } else if (ConstantExpr *CE = dyn_cast<ConstantExpr>(expr)) {
    return CE->Extract(off, w);
  } else {
    // Extract(Concat)
    if (ConcatExpr *ce = dyn_cast<ConcatExpr>(expr)) {
      // if the extract skips the right side of the concat
      if (off >= ce->getRight()->getWidth())
	return ExtractExpr::create(ce->getLeft(), off - ce->getRight()->getWidth(), w);
      
      // if the extract skips the left side of the concat
      if (off + w <= ce->getRight()->getWidth())
	return ExtractExpr::create(ce->getRight(), off, w);

      // E(C(x,y)) = C(E(x), E(y))
      return ConcatExpr::create(ExtractExpr::create(ce->getKid(0), 0, w - ce->getKid(1)->getWidth() + off),
				ExtractExpr::create(ce->getKid(1), off, ce->getKid(1)->getWidth() - off));
    }
  }
  
  return ExtractExpr::alloc(expr, off, w);
}
Example #8
0
File: Expr.cpp Project: JianNL/klee
static ref<Expr> SleExpr_create(const ref<Expr> &l, const ref<Expr> &r) {
  if (l->getWidth() == Expr::Bool) { // !(!l && r)
    return OrExpr::create(l, Expr::createIsZero(r));
  } else {
    return SleExpr::alloc(l, r);
  }
}
Example #9
0
File: Expr.cpp Project: JianNL/klee
static ref<Expr> UleExpr_create(const ref<Expr> &l, const ref<Expr> &r) {
  if (l->getWidth() == Expr::Bool) { // !(l && !r)
    return OrExpr::create(Expr::createIsZero(l), r);
  } else {
    return UleExpr::alloc(l, r);
  }
}
Example #10
0
void
aiosrv::getmsg (aiomsg_t msg)
{
  aiod_op op = buf->getop (msg);

  if (op == AIOD_NOP)
    nop (msg);
  else if (op >= AIOD_UNLINK && op <= AIOD_STATVFS)
    pathop (msg);
  else if (op >= AIOD_OPEN && op <= AIOD_WRITE)
    fhop (msg);
  else if (op == AIOD_FSTAT)
    fstat (msg);
  else if (op >= AIOD_OPENDIR && op <= AIOD_CLOSEDIR)
    dhop (msg);
  else if (op == AIOD_MKDIR) 
    mkdir (msg);
  else
    fatal ("bad opcode %d from client\n", op);

  if (aiodtrace)
    aiod_dump (buf->Xtmpl getptr<void> (msg));
  if (write (fd, &msg, sizeof (msg)) != sizeof (msg)) {
    if (errno != EPIPE)
      fatal ("aiosrv::write: %m\n");
    exit (0);
  }
}
Example #11
0
htmlTextPart::embeddedObject::embeddedObject
	(ref <contentHandler> data, const encoding& enc,
	 const string& id, const mediaType& type)
	: m_data(data->clone().dynamicCast <contentHandler>()),
	  m_encoding(enc), m_id(id), m_type(type)
{
}
Example #12
0
//------------------------------ HELPER FUNCTIONS ---------------------------//
bool ArrayExprHelper::isReadExprAtOffset(ref<Expr> e, const ReadExpr *base,
                                         ref<Expr> offset) {
  const ReadExpr *re = dyn_cast<ReadExpr>(e.get());
  if (!re || (re->getWidth() != Expr::Int8))
    return false;
  return SubExpr::create(re->index, base->index) == offset;
}
ref<Scriptable> MessageScriptType::Construct(ref<ParameterList> p) {
    static Parameter<std::wstring> PPath(L"path", 0);
    std::wstring path = PPath.Get(p, L"");
    ref<Message> m = GC::Hold(new Message(path));

    /* Any extra parameter will be set as parameter in the message
    i.e. you can use new Message("test",1,2,3); */
    unsigned int a = 1;
    while(true) {
        std::wstring argName = Stringify(a);
        ref<Scriptable> arg = p->Get(argName);


        if(arg && arg.IsCastableTo<ScriptAny>()) {
            Any value = ref<ScriptAny>(arg)->Unbox();
            m->SetParameter(a-1, value);
            ++a;
        }
        else {
            break;
        }
    }

    return GC::Hold(new MessageScriptable(m));
}
Example #14
0
 Action visitExprPost(const Expr &e) {
   if (e == *src.get()) {
     return Action::changeTo(dst);
   } else {
     return Action::doChildren();
   }
 }
ref<Expr> BitfieldSimplifier::replaceWithConstant(ref<Expr> e, uint64_t value)
{
    ConstantExpr *ce = dyn_cast<ConstantExpr>(e);
    if(ce && ce->getZExtValue() == value)
        return e;

    // Remove kids from cache
    unsigned numKids = e->getNumKids();
    for(unsigned i = 0; i < numKids; ++i)
        m_bitsInfoCache.erase(e->getKid(i));

    // Remove e from cache
    m_bitsInfoCache.erase(e);

    return ConstantExpr::create(value & ~zeroMask(e->getWidth()), e->getWidth());
}
Example #16
0
File: server.C Project: Amit-DU/dht
ptr<dorpc_arg> vnode_impl::marshal_doRPC (ref<location> l,
    const rpc_program &prog, int procno, ptr<void> in)
{
  //form the transport RPC
  ptr<dorpc_arg> arg = New refcounted<dorpc_arg> ();

  //header

  l->fill_node (arg->dest);
  me_->fill_node (arg->src);
  
  arg->progno = prog.progno;
  arg->procno = procno;

  //marshall the args ourself
  xdrproc_t inproc = prog.tbl[procno].xdr_arg;
  xdrsuio x (XDR_ENCODE);
  if ((!inproc) || (!inproc (x.xdrp (), in))) {
    fatal << "failed to marshall args\n";
    return NULL;
  } else {
    int args_len = x.uio ()->resid ();
    arg->args.setsize (args_len);
    if (args_len > 0)
      x.uio ()->copyout (arg->args.base ());
  }
  return arg;
}
Example #17
0
const bool MDNHelper::needConfirmation(const ref <const message> msg)
{
	ref <const header> hdr = msg->getHeader();

	// No "Return-Path" field
	if (!hdr->hasField(fields::RETURN_PATH))
		return true;

	// More than one address in Disposition-Notification-To
	if (hdr->hasField(fields::DISPOSITION_NOTIFICATION_TO))
	{
		const mailboxList& dnto = *hdr->DispositionNotificationTo()->getValue()
			.dynamicCast <const mailboxList>();

		if (dnto.getMailboxCount() > 1)
			return true;
		else if (dnto.getMailboxCount() == 0)
			return false;

		// Return-Path != Disposition-Notification-To
		const mailbox& mbox = *dnto.getMailboxAt(0);
		const path& rp = *hdr->ReturnPath()->getValue().dynamicCast <const path>();

		if (mbox.getEmail() != rp.getLocalPart() + "@" + rp.getDomain())
			return true;
	}

	// User confirmation not needed
	return false;
}
Example #18
0
static ref<Expr> AShrExpr_create(const ref<Expr> &l, const ref<Expr> &r) {
    if (l->getWidth() == Expr::Bool) { // l
        return l;
    } else {
        return AShrExpr::alloc(l, r);
    }
}
Example #19
0
 void get_model_core(model_ref & mdl) override { 
     m_solver->get_model(mdl);
     if (mdl) {
         model_converter_ref mc = local_model_converter();
         if (mc) (*mc)(mdl);
     }
 } 
Example #20
0
static ref<Expr> SRemExpr_create(const ref<Expr> &l, const ref<Expr> &r) {
    if (l->getWidth() == Expr::Bool) { // r must be 1
        return ConstantExpr::create(0, Expr::Bool);
    } else {
        return SRemExpr::alloc(l, r);
    }
}
Example #21
0
static ref<Expr> LShrExpr_create(const ref<Expr> &l, const ref<Expr> &r) {
    if (l->getWidth() == Expr::Bool) { // l & !r
        return AndExpr::create(l, Expr::createIsZero(r));
    } else {
        return LShrExpr::alloc(l, r);
    }
}
Example #22
0
 virtual void init_pdescrs(cmd_context & ctx, param_descrs & p) {
     m_dl_ctx->get_dl_context().collect_params(p);
     insert_timeout(p);
     p.insert(":print-answer", CPK_BOOL, "(default: false) print answer instance(s) to query.");
     p.insert(":print-certificate", CPK_BOOL, "(default: false) print certificate for reachability or non-reachability.");
     p.insert(":print-statistics",  CPK_BOOL, "(default: false) print statistics.");
 }
Example #23
0
static ref<Expr> SDivExpr_create(const ref<Expr> &l, const ref<Expr> &r) {
    if (l->getWidth() == Expr::Bool) { // r must be 1
        return l;
    } else {
        return SDivExpr::alloc(l, r);
    }
}
Example #24
0
File: write.C Project: fd0/lbfs
  void
  commit_reply(time_t rqtime, ref<commit3args> arg,
               ref<ex_commit3res> res, clnt_stat err) {
    outstanding_writes--;
    if (!err && !res->status) {
      srv->getxattr (rqtime, NFSPROC3_COMMIT, 0, arg, res);
      if (res->resok->file_wcc.before.present &&
	  res->resok->file_wcc.after.present) {
        if ((res->resok->file_wcc.before.attributes)->size == fa.size &&
	    (res->resok->file_wcc.before.attributes)->mtime == fa.mtime) {
	  ex_fattr3 *f = res->resok->file_wcc.after.attributes;
	  fa = *reinterpret_cast<fattr3 *> (f);
	}
	else {
	  warn << "wcc check failed: reply out of order, or conflict\n";
          warn << "commit wcc failed: "
	       << fa.size << ":" << fa.mtime.seconds << ":"
	       << fa.ctime.seconds << " -- "
	       << (res->resok->file_wcc.before.attributes)->size << ":"
	       << (res->resok->file_wcc.before.attributes)->mtime.seconds << ":"
	       << "\n";
	}
      }
    }
    if (!callback && !err && res->status == NFS3_OK) {
      ok();
      return;
    }
    if (!err)
      warn << "final commit failed: " << res->status << "\n";
    else
      warn << "final commit failed: " << err << "\n";
    fail();
  }
Example #25
0
File: write.C Project: fd0/lbfs
  void
  write_reply(time_t rqtime, ref<write3args> arg,
              ref<ex_write3res> res, clnt_stat err) {
    outstanding_writes--;
    if (!err) {
      srv->getxattr (rqtime, NFSPROC3_WRITE, 0, arg, res);
      if (res->resok->file_wcc.before.present &&
	  res->resok->file_wcc.after.present) {
        if ((res->resok->file_wcc.before.attributes)->size == fa.size &&
	    (res->resok->file_wcc.before.attributes)->mtime == fa.mtime) {
	  ex_fattr3 *f = res->resok->file_wcc.after.attributes;
	  fa = *reinterpret_cast<fattr3 *> (f);
	}
	else {
	  warn << "wcc check failed: reply out of order, or conflict\n";
          warn << "write wcc failed: "
	       << fa.size << ":" << fa.mtime.seconds << ":"
	       << fa.ctime.seconds << " -- "
	       << (res->resok->file_wcc.before.attributes)->size << ":"
	       << (res->resok->file_wcc.before.attributes)->mtime.seconds << ":"
	       << "\n";
	}
      }
    }
    if (!callback && !err && res->status == NFS3_OK) {
      do_write();
      ok();
      return;
    }
    warn << "write failed\n";
    fail();
  }
Example #26
0
void ShowSocket::SendSetClientAddress(ref<BasicClient> client, std::wstring na) {
	ThreadLock lock(&_lock);
	ref<Message> stream = GC::Hold(new Message(ActionSetAddress));
	stream->Add(client->GetInstanceID());
	stream->Add<std::wstring>(na);
	Send(stream, true);
}
Example #27
0
    lbool get_consequences_core(expr_ref_vector const& asms, expr_ref_vector const& vars, expr_ref_vector& consequences) override {
        datatype_util dt(m);
        bv_util bv(m);
        expr_ref_vector bvars(m), conseq(m), bounds(m);

        // ensure that enumeration variables that 
        // don't occur in the constraints
        // are also internalized.
        for (expr* v : vars) {
            expr_ref tmp(m.mk_eq(v, v), m);
            proof_ref proof(m);
            m_rewriter(tmp, tmp, proof);            
        }
        m_rewriter.flush_side_constraints(bounds);
        m_solver->assert_expr(bounds);

        // translate enumeration constants to bit-vectors.
        for (expr* v : vars) {
            func_decl* f = nullptr;
            if (is_app(v) && is_uninterp_const(v) && m_rewriter.enum2bv().find(to_app(v)->get_decl(), f)) {
                bvars.push_back(m.mk_const(f));
            }
            else {
                bvars.push_back(v);
            }
        }
        lbool r = m_solver->get_consequences(asms, bvars, consequences);

        // translate bit-vector consequences back to enumeration types
        for (unsigned i = 0; i < consequences.size(); ++i) {
            expr* a = nullptr, *b = nullptr, *u = nullptr, *v = nullptr;
            func_decl* f;
            rational num;
            unsigned bvsize;
            VERIFY(m.is_implies(consequences[i].get(), a, b));
            if (m.is_eq(b, u, v) && is_uninterp_const(u) && m_rewriter.bv2enum().find(to_app(u)->get_decl(), f) && bv.is_numeral(v, num, bvsize)) {
                SASSERT(num.is_unsigned());
                expr_ref head(m);
                ptr_vector<func_decl> const& enums = *dt.get_datatype_constructors(f->get_range());
                if (enums.size() > num.get_unsigned()) {
                    head = m.mk_eq(m.mk_const(f), m.mk_const(enums[num.get_unsigned()]));
                    consequences[i] = m.mk_implies(a, head);
                }
            }
        }
        return r;
    }
Example #28
0
void
filesrv::gotrdres (ref<erraccum> ea, ref<readdir3res> res,
		   int i, bool mp, clnt_stat stat)
{
  str path (strbuf ("readdir: ")
	    << (mp ? fstab[i].path_mntpt : fstab[i].path_root));
  if (!resok (ea, path, stat2str (res->status, stat)))
    return;

  entry3 *ep = res->resok->reply.entries;
  if (ep)
    for (;;) {
      if (ep->name == "..") {
	if (mp)
	  fstab[i].fileid_mntpt_dd = ep->fileid;
	else
	  fstab[i].fileid_root_dd = ep->fileid;
	return;
      }
      entry3 *nep = ep->nextentry;
      if (!nep)
	break;
      ep = nep;
    }

  if (res->resok->reply.eof) {
    warn << path << ": could not find \"..\"\n";
    ea->seterr ();
    return;
  }
  else if (!ep) {
    warn << path << ": zero entry non-EOF reply from kernel\n";
    ea->seterr ();
    return;
  }

  readdir3args arg;
  arg.dir = mp ? fstab[i].fh_mntpt : fstab[i].fh_root;
  arg.cookie = ep->cookie;
  arg.cookieverf = res->resok->cookieverf;
  arg.count = 8192;

  aclnt *c = mp ? fstab[i].parent->c : fstab[i].c;
  c->call (NFSPROC3_READDIR, &arg, res,
	   wrap (this, &filesrv::gotrdres, ea, res, i, mp),
	   auth_default);
}
Example #29
0
    virtual void execute(cmd_context& ctx) {
        if (m_target == 0) {
            throw cmd_exception("invalid query command, argument expected");
        }
        datalog::context& dlctx = m_dl_ctx->get_dl_context();
        set_background(ctx);        
        dlctx.updt_params(m_params);
        unsigned timeout   = m_params.get_uint(":timeout", UINT_MAX);
        cancel_eh<datalog::context> eh(dlctx);
        lbool status = l_undef;
        {
            scoped_ctrl_c ctrlc(eh);
            scoped_timer timer(timeout, &eh);
            cmd_context::scoped_watch sw(ctx);
            try {
                status = dlctx.query(m_target);
            }
            catch (z3_error & ex) {
                throw ex;
            }
            catch (z3_exception& ex) {
                ctx.regular_stream() << "(error \"query failed: " << ex.msg() << "\")" << std::endl;
            }
            dlctx.cleanup();
        }
        switch (status) {
        case l_false:
            ctx.regular_stream() << "unsat\n";
            print_certificate(ctx);
            break;
        case l_true: 
            ctx.regular_stream() << "sat\n";
            print_answer(ctx);
            print_certificate(ctx);
            break;
        case l_undef: 
            ctx.regular_stream() << "unknown\n";
            switch(dlctx.get_status()) {
            case datalog::INPUT_ERROR:
                break;
                
            case datalog::MEMOUT:
                ctx.regular_stream() << "memory bounds exceeded\n";
                break;

            case datalog::TIMEOUT:
                ctx.regular_stream() << "timeout\n";
                break;
                
            case datalog::OK: 
                break;
            default:
                UNREACHABLE();
            }
            break;
        }
        print_statistics(ctx);
        m_target = 0;
    }
Example #30
0
void
sfskey_kill (int argc, char **argv)
{
  nularg (argc, argv);
  if (aconn->ccd (false)) {
    int res;
    if (clnt_stat err = aconn->ccd ()->scall (AGENT_KILL, NULL, &res))
      fatal << "sfscd: " << err << "\n";
    else if (res)
      fatal << "sfscd: " << strerror (res) << "\n";
  }
  else if (clnt_stat err = aconn->cagent_ctl ()->scall (AGENTCTL_KILL,
							NULL, NULL))
    if (err != RPC_CANTRECV)
      fatal << "agent: " << err << "\n";
  exit (0);
}