Browse Source

[LibOS] Eliminate unnecessary nested functions

BEGIN_MIGRATION_DEF() is used to define nested functions unnecessarily.
Make them normal (non-nested) functions.
Isaku Yamahata 4 years ago
parent
commit
4182c29476

+ 4 - 4
LibOS/shim/include/shim_checkpoint.h

@@ -326,9 +326,9 @@ struct shim_cp_map_entry* get_cp_map_entry(void* map, void* addr, bool create);
         e->off                      = (off);                                      \
     } while (0)
 
-#define BEGIN_MIGRATION_DEF(name, ...)                               \
-    int migrate_##name(struct shim_cp_store* store, ##__VA_ARGS__) { \
-        int ret    = 0;                                              \
+#define BEGIN_MIGRATION_DEF(name, ...)                                  \
+    int migrate_cp_##name(struct shim_cp_store* store, ##__VA_ARGS__) { \
+        int ret    = 0;                                                 \
         ptr_t base = store->base;
 
 #define END_MIGRATION_DEF(name)     \
@@ -367,7 +367,7 @@ struct shim_cp_map_entry* get_cp_map_entry(void* map, void* addr, bool create);
             }                                                              \
             SAVE_PROFILE_INTERVAL(checkpoint_create_map);                  \
                                                                            \
-            ret = migrate_##name(store, ##__VA_ARGS__);                    \
+            ret = migrate_cp_##name(store, ##__VA_ARGS__);                 \
             if (ret < 0)                                                   \
                 goto out;                                                  \
                                                                            \

+ 11 - 17
LibOS/shim/src/sys/shim_exec.c

@@ -252,6 +252,17 @@ DEFINE_PROFILE_INTERVAL(search_and_check_file_for_exec, exec);
 DEFINE_PROFILE_INTERVAL(open_file_for_exec, exec);
 DEFINE_PROFILE_INTERVAL(close_CLOEXEC_files_for_exec, exec);
 
+static BEGIN_MIGRATION_DEF(execve, struct shim_thread* thread, struct shim_process* proc,
+                           const char** envp) {
+    DEFINE_MIGRATE(process, proc, sizeof(struct shim_process));
+    DEFINE_MIGRATE(all_mounts, NULL, 0);
+    DEFINE_MIGRATE(running_thread, thread, sizeof(struct shim_thread));
+    DEFINE_MIGRATE(handle_map, thread->handle_map, sizeof(struct shim_handle_map));
+    DEFINE_MIGRATE(migratable, NULL, 0);
+    DEFINE_MIGRATE(environ, envp, 0);
+}
+END_MIGRATION_DEF(execve)
+
 /* thread is cur_thread stripped off stack & tcb (see below func);
  * process is new process which is forked and waits for checkpoint. */
 static int migrate_execve(struct shim_cp_store* cpstore, struct shim_thread* thread,
@@ -272,23 +283,6 @@ static int migrate_execve(struct shim_cp_store* cpstore, struct shim_thread* thr
 
     SAVE_PROFILE_INTERVAL(close_CLOEXEC_files_for_exec);
 
-    /* Now we start to migrate bookkeeping for exec.
-       The data we need to migrate are:
-            1. cur_threadrent thread
-            2. cur_threadrent filesystem
-            3. handle mapping
-            4. each handle              */
-    BEGIN_MIGRATION_DEF(execve, struct shim_thread* thread, struct shim_process* proc,
-                        const char** envp) {
-        DEFINE_MIGRATE(process, proc, sizeof(struct shim_process));
-        DEFINE_MIGRATE(all_mounts, NULL, 0);
-        DEFINE_MIGRATE(running_thread, thread, sizeof(struct shim_thread));
-        DEFINE_MIGRATE(handle_map, thread->handle_map, sizeof(struct shim_handle_map));
-        DEFINE_MIGRATE(migratable, NULL, 0);
-        DEFINE_MIGRATE(environ, envp, 0);
-    }
-    END_MIGRATION_DEF(execve)
-
     return START_MIGRATE(cpstore, execve, thread, process, envp);
 }
 

+ 15 - 15
LibOS/shim/src/sys/shim_fork.c

@@ -35,24 +35,24 @@
 #include <shim_table.h>
 #include <shim_thread.h>
 
-int migrate_fork(struct shim_cp_store* store, struct shim_thread* thread,
-                 struct shim_process* process, va_list ap) {
-    __UNUSED(ap);
-    BEGIN_MIGRATION_DEF(fork, struct shim_thread* thread, struct shim_process* process) {
-        DEFINE_MIGRATE(process, process, sizeof(struct shim_process));
-        DEFINE_MIGRATE(all_mounts, NULL, 0);
-        DEFINE_MIGRATE(all_vmas, NULL, 0);
-        DEFINE_MIGRATE(running_thread, thread, sizeof(struct shim_thread));
-        DEFINE_MIGRATE(handle_map, thread->handle_map, sizeof(struct shim_handle_map));
-        DEFINE_MIGRATE(migratable, NULL, 0);
-        DEFINE_MIGRATE(brk, NULL, 0);
-        DEFINE_MIGRATE(loaded_libraries, NULL, 0);
+static BEGIN_MIGRATION_DEF(fork, struct shim_thread* thread, struct shim_process* process) {
+    DEFINE_MIGRATE(process, process, sizeof(struct shim_process));
+    DEFINE_MIGRATE(all_mounts, NULL, 0);
+    DEFINE_MIGRATE(all_vmas, NULL, 0);
+    DEFINE_MIGRATE(running_thread, thread, sizeof(struct shim_thread));
+    DEFINE_MIGRATE(handle_map, thread->handle_map, sizeof(struct shim_handle_map));
+    DEFINE_MIGRATE(migratable, NULL, 0);
+    DEFINE_MIGRATE(brk, NULL, 0);
+    DEFINE_MIGRATE(loaded_libraries, NULL, 0);
 #ifdef DEBUG
-        DEFINE_MIGRATE(gdb_map, NULL, 0);
+    DEFINE_MIGRATE(gdb_map, NULL, 0);
 #endif
-    }
-    END_MIGRATION_DEF(fork)
+}
+END_MIGRATION_DEF(fork)
 
+int migrate_fork(struct shim_cp_store* store, struct shim_thread* thread,
+                 struct shim_process* process, va_list ap) {
+    __UNUSED(ap);
     int ret = START_MIGRATE(store, fork, thread, process);
 
     thread->in_vm = false;

+ 14 - 14
LibOS/shim/src/sys/shim_migrate.c

@@ -220,26 +220,26 @@ static void* file_alloc(struct shim_cp_store* store, void* addr, size_t size) {
     return addr;
 }
 
+static BEGIN_MIGRATION_DEF(checkpoint) {
+    DEFINE_MIGRATE(process, &cur_process, sizeof(struct shim_process));
+    DEFINE_MIGRATE(all_mounts, NULL, 0);
+    DEFINE_MIGRATE(all_vmas, NULL, 0);
+    DEFINE_MIGRATE(all_running_threads, NULL, 0);
+    DEFINE_MIGRATE(brk, NULL, 0);
+    DEFINE_MIGRATE(loaded_libraries, NULL, 0);
+#ifdef DEBUG
+    DEFINE_MIGRATE(gdb_map, NULL, 0);
+#endif
+    DEFINE_MIGRATE(migratable, NULL, 0);
+}
+END_MIGRATION_DEF(checkpoint)
+
 static int finish_checkpoint(struct cp_session* cpsession) {
     struct shim_cp_store* cpstore = &cpsession->cpstore;
     int ret;
 
     cpstore->alloc = file_alloc;
 
-    BEGIN_MIGRATION_DEF(checkpoint) {
-        DEFINE_MIGRATE(process, &cur_process, sizeof(struct shim_process));
-        DEFINE_MIGRATE(all_mounts, NULL, 0);
-        DEFINE_MIGRATE(all_vmas, NULL, 0);
-        DEFINE_MIGRATE(all_running_threads, NULL, 0);
-        DEFINE_MIGRATE(brk, NULL, 0);
-        DEFINE_MIGRATE(loaded_libraries, NULL, 0);
-#ifdef DEBUG
-        DEFINE_MIGRATE(gdb_map, NULL, 0);
-#endif
-        DEFINE_MIGRATE(migratable, NULL, 0);
-    }
-    END_MIGRATION_DEF(checkpoint)
-
     if ((ret = START_MIGRATE(cpstore, checkpoint)) < 0)
         return ret;