ts tweaks for _dyn
[ginge.git] / loader / override.c
index a9d545b..5927bc2 100644 (file)
@@ -39,14 +39,17 @@ static const struct dev_fd_t takeover_devs[] = {
   { "/dev/fb1",     FAKEDEV_FB1 },
   { "/dev/fb/1",    FAKEDEV_FB1 },
   { "/dev/mmuhack", FAKEDEV_MMUHACK },
-  { "/dev/tty",     FAKEDEV_TTY0 },
+  { "/dev/tty",     FAKEDEV_TTY },
   { "/dev/tty0",    FAKEDEV_TTY0 },
+  { "/dev/touchscreen/wm97xx", FAKEDEV_WM97XX },
+  { "/etc/pointercal",         FAKEDEV_WM97XX_P },
+  { "/dev/input/mice", -ENODEV },
 #ifdef PND
-  { "/dev/input/event*", -1 }, // hide for now, may cause dupe events
+  { "/dev/input/event*", -ENODEV }, // hide for now, may cause dupe events
 #endif
 };
 
-static long w_open_raw(const char *pathname, int flags, mode_t mode)
+long w_open_raw(const char *pathname, int flags, mode_t mode)
 {
   long ret;
   int i;
@@ -68,8 +71,11 @@ static long w_open_raw(const char *pathname, int flags, mode_t mode)
     }
   }
 
-  if (i == ARRAY_SIZE(takeover_devs))
-    ret = g_open_raw(pathname, flags, mode);
+  if (i == ARRAY_SIZE(takeover_devs)) {
+    const char *w_path = emu_wrap_path(pathname);
+    ret = g_open_raw(w_path, flags, mode);
+    emu_wrap_path_free(w_path, pathname);
+  }
 
   if (ret >= 0) {
     for (i = 0; emu_interesting_fds[i].name != NULL; i++) {
@@ -137,12 +143,12 @@ long w_read_raw(int fd, void *buf, size_t count)
 {
   long ret;
 
-  if (fd == FAKEDEV_GPIO)
-    ret = emu_read_gpiodev(buf, count);
+  if (FAKEDEV_MEM <= fd && fd < FAKEDEV_FD_BOUNDARY)
+    ret = emu_do_read(fd, buf, count);
   else
     ret = g_read_raw(fd, buf, count);
 
-  //strace("read(%d, %p, %ld) = %ld\n", fd, buf, count, ret);
+  //strace("read(%d, %p, %zd) = %ld\n", fd, buf, count, ret);
   return ret;
 }
 
@@ -251,15 +257,20 @@ static UNUSED int w_execvp(const char *file, char *const argv[])
   return emu_do_execve(file, argv, environ);
 }
 
-// static note: this can't safely return because of the way it's patched in
-// static note2: can't be used, execve hangs?
-static UNUSED int w_execve(const char *filename, char *const argv[],
-                  char *const envp[])
+long w_execve_raw(const char *filename, char * const argv[],
+                  char * const envp[])
 {
   strace("execve(%s, %p, %p) = ?\n", filename, argv, envp);
   return emu_do_execve(filename, argv, envp);
 }
 
+static UNUSED int w_execve(const char *filename, char * const argv[],
+                           char * const envp[])
+{
+  long ret = w_execve_raw(filename, argv, envp);
+  return g_syscall_error(ret);
+}
+
 static int w_chdir(const char *path)
 {
   long ret;
@@ -268,7 +279,28 @@ static int w_chdir(const char *path)
     ret = 0;
   else
     ret = g_chdir_raw(path);
-  strace("chdir(%s) = %d\n", path, ret);
+
+  strace("chdir(%s) = %ld\n", path, ret);
+  return g_syscall_error(ret);
+}
+
+static ssize_t w_readlink(const char *path, char *buf, size_t bufsiz)
+{
+  long ret;
+
+#ifndef DL
+  if (path != NULL && strncmp(path, "/proc/", 6) == 0
+      && strcmp(strrchr(path, '/'), "/exe") == 0)
+  {
+    ret = snprintf(buf, bufsiz, "%s", bin_path);
+    if (ret > bufsiz)
+      ret = bufsiz;
+  }
+  else
+#endif
+    ret = g_readlink_raw(path, buf, bufsiz);
+
+  strace("readlink(%s, %s, %zd) = %ld\n", path, buf, bufsiz, ret);
   return g_syscall_error(ret);
 }
 
@@ -290,6 +322,7 @@ static int w_chdir(const char *path)
 #undef execvp
 #undef execve
 #undef chdir
+#undef readlink
 
 #ifdef DL
 
@@ -318,8 +351,9 @@ MAKE_WRAP_SYM_N(execlp);
 MAKE_WRAP_SYM_N(execle);
 MAKE_WRAP_SYM_N(execv);
 MAKE_WRAP_SYM_N(execvp);
-MAKE_WRAP_SYM(execve);
+MAKE_WRAP_SYM_N(execve);
 MAKE_WRAP_SYM_N(chdir);
+MAKE_WRAP_SYM_N(readlink);
 typeof(mmap) mmap2 __attribute__((alias("w_mmap")));
 
 #define REAL_FUNC_NP(name) \
@@ -340,7 +374,7 @@ static const struct {
   REAL_FUNC_NP(tcsetattr),
   REAL_FUNC_NP(system),
   // exec* - skipped
-  REAL_FUNC_NP(execve),
+  //REAL_FUNC_NP(execve),
   //REAL_FUNC_NP(chdir),
 };
 
@@ -354,7 +388,7 @@ static const struct {
 #define tcgetattr p_real_tcgetattr
 #define tcsetattr p_real_tcsetattr
 #define system p_real_system
-#define execve p_real_execve
+//#define execve p_real_execve
 //#define chdir p_real_chdir
 
 #undef MAKE_WRAP_SYM
@@ -437,7 +471,8 @@ int real_system(const char *command)
 int real_execve(const char *filename, char *const argv[],
                   char *const envp[])
 {
-  return execve(filename, argv, envp);
+  long ret = g_execve_raw(filename, argv, envp);
+  return g_syscall_error(ret);
 }
 
 int real_chdir(const char *path)
@@ -446,6 +481,12 @@ int real_chdir(const char *path)
   return g_syscall_error(ret);
 }
 
+ssize_t real_readlink(const char *path, char *buf, size_t bufsiz)
+{
+  long ret = g_readlink_raw(path, buf, bufsiz);
+  return g_syscall_error(ret);
+}
+
 void real_sleep(unsigned int seconds)
 {
   struct timespec ts = { seconds, 0 };