Merge branch 'next/vere'

* next/vere: (49 commits)
  vere: bumps version
  vere: bumps version
  ci: enable release version mgmt
  Revert "ci: reenable release mgmt"
  ci: reenable release mgmt
  ames: track/log bad ciphertext crashes separately
  u3: %evil leaves no trace
  vere: drop bail:evil events without error notifications
  jets: bail:evil in ae-siv decryption jets
  vere: make uv_cancel return code check explicit
  u3: check for overflow in interpreter if guard page not present
  build: default to using guard page
  u3: return 0 from u3e_fault() if guard page cannot be protected
  u3: control presence of guard page using macro
  Revert "u3: check for road stack overflow on every nock %2 and %9"
  build: make bench is phony
  u3: failure to mprotect() the new guard page is fatal
  u3: removes/disables obsolete road stack overflow checks
  u3: account for guard page in cellblock allocation conditional
  u3: bump road heap offset before allocating cellblock
  ...
This commit is contained in:
Joe Bryan 2022-07-28 17:33:22 -04:00
commit da47a2f98b
38 changed files with 647 additions and 311 deletions

View File

@ -232,9 +232,7 @@ jobs:
after:
runs-on: ubuntu-latest
needs: [urbit, mingw]
# XX disabled due to missing storage.objects.delete access
if: false
# if: inputs.upload
if: inputs.upload
steps:
- uses: google-github-actions/setup-gcloud@v0.2.0
with:

View File

@ -1,10 +1,10 @@
.PHONY: build build-all install cross release test pills ropsten-pills clean
build:
nix-build -A urbit -A herb --no-out-link
nix-build -A urbit --no-out-link
install:
nix-env -f . -iA urbit -iA herb
nix-env -f . -iA urbit
release:
sh/release

18
nix/sources-openssl.json Normal file
View File

@ -0,0 +1,18 @@
{
"openssl": {
"branch": "1_1_1n",
"homepage": "https://www.openssl.org/",
"pmnsh": {
"include": "build/include",
"lib": "build",
"prepare": "./config --prefix=`mkdir -p build && readlink -f ./build` --libdir=. no-shared no-tests",
"make": "install_dev"
},
"owner": "openssl",
"repo": "openssl",
"rev": "OpenSSL_1_1_1n",
"type": "tarball",
"url": "https://github.com/openssl/openssl/archive/refs/tags/OpenSSL_1_1_1n.tar.gz",
"url_template": "https://github.com/<owner>/<repo>/archive/refs/tags/<rev>.tar.gz"
}
}

View File

@ -4,6 +4,11 @@
"description": "A command line tool and library for transferring data with URL syntax",
"homepage": "http://curl.se/",
"pmnsh": {
"compat": {
"openbsd": {
"prepare": "autoreconf -vfi && ./configure --disable-shared --disable-ldap --disable-rtsp --without-brotli --without-libidn2 --without-libpsl --without-nghttp2 --with-openssl=`readlink -f ../openssl/build`"
}
},
"include": "include",
"lib": "lib/.libs",
"prepare": "autoreconf -vfi && ./configure --disable-shared --disable-ldap --disable-rtsp --without-brotli --without-libidn2 --without-libpsl --without-nghttp2 --with-openssl",
@ -76,6 +81,13 @@
},
"urcrypt": {
"pmnsh": {
"compat": {
"openbsd": {
"make": "install prefix=`readlink -f .` exec_prefix=`readlink -f .`",
"include": "include",
"lib": "lib"
}
},
"prepare": "./autogen.sh && ./configure --disable-shared PKG_CONFIG_PATH=../secp256k1 CFLAGS=\"-I../secp256k1/include -I../libaes_siv\" LDFLAGS=-L../libaes_siv",
"make": "install"
}

View File

@ -8,6 +8,9 @@
"compat": {
"mingw": {
"prepare": "cmake -G\"MSYS Makefiles\" -DCMAKE_INSTALL_PREFIX=. ."
},
"openbsd": {
"prepare": "cmake -DOPENSSL_ROOT_DIR=`readlink -f ../openssl/build` ."
}
},
"include": "include",
@ -35,6 +38,10 @@
"mingw": {
"make": "aes_siv_static",
"prepare": "cmake -G\"MSYS Makefiles\" -DDISABLE_DOCS:BOOL=ON ."
},
"openbsd": {
"make": "aes_siv_static",
"prepare": "cmake -DDISABLE_DOCS:BOOL=ON -DOPENSSL_ROOT_DIR=`readlink -f ../openssl/build` ."
}
}
},
@ -98,6 +105,10 @@
"mingw": {
"lib": "build/Win64-MinGW-w64",
"make": "-C build/Win64-MinGW-w64 libsoftfloat3.a"
},
"openbsd": {
"lib": "build/template-FAST_INT64",
"make": "-C build/template-FAST_INT64 libsoftfloat3.a"
}
},
"include": "source/include"

View File

@ -3,3 +3,8 @@
/include/config.h
/include/ca-bundle.h
/include/ivory.h
# indexing
/.cache/
compile_commands.json
tags

View File

@ -1,5 +1,6 @@
include config.mk
include $(foreach dir,$(compat),$(wildcard compat/$(dir)/*.mk))
compat_mks := $(foreach dir,$(compat),$(wildcard compat/$(dir)/*.mk))
include $(compat_mks)
jets = jets/tree.c $(wildcard jets/*/*.c)
noun = $(wildcard noun/*.c)
@ -32,7 +33,7 @@ CFLAGS := $(CFLAGS)
################################################################################
.PHONY: all test clean mrproper
.PHONY: all bench test clean mrproper
################################################################################
@ -53,7 +54,7 @@ clean:
rm -f ./tags $(all_objs) $(all_exes)
mrproper: clean
rm -f config.mk include/config.h
rm -f config.mk include/config.h compile_commands.json
################################################################################
@ -80,3 +81,15 @@ build/urbit: $(common_objs) $(daemon_objs) $(worker_objs)
tags: $(all_srcs) $(headers)
ctags $^
compile_commands.json: Makefile config.mk $(compat_mks)
@echo "[" > $@ && sep= && \
for src in $(all_srcs); do \
echo "$$sep{" >> $@; \
printf '"directory": "%s",\n' $$(pwd) >> $@; \
printf '"command": "%s",\n' "$(CC) -I./include $(CFLAGS) $$src $(CCEXTRA) -c" >> $@; \
printf '"file": "%s",\n' $$src >> $@; \
echo "}" >> $@; \
sep=','; \
done && \
echo "]" >> $@

View File

@ -0,0 +1,12 @@
diff --git a/Makefile b/Makefile
--- a/Makefile
+++ b/Makefile
@@ -18,7 +18,7 @@
# There may be other macros in mdb.c of interest. You should
# read mdb.c before changing any of them.
#
-CC = gcc
+CC = cc
AR = ar
W = -W -Wall -Wno-unused-parameter -Wbad-function-cast -Wuninitialized
THREADS = -pthread

View File

@ -0,0 +1,13 @@
diff --git a/makefile b/makefile
--- a/makefile
+++ b/makefile
@@ -12,5 +12,9 @@ shared: murmur3.c murmur3.h
$(CC) -fPIC -O3 -c murmur3.c
$(CC) -shared -Wl,--export-dynamic murmur3.o -o libmurmur3.so
+static: murmur3.c murmur3.h
+ $(CC) -fPIC -O3 -c murmur3.c
+ $(AR) rcs libmurmur3.a murmur3.o
+
clean:
rm -rf example *.o *.so

View File

@ -0,0 +1,85 @@
diff --git a/build/template-FAST_INT64/Makefile b/build/template-FAST_INT64/Makefile
--- a/build/template-FAST_INT64/Makefile
+++ b/build/template-FAST_INT64/Makefile
@@ -34,28 +34,27 @@
#
#=============================================================================
-# Edit lines marked with `==>'. See "SoftFloat-source.html".
+SOURCE_DIR ?= ../../source
+SPECIALIZE_TYPE ?= 8086-SSE
-==> SOURCE_DIR ?= ../../source
-==> SPECIALIZE_TYPE ?= 8086
+SOFTFLOAT_OPTS ?= \
+ -DSOFTFLOAT_ROUND_ODD -DINLINE_LEVEL=5 -DSOFTFLOAT_FAST_DIV32TO16 \
+ -DSOFTFLOAT_FAST_DIV64TO32
-==> SOFTFLOAT_OPTS ?= \
-==> -DSOFTFLOAT_ROUND_ODD -DINLINE_LEVEL=5 -DSOFTFLOAT_FAST_DIV32TO16 \
-==> -DSOFTFLOAT_FAST_DIV64TO32
+DELETE = rm -f
+C_INCLUDES = -I. -I$(SOURCE_DIR)/$(SPECIALIZE_TYPE) -I$(SOURCE_DIR)/include
+COMPILE_C = \
+ cc -c -DSOFTFLOAT_FAST_INT64 $(SOFTFLOAT_OPTS) $(C_INCLUDES) -O2 -o $@
+MAKELIB = ar crs $@
+LIBNAME = libsoftfloat3
-==> DELETE = rm -f
-==> C_INCLUDES = -I. -I$(SOURCE_DIR)/$(SPECIALIZE_TYPE) -I$(SOURCE_DIR)/include
-==> COMPILE_C = \
-==> cc -c -DSOFTFLOAT_FAST_INT64 $(SOFTFLOAT_OPTS) $(C_INCLUDES) -O2 -o $@
-==> MAKELIB = ar crs $@
+OBJ = .o
+LIB = .a
-==> OBJ = .o
-==> LIB = .a
-
-==> OTHER_HEADERS =
+OTHER_HEADERS =
.PHONY: all
-all: softfloat$(LIB)
+all: $(LIBNAME)$(LIB)
OBJS_PRIMITIVES = \
s_eq128$(OBJ) \
@@ -381,11 +380,11 @@ $(OBJS_PRIMITIVES) $(OBJS_OTHERS): %$(OBJ): $(SOURCE_DIR)/%.c
$(OBJS_SPECIALIZE): %$(OBJ): $(SOURCE_DIR)/$(SPECIALIZE_TYPE)/%.c
$(COMPILE_C) $(SOURCE_DIR)/$(SPECIALIZE_TYPE)/$*.c
-softfloat$(LIB): $(OBJS_ALL)
+$(LIBNAME)$(LIB): $(OBJS_ALL)
$(DELETE) $@
$(MAKELIB) $^
.PHONY: clean
clean:
- $(DELETE) $(OBJS_ALL) softfloat$(LIB)
+ $(DELETE) $(OBJS_ALL) $(LIBNAME)$(LIB)
diff --git a/build/template-FAST_INT64/platform.h b/build/template-FAST_INT64/platform.h
--- a/build/template-FAST_INT64/platform.h
+++ b/build/template-FAST_INT64/platform.h
@@ -34,17 +34,15 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
=============================================================================*/
-// Edit lines marked with `==>'. See "SoftFloat-source.html".
-
/*----------------------------------------------------------------------------
*----------------------------------------------------------------------------*/
-==> #define LITTLEENDIAN 1
+#define LITTLEENDIAN 1
/*----------------------------------------------------------------------------
*----------------------------------------------------------------------------*/
-==> #define INLINE inline
+#define INLINE inline
/*----------------------------------------------------------------------------
*----------------------------------------------------------------------------*/
-==> #define THREAD_LOCAL _Thread_local
+#define THREAD_LOCAL

View File

@ -3,13 +3,18 @@ declare -a ldirs
declare -a pdirs
declare -A hdeps
sources=(../../nix/sources.json ../../nix/sources-pmnsh.json)
[ "yes" == "${build_openssl-no}" ] && sources=(../../nix/sources-openssl.json ${sources[@]})
patches=compat/$1
deriver=urbit-$1-build
markfil=.$1~
depdirs=
nixpath=${NIX_STORE-../build}
: "${MAKE:=make}"
: ${gnutar:=tar}
: ${gnumake:=make}
: ${sha256tool:=sha256sum}
export MAKE=$gnumake
# LDFLAGS doesn't like absolute paths
if [ "${nixpath:0:1}" == "/" ]
@ -71,7 +76,7 @@ buildnixdep () {
fi
mkdir -p $dir
pushd $dir
curl -fL "$url"|(tar --strip $strip -xzf - || true)
curl -fL "$url"|($gnutar --strip $strip -xzf - || true)
popd
fi
else
@ -86,7 +91,7 @@ buildnixdep () {
[ -e $patch ] && patch -d $dir -p 1 <$patch
pushd $dir
eval "$cmdprep"
eval ${MAKE} "$cmdmake"
eval $gnumake "$cmdmake"
touch $markfil
popd
fi
@ -98,13 +103,13 @@ buildnixdep () {
echo Uploading freshly built $hash-$key to binary cache...
tar -C $dir -czf $hash.tar .
local size=$(stat -c '%s' $hash.tar)
read filehash _ < <(sha256sum $hash.tar)
read filehash _ < <($sha256tool $hash.tar)
curl -fL -H "Content-Type: application/gzip" -H "Authorization: Bearer $CACHIX_AUTH_TOKEN" --data-binary @"$hash.tar" "$cache/nar"
curl -fL -H "Content-Type: application/json" -H "Authorization: Bearer $CACHIX_AUTH_TOKEN" --data-binary @- "$cache/${hash}.narinfo" <<EOF
{
"cStoreHash": "$hash",
"cStoreSuffix": "$key",
"cNarHash": "sha256:$(hex2nixbase32 $filehash)",
"cNarHash": "$sha256tool:$(hex2nixbase32 $filehash)",
"cNarSize": $size,
"cFileHash": "$filehash",
"cFileSize": $size,
@ -129,7 +134,7 @@ do
patch=$patches/$key.patch
read hash _ < <((
echo -n $json
[ -e $patch ] && cat $patch)|sha256sum)
[ -e $patch ] && cat $patch)|$sha256tool)
hash=$(hex2nixbase32 $hash)
hdeps[$key]=$hash
depdirs="$depdirs|gsub(\"\\\\.\\\\./$key\";\"\\(\$d)/$hash-$key\")"

26
pkg/urbit/configure vendored
View File

@ -64,6 +64,7 @@ do
shift
done
[ -z "${NO_GUARD_PAGE-}" ] && defmacro U3_GUARD_PAGE 1
[ -n "${MEMORY_DEBUG-}" ] && defmacro U3_MEMORY_DEBUG 1
[ -n "${MEMORY_LOG-}" ] && defmacro U3_MEMORY_LOG 1
[ -n "${CPU_DEBUG-}" ] && defmacro U3_CPU_DEBUG 1
@ -86,7 +87,7 @@ case $(tr A-Z a-z <<< $cpu) in
i686)
defmacro U3_OS_ENDIAN_little 1
;;
x86_64)
x86_64 | amd64)
defmacro U3_OS_ENDIAN_little 1
;;
arm64|aarch64)
@ -110,7 +111,7 @@ case $(tr A-Z a-z <<< $os) in
mpkgs=(cmake curl gcc jq make)
pacman -S --needed autoconf automake-wrapper libtool patch ${mpkgs[@]/#/mingw-w64-x86_64-}
export MAKE=mingw32-make
gnumake=mingw32-make
. compat/poor-mans-nix-shell.sh mingw
compat/create-include-files.sh 'stat -c %s' /etc/pki/ca-trust/extracted/openssl/ca-bundle.trust.crt
@ -157,7 +158,28 @@ case $(tr A-Z a-z <<< $os) in
deps="$deps kvm" # XX use new compat.mk pattern
;;
*openbsd*)
# pkg_add bash automake libtool jq gtar cmake gmake libsigsegv gmp
# Tested versions:
# bash-5.1.8 automake-1.16.3 (autoconf-2.69p3) libtool-2.4.2p2
# jq-1.6p0 gtar-1.34-static cmake-3.20.3p0v0 gmake-4.3 libsigsegv-2.12
# gmp-6.2.1p0
gnutar=gtar
gnumake=gmake
sha256tool=sha256
build_openssl=yes
export AUTOCONF_VERSION="${AUTOCONF_VERSION-2.69}"
export AUTOMAKE_VERSION="${AUTOMAKE_VERSION-1.16}"
. compat/poor-mans-nix-shell.sh openbsd
compat/create-include-files.sh 'stat -f %z' /etc/ssl/cert.pem
defmacro U3_OS_bsd 1
defmacro U3_OS_no_ubc 1
export PKG_CONFIG_PATH="${PKG_CONFIG_PATH-}"
deps="$deps aes_siv secp256k1"
compat="${compat-} posix openbsd"
;;
*)
echo "Unknown or unsupported OS: '$os'" >&2

View File

@ -251,7 +251,7 @@ _main_getopt(c3_i argc, c3_c** argv)
break;
}
case 'Y': {
u3_Host.ops_u.puk_c = _main_repath(optarg);
u3_Host.ops_u.puk_c = strdup(optarg);
break;
}
case 'Z': {
@ -681,6 +681,7 @@ u3_ve_usage(c3_i argc, c3_c** argv)
"-Y, --scry-into FILE Optional name of file (for -X)\n",
"-Z, --scry-format FORMAT Optional file format ('jam', or aura, for -X)\n",
" --no-conn Do not run control plane\n",
" --no-dock Skip binary \"docking\" on boot\n",
"\n",
"Development Usage:\n",
" To create a development ship, use a fakezod:\n",

View File

@ -56,6 +56,16 @@
# define c3_max(x, y) ( ((x) > (y)) ? (x) : (y) )
# define c3_min(x, y) ( ((x) < (y)) ? (x) : (y) )
//! Round up/down (respectively).
//!
//! @param[in] x Integer to round.
//! @param[in] n Multiple to round to. Must be power of 2.
//!
//! @return `x` rounded to the nearest multiple of `n`.
# define c3_rop(x, n) (((x) + ((n) - 1)) & (~((n) - 1)))
# define c3_rod(x, n) ((x) & ~((n) - 1))
/* Rotate.
*/
# define c3_rotw(r, x) ( ((x) << (r)) | ((x) >> (32 - (r))) )

View File

@ -387,6 +387,7 @@
# define c3__ergo c3_s4('e','r','g','o')
# define c3__esh c3_s3('e','s','h')
# define c3__etch c3_s4('e','t','c','h')
# define c3__evil c3_s4('e','v','i','l')
# define c3__ex c3_s2('e','x')
# define c3__exit c3_s4('e','x','i','t')
# define c3__eyre c3_s4('e','y','r','e')

View File

@ -25,7 +25,7 @@
/* u3a_bytes: number of bytes in memory.
*/
# define u3a_bytes (c3_w)((1 << (2 + u3a_bits)))
# define u3a_bytes (sizeof(c3_w) * u3a_words)
/* u3a_cells: number of representable cells.
*/
@ -397,36 +397,33 @@
u3a_push(const u3a_pile* pil_u)
{
u3R->cap_p += pil_u->mov_ws;
return u3a_peek(pil_u);
}
/* u3a_pile_sane(): bail on invalid road stack state.
*/
inline void
u3a_pile_sane(const u3a_pile* pil_u)
{
#ifndef U3_GUARD_PAGE
// !off means we're on a north road
//
if ( !pil_u->off_ws ) {
if( !(u3R->cap_p > u3R->hat_p) ) {
u3m_bail(c3__meme);
}
#ifdef U3_MEMORY_DEBUG
# ifdef U3_MEMORY_DEBUG
c3_assert( pil_u->top_p >= u3R->cap_p );
#endif
# endif
}
else {
if( !(u3R->cap_p < u3R->hat_p) ) {
u3m_bail(c3__meme);
}
#ifdef U3_MEMORY_DEBUG
# ifdef U3_MEMORY_DEBUG
c3_assert( pil_u->top_p <= u3R->cap_p );
#endif
# endif
}
#endif /* ifndef U3_GUARD_PAGE */
#ifdef U3_MEMORY_DEBUG
c3_assert( pil_u->rod_u == u3R );
#endif
return u3a_peek(pil_u);
}
/* u3a_pile_done(): assert valid upon completion.
@ -708,14 +705,6 @@
void (*pat_f)(u3_atom, void*),
c3_o (*cel_f)(u3_noun, void*));
/* u3a_walk_fore_unsafe(): u3a_walk_fore(), without overflow checks
*/
void
u3a_walk_fore_unsafe(u3_noun a,
void* ptr_v,
void (*pat_f)(u3_atom, void*),
c3_o (*cel_f)(u3_noun, void*));
/* u3a_string(): `a` as an on-loom c-string.
*/
c3_c*

View File

@ -84,4 +84,9 @@
void
u3e_foul(void);
/* u3e_init(): initialize page tracking.
*/
void
u3e_init(void);
#endif /* ifndef U3_EVENTS_H */

View File

@ -44,6 +44,11 @@
void
u3m_pave(c3_o nuu_o);
/* u3m_signal(): treat a nock-level exception as a signal interrupt.
*/
void
u3m_signal(u3_noun sig_l);
/* u3m_file(): load file, as atom, or bail.
*/
u3_noun

View File

@ -27,7 +27,6 @@
*top = i;
} while ( u3_nul != t );
u3a_pile_sane(&pil_u);
u3j_gate_prep(&sit_u, u3k(b));
while ( c3n == u3a_pile_done(&pil_u) ) {

View File

@ -149,9 +149,11 @@ _cqea_siv_de(c3_y* key_y,
txt_y = u3r_bytes_alloc(0, txt_w, txt);
out_y = u3a_malloc(txt_w);
ret = ( 0 != (*low_f)(txt_y, txt_w, dat_u, soc_w, key_y, iv_y, out_y) )
? u3_none
: u3nc(0, u3i_bytes(txt_w, out_y));
if ( 0 != (*low_f)(txt_y, txt_w, dat_u, soc_w, key_y, iv_y, out_y) ) {
return u3m_bail(c3__evil);
}
ret = u3nc(0, u3i_bytes(txt_w, out_y));
u3a_free(txt_y);
u3a_free(out_y);

View File

@ -984,10 +984,6 @@
u3j_site raq_u;
u3j_gate_prep(&raq_u, u3k(raq));
// check for stack overflow
//
u3a_pile_sane(&pil_u);
while ( c3n == u3a_pile_done(&pil_u) ) {
p_wag = _last_k(par_u->har, p_wag);
puq_wag = u3j_gate_slam(&raq_u, u3nc(par_u->res, puq_wag));

View File

@ -13,8 +13,6 @@ void*
u3a_pop(const u3a_pile* pil_u);
void*
u3a_push(const u3a_pile* pil_u);
void
u3a_pile_sane(const u3a_pile* pil_u);
c3_o
u3a_pile_done(const u3a_pile* pil_u);
@ -715,12 +713,13 @@ u3a_cellblock(c3_w num_w)
c3_w i_w;
if ( c3y == u3a_is_north(u3R) ) {
if ( u3R->cap_p <= (u3R->hat_p + (num_w * u3a_minimum)) ) {
if ( u3R->cap_p <= (u3R->hat_p + (num_w * u3a_minimum) + (1 << u3a_page)) ) {
return c3n;
}
else {
u3_post hat_p = u3R->hat_p;
u3_post cel_p = u3R->all.cel_p;
u3_post hat_p = u3R->hat_p;
u3R->hat_p += (num_w * u3a_minimum);
for ( i_w = 0; i_w < num_w; i_w++) {
u3_post all_p = hat_p;
@ -744,17 +743,18 @@ u3a_cellblock(c3_w num_w)
u3to(u3a_fbox, fre_p)->nex_p = cel_p;
cel_p = fre_p;
}
u3R->hat_p = hat_p;
u3R->all.cel_p = cel_p;
}
}
else {
if ( (u3R->cap_p + (num_w * u3a_minimum)) >= u3R->hat_p ) {
if ( (u3R->cap_p + (num_w * u3a_minimum) + (1 << u3a_page)) >= u3R->hat_p ) {
return c3n;
}
else {
u3_post hat_p = u3R->hat_p;
u3_post cel_p = u3R->all.cel_p;
u3_post hat_p = u3R->hat_p;
u3R->hat_p -= (num_w * u3a_minimum);
for ( i_w = 0; i_w < num_w; i_w++ ) {
u3_post all_p = (hat_p -= u3a_minimum);
@ -776,7 +776,7 @@ u3a_cellblock(c3_w num_w)
u3to(u3a_fbox, fre_p)->nex_p = cel_p;
cel_p = fre_p;
}
u3R->hat_p = hat_p;
u3R->all.cel_p = cel_p;
}
}
@ -1174,7 +1174,6 @@ _ca_take_next_north(u3a_pile* pil_u, u3_noun veb)
else {
u3a_cell* old_u = (u3a_cell*)veb_u;
_ca_take* fam_u = u3a_push(pil_u);
u3a_pile_sane(pil_u);
fam_u->hed = u3_none;
fam_u->old = veb;
@ -1230,7 +1229,6 @@ _ca_take_next_south(u3a_pile* pil_u, u3_noun veb)
else {
u3a_cell* old_u = (u3a_cell*)veb_u;
_ca_take* fam_u = u3a_push(pil_u);
u3a_pile_sane(pil_u);
fam_u->hed = u3_none;
fam_u->old = veb;
@ -2654,50 +2652,6 @@ u3a_walk_fore(u3_noun a,
else {
*top = u3t(a);
top = u3a_push(&pil_u);
u3a_pile_sane(&pil_u);
*top = u3h(a);
}
a = *top;
}
}
/* u3a_walk_fore_unsafe(): u3a_walk_fore(), without overflow checks
*/
void
u3a_walk_fore_unsafe(u3_noun a,
void* ptr_v,
void (*pat_f)(u3_atom, void*),
c3_o (*cel_f)(u3_noun, void*))
{
u3_noun* top;
u3a_pile pil_u;
// initialize stack control; push argument
//
u3a_pile_prep(&pil_u, sizeof(u3_noun));
top = u3a_push(&pil_u);
*top = a;
while ( c3n == u3a_pile_done(&pil_u) ) {
// visit an atom, then pop the stack
//
if ( c3y == u3a_is_atom(a) ) {
pat_f(a, ptr_v);
top = u3a_pop(&pil_u);
}
// vist a cell, if c3n, pop the stack
//
else if ( c3n == cel_f(a, ptr_v) ) {
top = u3a_pop(&pil_u);
}
// otherwise, push the tail and continue into the head
//
else {
*top = u3t(a);
// NB: overflow check elided here
//
top = u3a_push(&pil_u);
*top = u3h(a);
}

View File

@ -29,6 +29,11 @@
//! handled outside this module).
//! - faults are handled by dirtying the page and switching protections to
//! read/write.
//! - a guard page is initially placed in the approximate middle of the free
//! space between the heap and stack at the time of the first page fault.
//! when a fault is detected in the guard page, the guard page is recentered
//! in the free space of the current road. if the guard page cannot be
//! recentered, then memory exhaustion has occurred.
//!
//! ### updates (u3e_save())
//!
@ -71,6 +76,15 @@
#include <fcntl.h>
#include <sys/stat.h>
// Base loom offset of the guard page.
static u3p(c3_w) gar_pag_p;
//! Urbit page size in 4-byte words.
static const size_t pag_wiz_i = 1 << u3a_page;
//! Urbit page size in bytes.
static const size_t pag_siz_i = sizeof(c3_w) * pag_wiz_i;
#ifdef U3_SNAPSHOT_VALIDATION
/* Image check.
*/
@ -172,6 +186,60 @@ _ce_mapfree(void* map_v)
}
#endif
#ifdef U3_GUARD_PAGE
//! Place a guard page at the (approximate) middle of the free space between
//! the heap and stack of the current road, bailing if memory has been
//! exhausted.
static c3_i
_ce_center_guard_page(void)
{
u3p(c3_w) bot_p, top_p;
if ( !u3R ) {
top_p = u3a_outa(u3_Loom + u3a_words);
bot_p = u3a_outa(u3_Loom);
}
else if ( c3y == u3a_is_north(u3R) ) {
top_p = c3_rod(u3R->cap_p, pag_wiz_i);
bot_p = c3_rop(u3R->hat_p, pag_wiz_i);
}
else {
top_p = c3_rod(u3R->hat_p, pag_wiz_i);
bot_p = c3_rop(u3R->cap_p, pag_wiz_i);
}
if ( top_p < bot_p + pag_wiz_i ) {
fprintf(stderr,
"loom: not enough memory to recenter the guard page\r\n");
goto bail;
}
const u3p(c3_w) old_gar_p = gar_pag_p;
const c3_w mid_p = (top_p - bot_p) / 2;
gar_pag_p = bot_p + c3_rod(mid_p, pag_wiz_i);
if ( old_gar_p == gar_pag_p ) {
fprintf(stderr,
"loom: can't move the guard page to the same location"
" (base address %p)\r\n",
u3a_into(gar_pag_p));
goto bail;
}
if ( -1 == mprotect(u3a_into(gar_pag_p), pag_siz_i, PROT_NONE) ) {
fprintf(stderr,
"loom: failed to protect the guard page "
"(base address %p)\r\n",
u3a_into(gar_pag_p));
goto fail;
}
return 1;
bail:
u3m_signal(c3__meme);
fail:
return 0;
}
#endif /* ifdef U3_GUARD_PAGE */
/* u3e_fault(): handle a memory event with libsigsegv protocol.
*/
c3_i
@ -193,40 +261,38 @@ u3e_fault(void* adr_v, c3_i ser_i)
c3_assert(0);
return 0;
}
else {
c3_w off_w = u3a_outa(adr_w);
c3_w pag_w = off_w >> u3a_page;
c3_w blk_w = (pag_w >> 5);
c3_w bit_w = (pag_w & 31);
#if 0
if ( pag_w == 131041 ) {
u3l_log("dirty page %d (at %p); unprotecting %p to %p\r\n",
pag_w,
adr_v,
(u3_Loom + (pag_w << u3a_page)),
(u3_Loom + (pag_w << u3a_page) + (1 << u3a_page)));
}
#endif
u3p(c3_w) adr_p = u3a_outa(adr_w);
c3_w pag_w = adr_p >> u3a_page;
c3_w blk_w = (pag_w >> 5);
c3_w bit_w = (pag_w & 31);
if ( 0 != (u3P.dit_w[blk_w] & (1 << bit_w)) ) {
fprintf(stderr, "strange page: %d, at %p, off %x\r\n",
pag_w, adr_w, off_w);
c3_assert(0);
return 0;
}
u3P.dit_w[blk_w] |= (1 << bit_w);
if ( -1 == mprotect((void *)(u3_Loom + (pag_w << u3a_page)),
(1 << (u3a_page + 2)),
(PROT_READ | PROT_WRITE)) )
{
fprintf(stderr, "loom: fault mprotect: %s\r\n", strerror(errno));
c3_assert(0);
#ifdef U3_GUARD_PAGE
// The fault happened in the guard page.
if ( gar_pag_p <= adr_p && adr_p < gar_pag_p + pag_wiz_i ) {
if ( 0 == _ce_center_guard_page() ) {
return 0;
}
}
else
#endif /* ifdef U3_GUARD_PAGE */
if ( 0 != (u3P.dit_w[blk_w] & (1 << bit_w)) ) {
fprintf(stderr, "strange page: %d, at %p, off %x\r\n", pag_w, adr_w, adr_p);
c3_assert(0);
return 0;
}
u3P.dit_w[blk_w] |= (1 << bit_w);
if ( -1 == mprotect((void *)(u3_Loom + (pag_w << u3a_page)),
pag_siz_i,
(PROT_READ | PROT_WRITE)) )
{
fprintf(stderr, "loom: fault mprotect: %s\r\n", strerror(errno));
c3_assert(0);
return 0;
}
return 1;
}
@ -262,7 +328,7 @@ _ce_image_open(u3e_image* img_u)
}
else {
c3_d siz_d = buf_u.st_size;
c3_d pgs_d = (siz_d + (c3_d)((1 << (u3a_page + 2)) - 1)) >>
c3_d pgs_d = (siz_d + (c3_d)(pag_siz_i - 1)) >>
(c3_d)(u3a_page + 2);
if ( !siz_d ) {
@ -388,12 +454,12 @@ _ce_patch_verify(u3_ce_patch* pat_u)
fprintf(stderr, "loom: patch seek: %s\r\n", strerror(errno));
return c3n;
}
if ( -1 == read(pat_u->mem_i, mem_w, (1 << (u3a_page + 2))) ) {
if ( -1 == read(pat_u->mem_i, mem_w, pag_siz_i) ) {
fprintf(stderr, "loom: patch read: %s\r\n", strerror(errno));
return c3n;
}
{
c3_w nug_w = u3r_mug_words(mem_w, (1 << u3a_page));
c3_w nug_w = u3r_mug_words(mem_w, pag_wiz_i);
if ( mug_w != nug_w ) {
fprintf(stderr, "loom: patch mug mismatch %d/%d; (%x, %x)\r\n",
@ -476,14 +542,8 @@ _ce_patch_write_page(u3_ce_patch* pat_u,
c3_w pgc_w,
c3_w* mem_w)
{
if ( -1 == lseek(pat_u->mem_i, (pgc_w << (u3a_page + 2)), SEEK_SET) ) {
c3_assert(0);
}
if ( (1 << (u3a_page + 2)) !=
write(pat_u->mem_i, mem_w, (1 << (u3a_page + 2))) )
{
c3_assert(0);
}
c3_assert(-1 != lseek(pat_u->mem_i, pgc_w * pag_siz_i, SEEK_SET));
c3_assert(pag_siz_i == write(pat_u->mem_i, mem_w, pag_siz_i));
}
/* _ce_patch_count_page(): count a page, producing new counter.
@ -515,8 +575,7 @@ _ce_patch_save_page(u3_ce_patch* pat_u,
c3_w* mem_w = u3_Loom + (pag_w << u3a_page);
pat_u->con_u->mem_u[pgc_w].pag_w = pag_w;
pat_u->con_u->mem_u[pgc_w].mug_w = u3r_mug_words(mem_w,
(1 << u3a_page));
pat_u->con_u->mem_u[pgc_w].mug_w = u3r_mug_words(mem_w, pag_wiz_i);
#if 0
u3l_log("protect a: page %d\r\n", pag_w);
@ -524,7 +583,7 @@ _ce_patch_save_page(u3_ce_patch* pat_u,
_ce_patch_write_page(pat_u, pgc_w, mem_w);
if ( -1 == mprotect(u3_Loom + (pag_w << u3a_page),
(1 << (u3a_page + 2)),
pag_siz_i,
PROT_READ) )
{
c3_assert(0);
@ -552,8 +611,8 @@ _ce_patch_compose(void)
u3m_water(&nwr_w, &swu_w);
nor_w = (nwr_w + ((1 << u3a_page) - 1)) >> u3a_page;
sou_w = (swu_w + ((1 << u3a_page) - 1)) >> u3a_page;
nor_w = (nwr_w + (pag_wiz_i - 1)) >> u3a_page;
sou_w = (swu_w + (pag_wiz_i - 1)) >> u3a_page;
}
#ifdef U3_SNAPSHOT_VALIDATION
@ -676,7 +735,7 @@ _ce_patch_apply(u3_ce_patch* pat_u)
//
for ( i_w = 0; i_w < pat_u->con_u->pgs_w; i_w++ ) {
c3_w pag_w = pat_u->con_u->mem_u[i_w].pag_w;
c3_w mem_w[1 << u3a_page];
c3_w mem_w[pag_wiz_i];
c3_i fid_i;
c3_w off_w;
@ -689,7 +748,7 @@ _ce_patch_apply(u3_ce_patch* pat_u)
off_w = (u3a_pages - (pag_w + 1));
}
if ( -1 == read(pat_u->mem_i, mem_w, (1 << (u3a_page + 2))) ) {
if ( -1 == read(pat_u->mem_i, mem_w, pag_siz_i) ) {
fprintf(stderr, "loom: patch apply read: %s\r\n", strerror(errno));
c3_assert(0);
}
@ -698,13 +757,13 @@ _ce_patch_apply(u3_ce_patch* pat_u)
fprintf(stderr, "loom: patch apply seek: %s\r\n", strerror(errno));
c3_assert(0);
}
if ( -1 == write(fid_i, mem_w, (1 << (u3a_page + 2))) ) {
if ( -1 == write(fid_i, mem_w, pag_siz_i) ) {
fprintf(stderr, "loom: patch apply write: %s\r\n", strerror(errno));
c3_assert(0);
}
}
#if 0
u3l_log("apply: %d, %x\n", pag_w, u3r_mug_words(mem_w, (1 << u3a_page)));
u3l_log("apply: %d, %x\n", pag_w, u3r_mug_words(mem_w, pag_wiz_i));
#endif
}
}
@ -721,7 +780,7 @@ _ce_image_blit(u3e_image* img_u,
}
c3_w i_w;
c3_w siz_w = 1 << (u3a_page + 2);
c3_w siz_w = pag_siz_i;
lseek(img_u->fid_i, 0, SEEK_SET);
for ( i_w = 0; i_w < img_u->pgs_w; i_w++ ) {
@ -753,18 +812,18 @@ _ce_image_fine(u3e_image* img_u,
c3_ws stp_ws)
{
c3_w i_w;
c3_w buf_w[1 << u3a_page];
c3_w buf_w[pag_wiz_i];
lseek(img_u->fid_i, 0, SEEK_SET);
for ( i_w=0; i_w < img_u->pgs_w; i_w++ ) {
c3_w mem_w, fil_w;
if ( -1 == read(img_u->fid_i, buf_w, (1 << (u3a_page + 2))) ) {
if ( -1 == read(img_u->fid_i, buf_w, pag_siz_i) ) {
fprintf(stderr, "loom: image fine read: %s\r\n", strerror(errno));
c3_assert(0);
}
mem_w = u3r_mug_words(ptr_w, (1 << u3a_page));
fil_w = u3r_mug_words(buf_w, (1 << u3a_page));
mem_w = u3r_mug_words(ptr_w, pag_wiz_i);
fil_w = u3r_mug_words(buf_w, pag_wiz_i);
if ( mem_w != fil_w ) {
c3_w pag_w = (ptr_w - u3_Loom) >> u3a_page;
@ -804,10 +863,10 @@ _ce_image_copy(u3e_image* fom_u, u3e_image* tou_u)
// copy pages into destination image
//
for ( i_w = 0; i_w < fom_u->pgs_w; i_w++ ) {
c3_w mem_w[1 << u3a_page];
c3_w mem_w[pag_wiz_i];
c3_w off_w = i_w;
if ( -1 == read(fom_u->fid_i, mem_w, (1 << (u3a_page + 2))) ) {
if ( -1 == read(fom_u->fid_i, mem_w, pag_siz_i) ) {
fprintf(stderr, "loom: image copy read: %s\r\n", strerror(errno));
return c3n;
}
@ -816,7 +875,7 @@ _ce_image_copy(u3e_image* fom_u, u3e_image* tou_u)
fprintf(stderr, "loom: image copy seek: %s\r\n", strerror(errno));
return c3n;
}
if ( -1 == write(tou_u->fid_i, mem_w, (1 << (u3a_page + 2))) ) {
if ( -1 == write(tou_u->fid_i, mem_w, pag_siz_i) ) {
fprintf(stderr, "loom: image copy write: %s\r\n", strerror(errno));
return c3n;
}
@ -921,11 +980,11 @@ u3e_save(void)
{
_ce_image_fine(&u3P.nor_u,
u3_Loom,
(1 << u3a_page));
pag_wiz_i);
_ce_image_fine(&u3P.sou_u,
(u3_Loom + (1 << u3a_bits) - (1 << u3a_page)),
-(1 << u3a_page));
(u3_Loom + (1 << u3a_bits) - pag_wiz_i),
-(ssize_t)pag_wiz_i);
c3_assert(u3P.nor_u.pgs_w == u3K.nor_w);
c3_assert(u3P.sou_u.pgs_w == u3K.sou_w);
@ -991,11 +1050,11 @@ u3e_live(c3_o nuu_o, c3_c* dir_c)
{
_ce_image_blit(&u3P.nor_u,
u3_Loom,
(1 << u3a_page));
pag_wiz_i);
_ce_image_blit(&u3P.sou_u,
(u3_Loom + (1 << u3a_bits) - (1 << u3a_page)),
-(1 << u3a_page));
(u3_Loom + (1 << u3a_bits) - pag_wiz_i),
-(ssize_t)pag_wiz_i);
u3l_log("boot: protected loom\r\n");
}
@ -1012,6 +1071,7 @@ u3e_live(c3_o nuu_o, c3_c* dir_c)
}
}
}
return nuu_o;
}
@ -1036,3 +1096,11 @@ u3e_foul(void)
{
memset((void*)u3P.dit_w, 0xff, sizeof(u3P.dit_w));
}
void
u3e_init(void)
{
#ifdef U3_GUARD_PAGE
_ce_center_guard_page();
#endif
}

View File

@ -361,7 +361,9 @@ _cm_signal_deep(c3_w mil_w)
// go utterly haywire.
//
if ( 0 == u3H->rod_u.bug.mer ) {
u3H->rod_u.bug.mer = u3i_string("emergency buffer");
u3H->rod_u.bug.mer = u3i_string(
"emergency buffer with sufficient space to cons the trace and bail"
);
}
if ( mil_w ) {
@ -731,6 +733,11 @@ u3m_bail(u3_noun how)
u3m_signal(how);
}
// release the emergency buffer, ensuring space for cells
//
u3z(u3R->bug.mer);
u3R->bug.mer = 0;
/* Reconstruct a correct error ball.
*/
if ( _(u3ud(how)) ) {
@ -900,6 +907,10 @@ u3m_hate(c3_w pad_w)
u3R->ear_p = u3R->cap_p;
u3m_leap(pad_w);
u3R->bug.mer = u3i_string(
"emergency buffer with sufficient space to cons the trace and bail"
);
}
/* u3m_love(): return product from leap.
@ -1290,20 +1301,32 @@ u3m_soft(c3_w mil_w,
return why;
}
else {
// don't use .^ at the top level!
//
c3_assert(1 != u3h(why));
u3_noun tax, cod, pro;
switch ( u3h(why) ) {
case 2: {
cod = c3__exit;
tax = u3t(why);
} break;
case 3: {
cod = u3h(u3t(why));
tax = u3t(u3t(why));
} break;
// don't use .^ at the top level!
//
default: {
u3m_p("invalid mot", u3h(why));
c3_assert(0);
}
}
// don't call +mook if we have no kernel
//
// This is required to soft the boot sequence.
// XX produce specific error motes instead of %2?
//
if ( 0 == u3A->roc ) {
u3_noun tax = u3t(why);
u3m_p("tone", u3h(why));
while ( u3_nul != tax ) {
u3_noun dat, mot, val;
u3x_cell(tax, &dat, &tax);
@ -1323,31 +1346,21 @@ u3m_soft(c3_w mil_w,
}
}
u3z(why);
return u3nc(c3__fail, u3_nul);
pro = u3nc(u3k(cod), u3_nul);
}
// %evil leaves no trace
//
else if ( c3__evil == cod ) {
pro = u3nc(u3k(cod), u3_nul);
}
else {
u3_noun tax, cod, pro, mok;
if ( 2 == u3h(why) ) {
cod = c3__exit;
tax = u3k(u3t(why));
}
else {
c3_assert(3 == u3h(why));
cod = u3k(u3h(u3t(why)));
tax = u3k(u3t(u3t(why)));
}
mok = u3dc("mook", 2, tax);
pro = u3nc(cod, u3k(u3t(mok)));
u3_noun mok = u3dc("mook", 2, u3k(tax));
pro = u3nc(u3k(cod), u3k(u3t(mok)));
u3z(mok);
u3z(why);
return pro;
}
u3z(why);
return pro;
}
}
@ -1796,6 +1809,10 @@ u3m_boot(c3_c* dir_c)
*/
u3m_pave(nuu_o);
/* Place the guard page.
*/
u3e_init();
/* Initialize the jet system.
*/
{

View File

@ -1444,9 +1444,9 @@ _n_push(c3_ys mov, c3_ys off, u3_noun a)
{
u3R->cap_p += mov;
// XX stack sanity-check disabled for performance
// XX switch to u3a_push()
//
#if 0
#ifndef U3_GUARD_PAGE
if ( 0 == off ) {
if( !(u3R->cap_p > u3R->hat_p) ) {
u3m_bail(c3__meme);

View File

@ -864,7 +864,7 @@ u3r_p(u3_noun a,
if ( (c3y == u3r_cell(a, &feg, &nux)) &&
(c3y == u3r_sing(feg, b)) )
{
*c = nux;
if ( c ) *c = nux;
return c3y;
}
else return c3n;
@ -1732,10 +1732,6 @@ _cr_mug_next(u3a_pile* pil_u, u3_noun veb)
u3a_cell* cel_u = (u3a_cell*)veb_u;
_cr_mugf* fam_u = u3a_push(pil_u);
// check for overflow
//
u3a_pile_sane(pil_u);
fam_u->mug_l = 0;
fam_u->cel = veb;

View File

@ -158,15 +158,9 @@ u3s_jam_fib(u3i_slab* sab_u, u3_noun a)
fib_u.bit_w = 0;
u3i_slab_init(sab_u, 0, fib_u.a_w);
// as this is a hot path, we unsafely elide overflow checks
//
// a page-fault overflow detection system is urgently needed ...
//
u3a_walk_fore_unsafe(a, &fib_u, _cs_jam_fib_atom_cb,
_cs_jam_fib_cell_cb);
u3a_walk_fore(a, &fib_u, _cs_jam_fib_atom_cb, _cs_jam_fib_cell_cb);
u3h_free(fib_u.har_p);
return fib_u.bit_w;
}
@ -270,18 +264,11 @@ u3s_jam_xeno(u3_noun a, c3_d* len_d, c3_y** byt_y)
{
_jam_xeno_t jam_u = {0};
ur_bsw_init(&jam_u.rit_u, ur_fib11, ur_fib12);
jam_u.har_p = u3h_new();
// as this is a hot path, we unsafely elide overflow checks
//
// a page-fault overflow detection system is urgently needed ...
//
u3a_walk_fore_unsafe(a, &jam_u, _cs_jam_xeno_atom,
_cs_jam_xeno_cell);
u3a_walk_fore(a, &jam_u, _cs_jam_xeno_atom, _cs_jam_xeno_cell);
u3h_free(jam_u.har_p);
return ur_bsw_done(&jam_u.rit_u, len_d, byt_y);
}
@ -360,7 +347,6 @@ _cs_cue_next(u3a_pile* pil_u,
//
else {
_cs_cue* fam_u = u3a_push(pil_u);
u3a_pile_sane(pil_u);
// NB: fam_u->wid unused in head-frame
//
@ -472,7 +458,6 @@ _cs_cue_xeno_next(u3a_pile* pil_u,
case ur_jam_cell: {
_cue_frame_t* fam_u = u3a_push(pil_u);
u3a_pile_sane(pil_u);
fam_u->ref = u3_none;
fam_u->bit_d = bit_d;
@ -731,7 +716,6 @@ _cs_cue_bytes_next(u3a_pile* pil_u,
case ur_jam_cell: {
_cue_frame_t* fam_u = u3a_push(pil_u);
u3a_pile_sane(pil_u);
fam_u->ref = u3_none;
fam_u->bit_d = bit_d;

View File

@ -0,0 +1,83 @@
#include "all.h"
/* _setup(): prepare for tests.
*/
static void
_setup(void)
{
u3m_init();
u3m_pave(c3y);
u3e_init();
}
static u3_noun
_nock_fol(u3_noun fol)
{
return u3n_nock_on(u3_nul, fol);
}
static c3_i
_test_nock_meme(void)
{
// (jam !=(=(~ =|(i=@ |-(?:(=(i ^~((bex 32))) ~ [i $(i +(i))]))))))
//
const c3_y buf_y[] = {
0xe1, 0x16, 0x1b, 0x4, 0x1b, 0xe1, 0x20, 0x58, 0x1c, 0x76, 0x4d, 0x96, 0xd8,
0x31, 0x60, 0x0, 0x0, 0x0, 0x0, 0xd8, 0x8, 0x37, 0xce, 0xd, 0x92, 0x21,
0x83, 0x68, 0x61, 0x87, 0x39, 0xce, 0x4d, 0xe, 0x92, 0x21, 0x87, 0x19, 0x8
};
u3_noun fol = u3s_cue_bytes(sizeof(buf_y), buf_y);
u3_noun gon;
c3_w i_w;
c3_i ret_i = 1;
for ( i_w = 0; i_w < 3; i_w++ ) {
gon = u3m_soft(0, _nock_fol, u3k(fol));
if ( c3n == u3r_p(gon, c3__meme, 0) ) {
u3m_p("nock meme unexpected mote", u3h(gon));
ret_i = 0;
u3z(gon);
break;
}
u3z(gon);
}
u3z(fol);
return ret_i;
}
static c3_i
_test_nock(void)
{
c3_i ret_i = 1;
if ( !_test_nock_meme() ) {
fprintf(stderr, "test nock meme: failed\r\n");
ret_i = 0;
}
return ret_i;
}
/* main(): run all test cases.
*/
int
main(int argc, char* argv[])
{
_setup();
if ( !_test_nock() ) {
fprintf(stderr, "test nock: failed\r\n");
exit(1);
}
// GC
//
u3m_grab(u3_none);
fprintf(stderr, "test nock: ok\r\n");
return 0;
}

View File

@ -63,11 +63,19 @@ u3_lmdb_init(const c3_c* pax_c, size_t siz_i)
return 0;
}
if ( (ret_w = mdb_env_open(env_u, pax_c, 0, 0664)) ) {
mdb_logerror(stderr, ret_w, "lmdb: failed to open event log");
// XX dispose env_u
//
return 0;
{
# if defined(U3_OS_no_ubc)
c3_w ops_w = MDB_WRITEMAP;
# else
c3_w ops_w = 0;
# endif
if ( (ret_w = mdb_env_open(env_u, pax_c, ops_w, 0664)) ) {
mdb_logerror(stderr, ret_w, "lmdb: failed to open event log");
// XX dispose env_u
//
return 0;
}
}
return env_u;

View File

@ -689,18 +689,14 @@ u3_disk_exit(u3_disk* log_u)
}
}
// cancel write thread
// try to cancel write thread
// shortcircuit cleanup if we cannot
//
// XX can deadlock when called from signal handler
// XX revise SIGTSTP handling
//
if ( c3y == log_u->ted_o ) {
c3_i sas_i;
do {
sas_i = uv_cancel(&log_u->req_u);
}
while ( UV_EBUSY == sas_i );
if ( (c3y == log_u->ted_o)
&& (0 > uv_cancel(&log_u->req_u)) )
{
// u3l_log("disk: unable to cleanup\r\n");
return;
}
// close database
@ -885,8 +881,11 @@ u3_disk_init(c3_c* pax_c, u3_disk_cb cb_u)
//
{
const size_t siz_i =
#if (defined(U3_CPU_aarch64) && defined(U3_OS_linux)) || defined(U3_OS_mingw)
#if defined(U3_OS_mingw)
0xf00000000;
// 500 GiB is as large as musl on aarch64 wants to allow
#elif (defined(U3_CPU_aarch64) && defined(U3_OS_linux))
0x7d00000000;
#else
0x10000000000;
#endif

View File

@ -52,6 +52,7 @@
c3_d foq_d; // forward queue size
c3_d fow_d; // forwarded count
c3_d fod_d; // forwards dropped count
c3_d bad_d; // bad ciphertext count
} sat_u; //
} u3_ames;
@ -768,51 +769,47 @@ _ames_cap_queue(u3_ames* sam_u)
}
}
/* _ames_punt_goof(): print %bail error report(s).
*/
static void
_ames_punt_goof(u3_noun lud)
{
if ( 2 == u3qb_lent(lud) ) {
u3_pier_punt_goof("hear", u3k(u3h(lud)));
u3_pier_punt_goof("crud", u3k(u3h(u3t(lud))));
}
else {
u3_noun dul = lud;
c3_w len_w = 1;
while ( u3_nul != dul ) {
u3l_log("ames: bail %u\r\n", len_w++);
u3_pier_punt_goof("ames", u3k(u3h(dul)));
dul = u3t(dul);
}
}
u3z(lud);
}
/* _ames_hear_bail(): handle packet failure.
*/
static void
_ames_hear_bail(u3_ovum* egg_u, u3_noun lud)
{
u3_ames* sam_u = (u3_ames*)egg_u->car_u;
sam_u->sat_u.fal_d++;
c3_w len_w = u3qb_lent(lud);
if ( (u3C.wag_w & u3o_verbose)
|| (0 == (sam_u->sat_u.fal_d % 1000)) )
{
_ames_punt_goof(lud);
u3l_log("ames: packet failed (%" PRIu64 " total)\n\n", sam_u->sat_u.fal_d);
if ( (1 == len_w) && c3__evil == u3h(u3h(lud)) ) {
sam_u->sat_u.bad_d++;
if ( (u3C.wag_w & u3o_verbose)
|| (0 == (sam_u->sat_u.bad_d % 100)) )
{
u3l_log("ames: heard bad crypto (%" PRIu64 " total), "
"check azimuth state\r\n",
sam_u->sat_u.bad_d);
}
}
else {
u3z(lud);
sam_u->sat_u.fal_d++;
if ( 0 == (sam_u->sat_u.fal_d % 1000) ) {
u3l_log("ames: packet failed (%" PRIu64 " total)\n\n", sam_u->sat_u.fal_d);
if ( (u3C.wag_w & u3o_verbose)
|| (0 == (sam_u->sat_u.fal_d % 100)) )
{
if ( 2 == len_w ) {
u3_pier_punt_goof("hear", u3k(u3h(lud)));
u3_pier_punt_goof("crud", u3k(u3h(u3t(lud))));
}
// !2 traces is unusual, just print the first if present
//
else if ( len_w ) {
u3_pier_punt_goof("hear", u3k(u3h(lud)));
}
u3l_log("ames: packet failed (%" PRIu64 " total)\r\n",
sam_u->sat_u.fal_d);
}
}
u3z(lud);
u3_ovum_free(egg_u);
}
@ -853,9 +850,10 @@ _ames_forward(u3_panc* pac_u, u3_noun las)
c3_c* rec_c = u3r_string(rec);
c3_y* pip_y = (c3_y*)&pac_u->ore_u.pip_w;
//NOTE ip byte order assumes little-endian
u3l_log("ames: forwarding for %s to %s from %d.%d.%d.%d:%d\n",
sen_c, rec_c,
pip_y[0], pip_y[1], pip_y[2], pip_y[3],
pip_y[3], pip_y[2], pip_y[1], pip_y[0],
pac_u->ore_u.por_s);
c3_free(sen_c); c3_free(rec_c);

View File

@ -666,6 +666,14 @@ _http_start_respond(u3_hreq* req_u,
c3_i has_len_i = 0;
while ( 0 != hed_u ) {
if ( 0x200 <= rec_u->version ) {
h2o_strtolower(hed_u->nam_c, hed_u->nam_w);
if ( 0 == strncmp(hed_u->nam_c, "connection", 10) ) {
hed_u = hed_u->nex_u;
continue;
}
}
if ( 0 == strncmp(hed_u->nam_c, "content-length", 14) ) {
has_len_i = 1;
}
@ -1608,7 +1616,7 @@ _http_init_tls(uv_buf_t key_u, uv_buf_t cer_u)
"RSA+AES:RSA+3DES:!aNULL:!MD5:!DSS");
// enable ALPN for HTTP 2 support
#if 0 //H2O_USE_ALPN
#if H2O_USE_ALPN
{
SSL_CTX_set_ecdh_auto(tls_u, 1);
h2o_ssl_register_alpn_protocols(tls_u, h2o_http2_alpn_protocols);

View File

@ -1036,13 +1036,11 @@ u3_term_ef_ctlc(void)
{
u3_utty* uty_u = _term_main();
{
if ( uty_u->car_u ) {
u3_noun wir = u3nt(c3__term, '1', u3_nul);
u3_noun cad = u3nt(c3__belt, c3__ctl, 'c');
c3_assert( 1 == uty_u->tid_l );
c3_assert( uty_u->car_u );
_term_ovum_plan(uty_u->car_u, wir, cad);
}

View File

@ -1507,51 +1507,61 @@ u3_king_done(void)
{
uv_handle_t* han_u = (uv_handle_t*)&u3K.tim_u;
// get next binary
//
if ( c3y == u3_Host.nex_o ) {
c3_c* pac_c;
c3_c* ver_c;
// hack to ensure we only try once
if ( u3_Host.xit_i ) {
if ( c3y == u3_Host.nex_o ) {
u3l_log("vere: upgrade failed\r\n");
}
else if ( c3y == u3_Host.pep_o ) {
u3l_log("vere: prep for upgrade failed\r\n");
}
}
else {
// get next binary
//
u3_Host.nex_o = c3n;
if ( c3y == u3_Host.nex_o ) {
c3_c* pac_c;
c3_c* ver_c;
pac_c = _king_get_pace();
// hack to ensure we only try once
//
u3_Host.nex_o = c3n;
switch ( u3_king_next(pac_c, &ver_c) ) {
case -2: {
u3l_log("vere: unable to check for next version\n");
} break;
pac_c = _king_get_pace();
case -1: {
u3l_log("vere: up to date\n");
} break;
switch ( u3_king_next(pac_c, &ver_c) ) {
case -2: {
u3l_log("vere: unable to check for next version\n");
} break;
case 0: {
u3l_log("vere: next (%%%s): %s\n", pac_c, ver_c);
_king_do_upgrade(pac_c, ver_c);
c3_free(ver_c);
} break;
case -1: {
u3l_log("vere: up to date\n");
} break;
default: c3_assert(0);
case 0: {
u3l_log("vere: next (%%%s): %s\n", pac_c, ver_c);
_king_do_upgrade(pac_c, ver_c);
c3_free(ver_c);
} break;
default: c3_assert(0);
}
c3_free(pac_c);
}
else if ( c3y == u3_Host.pep_o ) {
u3l_log("vere: ready for upgrade\n");
}
c3_free(pac_c);
}
else if ( c3y == u3_Host.pep_o ) {
u3l_log("vere: ready for upgrade\n");
}
// copy binary into pier on boot
//
if ( (c3y == u3_Host.ops_u.nuu)
&& (c3y == u3_Host.ops_u.doc) )
{
// hack to ensure we only try once
// copy binary into pier on boot
//
u3_Host.ops_u.nuu = c3n;
u3_king_dock(U3_VERE_PACE);
if ( (c3y == u3_Host.ops_u.nuu)
&& (c3y == u3_Host.ops_u.doc) )
{
// hack to ensure we only try once
//
u3_Host.ops_u.nuu = c3n;
u3_king_dock(U3_VERE_PACE);
}
}
// XX hack, if pier's are still linked, we're not actually done
@ -1566,7 +1576,7 @@ u3_king_done(void)
// XX remove move
//
exit(0);
exit(u3_Host.xit_i);
}
/* u3_king_exit(): shutdown gracefully
@ -1582,10 +1592,11 @@ u3_king_exit(void)
void
u3_king_bail(void)
{
u3_Host.xit_i = 1;
_king_forall_unlink(u3_pier_bail);
_king_loop_exit();
u3_king_done();
exit(1);
exit(u3_Host.xit_i);
}
/* u3_king_grab(): gc the daemon

View File

@ -2234,6 +2234,8 @@ u3_pier_exit(u3_pier* pir_u)
void
u3_pier_bail(u3_pier* pir_u)
{
u3_Host.xit_i = 1;
// halt serf
//
if ( pir_u->god_u ) {

View File

@ -1 +1 @@
1.9
1.10

View File

@ -565,6 +565,14 @@ _serf_work(u3_serf* sef_u, c3_w mil_w, u3_noun job)
sef_u->mug_l,
vir));
}
// event rejected -- bad ciphertext
//
else if ( c3__evil == u3h(gon) ) {
sef_u->sen_d = sef_u->dun_d;
u3z(job);
return u3nt(c3__bail, gon, u3_nul);
}
// event rejected
//
else {

View File

@ -22,7 +22,7 @@ let
#
# Typically the inputs listed here also have a shell.nix in their respective
# source directory you can use directly.
inputsFrom = with pkgsLocal; [ ent herb urbit urcrypt ];
inputsFrom = with pkgsLocal; [ ent urbit urcrypt ];
# Collect the named attribute from all dependencies listed in inputsFrom.
mergeFrom = name: pkgs.lib.concatLists (pkgs.lib.catAttrs name inputsFrom);