/* * Kind of a hacky way to see if the file being opened is something we're * interested in. For now, we are working under the assumption that a program * will open/read one file of interest, and open/write the other file of * interest. So we assume that files that are opened from /etc and /lib aren't * of interest. /proc and openssl.cnf also aren't interesting, from looking at * openssl. */ static int user_open(bitmask_transtbl *fcntl_flags_tbl, abi_long ret, void *p, abi_long flagarg){ const char *file = path((const char*)p); unsigned int flags = target_to_host_bitmask(flagarg, fcntl_flags_tbl); if (ret > 0){ if((strncmp(file, "/etc", 4) != 0) && (strncmp(file, "/lib", 4) != 0) && (strncmp(file, "/proc", 5) != 0) //&& (strncmp(file, "/dev", 4) != 0) && (strncmp(file, "/usr", 4) != 0) && (strstr(file, "openssl.cnf") == 0) && (strstr(file, "xpdfrc") == 0)){ printf("open %s for ", file); if ((flags & (O_RDONLY | O_WRONLY)) == O_RDONLY){ printf("read\n"); infd = ret; } if (flags & O_WRONLY){ printf("write\n"); outfd = ret; } } } return 0; }
abi_long do_openbsd_syscall(void *cpu_env, int num, abi_long arg1, abi_long arg2, abi_long arg3, abi_long arg4, abi_long arg5, abi_long arg6) { abi_long ret; void *p; #ifdef DEBUG gemu_log("openbsd syscall %d\n", num); #endif if(do_strace) print_openbsd_syscall(num, arg1, arg2, arg3, arg4, arg5, arg6); switch(num) { case TARGET_OPENBSD_NR_exit: #ifdef TARGET_GPROF _mcleanup(); #endif gdb_exit(cpu_env, arg1); /* XXX: should free thread stack and CPU env */ _exit(arg1); ret = 0; /* avoid warning */ break; case TARGET_OPENBSD_NR_read: if (!(p = lock_user(VERIFY_WRITE, arg2, arg3, 0))) goto efault; ret = get_errno(read(arg1, p, arg3)); unlock_user(p, arg2, ret); break; case TARGET_OPENBSD_NR_write: if (!(p = lock_user(VERIFY_READ, arg2, arg3, 1))) goto efault; ret = get_errno(write(arg1, p, arg3)); unlock_user(p, arg2, 0); break; case TARGET_OPENBSD_NR_open: if (!(p = lock_user_string(arg1))) goto efault; ret = get_errno(open(path(p), target_to_host_bitmask(arg2, fcntl_flags_tbl), arg3)); unlock_user(p, arg1, 0); break; case TARGET_OPENBSD_NR_mmap: ret = get_errno(target_mmap(arg1, arg2, arg3, target_to_host_bitmask(arg4, mmap_flags_tbl), arg5, arg6)); break; case TARGET_OPENBSD_NR_mprotect: ret = get_errno(target_mprotect(arg1, arg2, arg3)); break; case TARGET_OPENBSD_NR_syscall: case TARGET_OPENBSD_NR___syscall: ret = do_openbsd_syscall(cpu_env,arg1 & 0xffff,arg2,arg3,arg4,arg5,arg6,0); break; default: ret = syscall(num, arg1, arg2, arg3, arg4, arg5, arg6); break; } fail: #ifdef DEBUG gemu_log(" = %ld\n", ret); #endif if (do_strace) print_openbsd_syscall_ret(num, ret); return ret; efault: ret = -TARGET_EFAULT; goto fail; }
/* do_syscall() should always have a single exit point at the end so that actions, such as logging of syscall results, can be performed. All errnos that do_syscall() returns must be -TARGET_<errcode>. */ abi_long do_freebsd_syscall(void *cpu_env, int num, abi_long arg1, abi_long arg2, abi_long arg3, abi_long arg4, abi_long arg5, abi_long arg6, abi_long arg7, abi_long arg8) { abi_long ret; void *p; #ifdef DEBUG gemu_log("freebsd syscall %d\n", num); #endif if(do_strace) print_freebsd_syscall(num, arg1, arg2, arg3, arg4, arg5, arg6); switch(num) { case TARGET_FREEBSD_NR_exit: #ifdef TARGET_GPROF _mcleanup(); #endif gdb_exit(cpu_env, arg1); /* XXX: should free thread stack and CPU env */ _exit(arg1); ret = 0; /* avoid warning */ break; case TARGET_FREEBSD_NR_read: if (!(p = lock_user(VERIFY_WRITE, arg2, arg3, 0))) goto efault; ret = get_errno(read(arg1, p, arg3)); unlock_user(p, arg2, ret); break; case TARGET_FREEBSD_NR_write: if (!(p = lock_user(VERIFY_READ, arg2, arg3, 1))) goto efault; ret = get_errno(write(arg1, p, arg3)); unlock_user(p, arg2, 0); break; case TARGET_FREEBSD_NR_writev: { int count = arg3; struct iovec *vec; vec = alloca(count * sizeof(struct iovec)); if (lock_iovec(VERIFY_READ, vec, arg2, count, 1) < 0) goto efault; ret = get_errno(writev(arg1, vec, count)); unlock_iovec(vec, arg2, count, 0); } break; case TARGET_FREEBSD_NR_open: if (!(p = lock_user_string(arg1))) goto efault; ret = get_errno(open(path(p), target_to_host_bitmask(arg2, fcntl_flags_tbl), arg3)); unlock_user(p, arg1, 0); break; case TARGET_FREEBSD_NR_mmap: ret = get_errno(target_mmap(arg1, arg2, arg3, target_to_host_bitmask(arg4, mmap_flags_tbl), arg5, arg6)); break; case TARGET_FREEBSD_NR_mprotect: ret = get_errno(target_mprotect(arg1, arg2, arg3)); break; case TARGET_FREEBSD_NR_break: ret = do_obreak(arg1); break; #ifdef __FreeBSD__ case TARGET_FREEBSD_NR___sysctl: ret = do_freebsd_sysctl(arg1, arg2, arg3, arg4, arg5, arg6); break; #endif case TARGET_FREEBSD_NR_sysarch: ret = do_freebsd_sysarch(cpu_env, arg1, arg2); break; case TARGET_FREEBSD_NR_syscall: case TARGET_FREEBSD_NR___syscall: ret = do_freebsd_syscall(cpu_env,arg1 & 0xffff,arg2,arg3,arg4,arg5,arg6,arg7,arg8,0); break; default: ret = get_errno(syscall(num, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8)); break; } fail: #ifdef DEBUG gemu_log(" = %ld\n", ret); #endif if (do_strace) print_freebsd_syscall_ret(num, ret); return ret; efault: ret = -TARGET_EFAULT; goto fail; }