Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Comparing changes

Choose two branches to see what's changed or to start a new pull request. If you need to, you can also compare across forks.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also compare across forks.
base fork: hoelzro/mytrace
base: 0e767b02a3
...
head fork: hoelzro/mytrace
compare: df6661e34b
Checking mergeability… Don't worry, you can still create the pull request.
  • 5 commits
  • 3 files changed
  • 0 commit comments
  • 1 contributor
Showing with 30 additions and 17 deletions.
  1. +16 −14 main.c
  2. +4 −0 syscall_info.c
  3. +10 −3 syscall_info.h
View
30 main.c
@@ -43,7 +43,11 @@ next_trace(pid_t pid)
ptrace(PTRACE_SYSCALL, pid, NULL, 0);
ok = waitpid(pid, &status, 0);
- /* XXX check ok */
+
+ if(ok == -1) {
+ /* XXX elaborate */
+ return 0;
+ }
return status;
}
@@ -70,20 +74,19 @@ handle_syscall(pid_t pid)
get_syscall_info(pid, &info);
- if(info.syscall_no == __NR_write) {
- char *buffer;
+ switch(info.syscall_no) {
+ case __NR_connect: {
+ struct sockaddr *addr;
- buffer = malloc(info.args.write.count + 1);
- pmemcpy(buffer, info.args.write.buf, pid, info.args.write.count);
- buffer[info.args.write.count] = '\0';
+ addr = malloc(info.args.connect.addrlen);
+ pmemcpy((char *) addr, (const char *) info.args.connect.addr, pid,
+ info.args.connect.addrlen);
- free(buffer);
- } else if(info.syscall_no == __NR_exit) {
- printf("status = %d\n", info.args.exit.status);
- } else if(info.syscall_no == __NR_exit_group) {
- printf("status = %d\n", info.args.exit_group.status);
+ free(addr);
+ } /* fall through so next_trace gets called */
+ default:
+ return next_trace(pid); /* we don't care about other syscalls */
}
- return next_trace(pid);
}
static void
@@ -120,8 +123,7 @@ main(void)
ptrace(PTRACE_TRACEME, 0, 0, 0);
raise(SIGINT);
- printf("Hello!\n");
- exit(0);
+ execlp("nc", "nc", "localhost", "2000");
}
return 0;
View
4 syscall_info.c
@@ -4,6 +4,10 @@
#include "syscall_info.h"
+#if !__x86_64__
+# error "This only works on 64-bit Intel machines for now"
+#endif
+
/****************************************************************************/
/* Begin platform-specific code (put this in a different file) */
/****************************************************************************/
View
13 syscall_info.h
@@ -10,6 +10,12 @@ struct write_args {
size_t count REG_ALIGN;
};
+struct connect_args {
+ int sockfd REG_ALIGN;
+ const struct sockaddr *addr REG_ALIGN;
+ socklen_t addrlen REG_ALIGN;
+};
+
struct exit_args {
int status REG_ALIGN;
};
@@ -18,9 +24,10 @@ struct syscall_info {
int syscall_no;
union {
- struct write_args write;
- struct exit_args exit;
- struct exit_args exit_group;
+ struct write_args write;
+ struct connect_args connect;
+ struct exit_args exit;
+ struct exit_args exit_group;
struct {
void *registers[MAX_SYSCALL_ARGS];

No commit comments for this range

Something went wrong with that request. Please try again.