Exemplo n.º 1
0
/* Useful for printing annotations as comments.  Expects that
 * the annotation is a BrickAnnote. */
  void
Printer::print_annote(Annote *annote)
{
  start_comment();

  IdString name = annote->get_name();

  if (name != k_comment)
    fprintf(out, "[%s", name.chars());

  if (is_kind_of<BrickAnnote>(annote)) {
    BrickAnnote *an = (BrickAnnote *)(annote);
    char *separator = ": ";

    for (Iter<SuifBrick*> iter = an->get_brick_iterator();
        iter.is_valid(); iter.next())
    {
      fputs(separator, out);
      separator = ", ";

      SuifBrick *brick = iter.current();
      if (is_a<IntegerBrick>(brick)) {
        Integer i = ((IntegerBrick*)iter.current())->get_value();
        if (i.is_c_string_int())
          fputs(i.chars(), out);
        else
          fprintf(out, "%ld", i.c_long());
      }
      else if (is_a<StringBrick>(brick)) {
        putc('"', out);
        for (const char *p =
            ((StringBrick*)iter.current())->get_value().c_str();
            *p != '\0'; ++p)
        {
          if (*p == '"' || *p == '\\')
            putc('\\', out);
          putc(*p, out);
        }
        putc('"', out);
      }
      else {
        claim(is_a<SuifObjectBrick>(brick));
        SuifObject *so = ((SuifObjectBrick*)brick)->get_object();
        if (is_kind_of<Type>(so))
          fprint(out, (TypeId)so);
        else {
          const char *kind = so ? get_class_name(so) : "NULL";
          fprintf(out, "<<<%s object>>>", kind);
        }
      }
    }
  } else {
    claim(is_kind_of<GeneralAnnote>(annote), "Unexpected kind of Annote");
  }
  if (name != k_comment)
    fputs("]", out);
  fputs("\n", out);
}
Exemplo n.º 2
0
void boot(int a1, int a2, void *prom)
{
    unsigned sa, len;
    void *dst;
    unsigned char *im;
    unsigned initrd_start, initrd_size;

    printf("coffboot starting: loaded at 0x%p\n", &_start);
    setup_bats(ram_start);

    initrd_size = (char *)(&__ramdisk_end) - (char *)(&__ramdisk_begin);
    if (initrd_size) {
	initrd_start = (ram_end - initrd_size) & ~0xFFF;
	a1 = initrd_start;
	a2 = initrd_size;
	claim(initrd_start, ram_end - initrd_start, 0);
	printf("initial ramdisk moving 0x%x <- 0x%p (%x bytes)\n\r",
	       initrd_start, (char *)(&__ramdisk_begin), initrd_size);
	memcpy((char *)initrd_start, (char *)(&__ramdisk_begin), initrd_size);
	prog_size = initrd_start - prog_start;
    } else
	a2 = 0xdeadbeef;

    im = (char *)(&__image_begin);
    len = (char *)(&__image_end) - (char *)(&__image_begin);
    /* claim 4MB starting at PROG_START */
    claim(prog_start, prog_size, 0);
    map(prog_start, prog_start, prog_size);
    dst = (void *) prog_start;
    if (im[0] == 0x1f && im[1] == 0x8b) {
	/* set up scratch space */
	begin_avail = avail_high = avail_ram = heap;
	end_avail = heap + sizeof(heap);
	printf("heap at 0x%p\n", avail_ram);
	printf("gunzipping (0x%p <- 0x%p:0x%p)...", dst, im, im+len);
	gunzip(dst, prog_size, im, &len);
	printf("done %u bytes\n", len);
	printf("%u bytes of heap consumed, max in use %u\n",
	       avail_high - begin_avail, heap_max);
    } else {
	memmove(dst, im, len);
    }

    flush_cache(dst, len);
    make_bi_recs(((unsigned long) dst + len), "coffboot", _MACH_Pmac,
		    (prog_start + prog_size));

    sa = (unsigned long)prog_start;
    printf("start address = 0x%x\n", sa);

    (*(kernel_start_t)sa)(a1, a2, prom);

    printf("returned?\n");

    pause();
}
Exemplo n.º 3
0
void
chrpboot(int a1, int a2, void *prom)
{
    unsigned sa, len;
    void *dst;
    unsigned char *im;
    unsigned int initrd_size, initrd_start;
    
    printf("chrpboot starting: loaded at 0x%p\n\r", &_start);

    initrd_size = (char *)(&__ramdisk_end) - (char *)(&__ramdisk_begin);
    if (initrd_size) {
	initrd_start = (RAM_END - initrd_size) & ~0xFFF;
	a1 = initrd_start;
	a2 = initrd_size;
	claim(initrd_start, RAM_END - initrd_start, 0);
	printf("initial ramdisk moving 0x%x <- 0x%p (%x bytes)\n\r",
	       initrd_start, (char *)(&__ramdisk_begin), initrd_size);
	memcpy((char *)initrd_start, (char *)(&__ramdisk_begin), initrd_size);
    } else {
	initrd_start = 0;
	initrd_size = 0;
	a2 = 0xdeadbeef;
    }

    im = (char *)(&__image_begin);
    len = (char *)(&__image_end) - (char *)(&__image_begin);
    /* claim 4MB starting at PROG_START */
    claim(PROG_START, PROG_SIZE - PROG_START, 0);
    dst = (void *) PROG_START;
    if (im[0] == 0x1f && im[1] == 0x8b) {
	avail_ram = scratch;
	begin_avail = avail_high = avail_ram;
	end_avail = scratch + sizeof(scratch);
	printf("gunzipping (0x%p <- 0x%p:0x%p)...", dst, im, im+len);
	gunzip(dst, 0x400000, im, &len);
	printf("done %u bytes\n\r", len);
	printf("%u bytes of heap consumed, max in use %u\n\r",
	       avail_high - begin_avail, heap_max);
    } else {
	memmove(dst, im, len);
    }

    flush_cache(dst, len);
    make_bi_recs(((unsigned long) dst + len), "chrpboot", _MACH_chrp,
		    (PROG_START + PROG_SIZE));
    
    sa = (unsigned long)PROG_START;
    printf("start address = 0x%x\n\r", sa);

    (*(void (*)())sa)(a1, a2, prom, initrd_start, initrd_size);

    printf("returned?\n\r");

    pause();
}
Exemplo n.º 4
0
CfgNode*
get_parent_node(PhiNode *phi)
{
    SuifObject *annote = phi->get_parent();
    claim(is_kind_of<SsaPhiAnnote>(annote), "Bad phi-node parent");

    SuifObject *block = static_cast<SsaPhiAnnote*>(annote)->get_parent();
    claim(is_kind_of<CfgNode>(block), "Bad phi-node annote parent");

    return static_cast<CfgNode*>(block);
}
Exemplo n.º 5
0
bool
M2aSuifPass::parse_command_line(TokenStream* command_line_stream)
{
    // set defaults for optional command-line flags
    debuglvl = 0;
    m2a.print_all_notes = false;
    m2a.Gnum = 512;		// in bytes
    m2a.want_stabs = false;    

    bool result = PipelinablePass::parse_command_line(command_line_stream);

    debug(1, "Debug level is %d", debuglvl);
    debug(1, "Gnum = %d", m2a.Gnum);
    if (m2a.print_all_notes)
	debug(1, "Printing all notes");
    if (m2a.want_stabs)
	debug(1, "Printing with stabs information");

    int n = nonprinting_notes_option->get_number_of_values();
    claim((n == 0) || !m2a.print_all_notes, 
	  "cannot specify -noprint with -all_notes");

    // process non-printing notes, if any
    for (int i = 0; i < n; i++) {
	IdString s = nonprinting_notes_option->get_string(i)->get_string();
	nonprinting_notes.insert(s);
	debug(1, "Suppressing `%s' annotations", s.chars());
    }

    int file_count = file_names_option->get_number_of_values();
    int i = 0;

    // Process the input file name, if any.
    if (the_suif_env->get_file_set_block()) {		// expect no input file
	claim(file_count <= 1, "Too many file names: already have input");
    } else {
	claim(file_count > 0, "No input file");
	IdString s = file_names_option->get_string(i++)->get_string();
	the_suif_env->read(s.chars());
    }

    // Process the output file name, if any.
    if (i < file_count) {
	IdString s = file_names_option->get_string(i++)->get_string();
	m2a.out = fopen(s.chars(), "w");
	claim(m2a.out, "Couldn't open %s for writing", s.chars());
    } else {
	m2a.out = stdout;
    }
    claim(i == file_count,
	  "Too many file names: expected %d, got %d", i, file_count);
    return result;
}
Exemplo n.º 6
0
boot(int a1, int a2, void *prom)
{
    int ns, oh, i;
    unsigned sa, len;
    void *dst;
    unsigned char *im;
    unsigned initrd_start, initrd_size;
    
    printf("coffboot starting: loaded at 0x%x\n", _start);
    setup_bats(RAM_START);
    if (initrd_len) {
	initrd_size = initrd_len;
	initrd_start = (RAM_END - initrd_size) & ~0xFFF;
	a1 = initrd_start;
	a2 = initrd_size;
	claim(initrd_start - RAM_START, RAM_END - initrd_start, 0);
	printf("initial ramdisk moving 0x%x <- 0x%x (%x bytes)\n",
	       initrd_start, initrd_data, initrd_size);
	memcpy((char *)initrd_start, initrd_data, initrd_size);
    }
    im = image_data;
    len = image_len;
    /* claim 3MB starting at 0 */
    claim(0, 3 << 20, 0);
    dst = (void *) RAM_START;
    if (im[0] == 0x1f && im[1] == 0x8b) {
	/* claim 512kB for scratch space */
	avail_ram = claim(0, 512 << 10, 0x10) + RAM_START;
	end_avail = avail_ram + (512 << 10);
	printf("avail_ram = %x\n", avail_ram);
	printf("gunzipping (0x%x <- 0x%x:0x%0x)...", dst, im, im+len);
	gunzip(dst, 3 << 20, im, &len);
	printf("done %u bytes\n", len);
    } else {
	memmove(dst, im, len);
    }

    flush_cache(dst, len);
    make_bi_recs((unsigned long)dst + len);
    
    sa = (unsigned long)PROG_START;
    printf("start address = 0x%x\n", sa);

#if 0
    pause();
#endif
    (*(void (*)())sa)(a1, a2, prom);

    printf("returned?\n");

    pause();
}
Exemplo n.º 7
0
boot(int a1, int a2, void *prom)
{
    int ns, oh, i;
    unsigned sa, len;
    void *dst;
    unsigned char *im;
    unsigned initrd_start, initrd_size;
    extern char _start;
    
    printf("chrpboot starting: loaded at 0x%x\n", &_start);
    if (initrd_len) {
	initrd_size = initrd_len;
	initrd_start = (RAM_END - initrd_size) & ~0xFFF;
	a1 = initrd_start;
	a2 = initrd_size;
	claim(initrd_start, RAM_END - initrd_start, 0);
	printf("initial ramdisk moving 0x%x <- 0x%x (%x bytes)\n", initrd_start,
	       initrd_data,initrd_size);
	memcpy((char *)initrd_start, initrd_data, initrd_size);
    }
    im = image_data;
    len = image_len;
    /* claim 3MB starting at PROG_START */
    claim(PROG_START, PROG_SIZE, 0);
    dst = (void *) PROG_START;
    if (im[0] == 0x1f && im[1] == 0x8b) {
	/* claim some memory for scratch space */
	avail_ram = (char *) claim(0, SCRATCH_SIZE, 0x10);
	begin_avail = avail_high = avail_ram;
	end_avail = avail_ram + SCRATCH_SIZE;
	printf("heap at 0x%x\n", avail_ram);
	printf("gunzipping (0x%x <- 0x%x:0x%0x)...", dst, im, im+len);
	gunzip(dst, PROG_SIZE, im, &len);
	printf("done %u bytes\n", len);
	printf("%u bytes of heap consumed, max in use %u\n",
	       avail_high - begin_avail, heap_max);
    } else {
	memmove(dst, im, len);
    }

    flush_cache(dst, len);
    make_bi_recs((unsigned long) dst + len);

    sa = (unsigned long)PROG_START;
    printf("start address = 0x%x\n", sa);

    (*(void (*)())sa)(a1, a2, prom);

    printf("returned?\n");

    pause();
}
Exemplo n.º 8
0
void
M2c::do_proc_def(ProcDef *pd)
{
    const char *cur_pname = (get_name(pd)).chars();
    debug(3, "Processing procedure %s", cur_pname);

    // create a list to hold any .file op's found in the middle
    // of the text segment -- cannot print them there
    List<IdString> file_strings;

    claim(is_kind_of<InstrList>(get_body(pd)), "Body is not an InstrList");
    cur_body = static_cast<InstrList*>(get_body(pd));

    printer->print_proc_begin(pd);

    // print the procedure symbol table
    process_sym_table(pd->get_symbol_table());

    // walk the instruction list once to record all vr defs
    cur_handle = start(cur_body);
    process_vr_decls(pd);
    cur_handle = start(cur_body);

    Instr *mi = *cur_handle;
    if (mi->peek_annote(k_proc_entry) == NULL) {
	// Entry point to procedure is not the first instruction,
	// generate goto to instruction with k_proc_entry note.
	fprintf(out, "\n\tgoto %s_entry_pt;\n", cur_pname);
    } else {
	// simple entry point
	claim(is_null(mi));
	++cur_handle;	
    }

    // output procedure body
    while (cur_handle != end(cur_body)) {
	mi = *cur_handle;

	// do some work on a non-simple procedure entry point
	if (mi->peek_annote(k_proc_entry) != NULL) {
	    // generate label for earlier goto
	    claim(is_null(mi));
	    fprintf(out, "\n%s_entry_pt:\n", cur_pname);
	}
	printer->print_instr(mi);
	++cur_handle;
    }
    // procedure body must not end with a label
    if (is_label(mi))
	fputs("\t/* empty statement */;\n", out);
    fprintf(out, "}\t/* end of %s */\n\n", cur_pname);
}
Exemplo n.º 9
0
const NatSet*
DominanceInfo::reverse_dom_frontier(int n) const
{
    claim(_rdf, "DominanceInfo::reverse_dom_frontier() -- "
	  "run find_reverse_dom_frontier() first");
    return &_rdf[n];
}
Exemplo n.º 10
0
  VarSym*
get_var(Opnd opnd)
{
  IrOpnd *o = opnd;
  claim(is_kind_of<OpndVar>(o), "get_var: not a variable operand");
  return static_cast<OpndVar*>(o)->get_var();
}
Exemplo n.º 11
0
  Context*
find_context(IdString libname)
{
  ContextCacheHandle h = the_context_cache.find(libname);

  if (h != the_context_cache.end())
    return (*h).second;

  ContextCreatorHandle c = the_context_creator_registry.find(libname);

  if (c == the_context_creator_registry.end()) {	// library needs loading
#ifdef NCI_1999
    the_suif_env->get_dll_subsystem()->loadAndInitializeDLL(libname);
#else
    the_suif_env->require_module(libname);
#endif

    c = the_context_creator_registry.find(libname);
    claim(c != the_context_creator_registry.end(),
        "Library `%s' didn't register a context creator", libname.chars());
  }

  Context *result = ((*c).second)();			// create target context
  the_context_cache[libname] = result;
  return result;
}
Exemplo n.º 12
0
bool
DominanceInfo::postdominates(int n_dominator, int n_dominatee) const
{
    claim(_pdoms, "DominanceInfo::postdominates() -- "
		  "run find_postdominators() first");
    return _pdoms[n_dominatee].contains(n_dominator);
}
Exemplo n.º 13
0
 EnhancedMetafile::EnhancedMetafile
     ( const Size& size, const string& path, const string& description )
     : myHandle(claim(::create(
           size.data(), path.data(), description.data(), 0
           )))
 {
 }
Exemplo n.º 14
0
void goto_symext::symex_free(const expr2tc &expr)
{
  const code_free2t &code = to_code_free2t(expr);

  // Trigger 'free'-mode dereference of this pointer. Should generate various
  // dereference failure callbacks.
  expr2tc tmp = code.operand;
  dereference(tmp, false, true);

  address_of2tc addrof(code.operand->type, tmp);
  pointer_offset2tc ptr_offs(pointer_type2(), addrof);
  equality2tc eq(ptr_offs, zero_ulong);
  claim(eq, "Operand of free must have zero pointer offset");

  // Clear the alloc bit, and set the deallocated bit.
  guardt guard;
  type2tc sym_type = type2tc(new array_type2t(get_bool_type(),
                                              expr2tc(), true));
  pointer_object2tc ptr_obj(pointer_type2(), code.operand);

  symbol2tc dealloc_sym(sym_type, deallocd_arr_name);
  index2tc dealloc_index_expr(get_bool_type(), dealloc_sym, ptr_obj);
  expr2tc truth = true_expr;
  symex_assign_rec(dealloc_index_expr, truth, guard);

  symbol2tc valid_sym(sym_type, valid_ptr_arr_name);
  index2tc valid_index_expr(get_bool_type(), valid_sym, ptr_obj);
  expr2tc falsity = false_expr;
  symex_assign_rec(valid_index_expr, falsity, guard);
}
Exemplo n.º 15
0
  OpndHandle
srcs_end(Opnd addr_exp)
{
  claim(is_addr_exp(addr_exp), "srcs_end: not an address expression");
  IrOpnd *o = addr_exp;
  return static_cast<OpndAddrExp*>(o)->srcs().end();
}
Exemplo n.º 16
0
  int
srcs_size(Opnd addr_exp)
{
  claim(is_addr_exp(addr_exp), "srcs_size: not an address expression");
  IrOpnd *o = addr_exp;
  return static_cast<OpndAddrExp*>(o)->get_src_count();
}
Exemplo n.º 17
0
  Sym*
get_sym(Opnd opnd)
{
  IrOpnd *o = opnd;
  claim(is_kind_of<OpndAddrSym>(o), "get_sym: not an address-symbol operand");
  return static_cast<OpndAddrSym*>(o)->get_sym();
}
Exemplo n.º 18
0
  void
set_deref_type(Opnd opnd, TypeId type)
{
  claim(is_addr_exp(opnd));
  IrOpnd *o = opnd;
  static_cast<OpndAddrExp*>(o)->set_deref_type(type);
}
Exemplo n.º 19
0
CfgNode*
DominanceInfo::immed_postdom(int n) const
{
    claim(_ipdom, "DominanceInfo::immed_postdom() -- "
	  "run find_postdominators() first");
    return _ipdom[n];
}
Exemplo n.º 20
0
const NatSet*
DominanceInfo::postdominators(int n) const
{
    claim(_pdoms, "DominanceInfo::postdominators() -- "
	  "run find_postdominators() first");
    return &_pdoms[n];
}
Exemplo n.º 21
0
int
Expire_splay(
	  const Expire_splay_in * in
	, Expire_splay_out * out
	, Expire_splay_atoms * atoms)
{
	State * & state = atoms->state();
	State::ClaimThreadIdRAII claim(*state);
	std::vector<EventBase *> expired;
	std::vector<EventBase *> cancelled;
	time_t present_time = time(NULL);
	if(state->until_time > present_time) {
		sleep(state->until_time - present_time); // not terribly accurate
	}
	state->synch_update_internals(
		  present_time
		, expired
		, cancelled);
	oflux::PushTool<Expire_splay_out> ptool(out);
	std::vector<EventBase *>::iterator itr;
	int push_count = 0;
	for(itr = expired.begin(); itr != expired.end(); ++itr) {
		ptool->timer.reset(*itr);
		ptool->is_cancelled = false;
		ptool.next();
		++push_count;
	}
	for(itr = cancelled.begin(); itr != cancelled.end(); ++itr) {
		ptool->timer.reset(*itr);
		ptool->is_cancelled = true;
		ptool.next();
		++push_count;
	}
	return (push_count > 0 ? 0 : -1);
}
Exemplo n.º 22
0
  void
Printer::print_sym(Sym *s)
{
  if (s == NULL) {
    fputs("<<null>>", out);
  } else {
    SymTable *st = to<SymTable>(s->get_parent());
    IrObject *par = to<IrObject>(st->get_parent());
    if (is_kind_of<ProcDef>(par)) {
      // We make the local symbol name unique by appending
      // the procedure name as a prefix.
      ProcDef *pd = to<ProcDef>(par);
      fprintf(out, "%s.", get_name(pd).chars());
    } else {
      // We assume that we aren't given nested symbol tables, and
      // thus st must be a global symbol table.  The symbol
      // therefore is global and doesn't need a prefix.
      claim(is_global(st));
#ifndef CFE_NUMERIC_SYMS_FIXED
      // Symbols for literals are coming out of CFE with purely numeric names.
      const char *name = get_name(s).chars();
      if (isdigit(name[0]))
        fprintf(out, "__anon.");
#endif
    }
    fprintf(out, "%s", get_name(s).chars());
  }
}
Exemplo n.º 23
0
  int
get_reg(Opnd opnd)
{
  IrOpnd *o = opnd;
  claim(is_kind_of<OpndReg>(o), "get_reg: not a register operand");
  int reg = static_cast<OpndReg*>(o)->get_reg();
  return reg < 0 ? -(reg + 1) : reg;
}
Exemplo n.º 24
0
 Service::Service (
     Database& database, const string& name, const string& path
     )
     : Object(claim(::create(
           database.handle(), name.c_str(), path.c_str()
           )))
 {
 }
Exemplo n.º 25
0
void
Il2cfgSuifPass::do_file_set_block(FileSetBlock *fsb)
{
    claim(o_fname.is_empty() || fsb->get_file_block_count() == 1,
	  "Command-line output file => file set must be a singleton");

    set_opi_predefined_types(fsb);
}
Exemplo n.º 26
0
  Integer
get_immed_integer(Opnd opnd)
{
  IrOpnd *o = opnd;
  claim(is_kind_of<OpndImmedInteger>(o),
      "get_immed_int: not an integer immediate operand");
  return static_cast<OpndImmedInteger*>(o)->get_immed();
}
Exemplo n.º 27
0
  IdString
get_immed_string(Opnd opnd)
{
  IrOpnd *o = opnd;
  claim(is_kind_of<OpndImmedString>(o),
      "get_immed_string: not a string immediate operand");
  return static_cast<OpndImmedString*>(o)->get_immed();
}
Exemplo n.º 28
0
  TypeId
get_deref_type(Opnd opnd)
{
  if (is_addr_sym(opnd)) {
    Sym *sym = get_sym(opnd);
    if (is_kind_of<LabelSym>(sym))
      return NULL;
    else {
      claim(is_kind_of<VarSym>(sym) || is_kind_of<ProcSym>(sym));
      return sym->get_type();
    }
  }
  claim(is_addr_exp(opnd));

  IrOpnd *o = opnd;
  return static_cast<OpndAddrExp*>(o)->get_deref_type();
}
Exemplo n.º 29
0
void
Summarize::do_opt_unit(OptUnit *unit)
{
    const char *unit_name = get_name(unit).chars();
    LineNote note = get_note(unit, k_line);
    claim(!is_null(note), "Missing `line' annotation on unit `%s'", unit_name);

    const char *file_name = note.get_file().chars();

    debug(1, "Processing procedure `%s' from file `%s'", unit_name, file_name);

    // This pass requires a unit's body to be a CFG.  Be sure that a
    // preceding pass has left it in that form.

    claim(is_kind_of<Cfg>(get_body(unit)), "Body is not in CFG form");
    Cfg *unit_cfg = static_cast<Cfg*>(get_body(unit));
    if_debug(5)
	fprint(stdout, unit_cfg, false, true);		// no layout, just code

	for (int i = 0; i < nodes_size(unit_cfg); ++i)
	{
	    CfgNode *block = get_node(unit_cfg, i);
	    for (InstrHandle h = start(block); h != end(block); ++h)
		if (HaltLabelNote note = get_note(*h, k_halt))
		    switch (note.get_kind())
		    {
		      case halt::CBR:
			summarize_branch('c', out, block, note, max_event_id);
			break;
		      case halt::MBR:
			summarize_branch('m', out, block, note, max_event_id);
			break;
		      case halt::ENTRY:
			fprintf(out, "p %ld 1 %d %s:%s\n",
				note.get_unique_id(),
				find_branch_id(block, max_event_id),
				file_name,
				unit_name);
			break;
		      case halt::EXIT:
			fprintf(out, "r %ld 0\n", note.get_unique_id());
			break;
		    }
	}

}
Exemplo n.º 30
0
// will check for an existing stream for the packet, or create a new one if it did not exist
// when creating a new stream, checks for existing partner stream
tcp_reassembler_t::stream_set_t::iterator
tcp_reassembler_t::find_or_create_stream(packet_t *packet, const layer_t *tcplay)
{
	assert(tcplay);

	tcp_stream_t *r = claim();
	auto_release_t<tcp_stream_t> releaser(r); // make sure it will be released if we don't use it

	r->set_src_dst_from_packet(packet, false);
	std::pair<stream_set_t::iterator,bool> ituple = d_streams.insert(*r);

	if (ituple.second) // new stream was inserted
	{
		r->init(d_listener);
		releaser.do_not_release();

		// find partner
		tcp_stream_t *pr = claim();
		auto_release_t<tcp_stream_t> releaser(pr);

		pr->set_src_dst_from_packet(packet, true);
		stream_set_t::iterator pi = d_streams.find(*pr);
		if (pi != d_streams.end() && pi != ituple.first)
		{
			tcp_stream_t *partner = &*pi;

			// if we already trust sequence numbers and the other side happens to
			// have acks they must be close
			const tcphdr &hdr = reinterpret_cast<const tcphdr &>(*tcplay->data());
			bool seqs_are_close = true;

			if (partner->d_smallest_ack != 0 && !is_reasonable_seq(
						seq_nr_t(htonl(hdr.th_seq)), partner->d_smallest_ack))
				seqs_are_close = false;
			if (seqs_are_close && (hdr.th_flags & TH_ACK) && !is_reasonable_seq(
						seq_nr_t(htonl(hdr.th_ack)), partner->d_next_seq))
				seqs_are_close = false;
			if (seqs_are_close)
				r->found_partner(packet, &*pi);
			else
				d_listener->debug_packet(packet, "potential partner found, but sequence numbers too far apart");
		}
	}
	return ituple.first;
}