Dice Public API Overview
This guide summarizes the headers under include/dice/ so you can locate the
right building blocks when writing interceptors or subscribers.
Core Concepts
types.h: defineschain_id,type_id,metadata_t, and constants such asMAX_TYPES,MAX_CHAINS, andCHAIN_CONTROL; defines thethread_idtype and sentinel values (NO_THREAD,ANY_THREAD,MAIN_THREAD).chains/: standard chain identifiers.intercept.hintroducesINTERCEPT_EVENT,INTERCEPT_BEFORE,INTERCEPT_AFTER;capture.hprovides the corresponding republished chains (CAPTURE_*).events/: payload definitions and event identifiers. Each header groups a family of events (events/thread.h,events/malloc.h,events/memaccess.h, etc.). Include the relevant header to interpretEVENT_*payloads inside your handlers.
Pubsub and Module Glue
pubsub.h: the main runtime interface. Exposesps_publish,ps_subscribe, helper macros (PS_PUBLISH,EVENT_PAYLOAD), and theps_callback_fsignature.module.h: convenience macros for module initialization and subscription.DICE_MODULE_INIT/DICE_MODULE_FINIwrap constructor hooks, andPS_SUBSCRIBEregisters handlers with the slot (DICE_MODULE_SLOTdefaults to 9999).handler.h: emits the inline handler stubs used byPS_SUBSCRIBE. Most code relies on this indirectly viamodule.h.dispatch.h: declares the fast-path dispatch hooks that builtin modules use. When you compile a module withDICE_MODULE_SLOT < MAX_BUILTIN_SLOTSthe generated dispatch tables call your handler without going through the callback list.
Runtime Facilities
self.h: per-thread metadata helpers provided by the Self module. Useself_id,self_tls,self_tls_get, andself_tls_setto manage TLS and retrieve Dice thread identifiers.mempool.h: lock-protected slab allocator used by Dice internals. Modules should prefermempool_alloc/realloc/freeovermallocto avoid reentrancy.now.h: monotonic time helpers (now,in_sec,to_timespec) for benchmarks or diagnostics.
Interposition and Diagnostics
interpose.h: platform-specific macros (INTERPOSE,REAL,REAL_DECL) for wrapping libc and pthread functions while still calling the original.log.h: logging macros (log_debug,log_info,log_warn,log_fatal) and configuration controls (LOG_LEVEL,LOG_PREFIX,LOG_UNLOCKED).compiler.h: shared compiler attributes (DICE_CTOR,DICE_HIDE,likely, etc.) used across Dice headers.
Chains and Events at a Glance
When writing a handler:
- Include the chain header (
dice/chains/capture.hordice/chains/intercept.h). - Include the relevant event header (for example,
dice/events/malloc.h). - Subscribe with
PS_SUBSCRIBE(<CHAIN>, <EVENT_ID>, { … }). - Use
EVENT_PAYLOADor the struct definition from the event header to inspect the payload.
Example:
#include <dice/chains/capture.h>
#include <dice/events/mutex.h>
#include <dice/module.h>
PS_SUBSCRIBE(CAPTURE_BEFORE, EVENT_MUTEX_LOCK, {
struct mutex_event *ev = EVENT_PAYLOAD(ev);
/* inspect ev->mutex, ev->owner, etc. */
return PS_OK;
});
Consult the individual headers in include/dice/events/ for field-level
documentation of each payload.