Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
8b8d9b6
ames: add libnatpmp for automatic port forwarding
pkova Jan 29, 2024
8d320c6
bazel: make libnatpmp import better
pkova Jan 29, 2024
3a2c326
macos: fix lldb
pkova Feb 27, 2024
a422adf
macos: better mach exception handler error message
pkova Feb 28, 2024
0fff276
macos: remove unnecessary mach SIGFPE handling
pkova Feb 28, 2024
3517aef
events: better error messages for partial write
pkova Mar 13, 2024
8736b2c
bazel: add -fdebug-compilation-dir for debuggers to find source code
pkova Apr 3, 2024
1922768
install: add macos lldb guide
pkova Apr 9, 2024
3556e4b
main: only register mach exception handler once per process
pkova Apr 9, 2024
b199984
macos: fix lldb (#611)
pkova Apr 10, 2024
7c14e69
events: you likely ran out of disk -> check disk space
pkova Apr 15, 2024
25a7183
events: better error messages for partial write (#622)
pkova Apr 15, 2024
c774a31
add more helpful chop message
Apr 16, 2024
27e5c33
ames: address review comments for natpmp
pkova Apr 22, 2024
68429f6
ames: address more libnatpmp nits
pkova Apr 23, 2024
46d20ea
events: add docs link to no-chop printf
tinnus-napbus Apr 24, 2024
ae89983
ames: add libnatpmp for automatic port forwarding (#593)
pkova Apr 24, 2024
ab89195
add more helpful chop message (#635)
Apr 26, 2024
175c2d1
disk: fix broken chop error message
pkova May 1, 2024
639d032
disk: fix broken chop error message (#642)
pkova May 1, 2024
7323954
Revert "disk: fix broken chop error message"
pkova May 1, 2024
385bdf9
Revert "ames: add libnatpmp for automatic port forwarding"
pkova May 1, 2024
c305c50
Revert "ames: add libnatpmp for automatic port forwarding" (#644)
pkova May 1, 2024
07e781a
Revert "disk: fix broken chop error message" (#643)
pkova May 2, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions INSTALL.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,20 @@ This will take a few minutes.

After installing `automake`, `autoconf-archive`, `pkg-config`, and `libtool`, you're ready to build Vere.

#### Debugger

macOS is curious operating system because the kernel is derived from from two codebases, the Mach kernel and the BSD kernel. It inherits two different hardware exception handling facilities, Mach exceptions and POSIX signals. We use `libsigsegv` and utilize the POSIX signals which is usually fine except when it comes to debugging with `lldb`.

`lldb` hijacks the Mach exception ports for the task when it attaches to the process. Mach exceptions get handled before POSIX signals which means that as soon as vere faults (this happens often) `lldb` stop with a `EXC_BAD_ACCESS`. It is impossible to continue debugging from this state without the workaround we implemented in https://github.com/urbit/vere/pull/611.

There are more annoying warts with `lldb` currently. First, if you attach the debugger when booting the ship with `lldb -- your-ship/.run` you have to specify `-t`, otherwise the ship is unable to boot for mysterious reasons. The other option is to start the ship and attach afterwards with `lldb -p PID`. Afterwards you should do this dance:

```
p (void)darwin_register_mach_exception_handler()
pro hand -p true -s false -n false SIGBUS
pro hand -p true -s false -n false SIGSEGV
```

## Build Commands

Once you install the prerequisites, you're ready to build:
Expand Down
4 changes: 2 additions & 2 deletions bazel/common_settings.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ string_flag = rule(
def vere_library(copts = [], linkopts = [], **kwargs):
native.cc_library(
copts = copts + select({
"//:debug": ["-O0", "-g3", "-DC3DBG"],
"//:debug": ["-O0", "-g3", "-DC3DBG", "-fdebug-compilation-dir=."],
"//conditions:default": ["-O3"]
}) + select({
"//:lto": ['-flto'],
Expand All @@ -39,7 +39,7 @@ def vere_library(copts = [], linkopts = [], **kwargs):
def vere_binary(copts = [], linkopts = [], **kwargs):
native.cc_binary(
copts = copts + select({
"//:debug": ["-O0", "-g3", "-DC3DBG"],
"//:debug": ["-O0", "-g3", "-DC3DBG", "-fdebug-compilation-dir=."],
"//conditions:default": ["-O3"]
}) + select({
"//:lto": ['-flto'],
Expand Down
12 changes: 6 additions & 6 deletions pkg/noun/events.c
Original file line number Diff line number Diff line change
Expand Up @@ -652,10 +652,10 @@ _ce_patch_write_page(u3_ce_patch* pat_u,
(ret_zs = pwrite(pat_u->mem_i, mem_w, _ce_page, _ce_len(pgc_w))) )
{
if ( 0 < ret_zs ) {
fprintf(stderr, "loom: patch partial write: %"PRIc3_zs"\r\n", ret_zs);
fprintf(stderr, "loom: patch partial write: %"PRIc3_zs", check disk space\r\n", ret_zs);
}
else {
fprintf(stderr, "loom: patch write: fail: %s\r\n", strerror(errno));
fprintf(stderr, "loom: patch write: fail: %s, check disk space\r\n", strerror(errno));
}
u3_assert(0);
}
Expand Down Expand Up @@ -871,11 +871,11 @@ _ce_patch_apply(u3_ce_patch* pat_u)
(ret_zs = pwrite(fid_i, buf_y, _ce_page, off_z)) )
{
if ( 0 < ret_zs ) {
fprintf(stderr, "loom: patch apply partial write: %"PRIc3_zs"\r\n",
fprintf(stderr, "loom: patch apply partial write: %"PRIc3_zs", check disk space\r\n",
ret_zs);
}
else {
fprintf(stderr, "loom: patch apply write: %s\r\n", strerror(errno));
fprintf(stderr, "loom: patch apply write: %s, check disk space\r\n", strerror(errno));
}
u3_assert(0);
}
Expand Down Expand Up @@ -1323,11 +1323,11 @@ _ce_image_copy(u3e_image* fom_u, u3e_image* tou_u)
}
if ( _ce_page != (ret_i = write(tou_u->fid_i, buf_y, _ce_page)) ) {
if ( 0 < ret_i ) {
fprintf(stderr, "loom: image (%s) copy partial write: %zu\r\n",
fprintf(stderr, "loom: image (%s) copy partial write: %zu, check disk space\r\n",
tou_u->nam_c, (size_t)ret_i);
}
else {
fprintf(stderr, "loom: image (%s) copy write: %s\r\n",
fprintf(stderr, "loom: image (%s) copy write: %s, check disk space\r\n",
tou_u->nam_c, strerror(errno));
}
return c3n;
Expand Down
1 change: 1 addition & 0 deletions pkg/vere/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ vere_library(
"@platforms//os:macos": [
"platform/darwin/daemon.c",
"platform/darwin/ptty.c",
"platform/darwin/mach.c",
],
"@platforms//os:linux": [
"platform/linux/daemon.c",
Expand Down
4 changes: 3 additions & 1 deletion pkg/vere/disk.c
Original file line number Diff line number Diff line change
Expand Up @@ -1632,7 +1632,9 @@ u3_disk_chop(u3_disk* log_u, c3_d eve_d)
u3_disk_epoc_list(log_u, sot_d);

if ( len_z <= 2 ) {
fprintf(stderr, "chop: nothing to do, have a great day\r\n");
fprintf(stderr, "chop: nothing to do, try running roll first\r\n"
"chop: for more info see "
"https://docs.urbit.org/manual/running/vere#chop\r\n");
exit(0); // enjoy
}

Expand Down
5 changes: 4 additions & 1 deletion pkg/vere/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -1140,7 +1140,6 @@ _cw_serf_commence(c3_i argc, c3_c* argv[])
fprintf(stderr, "serf: missing args\n");
exit(1);
}

// XX use named arguments and getopt

c3_d eve_d = 0;
Expand Down Expand Up @@ -2935,6 +2934,10 @@ main(c3_i argc,

_main_init();

#if defined(U3_OS_osx)
darwin_register_mach_exception_handler();
#endif

c3_c* bin_c = strdup(argv[0]);

// parse for subcommands
Expand Down
28 changes: 28 additions & 0 deletions pkg/vere/platform/darwin/mach.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#include "log.h"

#include <mach/mach.h>
#include <mach/mach_error.h>
#include <mach/exception.h>
#include <mach/task.h>


// lldb does not listen to BSD signals, it only listens to Mach exceptions.
// The Mach exception EXC_BAD_ACCESS corresponds to SIGSEGV, but lldb has
// problems converting between them because of a longstanding macOS kernel bug.
// This means that without this workaround we cannot debug our binaries with
// lldb. The first segfault we hit causes an infinite loop in lldb no matter
// how many times you try to continue. This workaround is implemented in projects
// such as the Go runtime.
// See https://bugs.llvm.org/show_bug.cgi?id=22868#c1 for more details.

void darwin_register_mach_exception_handler() {
kern_return_t kr = task_set_exception_ports(
mach_task_self(),
EXC_MASK_BAD_ACCESS, // SIGSEGV
MACH_PORT_NULL,
EXCEPTION_STATE_IDENTITY,
MACHINE_THREAD_STATE);
if ( KERN_SUCCESS != kr) {
u3l_log("mach: unable to register exception handler");
}
}
7 changes: 7 additions & 0 deletions pkg/vere/vere.h
Original file line number Diff line number Diff line change
Expand Up @@ -1557,6 +1557,13 @@
void
u3_daemon_init();

#if defined(U3_OS_osx)
/* darwin_register_mach_exception_handler(): make lldb work
*/
void
darwin_register_mach_exception_handler();
#endif

/* u3_write_fd(): retry interrupts, continue partial writes, assert errors.
*/
void
Expand Down