1 /* This program should crash and produce coredump */
10 #include <sys/types.h>
11 #include <sys/sysctl.h>
15 #if defined(__linux__)
16 void write_maps(char *fname)
18 char buf[512], path[128];
21 FILE *maps = fopen("/proc/self/maps", "r");
22 FILE *out = fopen(fname, "w");
27 while (fgets(buf, sizeof(buf), maps))
29 if (sscanf(buf, "%jx-%*x %*c%*c%c%*c %*x %*s %*d /%126[^\n]", &addr, &exec, path+1) != 3)
36 fprintf(out, "0x%jx:%s ", addr, path);
43 #elif defined(__FreeBSD__)
45 write_maps(char *fname)
49 struct kinfo_vmentry *kv;
53 out = fopen(fname, "w");
60 mib[2] = KERN_PROC_VMMAP;
62 error = sysctl(mib, 4, NULL, &len, NULL, 0);
69 error = sysctl(mib, 4, buf, &len, NULL, 0);
73 for (bp = buf, eb = buf + len; bp < eb; bp += kv->kve_structsize) {
74 kv = (struct kinfo_vmentry *)(uintptr_t)bp;
75 if (kv->kve_type == KVME_TYPE_VNODE &&
76 (kv->kve_protection & KVME_PROT_EXEC) != 0) {
77 fprintf(out, "0x%jx:%s ", kv->kve_start, kv->kve_path);
90 int c(int x) NOINLINE ALIAS(b);
91 #define compiler_barrier() asm volatile("");
94 #define compiler_barrier()
99 *(volatile int *)32 = 1;
103 int NOINLINE b(int x)
117 main (int argc, char **argv)