Patchwork [1/5] linux-user: move exit to own function

login
register
mail settings
Submitter riku.voipio@linaro.org
Date Oct. 12, 2012, 6:24 p.m.
Message ID <266abe097ce7b655bd1605d190188e8653a71b56.1350063473.git.riku.voipio@linaro.org>
Download mbox | patch
Permalink /patch/191175/
State New
Headers show

Comments

riku.voipio@linaro.org - Oct. 12, 2012, 6:24 p.m.
From: Riku Voipio <riku.voipio@linaro.org>

In preparations for for refactoring the main switch/case out

Signed-off-by: Riku Voipio <riku.voipio@linaro.org>
---
 linux-user/syscall.c |   92 ++++++++++++++++++++++++++------------------------
 1 file changed, 48 insertions(+), 44 deletions(-)

Patch

diff --git a/linux-user/syscall.c b/linux-user/syscall.c
index 471d060..0b077e7 100644
--- a/linux-user/syscall.c
+++ b/linux-user/syscall.c
@@ -5083,6 +5083,53 @@  static int do_open(void *cpu_env, const char *pathname, int flags, mode_t mode)
 
     return get_errno(open(path(pathname), flags, mode));
 }
+static void do_exit(void *, abi_long) __attribute__ ((noreturn));
+static void do_exit(void *cpu_env, abi_long arg1)
+{
+#ifdef CONFIG_USE_NPTL
+    /* In old applications this may be used to implement _exit(2).
+       However in threaded applictions it is used for thread termination,
+       and _exit_group is used for application termination.
+       Do thread termination if we have more then one thread.  */
+    /* FIXME: This probably breaks if a signal arrives.  We should probably
+       be disabling signals.  */
+    if (first_cpu->next_cpu) {
+        TaskState *ts;
+        CPUArchState **lastp;
+        CPUArchState *p;
+
+        cpu_list_lock();
+        lastp = &first_cpu;
+        p = first_cpu;
+        while (p && p != (CPUArchState *)cpu_env) {
+            lastp = &p->next_cpu;
+            p = p->next_cpu;
+        }
+        /* If we didn't find the CPU for this thread then something is
+           horribly wrong.  */
+        if (!p)
+            abort();
+        /* Remove the CPU from the list.  */
+        *lastp = p->next_cpu;
+        cpu_list_unlock();
+        ts = ((CPUArchState *)cpu_env)->opaque;
+        if (ts->child_tidptr) {
+            put_user_u32(0, ts->child_tidptr);
+            sys_futex(g2h(ts->child_tidptr), FUTEX_WAKE, INT_MAX,
+                      NULL, NULL, 0);
+        }
+        thread_env = NULL;
+        object_delete(OBJECT(ENV_GET_CPU(cpu_env)));
+        g_free(ts);
+        pthread_exit(NULL);
+    }
+#endif
+#ifdef TARGET_GPROF
+    _mcleanup();
+#endif
+    gdb_exit(cpu_env, arg1);
+    _exit(arg1);
+}
 
 /* do_syscall() should always have a single exit point at the end so
    that actions, such as logging of syscall results, can be performed.
@@ -5105,50 +5152,7 @@  abi_long do_syscall(void *cpu_env, int num, abi_long arg1,
 
     switch(num) {
     case TARGET_NR_exit:
-#ifdef CONFIG_USE_NPTL
-      /* In old applications this may be used to implement _exit(2).
-         However in threaded applictions it is used for thread termination,
-         and _exit_group is used for application termination.
-         Do thread termination if we have more then one thread.  */
-      /* FIXME: This probably breaks if a signal arrives.  We should probably
-         be disabling signals.  */
-      if (first_cpu->next_cpu) {
-          TaskState *ts;
-          CPUArchState **lastp;
-          CPUArchState *p;
-
-          cpu_list_lock();
-          lastp = &first_cpu;
-          p = first_cpu;
-          while (p && p != (CPUArchState *)cpu_env) {
-              lastp = &p->next_cpu;
-              p = p->next_cpu;
-          }
-          /* If we didn't find the CPU for this thread then something is
-             horribly wrong.  */
-          if (!p)
-              abort();
-          /* Remove the CPU from the list.  */
-          *lastp = p->next_cpu;
-          cpu_list_unlock();
-          ts = ((CPUArchState *)cpu_env)->opaque;
-          if (ts->child_tidptr) {
-              put_user_u32(0, ts->child_tidptr);
-              sys_futex(g2h(ts->child_tidptr), FUTEX_WAKE, INT_MAX,
-                        NULL, NULL, 0);
-          }
-          thread_env = NULL;
-          object_delete(OBJECT(ENV_GET_CPU(cpu_env)));
-          g_free(ts);
-          pthread_exit(NULL);
-      }
-#endif
-#ifdef TARGET_GPROF
-        _mcleanup();
-#endif
-        gdb_exit(cpu_env, arg1);
-        _exit(arg1);
-        ret = 0; /* avoid warning */
+        do_exit(cpu_env, arg1);
         break;
     case TARGET_NR_read:
         if (arg3 == 0)