/* u2_cm_done(): terminate trap.
*/
void
u2_cm_done()
{
  u2_ray kit_r = u2_wire_kit_r(u2_Wire);

  c3_assert(kit_r != 0);

  u2z(u2_kite_tax(kit_r));
  u2z(u2_kite_don(kit_r));
  u2_wire_kit_r(u2_Wire) = u2_kite_par_r(kit_r);

  u2_rl_rfree(u2_Wire, kit_r);
}
/* u2_cm_rind(): open and produce a new jump buffer.
*/
void*
u2_cm_rind()
{
  u2_ray kit_r = u2_rl_ralloc(u2_Wire, c3_wiseof(u2_loom_kite));

  u2_kite_par_r(kit_r) = u2_wire_kit_r(u2_Wire);
  u2_wire_kit_r(u2_Wire) = kit_r;

  //  Save the old stack and actions.
  //
  u2_kite_tax(kit_r) = u2k(u2_wire_tax(u2_Wire));
  u2_kite_don(kit_r) = u2k(u2_wrac_at(u2_Wire, duz.don));

  return u2_at_cord(u2_kite_buf_r(kit_r), c3_wiseof(jmp_buf));
}
u2_noun
u2_cm_bail(c3_l how_l)
{
  u2_ray kit_r = u2_wire_kit_r(u2_Wire);

  if ( u2_yes == u2_Flag_Abort ) {
    if ( c3__fail == how_l ) { c3_assert(0); }
    c3_assert(0);
  }
  u2_tx_sys_bit(u2_Wire, u2_yes);

  // fprintf(stderr, "bail\n");
  // if ( _num == 0 ) { c3_assert(0); } else _num--;

  {
    u2_noun jaq;
    jmp_buf buf_f;

    // Reset the old stack trace, pulling off the local top.
    //
    jaq = u2_cm_wail();

    // Reset the old action trace.
    {
      u2z(u2_wrac_at(u2_Wire, duz.don));
      u2_wrac_at(u2_Wire, duz.don) = u2_kite_don(kit_r);
    }

    // Copy out the jump buffer; free the old kite.
    {
      memcpy((void *)buf_f,
             u2_at_cord(u2_kite_buf_r(kit_r), c3_wiseof(jmp_buf)),
             sizeof(jmp_buf));

      u2_wire_kit_r(u2_Wire) = u2_kite_par_r(kit_r);
      u2_rl_rfree(u2_Wire, kit_r);
    }

    // Longjmp with the how-trace pair.  XX: no workee with 64-bit nouns.
    //
    {
      _longjmp(buf_f, u2nc(how_l, jaq));
    }
  }
  return 0;
}
/* u2_cm_wail(): produce and reset the local trace, without bailing.
*/
u2_noun
u2_cm_wail()
{
  u2_ray  kit_r = u2_wire_kit_r(u2_Wire);
  u2_noun old   = u2_kite_tax(u2_wire_kit_r(u2_Wire));
  u2_noun nuw   = u2_wire_tax(u2_Wire);
  u2_noun jaq;

  jaq = _cm_jack(old, nuw);

  // c3_assert(1 == u2_rl_refs(u2_Wire, old));
  u2_wire_tax(u2_Wire) = old;
  u2_kite_tax(kit_r) = u2k(old);
  // c3_assert(1 == u2_rl_refs(u2_Wire, jaq));

  return jaq;
}
/* u2_cm_bowl(): bail out with preset report.
*/
u2_noun
u2_cm_bowl(u2_noun how)
{
  u2_ray kit_r = u2_wire_kit_r(u2_Wire);

  u2_tx_sys_bit(u2_Wire, u2_yes);

  {
    u2_noun jaq;
    jmp_buf buf_f;

    // Reset the old stack trace, pulling off the local top.
    //
    jaq = u2_cm_wail();

    // Reset the old action trace.
    {
      u2z(u2_wrac_at(u2_Wire, duz.don));
      u2_wrac_at(u2_Wire, duz.don) = u2_kite_don(kit_r);
    }

    // Copy out the jump buffer; free the old kite.
    {
      memcpy((void *)buf_f,
             u2_at_cord(u2_kite_buf_r(kit_r), c3_wiseof(jmp_buf)),
             sizeof(jmp_buf));

      u2_wire_kit_r(u2_Wire) = u2_kite_par_r(kit_r);
      u2_rl_rfree(u2_Wire, kit_r);
    }

    // Longjmp with the how-trace pair.  XX: no workee with 64-bit nouns.
    //
    {
      u2z(jaq);
      _longjmp(buf_f, how);
    }
  }
  return 0;
}
Example #6
0
/* u2_lo_soft(): standard soft wrapper.  unifies unix and nock errors.
**
**  Produces [%$ result] or [%error (list tank)].
*/
u2_noun
u2_lo_soft(u2_reck* rec_u, c3_w sec_w, u2_funk fun_f, u2_noun arg)
{
  u2_noun hoe, pro, rop;

  u2_rl_leap(u2_Wire, c3__rock);

  //  system level setjmp, for signals
  //
  c3_assert(u2_nul == u2_wire_tax(u2_Wire));
  c3_assert(0 == u2_wire_kit_r(u2_Wire));

  //  stop signals
  //
  u2_unix_ef_hold();
  _lo_signal_deep(sec_w);

  if ( 0 != sigsetjmp(Signal_buf, 1) ) {
    u2_noun tax, pre, mok;

    //  return to blank state
    //
    _lo_signal_done();

    //  acquire trace and reset memory
    //
    tax = u2_wire_tax(u2_Wire);
    u2_rl_fall(u2_Wire);
    u2z(arg);

    tax = u2_rl_take(u2_Wire, tax);
    u2_wire_tax(u2_Wire) = u2_nul;
    mok = u2_dc("mook", 2, tax);

    //  other ugly disgusting cleanups
    {
      u2_wire_kit_r(u2_Wire) = 0;

      u2_hevx_be(u2_wire_hev_r(u2_Wire), u2_pryr, god) = 0;
      u2_hevx_at(u2_wire_hev_r(u2_Wire), lad) = 0;
    }

    switch ( Sigcause ) {
      default:            pre = c3__wyrd; break;
      case sig_none:      pre = c3__none; break;
      case sig_overflow:  pre = c3__over; break;
      case sig_interrupt: pre = c3__intr; break;
      case sig_terminate: pre = c3__term; break;
      case sig_memory:    pre = c3__full; break;
      case sig_assert:    pre = c3__lame; break;
      case sig_timer:     fprintf(stderr, "timer!!\r\n"); pre = c3__slow; break;
    }
    rop = u2nc(pre, u2k(u2t(mok)));
    u2z(mok);
    fprintf(stderr, "error computed\r\n");
    return rop;
  }

  if ( 0 != (hoe = u2_cm_trap()) ) {
    u2_noun mok;

    u2_rl_fall(u2_Wire);
    hoe = u2_rl_take(u2_Wire, hoe);
    u2_rl_flog(u2_Wire);

    mok = u2_dc("mook", 2, u2k(u2t(hoe)));
    rop = u2nc(u2k(u2h(hoe)), u2k(u2t(mok)));

    u2z(arg);
    u2z(hoe);
    u2z(mok);
  }
  else {
    u2_noun pro = fun_f(rec_u, arg);

    _lo_signal_done();
    u2_cm_done();

    u2_rl_fall(u2_Wire);
    pro = u2_rl_take(u2_Wire, pro);
    u2_rl_flog(u2_Wire);

    u2z(arg);
    rop = u2nc(u2_blip, pro);
  }
  pro = rop;

  return pro;
}
Example #7
0
File: wire.c Project: MacTop/urbit
/* u2_wr_init():
**
**   Install an empty wire within `hat_r` and `mat_r` in the loom,
**   with memory model `hip`.
**
**   Returns ray to wire, which always equalls the passed `mat_r`.
*/
u2_ray
u2_wr_init(c3_m   hip_m,
           u2_ray hat_r,
           u2_ray mat_r)
{
  u2_ray wir_r;

  wir_r = u2_rl_init(hip_m, hat_r, mat_r);
  u2_rail_hat_r(wir_r) += (c3_wiseof(u2_loom_wire) - c3_wiseof(u2_loom_rail));

#if 1
  u2_wire_bas_r(wir_r) = 0;
#endif

  u2_wire_kit_r(wir_r) = 0;

  u2_cs_init(u2_wire_des_r(wir_r));

  /* Trace stack, garbage.
  */
  {
    u2_wire_tax(wir_r) = u2_nul;
    u2_wire_lan(wir_r) = u2_yes;
  }

  /* Permanent basket = 1/16 of address space.
  */
  {
    u2_ray bas_r;

    bas_r = u2_rl_leap_part(wir_r, c3__sand, 1, 16, 0);
    u2_wire_bas_r(wir_r) = bas_r;

#if 0
    fprintf(stderr, "bas_r %d, hat %d, mat %d, cap %d, rut %d\n",
        bas_r >> LoomPageWords,
        u2_rail_hat_r(bas_r) >> LoomPageWords,
        u2_rail_mat_r(bas_r) >> LoomPageWords,
        u2_rail_cap_r(bas_r) >> LoomPageWords,
        u2_rail_rut_r(bas_r) >> LoomPageWords);

    fprintf(stderr, "wir_r %d, hat %d, mat %d, cap %d, rut %d\n",
        wir_r >> LoomPageWords,
        u2_rail_hat_r(wir_r) >> LoomPageWords,
        u2_rail_mat_r(wir_r) >> LoomPageWords,
        u2_rail_cap_r(wir_r) >> LoomPageWords,
        u2_rail_rut_r(wir_r) >> LoomPageWords);
#endif

    // u2_ba_init(wir_r, 0);
  }

#if 1
  /* Host control.
  */
  {
    u2_ho_push();
  }
#endif

  /* Basic performance tracking.
  */
  {
    u2_wire_bex_r(wir_r) = u2_rl_ralloc(wir_r, c3_wiseof(u2_loom_benx));

    u2_bx_boot(wir_r);
  }

  /* New performance tracking.
  */
  {
    u2_wire_rac_r(wir_r) = u2_tx_init(wir_r);
  }

  /* Global namespace.
  */
  {
    u2_wire_hev_r(wir_r) = u2_hv_init(wir_r);
  }

  /* OS kernel.
  */
  {
    u2_wire_arv_r(wir_r) = u2_rl_ralloc(wir_r, c3_wiseof(u2_reck));
  }

  return wir_r;
}