[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PATCH 03/19] linux-user: add open() hijack infrastructure
From: |
riku . voipio |
Subject: |
[Qemu-devel] [PATCH 03/19] linux-user: add open() hijack infrastructure |
Date: |
Tue, 31 Jan 2012 11:29:12 +0200 |
From: Alexander Graf <address@hidden>
There are a number of files in /proc that expose host information
to the guest program. This patch adds infrastructure to override
the open() syscall for guest programs to enable us to on the fly
generate guest sensible files.
Signed-off-by: Alexander Graf <address@hidden>
Signed-off-by: Riku Voipio <address@hidden>
---
linux-user/syscall.c | 52 +++++++++++++++++++++++++++++++++++++++++++++++--
1 files changed, 49 insertions(+), 3 deletions(-)
diff --git a/linux-user/syscall.c b/linux-user/syscall.c
index 2bf9e7e..e100025 100644
--- a/linux-user/syscall.c
+++ b/linux-user/syscall.c
@@ -4600,6 +4600,52 @@ int get_osversion(void)
return osversion;
}
+static int do_open(void *cpu_env, const char *pathname, int flags, mode_t mode)
+{
+ struct fake_open {
+ const char *filename;
+ int (*fill)(void *cpu_env, int fd);
+ };
+ const struct fake_open *fake_open;
+ static const struct fake_open fakes[] = {
+ { NULL, NULL }
+ };
+
+ for (fake_open = fakes; fake_open->filename; fake_open++) {
+ if (!strncmp(pathname, fake_open->filename,
+ strlen(fake_open->filename))) {
+ break;
+ }
+ }
+
+ if (fake_open->filename) {
+ const char *tmpdir;
+ char filename[PATH_MAX];
+ int fd, r;
+
+ /* create temporary file to map stat to */
+ tmpdir = getenv("TMPDIR");
+ if (!tmpdir)
+ tmpdir = "/tmp";
+ snprintf(filename, sizeof(filename), "%s/qemu-open.XXXXXX", tmpdir);
+ fd = mkstemp(filename);
+ if (fd < 0) {
+ return fd;
+ }
+ unlink(filename);
+
+ if ((r = fake_open->fill(cpu_env, fd))) {
+ close(fd);
+ return r;
+ }
+ lseek(fd, 0, SEEK_SET);
+
+ return fd;
+ }
+
+ return get_errno(open(path(pathname), flags, mode));
+}
+
/* 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>. */
@@ -4685,9 +4731,9 @@ abi_long do_syscall(void *cpu_env, int num, abi_long arg1,
case TARGET_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));
+ ret = get_errno(do_open(cpu_env, p,
+ target_to_host_bitmask(arg2, fcntl_flags_tbl),
+ arg3));
unlock_user(p, arg1, 0);
break;
#if defined(TARGET_NR_openat) && defined(__NR_openat)
--
1.7.5.4
- [Qemu-devel] [PATCH 00/19] Pending linux-user patches, riku . voipio, 2012/01/31
- [Qemu-devel] [PATCH 14/19] linux-user: Implement *listxattr syscalls, riku . voipio, 2012/01/31
- [Qemu-devel] [PATCH 01/19] linux-user: stack_base is now mandatory on all targets, riku . voipio, 2012/01/31
- [Qemu-devel] [PATCH 07/19] linux-user/main.c: Add option to user-mode emulation so that user can specify log file name, riku . voipio, 2012/01/31
- [Qemu-devel] [PATCH 04/19] linux-user: fake /proc/self/maps, riku . voipio, 2012/01/31
- [Qemu-devel] [PATCH 15/19] linux-user: Add default-configs for mipsn32[el], riku . voipio, 2012/01/31
- [Qemu-devel] [PATCH 18/19] linux-user: Define TARGET_QEMU_ESIGRETURN for mips64, riku . voipio, 2012/01/31
- [Qemu-devel] [PATCH 03/19] linux-user: add open() hijack infrastructure,
riku . voipio <=
- [Qemu-devel] [PATCH 10/19] linux-user/strace.c: Correct errno printing for mmap etc, riku . voipio, 2012/01/31
- [Qemu-devel] [PATCH 11/19] linux-user: fix wait* syscall status returns, riku . voipio, 2012/01/31
- [Qemu-devel] [PATCH 06/19] linux-user: fake /proc/self/auxv, riku . voipio, 2012/01/31
- [Qemu-devel] [PATCH 05/19] linux-user: fake /proc/self/stat, riku . voipio, 2012/01/31
- [Qemu-devel] [PATCH 13/19] linux-user/syscall.c: Implement f and l versions of set/get/removexattr, riku . voipio, 2012/01/31
- [Qemu-devel] [PATCH 17/19] linux-user: Define TARGET_QEMU_ESIGRETURN for mipsn32, riku . voipio, 2012/01/31
- [Qemu-devel] [PATCH 12/19] linux-user: Allow NULL value pointer in setxattr and getxattr, riku . voipio, 2012/01/31
- [Qemu-devel] [PATCH 16/19] linux-user: Add default configs for mips64[el], riku . voipio, 2012/01/31
- [Qemu-devel] [PATCH 09/19] linux-user: fix QEMU_STRACE=1 segfault, riku . voipio, 2012/01/31
- [Qemu-devel] [PATCH 02/19] linux-user: save auxv length, riku . voipio, 2012/01/31