Kaynağa Gözat

[LibOS] remove unnecessary __alloca()

remove abuse of __alloca() with normal variable on stack.
This patch cleans up abuse of __alloca().

Signed-off-by: Isaku Yamahata <isaku.yamahata@gmail.com>
Isaku Yamahata 5 yıl önce
ebeveyn
işleme
9aebe3c0f8

+ 1 - 1
LibOS/shim/src/fs/chroot/fs.c

@@ -168,7 +168,7 @@ static int make_uri (struct shim_dentry * dent)
     assert(mdata);
 
     struct shim_file_data * data = FILE_DENTRY_DATA(dent);
-    char * uri = __alloca(URI_MAX_SIZE);
+    char uri[URI_MAX_SIZE];
     int len = concat_uri(uri, URI_MAX_SIZE, data->type,
                          mdata->root_uri,
                          mdata->root_uri_len,

+ 28 - 29
LibOS/shim/src/shim_checkpoint.c

@@ -891,7 +891,6 @@ int do_migrate_process (int (*migrate) (struct shim_cp_store *,
     int ret = 0;
     struct shim_process * new_process = NULL;
     struct newproc_header hdr;
-    struct shim_cp_store * cpstore = NULL;
     int bytes;
     memset(&hdr, 0, sizeof(hdr));
 
@@ -953,27 +952,27 @@ int do_migrate_process (int (*migrate) (struct shim_cp_store *,
     SAVE_PROFILE_INTERVAL(migrate_connect_ipc);
 
     /* Allocate a space for dumping the checkpoint data. */
-    cpstore = __alloca(sizeof(struct shim_cp_store));
-    memset(cpstore, 0, sizeof(struct shim_cp_store));
-    cpstore->alloc    = cp_alloc;
-    cpstore->use_gipc = use_gipc;
-    cpstore->bound    = CP_INIT_VMA_SIZE;
+    struct shim_cp_store cpstore;
+    memset(&cpstore, 0, sizeof(cpstore));
+    cpstore.alloc    = cp_alloc;
+    cpstore.use_gipc = use_gipc;
+    cpstore.bound    = CP_INIT_VMA_SIZE;
 
     while (1) {
         /*
          * Try allocating a space of a certain size. If the allocation fails,
          * continue to try with smaller sizes.
          */
-        cpstore->base = (ptr_t) cp_alloc(cpstore, 0, cpstore->bound);
-        if (cpstore->base)
+        cpstore.base = (ptr_t) cp_alloc(&cpstore, 0, cpstore.bound);
+        if (cpstore.base)
             break;
 
-        cpstore->bound >>= 1;
-        if (cpstore->bound < allocsize)
+        cpstore.bound >>= 1;
+        if (cpstore.bound < allocsize)
             break;
     }
 
-    if (!cpstore->base) {
+    if (!cpstore.base) {
         ret = -ENOMEM;
         debug("failed creating checkpoint store\n");
         goto err;
@@ -984,7 +983,7 @@ int do_migrate_process (int (*migrate) (struct shim_cp_store *,
     /* Calling the migration function defined by the caller. */
     va_list ap;
     va_start(ap, thread);
-    ret = (*migrate) (cpstore, thread, new_process, ap);
+    ret = (*migrate) (&cpstore, thread, new_process, ap);
     va_end(ap);
     if (ret < 0) {
         debug("failed creating checkpoint (ret = %d)\n", ret);
@@ -994,36 +993,36 @@ int do_migrate_process (int (*migrate) (struct shim_cp_store *,
     SAVE_PROFILE_INTERVAL(migrate_save_checkpoint);
 
     unsigned long checkpoint_time = GET_PROFILE_INTERVAL();
-    unsigned long checkpoint_size = cpstore->offset + cpstore->mem_size;
+    unsigned long checkpoint_size = cpstore.offset + cpstore.mem_size;
 
     /* Checkpoint data created. */
     debug("checkpoint of %u bytes created, %lu microsecond is spent.\n",
           checkpoint_size, checkpoint_time);
 
-    hdr.checkpoint.hdr.addr = (void *) cpstore->base;
+    hdr.checkpoint.hdr.addr = (void *) cpstore.base;
     hdr.checkpoint.hdr.size = checkpoint_size;
 
-    if (cpstore->mem_nentries) {
+    if (cpstore.mem_nentries) {
         hdr.checkpoint.mem.entoffset =
-                    (ptr_t) cpstore->last_mem_entry - cpstore->base;
-        hdr.checkpoint.mem.nentries  = cpstore->mem_nentries;
+                    (ptr_t) cpstore.last_mem_entry - cpstore.base;
+        hdr.checkpoint.mem.nentries  = cpstore.mem_nentries;
     }
 
-    if (cpstore->use_gipc) {
+    if (cpstore.use_gipc) {
         snprintf(hdr.checkpoint.gipc.uri, sizeof(hdr.checkpoint.gipc.uri),
                  "gipc:%lld", gipc_key);
 
-        if (cpstore->gipc_nentries) {
+        if (cpstore.gipc_nentries) {
             hdr.checkpoint.gipc.entoffset =
-                        (ptr_t) cpstore->last_gipc_entry - cpstore->base;
-            hdr.checkpoint.gipc.nentries  = cpstore->gipc_nentries;
+                        (ptr_t) cpstore.last_gipc_entry - cpstore.base;
+            hdr.checkpoint.gipc.nentries  = cpstore.gipc_nentries;
         }
     }
 
-    if (cpstore->palhdl_nentries) {
+    if (cpstore.palhdl_nentries) {
         hdr.checkpoint.palhdl.entoffset =
-                    (ptr_t) cpstore->last_palhdl_entry - cpstore->base;
-        hdr.checkpoint.palhdl.nentries  = cpstore->palhdl_nentries;
+                    (ptr_t) cpstore.last_palhdl_entry - cpstore.base;
+        hdr.checkpoint.palhdl.nentries  = cpstore.palhdl_nentries;
     }
 
 #ifdef PROFILE
@@ -1050,8 +1049,8 @@ int do_migrate_process (int (*migrate) (struct shim_cp_store *,
     SAVE_PROFILE_INTERVAL(migrate_send_header);
 
     /* Sending the checkpoint either through GIPC or the RPC stream */
-    ret = cpstore->use_gipc ? send_checkpoint_by_gipc(gipc_hdl, cpstore) :
-          send_checkpoint_on_stream(proc, cpstore);
+    ret = cpstore.use_gipc ? send_checkpoint_by_gipc(gipc_hdl, &cpstore) :
+          send_checkpoint_on_stream(proc, &cpstore);
 
     if (ret < 0) {
         debug("failed sending checkpoint (ret = %d)\n", ret);
@@ -1064,19 +1063,19 @@ int do_migrate_process (int (*migrate) (struct shim_cp_store *,
      * For socket and RPC streams, we need to migrate the PAL handles
      * to the new process using PAL calls.
      */
-    if ((ret = send_handles_on_stream(proc, cpstore)) < 0)
+    if ((ret = send_handles_on_stream(proc, &cpstore)) < 0)
         goto err;
 
     SAVE_PROFILE_INTERVAL(migrate_send_pal_handles);
 
     /* Free the checkpoint space */
-    if ((ret = bkeep_munmap((void *) cpstore->base, cpstore->bound,
+    if ((ret = bkeep_munmap((void *) cpstore.base, cpstore.bound,
                             CP_VMA_FLAGS)) < 0) {
         debug("failed unmaping checkpoint (ret = %d)\n", ret);
         goto err;
     }
 
-    DkVirtualMemoryFree((PAL_PTR) cpstore->base, cpstore->bound);
+    DkVirtualMemoryFree((PAL_PTR) cpstore.base, cpstore.bound);
 
     SAVE_PROFILE_INTERVAL(migrate_free_checkpoint);
 

+ 21 - 21
LibOS/shim/src/sys/shim_clone.c

@@ -115,8 +115,8 @@ int clone_implementation_wrapper(struct clone_args * arg)
     debug_setbuf(tcb, true);
     debug("set tcb to %p (stack allocated? %d)\n", my_thread->tcb, stack_allocated);
 
-    struct shim_regs * regs = __alloca(sizeof(struct shim_regs));
-    *regs = *((__libc_tcb_t *) arg->parent->tcb)->shim_tcb.context.regs;
+    struct shim_regs regs;
+    regs = *((__libc_tcb_t *) arg->parent->tcb)->shim_tcb.context.regs;
 
     if (my_thread->set_child_tid)
         *(my_thread->set_child_tid) = my_thread->tid;
@@ -144,7 +144,7 @@ int clone_implementation_wrapper(struct clone_args * arg)
     debug("child swapping stack to %p return %p: %d\n",
           stack, return_pc, my_thread->tid);
 
-    tcb->context.regs = regs;
+    tcb->context.regs = &regs;
     tcb->context.sp = stack;
     tcb->context.ret_ip = return_pc;
 
@@ -293,25 +293,25 @@ int shim_do_clone (int flags, void * user_stack_addr, int * parent_tidptr,
 
     enable_locking();
 
-    struct clone_args * new_args = __alloca(sizeof(struct clone_args));
-    memset(new_args, 0, sizeof(struct clone_args));
+    struct clone_args new_args;
+    memset(&new_args, 0, sizeof(new_args));
 
-    new_args->create_event = DkNotificationEventCreate(PAL_FALSE);
-    if (!new_args->create_event) {
+    new_args.create_event = DkNotificationEventCreate(PAL_FALSE);
+    if (!new_args.create_event) {
         ret = -PAL_ERRNO;
         goto clone_thread_failed;
     }
 
-    new_args->initialize_event = DkNotificationEventCreate(PAL_FALSE);
-    if (!new_args->initialize_event) {
+    new_args.initialize_event = DkNotificationEventCreate(PAL_FALSE);
+    if (!new_args.initialize_event) {
         ret = -PAL_ERRNO;
         goto clone_thread_failed;
     }
 
-    new_args->thread    = thread;
-    new_args->parent    = self;
-    new_args->stack     = user_stack_addr;
-    new_args->return_pc = *(void **) user_stack_addr;
+    new_args.thread    = thread;
+    new_args.parent    = self;
+    new_args.stack     = user_stack_addr;
+    new_args.return_pc = *(void **) user_stack_addr;
 
     // Invoke DkThreadCreate to spawn off a child process using the actual 
     // "clone" system call. DkThreadCreate allocates a stack for the child 
@@ -320,7 +320,7 @@ int shim_do_clone (int flags, void * user_stack_addr, int * parent_tidptr,
     // returns .The parent comes back here - however, the child is Happily 
     // running the function we gave to DkThreadCreate.
     PAL_HANDLE pal_handle = thread_create(clone_implementation_wrapper,
-                                          new_args, flags);
+                                          &new_args, flags);
     if (!pal_handle) {
         ret = -PAL_ERRNO;
         goto clone_thread_failed;
@@ -332,17 +332,17 @@ int shim_do_clone (int flags, void * user_stack_addr, int * parent_tidptr,
     if (set_parent_tid)
         *set_parent_tid = tid;
 
-    DkEventSet(new_args->create_event);
-    DkObjectsWaitAny(1, &new_args->initialize_event, NO_TIMEOUT);
-    DkObjectClose(new_args->initialize_event);
+    DkEventSet(new_args.create_event);
+    DkObjectsWaitAny(1, &new_args.initialize_event, NO_TIMEOUT);
+    DkObjectClose(new_args.initialize_event);
     put_thread(thread);
     return tid;
 
 clone_thread_failed:
-    if (new_args->create_event)
-        DkObjectClose(new_args->create_event);
-    if (new_args->initialize_event)
-        DkObjectClose(new_args->initialize_event);
+    if (new_args.create_event)
+        DkObjectClose(new_args.create_event);
+    if (new_args.initialize_event)
+        DkObjectClose(new_args.initialize_event);
 failed:
     if (thread)
         put_thread(thread);

+ 1 - 1
LibOS/shim/src/sys/shim_pipe.c

@@ -41,7 +41,7 @@ int create_pipes (IDTYPE * pipeid, PAL_HANDLE * srv, PAL_HANDLE * cli,
 {
     PAL_HANDLE hdl0 = NULL, hdl1 = NULL, hdl2 = NULL;
     int ret = 0;
-    char * uri = __alloca(PIPE_URI_SIZE);
+    char uri[PIPE_URI_SIZE];
 
     if ((ret = create_pipe(pipeid, uri, PIPE_URI_SIZE, &hdl0,
                            qstr)) < 0) {