summaryrefslogtreecommitdiff
path: root/targets
diff options
context:
space:
mode:
authorGabriel Schneider <[email protected]>2026-11-11 20:08:00 -0300
committerGabriel Schneider <[email protected]>2026-11-11 20:08:07 -0300
commit0ec2376cae2fdfc50e90d930ebc86c7a5b7f5594 (patch)
treebb820b7e39994177b6abc503ab5b980603d34513 /targets
parentcc2059e39047cafe1886dc17084855ddd0c52b01 (diff)
downloadcomputeranim-0ec2376cae2fdfc50e90d930ebc86c7a5b7f5594.tar.gz
computeranim-0ec2376cae2fdfc50e90d930ebc86c7a5b7f5594.zip
trace: what push, call and ret touch; names for data; the stack's roles, sharper
For a disassembly that points at the stack word it touched. The stack's own instructions have touches (push, call and enter write at rsp-8; pop and ret read at rsp; leave at rbp), and a rep string instruction its whole range. An address a global or static object holds is named (head+0, libc.so.6!main_arena+96). The saved rbp has its role at the push that makes it; every local in a shared word is given; the stack protector's copy is found by seeing its store; ztrace show labels each stack word. Six bytes a moment and 3% slower on the list by instruction. Co-Authored-By: Claude Fable 5.2 <[email protected]> Claude-Session: https://claude.ai/code/session_016Y9MNCKgYCGiANnEwcEQxa
Diffstat (limited to 'targets')
-rw-r--r--targets/stack.c36
1 files changed, 36 insertions, 0 deletions
diff --git a/targets/stack.c b/targets/stack.c
new file mode 100644
index 0000000..6ba2735
--- /dev/null
+++ b/targets/stack.c
@@ -0,0 +1,36 @@
+// What a stack's own instructions and the string instructions touch, by
+// instruction: pushes and pops, calls and returns, enter and leave, the
+// flags pushed; copies and fills, repeated, both ways. Built at -O0 with
+// the stack protector: `fill` keeps a canary, and its i and n share a word.
+#include <stdint.h>
+
+char dst[64], src[64] = "abcdefghijklmnopqrstuvwxyz";
+// Past the file's last page: zeroes in a mapping of their own.
+char big[1 << 16];
+
+__attribute__((noinline)) static void strings(void) {
+ void *d = dst, *s = src;
+ uint64_t n = 3;
+ __asm__ volatile("rep movsq" : "+D"(d), "+S"(s), "+c"(n) : : "memory");
+ d = dst + 40;
+ n = 5;
+ __asm__ volatile("rep stosb" : "+D"(d), "+c"(n) : "a"(0x41) : "memory");
+ // Down from the last byte, the direction flag set.
+ d = dst + 63;
+ s = src + 25;
+ n = 4;
+ __asm__ volatile("std; rep movsb; cld" : "+D"(d), "+S"(s), "+c"(n) : : "memory");
+ __asm__ volatile("pushfq; popfq; push %%rbx; pop %%rbx; enter $16, $0; leave" : : : "memory");
+}
+
+__attribute__((noinline)) static int fill(int n) {
+ char buf[16];
+ for (int i = 0; i < n; i++) buf[i] = 'A' + i;
+ return buf[n - 1];
+}
+
+int main(void) {
+ strings();
+ big[4096] = 1;
+ return fill(16) + big[4096] + dst[0] - 'P' - 1 - 'a';
+}