Merge branch 'master' of github.com:urbit/urbit

This commit is contained in:
C. Guy Yarvin 2014-01-27 10:49:41 -08:00
commit eafd120bb4
5 changed files with 103 additions and 42 deletions

View File

@ -44,7 +44,7 @@ ifeq ($(OS),osx)
endif
ifeq ($(OS),linux)
OSLIBS=-lcrypto -lpthread -lrt -lcurses
DEFINES=-D_FILE_OFFSET_BITS=64
DEFINES=-D_FILE_OFFSET_BITS=64 -D_LARGEFILE64_SOURCE
endif
ifeq ($(OS),bsd)
OSLIBS=-lcrypto -lpthread -lncurses -lkvm
@ -54,7 +54,7 @@ LIBS=-lgmp -lncurses -lsigsegv $(OSLIBS)
INCLUDE=include
GENERATED=generated
DEFINES=-DU2_OS_$(OS) -DU2_OS_ENDIAN_$(ENDIAN) -D U2_LIB=\"$(LIB)\"
MDEFINES=-DU2_OS_$(OS) -DU2_OS_ENDIAN_$(ENDIAN) -D U2_LIB=\"$(LIB)\"
CFLAGS=-O3 \
-I/usr/local/include \
@ -62,7 +62,8 @@ CFLAGS=-O3 \
-I$(INCLUDE) \
-Ioutside/libuv/include \
-I $(GENERATED) \
$(DEFINES)
$(DEFINES) \
$(MDEFINES)
CWFLAGS=-Wall

View File

@ -16,7 +16,7 @@
/* functions
*/
u2_weak // produce
j2_mbc(Pt5, shax)(u2_wire wir_r,
j2_mbc(Pt5, shax)(u2_wire wir_r,
u2_atom a) // retain
{
c3_w met_w = u2_met(3, a);
@ -46,7 +46,38 @@
}
u2_weak // produce
j2_mbc(Pt5, shas)(u2_wire wir_r,
j2_mbc(Pt5, shal)(u2_wire wir_r,
u2_atom a, // retain
u2_atom b) // retain
{
c3_assert(u2_fly_is_cat(a));
c3_y* fat_y = malloc(a + 1);
u2_bytes(0, a, fat_y, b);
{
c3_y dig_y[64];
#if defined(U2_OS_linux) || defined(U2_OS_bsd)
SHA512_CTX ctx_h;
SHA512_Init(&ctx_h);
SHA512_Update(&ctx_h, fat_y, a);
SHA512_Final(dig_y, &ctx_h);
#elif defined(U2_OS_osx)
CC_SHA512_CTX ctx_h;
CC_SHA512_Init(&ctx_h);
CC_SHA512_Update(&ctx_h, fat_y, a);
CC_SHA512_Final(dig_y, &ctx_h);
#else
#error "port: sha512"
#endif
free(fat_y);
return u2_rl_bytes(wir_r, 64, dig_y);
}
}
u2_weak // produce
j2_mbc(Pt5, shas)(u2_wire wir_r,
u2_atom sal, // retain
u2_atom ruz) // retain
{
@ -58,13 +89,13 @@
}
u2_weak // produce
j2_mb(Pt5, shax)(u2_wire wir_r,
j2_mb(Pt5, shax)(u2_wire wir_r,
u2_noun cor) // retain
{
u2_noun a;
if ( (u2_none == (a = u2_frag(u2_cv_sam, cor))) ||
(u2_no == u2_stud(a)) )
(u2_no == u2_stud(a)) )
{
return u2_bl_bail(wir_r, c3__exit);
} else {
@ -73,7 +104,25 @@
}
u2_weak // produce
j2_mb(Pt5, shas)(u2_wire wir_r,
j2_mb(Pt5, shal)(u2_wire wir_r,
u2_noun cor) // retain
{
u2_noun a, b;
if ( (u2_none == (a = u2_frag(u2_cv_sam_2, cor))) ||
(u2_none == (b = u2_frag(u2_cv_sam_3, cor))) ||
(u2_no == u2_stud(a)) ||
(u2_no == u2_fly_is_cat(a)) ||
(u2_no == u2_stud(b)) )
{
return u2_bl_bail(wir_r, c3__exit);
} else {
return j2_mbc(Pt5, shal)(wir_r, a, b);
}
}
u2_weak // produce
j2_mb(Pt5, shas)(u2_wire wir_r,
u2_noun cor) // retain
{
u2_noun sal, ruz;
@ -81,7 +130,7 @@
if ( (u2_none == (sal = u2_frag(u2_cv_sam_2, cor))) ||
(u2_none == (ruz = u2_frag(u2_cv_sam_3, cor))) ||
(u2_no == u2_stud(sal)) ||
(u2_no == u2_stud(ruz)) )
(u2_no == u2_stud(ruz)) )
{
return u2_bl_bail(wir_r, c3__exit);
} else {
@ -110,7 +159,7 @@
if ( b < 256 ) {
u2_noun e = j2_mbc(Pt3, end)(wir_r, 0, b, d);
u2z(d);
m = u2nc(b, e);
b = 0;
@ -124,9 +173,9 @@
}
return u2_ckb_flop(l);
}
u2_noun // produce
j2_mcc(Pt5, og, raw)(u2_wire wir_r,
j2_mcc(Pt5, og, raw)(u2_wire wir_r,
u2_noun a, // retain
u2_noun b) // retain
{
@ -143,7 +192,7 @@
}
u2_weak // transfer
j2_mc(Pt5, og, raw)(u2_wire wir_r,
j2_mc(Pt5, og, raw)(u2_wire wir_r,
u2_noun cor) // retain
{
u2_noun a, b;
@ -159,30 +208,35 @@
/* structures
*/
u2_ho_jet
j2_mbj(Pt5, shax)[] = {
u2_ho_jet
j2_mbj(Pt5, shax)[] = {
{ ".2", c3__lite, j2_mb(Pt5, shax), Tier5, u2_none, u2_none },
{ }
};
u2_ho_jet
j2_mbj(Pt5, shas)[] = {
u2_ho_jet
j2_mbj(Pt5, shal)[] = {
{ ".2", c3__lite, j2_mb(Pt5, shal), u2_jet_live|u2_jet_test, u2_none, u2_none },
{ }
};
u2_ho_jet
j2_mbj(Pt5, shas)[] = {
{ ".2", c3__lite, j2_mb(Pt5, shas), Tier5, u2_none, u2_none },
{ }
};
u2_ho_jet
u2_ho_jet
j2_mcj(Pt5, og, raw)[] = {
{ ".2", c3__lite, j2_mc(Pt5, og, raw), Tier5, u2_none, u2_none },
{ }
};
u2_ho_driver
u2_ho_driver
j2_mbd(Pt5, og)[] = {
{ j2_sc(Pt5, og, raw), j2_mcj(Pt5, og, raw), 0, 0, u2_none },
{}
};
u2_ho_driver
j2_db(Pt5, og) =
j2_db(Pt5, og) =
{ j2_sb(Pt5, og), 0, j2_mbd(Pt5, og), 0, u2_none };

View File

@ -237,7 +237,7 @@
*/
typedef struct {
c3_i fid_i; // file descriptor
c3_w len_w; // length in words
c3_d len_d; // length in words
} u2_ulog;
struct _u2_uhot;

View File

@ -7,6 +7,7 @@
#include <fcntl.h>
#include <sys/ioctl.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <unistd.h>
#include <setjmp.h>
#include <gmp.h>
@ -454,7 +455,8 @@ static void
_lo_pack(u2_reck* rec_u, u2_noun ron)
{
u2_ulog* lug_u = &u2_Host.lug_u;
c3_w len_w, tar_w;
c3_w len_w;
c3_d tar_d;
c3_w* img_w;
u2_ular lar_u;
@ -463,16 +465,16 @@ _lo_pack(u2_reck* rec_u, u2_noun ron)
}
len_w = u2_cr_met(5, ron);
tar_w = (lug_u->len_w + len_w);
tar_d = (lug_u->len_d + len_w);
lar_u.syn_w = u2_mug(tar_w);
lar_u.syn_w = u2_mug((c3_w)tar_d);
lar_u.mug_w = u2_mug(ron);
lar_u.ent_w = rec_u->ent_w;
lar_u.len_w = len_w;
// XX: this is not in any way, shape or form a proper 2PC!
//
if ( -1 == lseek(lug_u->fid_i, 4 * tar_w, SEEK_SET) ) {
if ( -1 == lseek64(lug_u->fid_i, 4ULL * tar_d, SEEK_SET) ) {
perror("lseek");
uL(fprintf(uH, "lo_save: seek failed\n"));
c3_assert(0);
@ -482,7 +484,7 @@ _lo_pack(u2_reck* rec_u, u2_noun ron)
uL(fprintf(uH, "lo_save: write failed\n"));
c3_assert(0);
}
if ( -1 == lseek(lug_u->fid_i, 4 * lug_u->len_w, SEEK_SET) ) {
if ( -1 == lseek64(lug_u->fid_i, 4ULL * lug_u->len_d, SEEK_SET) ) {
perror("lseek");
uL(fprintf(uH, "lo_save: seek failed\n"));
c3_assert(0);
@ -504,7 +506,7 @@ _lo_pack(u2_reck* rec_u, u2_noun ron)
uL(fprintf(uH, "lo_save: write failed\n"));
c3_assert(0);
}
lug_u->len_w += (lar_u.len_w + c3_wiseof(lar_u));
lug_u->len_d += (c3_d)(lar_u.len_w + c3_wiseof(lar_u));
free(img_w);
// Sync. Or, what goes by sync.
@ -520,7 +522,7 @@ _lo_save(u2_reck* rec_u, u2_noun ovo)
{
u2_noun ron = u2_cke_jam(u2nc(u2k(rec_u->now), ovo));
if ( u2_Host.lug_u.len_w ) {
if ( u2_Host.lug_u.len_d ) {
_lo_pack(rec_u, ron);
rec_u->ent_w += 1;
} else {
@ -1279,7 +1281,7 @@ _lo_zest(u2_reck* rec_u)
u2_lo_bail(rec_u);
}
u2_Host.lug_u.len_w = c3_wiseof(led_u);
u2_Host.lug_u.len_d = c3_wiseof(led_u);
}
// Save the boot events.
@ -1372,7 +1374,7 @@ _lo_rest(u2_reck* rec_u)
return;
}
u2_Host.lug_u.fid_i = fid_i;
u2_Host.lug_u.len_w = ((buf_b.st_size + 3) >> 2);
u2_Host.lug_u.len_d = ((buf_b.st_size + 3ULL) >> 2ULL);
}
// Check the fscking header. It's probably corrupt.
@ -1442,25 +1444,28 @@ _lo_rest(u2_reck* rec_u)
// Read in the fscking events. These are probably corrupt as well.
{
c3_w end_w, ent_w;
c3_w ent_w;
c3_d end_d;
end_w = u2_Host.lug_u.len_w;
end_d = u2_Host.lug_u.len_d;
ent_w = 0;
if ( -1 == lseek(fid_i, 4 * end_w, SEEK_SET) ) {
if ( -1 == lseek64(fid_i, 4ULL * end_d, SEEK_SET) ) {
fprintf(stderr, "end_d %llx\n", end_d);
perror("lseek");
uL(fprintf(uH, "record (%s) is corrupt (c)\n", ful_c));
u2_lo_bail(rec_u);
}
while ( end_w != c3_wiseof(u2_uled) ) {
c3_w tar_w = (end_w - c3_wiseof(u2_ular));
while ( end_d != c3_wiseof(u2_uled) ) {
c3_d tar_d = (end_d - (c3_d)c3_wiseof(u2_ular));
u2_ular lar_u;
c3_w* img_w;
u2_noun ron;
// hL(fprintf(uH, "rest: reading event at %d\n", end_w));
uL(fprintf(uH, "rest: reading event at %llx\n", end_d));
if ( -1 == lseek(fid_i, 4 * tar_w, SEEK_SET) ) {
if ( -1 == lseek64(fid_i, 4ULL * tar_d, SEEK_SET) ) {
uL(fprintf(uH, "record (%s) is corrupt (d)\n", ful_c));
u2_lo_bail(rec_u);
}
@ -1469,7 +1474,7 @@ _lo_rest(u2_reck* rec_u)
u2_lo_bail(rec_u);
}
if ( lar_u.syn_w != u2_mug(tar_w) ) {
if ( lar_u.syn_w != u2_mug((c3_w)tar_d) ) {
uL(fprintf(uH, "record (%s) is corrupt (f)\n", ful_c));
u2_lo_bail(rec_u);
}
@ -1484,7 +1489,7 @@ _lo_rest(u2_reck* rec_u)
#endif
img_w = malloc(4 * lar_u.len_w);
if ( end_w == u2_Host.lug_u.len_w ) {
if ( end_d == u2_Host.lug_u.len_d ) {
ent_w = las_w = lar_u.ent_w;
}
else {
@ -1495,14 +1500,14 @@ _lo_rest(u2_reck* rec_u)
}
ent_w -= 1;
}
end_w = (tar_w - lar_u.len_w);
end_d = (tar_d - (c3_d)lar_u.len_w);
if ( ent_w < old_w ) {
free(img_w);
break;
}
if ( -1 == lseek(fid_i, 4 * end_w, SEEK_SET) ) {
if ( -1 == lseek64(fid_i, 4ULL * end_d, SEEK_SET) ) {
uL(fprintf(uH, "record (%s) is corrupt (h)\n", ful_c));
u2_lo_bail(rec_u);
}
@ -1627,7 +1632,7 @@ _lo_rest(u2_reck* rec_u)
led_u.kno_w = rec_u->kno_w; // may need actual translation!
led_u.tno_l = 1;
if ( (-1 == lseek(fid_i, 0, SEEK_SET)) ||
if ( (-1 == lseek64(fid_i, 0, SEEK_SET)) ||
(sizeof(led_u) != write(fid_i, &led_u, sizeof(led_u))) )
{
uL(fprintf(uH, "record (%s) failed to rewrite\n", ful_c));

View File

@ -123,6 +123,7 @@ _main_getopt(c3_i argc, c3_c** argv)
u2_Host.ops_u.hom_c = getenv("URBIT_HOME");
if ( u2_Host.ops_u.hom_c == 0 ) {
fprintf(stderr, "$URBIT_HOME not set, falling back to $HOME/urbit\n");
c3_c* hom_c = getenv("HOME");
c3_w hom_w = strlen(hom_c) + 6;