Merge branch 'cc-release' of https://github.com/urbit/urbit into bs/uterm

This commit is contained in:
Benjamin Summers 2019-05-05 11:53:00 -07:00
commit 88f1bc5eeb
7 changed files with 123 additions and 525 deletions

View File

@ -4,21 +4,15 @@
*/
/** System management.
**/
/* u3m_boot(): start the u3 system.
*/
void
u3m_boot(c3_o nuu_o, c3_o bug_o, c3_c* dir_c, c3_c *pil_c, c3_c *url_c, c3_c *arv_c);
/* u3m_boot_new(): start the u3 system (new). return next event,
** starting from 1.
/* u3m_boot(): start the u3 system. return next event, starting from 1.
*/
c3_d
u3m_boot_new(c3_c* dir_c);
u3m_boot(c3_c* dir_c);
/* u3m_boot_pier(): start without checkpointing.
/* u3m_boot_lite(): start without checkpointing.
*/
c3_d
u3m_boot_pier(void);
u3m_boot_lite(void);
/* u3m_bail(): bail out. Does not return.
**

View File

@ -15,9 +15,6 @@
u3_noun sen; // instance string
u3_noun our; // identity
u3_noun fak; // c3y is fake
u3_noun sys; // system pill
u3_noun roc; // kernel core
} u3v_arvo;
@ -39,36 +36,16 @@
/** Functions.
**/
/* u3v_do(): use a kernel function.
*/
u3_noun
u3v_do(const c3_c* txt_c, u3_noun arg);
/* u3v_boot(): evaluate boot sequence, making a kernel
*/
void
c3_o
u3v_boot(u3_noun eve);
/* u3v_boot_lite(): light bootstrap sequence, just making a kernel.
*/
void
c3_o
u3v_boot_lite(u3_noun lit);
/* u3v_start(): start time.
*/
void
u3v_start(u3_noun now);
/* u3v_arm(): load a kernel arm.
*/
u3_noun
u3v_arm(const c3_c* txt_c);
/* u3v_pike(): poke with floating core.
*/
u3_noun
u3v_pike(u3_noun ovo, u3_noun cor);
/* u3v_do(): use a kernel function.
*/
u3_noun
@ -119,11 +96,6 @@
void
u3v_plan(u3_noun pax, u3_noun fav);
/* u3v_plow(): queue multiple ova (external).
*/
void
u3v_plow(u3_noun ova);
/* u3v_mark(): mark arvo kernel.
*/
c3_w

View File

@ -1206,7 +1206,7 @@ u3m_soft(c3_w sec_w,
//
if ( 0 == u3A->roc ) {
u3z(why);
return u3nc(2, u3_nul);
return u3nc(c3__fail, u3_nul);
}
else {
u3_noun tax, cod, pro, mok;
@ -1590,7 +1590,8 @@ u3m_init(void)
-1, 0);
u3l_log("boot: mapping %dMB failed\r\n", (len_w / (1024 * 1024)));
u3l_log("see urbit.org/docs/getting-started#swap for adding swap space\r\n");
u3l_log("see urbit.org/docs/getting-started/installing-urbit/#swap"
"for adding swap space\r\n");
if ( -1 != (c3_ps)map_v ) {
u3l_log("if porting to a new platform, try U3_OS_LoomBase %p\r\n",
dyn_v);
@ -1602,289 +1603,16 @@ u3m_init(void)
}
}
/* _cm_init_new(): start the environment.
*/
void
_cm_init_new(void)
{
_cm_limits();
_cm_signals();
/* Make sure GMP uses our malloc.
*/
mp_set_memory_functions(u3a_malloc, u3a_realloc2, u3a_free2);
/* Map at fixed address.
*/
{
c3_w len_w = u3a_bytes;
void* map_v;
map_v = mmap((void *)u3_Loom,
len_w,
(PROT_READ | PROT_WRITE),
(MAP_ANON | MAP_FIXED | MAP_PRIVATE),
-1, 0);
if ( -1 == (c3_ps)map_v ) {
void* dyn_v = mmap((void *)0,
len_w,
PROT_READ,
MAP_ANON | MAP_PRIVATE,
-1, 0);
u3l_log("boot: mapping %dMB failed\r\n", (len_w / (1024 * 1024)));
u3l_log("see urbit.org/docs/using/install to add swap space\r\n");
if ( -1 != (c3_ps)map_v ) {
u3l_log("if porting to a new platform, try U3_OS_LoomBase %p\r\n",
dyn_v);
}
exit(1);
}
u3l_log("loom: mapped %dMB\r\n", len_w >> 20);
}
}
// XX orphaned, find a way to restore
#if 0
/* _get_cmd_output(): Run a shell command and capture its output.
Exits with an error if the command fails or produces no output.
The 'out_c' parameter should be an array of sufficient length to hold
the command's output, up to a max of len_c characters.
*/
static void
_get_cmd_output(c3_c *cmd_c, c3_c *out_c, c3_w len_c)
{
FILE *fp = popen(cmd_c, "r");
if ( NULL == fp ) {
u3l_log("'%s' failed\n", cmd_c);
exit(1);
}
if ( NULL == fgets(out_c, len_c, fp) ) {
u3l_log("'%s' produced no output\n", cmd_c);
exit(1);
}
pclose(fp);
}
/* _arvo_hash(): get a shortened hash of the last git commit
that modified the sys/ directory in arvo.
hax_c must be an array with length >= 11.
*/
static void
_arvo_hash(c3_c *out_c, c3_c *arv_c)
{
c3_c cmd_c[2048];
sprintf(cmd_c, "git -C %s log -1 HEAD --format=%%H -- sys/", arv_c);
_get_cmd_output(cmd_c, out_c, 11);
out_c[10] = 0; // end with null-byte
}
/* _git_pill_url(): produce a URL from which to download a pill
based on the location of an arvo git repository.
*/
static void
_git_pill_url(c3_c *out_c, c3_c *arv_c)
{
c3_c hax_c[11];
assert(NULL != arv_c);
if ( 0 != system("which git >> /dev/null") ) {
u3l_log("Could not find git executable\n");
exit(1);
}
_arvo_hash(hax_c, arv_c);
sprintf(out_c, "https://bootstrap.urbit.org/git-%s.pill", hax_c);
}
#endif
// XX deprecated, remove
#if 0
/* _boot_home(): create ship directory.
*/
static void
_boot_home(c3_c *dir_c, c3_c *pil_c, c3_c *url_c, c3_c *arv_c)
{
c3_c* nam_c = "urbit.pill";
c3_c ful_c[2048];
/* Create subdirectories. */
{
mkdir(dir_c, 0700);
snprintf(ful_c, 2048, "%s/.urb", dir_c);
mkdir(ful_c, 0700);
snprintf(ful_c, 2048, "%s/.urb/get", dir_c);
mkdir(ful_c, 0700);
snprintf(ful_c, 2048, "%s/.urb/put", dir_c);
mkdir(ful_c, 0700);
snprintf(ful_c, 2048, "%s/.urb/sis", dir_c);
mkdir(ful_c, 0700);
}
/* Copy urbit.pill. */
{
{
struct stat s;
snprintf(ful_c, 2048, "%s/.urb/%s", dir_c, nam_c);
if ( stat(ful_c, &s) == 0 ) {
/* we're in a "logical boot". awful hack, but bail here */
u3l_log("%s confirmed to exist\r\n", ful_c);
return;
}
}
/* Copy local pill file. */
if ( pil_c != 0 ) {
snprintf(ful_c, 2048, "cp %s %s/.urb/%s",
pil_c, dir_c, nam_c);
u3l_log("%s\r\n", ful_c);
if ( 0 != system(ful_c) ) {
u3l_log("could not %s\n", ful_c);
exit(1);
}
}
/* Fetch remote pill over HTTP. */
else {
CURL *curl;
CURLcode result;
FILE *file;
c3_c pil_c[2048];
long cod_l;
/* use arvo git hash and branch for pill url unless overridden */
if ( NULL == url_c ) {
url_c = pil_c;
_git_pill_url(url_c, arv_c);
}
snprintf(ful_c, 2048, "%s/.urb/urbit.pill", dir_c);
u3l_log("fetching %s to %s\r\n", url_c, ful_c);
if ( !(curl = curl_easy_init()) ) {
u3l_log("failed to initialize libcurl\n");
exit(1);
}
if ( !(file = fopen(ful_c, "w")) ) {
u3l_log("failed to open %s\n", ful_c);
exit(1);
}
curl_easy_setopt(curl, CURLOPT_URL, url_c);
curl_easy_setopt(curl, CURLOPT_WRITEDATA, file);
result = curl_easy_perform(curl);
curl_easy_getinfo(curl, CURLINFO_RESPONSE_CODE, &cod_l);
fclose(file);
if ( CURLE_OK != result ) {
u3l_log("failed to fetch %s: %s\n",
url_c, curl_easy_strerror(result));
u3l_log("please fetch it manually and specify the location with -B\n");
exit(1);
}
if ( 300 <= cod_l ) {
u3l_log("error fetching %s: HTTP %ld\n", url_c, cod_l);
u3l_log("please fetch it manually and specify the location with -B\n");
exit(1);
}
curl_easy_cleanup(curl);
}
}
}
#endif
// XX deprecated, remove
#if 0
/* u3m_boot(): start the u3 system (old).
*/
void
u3m_boot(c3_o nuu_o, c3_o bug_o, c3_c* dir_c,
c3_c *pil_c, c3_c *url_c, c3_c *arv_c)
{
/* Activate the loom.
*/
u3m_init();
/* Activate the storage system.
*/
nuu_o = u3e_live(nuu_o, dir_c);
/* Activate tracing.
*/
u3t_init();
/* Construct or activate the allocator.
*/
u3m_pave(nuu_o, bug_o);
/* Initialize the jet system.
*/
u3j_boot(nuu_o);
/* Install or reactivate the kernel.
*/
if ( _(nuu_o) ) {
c3_c ful_c[2048];
_boot_home(dir_c, pil_c, url_c, arv_c);
snprintf(ful_c, 2048, "%s/.urb/urbit.pill", dir_c);
u3l_log("boot: loading %s\r\n", ful_c);
{
u3_noun pil = u3m_file(ful_c);
u3_noun sys, bot;
{
u3_noun pro = u3m_soft(0, u3ke_cue, u3k(pil));
if ( 0 != u3h(pro) ) {
u3l_log("boot: failed: unable to parse pill\r\n");
exit(1);
}
sys = u3k(u3t(pro));
u3z(pro);
}
// XX confirm trel of lists?
//
if ( c3n == u3r_trel(sys, &bot, 0, 0) ) {
u3l_log("boot: failed: obsolete pill structure\r\n");
exit(1);
}
u3v_boot(u3k(bot));
u3z(sys);
u3z(pil);
}
}
else {
u3v_hose();
u3j_ream();
u3n_ream();
}
}
#endif
/* u3m_boot_new(): start the u3 system (new). return next event,
** starting from 1.
/* u3m_boot(): start the u3 system. return next event, starting from 1.
*/
c3_d
u3m_boot_new(c3_c* dir_c)
u3m_boot(c3_c* dir_c)
{
c3_o nuu_o;
/* Activate the loom.
*/
_cm_init_new();
u3m_init();
/* Activate the storage system.
*/
@ -1926,14 +1654,14 @@ u3m_boot_new(c3_c* dir_c)
}
}
/* u3m_boot_pier(): start without checkpointing.
/* u3m_boot_lite(): start without checkpointing.
*/
c3_d
u3m_boot_pier(void)
u3m_boot_lite(void)
{
/* Activate the loom.
*/
_cm_init_new();
u3m_init();
/* Activate tracing.
*/

View File

@ -77,7 +77,7 @@ u3t_heck(u3_atom cog)
u3R = &(u3H->rod_u);
{
if ( 0 == u3R->pro.day ) {
u3R->pro.day = u3v_do("doss", 0);
u3R->pro.day = u3do("doss", 0);
}
u3R->pro.day = u3dc("pi-heck", u3i_string(str_c), u3R->pro.day);
}

View File

@ -8,6 +8,87 @@
#define _CVX_POKE 47
#define _CVX_PEEK 46
/* _cv_life(): execute initial lifecycle, producing Arvo core.
*/
static u3_noun
_cv_life(u3_noun eve)
{
u3_noun lyf = u3nt(2, u3nc(0, 3), u3nc(0, 2));
u3_noun gat = u3n_nock_on(eve, lyf);
u3_noun cor = u3k(u3x_at(7, gat));
u3z(gat);
return cor;
}
/* u3v_boot(): evaluate boot sequence, making a kernel
*/
c3_o
u3v_boot(u3_noun eve)
{
// ensure zero-initialized kernel
//
u3A->roc = 0;
{
u3_noun pro = u3m_soft(0, _cv_life, eve);
if ( u3_blip != u3h(pro) ) {
u3z(pro);
return c3n;
}
u3A->roc = u3k(u3t(pro));
u3z(pro);
}
return c3y;
}
/* _cv_lite(): load lightweight, core-only pill.
*/
static u3_noun
_cv_lite(u3_noun pil)
{
u3_noun arv = u3ke_cue(pil);
u3_noun eve, pro;
u3x_trel(arv, &eve, 0, 0);
u3l_log("lite: arvo formula %x\r\n", u3r_mug(arv));
pro = _cv_life(u3k(eve));
u3l_log("lite: core %x\r\n", u3r_mug(pro));
u3z(arv);
return pro;
}
/* u3v_boot_lite(): light bootstrap sequence, just making a kernel.
*/
c3_o
u3v_boot_lite(u3_atom lit)
{
// ensure zero-initialized kernel
//
u3A->roc = 0;
{
u3_noun pro = u3m_soft(0, _cv_lite, lit);
if ( u3_blip != u3h(pro) ) {
u3z(pro);
return c3n;
}
u3A->roc = u3k(u3t(pro));
u3z(pro);
}
u3l_log("lite: final state %x\r\n", u3r_mug(u3A->roc));
return c3y;
}
/* _cv_nock_wish(): call wish through hardcoded interface.
*/
static u3_noun
@ -21,144 +102,6 @@ _cv_nock_wish(u3_noun txt)
return pro;
}
/* u3v_boot(): evaluate boot sequence, making a kernel
*/
void
u3v_boot(u3_noun eve)
{
u3_noun cor;
// ensure zero-initialized kernel
//
u3A->roc = 0;
{
// default namespace function: |=(a/{* *} ~)
//
u3_noun gul = u3nt(u3nt(1, 0, 0), 0, 0);
// lifecycle formula
//
u3_noun lyf = u3nt(2, u3nc(0, 3), u3nc(0, 2));
// evalute lifecycle formula against the boot sequence
// in a virtualization context
//
u3_noun pro = u3m_soft_run(gul, u3n_nock_on, eve, lyf);
if ( 0 != u3h(pro) ) {
u3l_log("boot: failed: invalid boot sequence (from pill)\r\n");
u3z(pro);
return;
}
cor = u3k(u3t(pro));
u3z(pro);
}
// save the Arvo core (at +7 of the Arvo gate)
//
u3A->roc = u3k(u3x_at(7, cor));
u3z(cor);
}
/* u3v_fire(): execute initial lifecycle.
*/
u3_noun
u3v_fire(u3_noun sys)
{
u3_noun fol = u3nt(2, u3nc(0, 3), u3nc(0, 2));
return u3n_nock_on(sys, fol);
}
/* u3v_load(): loading sequence.
*/
u3_noun
u3v_load(u3_noun pil)
{
u3_noun sys = u3ke_cue(pil);
u3l_log("load: mug: %x\r\n", u3r_mug(sys));
{
u3_noun cor = u3v_fire(sys);
u3_noun pro;
pro = u3k(u3r_at(7, cor));
u3z(cor);
return pro;
}
}
/* u3v_lite(): load lightweight, core-only pill.
*/
u3_noun
u3v_lite(u3_noun pil)
{
u3_noun lyf = u3nt(2, u3nc(0, 3), u3nc(0, 2));
u3_noun arv = u3ke_cue(pil);
u3_noun bot, cor, pro;
u3x_trel(arv, &bot, 0, 0);
u3l_log("lite: arvo formula %x\r\n", u3r_mug(arv));
cor = u3n_nock_on(bot, lyf);
u3l_log("lite: core %x\r\n", u3r_mug(cor));
pro = u3k(u3r_at(7, cor));
u3z(cor);
u3z(arv);
return pro;
}
// XX deprecated, remove
#if 0
/* u3v_boot(): correct bootstrap sequence.
*/
void
u3v_boot(c3_c* pas_c)
{
u3_noun pru;
if ( !u3A->sys ) {
u3A->sys = u3m_file(pas_c);
}
pru = u3m_soft(0, u3v_load, u3k(u3A->sys));
if ( u3h(pru) != 0 ) {
u3l_log("boot failed\r\n");
exit(1);
}
u3l_log("boot: final state %x\r\n", u3r_mug(u3t(pru)));
u3A->ken = 0;
u3A->roc = u3k(u3t(pru));
u3z(pru);
}
#endif
/* u3v_boot_lite(): light bootstrap sequence, just making a kernel.
*/
void
u3v_boot_lite(u3_atom lit)
{
u3_noun pru = u3m_soft(0, u3v_lite, lit);
if ( u3h(pru) != 0 ) {
u3l_log("boot failed\r\n");
exit(1);
}
u3l_log("lite: final state %x\r\n", u3r_mug(u3t(pru)));
u3A->roc = u3k(u3t(pru));
u3z(pru);
}
/* u3v_wish(): text expression with cache.
*/
u3_noun
@ -185,40 +128,6 @@ u3v_wish(const c3_c* str_c)
return exp;
}
// XX deprecated, remove
#if 0
/* _cv_mung(): formula wrapper with gate and sample.
*/
static u3_noun
_cv_mung_in(u3_noun gam)
{
u3_noun pro = u3n_slam_on(u3k(u3h(gam)), u3k(u3t(gam)));
u3z(gam); return pro;
}
static u3_noun
_cv_mung(c3_w sec_w, u3_noun gat, u3_noun sam)
{
u3_noun gam = u3nc(gat, sam);
return u3m_soft(0, _cv_mung_in, gam);
}
#endif
// XX deprecated, remove
#if 0
/* u3v_pike(): poke with floating core.
*/
u3_noun
u3v_pike(u3_noun ovo, u3_noun cor)
{
u3_noun fun = u3n_nock_on(cor, u3k(u3x_at(_CVX_POKE, cor)));
u3_noun sam = u3nc(u3k(u3A->now), ovo);
return _cv_mung(0, fun, sam);
}
#endif
/* _cv_nock_poke(): call poke through hardcoded interface.
*/
static u3_noun

View File

@ -654,6 +654,21 @@ _boothack_doom(void)
if ( 0 != u3_Host.ops_u.key_c ) {
kef = u3m_file(u3_Host.ops_u.key_c);
// handle trailing newline
//
{
c3_c* key_c = u3r_string(kef);
c3_w len_w = strlen(key_c);
if (len_w && (key_c[len_w - 1] == '\n')) {
key_c[len_w - 1] = '\0';
u3z(kef);
kef = u3i_string(key_c);
}
c3_free(key_c);
}
}
else if ( 0 != u3_Host.ops_u.gen_c ) {
kef = u3i_string(u3_Host.ops_u.gen_c);
@ -825,7 +840,7 @@ u3_daemon_commence()
sag_w = u3C.wag_w;
u3C.wag_w |= u3o_hashless;
u3m_boot_pier();
u3m_boot_lite();
// wire up signal controls
//
@ -847,7 +862,10 @@ u3_daemon_commence()
lit = u3i_bytes(u3_Ivory_length_w, u3_Ivory_pill_y);
}
u3v_boot_lite(lit);
if ( c3n == u3v_boot_lite(lit)) {
u3l_log("lite: boot failed\r\n");
exit(1);
}
}
/* listen on command socket

View File

@ -597,22 +597,6 @@ _worker_work_live(c3_d evt_d, u3_noun job)
}
}
/* _worker_boot_fire(): execute boot sequence.
*/
static u3_noun
_worker_boot_fire(u3_noun eve)
{
// XX virtualize? use u3v_boot?
//
u3_noun cor = u3n_nock_on(eve, u3nt(2, u3nc(0, 3), u3nc(0, 2)));
u3_noun pro;
pro = u3k(u3r_at(7, cor));
u3z(cor);
return pro;
}
/* _worker_work_boot(): apply initial-stage event.
*/
static void
@ -629,28 +613,21 @@ _worker_work_boot(c3_d evt_d, u3_noun job)
u3l_log("work: (%" PRIu64 ")| boot\r\n", evt_d);
if ( u3V.len_w == evt_d ) {
u3_noun eve, pru;
eve = u3kb_flop(u3V.roe);
u3V.roe = u3_nul;
u3_noun eve = u3kb_flop(u3V.roe);
u3V.roe = u3_nul;
u3l_log("work: (%" PRIu64 ")| pill: %x\r\n", evt_d, u3r_mug(eve));
pru = u3m_soft(0, _worker_boot_fire, eve);
if ( u3_blip != u3h(pru) ) {
u3l_log("boot failed\r\n");
if ( c3n == u3v_boot(eve) ) {
u3l_log("work: boot failed: invalid sequence (from pill)\r\n");
exit(1);
}
u3V.dun_d = evt_d;
u3A->ent_d = u3V.dun_d;
u3A->roc = u3k(u3t(pru));
u3V.mug_l = u3r_mug(u3A->roc);
u3A->ent_d = u3V.dun_d;
u3l_log("work: (%" PRIu64 ")| core: %x\r\n", evt_d, u3V.mug_l);
u3z(pru);
}
else {
// prior to the evaluation of the entire lifecycle sequence,
@ -928,7 +905,7 @@ main(c3_i argc, c3_c* argv[])
/* boot image
*/
{
u3V.sen_d = u3V.dun_d = u3m_boot_new(dir_c);
u3V.sen_d = u3V.dun_d = u3m_boot(dir_c);
u3C.stderr_log_f = _worker_send_stdr;
u3C.slog_f = _worker_send_slog;
}