add wrapasm: i386 tracer using tail call from asm
[ldtrace] / wrap_help.c
diff --git a/wrap_help.c b/wrap_help.c
new file mode 100644 (file)
index 0000000..e2a80fd
--- /dev/null
@@ -0,0 +1,18 @@
+#define _GNU_SOURCE
+#include <dlfcn.h>
+#include <sys/uio.h>
+#include <sys/syscall.h>
+
+long __syscall(long,...);
+
+static char *end(char *s) {while(*s) s++; return s;}
+
+void *wrap_help(char *s)
+{
+       struct iovec iov[2] = {
+               { .iov_base = s, .iov_len = end(s)-s },
+               { .iov_base = "\n", .iov_len = 1 }
+       };
+       __syscall(SYS_writev, 2, iov, 2);
+       return dlsym(RTLD_NEXT, s);
+}