From 26cbb9c7c8c4235ecb88df81d8b53dbe3f2e104c Mon Sep 17 00:00:00 2001 From: Joe Bryan Date: Tue, 23 Apr 2019 15:07:53 -0700 Subject: [PATCH 01/12] inject fresh entropy on every restart --- pkg/urbit/vere/pier.c | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/pkg/urbit/vere/pier.c b/pkg/urbit/vere/pier.c index c090f4bc6..192af6705 100644 --- a/pkg/urbit/vere/pier.c +++ b/pkg/urbit/vere/pier.c @@ -1293,6 +1293,18 @@ _pier_loop_wake(u3_pier* pir_u) { c3_l cod_l; + // inject fresh entropy + // + { + c3_w eny_w[16]; + c3_rand(eny_w); + + u3_noun wir = u3nt(u3_blip, c3__arvo, u3_nul); + u3_noun car = u3nc(c3__wack, u3i_words(16, eny_w)); + + _pier_writ_insert_ovum(pir_u, 0, u3nc(wir, car)); + } + cod_l = u3a_lush(c3__unix); u3_unix_io_talk(pir_u); u3_unix_ef_bake(pir_u); @@ -1510,8 +1522,6 @@ _pier_boot_vent(u3_boot* bot_u) // prepend entropy to the module sequence // - // XX also copy to _pier_loop_wake? - // { c3_w eny_w[16]; c3_rand(eny_w); From 6d778bee3fcb156880a88f3793599c6844f90b89 Mon Sep 17 00:00:00 2001 From: Joe Bryan Date: Tue, 23 Apr 2019 15:09:23 -0700 Subject: [PATCH 02/12] aligns worker printfs, adjusts function indentation --- pkg/urbit/worker/main.c | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/pkg/urbit/worker/main.c b/pkg/urbit/worker/main.c index b27c25647..5c529d80f 100644 --- a/pkg/urbit/worker/main.c +++ b/pkg/urbit/worker/main.c @@ -329,7 +329,7 @@ _worker_grab(u3_noun sac, u3_noun ovo, u3_noun vir) static void _worker_fail(void* vod_p, const c3_c* wut_c) { - u3l_log("worker: fail: %s\r\n", wut_c); + u3l_log("work: fail: %s\r\n", wut_c); exit(1); } @@ -481,7 +481,7 @@ _worker_work_live(c3_d evt_d, // event number if ( c3__belt != u3h(u3t(ovo)) ) { c3_c* txt_c = u3r_string(u3h(u3t(ovo))); - u3l_log("worker: %s (%" PRIu64 ") live\r\n", txt_c, evt_d); + u3l_log("work: %s (%" PRIu64 ") live\r\n", txt_c, evt_d); } } #endif @@ -563,15 +563,15 @@ _worker_boot_fire(u3_noun eve) */ static void _worker_work_boot(c3_d evt_d, - c3_l mug_l, - u3_noun job) + c3_l mug_l, + u3_noun job) { c3_assert(evt_d == u3V.evt_d + 1ULL); u3V.evt_d = evt_d; u3A->roe = u3nc(job, u3A->roe); - u3l_log("worker: (%" PRIu64 ")| boot\r\n", evt_d); + u3l_log("work: (%" PRIu64 ")| boot\r\n", evt_d); if ( u3V.len_w == evt_d ) { u3_noun eve, pru; @@ -579,7 +579,7 @@ _worker_work_boot(c3_d evt_d, eve = u3kb_flop(u3A->roe); u3A->roe = 0; - u3l_log("worker: (%" PRIu64 ")| pill: %x\r\n", evt_d, u3r_mug(eve)); + u3l_log("work: (%" PRIu64 ")| pill: %x\r\n", evt_d, u3r_mug(eve)); pru = u3m_soft(0, _worker_boot_fire, eve); @@ -590,7 +590,7 @@ _worker_work_boot(c3_d evt_d, u3A->roc = u3k(u3t(pru)); - u3l_log("worker: (%" PRIu64 ")| core: %x\r\n", evt_d, u3r_mug(u3A->roc)); + u3l_log("work: (%" PRIu64 ")| core: %x\r\n", evt_d, u3r_mug(u3A->roc)); // XX set u3A->evt_d ? // @@ -607,8 +607,8 @@ _worker_work_boot(c3_d evt_d, */ static void _worker_poke_work(c3_d evt_d, // event number - c3_l mug_l, // mug of state - u3_noun job) // full event + c3_l mug_l, // mug of state + u3_noun job) // full event { if ( u3C.wag_w & u3o_trace ) { if ( u3_Host.tra_u.con_w == 0 && u3_Host.tra_u.fun_w == 0 ) { @@ -796,7 +796,7 @@ u3_worker_boot(void) u3V.len_w = 0; } - u3l_log("worker: play %" PRIu64 "\r\n", nex_d); + u3l_log("work: play %" PRIu64 "\r\n", nex_d); _worker_send(u3nc(c3__play, dat)); } From 1ec9b9eee9b3682fda2ea9f787faadc645fc9920 Mon Sep 17 00:00:00 2001 From: Joe Bryan Date: Tue, 23 Apr 2019 15:14:20 -0700 Subject: [PATCH 03/12] limits event replacement to three attempts --- pkg/urbit/include/vere/vere.h | 1 + pkg/urbit/vere/pier.c | 10 +++++++++- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/pkg/urbit/include/vere/vere.h b/pkg/urbit/include/vere/vere.h index 4ac7d47f5..3f36600f3 100644 --- a/pkg/urbit/include/vere/vere.h +++ b/pkg/urbit/include/vere/vere.h @@ -611,6 +611,7 @@ struct _u3_pier* pir_u; // backpointer to pier u3_noun job; // (pair date ovum) c3_d evt_d; // event number + c3_d rep_d; // replacement count u3_noun now; // event time c3_l msc_l; // ms to timeout c3_l mug_l; // hash before executing diff --git a/pkg/urbit/vere/pier.c b/pkg/urbit/vere/pier.c index 192af6705..a43767c37 100644 --- a/pkg/urbit/vere/pier.c +++ b/pkg/urbit/vere/pier.c @@ -837,6 +837,12 @@ _pier_work_replace(u3_writ* wit_u, c3_assert(god_u->sen_d == wit_u->evt_d); + // something has gone very wrong, we should probably stop now + // + if ( wit_u->rep_d >= 3ULL ) { + u3_pier_bail(); + } + /* move backward in work processing */ { @@ -846,7 +852,9 @@ _pier_work_replace(u3_writ* wit_u, u3z(wit_u->mat); wit_u->mat = mat; - god_u->sen_d -= 1; + wit_u->rep_d += 1ULL; + + god_u->sen_d -= 1ULL; } if ( wit_u->evt_d > pir_u->lif_d ) { From 450fd5199e3f3b58bdfc380f6b17244872b9858b Mon Sep 17 00:00:00 2001 From: Joe Bryan Date: Tue, 23 Apr 2019 15:33:02 -0700 Subject: [PATCH 04/12] adds additional replacement events %hole (negative ack) and %warn (%crud failed) --- pkg/urbit/worker/main.c | 46 ++++++++++++++++++++++++++++++++++++++--- 1 file changed, 43 insertions(+), 3 deletions(-) diff --git a/pkg/urbit/worker/main.c b/pkg/urbit/worker/main.c index 5c529d80f..0b7044769 100644 --- a/pkg/urbit/worker/main.c +++ b/pkg/urbit/worker/main.c @@ -388,10 +388,50 @@ _worker_send_slog(u3_noun hod) static void _worker_lame(c3_d evt_d, u3_noun ovo, u3_noun why, u3_noun tan) { - // %crud will be sent on the original wire. + u3_noun rep; + u3_noun wir, tag, cad; + + u3x_trel(ovo, &wir, &tag, &cad); + + // a deterministic error (%exit) in a network packet (%hear) + // generates a negative-acknowlegement attempt (%hole). // - _worker_send_replace(evt_d, u3nc(u3k(u3h(ovo)), u3nt(c3__crud, why, tan))); - u3z(ovo); + // A comment from the old implementation: + // There should be a separate path for crypto failures, + // to prevent timing attacks, but isn't right now. To deal + // with a crypto failure, just drop the packet. + // + if ( (c3__hear == tag) && (c3__exit == why) ) { + rep = u3nt(u3k(wir), c3__hole, u3k(cad)); + } + // failed event notifications (%crud) are replaced with + // an even more generic notifications, on a generic arvo wire. + // + // N.B this must not be allowed to fail! + // + else if ( c3__crud == tag ) { + rep = u3nc(u3nt(u3_blip, c3__arvo, u3_nul), + u3nc(c3__warn, u3i_tape("crude crashed!"))); + } + // failed failure failing fails + // + else if ( c3__warn == tag ) { + _worker_fail(0, "%warn replacement event failed"); + c3_assert(0); + } + // failure notifications are sent on the same wire + // + else { + // prepend failure mote to tank + // + u3_noun tap = u3kb_weld(u3i_tape("bail: "), u3qc_rip(3, why)); + u3_noun nat = u3nc(u3nc(c3__leaf, tap), u3k(tan)); + rep = u3nc(u3k(wir), u3nt(c3__crud, u3k(tag), nat)); + } + + _worker_send_replace(evt_d, rep); + + u3z(ovo); u3z(why); u3z(tan); } /* _worker_sure(): event succeeded, report completion. From cfb6202edbf769d4ca941abc95f39bf4b7a9965e Mon Sep 17 00:00:00 2001 From: Joe Bryan Date: Wed, 24 Apr 2019 22:21:09 -0700 Subject: [PATCH 05/12] tweaks replacement events: %crud contents, %warn structure --- pkg/urbit/worker/main.c | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/pkg/urbit/worker/main.c b/pkg/urbit/worker/main.c index 0b7044769..5151dd775 100644 --- a/pkg/urbit/worker/main.c +++ b/pkg/urbit/worker/main.c @@ -406,12 +406,15 @@ _worker_lame(c3_d evt_d, u3_noun ovo, u3_noun why, u3_noun tan) } // failed event notifications (%crud) are replaced with // an even more generic notifications, on a generic arvo wire. + // N.B this must not be allowed to fail! // - // N.B this must not be allowed to fail! + // [%warn original-event-tag=@tas combined-trace=(list tank)] // else if ( c3__crud == tag ) { + u3_noun lef = u3nc(c3__leaf, u3i_tape("crude crashed!")); + u3_noun nat = u3kb_weld(u3k(u3t(cad)), u3nc(lef, u3k(tan))); rep = u3nc(u3nt(u3_blip, c3__arvo, u3_nul), - u3nc(c3__warn, u3i_tape("crude crashed!"))); + u3nt(c3__warn, u3k(u3h(cad)), nat)); } // failed failure failing fails // @@ -421,11 +424,14 @@ _worker_lame(c3_d evt_d, u3_noun ovo, u3_noun why, u3_noun tan) } // failure notifications are sent on the same wire // + // [%crud event-tag=@tas event-trace=(list tank)] + // else { // prepend failure mote to tank // - u3_noun tap = u3kb_weld(u3i_tape("bail: "), u3qc_rip(3, why)); - u3_noun nat = u3nc(u3nc(c3__leaf, tap), u3k(tan)); + u3_noun lef = u3nc(c3__leaf, u3kb_weld(u3i_tape("bail: "), + u3qc_rip(3, why))); + u3_noun nat = u3kb_weld(u3k(tan), u3nc(lef, u3_nul)); rep = u3nc(u3k(wir), u3nt(c3__crud, u3k(tag), nat)); } From d0269662c80185c13c12b54a0cc4b945b18aa804 Mon Sep 17 00:00:00 2001 From: Joe Bryan Date: Wed, 24 Apr 2019 22:21:36 -0700 Subject: [PATCH 06/12] fixes memory leak in worker %save handler --- pkg/urbit/worker/main.c | 1 + 1 file changed, 1 insertion(+) diff --git a/pkg/urbit/worker/main.c b/pkg/urbit/worker/main.c index 5151dd775..ccb7fe816 100644 --- a/pkg/urbit/worker/main.c +++ b/pkg/urbit/worker/main.c @@ -803,6 +803,7 @@ _worker_poke(void* vod_p, u3_noun mat) evt_d = u3r_chub(0, evt); u3z(evt); + u3z(jar); c3_assert( evt_d == u3V.evt_d ); From 61bf83ff56622d2be35db595c9385b8df1a2040d Mon Sep 17 00:00:00 2001 From: BernardoDeLaPlaz Date: Thu, 25 Apr 2019 14:01:21 -0400 Subject: [PATCH 07/12] remove all build warnings --- .gitignore | 1 + pkg/urbit/configure | 8 ++++++++ pkg/urbit/include/config.h.in | 2 ++ pkg/urbit/include/noun/aliases.h | 11 +++++++++++ pkg/urbit/include/vere/vere.h | 3 +++ pkg/urbit/noun/events.c | 14 ++++++++++++-- pkg/urbit/noun/imprison.c | 4 ++-- pkg/urbit/noun/manage.c | 20 +++++++++++++++----- pkg/urbit/noun/retrieve.c | 2 +- pkg/urbit/vere/term.c | 18 ++++++++++++++---- pkg/urbit/vere/unix.c | 23 ++++++++++++++++++++--- pkg/urbit/vere/walk.c | 2 +- 12 files changed, 90 insertions(+), 18 deletions(-) diff --git a/.gitignore b/.gitignore index 380990d3a..d76c49744 100644 --- a/.gitignore +++ b/.gitignore @@ -5,3 +5,4 @@ /zod /fakezod* tags +TAGS \ No newline at end of file diff --git a/pkg/urbit/configure b/pkg/urbit/configure index 484c52e9a..bad74596b 100755 --- a/pkg/urbit/configure +++ b/pkg/urbit/configure @@ -17,6 +17,14 @@ defmacro () { defmacro URBIT_VERSION "\"$URBIT_VERSION\"" +# propogate this info into config.h, so that we can know what __attribute__ style to use in aliases. +if [ ${CC-cc} == "gcc" ] +then + defmacro GCC 1 +else + defmacro GCC 0 +fi + [ -n "$MEMORY_DEBUG" ] && defmacro U3_MEMORY_DEBUG 1 [ -n "$CPU_DEBUG" ] && defmacro U3_CPU_DEBUG 1 [ -n "$EVENT_TIME_DEBUG" ] && defmacro U3_EVENT_TIME_DEBUG 1 diff --git a/pkg/urbit/include/config.h.in b/pkg/urbit/include/config.h.in index 556b0954f..87d02e52e 100644 --- a/pkg/urbit/include/config.h.in +++ b/pkg/urbit/include/config.h.in @@ -3,6 +3,8 @@ #mesondefine URBIT_VERSION +#mesondefine GCC + #mesondefine U3_OS_linux #mesondefine U3_OS_bsd #mesondefine U3_OS_osx diff --git a/pkg/urbit/include/noun/aliases.h b/pkg/urbit/include/noun/aliases.h index c8d0e852f..2f542e361 100644 --- a/pkg/urbit/include/noun/aliases.h +++ b/pkg/urbit/include/noun/aliases.h @@ -107,3 +107,14 @@ # define u3tn(type, x) (x == 0) ? (void *)0 : ((type *) u3a_into(x)) # define u3of(type, x) (u3a_outa((type *)x)) + +/* turn off address sanitizer to increase speed + https://en.wikipedia.org/wiki/AddressSanitizer +*/ +#if GCC + /* gcc style */ + #define NO_SANITIZE_ADDRESS __attribute__((no_sanitize_address)) +#else + /* Clang style */ + #define NO_SANITIZE_ADDRESS __attribute__((no_sanitize("address"))) +#endif diff --git a/pkg/urbit/include/vere/vere.h b/pkg/urbit/include/vere/vere.h index ba8dc8e35..f3e4b15b9 100644 --- a/pkg/urbit/include/vere/vere.h +++ b/pkg/urbit/include/vere/vere.h @@ -1335,3 +1335,6 @@ */ void u3_king_grab(void* vod_p); + + c3_w + u3_readdir_r(DIR *dirp, struct dirent *entry, struct dirent **result); diff --git a/pkg/urbit/noun/events.c b/pkg/urbit/noun/events.c index d162cfc9a..cbb2f8f48 100644 --- a/pkg/urbit/noun/events.c +++ b/pkg/urbit/noun/events.c @@ -633,12 +633,22 @@ _ce_patch_apply(u3_ce_patch* pat_u) //printf("image: sou_w %d, new %d\r\n", u3P.sou_u.pgs_w, pat_u->con_u->sou_w); if ( u3P.nor_u.pgs_w > pat_u->con_u->nor_w ) { - ftruncate(u3P.nor_u.fid_i, u3P.nor_u.pgs_w << (u3a_page + 2)); + c3_w ret_w; + ret_w = ftruncate(u3P.nor_u.fid_i, u3P.nor_u.pgs_w << (u3a_page + 2)); + if (ret_w){ + perror("_ce_patch_apply"); + c3_assert(0); + } } u3P.nor_u.pgs_w = pat_u->con_u->nor_w; if ( u3P.sou_u.pgs_w > pat_u->con_u->sou_w ) { - ftruncate(u3P.sou_u.fid_i, u3P.sou_u.pgs_w << (u3a_page + 2)); + c3_w ret_w; + ret_w = ftruncate(u3P.sou_u.fid_i, u3P.sou_u.pgs_w << (u3a_page + 2)); + if (ret_w){ + perror("_ce_patch_apply"); + c3_assert(0); + } } u3P.sou_u.pgs_w = pat_u->con_u->sou_w; diff --git a/pkg/urbit/noun/imprison.c b/pkg/urbit/noun/imprison.c index bc70054e6..4244c3ae8 100644 --- a/pkg/urbit/noun/imprison.c +++ b/pkg/urbit/noun/imprison.c @@ -478,7 +478,7 @@ u3i_list(u3_weak one, ...); return cut_t ? cut_w : i_w; } - __attribute__((no_sanitize("address"))) +NO_SANITIZE_ADDRESS static u3_noun // transfer _molt_apply(u3_noun som, // retain c3_w len_w, @@ -504,7 +504,7 @@ u3i_list(u3_weak one, ...); } } -__attribute__((no_sanitize("address"))) +NO_SANITIZE_ADDRESS u3_noun u3i_molt(u3_noun som, ...) { diff --git a/pkg/urbit/noun/manage.c b/pkg/urbit/noun/manage.c index 730722ab5..9e05b45e0 100644 --- a/pkg/urbit/noun/manage.c +++ b/pkg/urbit/noun/manage.c @@ -97,19 +97,29 @@ _cm_punt(u3_noun tax) } #endif +static void _write(int fd, const void *buf, size_t count) +{ + + if (count != write(fd, buf, count)){ + fprintf(stderr, "write failed\r\n"); + assert(0); + } +} + + /* _cm_emergency(): write emergency text to stderr, never failing. */ static void _cm_emergency(c3_c* cap_c, c3_l sig_l) { - write(2, "\r\n", 2); - write(2, cap_c, strlen(cap_c)); + _write(2, "\r\n", 2); + _write(2, cap_c, strlen(cap_c)); if ( sig_l ) { - write(2, ": ", 2); - write(2, &sig_l, 4); + _write(2, ": ", 2); + _write(2, &sig_l, 4); } - write(2, "\r\n", 2); + _write(2, "\r\n", 2); } static void _cm_overflow(void *arg1, void *arg2, void *arg3) diff --git a/pkg/urbit/noun/retrieve.c b/pkg/urbit/noun/retrieve.c index 2e70bbc9c..adeb06e5f 100644 --- a/pkg/urbit/noun/retrieve.c +++ b/pkg/urbit/noun/retrieve.c @@ -161,7 +161,7 @@ u3r_at(u3_atom a, u3_noun b) } } -__attribute__((no_sanitize("address"))) +NO_SANITIZE_ADDRESS c3_o u3r_mean(u3_noun som, ...) diff --git a/pkg/urbit/vere/term.c b/pkg/urbit/vere/term.c index e0adbcf47..550297bf3 100644 --- a/pkg/urbit/vere/term.c +++ b/pkg/urbit/vere/term.c @@ -26,6 +26,16 @@ static inline void _term_suck(u3_utty*, const c3_y*, ssize_t); #define _SPIN_RATE_US 250000 // spinner rate (microseconds/frame) #define _SPIN_IDLE_US 500000 // spinner cools down if stopped this long +static void _write(int fd, const void *buf, size_t count) +{ + + if (count != write(fd, buf, count)){ + fprintf(stderr, "write failed\r\n"); + assert(0); + } +} + + /* _term_msc_out_host(): unix microseconds from current host time. */ static c3_d @@ -290,7 +300,7 @@ u3_term_io_exit(void) if ( -1 == fcntl(uty_u->fid_i, F_SETFL, uty_u->cug_i) ) { c3_assert(!"exit-fcntl"); } - write(uty_u->fid_i, "\r\n", 2); + _write(uty_u->fid_i, "\r\n", 2); #if 0 if ( uty_u->tat_u.sun.sit_u ) { @@ -764,7 +774,7 @@ _term_try_write_str(u3_utty* uty_u, { // c3_i fid_i = uv_fileno(&uty_u->pop_u); c3_i fid_i = uty_u->pop_u.io_watcher.fd; // XX old libuv - write(fid_i, hun_y, strlen(hun_y)); + _write(fid_i, hun_y, strlen(hun_y)); } /* _term_try_move_left(): move the cursor left (off-thread). @@ -1196,8 +1206,8 @@ u3_term_io_hija(void) perror("hija-fcntl-0"); c3_assert(!"hija-fcntl"); } - write(uty_u->fid_i, "\r", 1); - write(uty_u->fid_i, uty_u->ufo_u.out.el_y, + _write(uty_u->fid_i, "\r", 1); + _write(uty_u->fid_i, uty_u->ufo_u.out.el_y, strlen((c3_c*) uty_u->ufo_u.out.el_y)); } return stdout; diff --git a/pkg/urbit/vere/unix.c b/pkg/urbit/vere/unix.c index 653921160..efcbf2000 100644 --- a/pkg/urbit/vere/unix.c +++ b/pkg/urbit/vere/unix.c @@ -15,6 +15,23 @@ #include "vere/vere.h" +c3_w u3_readdir_r(DIR *dirp, struct dirent *entry, struct dirent **result) +{ + errno = 0; + struct dirent * tmp_u = readdir(dirp); + + if (NULL == tmp_u){ + *result = NULL; + return (errno); // either success or error code + } else { + memcpy(entry, tmp_u, sizeof(struct dirent)); + *result = entry; + } + + return(0); +} + + /* _unix_down(): descend path. */ static c3_c* @@ -311,7 +328,7 @@ _unix_scan_mount_point(u3_pier *pir_u, u3_umon* mon_u) struct dirent* out_u; c3_w err_w; - if ( 0 != (err_w = readdir_r(rid_u, &ent_u, &out_u)) ) { + if ( 0 != (err_w = u3_readdir_r(rid_u, &ent_u, &out_u)) ) { uL(fprintf(uH, "erroring loading pier directory %s: %s\r\n", mon_u->dir_u.pax_c, strerror(errno))); c3_assert(0); @@ -756,7 +773,7 @@ _unix_update_dir(u3_pier *pir_u, u3_udir* dir_u) struct dirent* out_u; c3_w err_w; - if ( (err_w = readdir_r(rid_u, &ent_u, &out_u)) != 0 ) { + if ( (err_w = u3_readdir_r(rid_u, &ent_u, &out_u)) != 0 ) { uL(fprintf(uH, "error loading directory %s: %s\r\n", dir_u->pax_c, strerror(err_w))); c3_assert(0); @@ -948,7 +965,7 @@ _unix_initial_update_dir(c3_c* pax_c, c3_c* bas_c) struct dirent* out_u; c3_w err_w; - if ( 0 != (err_w = readdir_r(rid_u, &ent_u, &out_u)) ) { + if ( 0 != (err_w = u3_readdir_r(rid_u, &ent_u, &out_u)) ) { uL(fprintf(uH, "error loading initial directory %s: %s\r\n", pax_c, strerror(errno))); c3_assert(0); diff --git a/pkg/urbit/vere/walk.c b/pkg/urbit/vere/walk.c index 67c295c8f..34b45e39f 100644 --- a/pkg/urbit/vere/walk.c +++ b/pkg/urbit/vere/walk.c @@ -192,7 +192,7 @@ _walk_in(const c3_c* dir_c, c3_w len_w) struct dirent ent_n; struct dirent* out_n; - if ( readdir_r(dir_d, &ent_n, &out_n) != 0 ) { + if ( u3_readdir_r(dir_d, &ent_n, &out_n) != 0 ) { uL(fprintf(uH, "%s: %s\n", dir_c, strerror(errno))); break; } From 22fe68f67ceec623009db325dd23ff1168339ab0 Mon Sep 17 00:00:00 2001 From: BernardoDeLaPlaz Date: Thu, 25 Apr 2019 16:24:55 -0400 Subject: [PATCH 08/12] fix one new build warning --- pkg/urbit/tests/hashtable_tests.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/pkg/urbit/tests/hashtable_tests.c b/pkg/urbit/tests/hashtable_tests.c index 17060502f..8955a000d 100644 --- a/pkg/urbit/tests/hashtable_tests.c +++ b/pkg/urbit/tests/hashtable_tests.c @@ -6,6 +6,10 @@ static void _test_cache_trimming(void); static void _test_no_cache(void); static void _test_skip_slot(void); +// defined in noun/hashtable.c +c3_w _ch_skip_slot(c3_w mug_w, c3_w lef_w); + + /* main(): run all test cases. */ int From ac59fb749ccab6dc49625af25b2c8f320926d740 Mon Sep 17 00:00:00 2001 From: Joe Bryan Date: Thu, 25 Apr 2019 13:35:34 -0700 Subject: [PATCH 09/12] updates arvo submodule and brass.pill to latest arvo next --- bin/brass.pill | 4 ++-- pkg/arvo | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/bin/brass.pill b/bin/brass.pill index acc3c6fba..9aa506f16 100644 --- a/bin/brass.pill +++ b/bin/brass.pill @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:e85cccf129bc9d03280d6142be58e56e230717c2ca9b8baeab38fb541e91b4f9 -size 5280561 +oid sha256:8e1b2d19d2b71a3c407358ff69b14de0029bd6a7c486b819f59274d615652917 +size 5210146 diff --git a/pkg/arvo b/pkg/arvo index 46c924734..587b4d26d 160000 --- a/pkg/arvo +++ b/pkg/arvo @@ -1 +1 @@ -Subproject commit 46c92473477ba8f4d14a6e2bb22319c8bf5970a4 +Subproject commit 587b4d26df6396a21478a110fc0736df319298a0 From c0403d20964cb52638c9df9d7309daf23d678472 Mon Sep 17 00:00:00 2001 From: BernardoDeLaPlaz Date: Thu, 25 Apr 2019 18:05:26 -0400 Subject: [PATCH 10/12] code review --- pkg/urbit/configure | 8 -------- pkg/urbit/include/config.h.in | 20 -------------------- pkg/urbit/include/noun/aliases.h | 11 ----------- pkg/urbit/include/vere/vere.h | 2 +- pkg/urbit/noun/imprison.c | 4 ++-- pkg/urbit/noun/manage.c | 5 ++--- pkg/urbit/noun/retrieve.c | 2 +- pkg/urbit/vere/term.c | 5 ++--- 8 files changed, 8 insertions(+), 49 deletions(-) delete mode 100644 pkg/urbit/include/config.h.in diff --git a/pkg/urbit/configure b/pkg/urbit/configure index f45b7b1fc..fa8bd9ef4 100755 --- a/pkg/urbit/configure +++ b/pkg/urbit/configure @@ -17,14 +17,6 @@ defmacro () { defmacro URBIT_VERSION "\"$URBIT_VERSION\"" -# propogate this info into config.h, so that we can know what __attribute__ style to use in aliases. -if [ ${CC-cc} == "gcc" ] -then - defmacro GCC 1 -else - defmacro GCC 0 -fi - [ -n "$MEMORY_DEBUG" ] && defmacro U3_MEMORY_DEBUG 1 [ -n "$CPU_DEBUG" ] && defmacro U3_CPU_DEBUG 1 [ -n "$EVENT_TIME_DEBUG" ] && defmacro U3_EVENT_TIME_DEBUG 1 diff --git a/pkg/urbit/include/config.h.in b/pkg/urbit/include/config.h.in deleted file mode 100644 index 87d02e52e..000000000 --- a/pkg/urbit/include/config.h.in +++ /dev/null @@ -1,20 +0,0 @@ -#ifndef CONFIG_H -#define CONFIG_H - -#mesondefine URBIT_VERSION - -#mesondefine GCC - -#mesondefine U3_OS_linux -#mesondefine U3_OS_bsd -#mesondefine U3_OS_osx - -#mesondefine U3_OS_ENDIAN_little -#mesondefine U3_OS_ENDIAN_big - -#mesondefine U3_MEMORY_DEBUG -#mesondefine U3_CPU_DEBUG -#mesondefine U3_EVENT_TIME_DEBUG -#mesondefine U3_MEMORY_LOG - -#endif /*CONFIG_H*/ diff --git a/pkg/urbit/include/noun/aliases.h b/pkg/urbit/include/noun/aliases.h index 2f542e361..c8d0e852f 100644 --- a/pkg/urbit/include/noun/aliases.h +++ b/pkg/urbit/include/noun/aliases.h @@ -107,14 +107,3 @@ # define u3tn(type, x) (x == 0) ? (void *)0 : ((type *) u3a_into(x)) # define u3of(type, x) (u3a_outa((type *)x)) - -/* turn off address sanitizer to increase speed - https://en.wikipedia.org/wiki/AddressSanitizer -*/ -#if GCC - /* gcc style */ - #define NO_SANITIZE_ADDRESS __attribute__((no_sanitize_address)) -#else - /* Clang style */ - #define NO_SANITIZE_ADDRESS __attribute__((no_sanitize("address"))) -#endif diff --git a/pkg/urbit/include/vere/vere.h b/pkg/urbit/include/vere/vere.h index de181b5ab..b03051888 100644 --- a/pkg/urbit/include/vere/vere.h +++ b/pkg/urbit/include/vere/vere.h @@ -1345,4 +1345,4 @@ u3_daemon_grab(void* vod_p); c3_w - u3_readdir_r(DIR *dirp, struct dirent *entry, struct dirent **result); + u3_readdir_r(DIR *dirp, struct dirent *entry, struct dirent **result); diff --git a/pkg/urbit/noun/imprison.c b/pkg/urbit/noun/imprison.c index 58a30cb6d..9be2b7377 100644 --- a/pkg/urbit/noun/imprison.c +++ b/pkg/urbit/noun/imprison.c @@ -478,7 +478,7 @@ u3i_list(u3_weak one, ...); return cut_t ? cut_w : i_w; } -NO_SANITIZE_ADDRESS + __attribute__((no_sanitize_address)) static u3_noun // transfer _molt_apply(u3_noun som, // retain c3_w len_w, @@ -504,7 +504,7 @@ NO_SANITIZE_ADDRESS } } -NO_SANITIZE_ADDRESS +__attribute__((no_sanitize_address)) u3_noun u3i_molt(u3_noun som, ...) { diff --git a/pkg/urbit/noun/manage.c b/pkg/urbit/noun/manage.c index bf3e2ae15..f329e9d14 100644 --- a/pkg/urbit/noun/manage.c +++ b/pkg/urbit/noun/manage.c @@ -96,10 +96,9 @@ _cm_punt(u3_noun tax) static void _write(int fd, const void *buf, size_t count) { - if (count != write(fd, buf, count)){ - fprintf(stderr, "write failed\r\n"); - assert(0); + u3l_log("write failed\r\n"); + c3_assert(0); } } diff --git a/pkg/urbit/noun/retrieve.c b/pkg/urbit/noun/retrieve.c index adeb06e5f..8b2fc0b59 100644 --- a/pkg/urbit/noun/retrieve.c +++ b/pkg/urbit/noun/retrieve.c @@ -161,7 +161,7 @@ u3r_at(u3_atom a, u3_noun b) } } -NO_SANITIZE_ADDRESS +__attribute__((no_sanitize_address)) c3_o u3r_mean(u3_noun som, ...) diff --git a/pkg/urbit/vere/term.c b/pkg/urbit/vere/term.c index ca4c58d38..868a33c53 100644 --- a/pkg/urbit/vere/term.c +++ b/pkg/urbit/vere/term.c @@ -29,10 +29,9 @@ static u3_utty* _term_main(); static void _write(int fd, const void *buf, size_t count) { - if (count != write(fd, buf, count)){ - fprintf(stderr, "write failed\r\n"); - assert(0); + u3l_log("write failed\r\n"); + c3_assert(0); } } From 043333f7672dbdac12f600204d4809a7b5bf2e9c Mon Sep 17 00:00:00 2001 From: BernardoDeLaPlaz Date: Thu, 25 Apr 2019 18:23:53 -0400 Subject: [PATCH 11/12] -Werror turned on --- pkg/urbit/Makefile | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/pkg/urbit/Makefile b/pkg/urbit/Makefile index 10c65555d..28513fe4a 100644 --- a/pkg/urbit/Makefile +++ b/pkg/urbit/Makefile @@ -17,6 +17,12 @@ all_objs = $(common_objs) $(daemon_objs) $(worker_objs) all_srcs = $(common) $(daemon) $(worker) all_exes = ./hash_tests ./hashtable_tests ./urbit ./urbit-worker + +# -Werror promotes all warnings that are enabled into errors (this is on) +# -Wall issues all types of errors. This is off (for now) +CFLAGS := $(CFLAGS) -Werror + + ################################################################################ .PHONY: all test clean mkproper From 1c4732ca229eec389ddde41f3e4234e6e4ec742d Mon Sep 17 00:00:00 2001 From: benjamin-tlon <42358674+benjamin-tlon@users.noreply.github.com> Date: Thu, 25 Apr 2019 16:45:39 -0700 Subject: [PATCH 12/12] Run urbit tests on the debug build, with GC enabled. (#1252) * Run tests with `urbit-debug` and enable GC while running tests. * Build `urbit-debug` with `-O0`. --- nix/ops/brass/builder.sh | 2 +- nix/ops/brass/default.nix | 13 +++++++++++-- nix/ops/default.nix | 14 +++++++------- nix/ops/fakeship/builder.sh | 2 +- nix/ops/fakeship/default.nix | 15 ++++++++++++--- nix/ops/solid/builder.sh | 2 +- nix/ops/solid/default.nix | 13 +++++++++++-- nix/ops/test/builder.sh | 2 +- nix/ops/test/default.nix | 17 +++++++++++++---- nix/pkgs/urbit/builder.sh | 2 +- nix/pkgs/urbit/default.nix | 2 +- sh/test | 2 +- 12 files changed, 61 insertions(+), 25 deletions(-) diff --git a/nix/ops/brass/builder.sh b/nix/ops/brass/builder.sh index 408dc99bb..7023c0484 100755 --- a/nix/ops/brass/builder.sh +++ b/nix/ops/brass/builder.sh @@ -5,7 +5,7 @@ set -ex cp -r $FAKEZOD ./zod chmod -R u+rw ./zod -urbit -d ./zod +$URBIT -d ./zod cleanup () { if [ -e ./zod/.vere.lock ] diff --git a/nix/ops/brass/default.nix b/nix/ops/brass/default.nix index 50b8e98ce..e7073011d 100644 --- a/nix/ops/brass/default.nix +++ b/nix/ops/brass/default.nix @@ -1,10 +1,19 @@ -{ pkgs, tlon, deps, urbit, fakezod, arvo }: +{ pkgs, tlon, deps, fakezod, arvo, debug }: + +let + + urbitExe = if debug + then "${tlon.urbit-debug}/bin/urbit-debug -g" + else "${tlon.urbit}/bin/urbit"; + +in pkgs.stdenv.mkDerivation rec { name = "brass"; builder = ./builder.sh; - buildInputs = [ urbit tlon.herb pkgs.coreutils ]; + buildInputs = [ tlon.herb pkgs.coreutils ]; + URBIT = urbitExe; FAKEZOD = fakezod; ARVO = arvo; } diff --git a/nix/ops/default.nix b/nix/ops/default.nix index b4c66d25b..0486b102b 100644 --- a/nix/ops/default.nix +++ b/nix/ops/default.nix @@ -1,4 +1,4 @@ -{ pkgs ? import ../nixpkgs.nix }: +{ pkgs ? import ../nixpkgs.nix, debug ? false }: let @@ -12,34 +12,34 @@ in rec { bootzod = import ./fakeship { - inherit pkgs tlon deps urbit; + inherit pkgs tlon deps debug; brass = ../../bin/brass.pill; ship = "zod"; }; bootbus = import ./fakeship { - inherit pkgs tlon deps urbit; + inherit pkgs tlon deps debug; brass = ../../bin/brass.pill; ship = "bus"; }; test = import ./test { - inherit pkgs tlon deps urbit arvo; + inherit pkgs tlon deps arvo debug; ship = bootzod; }; solid = import ./solid { - inherit arvo pkgs tlon deps urbit; + inherit arvo pkgs tlon deps debug; fakezod = bootzod; }; brass = import ./brass { - inherit arvo pkgs tlon deps urbit; + inherit arvo pkgs tlon deps debug; fakezod = bootzod; }; fakezod = import ./fakeship { - inherit pkgs tlon deps urbit brass; + inherit pkgs tlon deps brass debug; ship = "zod"; }; diff --git a/nix/ops/fakeship/builder.sh b/nix/ops/fakeship/builder.sh index 1a5c42231..034350c83 100755 --- a/nix/ops/fakeship/builder.sh +++ b/nix/ops/fakeship/builder.sh @@ -2,7 +2,7 @@ source $stdenv/setup set -ex -urbit -d -F $SHIP -B "$PILL" $out +$URBIT -d -F $SHIP -B "$PILL" $out check () { [ 3 -eq "$(herb $out -d 3)" ] diff --git a/nix/ops/fakeship/default.nix b/nix/ops/fakeship/default.nix index 7d534fd20..1e5e6285a 100644 --- a/nix/ops/fakeship/default.nix +++ b/nix/ops/fakeship/default.nix @@ -1,9 +1,18 @@ -{ pkgs, tlon, deps, urbit, brass, ship ? "zod" }: +{ pkgs, tlon, deps, brass, ship, debug }: -pkgs.stdenv.mkDerivation rec { +let + + urbitExe = if debug + then "${tlon.urbit-debug}/bin/urbit-debug -g" + else "${tlon.urbit}/bin/urbit"; + +in + +pkgs.stdenv.mkDerivation { name = "fake" + ship; builder = ./builder.sh; - buildInputs = [ urbit tlon.herb ]; + buildInputs = [ tlon.herb ]; + URBIT = urbitExe; PILL = brass; SHIP = ship; } diff --git a/nix/ops/solid/builder.sh b/nix/ops/solid/builder.sh index 345c92d18..94f03aa87 100755 --- a/nix/ops/solid/builder.sh +++ b/nix/ops/solid/builder.sh @@ -5,7 +5,7 @@ set -ex cp -r $FAKEZOD ./zod chmod -R u+rw ./zod -urbit -d ./zod +$URBIT -d ./zod cleanup () { if [ -e ./zod/.vere.lock ] diff --git a/nix/ops/solid/default.nix b/nix/ops/solid/default.nix index 370aaf4a3..c9c239a64 100644 --- a/nix/ops/solid/default.nix +++ b/nix/ops/solid/default.nix @@ -1,10 +1,19 @@ -{ pkgs, tlon, deps, urbit, fakezod, arvo }: +{ pkgs, tlon, deps, fakezod, arvo, debug }: + +let + + urbitExe = if debug + then "${tlon.urbit-debug}/bin/urbit-debug -g" + else "${tlon.urbit}/bin/urbit"; + +in pkgs.stdenv.mkDerivation rec { name = "solid"; builder = ./builder.sh; - buildInputs = [ urbit tlon.herb pkgs.coreutils ]; + buildInputs = [ tlon.herb ]; + URBIT = urbitExe; FAKEZOD = fakezod; ARVO = arvo; } diff --git a/nix/ops/test/builder.sh b/nix/ops/test/builder.sh index 8034ea55e..cfda98365 100644 --- a/nix/ops/test/builder.sh +++ b/nix/ops/test/builder.sh @@ -5,7 +5,7 @@ set -ex cp -r $SHIP ./ship chmod -R u+rw ./ship -urbit -d ./ship 2> urbit-output +$URBIT -d ./ship 2> urbit-output tail -f urbit-output >&2 & tailproc=$! diff --git a/nix/ops/test/default.nix b/nix/ops/test/default.nix index b6f4c26d8..607ccb4f8 100644 --- a/nix/ops/test/default.nix +++ b/nix/ops/test/default.nix @@ -1,10 +1,19 @@ -{ pkgs, tlon, deps, urbit, ship, arvo }: +{ pkgs, tlon, deps, ship, arvo, debug }: + +let + + urbitExe = if debug + then "${tlon.urbit-debug}/bin/urbit-debug -g" + else "${tlon.urbit}/bin/urbit"; + +in pkgs.stdenv.mkDerivation rec { name = "test"; builder = ./builder.sh; - buildInputs = [ urbit tlon.herb pkgs.coreutils ]; + buildInputs = [ tlon.herb ]; - SHIP = ship; - ARVO = arvo; + URBIT = urbitExe; + SHIP = ship; + ARVO = arvo; } diff --git a/nix/pkgs/urbit/builder.sh b/nix/pkgs/urbit/builder.sh index bb04e4df5..aa73e06ea 100644 --- a/nix/pkgs/urbit/builder.sh +++ b/nix/pkgs/urbit/builder.sh @@ -7,7 +7,7 @@ cd src bash ./configure make clean -make urbit urbit-worker -j8 +make all -j8 make test mkdir -p $out/bin diff --git a/nix/pkgs/urbit/default.nix b/nix/pkgs/urbit/default.nix index 5eedebfea..1cf8fb92e 100644 --- a/nix/pkgs/urbit/default.nix +++ b/nix/pkgs/urbit/default.nix @@ -29,7 +29,7 @@ pkgs.stdenv.mkDerivation { # See https://github.com/NixOS/nixpkgs/issues/18995 hardeningDisable = if debug then [ "all" ] else []; - CFLAGS = if debug then "-O0 -g" else "-O3"; + CFLAGS = if debug then "-O1 -g" else "-O3"; MEMORY_DEBUG = debug; CPU_DEBUG = debug; EVENT_TIME_DEBUG = false; diff --git a/sh/test b/sh/test index 5b1470239..14cfb805a 100755 --- a/sh/test +++ b/sh/test @@ -2,7 +2,7 @@ set -e -pkg=$(nix-build nix/ops -A test --no-out-link) +pkg=$(nix-build nix/ops -A test --no-out-link --arg debug true) hdr () { echo =====$(sed 's/./=/g' <<< "$1")=====