diff --git a/build.zig b/build.zig index 7446c7a..b7f0ac9 100644 --- a/build.zig +++ b/build.zig @@ -4,10 +4,16 @@ pub fn build(b: *std.build.Builder) void { const target = b.standardTargetOptions(.{}); const mode = b.standardReleaseOptions(); + const libsegfault = b.addStaticLibrary("segfault", "src/segfault.zig"); + libsegfault.setTarget(target); + libsegfault.setBuildMode(mode); + libsegfault.force_pic = true; + const exe = b.addExecutable("st", null); exe.setTarget(target); exe.setBuildMode(mode); exe.install(); + exe.linkLibrary(libsegfault); exe.linkSystemLibrary("fontconfig"); exe.linkSystemLibrary("freetype2"); exe.linkSystemLibrary("Xft"); diff --git a/src/segfault.zig b/src/segfault.zig new file mode 100644 index 0000000..de11c91 --- /dev/null +++ b/src/segfault.zig @@ -0,0 +1,8 @@ +const std = @import("std"); + +/// installs a segfault handler on supported platforms in debug and safe modes. +/// while a zig main does this automatically, a C main will want to call this explicitly. +/// hence, the export for C call convention. +export fn setupSegfaultHandler() void { + std.debug.maybeEnableSegfaultHandler(); +} diff --git a/x.c b/x.c index 23af62b..9c72acd 100644 --- a/x.c +++ b/x.c @@ -61,6 +61,8 @@ static void zoomabs(const Arg *); static void zoomreset(const Arg *); static void ttysend(const Arg *); +extern void setupSegfaultHandler(void); + /* config.h for applying patches and the configuration. */ #include "config.h" @@ -2103,6 +2105,9 @@ usage(void) int main(int argc, char *argv[]) { + // install zig's UB handler. + setupSegfaultHandler(); + xw.l = xw.t = 0; xw.isfixed = False; xsetcursor(cursorshape);