aboutsummaryrefslogtreecommitdiffstats
path: root/common.h
diff options
context:
space:
mode:
authorMattias Andrée <maandree@kth.se>2020-05-30 17:34:29 +0200
committerMattias Andrée <maandree@kth.se>2020-05-30 17:34:29 +0200
commit712f56fe3369c59d32b9000830b4ed7b25ed24b5 (patch)
tree27ddf931fd2d980d0c4dcdfb025f26f5380fb5d6 /common.h
parentPrint errno names and strings (diff)
downloadsctrace-712f56fe3369c59d32b9000830b4ed7b25ed24b5.tar.gz
sctrace-712f56fe3369c59d32b9000830b4ed7b25ed24b5.tar.bz2
sctrace-712f56fe3369c59d32b9000830b4ed7b25ed24b5.tar.xz
Add support for tracing fork children
Signed-off-by: Mattias Andrée <maandree@kth.se>
Diffstat (limited to '')
-rw-r--r--common.h90
1 files changed, 90 insertions, 0 deletions
diff --git a/common.h b/common.h
new file mode 100644
index 0000000..f027327
--- /dev/null
+++ b/common.h
@@ -0,0 +1,90 @@
+/* See LICENSE file for copyright and license details. */
+#if !defined __x86_64__ || defined __IPL32__
+# error "This program is only implemented for x86-64"
+#endif
+
+#include <sys/ptrace.h>
+#include <sys/syscall.h>
+#include <sys/uio.h>
+#include <sys/user.h>
+#include <sys/wait.h>
+#include <ctype.h>
+#include <errno.h>
+#include <limits.h>
+#include <signal.h>
+#include <stdarg.h>
+#include <stdint.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
+
+/* Constants used in system calls */
+#include <sys/epoll.h>
+#include <sys/socket.h>
+#include <fcntl.h>
+
+#include "arg.h"
+#include "list-errnos.h"
+
+
+enum type {
+ Unknown,
+ Void,
+ Int,
+ UInt,
+ OInt,
+ XInt,
+ Long,
+ ULong,
+ OLong,
+ XLong,
+ LLong,
+ ULLong,
+ OLLong,
+ XLLong,
+ Ptr
+};
+
+enum state {
+ Normal,
+ Syscall
+};
+
+struct process {
+ pid_t pid;
+ struct process *next;
+ struct process *prev;
+ enum state state;
+
+ /* Syscall data */
+ unsigned long long int scall;
+ unsigned long long int args[6];
+ unsigned long long int ret;
+ enum type ret_type;
+};
+
+
+/* consts.c */
+const char *get_errno_name(int err);
+
+/* memory.c */
+char *get_string(pid_t pid, unsigned long int addr, size_t *lenp, const char **errorp);
+int get_struct(pid_t pid, unsigned long int addr, void *out, size_t size, const char **errorp);
+char *get_memory(pid_t pid, unsigned long int addr, size_t n, const char **errorp);
+char *escape_memory(char *str, size_t m);
+
+/* print.c */
+void print_systemcall(struct process *proc);
+void print_systemcall_exit(struct process *proc);
+
+/* process.c */
+void init_process_list(void);
+struct process *find_process(pid_t pid);
+struct process *add_process(pid_t pid, int trace_options);
+void remove_process(struct process *proc);
+
+/* util.c */
+void set_trace_output(FILE *fp);
+void tprintf(struct process *proc, const char *fmt, ...);
+_Noreturn void eprintf(const char *fmt, ...);