22#include "augment/augment_export.h"
33typedef enum AugmentPhase {
39 AUGMENT_PHASE_BEFORE = 0,
46 AUGMENT_PHASE_AFTER = 1,
53 AUGMENT_PHASE_REPLACE = 2,
74typedef void (*AugmentFn)(
AugmentCtx* ctx,
void* userdata);
122#define AUGMENT_HOOK(sym, fn) \
123 static struct _AugmentAutoHook_##sym { \
124 _AugmentAutoHook_##sym() { \
125 static const auto _fn = fn; \
128 AUGMENT_PHASE_BEFORE, \
129 [](AugmentCtx* ctx, void*) { _fn(ctx); }, \
132 } _augment_autohook_instance_##sym
144AUGMENT_API
void augment_register_instance(
const char* class_name,
void* ptr);
154AUGMENT_API
void augment_unregister_instance(
const char* class_name,
void* ptr);
165AUGMENT_API
void* augment_get_instance(
const char* class_name,
int index);
173AUGMENT_API
int augment_instance_count(
const char* class_name);
177using AugmentLogFn = void(*)(
const char* tag,
const char* msg);
178AUGMENT_API
void augment_set_logger(AugmentLogFn fn);
180AUGMENT_API
void augment_invoke(
const char* symbol,
AugmentCtx* ctx);
181AUGMENT_API
void* augment_before(
const char* symbol,
AugmentCtx* ctx);
182AUGMENT_API
void augment_after(
const char* symbol,
AugmentCtx* ctx);
183AUGMENT_API
int augment_enter(
const char* symbol,
AugmentCtx* ctx);
184AUGMENT_API
int augment_register(
191AUGMENT_API
void augment_register_ptr(
196AUGMENT_API
void augment_unregister(
const char* augment_id);
197AUGMENT_API
void augment_install_all(
void);
198AUGMENT_API
void augment_clear(
void);
199AUGMENT_API
const char* augment_inspect(
const char* symbol);
200AUGMENT_API
void* augment_resolve(
const char* symbol);
201AUGMENT_API
int augment_self_test(
void);
204AUGMENT_API
void augment_register_signature(
const char* symbol,
int is_member,
205 const char* rtype,
const char** atypes,
207AUGMENT_API
void augment_register_struct(
const char* name,
const char** member_kinds,
209AUGMENT_API
int augment_load_signatures(
const char* path);
210AUGMENT_API
int augment_field_offset(
const char* field);
211AUGMENT_API
void* augment_make_closure(
const char* symbol);
212AUGMENT_API
int augment_call(
const char* symbol,
void** args,
unsigned nargs,
void* ret_out,
int instance_index = -1);
214inline void augment_register_signature(
const char*,
int,
const char*,
const char**,
unsigned) {}
215inline void augment_register_struct(
const char*,
const char**,
unsigned) {}
216inline int augment_load_signatures(
const char*) {
return 0; }
217inline int augment_field_offset(
const char*) {
return -1; }
218inline void* augment_make_closure(
const char*) {
return nullptr; }
219inline int augment_call(
const char*,
void**,
unsigned,
void*,
int = -1) {
return 0; }
225AUGMENT_API
int augment_manifest_load(
const char* path);
227AUGMENT_API
int augment_fn_count(
const char* flat);
228AUGMENT_API
const char* augment_fn_mangled(
const char* flat,
int i);
229AUGMENT_API
const char* augment_fn_loc(
const char* flat,
int i);
230AUGMENT_API
const char* augment_resolve_sig(
const char* flat,
const char* sig);
232AUGMENT_API
int augment_fn_params(
const char* mangled,
const AugmentArg** out);
233AUGMENT_API
int augment_struct_fields(
const char* name,
const AugmentField** out);
235AUGMENT_API
int augment_enum_values(
const char* name,
const AugmentEnumVal** out);
236AUGMENT_API
int augment_global_addr(
const char* name,
const char** kind_out,
void** addr_out);
238AUGMENT_API
const char* augment_fn_self_view(
const char* mangled);
239AUGMENT_API
const char* augment_fn_ret(
const char* mangled);
241AUGMENT_API
void augment_mem_read(
void* base,
int offset,
const char* kind,
void* out);
242AUGMENT_API
void augment_mem_write(
void* base,
int offset,
const char* kind,
const void* in);
243AUGMENT_API
int augment_mem_read_str(
void* base,
int offset,
int cap,
char* out);
244AUGMENT_API
void augment_mem_write_str(
void* base,
int offset,
int cap,
const char* s);
Definition augment.hpp:222
Declares what a hook touches, for automated conflict detection.
Definition augment.hpp:82
const char *const * writes
Symbols/fields this hook writes.
Definition augment.hpp:89
int n_reads
Number of entries in reads.
Definition augment.hpp:87
int n_writes
Number of entries in writes.
Definition augment.hpp:90
int n_affects
Number of entries in affects.
Definition augment.hpp:84
const char *const * reads
Symbols/fields this hook reads.
Definition augment.hpp:86
const char *const * affects
Symbols/fields this hook affects (side effects).
Definition augment.hpp:83
Context passed to a hooked function's callback.
Definition augment.hpp:59
void * self
this pointer
Definition augment.hpp:60
int arg_count
number of arguments
Definition augment.hpp:65
int cancelled
set nonzero in before to skip original
Definition augment.hpp:63
void ** args
argument array, index 0 = first param
Definition augment.hpp:61
void * user
internal, do not touch
Definition augment.hpp:64
void * ret
return value slot
Definition augment.hpp:62
Definition augment.hpp:234
Definition augment.hpp:223
Options used when registering a hook.
Definition augment.hpp:96
const char * tag
Human-readable label for logs / debug.
Definition augment.hpp:98
AugmentContract contract
Declared read/write/affects surface, for conflict detection.
Definition augment.hpp:100
int priority
Execution order relative to other hooks (lower runs first).
Definition augment.hpp:97
const char * augment_id
Unique identifier for this hook registration.
Definition augment.hpp:99