Skip to content

Commit

Permalink
code cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
anoll committed Aug 26, 2011
1 parent 4cb635d commit 77d51e1
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 36 deletions.
30 changes: 10 additions & 20 deletions src/replayer/rep_process_event.c
@@ -1,41 +1,31 @@
#define _GNU_SOURCE

#include <assert.h>
#include <err.h>
#include <poll.h>
#include <sys/socket.h>
#include <fcntl.h>
#include <stdint.h>
#include <stdlib.h>
#include <string.h>
#include <syscall.h>
#include <fcntl.h>

#include <linux/futex.h>
#include <linux/net.h>
#include <linux/ipc.h>
#include <linux/soundcard.h>

#include <sys/ioctl.h>
#include <sys/utsname.h>
#include <sys/socket.h>

#include <i386-linux-gnu/asm/ldt.h>
#include <sys/mman.h>
#include <sys/stat.h>
#include <sys/user.h>

#include <sound/sfnt_info.h>

#include <stdint.h>
#include <drm/drm.h>
#include <drm/radeon_drm.h>
#include <drm/i915_drm.h>

#include "rep_process_event.h"
#include "rep_sched.h"
#include "read_trace.h"

#include "../share/ipc.h"
#include "../share/sys.h"
#include "../share/trace.h"
#include "../share/util.h"
#include "read_trace.h"
#include "../share/shmem.h"

/*
* Compares the register file as it appeared in the recording phase
Expand Down Expand Up @@ -113,7 +103,7 @@ static void finish_syscall_emu(struct context* context)
if (current_syscall != rec_syscall) {
printf("stop reason: %x :%d\n", ctx->status,
WSTOPSIG(ctx->status));
errx(1, "Internal error: syscalls out of sync: rec: %d now: %d\n", rec_syscall, current_syscall);
fprintf(stderr, "Internal error: syscalls out of sync: rec: %d now: %d\n", rec_syscall, current_syscall);
sys_exit();
}

Expand Down Expand Up @@ -268,7 +258,8 @@ static void handle_socket(struct context* context, struct trace_entry* trace)
}

default:
errx(1, "unknwon call in socket: %d -- bailing out\n", call);
fprintf(stderr, "unknwon call in socket: %d -- bailing out\n", call);
sys_exit();
}

set_return_value(context);
Expand Down Expand Up @@ -1506,8 +1497,7 @@ void rep_process_syscall(struct context* context)
SYS_EXEC_ARG(rt_sigprocmask,1)

default:
errx(1, " Replayer: unknown system call: %d -- bailing out\n", syscall);
fflush(stderr);
fprintf(stderr, " Replayer: unknown system call: %d -- bailing out\n", syscall);
}

if (state == STATE_SYSCALL_EXIT) {
Expand Down
7 changes: 4 additions & 3 deletions src/share/ipc.h
@@ -1,8 +1,9 @@
#ifndef READ_FROM_CHILD_H_
#define READ_FROM_CHILD_H_
#ifndef __IPC_H__
#define __IPC_H__

#include <sys/user.h>

#include "types.h"

void read_child_registers(int child_id, struct user_regs_struct* regs);
long read_child_code(pid_t pid, void* addr);
Expand Down Expand Up @@ -39,4 +40,4 @@ void write_child_ebp(int tid, long int val);
char* read_child_str(pid_t pid, long int addr);
void* read_child_data_tid(pid_t tid, size_t size, long int addr);

#endif /* READ_FROM_CHILD_H_ */
#endif /* __IPC_H__ */
13 changes: 10 additions & 3 deletions src/replayer/shmem.c → src/share/shmem.c
@@ -1,12 +1,19 @@
#include <stdio.h>
#include <sys/shm.h>


#include "../share/sys.h"


#define SHMEM_MAXKEYS 10

static int shmem_keys[SHMEM_MAXKEYS][2];


/**
* TODO: Replace this with a decent hasmap. It's a simple
* list right now, since it will not have a noticeable impact
* on performance.
*/
void shmem_store_key(int key, int val)
{
int i;
Expand All @@ -19,7 +26,7 @@ void shmem_store_key(int key, int val)
}

/* too many keys */
printf("too many shared keys -- bailing out\n");
fprintf(stderr,"too many shared keys -- bailing out\n");
sys_exit();
}

Expand All @@ -33,7 +40,7 @@ int shmem_get_key(int key)
}

/* too many keys */
printf("shmem key not found -- bailing out\n");
fprintf(stderr,"shmem key not found -- bailing out\n");
sys_exit();

return -1;
Expand Down
17 changes: 7 additions & 10 deletions src/share/sys.c
@@ -1,14 +1,9 @@
#define _GNU_SOURCE
#define _GNU_SOURCE

#include <assert.h>
#include <err.h>
#include <fcntl.h>
#include <sched.h>
#include <signal.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <sys/personality.h>
#include <sys/mman.h>
#include <sys/prctl.h>
Expand All @@ -20,7 +15,7 @@
#include "sys.h"
#include "util.h"
#include "ipc.h"

#include "../recorder/rec_sched.h"

FILE* sys_fopen(const char* path, const char* mode)
{
Expand Down Expand Up @@ -117,7 +112,7 @@ void sys_setup_process()
}

unsigned long mask = 0x4;
if (sched_setaffinity(0, sizeof(mask), &mask) == -1) {
if (sched_setaffinity(0, sizeof(mask), (cpu_set_t*)&mask) == -1) {
perror("error setting affinity -- bailing out\n");
sys_exit();
}
Expand Down Expand Up @@ -285,7 +280,8 @@ void* sys_mmap(void* addr, size_t length, int prot, int flags, int fd, off_t off
{
void* tmp = mmap(addr, length, prot, flags, fd, offset);
if (tmp == MAP_FAILED) {
errx(1, "cannot memory-map file\n");
fprintf(stderr, "cannot memory-map file\n");
sys_exit();
}
return tmp;
}
Expand Down Expand Up @@ -316,7 +312,8 @@ void* sys_malloc_zero(int size)
void sys_free(void** ptr)
{
if (*ptr == NULL) {
errx(1, "Failed to free memory of size -- bailing out\n");
fprintf(stderr, "Failed to free memory of size -- bailing out\n");
sys_exit();
}
free(*ptr);
*ptr = 0;
Expand Down
1 change: 1 addition & 0 deletions src/share/util.h
Expand Up @@ -20,6 +20,7 @@

char* get_inst(pid_t pid, int eip_offset, int* opcode_size);
void print_inst(pid_t tid);
void print_syscall(struct context *ctx, struct trace_entry *trace);

int compare_register_files(char* name1, struct user_regs_struct* reg1, char* name2, struct user_regs_struct* reg2, int print, int stop);
uint64_t str2ull(const char* start, size_t max_size);
Expand Down

0 comments on commit 77d51e1

Please sign in to comment.