summaryrefslogtreecommitdiff
path: root/targets/agent_list.c
diff options
context:
space:
mode:
authorGabriel Schneider <[email protected]>2026-11-10 11:44:48 -0300
committerGabriel Schneider <[email protected]>2026-11-10 12:09:34 -0300
commitce7c0abf14e7ab056d5479adc3f05df9976e94e4 (patch)
tree8931de9a55b3d7c2ec2d52d3b3817c6f7eb5db5a /targets/agent_list.c
parente7aa7801c10ed34194b7fe3f5ca8722a72404e65 (diff)
downloadcomputeranim-ce7c0abf14e7ab056d5479adc3f05df9976e94e4.tar.gz
computeranim-ce7c0abf14e7ab056d5479adc3f05df9976e94e4.zip
agent: the in-process backend, and ztrace run's options for it
libztrace-agent.so (preloaded) and libztrace-agent.a (linked in), one source: map and thread_start at startup; alloc/free from the interposed allocator; syscall_enter/exit through Syscall User Dispatch; call/ret from int3 hooks; mem_write from watched regions diffed in-process; the target-side API (include/ztrace.h, and the ztrace-agent module for Zig). ztrace run turns each on (--alloc --syscalls --hook --watch), chooses the moments (--cut), and stops the target at event kinds without ptrace (--stop-at, --read, -i). test-agent records real targets and checks the recordings. Co-Authored-By: Claude Fable 5.2 <[email protected]>
Diffstat (limited to 'targets/agent_list.c')
-rw-r--r--targets/agent_list.c46
1 files changed, 46 insertions, 0 deletions
diff --git a/targets/agent_list.c b/targets/agent_list.c
new file mode 100644
index 0000000..8787638
--- /dev/null
+++ b/targets/agent_list.c
@@ -0,0 +1,46 @@
+// What the allocation tracker is for: a linked list of N nodes built and
+// torn down, beside one of each other way to allocate.
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+struct node {
+ struct node *next;
+ long value;
+};
+
+int main(int argc, char **argv) {
+ long n = argc > 1 ? atol(argv[1]) : 100;
+ struct node *head = NULL;
+ for (long i = 0; i < n; i++) {
+ struct node *node = malloc(sizeof *node);
+ node->value = i;
+ node->next = head;
+ head = node;
+ }
+
+ // A vector that grows: realloc in place and realloc that moves.
+ size_t cap = 4, len = 0;
+ long *values = calloc(cap, sizeof *values);
+ for (struct node *node = head; node; node = node->next) {
+ if (len == cap) values = realloc(values, (cap *= 2) * sizeof *values);
+ values[len++] = node->value;
+ }
+ void *aligned = NULL;
+ if (posix_memalign(&aligned, 64, 100)) return 1;
+ void *page = aligned_alloc(4096, 4096);
+ memset(page, 1, 4096);
+
+ long sum = ((char *)page)[100] - 1;
+ while (head) {
+ struct node *node = head;
+ head = node->next;
+ sum += node->value;
+ free(node);
+ }
+ free(values);
+ free(aligned);
+ free(page);
+ printf("sum %ld of %zu\n", sum, len);
+ return 0;
+}