Skip to content

Zig, Nim, Crystal, D, Odin, V (C2) ​

Ready

The hub recognises the services this package fits and proposes the compose part of the change, if any; the source change stays by hand, with the steps and examples in the proposal's review. Nothing changes until a player approves it (Hook proposals). The cheat sheets have the steps by hand.

This package is for services written in Zig, Nim, Crystal, D, Odin or V. Each language gets a thin binding over C1's guarded C binding vbxhook, which is compiled into the service, plus a request wrapper for its most common HTTP server. The binding goes in as a source change: the binding and vbxhook.c are vendored into the service's tree and a few lines are added around the server. The service also gets a read-only compose mount of the hook directory at /opt/vbxtrace. All the safety rules (the tracer check, VBXTRACE=0, switching off after 5 errors, chaos testing) live in vbxhook.c, so they are the same in every language.

Not every service needs this hook. The kernel already links thread-per-connection and forking servers exactly. For those servers the hook only adds request boundaries on keep-alive connections. See Covers.

Covers ​

LanguageToolchain testedServer / frameworkSampleRequest index
Zig0.14.1 (official tarball, sha256-pinned) on Alpine 3.22 (musl); also checked on Debian trixie (glibc)std.http.Server (HTTP/1.1, keep-alive)zig-stdhttpexact (one HttpConnection per connection)
Nim2.2.4 (nimlang/nim:2.2.4-alpine-regular)std/asynchttpserver (serve, acceptRequest)nim-asynchttpserverexact (per AsyncSocket object)
Crystal1.17.1 (crystallang/crystal:1.17.1-alpine); the reopened method dates back to 1.12HTTP::Server and everything built on it: Kemal 1.15, Lucky, Amber, Athena, Gripcrystal-http, crystal-kemalexact (per connection fiber)
DLDC 1.41.0 (official tarball, sha256-pinned) on Debian trixie; vibe-core 2.14, vibe-http 1.2.2vibe.d (listenHTTP, URLRouter)d-vibedexact (per connection task)
Odindev-2026-10 (official tarball, sha256-pinned) on Debian trixiecore:net TCP servers: raw line protocols, hand-rolled HTTPodin-rawraw sessions: always 0; HTTP: a counter you keep per connection
V0.5.2 (official release zip, sha256-pinned) on Debian trixieveb (fasthttp backend)v-vebexact (per fd + socket inode)

Some frameworks are not covered yet, each for a reason:

FrameworkWhy it is not covered
Zig: zap (facil.io), http.zigzap's Request gives no connection object, no per-connection storage and no close callback; all it has is facil.io's uuid. A counter keyed by that uuid would not be exact when connections come and go. zap also pins Zig versions and builds facil.io. Both can call beginFd / end by hand.
Zig 0.15 std.http.Server0.15 rewrote the server around std.Io.Reader/Writer. The extern fn layer still works; only HttpConnection/Request in vbxtrace.zig need porting.
Nim: Jester, PrologueJester's default backend is httpbeast, which runs its own epoll loop on several threads and gives the handler no connection. Prologue sits on httpx, which is the same kind of server. With -d:useStdLib, Jester runs on asynchttpserver, but it imports that module itself, so the drop-in import does not reach it. Not sampled; would need a patch inside Jester.
D: HTTP/2 in vibe-httpvibe-http's HTTP/2 (opt-in HTTPServerOption.enableHTTP2 over TLS) runs streams in tasks of their own, so no exact per-connection index exists there. traced reports those requests with protocol http2 and request index unknown (REQUEST_INDEX_UNKNOWN) instead of a guess.
Odin: odin-httpIt is not part of the Odin distribution, and its connection type is internal. A service built on it can call vbx.begin/vbx.end from its handler with the connection's socket.
V: net.http.ServerIts Handler gets only http.Request: no socket, no peer port, no connection boundary, so request keys cannot be exact. Its workers serve one connection at a time on a thread, so the kernel already links everything per connection.

What the kernel already links without this hook:

Server modelLanguages / serversLinked byHook adds
thread per connectionZig std.http.Server with a thread per accepted connection (the usual pattern); Odin core:net with a thread per connection; D with std.socket threads; V net.http.Server workersthe thread holds exactly one client socketrequest boundaries on keep-alive connections, raw session boundaries, work handed to other threads
process per connection (socat fork, xinetd running any of these binaries)allprocess lineagerequest boundaries
fibers / green threads / event loop: many connections on one threadCrystal HTTP::Server (fibers), vibe.d (tasks), Nim asynchttpserver (async), veb (fasthttp worker threads, each with many connections)nothing per requesteverything

How it gets in ​

On a developer machine: no registry package; copy the files from the hook directory that vulnboxctl hooks install-local puts in ~/.local/share/vulnboxd/trace, as below; see Local development.

The change is always a source change plus a compose mount. Each language's proposal does three things:

  1. It vendors the language binding (from /usr/local/lib/vulnboxd/trace/native/<lang>/) together with native/c/vbxhook.h, native/c/vbxhook.c and include/vbxtrace.h into the service tree.
  2. It compiles vbxhook.c into the service. Nim and Zig do this through their own build. Crystal, D, Odin and V build an object or archive with cc in the Dockerfile.
  3. It adds the wrapper lines around the server and, optionally, the spawn, file and connect helpers.

The mount, the same for every language:

diff
 services:
   <service>:
+    volumes:
+      - /usr/local/lib/vulnboxd/trace:/opt/vbxtrace:ro

By default vbxhook.c dlopen()s /opt/vbxtrace/libvbxtrace-$(uname -m).so at its first call. That needs the mount and a dynamically linked binary. Without the mount the binding simply stays off. If you build a fully static binary, compile vbxhook.c with -DVBXHOOK_STATIC and link libvbxtrace-<arch>.a instead; no mount is needed then (see C1). Glibc older than 2.34 needs -ldl.

In full, vbxhook.c looks for the core in this order: the file named by VBXTRACE_LIB, then /opt/vbxtrace/libvbxtrace-<arch>.so (the mount), then, only with VBXTRACE_DEV=1 and only when the directory and the library belong to root or the user and nobody else can write them, ~/.local/share/vulnboxd/trace (or $XDG_DATA_HOME/vulnboxd/trace) for local development. A setuid or file-capability binary ignores VBXTRACE_LIB and VBXTRACE_DEV.

The hub proposes C2 when it detects the following (per language, from hooks/native/c2/proposals/<lang>.toml):

LanguageFilesImageCommandDependencies
Zigbuild.zig, build.zig.zon, *.zigzigzig build, zig build-exe, zig run
Nim*.nimble, nim.cfg, config.nims, *.nim^nimlang/nim, nimnim c, nimble buildasynchttpserver
Crystalshard.yml, shard.lock, *.cr^crystallang/crystalcrystal build, shards buildkemal, lucky, amber, athena, grip
Ddub.json, dub.sdl, dub.selections.json, *.d^dlang2/, ldc, dmd, gdcdub build, ldc2, dmdvibe-d, vibe-http, vibe-core
Odin*.odin, ols.jsonodinodin build, odin run
Vv.mod, *.vvlang, thevlang/v -prod, v runveb

Zig ​

  1. Copy native/zig/vbxtrace.zig next to main.zig. Zig 0.14 refuses imports from outside the root module's directory.
  2. Copy vbxhook.{h,c} and vbxtrace.h into ./vbxtrace/.
  3. Add to build.zig:
zig
exe.linkLibC();
exe.linkage = .dynamic;   // on musl, Zig links -lc statically by default; a static exe cannot dlopen
exe.addIncludePath(b.path("vbxtrace"));
exe.addCSourceFile(.{ .file = b.path("vbxtrace/vbxhook.c") });

(On the command line: zig build-exe -O ReleaseFast -lc -dynamic -I vbxtrace main.zig vbxtrace/vbxhook.c.)

  1. Serve each connection through the wrapper:
diff
+const vbx = @import("vbxtrace.zig");
-fn handle(req: *std.http.Server.Request) !void {
+fn handle(_: void, req: *vbx.Request) !void {          // req.inner: std's Request, req.ctx: the context
 ...
-    var server = std.http.Server.init(conn, &buf);
-    while (server.state == .ready) {
-        var req = server.receiveHead() catch return;
-        handle(&req) catch return;
-    }
+    vbx.serve(conn, &buf, {}, handle);

You can keep your own loop instead: var hc = vbx.HttpConnection.init(conn, &buf), then hc.receiveHead(), req.respond(...) and defer req.end(). Full example: proposals/zig-stdhttp.diff.

Nim ​

Copy native/nim/ (vbxtrace.nim and vbxtrace/asynchttp.nim) and vbxhook.{h,c} and vbxtrace.h all into the service's source directory. vbxtrace.nim compiles vbxhook.c itself with {.compile.}. To keep the files elsewhere, pass -d:vbxhookC=<path to vbxhook.c> -d:vbxhookInc=<dir>. Then swap one import:

diff
-import std/[asyncdispatch, asynchttpserver, osproc]
+import std/[asyncdispatch, osproc]
+import vbxtrace, vbxtrace/asynchttp   # vulnboxd request tracing (replaces std/asynchttpserver)
 ...
-    let p = startProcess("/bin/ping", args = ["-c", "1", req.url.query], options = {poUsePath})
+    let p = startProcess(ctx(req), "/bin/ping", args = ["-c", "1", req.url.query], options = {poUsePath})

vbxtrace/asynchttp re-exports asynchttpserver, replacing three procs with tracing versions: serve, acceptRequest and respond. Nothing else in the service changes. Example: proposals/nim-asynchttpserver.diff.

Crystal ​

  1. Copy native/crystal/vbxtrace.cr and vbxhook.{h,c} and vbxtrace.h to src/vbxtrace/.
  2. Build the object that vbxtrace.cr links (through @[Link(ldflags: "#{__DIR__}/vbxhook.o")]). The official crystallang/crystal images include cc.
diff
-RUN crystal build --release -o /app/notes src/server.cr
+RUN cc -O2 -c -Isrc/vbxtrace -o src/vbxtrace/vbxhook.o src/vbxtrace/vbxhook.c \
+    && crystal build --release -o /app/notes src/server.cr
  1. Put the handler first in the chain:
diff
 require "http/server"
+require "./vbxtrace/vbxtrace" # vulnboxd request tracing

-server = HTTP::Server.new([HTTP::LogHandler.new]) do |ctx|
+server = HTTP::Server.new([Vbxtrace::Handler.new, HTTP::LogHandler.new]) do |ctx|
 ...
-    Process.run("ping", ["-c", "1", ctx.request.query.to_s], output: output)
+    Vbxtrace.process_run("ping", ["-c", "1", ctx.request.query.to_s], output: output)

For Kemal, add use Vbxtrace::Handler.new, 0 before Kemal.run (older Kemal versions: add_handler Vbxtrace::Handler.new, 0). For Lucky, put Vbxtrace::Handler.new first in the middleware array of src/app_server.cr. Drop --static (or use the static variant). Example: proposals/crystal-http.diff.

D (vibe.d) ​

  1. Copy native/d/vbxtrace.d and vbxtrace_vibe.d and vbxhook.{h,c} and vbxtrace.h into ./vbxtrace/.
  2. Add to dub.sdl (dub.json takes the same keys):
text
sourcePaths "source" "vbxtrace"
importPaths "source" "vbxtrace"
preBuildCommands "cc -O2 -c -I$PACKAGE_DIR/vbxtrace -o $PACKAGE_DIR/vbxtrace/vbxhook.o $PACKAGE_DIR/vbxtrace/vbxhook.c"
sourceFiles "vbxtrace/vbxhook.o"
  1. Wrap the handler:
diff
+import vbxtrace;      // vulnboxd request tracing
+import vbxtrace_vibe;
 ...
-    listenHTTP(settings, router);
+    listenHTTP(settings, traced(settings, router));

traced accepts every handler shape that listenHTTP does: delegates, functions, their scope variants, and HTTPServerRequestHandler objects such as URLRouter. Example: proposals/d-vibed.diff.

Odin ​

  1. Copy native/odin/vbxtrace.odin into ./vbxtrace/ (a package of its own).
  2. Build vbxtrace/vbxhook.a, which the binding foreign imports:
dockerfile
RUN cc -O2 -c -Ivbxtrace -o /tmp/vbxhook.o vbxtrace/vbxhook.c && ar rcs vbxtrace/vbxhook.a /tmp/vbxhook.o
  1. Wrap each accepted connection:
diff
+import vbx "vbxtrace" // vulnboxd request tracing
 handle :: proc(client: net.TCP_Socket) {
 	defer net.close(client)
+	ctx := vbx.begin(client, 0, vbx.PROTO_RAW)
+	defer vbx.end(ctx, 0)
 ...
-	f, err := os.open("/data/log", {.Write, .Create, .Append})
+	f, err := vbx.open(ctx, "/data/log", {.Write, .Create, .Append})

For a hand-rolled HTTP server, call vbx.begin(client, requests, vbx.PROTO_HTTP1) and vbx.end(ctx, status) once per request, with requests counted per connection (see the sample's serve_http). Example: proposals/odin-tcp.diff.

V (veb) ​

  1. Copy native/v/vbxtrace/ (vbxtrace.v, vebhook/) to ./vbxtrace/ next to main.v, and copy vbxhook.h, vbxhook.c and vbxtrace.h into it.
  2. Build vbxtrace/vbxhook.o, which vbxtrace.v links through #flag @DIR/vbxhook.o:
dockerfile
RUN cc -O2 -c -Ivbxtrace -o vbxtrace/vbxhook.o vbxtrace/vbxhook.c
  1. Add three hooks to the veb app:
diff
+import vbxtrace // vulnboxd request tracing
+import vbxtrace.vebhook
 ...
+pub fn (mut ctx Context) before_request() {
+	vebhook.begin(mut ctx.Context)
+}
+
+pub fn (mut ctx Context) not_found() veb.Result {
+	return vebhook.not_found(mut ctx.Context)
+}
 ...
 	mut app := &App{}
+	app.use(handler: fn (mut ctx Context) bool {
+		return vebhook.after(mut ctx.Context)
+	}, after: true)

If the app already has before_request or not_found, call vebhook.begin or vebhook.end(404) from them. Register the after-middleware last. Example: proposals/v-veb.diff.

What it records ​

Every language reports the same events through vbxhook. The tables show where each event comes from.

EventJoin key
request_begin / request_endlocal port + peer address and port of the accepted socket (from getsockname/getpeername on its fd, or the explicit keys where noted), request index on the connection, protocol
spawnedchild pid
connectedlocal port of the outgoing socket (from the fd)
openedpid + fd, plus the open(2) flags (0x241 = O_WRONLY|O_CREAT|O_TRUNC; O_CLOEXEC, which every runtime adds, is not reported)
handoff, context_enter/context_exitcontext ids

Zig ​

EventEmitted from
request_beginHttpConnection.receiveHead() after std's receiveHead succeeds: vbxh_begin_fd(stream fd, connection's counter, http1)
request_endRequest.end() (serve calls it in a defer) with the status of the last respond/respondStreaming, or 0 if nothing was sent
spawnedvbx.spawn / vbx.spawnAndWait (std.process.Child.spawn, child.id)
openedvbx.createFile (flags from CreateFlags: access mode | O_CREAT | O_TRUNC | O_EXCL; the default .{} is 0x241), vbx.openFile (access mode only)
connectedvbx.tcpConnectToAddress, vbx.tcpConnectToHost
handoff + enter/exitvbx.spawnThread(ctx, config, f, args) (std.Thread.spawn)

Nim ​

EventEmitted from
request_beginthe wrapped callback of serve/acceptRequest: beginRequest(req.client.getFd(), index)
request_endafter the callback's future completes, with the code passed to respond. A callback that raises ends with 500 if nothing was sent, and the error propagates. A request answered without respond (writing to req.client directly) ends with 0.
spawnedstartProcess(ctx, ...) (osproc.startProcess, processID)
openedopen(ctx, filename, mode) (system.open, getFileHandle; flags from FileMode: fmWrite = 0x241, fmAppend = 0x441, …)
connecteddial(ctx, ...) (net.dial), dialAsync(ctx, ...) (asyncnet.dial)
handoff + enter/exithandoff(ctx) + withContext(child): ... for threads / spawn

There is also a lower-level API for other servers: beginRequest(fd, index), beginRequest(localPort, peerIp, peerPort, index), endRequest, withRequest(fd, index, status): ... (synchronous servers), current()/setCurrent().

Crystal ​

EventEmitted from
request_beginVbxtrace::Handler#call: vbxh_begin_fd(connection socket fd, fiber's counter, http1). Outside HTTP::Server#handle_client (a custom server feeding RequestProcessor), it falls back to request.local_address / remote_address with request index unknown (REQUEST_INDEX_UNKNOWN), since no connection boundary is visible there.
request_endafter call_next, with context.response.status_code. If the chain raises, the request ends with 500, which is what HTTP::Server answers, and the exception is re-raised unchanged.
spawnedVbxtrace.process (Process.new, process.pid), Vbxtrace.process_run (the same, then wait)
openedVbxtrace.file_open(path, mode) (File.open; "w" = 0x241, "a" = 0x441, "r+" = 0x2, …)
connectedVbxtrace.tcp_connect (TCPSocket.new), Vbxtrace.connected(socket)
handoff + enter/exitVbxtrace.spawn { ... } instead of spawn
raw sessionsVbxtrace.session(socket) { ... } for TCPServer services: protocol raw, index 0, status 0

D (vibe.d) ​

EventEmitted from
request_beginTracedHandler.handleRequest: vbxh_begin_str(settings.port, req.clientAddress, its port, task-local counter, http1). vibe.d does not give the request handler the connection's fd, so the peer comes from clientAddress, which vibe-http copies from the accepted TCPConnection, and the local port from the settings the server listens with. It is only computed while a tracer is attached.
request_endafter the wrapped handler: res.statusCode, or 404 if no handler wrote a response (vibe.d then answers 404 itself). HTTPStatusException ends with its status and other exceptions with 500 (vibe.d's answers); the exception is rethrown.
spawnedvbxtrace.spawnProcess(ctx, ...) (std.process.spawnProcess, pid.processID)
openedopenFile(ctx, name, mode) (std.stdio.File; flags from the fopen mode)
connectedvbxtrace_vibe.connected(ctx, conn) after connectTCP (TCPConnection.fd); vbxtrace.connected(ctx, socket) for std.socket
handoff + enter/exittracedTask(work) instead of runTask(work)

Odin ​

EventEmitted from
request_beginvbx.begin(client, index, protocol): vbxh_begin_fd on the accepted net.TCP_Socket. It also sets the thread's current request.
request_endvbx.end(ctx, status): 0 for raw sessions, the HTTP status otherwise
spawnedvbx.process_start(ctx, desc) (os.process_start, p.pid)
openedvbx.open(ctx, name, flags, perm) (os.open, os.fd; Linux flags from File_Flags: {.Write, .Create, .Trunc} = 0x241)
connectedvbx.dial_tcp_endpoint, vbx.dial_tcp_hostname
handoff + enter/exitvbx.spawn_thread(ctx, data, fn) (thread.create_and_start_with_poly_data); vbx.handoff / vbx.enter / vbx.exit for pools

V (veb) ​

EventEmitted from
request_beginvebhook.begin from Context.before_request(): vbxh_begin_fd(client fd, conn_request_index(fd), http1). veb keeps the client fd in a private Context.client_fd; the binding reads it through compile-time reflection ($for f in veb.Context.fields). If a veb version has no such field, the fd reads as -1 and the hook stays silent instead of guessing.
request_endvebhook.after (the last global after-middleware) with ctx.res.status_code; vebhook.not_found with 404
spawnedvbxtrace.process_run(ctx, mut p) (os.Process.run, p.pid)
openedvbxtrace.create(ctx, path) (os.create, 0x241), vbxtrace.open_file(ctx, path, mode)
connectedvbxtrace.dial_tcp(ctx, address) (net.dial_tcp, conn.sock.handle)
handoff + enter/exitvbxtrace.handoff(ctx), then vbxtrace.enter/vbxtrace.exit around work you spawn

Request index ​

LanguageHow the index is countedWhy it is exact
ZigHttpConnection.requests, starting at 0one HttpConnection per accepted connection
Nima table keyed by the request's AsyncSocket object; the entry holds a reference to the socket, and entries of closed sockets are dropped when the next new connection arrivesasynchttpserver serves a connection's requests one after another on one AsyncSocket, which lives exactly as long as the connection; holding the reference keeps its address from being reused while the entry exists
Crystalfields on Fiber (vbx_conn_fd, vbx_conn_requests), set and reset in a reopened HTTP::Server#handle_clientHTTP::Server runs handle_client once per connection in a fiber of its own and processes every keep-alive request of the connection in it
DTaskLocal!uintvibe-http serves each accepted connection in a task of its own (listenTCP → runTask), and handles its requests sequentially inside it; vibe-core clears task-local storage when a task ends, so a pooled fiber starts the next connection at 0
Odinyour counter per connection (raw sessions: always 0)the server code owns the connection
Vconn_request_index(fd): a slot per fd (up to 65535) holding the socket's inode number and a counter; a different inode means a new connection, so the counter resetsa socket's inode number is unique while the socket exists; a connection's requests are handled one at a time, so its slot is never written concurrently

Where a binding cannot know the index exactly, it passes VBXH_REQUEST_INDEX_UNKNOWN (each binding has the constant: Zig request_index_unknown, Nim RequestIndexUnknown, Crystal Vbxtrace::REQUEST_INDEX_UNKNOWN, D REQUEST_INDEX_UNKNOWN, Odin REQUEST_INDEX_UNKNOWN, V vbxtrace.request_index_unknown). vulnboxd then links the request only through other exact facts, never by guessing. Pass it too from your own code when you cannot count per connection.

Requests the server rejects before the handler runs, such as a malformed request line or a 400 from the parser, are not counted. Those servers close the connection afterwards, so no later index is affected.

Context following ​

LanguageMechanismFollows automaticallyNeeds handoff
Zigvbxhook's per-thread slot: receiveHead sets it, end() clears it; vbx.current(), or pass req.ctxeverything on the connection's threadnew threads (vbx.spawnThread does it), std.Thread.Pool jobs (vbx.handoff before queueing, vbx.enter/vbx.exit in the job)
Nimpassed through the request: ctx(req) finds the connection's current request (one request at a time per connection). Async code must not use the thread slot across await; synchronous servers can (withRequest, current()).every await inside the callback, since ctx(req) is looked up per callwork moved to threads / spawn (handoff + withContext)
CrystalFiber#vbx_ctx, set by the handler for the duration of the chain; Vbxtrace.currenteverything on the request's fiber, across every blocking IO (fibers yield and resume transparently)fibers started with spawn (fiber-local state is not inherited): use Vbxtrace.spawn
DTaskLocal!ulong; vbxtrace_vibe.current()everything in the request's task, across vibe's yieldsrunTask / runWorkerTask (task-locals are not inherited): tracedTask; std.parallelism / threads: handoff + enter/exit
Odinvbxhook's per-thread slot (vbx.begin sets it, vbx.end clears it), or pass the ideverything on the connection's threadother threads: vbx.spawn_thread; thread.Pool tasks: vbx.handoff + vbx.enter/vbx.exit
Vvbxhook's per-thread slot: a veb request runs from before_request to the after-middleware on one fasthttp worker thread; vbxtrace.current()everything inside the handlerspawned threads: vbxtrace.handoff + vbxtrace.enter/vbxtrace.exit

Known gaps ​

All languages. Only calls made through the helpers are linked to a request. A raw posix.open, fork, connect or C library call, or a database driver's own socket, is linked only the way the kernel links it: exactly on thread-per-connection servers, not at all on fiber/async servers. Call spawned/opened/connected explicitly after such calls. A fully static binary keeps the hook off unless you build the static variant. io_uring-based I/O is not covered (as in C1).

LanguageGaps
Zigonly the 0.14.x std.http.Server helper; zap and http.zig not wrapped (see Covers); if std.Thread.spawn fails inside spawnThread, the handoff was already emitted with no enter; HTTP/1 only
NimJester/httpbeast and Prologue/httpx not covered; requests answered without respond end with status 0; the per-connection table purges closed sockets only when a new connection arrives (bounded by the number of connections open at that moment)
Crystalthe per-connection index relies on reopening the private HTTP::Server#handle_client (checked against 1.12–1.17; a future rename makes the handler fall back to the request's addresses with index unknown, so re-check after upgrading Crystal). With -Dpreview_mt and execution contexts, fiber-local state is still right, because it lives on the fiber.
Dno fd: keys come from req.clientAddress and settings.port. Behind a bindAddresses list with different ports per address, pass the right settings. HTTP/2 requests are reported with index unknown.
Odinno HTTP framework wrapper (Odin has no standard HTTP server); the request index of hand-rolled HTTP is yours to count
Vreads veb's private client_fd by reflection, so re-check after upgrading V (the hook goes silent rather than wrong). A request that a before-middleware answers on its own (returning false) or a user after-middleware cuts short never reaches vebhook.after; it is closed with status 0 when that worker thread starts its next request. veb's static file serving never calls before_request, so static files are not reported. Requests on fds ≥ 65536 (or when fstat fails) are reported with index unknown. net.http.Server not covered.

Safety ​

What is wrapped: nothing is hooked behind the service's back. The binding is a set of functions the service calls. Each wrapper calls the language API first and reports afterwards, passing the API's result, error or exception through unchanged. It only reports on success.

Guardevery event goes through vbxhook.c. It does nothing unless the core is loaded, the binding is not disabled, and a tracer is attached (vbx_v1_enabled()). While no tracer is attached, a call costs a few loads.
Internal errorscounted in vbxhook.c: a missing core symbol, getsockname/getpeername failing, an unparsable address. After 5 the binding switches off for the process. Each binding exposes the count (errors()).
VBXTRACE=0read by vbxhook.c at its first call: the binding stays off for the process
No new failure modesthe C functions never raise, block, allocate or change errno. No language binding raises, panics or allocates without bound on the hook path, and none changes a request, a response or a status.
ExceptionsCrystal, D and Nim end the request with the status the server answers (500, or the HTTPStatusException's status in D) and re-raise unchanged. Zig ends with the status already sent, or 0, when the handler returns an error.
Chaos testwith VBXTRACE_CHAOS=1, every call into the core fails inside the guard. Every sample's responses are byte-identical to the normal run.

Overhead will be measured in the performance phase; no numbers are published for this package yet.

Without a tracer, the hook adds two or three calls per request, each of which returns after a single load. V adds one fstat per request (the connection index); Nim adds a table lookup.

Turning it off ​

Set VBXTRACE=0 in the service's environment and restart it, or revert the change that added the hook; vulnboxd's rollback covers a hook that breaks a service.

Removing the /opt/vbxtrace mount also turns it off: dlopen fails and the binding stays off for good, at no cost. To remove the hook completely, revert the diff: delete the vendored directory (vbxtrace.zig, vbxtrace.nim + vbxtrace/, src/vbxtrace/, vbxtrace/), the vbxhook.c build step (build.zig lines, the cc line in the Dockerfile, the dub preBuildCommands/sourceFiles), and the wrapper lines. The helpers are thin wrappers, so replacing Vbxtrace.process_run( with Process.run( (and so on) restores the original calls.

Troubleshooting ​

  • Are the probes there? readelf -n /usr/local/lib/vulnboxd/trace/libvbxtrace-x86_64.so lists them, and so does sudo bpftrace -l 'usdt:/usr/local/lib/vulnboxd/trace/libvbxtrace-x86_64.so:*'.
  • Is the hook loaded? grep vbxtrace /proc/<pid>/maps shows the core once the first request (or the binding's init() at startup) has loaded it. Every binding's init()/load() returns true when the core loaded (Zig vbx.init(), Nim vbxtrace.init(), Crystal Vbxtrace.init, D vbxtrace.init(), Odin vbx.init(), V vbxtrace.load()), and active() is true while a tracer is attached. errors() >= 5 means the binding switched itself off.
  • Which links did a flow get? The hub shows each link's method; this package's are hook:C2.
  • The binary is static, so the hook silently stays off. Check with ldd <binary> (it must show libc.so.6 or ld-musl).
    • Zig on musl links static by default with -lc: use -dynamic / exe.linkage = .dynamic.
    • Crystal: remove --static.
    • Nim: remove --passL:-static.
    • Or build the static variant: -DVBXHOOK_STATIC plus libvbxtrace-<arch>.a.
  • vbxtrace.h: No such file or directory when compiling vbxhook.c: the -I for the directory holding vbxtrace.h (and vbxhook.h) is missing. Nim: -d:vbxhookInc=<dir>.
  • Undefined dlopen/dlsym on glibc < 2.34: add -ldl.
    • Zig: exe.linkSystemLibrary("dl").
    • Nim: --passL:-ldl.
    • Crystal: @[Link("dl")].
    • D: libs "dl".
    • Odin: -extra-linker-flags:-ldl.
    • V: #flag -ldl.
  • Undefined vbxh_* symbols. The object was not built or not linked.
    • Crystal looks for vbxhook.o next to vbxtrace.cr.
    • Odin looks for vbxhook.a next to vbxtrace.odin.
    • V looks for vbxhook.o in vbxtrace/.
    • D: check sourceFiles.
  • Zig: "import of file outside module path". vbxtrace.zig must sit inside the root module's directory.
  • Nim: "ambiguous call" for serve/respond. The service imports both std/asynchttpserver and vbxtrace/asynchttp. Remove the std import; vbxtrace/asynchttp re-exports everything else.
  • Crystal: every request has index 0 and no fd. The handler is not running inside HTTP::Server#handle_client: a custom server, or a Crystal version that renamed it. Check that require "./vbxtrace/vbxtrace" comes after require "http/server".
  • D: wrong local port. traced takes the port from the settings object passed to it. Pass the same settings as listenHTTP.
  • V: no events at all. vebhook.client_fd(ctx) returns -1: this veb version has no client_fd field (or uses a different backend). The hook then stays silent by design.