Explorar el Código

[LibOS] Convert locks from macros to functions

Michał Kowalczyk hace 6 años
padre
commit
ae733cacd7
Se han modificado 41 ficheros con 607 adiciones y 627 borrados
  1. 26 46
      LibOS/shim/include/shim_internal.h
  2. 39 39
      LibOS/shim/src/bookkeep/shim_handle.c
  3. 2 2
      LibOS/shim/src/bookkeep/shim_signal.c
  4. 38 38
      LibOS/shim/src/bookkeep/shim_thread.c
  5. 22 22
      LibOS/shim/src/bookkeep/shim_vma.c
  6. 2 2
      LibOS/shim/src/elf/shim_rtld.c
  7. 37 37
      LibOS/shim/src/fs/chroot/fs.c
  8. 2 2
      LibOS/shim/src/fs/pipe/fs.c
  9. 17 17
      LibOS/shim/src/fs/proc/ipc-thread.c
  10. 12 12
      LibOS/shim/src/fs/proc/thread.c
  11. 5 5
      LibOS/shim/src/fs/shim_dcache.c
  12. 14 14
      LibOS/shim/src/fs/shim_fs.c
  13. 10 10
      LibOS/shim/src/fs/shim_namei.c
  14. 14 14
      LibOS/shim/src/fs/socket/fs.c
  15. 24 24
      LibOS/shim/src/ipc/shim_ipc.c
  16. 4 4
      LibOS/shim/src/ipc/shim_ipc_child.c
  17. 38 38
      LibOS/shim/src/ipc/shim_ipc_helper.c
  18. 63 63
      LibOS/shim/src/ipc/shim_ipc_nsimpl.h
  19. 13 13
      LibOS/shim/src/ipc/shim_ipc_pid.c
  20. 4 4
      LibOS/shim/src/ipc/shim_ipc_sysv.c
  21. 17 17
      LibOS/shim/src/shim_async.c
  22. 1 1
      LibOS/shim/src/shim_init.c
  23. 3 3
      LibOS/shim/src/shim_malloc.c
  24. 2 2
      LibOS/shim/src/sys/shim_clone.c
  25. 15 15
      LibOS/shim/src/sys/shim_epoll.c
  26. 5 5
      LibOS/shim/src/sys/shim_exec.c
  27. 5 5
      LibOS/shim/src/sys/shim_exit.c
  28. 6 6
      LibOS/shim/src/sys/shim_fcntl.c
  29. 2 2
      LibOS/shim/src/sys/shim_fork.c
  30. 4 4
      LibOS/shim/src/sys/shim_fs.c
  31. 20 20
      LibOS/shim/src/sys/shim_futex.c
  32. 4 4
      LibOS/shim/src/sys/shim_getcwd.c
  33. 31 31
      LibOS/shim/src/sys/shim_msgget.c
  34. 4 4
      LibOS/shim/src/sys/shim_open.c
  35. 3 3
      LibOS/shim/src/sys/shim_poll.c
  36. 22 22
      LibOS/shim/src/sys/shim_semget.c
  37. 31 31
      LibOS/shim/src/sys/shim_sigaction.c
  38. 30 30
      LibOS/shim/src/sys/shim_socket.c
  39. 2 2
      LibOS/shim/src/sys/shim_vfork.c
  40. 11 11
      LibOS/shim/src/sys/shim_wait.c
  41. 3 3
      LibOS/shim/src/utils/strobjs.c

+ 26 - 46
LibOS/shim/include/shim_internal.h

@@ -473,54 +473,37 @@ static inline void enable_preempt (shim_tcb_t * tcb)
     __enable_preempt(tcb);
 }
 
-#define DEBUG_LOCK      0
+#define DEBUG_LOCK 0
 
-static inline bool __lock_created(struct shim_lock* l)
+static inline bool lock_created(struct shim_lock* l)
 {
     return l->lock != NULL;
 }
 
-#define lock_created(l)  __lock_created(&(l))
-
-static inline void __clear_lock(struct shim_lock* l)
+static inline void clear_lock(struct shim_lock* l)
 {
     l->lock = NULL;
     l->owner = 0;
 }
 
-#define clear_lock(l)  __clear_lock(&(l))
-
-static inline void __create_lock(struct shim_lock* l)
+static inline void create_lock(struct shim_lock* l)
 {
     l->lock = DkMutexCreate(0);
     /* l->owner = LOCK_FREE; */
     /* l->reowned = 0; */
 }
 
-#define create_lock(l)  __create_lock(&(l))
-
-static inline void __destroy_lock(struct shim_lock* l)
+static inline void destroy_lock(struct shim_lock* l)
 {
     DkObjectClose(l->lock);
 }
 
-#define destroy_lock(l) __destroy_lock(&(l))
-
-static inline void ____try_create_lock(struct shim_lock* l)
-{
-    if (!__lock_created(l))
-        __create_lock(l);
-}
-
-#define try_create_lock(l)  ____try_create_lock(&(l))
-
 #if DEBUG_LOCK == 1
-# define lock(l) __lock(&(l), #l, __FILE__, __LINE__)
-static inline void __lock (struct shim_lock* l,
-                           const char * name, const char * file, int line)
+#define lock(l) __lock(l, #l, __FILE__, __LINE__)
+static void __lock(struct shim_lock* l,
+                   const char* name, const char* file, int line)
 #else
-# define lock(l) __lock(&(l))
-static inline void __lock (struct shim_lock* l)
+static void lock(struct shim_lock* l)
 #endif
 {
     if (!lock_enabled || !l->lock)
@@ -541,18 +524,17 @@ static inline void __lock (struct shim_lock* l)
 }
 
 #if DEBUG_LOCK == 1
-# define unlock(l) __unlock(&(l), #l, __FILE__, __LINE__)
-static inline void __unlock (struct shim_lock* l,
-                             const char * name, const char * file, int line)
+#define unlock(l) __unlock(l, #l, __FILE__, __LINE__)
+static inline void __unlock(struct shim_lock* l,
+                            const char* name, const char* file, int line)
 #else
-# define unlock(l) __unlock(&(l))
-static inline void __unlock (struct shim_lock* l)
+static inline void unlock(struct shim_lock* l)
 #endif
 {
     if (!lock_enabled || !l->lock)
         return;
 
-    shim_tcb_t * tcb = shim_get_tls();
+    shim_tcb_t* tcb = shim_get_tls();
 
 #if DEBUG_LOCK == 1
     debug("unlock(%s=%p) %s:%d\n", name, l, file, line);
@@ -563,17 +545,15 @@ static inline void __unlock (struct shim_lock* l)
     enable_preempt(tcb);
 }
 
-static inline bool __locked (struct shim_lock* l)
+static inline bool locked(struct shim_lock* l)
 {
     if (!lock_enabled || !l->lock)
         return false;
 
-    shim_tcb_t * tcb = shim_get_tls();
+    shim_tcb_t* tcb = shim_get_tls();
     return tcb->tid == l->owner;
 }
 
-#define locked(l) __locked(&(l))
-
 #define DEBUG_MASTER_LOCK       0
 
 extern struct shim_lock __master_lock;
@@ -581,25 +561,25 @@ extern struct shim_lock __master_lock;
 #if DEBUG_MASTER_LOCK == 1
 # define master_lock()                                              \
     do {                                                            \
-        lock(__master_lock);                                        \
-        pal_printf("master lock " __FILE__ ":%d\n", __LINE__);       \
+        lock(&__master_lock);                                       \
+        pal_printf("master lock " __FILE__ ":%d\n", __LINE__);      \
     } while (0)
 # define master_unlock()                                            \
     do {                                                            \
-        pal_printf("master unlock " __FILE__ ":%d\n", __LINE__);     \
-        unlock(__master_lock);                                      \
+        pal_printf("master unlock " __FILE__ ":%d\n", __LINE__);    \
+        unlock(&__master_lock);                                     \
     } while (0)
 #else
-# define master_lock() do { lock(__master_lock); } while (0)
-# define master_unlock() do { unlock(__master_lock); } while (0)
+# define master_lock() do { lock(&__master_lock); } while (0)
+# define master_unlock() do { unlock(&__master_lock); } while (0)
 #endif
 
-static inline void create_lock_runtime (struct shim_lock* l)
+static inline void create_lock_runtime(struct shim_lock* l)
 {
-    if (!lock_created(*l)) {
+    if (!lock_created(l)) {
         master_lock();
-        if (!lock_created(*l))
-            create_lock(*l);
+        if (!lock_created(l))
+            create_lock(l);
         master_unlock();
     }
 }

+ 39 - 39
LibOS/shim/src/bookkeep/shim_handle.c

@@ -36,8 +36,8 @@ static struct shim_lock handle_mgr_lock;
 
 #define HANDLE_MGR_ALLOC        32
 
-#define system_lock()   lock(handle_mgr_lock)
-#define system_unlock() unlock(handle_mgr_lock)
+#define system_lock()   lock(&handle_mgr_lock)
+#define system_unlock() unlock(&handle_mgr_lock)
 #define PAGE_SIZE       allocsize
 
 #define OBJ_TYPE struct shim_handle
@@ -111,9 +111,9 @@ static inline int init_exec_handle (struct shim_thread * thread)
         set_handle_fs(exec, &chroot_builtin_fs);
     }
 
-    lock(thread->lock);
+    lock(&thread->lock);
     thread->exec = exec;
-    unlock(thread->lock);
+    unlock(&thread->lock);
 
     return 0;
 }
@@ -130,7 +130,7 @@ static struct shim_handle_map * __enlarge_handle_map
 
 int init_handle (void)
 {
-    create_lock(handle_mgr_lock);
+    create_lock(&handle_mgr_lock);
     handle_mgr = create_mem_mgr(init_align_up(HANDLE_MGR_ALLOC));
     if (!handle_mgr)
         return -ENOMEM;
@@ -154,11 +154,11 @@ int init_important_handles (void)
         set_handle_map(thread, handle_map);
     }
 
-    lock(handle_map->lock);
+    lock(&handle_map->lock);
 
     if (handle_map->fd_size < 3) {
         if (!__enlarge_handle_map(handle_map, INIT_HANDLE_MAP_SIZE)) {
-            unlock(handle_map->lock);
+            unlock(&handle_map->lock);
             return -ENOMEM;
         }
     }
@@ -193,7 +193,7 @@ int init_important_handles (void)
     if (handle_map->fd_top == FD_NULL || handle_map->fd_top < 2)
         handle_map->fd_top = 2;
 
-    unlock(handle_map->lock);
+    unlock(&handle_map->lock);
 
 done:
     init_exec_handle(thread);
@@ -226,10 +226,10 @@ struct shim_handle * get_fd_handle (FDTYPE fd, int * flags,
         map = get_cur_handle_map(NULL);
 
     struct shim_handle * hdl = NULL;
-    lock(map->lock);
+    lock(&map->lock);
     if ((hdl = __get_fd_handle(fd, flags, map)))
         get_handle(hdl);
-    unlock(map->lock);
+    unlock(&map->lock);
     return hdl;
 }
 
@@ -268,13 +268,13 @@ struct shim_handle * detach_fd_handle (FDTYPE fd, int * flags,
     if (!handle_map && !(handle_map = get_cur_handle_map(NULL)))
         return NULL;
 
-    lock(handle_map->lock);
+    lock(&handle_map->lock);
 
     if (fd < handle_map->fd_size)
         handle = __detach_fd_handle(handle_map->map[fd], flags,
                                     handle_map);
 
-    unlock(handle_map->lock);
+    unlock(&handle_map->lock);
     return handle;
 }
 
@@ -288,7 +288,7 @@ struct shim_handle * get_new_handle (void)
 
     memset(new_handle, 0, sizeof(struct shim_handle));
     REF_SET(new_handle->ref_count, 1);
-    create_lock(new_handle->lock);
+    create_lock(&new_handle->lock);
     new_handle->owner = cur_process.vmid;
     INIT_LISTP(&new_handle->epolls);
     return new_handle;
@@ -323,7 +323,7 @@ int set_new_fd_handle (struct shim_handle * hdl, int flags,
     if (!handle_map && !(handle_map = get_cur_handle_map(NULL)))
         return -EBADF;
 
-    lock(handle_map->lock);
+    lock(&handle_map->lock);
 
     if (!handle_map->map ||
         handle_map->fd_size < INIT_HANDLE_MAP_SIZE)
@@ -359,7 +359,7 @@ extend:
     } else
         ret = fd;
 out:
-    unlock(handle_map->lock);
+    unlock(&handle_map->lock);
     return ret;
 }
 
@@ -372,7 +372,7 @@ int set_new_fd_handle_by_fd (FDTYPE fd, struct shim_handle * hdl, int flags,
     if (!handle_map && !(handle_map = get_cur_handle_map(NULL)))
         return -EBADF;
 
-    lock(handle_map->lock);
+    lock(&handle_map->lock);
 
     if (!handle_map->map ||
         handle_map->fd_size < INIT_HANDLE_MAP_SIZE)
@@ -423,7 +423,7 @@ extend:
     } else
         ret = fd;
 out:
-    unlock(handle_map->lock);
+    unlock(&handle_map->lock);
     return ret;
 }
 
@@ -518,7 +518,7 @@ void get_handle (struct shim_handle * hdl)
 
 static void destroy_handle (struct shim_handle * hdl)
 {
-    destroy_lock(hdl->lock);
+    destroy_lock(&hdl->lock);
 
     if (memory_migrated(hdl))
         memset(hdl, 0, sizeof(struct shim_handle));
@@ -586,7 +586,7 @@ void dup_fd_handle (struct shim_handle_map * map,
 {
     struct shim_handle * replaced = NULL;
 
-    lock(map->lock);
+    lock(&map->lock);
 
     if (old->vfd != FD_NULL) {
         open_handle(old->handle);
@@ -594,7 +594,7 @@ void dup_fd_handle (struct shim_handle_map * map,
         new->handle = old->handle;
     }
 
-    unlock(map->lock);
+    unlock(&map->lock);
 
     if (replaced)
         close_handle(replaced);
@@ -617,7 +617,7 @@ static struct shim_handle_map * get_new_handle_map (FDTYPE size)
 
     handle_map->fd_top  = FD_NULL;
     handle_map->fd_size = size;
-    create_lock(handle_map->lock);
+    create_lock(&handle_map->lock);
 
     return handle_map;
 }
@@ -645,7 +645,7 @@ static struct shim_handle_map * __enlarge_handle_map
 int dup_handle_map (struct shim_handle_map ** new,
                     struct shim_handle_map * old_map)
 {
-    lock(old_map->lock);
+    lock(&old_map->lock);
 
     /* allocate a new handle mapping with the same size as
        the old one */
@@ -677,7 +677,7 @@ int dup_handle_map (struct shim_handle_map ** new,
                     close_handle(new_map->map[j]->handle);
                     free(new_map->map[j]);
                 }
-                unlock(old_map->lock);
+                unlock(&old_map->lock);
                 *new = NULL;
                 free(new_map);
                 return -ENOMEM;
@@ -692,7 +692,7 @@ int dup_handle_map (struct shim_handle_map ** new,
     }
 
 done:
-    unlock(old_map->lock);
+    unlock(&old_map->lock);
     *new = new_map;
     return 0;
 }
@@ -725,7 +725,7 @@ void put_handle_map (struct shim_handle_map * map)
         }
 
 done:
-        destroy_lock(map->lock);
+        destroy_lock(&map->lock);
         free(map->map);
         free(map);
     }
@@ -734,7 +734,7 @@ done:
 int flush_handle_map (struct shim_handle_map * map)
 {
     get_handle_map(map);
-    lock(map->lock);
+    lock(&map->lock);
 
     if (map->fd_top == FD_NULL)
         goto done;
@@ -751,7 +751,7 @@ int flush_handle_map (struct shim_handle_map * map)
     }
 
 done:
-    unlock(map->lock);
+    unlock(&map->lock);
     put_handle_map(map);
     return 0;
 }
@@ -761,7 +761,7 @@ int walk_handle_map (int (*callback) (struct shim_fd_handle *,
                      struct shim_handle_map * map, void * arg)
 {
     int ret = 0;
-    lock(map->lock);
+    lock(&map->lock);
 
     if (map->fd_top == FD_NULL)
         goto done;
@@ -775,7 +775,7 @@ int walk_handle_map (int (*callback) (struct shim_fd_handle *,
     }
 
 done:
-    unlock(map->lock);
+    unlock(&map->lock);
     return ret;
 }
 
@@ -793,7 +793,7 @@ BEGIN_CP_FUNC(handle)
         ADD_TO_CP_MAP(obj, off);
         new_hdl = (struct shim_handle *) (base + off);
 
-        lock(hdl->lock);
+        lock(&hdl->lock);
         struct shim_mount * fs = hdl->fs;
         *new_hdl = *hdl;
 
@@ -803,7 +803,7 @@ BEGIN_CP_FUNC(handle)
         new_hdl->dentry = NULL;
         REF_SET(new_hdl->opened, 0);
         REF_SET(new_hdl->ref_count, 0);
-        clear_lock(new_hdl->lock);
+        clear_lock(&new_hdl->lock);
 
         DO_CP_IN_MEMBER(qstr, new_hdl, path);
         DO_CP_IN_MEMBER(qstr, new_hdl, uri);
@@ -829,7 +829,7 @@ BEGIN_CP_FUNC(handle)
 
         INIT_LISTP(&new_hdl->epolls);
 
-        unlock(hdl->lock);
+        unlock(&hdl->lock);
         ADD_CP_FUNC_ENTRY(off);
     } else {
         new_hdl = (struct shim_handle *) (base + off);
@@ -849,7 +849,7 @@ BEGIN_RS_FUNC(handle)
     CP_REBASE(hdl->dentry);
     CP_REBASE(hdl->epolls);
 
-    create_lock(hdl->lock);
+    create_lock(&hdl->lock);
 
     if (!hdl->fs) {
         assert(hdl->fs_type);
@@ -894,7 +894,7 @@ BEGIN_CP_FUNC(handle_map)
     struct shim_handle_map * new_handle_map = NULL;
     struct shim_fd_handle ** ptr_array;
 
-    lock(handle_map->lock);
+    lock(&handle_map->lock);
 
     int fd_size = handle_map->fd_top != FD_NULL ?
                   handle_map->fd_top + 1 : 0;
@@ -917,7 +917,7 @@ BEGIN_CP_FUNC(handle_map)
         new_handle_map->map = fd_size ? ptr_array : NULL;
 
         REF_SET(new_handle_map->ref_count, 0);
-        clear_lock(new_handle_map->lock);
+        clear_lock(&new_handle_map->lock);
 
         for (int i = 0 ; i < fd_size ; i++) {
             if (HANDLE_ALLOCATED(handle_map->map[i]))
@@ -931,7 +931,7 @@ BEGIN_CP_FUNC(handle_map)
         new_handle_map = (struct shim_handle_map *) (base + off);
     }
 
-    unlock(handle_map->lock);
+    unlock(&handle_map->lock);
 
     if (objp)
         *objp = (void *) new_handle_map;
@@ -947,8 +947,8 @@ BEGIN_RS_FUNC(handle_map)
 
     DEBUG_RS("size=%d,top=%d", handle_map->fd_size, handle_map->fd_top);
 
-    create_lock(handle_map->lock);
-    lock(handle_map->lock);
+    create_lock(&handle_map->lock);
+    lock(&handle_map->lock);
 
     if (handle_map->fd_top != FD_NULL)
         for (int i = 0 ; i <= handle_map->fd_top ; i++) {
@@ -963,6 +963,6 @@ BEGIN_RS_FUNC(handle_map)
             }
         }
 
-    unlock(handle_map->lock);
+    unlock(&handle_map->lock);
 }
 END_RS_FUNC(handle_map)

+ 2 - 2
LibOS/shim/src/bookkeep/shim_signal.c

@@ -610,7 +610,7 @@ __handle_one_signal (shim_tcb_t * tcb, int sig, struct shim_signal * signal)
 
     debug("%s handled\n", signal_name(sig));
 
-    lock(thread->lock);
+    lock(&thread->lock);
 
     if (sighdl->action) {
         struct __kernel_sigaction * act = sighdl->action;
@@ -630,7 +630,7 @@ __handle_one_signal (shim_tcb_t * tcb, int sig, struct shim_signal * signal)
         }
     }
 
-    unlock(thread->lock);
+    unlock(&thread->lock);
 
     if ((void *) handler == (void *) 1) /* SIG_IGN */
         return;

+ 38 - 38
LibOS/shim/src/bookkeep/shim_thread.c

@@ -49,7 +49,7 @@ PAL_HANDLE thread_start_event = NULL;
 
 int init_thread (void)
 {
-    create_lock(thread_list_lock);
+    create_lock(&thread_list_lock);
 
     struct shim_thread * cur_thread = get_cur_thread();
     if (cur_thread)
@@ -69,12 +69,12 @@ void dump_threads (void)
 {
     struct shim_thread * tmp;
 
-    lock(thread_list_lock);
+    lock(&thread_list_lock);
     listp_for_each_entry(tmp, &thread_list, list) {
         debug("thread %d, vmid = %d, pgid = %d, ppid = %d, tgid = %d, in_vm = %d\n",
                 tmp->tid, tmp->vmid, tmp->pgid, tmp->ppid, tmp->tgid, tmp->in_vm);
     }
-    unlock(thread_list_lock);
+    unlock(&thread_list_lock);
 }
 
 struct shim_thread * __lookup_thread (IDTYPE tid)
@@ -93,9 +93,9 @@ struct shim_thread * __lookup_thread (IDTYPE tid)
 
 struct shim_thread * lookup_thread (IDTYPE tid)
 {
-    lock(thread_list_lock);
+    lock(&thread_list_lock);
     struct shim_thread * thread = __lookup_thread(tid);
-    unlock(thread_list_lock);
+    unlock(&thread_list_lock);
     return thread;
 }
 
@@ -144,10 +144,10 @@ IDTYPE get_pid (void)
 
 static IDTYPE get_internal_pid (void)
 {
-    lock(thread_list_lock);
+    lock(&thread_list_lock);
     internal_tid_alloc_idx++;
     IDTYPE idx = internal_tid_alloc_idx;
-    unlock(thread_list_lock);
+    unlock(&thread_list_lock);
     assert(is_internal_tid(idx));
     return idx;
 }
@@ -237,7 +237,7 @@ struct shim_thread * get_new_thread (IDTYPE new_tid)
     thread->signal_logs = malloc(sizeof(struct shim_signal_log) *
                                  NUM_SIGS);
     thread->vmid = cur_process.vmid;
-    create_lock(thread->lock);
+    create_lock(&thread->lock);
     thread->scheduler_event = DkNotificationEventCreate(PAL_TRUE);
     thread->exit_event = DkNotificationEventCreate(PAL_FALSE);
     thread->child_exit_event = DkNotificationEventCreate(PAL_FALSE);
@@ -256,7 +256,7 @@ struct shim_thread * get_new_internal_thread (void)
     thread->vmid  = cur_process.vmid;
     thread->tid   = new_tid;
     thread->in_vm = thread->is_alive = true;
-    create_lock(thread->lock);
+    create_lock(&thread->lock);
     thread->exit_event = DkNotificationEventCreate(PAL_FALSE);
     return thread;
 }
@@ -277,9 +277,9 @@ struct shim_simple_thread * __lookup_simple_thread (IDTYPE tid)
 
 struct shim_simple_thread * lookup_simple_thread (IDTYPE tid)
 {
-    lock(thread_list_lock);
+    lock(&thread_list_lock);
     struct shim_simple_thread * thread = __lookup_simple_thread(tid);
-    unlock(thread_list_lock);
+    unlock(&thread_list_lock);
     return thread;
 }
 
@@ -295,7 +295,7 @@ struct shim_simple_thread * get_new_simple_thread (void)
 
     INIT_LIST_HEAD(thread, list);
 
-    create_lock(thread->lock);
+    create_lock(&thread->lock);
     thread->exit_event = DkNotificationEventCreate(PAL_FALSE);
 
     return thread;
@@ -339,7 +339,7 @@ void put_thread (struct shim_thread * thread)
             DkObjectClose(thread->exit_event);
         if (thread->child_exit_event)
             DkObjectClose(thread->child_exit_event);
-        destroy_lock(thread->lock);
+        destroy_lock(&thread->lock);
 
         free(thread->signal_logs);
         free(thread);
@@ -360,7 +360,7 @@ void put_simple_thread (struct shim_simple_thread * thread)
         listp_del(thread, &simple_thread_list, list);
         if (thread->exit_event)
             DkObjectClose(thread->exit_event);
-        destroy_lock(thread->lock);
+        destroy_lock(&thread->lock);
         free(thread);
     }
 }
@@ -374,15 +374,15 @@ void set_as_child (struct shim_thread * parent,
     get_thread(parent);
     get_thread(child);
 
-    lock(child->lock);
+    lock(&child->lock);
     child->ppid = parent->tid;
     child->parent = parent;
 
-    lock(parent->lock);
+    lock(&parent->lock);
     listp_add_tail(child, &parent->children, siblings);
-    unlock(parent->lock);
+    unlock(&parent->lock);
 
-    unlock(child->lock);
+    unlock(&child->lock);
 }
 
 void add_thread (struct shim_thread * thread)
@@ -391,12 +391,12 @@ void add_thread (struct shim_thread * thread)
         return;
 
     struct shim_thread * tmp, * prev = NULL;
-    lock(thread_list_lock);
+    lock(&thread_list_lock);
 
     /* keep it sorted */
     listp_for_each_entry_reverse(tmp, &thread_list, list) {
         if (tmp->tid == thread->tid) {
-            unlock(thread_list_lock);
+            unlock(&thread_list_lock);
             return;
         }
         if (tmp->tid < thread->tid) {
@@ -407,7 +407,7 @@ void add_thread (struct shim_thread * thread)
 
     get_thread(thread);
     listp_add_after(thread, prev, &thread_list, list);
-    unlock(thread_list_lock);
+    unlock(&thread_list_lock);
 }
 
 void del_thread (struct shim_thread * thread)
@@ -420,10 +420,10 @@ void del_thread (struct shim_thread * thread)
         return;
     }
 
-    lock(thread_list_lock);
+    lock(&thread_list_lock);
     /* thread->list goes on the thread_list */
     listp_del_init(thread, &thread_list, list);
-    unlock(thread_list_lock);
+    unlock(&thread_list_lock);
     put_thread(thread);
 }
 
@@ -433,12 +433,12 @@ void add_simple_thread (struct shim_simple_thread * thread)
         return;
 
     struct shim_simple_thread * tmp, * prev = NULL;
-    lock(thread_list_lock);
+    lock(&thread_list_lock);
 
     /* keep it sorted */
     listp_for_each_entry_reverse(tmp, &simple_thread_list, list) {
         if (tmp->tid == thread->tid) {
-            unlock(thread_list_lock);
+            unlock(&thread_list_lock);
             return;
         }
         if (tmp->tid < thread->tid) {
@@ -449,7 +449,7 @@ void add_simple_thread (struct shim_simple_thread * thread)
 
     get_simple_thread(thread);
     listp_add_after(thread, prev, &simple_thread_list, list);
-    unlock(thread_list_lock);
+    unlock(&thread_list_lock);
 }
 
 void del_simple_thread (struct shim_simple_thread * thread)
@@ -457,9 +457,9 @@ void del_simple_thread (struct shim_simple_thread * thread)
     if (list_empty(thread, list))
         return;
 
-    lock(thread_list_lock);
+    lock(&thread_list_lock);
     listp_del_init(thread, &simple_thread_list, list);
-    unlock(thread_list_lock);
+    unlock(&thread_list_lock);
     put_simple_thread(thread);
 }
 
@@ -467,7 +467,7 @@ int check_last_thread (struct shim_thread * self)
 {
     struct shim_thread * tmp;
 
-    lock(thread_list_lock);
+    lock(&thread_list_lock);
     /* find out if there is any thread that is
        1) no current thread 2) in current vm
        3) still alive */
@@ -475,13 +475,13 @@ int check_last_thread (struct shim_thread * self)
         if (tmp->tid &&
             (!self || tmp->tid != self->tid) && tmp->in_vm && tmp->is_alive) {
             debug("check_last_thread: thread %d is alive\n", tmp->tid);
-            unlock(thread_list_lock);
+            unlock(&thread_list_lock);
             return tmp->tid;
         }
     }
 
     debug("this is the only thread %d\n", self->tid);
-    unlock(thread_list_lock);
+    unlock(&thread_list_lock);
     return 0;
 }
 
@@ -494,7 +494,7 @@ int walk_thread_list (int (*callback) (struct shim_thread *, void *, bool *),
     IDTYPE min_tid = 0;
 
 relock:
-    lock(thread_list_lock);
+    lock(&thread_list_lock);
 
     debug("walk_thread_list(callback=%p)\n", callback);
 
@@ -520,7 +520,7 @@ relock:
 
     ret = srched ? 0 : -ESRCH;
 out_locked:
-    unlock(thread_list_lock);
+    unlock(&thread_list_lock);
 out:
     return ret;
 }
@@ -535,7 +535,7 @@ int walk_simple_thread_list (int (*callback) (struct shim_simple_thread *,
     IDTYPE min_tid = 0;
 
 relock:
-    lock(thread_list_lock);
+    lock(&thread_list_lock);
 
     listp_for_each_entry_safe(tmp, n, &simple_thread_list, list) {
         if (tmp->tid <= min_tid)
@@ -558,7 +558,7 @@ relock:
 
     ret = srched ? 0 : -ESRCH;
 out_locked:
-    unlock(thread_list_lock);
+    unlock(&thread_list_lock);
 out:
     return ret;
 }
@@ -664,7 +664,7 @@ BEGIN_RS_FUNC(thread)
     CP_REBASE(thread->cwd);
     CP_REBASE(thread->signal_handles);
 
-    create_lock(thread->lock);
+    create_lock(&thread->lock);
     thread->scheduler_event = DkNotificationEventCreate(PAL_TRUE);
     thread->exit_event = DkNotificationEventCreate(PAL_FALSE);
     thread->child_exit_event = DkNotificationEventCreate(PAL_FALSE);
@@ -790,7 +790,7 @@ END_RS_FUNC(running_thread)
 BEGIN_CP_FUNC(all_running_threads)
 {
     struct shim_thread * thread;
-    lock(thread_list_lock);
+    lock(&thread_list_lock);
 
     listp_for_each_entry(thread, &thread_list, list) {
         if (!thread->in_vm || !thread->is_alive)
@@ -800,6 +800,6 @@ BEGIN_CP_FUNC(all_running_threads)
         DO_CP(handle_map, thread->handle_map, NULL);
     }
 
-    unlock(thread_list_lock);
+    unlock(&thread_list_lock);
 }
 END_CP_FUNC_NO_RS(all_running_threads)

+ 22 - 22
LibOS/shim/src/bookkeep/shim_vma.c

@@ -334,7 +334,7 @@ int init_vma (void)
         assert(reserved_vmas[i]);
     }
 
-    create_lock(vma_list_lock);
+    create_lock(&vma_list_lock);
 
     current_heap_top = PAL_CB(user_address.end);
 
@@ -499,14 +499,14 @@ int bkeep_mmap (void * addr, uint64_t length, int prot, int flags,
 
     debug("bkeep_mmap: %p-%p\n", addr, addr + length);
 
-    lock(vma_list_lock);
+    lock(&vma_list_lock);
     struct shim_vma * prev = NULL;
     __lookup_vma(addr, &prev);
     int ret = __bkeep_mmap(prev, addr, addr + length, prot, flags, file, offset,
                            comment);
     assert_vma_list();
     __restore_reserved_vmas();
-    unlock(vma_list_lock);
+    unlock(&vma_list_lock);
     return ret;
 }
 
@@ -680,13 +680,13 @@ int bkeep_munmap (void * addr, uint64_t length, int flags)
 
     debug("bkeep_munmap: %p-%p\n", addr, addr + length);
 
-    lock(vma_list_lock);
+    lock(&vma_list_lock);
     struct shim_vma * prev = NULL;
     __lookup_vma(addr, &prev);
     int ret = __bkeep_munmap(&prev, addr, addr + length, flags);
     assert_vma_list();
     __restore_reserved_vmas();
-    unlock(vma_list_lock);
+    unlock(&vma_list_lock);
     return ret;
 }
 
@@ -791,13 +791,13 @@ int bkeep_mprotect (void * addr, uint64_t length, int prot, int flags)
 
     debug("bkeep_mprotect: %p-%p\n", addr, addr + length);
 
-    lock(vma_list_lock);
+    lock(&vma_list_lock);
     struct shim_vma * prev = NULL;
     __lookup_vma(addr, &prev);
     int ret = __bkeep_mprotect(prev, addr, addr + length, prot, flags);
     assert_vma_list();
     __restore_reserved_vmas();
-    unlock(vma_list_lock);
+    unlock(&vma_list_lock);
     return ret;
 }
 
@@ -855,12 +855,12 @@ void * bkeep_unmapped (void * top_addr, void * bottom_addr, uint64_t length,
                        int prot, int flags, struct shim_handle * file,
                        uint64_t offset, const char * comment)
 {
-    lock(vma_list_lock);
+    lock(&vma_list_lock);
     void * addr = __bkeep_unmapped(top_addr, bottom_addr, length, prot, flags,
                                    file, offset, comment);
     assert_vma_list();
     __restore_reserved_vmas();
-    unlock(vma_list_lock);
+    unlock(&vma_list_lock);
     return addr;
 }
 
@@ -868,7 +868,7 @@ void * bkeep_unmapped_heap (uint64_t length, int prot, int flags,
                             struct shim_handle * file,
                             uint64_t offset, const char * comment)
 {
-    lock(vma_list_lock);
+    lock(&vma_list_lock);
 
     void * bottom_addr = PAL_CB(user_address.start);
     void * top_addr = current_heap_top;
@@ -925,7 +925,7 @@ again:
 
 out:
     __restore_reserved_vmas();
-    unlock(vma_list_lock);
+    unlock(&vma_list_lock);
 #ifdef MAP_32BIT
     assert(!(flags & MAP_32BIT) || !addr || addr + length <= ADDR_32BIT);
 #endif
@@ -948,18 +948,18 @@ __dump_vma (struct shim_vma_val * val, const struct shim_vma * vma)
 
 int lookup_vma (void * addr, struct shim_vma_val * res)
 {
-    lock(vma_list_lock);
+    lock(&vma_list_lock);
 
     struct shim_vma * vma = __lookup_vma(addr, NULL);
     if (!vma) {
-        unlock(vma_list_lock);
+        unlock(&vma_list_lock);
         return -ENOENT;
     }
 
     if (res)
         __dump_vma(res, vma);
 
-    unlock(vma_list_lock);
+    unlock(&vma_list_lock);
     return 0;
 }
 
@@ -968,7 +968,7 @@ int lookup_overlap_vma (void * addr, uint64_t length,
 {
     struct shim_vma * tmp, * vma = NULL;
 
-    lock(vma_list_lock);
+    lock(&vma_list_lock);
 
     listp_for_each_entry(tmp, &vma_list, list)
         if (test_vma_overlap (tmp, addr, addr + length)) {
@@ -978,14 +978,14 @@ int lookup_overlap_vma (void * addr, uint64_t length,
 
 
     if (!vma) {
-        unlock(vma_list_lock);
+        unlock(&vma_list_lock);
         return -ENOENT;
     }
 
     if (res)
         __dump_vma(res, vma);
 
-    unlock(vma_list_lock);
+    unlock(&vma_list_lock);
     return 0;
 }
 
@@ -993,14 +993,14 @@ bool is_in_one_vma (void * addr, size_t length)
 {
     struct shim_vma* vma;
 
-    lock(vma_list_lock);
+    lock(&vma_list_lock);
     listp_for_each_entry(vma, &vma_list, list)
         if (test_vma_contain(vma, addr, addr + length)) {
-            unlock(vma_list_lock);
+            unlock(&vma_list_lock);
             return true;
         }
 
-    unlock(vma_list_lock);
+    unlock(&vma_list_lock);
     return false;
 }
 
@@ -1009,7 +1009,7 @@ int dump_all_vmas (struct shim_vma_val * vmas, size_t max_count)
     struct shim_vma_val * val = vmas;
     struct shim_vma * vma;
     int cnt = 0;
-    lock(vma_list_lock);
+    lock(&vma_list_lock);
 
     listp_for_each_entry(vma, &vma_list, list) {
         if (VMA_TYPE(vma->flags))
@@ -1030,7 +1030,7 @@ int dump_all_vmas (struct shim_vma_val * vmas, size_t max_count)
         val++;
     }
 
-    unlock(vma_list_lock);
+    unlock(&vma_list_lock);
     return cnt;
 }
 

+ 2 - 2
LibOS/shim/src/elf/shim_rtld.c

@@ -1491,11 +1491,11 @@ int init_loader (void)
     struct shim_thread * cur_thread = get_cur_thread();
     int ret = 0;
 
-    lock(cur_thread->lock);
+    lock(&cur_thread->lock);
     struct shim_handle * exec = cur_thread->exec;
     if (exec)
         get_handle(exec);
-    unlock(cur_thread->lock);
+    unlock(&cur_thread->lock);
 
     if (!exec)
         return 0;

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

@@ -151,14 +151,14 @@ static struct shim_file_data * __create_data (void)
     if (!data)
         return NULL;
 
-    create_lock(data->lock);
+    create_lock(&data->lock);
     return data;
 }
 
 static void __destroy_data (struct shim_file_data * data)
 {
     qstrfree(&data->host_uri);
-    destroy_lock(data->lock);
+    destroy_lock(&data->lock);
     free(data);
 }
 
@@ -246,7 +246,7 @@ static int __query_attr (struct shim_dentry * dent,
         if (old_type != FILE_DIR) {
             dent->state |= DENTRY_ISDIRECTORY;
             if ((ret = make_uri(dent)) < 0) {
-                unlock(data->lock);
+                unlock(&data->lock);
                 return ret;
             }
         }
@@ -302,10 +302,10 @@ static inline int try_create_data (struct shim_dentry * dent,
     struct shim_file_data * data = FILE_DENTRY_DATA(dent);
 
     if (!data) {
-        lock(dent->lock);
+        lock(&dent->lock);
         int ret = create_data(dent, uri, len);
         data = FILE_DENTRY_DATA(dent);
-        unlock(dent->lock);
+        unlock(&dent->lock);
         if (ret < 0) {
             return ret;
         }
@@ -324,10 +324,10 @@ static int query_dentry (struct shim_dentry * dent, PAL_HANDLE pal_handle,
     if ((ret = try_create_data(dent, NULL, 0, &data)) < 0)
         return ret;
 
-    lock(data->lock);
+    lock(&data->lock);
 
     if (!data->queried && (ret = __query_attr(dent, data, pal_handle)) < 0) {
-        unlock(data->lock);
+        unlock(&data->lock);
         return ret;
     }
 
@@ -364,7 +364,7 @@ static int query_dentry (struct shim_dentry * dent, PAL_HANDLE pal_handle,
         }
     }
 
-    unlock(data->lock);
+    unlock(&data->lock);
     return 0;
 }
 
@@ -426,9 +426,9 @@ static int __chroot_open (struct shim_dentry * dent,
     }
 
     if (!data->queried) {
-        lock(data->lock);
+        lock(&data->lock);
         ret = __query_attr(dent, data, palhdl);
-        unlock(data->lock);
+        unlock(&data->lock);
     }
 
     if (!hdl) {
@@ -454,10 +454,10 @@ static int chroot_open (struct shim_handle * hdl, struct shim_dentry * dent,
         return ret;
 
     if (dent->mode == NO_MODE) {
-        lock(data->lock);
+        lock(&data->lock);
         ret = __query_attr(dent, data, NULL);
         dent->mode = data->mode;
-        unlock(data->lock);
+        unlock(&data->lock);
     }
 
     if ((ret = __chroot_open(dent, NULL, 0, flags, dent->mode, hdl, data)) < 0)
@@ -508,10 +508,10 @@ static int chroot_creat (struct shim_handle * hdl, struct shim_dentry * dir,
     /* Increment the parent's link count */
     struct shim_file_data *parent_data = FILE_DENTRY_DATA(dir);
     if (parent_data) {
-        lock(parent_data->lock);
+        lock(&parent_data->lock);
         if (parent_data->queried)
             parent_data->nlink++;
-        unlock(parent_data->lock);
+        unlock(&parent_data->lock);
     }
     return 0;
 }
@@ -536,10 +536,10 @@ static int chroot_mkdir (struct shim_dentry * dir, struct shim_dentry * dent,
     /* Increment the parent's link count */
     struct shim_file_data *parent_data = FILE_DENTRY_DATA(dir);
     if (parent_data) {
-        lock(parent_data->lock);
+        lock(&parent_data->lock);
         if (parent_data->queried)
             parent_data->nlink++;
-        unlock(parent_data->lock);
+        unlock(&parent_data->lock);
     }
     return ret;
 }
@@ -615,12 +615,12 @@ static int chroot_flush (struct shim_handle * hdl)
     struct shim_file_handle * file = &hdl->info.file;
 
     if (file->buf_type == FILEBUF_MAP) {
-        lock(hdl->lock);
+        lock(&hdl->lock);
         void * mapbuf = file->mapbuf;
         int mapsize = file->mapsize;
         file->mapoffset = 0;
         file->mapbuf = NULL;
-        unlock(hdl->lock);
+        unlock(&hdl->lock);
 
         if (mapbuf) {
             DkStreamUnmap(mapbuf, mapsize);
@@ -693,7 +693,7 @@ static int map_read (struct shim_handle * hdl, void * buf, size_t count)
 {
     struct shim_file_handle * file = &hdl->info.file;
     int ret = 0;
-    lock(hdl->lock);
+    lock(&hdl->lock);
 
     struct shim_file_data * data = FILE_HANDLE_DATA(hdl);
     uint64_t size = atomic_read(&data->size);
@@ -710,7 +710,7 @@ static int map_read (struct shim_handle * hdl, void * buf, size_t count)
     }
 
     if ((ret = __map_buffer(hdl, count)) < 0) {
-        unlock(hdl->lock);
+        unlock(&hdl->lock);
         return ret;
     }
 
@@ -723,7 +723,7 @@ static int map_read (struct shim_handle * hdl, void * buf, size_t count)
     }
 
 out:
-    unlock(hdl->lock);
+    unlock(&hdl->lock);
     return count;
 }
 
@@ -733,7 +733,7 @@ static int map_write (struct shim_handle * hdl, const void * buf,
     struct shim_file_handle * file = &hdl->info.file;
     int ret = 0;
 
-    lock(hdl->lock);
+    lock(&hdl->lock);
 
     struct shim_file_data * data = FILE_HANDLE_DATA(hdl);
     uint64_t marker = file->marker;
@@ -777,7 +777,7 @@ static int map_write (struct shim_handle * hdl, const void * buf,
 
     ret = count;
 out:
-    unlock(hdl->lock);
+    unlock(&hdl->lock);
     return ret;
 }
 
@@ -805,10 +805,10 @@ static int chroot_read (struct shim_handle * hdl, void * buf,
         if (ret != -EACCES)
             goto out;
 
-        lock(hdl->lock);
+        lock(&hdl->lock);
         file->buf_type = FILEBUF_NONE;
     } else {
-        lock(hdl->lock);
+        lock(&hdl->lock);
     }
 
     ret = DkStreamRead(hdl->pal_handle, file->marker, count, buf, NULL, 0) ? :
@@ -817,7 +817,7 @@ static int chroot_read (struct shim_handle * hdl, void * buf,
     if (ret > 0 && file->type != FILE_TTY)
         file->marker += ret;
 
-    unlock(hdl->lock);
+    unlock(&hdl->lock);
 out:
     return ret;
 }
@@ -846,10 +846,10 @@ static int chroot_write (struct shim_handle * hdl, const void * buf,
         if (ret != -EACCES)
             goto out;
 
-        lock(hdl->lock);
+        lock(&hdl->lock);
         file->buf_type = FILEBUF_NONE;
     } else {
-        lock(hdl->lock);
+        lock(&hdl->lock);
     }
 
     ret = DkStreamWrite(hdl->pal_handle, file->marker, count, (void *) buf, NULL) ? :
@@ -858,7 +858,7 @@ static int chroot_write (struct shim_handle * hdl, const void * buf,
     if (ret > 0 && file->type != FILE_TTY)
         file->marker += ret;
 
-    unlock(hdl->lock);
+    unlock(&hdl->lock);
 out:
     return ret;
 
@@ -898,7 +898,7 @@ static int chroot_seek (struct shim_handle * hdl, off_t offset, int wence)
         return ret;
 
     struct shim_file_handle * file = &hdl->info.file;
-    lock(hdl->lock);
+    lock(&hdl->lock);
 
     int marker = file->marker;
     int size = file->size;
@@ -930,7 +930,7 @@ static int chroot_seek (struct shim_handle * hdl, off_t offset, int wence)
     ret = file->marker = marker;
 
 out:
-    unlock(hdl->lock);
+    unlock(&hdl->lock);
     return ret;
 }
 
@@ -946,7 +946,7 @@ static int chroot_truncate (struct shim_handle * hdl, uint64_t len)
         return -EINVAL;
 
     struct shim_file_handle * file = &hdl->info.file;
-    lock(hdl->lock);
+    lock(&hdl->lock);
 
     file->size = len;
 
@@ -968,7 +968,7 @@ static int chroot_truncate (struct shim_handle * hdl, uint64_t len)
         file->marker = len;
 
 out:
-    unlock(hdl->lock);
+    unlock(&hdl->lock);
     return ret;
 }
 
@@ -1190,10 +1190,10 @@ static int chroot_unlink (struct shim_dentry * dir, struct shim_dentry * dent)
     /* Drop the parent's link count */
     struct shim_file_data *parent_data = FILE_DENTRY_DATA(dir);
     if (parent_data) {
-        lock(parent_data->lock);
+        lock(&parent_data->lock);
         if (parent_data->queried)
             parent_data->nlink--;
-        unlock(parent_data->lock);
+        unlock(&parent_data->lock);
     }
 
     return 0;
@@ -1211,7 +1211,7 @@ static int chroot_poll (struct shim_handle * hdl, int poll_type)
     if (poll_type == FS_POLL_SZ)
         return size;
 
-    lock(hdl->lock);
+    lock(&hdl->lock);
 
     struct shim_file_handle * file = &hdl->info.file;
     if (check_version(hdl) &&
@@ -1230,7 +1230,7 @@ static int chroot_poll (struct shim_handle * hdl, int poll_type)
     ret = -EAGAIN;
 
 out:
-    unlock(hdl->lock);
+    unlock(&hdl->lock);
     return ret;
 }
 

+ 2 - 2
LibOS/shim/src/fs/pipe/fs.c

@@ -107,7 +107,7 @@ static int pipe_poll (struct shim_handle * hdl, int poll_type)
 {
     int ret = 0;
 
-    lock(hdl->lock);
+    lock(&hdl->lock);
 
     if (!hdl->pal_handle) {
         ret = -EBADF;
@@ -134,7 +134,7 @@ static int pipe_poll (struct shim_handle * hdl, int poll_type)
         ret |= FS_POLL_WR;
 
 out:
-    unlock(hdl->lock);
+    unlock(&hdl->lock);
     return ret;
 }
 

+ 17 - 17
LibOS/shim/src/fs/proc/ipc-thread.c

@@ -205,16 +205,16 @@ static int proc_match_ipc_thread (const char * name)
         return 0;
 
     create_lock_runtime(&status_lock);
-    lock(status_lock);
+    lock(&status_lock);
 
     if (pid_status_cache)
         for (int i = 0 ; i < pid_status_cache->nstatus ; i++)
             if (pid_status_cache->status[i].pid == pid) {
-                unlock(status_lock);
+                unlock(&status_lock);
                 return 1;
             }
 
-    unlock(status_lock);
+    unlock(&status_lock);
     return 0;
 }
 
@@ -228,17 +228,17 @@ static int proc_ipc_thread_dir_mode (const char * name, mode_t * mode)
         return 0;
 
     create_lock_runtime(&status_lock);
-    lock(status_lock);
+    lock(&status_lock);
 
     if (pid_status_cache)
         for (int i = 0 ; i < pid_status_cache->nstatus ; i++)
             if (pid_status_cache->status[i].pid == pid) {
-                unlock(status_lock);
+                unlock(&status_lock);
                 *mode = 0500;
                 return 0;
             }
 
-    unlock(status_lock);
+    unlock(&status_lock);
     return -ENOENT;
 }
 
@@ -252,7 +252,7 @@ static int proc_ipc_thread_dir_stat (const char * name, struct stat * buf)
         return 0;
 
     create_lock_runtime(&status_lock);
-    lock(status_lock);
+    lock(&status_lock);
 
     if (pid_status_cache)
         for (int i = 0 ; i < pid_status_cache->nstatus ; i++)
@@ -263,11 +263,11 @@ static int proc_ipc_thread_dir_stat (const char * name, struct stat * buf)
                 buf->st_uid = 0; /* XXX */
                 buf->st_gid = 0; /* XXX */
                 buf->st_size = 4096;
-                unlock(status_lock);
+                unlock(&status_lock);
                 return 0;
             }
 
-    unlock(status_lock);
+    unlock(&status_lock);
     return -ENOENT;
 }
 
@@ -281,12 +281,12 @@ static int proc_list_ipc_thread (const char * name, struct shim_dirent ** buf,
 
     create_lock_runtime(&status_lock);
 
-    lock(status_lock);
+    lock(&status_lock);
     if (pid_status_cache && !pid_status_cache->dirty) {
         status = pid_status_cache;
         status->ref_count++;
     }
-    unlock(status_lock);
+    unlock(&status_lock);
 
     if (!status) {
         status = malloc(sizeof(struct pid_status_cache));
@@ -303,7 +303,7 @@ static int proc_list_ipc_thread (const char * name, struct shim_dirent ** buf,
         status->ref_count = 1;
         status->dirty = false;
 
-        lock(status_lock);
+        lock(&status_lock);
         if (pid_status_cache) {
             if (pid_status_cache->dirty) {
                 if (!pid_status_cache->ref_count)
@@ -319,7 +319,7 @@ static int proc_list_ipc_thread (const char * name, struct shim_dirent ** buf,
         } else {
             pid_status_cache = status;
         }
-        unlock(status_lock);
+        unlock(&status_lock);
     }
 
     if (!status->nstatus)
@@ -353,19 +353,19 @@ static int proc_list_ipc_thread (const char * name, struct shim_dirent ** buf,
 
     *buf = ptr;
 success:
-    lock(status_lock);
+    lock(&status_lock);
     status->dirty = true;
     status->ref_count--;
     if (!status->ref_count && status != pid_status_cache)
         free(status);
-    unlock(status_lock);
+    unlock(&status_lock);
     return 0;
 err:
-    lock(status_lock);
+    lock(&status_lock);
     status->ref_count--;
     if (!status->ref_count && status != pid_status_cache)
         free(status);
-    unlock(status_lock);
+    unlock(&status_lock);
     return ret;
 }
 

+ 12 - 12
LibOS/shim/src/fs/proc/thread.c

@@ -87,7 +87,7 @@ static int find_thread_link (const char * name, struct shim_qstr * link,
         goto out;
     }
 
-    lock(thread->lock);
+    lock(&thread->lock);
 
     if (next_len == static_strlen("root") && !memcmp(next, "root", next_len)) {
         dent = thread->root;
@@ -102,7 +102,7 @@ static int find_thread_link (const char * name, struct shim_qstr * link,
     if (next_len == static_strlen("exe") && !memcmp(next, "exe", next_len)) {
         struct shim_handle * exec = thread->exec;
         if (!exec->dentry) {
-            unlock(thread->lock);
+            unlock(&thread->lock);
             ret = -EINVAL;
             goto out;
         }
@@ -110,7 +110,7 @@ static int find_thread_link (const char * name, struct shim_qstr * link,
         get_dentry(dent);
     }
 
-    unlock(thread->lock);
+    unlock(&thread->lock);
 
     if (nextnext) {
         struct shim_dentry * next_dent = NULL;
@@ -252,12 +252,12 @@ static int parse_thread_fd (const char * name, const char ** rest,
 
     struct shim_handle_map * handle_map = get_cur_handle_map(thread);
 
-    lock(handle_map->lock);
+    lock(&handle_map->lock);
 
     if (fd >= handle_map->fd_top ||
         handle_map->map[fd] == NULL ||
         handle_map->map[fd]->handle == NULL) {
-        unlock(handle_map->lock);
+        unlock(&handle_map->lock);
         return -ENOENT;
     }
 
@@ -266,7 +266,7 @@ static int parse_thread_fd (const char * name, const char ** rest,
         get_handle(*phdl);
     }
 
-    unlock(handle_map->lock);
+    unlock(&handle_map->lock);
 
     if (rest)
         *rest = *p ? p + 1 : NULL;
@@ -300,7 +300,7 @@ static int proc_list_thread_each_fd (const char * name,
     int err = 0, bytes = 0;
     struct shim_dirent * dirent = *buf, ** last = NULL;
 
-    lock(handle_map->lock);
+    lock(&handle_map->lock);
 
     for (int i = 0 ; i < handle_map->fd_size ; i++)
         if (handle_map->map[i] &&
@@ -326,7 +326,7 @@ static int proc_list_thread_each_fd (const char * name,
             dirent = dirent->next;
         }
 
-    unlock(handle_map->lock);
+    unlock(&handle_map->lock);
     put_thread(thread);
 
     if (last)
@@ -352,14 +352,14 @@ static int find_thread_each_fd (const char * name, struct shim_qstr * link,
     if ((ret = parse_thread_fd(name, &rest, &handle)) < 0)
         return ret;
 
-    lock(handle->lock);
+    lock(&handle->lock);
 
     if (handle->dentry) {
         dent = handle->dentry;
         get_dentry(dent);
     }
 
-    unlock(handle->lock);
+    unlock(&handle->lock);
 
     if (!dent) {
         ret = -ENOENT;
@@ -680,10 +680,10 @@ static int proc_thread_dir_stat (const char * name, struct stat * buf)
     memset(buf, 0, sizeof(struct stat));
     buf->st_dev = buf->st_ino = 1;
     buf->st_mode = 0500|S_IFDIR;
-    lock(thread->lock);
+    lock(&thread->lock);
     buf->st_uid = thread->uid;
     buf->st_gid = thread->gid;
-    unlock(thread->lock);
+    unlock(&thread->lock);
     buf->st_size = 4096;
     return 0;
 }

+ 5 - 5
LibOS/shim/src/fs/shim_dcache.c

@@ -77,7 +77,7 @@ int init_dcache (void)
 {
     dentry_mgr = create_mem_mgr(init_align_up(DCACHE_MGR_ALLOC));
 
-    create_lock(dcache_lock);
+    create_lock(&dcache_lock);
 
     dentry_root = alloc_dentry();
 
@@ -336,14 +336,14 @@ BEGIN_CP_FUNC(dentry)
         ADD_TO_CP_MAP(obj, off);
         new_dent = (struct shim_dentry *) (base + off);
 
-        lock(dent->lock);
+        lock(&dent->lock);
         *new_dent = *dent;
         INIT_LIST_HEAD(new_dent, hlist);
         INIT_LIST_HEAD(new_dent, list);
         INIT_LISTP(&new_dent->children);
         INIT_LIST_HEAD(new_dent, siblings);
         new_dent->data = NULL;
-        clear_lock(new_dent->lock);
+        clear_lock(&new_dent->lock);
         REF_SET(new_dent->ref_count, 0);
 
         DO_CP_IN_MEMBER(qstr, new_dent, rel_path);
@@ -358,7 +358,7 @@ BEGIN_CP_FUNC(dentry)
         if (dent->mounted)
             DO_CP_MEMBER(mount, dent, new_dent, mounted);
 
-        unlock(dent->lock);
+        unlock(&dent->lock);
         ADD_CP_FUNC_ENTRY(off);
     } else {
         new_dent = (struct shim_dentry *) (base + off);
@@ -381,7 +381,7 @@ BEGIN_RS_FUNC(dentry)
     CP_REBASE(dent->parent);
     CP_REBASE(dent->mounted);
 
-    create_lock(dent->lock);
+    create_lock(&dent->lock);
 
     /* DEP 6/16/17: I believe the point of this line is to
      * fix up the children linked list.  Presumably the ref count and

+ 14 - 14
LibOS/shim/src/fs/shim_fs.c

@@ -60,8 +60,8 @@ struct shim_mount * builtin_fs [NUM_BUILTIN_FS] = {
 
 static struct shim_lock mount_mgr_lock;
 
-#define system_lock()       lock(mount_mgr_lock)
-#define system_unlock()     unlock(mount_mgr_lock)
+#define system_lock()       lock(&mount_mgr_lock)
+#define system_unlock()     unlock(&mount_mgr_lock)
 
 #define MOUNT_MGR_ALLOC     64
 #define PAGE_SIZE           allocsize
@@ -81,8 +81,8 @@ int init_fs (void)
     if (!mount_mgr)
         return -ENOMEM;
 
-    create_lock(mount_mgr_lock);
-    create_lock(mount_list_lock);
+    create_lock(&mount_mgr_lock);
+    create_lock(&mount_list_lock);
     return 0;
 }
 
@@ -325,10 +325,10 @@ int __mount_fs (struct shim_mount * mount, struct shim_dentry * dent)
     if ((ret = __del_dentry_tree(dent)) < 0)
         return ret;
 
-    lock(mount_list_lock);
+    lock(&mount_list_lock);
     get_mount(mount);
     listp_add_tail(mount, &mount_list, list);
-    unlock(mount_list_lock);
+    unlock(&mount_list_lock);
 
     do {
         struct shim_dentry * parent = dent->parent;
@@ -422,7 +422,7 @@ int mount_fs (const char * type, const char * uri, const char * mount_point,
         }
     }
 
-    lock(dcache_lock);
+    lock(&dcache_lock);
 
     struct shim_mount * mount = alloc_mount();
     void * mount_data = NULL;
@@ -489,7 +489,7 @@ int mount_fs (const char * type, const char * uri, const char * mount_point,
         *dentp = dent;
 
 out_with_unlock:
-    unlock(dcache_lock);
+    unlock(&dcache_lock);
 out:
     return ret;
 }
@@ -511,7 +511,7 @@ int walk_mounts (int (*walk) (struct shim_mount * mount, void * arg),
     int ret = 0;
     int nsrched = 0;
 
-    lock(mount_list_lock);
+    lock(&mount_list_lock);
 
     listp_for_each_entry_safe(mount, n, &mount_list, list) {
         if ((ret = (*walk) (mount, arg)) < 0)
@@ -521,7 +521,7 @@ int walk_mounts (int (*walk) (struct shim_mount * mount, void * arg),
             nsrched++;
     }
 
-    unlock(mount_list_lock);
+    unlock(&mount_list_lock);
     return ret < 0 ? ret : (nsrched ? 0 : -ESRCH);
 }
 
@@ -530,7 +530,7 @@ struct shim_mount * find_mount_from_uri (const char * uri)
     struct shim_mount * mount, * found = NULL;
     int longest_path = 0;
 
-    lock(mount_list_lock);
+    lock(&mount_list_lock);
     listp_for_each_entry(mount, &mount_list, list) {
         if (qstrempty(&mount->uri))
             continue;
@@ -547,7 +547,7 @@ struct shim_mount * find_mount_from_uri (const char * uri)
     if (found)
         get_mount(found);
 
-    unlock(mount_list_lock);
+    unlock(&mount_list_lock);
     return found;
 }
 
@@ -644,10 +644,10 @@ END_RS_FUNC(mount)
 BEGIN_CP_FUNC(all_mounts)
 {
     struct shim_mount * mount;
-    lock(mount_list_lock);
+    lock(&mount_list_lock);
     listp_for_each_entry(mount, &mount_list, list)
         DO_CP(mount, mount, NULL);
-    unlock(mount_list_lock);
+    unlock(&mount_list_lock);
 
     /* add an empty entry to mark as migrated */
     ADD_CP_FUNC_ENTRY(0UL);

+ 10 - 10
LibOS/shim/src/fs/shim_namei.c

@@ -471,9 +471,9 @@ int path_lookupat (struct shim_dentry * start, const char * name, int flags,
                    struct shim_dentry ** dent, struct shim_mount * fs)
 {
     int ret = 0;
-    lock(dcache_lock);
+    lock(&dcache_lock);
     ret = __path_lookupat (start, name, flags, dent, 0, fs, 0);
-    unlock(dcache_lock);
+    unlock(&dcache_lock);
     return ret;
 }
 
@@ -501,7 +501,7 @@ int open_namei (struct shim_handle * hdl, struct shim_dentry * start,
     int err = 0, newly_created = 0;
     struct shim_dentry *mydent = NULL;
 
-    lock(dcache_lock);
+    lock(&dcache_lock);
 
     // lookup the path from start, passing flags
     err = __path_lookupat(start, path, lookup_flags, &mydent, 0, NULL, 0);
@@ -572,7 +572,7 @@ out:
     if (dent && !err)
         *dent = mydent;
 
-    unlock(dcache_lock);
+    unlock(&dcache_lock);
 
     return err;
 }
@@ -695,14 +695,14 @@ int list_directory_dentry (struct shim_dentry *dent) {
 
     int ret = 0;
     struct shim_mount * fs = dent->fs;
-    lock(dcache_lock);
+    lock(&dcache_lock);
 
     /* DEP 8/4/17: Another process could list this directory
      * while we are waiting on the dcache lock.  This is ok,
      * no need to blow an assert.
      */
     if (dent->state & DENTRY_LISTED){
-        unlock(dcache_lock);
+        unlock(&dcache_lock);
         return 0;
     }
 
@@ -711,7 +711,7 @@ int list_directory_dentry (struct shim_dentry *dent) {
     // expect to learn is beyond me, but be careful with blowing assert
     // and tell the program something to keep it moving.
     if (dent->state & DENTRY_NEGATIVE) {
-        unlock(dcache_lock);
+        unlock(&dcache_lock);
         return 0;
     }
 
@@ -745,7 +745,7 @@ int list_directory_dentry (struct shim_dentry *dent) {
     dent->state |= DENTRY_LISTED;
 
 done_read:
-    unlock(dcache_lock);
+    unlock(&dcache_lock);
     free(dirent);
     return ret;
 }
@@ -780,7 +780,7 @@ int list_directory_handle (struct shim_dentry * dent, struct shim_handle * hdl)
     if (!children)
         return -ENOMEM;
 
-    lock(dcache_lock);
+    lock(&dcache_lock);
     listp_for_each_entry(child, &dent->children, siblings) {
         if (count >= nchildren)
             break;
@@ -800,7 +800,7 @@ int list_directory_handle (struct shim_dentry * dent, struct shim_handle * hdl)
     hdl->info.dir.buf = children;
     hdl->info.dir.ptr = children;
 
-    unlock(dcache_lock);
+    unlock(&dcache_lock);
 
     return 0;
 }

+ 14 - 14
LibOS/shim/src/fs/socket/fs.c

@@ -54,14 +54,14 @@ static int socket_read (struct shim_handle * hdl, void * buf,
     if (!count)
         return 0;
 
-    lock(hdl->lock);
+    lock(&hdl->lock);
 
     if (sock->sock_type == SOCK_STREAM &&
         sock->sock_state != SOCK_ACCEPTED &&
         sock->sock_state != SOCK_CONNECTED &&
         sock->sock_state != SOCK_BOUNDCONNECTED) {
         sock->error = ENOTCONN;
-        unlock(hdl->lock);
+        unlock(&hdl->lock);
         return -ENOTCONN;
     }
 
@@ -69,11 +69,11 @@ static int socket_read (struct shim_handle * hdl, void * buf,
         sock->sock_state != SOCK_CONNECTED &&
         sock->sock_state != SOCK_BOUNDCONNECTED) {
         sock->error = EDESTADDRREQ;
-        unlock(hdl->lock);
+        unlock(&hdl->lock);
         return -EDESTADDRREQ;
     }
 
-    unlock(hdl->lock);
+    unlock(&hdl->lock);
 
     bytes = DkStreamRead(hdl->pal_handle, 0, count, buf, NULL, 0);
 
@@ -83,9 +83,9 @@ static int socket_read (struct shim_handle * hdl, void * buf,
                 return 0;
             default: {
                 int err = PAL_ERRNO;
-                lock(hdl->lock);
+                lock(&hdl->lock);
                 sock->error = err;
-                unlock(hdl->lock);
+                unlock(&hdl->lock);
                 return -err;
             }
         }
@@ -98,14 +98,14 @@ static int socket_write (struct shim_handle * hdl, const void * buf,
 {
     struct shim_sock_handle * sock = &hdl->info.sock;
 
-    lock(hdl->lock);
+    lock(&hdl->lock);
 
     if (sock->sock_type == SOCK_STREAM &&
         sock->sock_state != SOCK_ACCEPTED &&
         sock->sock_state != SOCK_CONNECTED &&
         sock->sock_state != SOCK_BOUNDCONNECTED) {
         sock->error = ENOTCONN;
-        unlock(hdl->lock);
+        unlock(&hdl->lock);
         return -ENOTCONN;
     }
 
@@ -113,11 +113,11 @@ static int socket_write (struct shim_handle * hdl, const void * buf,
         sock->sock_state != SOCK_CONNECTED &&
         sock->sock_state != SOCK_BOUNDCONNECTED) {
         sock->error = EDESTADDRREQ;
-        unlock(hdl->lock);
+        unlock(&hdl->lock);
         return -EDESTADDRREQ;
     }
 
-    unlock(hdl->lock);
+    unlock(&hdl->lock);
 
     if (!count)
         return 0;
@@ -134,9 +134,9 @@ static int socket_write (struct shim_handle * hdl, const void * buf,
                 err = PAL_ERRNO;
                 break;
         }
-        lock(hdl->lock);
+        lock(&hdl->lock);
         sock->error = err;
-        unlock(hdl->lock);
+        unlock(&hdl->lock);
         return -err;
     }
 
@@ -173,7 +173,7 @@ static int socket_poll (struct shim_handle * hdl, int poll_type)
     struct shim_sock_handle * sock = &hdl->info.sock;
     int ret = 0;
 
-    lock(hdl->lock);
+    lock(&hdl->lock);
 
     if (poll_type & FS_POLL_RD) {
         if (sock->sock_type == SOCK_STREAM) {
@@ -241,7 +241,7 @@ out:
         sock->error = -ret;
     }
 
-    unlock(hdl->lock);
+    unlock(&hdl->lock);
     return ret;
 }
 

+ 24 - 24
LibOS/shim/src/ipc/shim_ipc.c

@@ -61,7 +61,7 @@ int init_ipc (void)
 {
     int ret = 0;
 
-    create_lock(ipc_info_lock);
+    create_lock(&ipc_info_lock);
 
     if (!(ipc_info_mgr = create_mem_mgr(init_align_up(ipc_info_mgr_ALLOC))))
         return -ENOMEM;
@@ -110,9 +110,9 @@ static struct shim_ipc_info * __get_new_ipc_info (IDTYPE vmid, const char * uri,
 struct shim_ipc_info * get_new_ipc_info (IDTYPE vmid, const char * uri,
                                          size_t len)
 {
-    lock(ipc_info_lock);
+    lock(&ipc_info_lock);
     struct shim_ipc_info * info = __get_new_ipc_info(vmid, uri, len);
-    unlock(ipc_info_lock);
+    unlock(&ipc_info_lock);
     return info;
 }
 
@@ -173,9 +173,9 @@ void put_ipc_info (struct shim_ipc_info * info)
         return;
 
     unset_ipc_info(info);
-    lock(ipc_info_lock);
+    lock(&ipc_info_lock);
     free_mem_obj_to_mgr(ipc_info_mgr, info);
-    unlock(ipc_info_lock);
+    unlock(&ipc_info_lock);
 }
 
 #define CLIENT_HASH_LEN     6
@@ -196,11 +196,11 @@ lookup_and_alloc_client (IDTYPE vmid, const char * uri)
 
     assert(vmid);
 
-    lock(ipc_info_lock);
+    lock(&ipc_info_lock);
     listp_for_each_entry(p, head, hlist)
         if (p->vmid == vmid && !qstrcmpstr(&p->uri, uri, len)) {
             get_ipc_info(p);
-            unlock(ipc_info_lock);
+            unlock(&ipc_info_lock);
             return p;
         }
 
@@ -209,13 +209,13 @@ lookup_and_alloc_client (IDTYPE vmid, const char * uri)
         listp_add(p, head, hlist);
         get_ipc_info(p);
     }
-    unlock(ipc_info_lock);
+    unlock(&ipc_info_lock);
     return p;
 }
 
 void put_client (struct shim_ipc_info * info)
 {
-    lock(ipc_info_lock);
+    lock(&ipc_info_lock);
     /* Look up the hash */
     LISTP_TYPE(shim_ipc_info) *head = client_table + CLIENT_HASH(info->vmid);
     __put_ipc_info(info);
@@ -223,7 +223,7 @@ void put_client (struct shim_ipc_info * info)
         listp_del_init(info, head, hlist);
         __put_ipc_info(info);
     }
-    unlock(ipc_info_lock);
+    unlock(&ipc_info_lock);
 }
 
 struct shim_ipc_info * discover_client (struct shim_ipc_port * port,
@@ -234,14 +234,14 @@ struct shim_ipc_info * discover_client (struct shim_ipc_port * port,
 
     assert(vmid);
 
-    lock(ipc_info_lock);
+    lock(&ipc_info_lock);
     listp_for_each_entry(p, head, hlist)
         if (p->vmid == vmid && !qstrempty(&p->uri)) {
             __get_ipc_info(p);
-            unlock(ipc_info_lock);
+            unlock(&ipc_info_lock);
             return p;
         }
-    unlock(ipc_info_lock);
+    unlock(&ipc_info_lock);
     return NULL;
 
     if (!ipc_finduri_send(port, vmid, &p))
@@ -261,7 +261,7 @@ struct shim_process * create_new_process (bool inherit_parent)
     if (!inherit_parent)
         return new_process;
 
-    lock(cur_process.lock);
+    lock(&cur_process.lock);
 
     if (cur_process.self)
         qstrcopy(&new_process->parent->uri, &cur_process.self->uri);
@@ -273,7 +273,7 @@ struct shim_process * create_new_process (bool inherit_parent)
                                  qstrgetstr(&cur_process.ns[i]->uri),
                                  cur_process.ns[i]->uri.len);
 
-    unlock(cur_process.lock);
+    unlock(&cur_process.lock);
     return new_process;
 }
 
@@ -388,10 +388,10 @@ int close_ipc_message_duplex (struct shim_ipc_msg_obj * msg,
     if (port) {
         // Check if the message is pending on the port for response. If so,
         // remove the message from the list.
-        lock(port->msgs_lock);
+        lock(&port->msgs_lock);
         if (!list_empty(msg, list))
             listp_del_init(msg, &port->msgs, list);
-        unlock(port->msgs_lock);
+        unlock(&port->msgs_lock);
     }
 
     if (msg->thread) {
@@ -412,10 +412,10 @@ int send_ipc_message_duplex (struct shim_ipc_msg_obj * msg,
     msg->msg.seq = atomic_read(&ipc_seq_counter);
 
     if (save) {
-        lock(port->msgs_lock);
+        lock(&port->msgs_lock);
         msg->private = private_data;
         listp_add_tail(msg, &port->msgs, list);
-        unlock(port->msgs_lock);
+        unlock(&port->msgs_lock);
     }
 
     int ret = send_ipc_message(&msg->msg, port);
@@ -433,14 +433,14 @@ struct shim_ipc_msg_obj * find_ipc_msg_duplex (struct shim_ipc_port * port,
                                                unsigned long seq)
 {
     struct shim_ipc_msg_obj * tmp, * found = NULL;
-    lock(port->msgs_lock);
+    lock(&port->msgs_lock);
     listp_for_each_entry(tmp, &port->msgs, list)
         if (tmp->msg.seq == seq) {
             found = tmp;
             listp_del_init(tmp, &port->msgs, list);
             break;
         }
-    unlock(port->msgs_lock);
+    unlock(&port->msgs_lock);
     return found;
 }
 
@@ -494,7 +494,7 @@ struct shim_ipc_info * create_ipc_port (IDTYPE vmid, bool listen)
 
 int create_ipc_location (struct shim_ipc_info ** info)
 {
-    lock(cur_process.lock);
+    lock(&cur_process.lock);
     int ret = -EACCES;
 
     if (cur_process.self)
@@ -509,7 +509,7 @@ success:
     *info = cur_process.self;
     ret = 0;
 out:
-    unlock(cur_process.lock);
+    unlock(&cur_process.lock);
     return ret;
 }
 
@@ -749,7 +749,7 @@ BEGIN_RS_FUNC(process)
 
     proc->vmid = cur_process.vmid;
     memcpy(&cur_process, proc, sizeof(struct shim_process));
-    create_lock(cur_process.lock);
+    create_lock(&cur_process.lock);
 
     DEBUG_RS("vmid=%u,uri=%s,parent=%u(%s)", proc->vmid,
              proc->self ? qstrgetstr(&proc->self->uri) : "",

+ 4 - 4
LibOS/shim/src/ipc/shim_ipc_child.c

@@ -89,14 +89,14 @@ void ipc_parent_exit (struct shim_ipc_port * port, IDTYPE vmid,
 
     struct shim_ipc_info * parent = NULL;
 
-    lock(cur_process.lock);
+    lock(&cur_process.lock);
 
     if (parent && vmid == cur_process.parent->vmid) {
         parent = cur_process.parent;
         cur_process.parent = NULL;
     }
 
-    unlock(cur_process.lock);
+    unlock(&cur_process.lock);
 
     if (parent)
         put_ipc_info(parent);
@@ -177,12 +177,12 @@ void ipc_child_exit (struct shim_ipc_port * port, IDTYPE vmid,
 static struct shim_ipc_port * get_parent_port (IDTYPE * dest)
 {
     struct shim_ipc_port * port = NULL;
-    lock(cur_process.lock);
+    lock(&cur_process.lock);
     if (cur_process.parent && (port = cur_process.parent->port)) {
         get_ipc_port(port);
         *dest = cur_process.parent->vmid;
     }
-    unlock(cur_process.lock);
+    unlock(&cur_process.lock);
     return port;
 }
 

+ 38 - 38
LibOS/shim/src/ipc/shim_ipc_helper.c

@@ -156,7 +156,7 @@ int init_ipc_helper (void)
 {
     bool need_helper = (ipc_helper_state == HELPER_DELAYED);
     ipc_helper_state = HELPER_NOTALIVE;
-    create_lock(ipc_helper_lock);
+    create_lock(&ipc_helper_lock);
     create_event(&ipc_helper_event);
     if (need_helper) {
         /*
@@ -166,9 +166,9 @@ int init_ipc_helper (void)
         enable_locking();
 
         /* Go ahead and lock the ipc helper lock here, for consistency */
-        lock(ipc_helper_lock);
+        lock(&ipc_helper_lock);
         create_ipc_helper();
-        unlock(ipc_helper_lock);
+        unlock(&ipc_helper_lock);
     }
     return 0;
 }
@@ -192,7 +192,7 @@ static void __free_ipc_port (struct shim_ipc_port * pobj)
         pobj->pal_handle = NULL;
     }
 
-    destroy_lock(pobj->msgs_lock);
+    destroy_lock(&pobj->msgs_lock);
     free_mem_obj_to_mgr(port_mgr, pobj);
 }
 
@@ -298,12 +298,12 @@ void add_ipc_port (struct shim_ipc_port * port, IDTYPE vmid, int type,
     debug("adding port %p (handle %p) for process %u (type=%04x)\n",
           port, port->pal_handle, port->info.vmid, type);
 
-    lock(ipc_helper_lock);
+    lock(&ipc_helper_lock);
     bool need_restart = __add_ipc_port(port, vmid, type, fini);
     if (need_restart)
         restart_ipc_helper(true);
 
-    unlock(ipc_helper_lock);
+    unlock(&ipc_helper_lock);
 }
 
 static struct shim_ipc_port * __get_new_ipc_port (PAL_HANDLE hdl)
@@ -324,7 +324,7 @@ static struct shim_ipc_port * __get_new_ipc_port (PAL_HANDLE hdl)
     INIT_LIST_HEAD(port, list);
     INIT_LISTP(&port->msgs);
     REF_SET(port->ref_count, 1);
-    create_lock(port->msgs_lock);
+    create_lock(&port->msgs_lock);
     return port;
 }
 
@@ -335,7 +335,7 @@ void add_ipc_port_by_id (IDTYPE vmid, PAL_HANDLE hdl, int type,
           hdl, vmid, type);
 
     assert(!!hdl && PAL_GET_TYPE(hdl));
-    lock(ipc_helper_lock);
+    lock(&ipc_helper_lock);
 
     LISTP_TYPE(shim_ipc_port) * head = vmid ? &ipc_port_pool[PID_HASH(vmid)] : NULL;
     struct shim_ipc_port * tmp, * port = NULL;
@@ -374,7 +374,7 @@ void add_ipc_port_by_id (IDTYPE vmid, PAL_HANDLE hdl, int type,
         restart_ipc_helper(true);
 
 out:
-    unlock(ipc_helper_lock);
+    unlock(&ipc_helper_lock);
 }
 
 static bool __del_ipc_port (struct shim_ipc_port * port, int type)
@@ -420,7 +420,7 @@ static bool __del_ipc_port (struct shim_ipc_port * port, int type)
 
     // Need to check if there are any pending messages on the port, which means
     // some threads might be blocking for responses.
-    lock(port->msgs_lock);
+    lock(&port->msgs_lock);
     struct shim_ipc_msg_obj * msg, * n;
     listp_for_each_entry_safe(msg, n, &port->msgs, list) {
         listp_del_init(msg, &port->msgs, list);
@@ -430,7 +430,7 @@ static bool __del_ipc_port (struct shim_ipc_port * port, int type)
             thread_wakeup(msg->thread);
         }
     }
-    unlock(port->msgs_lock);
+    unlock(&port->msgs_lock);
 
 out:
     port->update = true;
@@ -440,11 +440,11 @@ out:
 
 void del_ipc_port (struct shim_ipc_port * port, int type)
 {
-    lock(ipc_helper_lock);
+    lock(&ipc_helper_lock);
 
     // If the port is already deleted, don't delete it again.
     if (list_empty(port, list)) {
-        unlock(ipc_helper_lock);
+        unlock(&ipc_helper_lock);
         return;
     }
 
@@ -453,7 +453,7 @@ void del_ipc_port (struct shim_ipc_port * port, int type)
     if (need_restart)
         restart_ipc_helper(false);
 
-    unlock(ipc_helper_lock);
+    unlock(&ipc_helper_lock);
 }
 
 void del_ipc_port_by_id (IDTYPE vmid, int type)
@@ -462,7 +462,7 @@ void del_ipc_port_by_id (IDTYPE vmid, int type)
     struct shim_ipc_port * port, *n;
     bool need_restart = false;
 
-    lock(ipc_helper_lock);
+    lock(&ipc_helper_lock);
 
     listp_for_each_entry_safe(port, n, head, hlist) {
         if (list_empty(port, list))
@@ -478,7 +478,7 @@ void del_ipc_port_by_id (IDTYPE vmid, int type)
     if (need_restart)
         restart_ipc_helper(false);
 
-    unlock(ipc_helper_lock);
+    unlock(&ipc_helper_lock);
 }
 
 void del_ipc_port_fini (struct shim_ipc_port * port, unsigned int exitcode)
@@ -486,11 +486,11 @@ void del_ipc_port_fini (struct shim_ipc_port * port, unsigned int exitcode)
     port_fini fini[MAX_IPC_PORT_FINI_CB];
     int nfini = 0;
     assert(REF_GET(port->ref_count) > 0);
-    lock(ipc_helper_lock);
+    lock(&ipc_helper_lock);
 
     // If the port is already deleted, don't delete it again.
     if (list_empty(port, list)) {
-        unlock(ipc_helper_lock);
+        unlock(&ipc_helper_lock);
         return;
     }
 
@@ -506,7 +506,7 @@ void del_ipc_port_fini (struct shim_ipc_port * port, unsigned int exitcode)
     if (need_restart)
         restart_ipc_helper(false);
 
-    unlock(ipc_helper_lock);
+    unlock(&ipc_helper_lock);
 
     for (int i = 0 ; i < nfini ; i++)
         (fini[i])(port, vmid, exitcode);
@@ -530,13 +530,13 @@ static struct shim_ipc_port * __lookup_ipc_port (IDTYPE vmid, int type)
 
 struct shim_ipc_port * lookup_ipc_port (IDTYPE vmid, int type)
 {
-    lock(ipc_helper_lock);
+    lock(&ipc_helper_lock);
     struct shim_ipc_port * port = __lookup_ipc_port(vmid, type);
     if (port) {
         assert(!list_empty(port, list));
         assert(!vmid || !list_empty(port, hlist));
     }
-    unlock(ipc_helper_lock);
+    unlock(&ipc_helper_lock);
     return port;
 }
 
@@ -556,9 +556,9 @@ void put_ipc_port (struct shim_ipc_port * port)
 #endif
 
     if (!ref_count) {
-        lock(ipc_helper_lock); // Need to grab the lock
+        lock(&ipc_helper_lock); // Need to grab the lock
         __free_ipc_port(port);
-        unlock(ipc_helper_lock);
+        unlock(&ipc_helper_lock);
     }
 }
 
@@ -567,7 +567,7 @@ void del_all_ipc_ports (int type)
     struct shim_ipc_port * pobj, * n;
     bool need_restart = false;
 
-    lock(ipc_helper_lock);
+    lock(&ipc_helper_lock);
 
     listp_for_each_entry_safe(pobj, n, &pobj_list, list) {
         if (__del_ipc_port(pobj, type))
@@ -577,7 +577,7 @@ void del_all_ipc_ports (int type)
     if (need_restart)
         restart_ipc_helper(false);
 
-    unlock(ipc_helper_lock);
+    unlock(&ipc_helper_lock);
 }
 
 int broadcast_ipc (struct shim_ipc_msg * msg, struct shim_ipc_port ** exclude,
@@ -597,7 +597,7 @@ int broadcast_ipc (struct shim_ipc_msg * msg, struct shim_ipc_port ** exclude,
             return 0;
     }
 
-    lock(ipc_helper_lock);
+    lock(&ipc_helper_lock);
 
     int ntargets = 0;
     listp_for_each_entry(pobj, &pobj_list, list) {
@@ -616,7 +616,7 @@ int broadcast_ipc (struct shim_ipc_msg * msg, struct shim_ipc_port ** exclude,
             targets[i++] = pobj;
         }
 
-    unlock(ipc_helper_lock);
+    unlock(&ipc_helper_lock);
 
     for (i = 0 ; i < ntargets ; i++) {
         pobj = targets[i];
@@ -820,9 +820,9 @@ static void shim_ipc_helper (void * arg)
     debug_setbuf(&tcb.shim_tcb, true);
     debug("set tcb to %p\n", &tcb);
 
-    lock(ipc_helper_lock);
+    lock(&ipc_helper_lock);
     bool notme = (self != ipc_helper_thread);
-    unlock(ipc_helper_lock);
+    unlock(&ipc_helper_lock);
 
     if (notme) {
         put_thread(self);
@@ -934,7 +934,7 @@ update_status:
             continue;
 update_list:
         ipc_helper_update = false;
-        lock(ipc_helper_lock);
+        lock(&ipc_helper_lock);
 
         int compact = 0;
         /* first walk though all the polling ports and remove the one
@@ -1014,7 +1014,7 @@ update_list:
                   pobj->private.type);
         }
 
-        unlock(ipc_helper_lock);
+        unlock(&ipc_helper_lock);
     }
 
     for (int i = 0 ; i < port_num ; i++) {
@@ -1037,10 +1037,10 @@ end:
         shim_terminate(0); // Same as shim_clean(), but this is the official termination function
     }
 
-    lock(ipc_helper_lock);
+    lock(&ipc_helper_lock);
     ipc_helper_state = HELPER_NOTALIVE;
     ipc_helper_thread = NULL;
-    unlock(ipc_helper_lock);
+    unlock(&ipc_helper_lock);
     put_thread(self);
     debug("ipc helper thread terminated\n");
 
@@ -1095,7 +1095,7 @@ int exit_with_ipc_helper (bool handover, struct shim_thread ** ret)
     if (IN_HELPER() || ipc_helper_state != HELPER_ALIVE)
         return 0;
 
-    lock(ipc_helper_lock);
+    lock(&ipc_helper_lock);
     if (handover) {
         handover = false;
         struct shim_ipc_port * pobj;
@@ -1119,7 +1119,7 @@ int exit_with_ipc_helper (bool handover, struct shim_thread ** ret)
         get_thread(ipc_helper_thread);
         *ret = ipc_helper_thread;
     }
-    unlock(ipc_helper_lock);
+    unlock(&ipc_helper_lock);
 
     set_event(&ipc_helper_event, 1);
 
@@ -1143,17 +1143,17 @@ int exit_with_ipc_helper (bool handover, struct shim_thread ** ret)
 
 int terminate_ipc_helper (void)
 {
-    lock(ipc_helper_lock);
+    lock(&ipc_helper_lock);
 
     struct shim_thread * thread = ipc_helper_thread;
     if (!thread) {
-        unlock(ipc_helper_lock);
+        unlock(&ipc_helper_lock);
         return -ESRCH;
     }
 
     debug("terminating ipc helper\n");
     ipc_helper_state = HELPER_NOTALIVE;
     set_event(&ipc_helper_event, 1);
-    unlock(ipc_helper_lock);
+    unlock(&ipc_helper_lock);
     return 0;
 }

+ 63 - 63
LibOS/shim/src/ipc/shim_ipc_nsimpl.h

@@ -118,11 +118,11 @@ static inline LEASETYPE get_lease (void)
 
 void CONCAT3(debug_print, NS, ranges) (void)
 {
-    lock(range_map_lock);
+    lock(&range_map_lock);
     sys_printf(NS_STR " ranges in process %010u:\n", cur_process.vmid);
 
     if (!range_map) {
-        unlock(range_map_lock);
+        unlock(&range_map_lock);
         return;
     }
 
@@ -170,7 +170,7 @@ void CONCAT3(debug_print, NS, ranges) (void)
         }
     }
 
-    unlock(range_map_lock);
+    unlock(&range_map_lock);
 }
 
 #define INIT_RANGE_MAP_SIZE     32
@@ -339,12 +339,12 @@ int CONCAT3(add, NS, range) (IDTYPE base, IDTYPE owner,
     if (!r)
         return -ENOMEM;
 
-    lock(range_map_lock);
+    lock(&range_map_lock);
     r->owner = NULL;
     ret = __add_range(r, off, owner, uri, lease);
     if (ret < 0)
         free(r);
-    unlock(range_map_lock);
+    unlock(&range_map_lock);
     return ret;
 }
 
@@ -367,7 +367,7 @@ int CONCAT3(add, NS, subrange) (IDTYPE idx, IDTYPE owner,
         return -ENOMEM;
 
     assert(owner);
-    lock(range_map_lock);
+    lock(&range_map_lock);
 
     s->owner = lookup_and_alloc_client(owner, uri);
     if (!s->owner) {
@@ -410,14 +410,14 @@ int CONCAT3(add, NS, subrange) (IDTYPE idx, IDTYPE owner,
     if (lease)
         *lease = s->lease;
 
-    unlock(range_map_lock);
+    unlock(&range_map_lock);
     return 0;
 
 failed:
     if (s->owner)
         put_ipc_info(s->owner);
 
-    unlock(range_map_lock);
+    unlock(&range_map_lock);
     free(s);
     return err;
 }
@@ -430,7 +430,7 @@ int CONCAT3(alloc, NS, range) (IDTYPE owner, const char * uri,
         return -ENOMEM;
 
     int ret = 0;
-    lock(range_map_lock);
+    lock(&range_map_lock);
     r->owner = NULL;
     int i = 0, j = 0;
 
@@ -462,7 +462,7 @@ int CONCAT3(alloc, NS, range) (IDTYPE owner, const char * uri,
     if (lease)
         *lease = l;
 out:
-    unlock(range_map_lock);
+    unlock(&range_map_lock);
     return ret;
 }
 
@@ -472,11 +472,11 @@ int CONCAT3(get, NS, range) (IDTYPE idx,
 {
     int off = (idx - 1) / RANGE_SIZE;
 
-    lock(range_map_lock);
+    lock(&range_map_lock);
 
     struct range * r = __get_range(off);
     if (!r) {
-        unlock(range_map_lock);
+        unlock(&range_map_lock);
         return -ESRCH;
     }
 
@@ -494,7 +494,7 @@ int CONCAT3(get, NS, range) (IDTYPE idx,
     }
 
     if (!p) {
-        unlock(range_map_lock);
+        unlock(&range_map_lock);
         return -ESRCH;
     }
 
@@ -513,7 +513,7 @@ int CONCAT3(get, NS, range) (IDTYPE idx,
         *info = p;
     }
 
-    unlock(range_map_lock);
+    unlock(&range_map_lock);
     return 0;
 }
 
@@ -522,7 +522,7 @@ int CONCAT3(del, NS, range) (IDTYPE idx)
     int off = (idx - 1) / RANGE_SIZE;
     int ret = -ESRCH;
 
-    lock(range_map_lock);
+    lock(&range_map_lock);
 
     struct range * r = __get_range(off);
     if (!r)
@@ -565,7 +565,7 @@ int CONCAT3(del, NS, range) (IDTYPE idx)
 
     ret = 0;
 failed:
-    unlock(range_map_lock);
+    unlock(&range_map_lock);
     return ret;
 }
 
@@ -575,7 +575,7 @@ int CONCAT3(del, NS, subrange) (IDTYPE idx)
     IDTYPE base = off * RANGE_SIZE + 1;
     int ret = -ESRCH;
 
-    lock(range_map_lock);
+    lock(&range_map_lock);
 
     struct range * r = __get_range(off);
     if (!r)
@@ -587,7 +587,7 @@ int CONCAT3(del, NS, subrange) (IDTYPE idx)
     CONCAT3(__del, NS, subrange) (&r->subranges->map[idx - base]);
     ret = 0;
 failed:
-    unlock(range_map_lock);
+    unlock(&range_map_lock);
     return ret;
 }
 
@@ -595,18 +595,18 @@ int CONCAT3(renew, NS, range) (IDTYPE idx, LEASETYPE * lease)
 {
     int off = (idx - 1) / RANGE_SIZE;
 
-    lock(range_map_lock);
+    lock(&range_map_lock);
 
     struct range * r = __get_range(off);
     if (!r) {
-        unlock(range_map_lock);
+        unlock(&range_map_lock);
         return -ESRCH;
     }
 
     r->lease = get_lease();
     if (lease)
         *lease = r->lease;
-    unlock(range_map_lock);
+    unlock(&range_map_lock);
     return 0;
 }
 
@@ -615,16 +615,16 @@ int CONCAT3(renew, NS, subrange) (IDTYPE idx, LEASETYPE * lease)
     int off = (idx - 1) / RANGE_SIZE;
     IDTYPE base = off * RANGE_SIZE + 1;
 
-    lock(range_map_lock);
+    lock(&range_map_lock);
 
     struct range * r = __get_range(off);
     if (!r) {
-        unlock(range_map_lock);
+        unlock(&range_map_lock);
         return -ESRCH;
     }
 
     if (!r->subranges || !r->subranges->map[idx - base]) {
-        unlock(range_map_lock);
+        unlock(&range_map_lock);
         return -ESRCH;
     }
 
@@ -632,7 +632,7 @@ int CONCAT3(renew, NS, subrange) (IDTYPE idx, LEASETYPE * lease)
     s->lease = get_lease();
     if (lease)
         *lease = s->lease;
-    unlock(range_map_lock);
+    unlock(&range_map_lock);
     return 0;
 }
 
@@ -640,7 +640,7 @@ IDTYPE CONCAT2(allocate, NS) (IDTYPE min, IDTYPE max)
 {
     IDTYPE idx = min;
     struct range * r;
-    lock(range_map_lock);
+    lock(&range_map_lock);
 
     listp_for_each_entry (r, &owned_ranges, list) {
         if (max && idx >= max)
@@ -679,7 +679,7 @@ IDTYPE CONCAT2(allocate, NS) (IDTYPE min, IDTYPE max)
     idx = 0;
 
 out:
-    unlock(range_map_lock);
+    unlock(&range_map_lock);
     return idx;
 }
 
@@ -688,7 +688,7 @@ void CONCAT2(release, NS) (IDTYPE idx)
     int off = (idx - 1) / RANGE_SIZE;
     IDTYPE base = off * RANGE_SIZE + 1;
 
-    lock(range_map_lock);
+    lock(&range_map_lock);
 
     struct range * r = __get_range(off);
     if (!r)
@@ -713,13 +713,13 @@ void CONCAT2(release, NS) (IDTYPE idx)
     }
 
 out:
-    unlock(range_map_lock);
+    unlock(&range_map_lock);
 }
 
 
 static inline void init_namespace (void)
 {
-    create_lock(range_map_lock);
+    create_lock(&range_map_lock);
 }
 
 #define _NS_ID(ns)     __NS_ID(ns)
@@ -741,16 +741,16 @@ static inline void init_namespace (void)
 static void ipc_leader_exit (struct shim_ipc_port * port, IDTYPE vmid,
                              unsigned int exitcode)
 {
-    lock(cur_process.lock);
+    lock(&cur_process.lock);
 
     if (!NS_LEADER || NS_LEADER->port != port) {
-        unlock(cur_process.lock);
+        unlock(&cur_process.lock);
         return;
     }
 
     struct shim_ipc_info * info = NS_LEADER;
     NS_LEADER = NULL;
-    unlock(cur_process.lock);
+    unlock(&cur_process.lock);
 
     debug("ipc port %p of process %u closed suggests " NS_STR " leader exits\n",
           port, vmid);
@@ -766,7 +766,7 @@ static void ipc_leader_exit (struct shim_ipc_port * port, IDTYPE vmid,
 static void __discover_ns (bool block, bool need_locate)
 {
     bool ipc_pending = false;
-    lock(cur_process.lock);
+    lock(&cur_process.lock);
 
     if (NS_LEADER) {
         if (NS_LEADER->vmid == cur_process.vmid) {
@@ -793,18 +793,18 @@ static void __discover_ns (bool block, bool need_locate)
      * succeeds, NS_LEADER will contain the IPC information of the namespace leader.
      */
 
-    unlock(cur_process.lock);
+    unlock(&cur_process.lock);
 
     // Send out an IPC message to find out the namespace information.
     // If the call is non-blocking, can't expect the answer when the function finishes.
     if (!NS_SEND(findns)(block)) {
         ipc_pending = !block; // There is still some unfinished business with IPC
-        lock(cur_process.lock);
+        lock(&cur_process.lock);
         assert(NS_LEADER);
         goto out;
     }
 
-    lock(cur_process.lock);
+    lock(&cur_process.lock);
 
     if (NS_LEADER && (!need_locate || !qstrempty(&NS_LEADER->uri)))
         goto out;
@@ -834,29 +834,29 @@ out:
             assert(!qstrempty(&NS_LEADER->uri));        // A known URI is needed
     }
 
-    unlock(cur_process.lock);
+    unlock(&cur_process.lock);
 }
 
 static int connect_ns (IDTYPE * vmid, struct shim_ipc_port ** portptr)
 {
     __discover_ns(true, false); // This function cannot be called with cur_process.lock held
-    lock(cur_process.lock);
+    lock(&cur_process.lock);
 
     if (!NS_LEADER) {
-        unlock(cur_process.lock);
+        unlock(&cur_process.lock);
         return -ESRCH;
     }
 
     if (NS_LEADER->vmid == cur_process.vmid) {
         if (vmid)
             *vmid = NS_LEADER->vmid;
-        unlock(cur_process.lock);
+        unlock(&cur_process.lock);
         return 0;
     }
 
     if (!NS_LEADER->port) {
         if (qstrempty(&NS_LEADER->uri)) {
-            unlock(cur_process.lock);
+            unlock(&cur_process.lock);
             return -ESRCH;
         }
 
@@ -864,7 +864,7 @@ static int connect_ns (IDTYPE * vmid, struct shim_ipc_port ** portptr)
                                              0, 0, 0, 0);
 
         if (!pal_handle) {
-            unlock(cur_process.lock);
+            unlock(&cur_process.lock);
             return -PAL_ERRNO;
         }
 
@@ -881,7 +881,7 @@ static int connect_ns (IDTYPE * vmid, struct shim_ipc_port ** portptr)
         *portptr = NS_LEADER->port;
     }
 
-    unlock(cur_process.lock);
+    unlock(&cur_process.lock);
     return 0;
 }
 
@@ -890,12 +890,12 @@ static int connect_ns (IDTYPE * vmid, struct shim_ipc_port ** portptr)
 #if 0
 static int disconnect_ns(struct shim_ipc_port * port)
 {
-    lock(cur_process.lock);
+    lock(&cur_process.lock);
     if (NS_LEADER && NS_LEADER->port == port) {
         NS_LEADER->port = NULL;
         put_ipc_port(port);
     }
-    unlock(cur_process.lock);
+    unlock(&cur_process.lock);
     del_ipc_port(port, IPC_PORT_LDR);
     return 0;
 }
@@ -903,9 +903,9 @@ static int disconnect_ns(struct shim_ipc_port * port)
 
 int CONCAT3(prepare, NS, leader) (void)
 {
-    lock(cur_process.lock);
+    lock(&cur_process.lock);
     bool need_discover = (!NS_LEADER || qstrempty(&NS_LEADER->uri));
-    unlock(cur_process.lock);
+    unlock(&cur_process.lock);
 
     if (need_discover)
         __discover_ns(true, true); // This function cannot be called with cur_process.lock held
@@ -954,12 +954,12 @@ static int connect_owner (IDTYPE idx, struct shim_ipc_port ** portptr,
         assert(range.port);
     }
 
-    lock(range_map_lock);
+    lock(&range_map_lock);
     if (info->port)
         put_ipc_port(info->port);
     get_ipc_port(range.port);
     info->port = range.port;
-    unlock(range_map_lock);
+    unlock(&range_map_lock);
 
 success:
     if (portptr)
@@ -984,16 +984,16 @@ int NS_SEND(findns) (bool block)
 {
     BEGIN_PROFILE_INTERVAL();
     int ret = -ESRCH;
-    lock(cur_process.lock);
+    lock(&cur_process.lock);
     if (!cur_process.parent || !cur_process.parent->port) {
-        unlock(cur_process.lock);
+        unlock(&cur_process.lock);
         goto out;
     }
 
     IDTYPE dest = cur_process.parent->vmid;
     struct shim_ipc_port * port = cur_process.parent->port;
     get_ipc_port(port);
-    unlock(cur_process.lock);
+    unlock(&cur_process.lock);
 
     if (block) {
         struct shim_ipc_msg_obj * msg =
@@ -1027,7 +1027,7 @@ int NS_CALLBACK(findns) (IPC_CALLBACK_ARGS)
 
     int ret = 0;
     __discover_ns(false, true); // This function cannot be called with cur_process.lock held
-    lock(cur_process.lock);
+    lock(&cur_process.lock);
 
     if (NS_LEADER && !qstrempty(&NS_LEADER->uri)) {
         // Got the answer! Send back the discovery now.
@@ -1046,7 +1046,7 @@ int NS_CALLBACK(findns) (IPC_CALLBACK_ARGS)
             ret = -ENOMEM;
         }
     }
-    unlock(cur_process.lock);
+    unlock(&cur_process.lock);
     SAVE_PROFILE_INTERVAL(NS_CALLBACK(findns));
     return ret;
 }
@@ -1084,7 +1084,7 @@ int NS_CALLBACK(tellns) (IPC_CALLBACK_ARGS)
     debug("ipc callback from %u: " NS_CODE_STR(TELLNS) "(%u, %s)\n",
           msg->src, msgin->vmid, msgin->uri);
 
-    lock(cur_process.lock);
+    lock(&cur_process.lock);
 
     if (NS_LEADER) {
         NS_LEADER->vmid = msgin->vmid;
@@ -1115,7 +1115,7 @@ int NS_CALLBACK(tellns) (IPC_CALLBACK_ARGS)
         thread_wakeup(obj->thread);
 
 out:
-    unlock(cur_process.lock);
+    unlock(&cur_process.lock);
     SAVE_PROFILE_INTERVAL(NS_CALLBACK(tellns));
     return ret;
 }
@@ -1549,7 +1549,7 @@ int NS_CALLBACK(queryall) (IPC_CALLBACK_ARGS)
     struct range * r;
     int ret;
 
-    lock(range_map_lock);
+    lock(&range_map_lock);
 
     int maxanswers = nowned + noffered + nsubed;
     int nanswers = 0, nowners = 0, i;
@@ -1618,7 +1618,7 @@ retry:
         goto retry;
     }
 
-    unlock(range_map_lock);
+    unlock(&range_map_lock);
 
     ret = NS_SEND(answer)(port, msg->src, nanswers, answers, nowners,
                           ownerdata, ownerdatasz, msg->seq);
@@ -1732,7 +1732,7 @@ int CONCAT2(NS, add_key) (NS_KEY * key, IDTYPE id)
     struct key * k;
     int ret = -EEXIST;
 
-    lock(range_map_lock);
+    lock(&range_map_lock);
 
     listp_for_each_entry(k, head, hlist)
         if (!KEY_COMP(&k->key, key))
@@ -1753,7 +1753,7 @@ int CONCAT2(NS, add_key) (NS_KEY * key, IDTYPE id)
           KEY_HASH(key), id, head);
     ret = 0;
 out:
-    unlock(range_map_lock);
+    unlock(&range_map_lock);
     return ret;
 }
 
@@ -1763,7 +1763,7 @@ int CONCAT2(NS, get_key) (NS_KEY * key, bool delete)
     struct key * k;
     int id = -ENOENT;
 
-    lock(range_map_lock);
+    lock(&range_map_lock);
 
     listp_for_each_entry(k, head, hlist)
         if (!KEY_COMP(&k->key, key)) {
@@ -1775,7 +1775,7 @@ int CONCAT2(NS, get_key) (NS_KEY * key, bool delete)
             break;
         }
 
-    unlock(range_map_lock);
+    unlock(&range_map_lock);
     return id;
 }
 

+ 13 - 13
LibOS/shim/src/ipc/shim_ipc_pid.c

@@ -327,7 +327,7 @@ int get_all_pid_status (struct pid_status ** status)
     struct range * r;
     int ret;
 
-    lock(range_map_lock);
+    lock(&range_map_lock);
 
 retry:
     listp_for_each_entry (r, list, list) {
@@ -369,14 +369,14 @@ next_sub:
             IDTYPE owner = p->vmid;
             char * uri = qstrtostr(&p->uri, true);
             struct shim_ipc_port * port = NULL;
-            unlock(range_map_lock);
+            unlock(&range_map_lock);
 
             PAL_HANDLE pal_handle = DkStreamOpen(uri, 0, 0, 0, 0);
 
             if (pal_handle)
                 add_ipc_port_by_id(owner, pal_handle, type, NULL, &port);
 
-            lock(range_map_lock);
+            lock(&range_map_lock);
             listp_for_each_entry(r, list, list)
                 if (r->offset >= off)
                     break;
@@ -428,7 +428,7 @@ next_sub:
                 struct pid_status * new_buf = malloc(newsize);
 
                 if (!new_buf) {
-                    unlock(range_map_lock);
+                    unlock(&range_map_lock);
                     free(range_status);
                     free(status_buf);
                     return -ENOMEM;
@@ -457,7 +457,7 @@ next_sub:
         goto retry;
     }
 
-    unlock(range_map_lock);
+    unlock(&range_map_lock);
 
     if (!nstatus) {
         free(status_buf);
@@ -522,7 +522,7 @@ int ipc_pid_getmeta_callback (IPC_CALLBACK_ARGS)
         goto out;
     }
 
-    lock(thread->lock);
+    lock(&thread->lock);
 
     switch (msgin->code) {
         case PID_META_CRED:
@@ -557,7 +557,7 @@ int ipc_pid_getmeta_callback (IPC_CALLBACK_ARGS)
             break;
     }
 
-    unlock(thread->lock);
+    unlock(&thread->lock);
     put_thread(thread);
 
     if (ret < 0)
@@ -754,7 +754,7 @@ static struct shim_lock rpc_queue_lock;
 int get_rpc_msg (IDTYPE * sender, void * buf, int len)
 {
     create_lock_runtime(&rpc_queue_lock);
-    lock(rpc_queue_lock);
+    lock(&rpc_queue_lock);
 
     if (!listp_empty(&rpc_msgs)) {
         struct rpcmsg * m = listp_first_entry(&rpc_msgs, struct rpcmsg, list);
@@ -764,13 +764,13 @@ int get_rpc_msg (IDTYPE * sender, void * buf, int len)
         if (sender)
             *sender = m->sender;
         memcpy(buf, m->payload, len);
-        unlock(rpc_queue_lock);
+        unlock(&rpc_queue_lock);
         return len;
     }
 
     struct rpcreq * r = malloc(sizeof(struct rpcreq));
     if (!r) {
-        unlock(rpc_queue_lock);
+        unlock(&rpc_queue_lock);
         return -ENOMEM;
     }
 
@@ -780,7 +780,7 @@ int get_rpc_msg (IDTYPE * sender, void * buf, int len)
     r->buffer = buf;
     thread_setwait(&r->thread, NULL);
     listp_add_tail(r, &rpc_reqs, list);
-    unlock(rpc_queue_lock);
+    unlock(&rpc_queue_lock);
     thread_sleep(NO_TIMEOUT);
     put_thread(r->thread);
     if (sender)
@@ -799,7 +799,7 @@ int ipc_pid_sendrpc_callback (IPC_CALLBACK_ARGS)
           msgin->sender, msgin->len);
 
     create_lock_runtime(&rpc_queue_lock);
-    lock(rpc_queue_lock);
+    lock(&rpc_queue_lock);
 
     if (!listp_empty(&rpc_reqs)) {
         struct rpcreq * r = listp_first_entry(&rpc_reqs, struct rpcreq, list);
@@ -824,7 +824,7 @@ int ipc_pid_sendrpc_callback (IPC_CALLBACK_ARGS)
     memcpy(m->payload, msgin->payload, msgin->len);
     listp_add_tail(m, &rpc_msgs, list);
 out:
-    unlock(rpc_queue_lock);
+    unlock(&rpc_queue_lock);
     SAVE_PROFILE_INTERVAL(ipc_pid_sendrpc_callback);
     return ret;
 }

+ 4 - 4
LibOS/shim/src/ipc/shim_ipc_sysv.c

@@ -436,7 +436,7 @@ int ipc_sysv_msgmov_callback (IPC_CALLBACK_ARGS)
     struct shim_handle * hdl = container_of(msgq, struct shim_handle,
                                             info.msg);
 
-    lock(hdl->lock);
+    lock(&hdl->lock);
     int nscores = (msgin->nscores > MAX_SYSV_CLIENTS) ?
                   MAX_SYSV_CLIENTS : msgin->nscores;
     if (nscores)
@@ -444,7 +444,7 @@ int ipc_sysv_msgmov_callback (IPC_CALLBACK_ARGS)
     if (nscores < MAX_SYSV_CLIENTS)
         memset(msgq->scores + nscores, 0,
                sizeof(struct sysv_score) * (MAX_SYSV_CLIENTS - nscores));
-    unlock(hdl->lock);
+    unlock(&hdl->lock);
 
     ret = recover_msg_ownership(msgq);
 
@@ -826,7 +826,7 @@ int ipc_sysv_semmov_callback (IPC_CALLBACK_ARGS)
     struct shim_handle * hdl = container_of(sem, struct shim_handle,
                                             info.sem);
 
-    lock(hdl->lock);
+    lock(&hdl->lock);
     int nscores = (msgin->nscores > MAX_SYSV_CLIENTS) ?
                   MAX_SYSV_CLIENTS : msgin->nscores;
     if (nscores)
@@ -834,7 +834,7 @@ int ipc_sysv_semmov_callback (IPC_CALLBACK_ARGS)
     if (nscores < MAX_SYSV_CLIENTS)
         memset(sem->scores + nscores, 0,
                sizeof(struct sysv_score) * (MAX_SYSV_CLIENTS - nscores));
-    unlock(hdl->lock);
+    unlock(&hdl->lock);
 
     ret = recover_sem_ownership(sem, sems, msgin->nsems, clients,
                                 msgin->nsrcs);

+ 17 - 17
LibOS/shim/src/shim_async.c

@@ -73,7 +73,7 @@ int64_t install_async_event (PAL_HANDLE object, unsigned long time,
     event->install_time = time ? install_time : 0;
     event->expire_time  = time ? install_time + time : 0;
 
-    lock(async_helper_lock);
+    lock(&async_helper_lock);
 
     struct async_event * tmp;
 
@@ -115,7 +115,7 @@ int64_t install_async_event (PAL_HANDLE object, unsigned long time,
     if (async_helper_state == HELPER_NOTALIVE)
         create_async_helper();
 
-    unlock(async_helper_lock);
+    unlock(&async_helper_lock);
 
     set_event(&async_helper_event, 1);
     return rv;
@@ -126,7 +126,7 @@ int init_async (void)
     /* This is early enough in init that we can write this variable without
      * the lock. */
     async_helper_state = HELPER_NOTALIVE;
-    create_lock(async_helper_lock);
+    create_lock(&async_helper_lock);
     create_event(&async_helper_event);
     return 0;
 }
@@ -145,9 +145,9 @@ static void shim_async_helper (void * arg)
     debug_setbuf(&tcb.shim_tcb, true);
     debug("set tcb to %p\n", &tcb);
 
-    lock(async_helper_lock);
+    lock(&async_helper_lock);
     bool notme = (self != async_helper_thread);
-    unlock(async_helper_lock);
+    unlock(&async_helper_lock);
 
     if (notme) {
         put_thread(self);
@@ -199,7 +199,7 @@ static void shim_async_helper (void * arg)
 
                 next_event->callback(next_event->caller, next_event->arg);
 
-                lock(async_helper_lock);
+                lock(&async_helper_lock);
                 /* DEP: Events can only be on the async list */
                 listp_del(next_event, &async_list, list);
                 free(next_event);
@@ -215,22 +215,22 @@ update_status:
             if (async_helper_state == HELPER_NOTALIVE) {
                 break;
             } else {
-                lock(async_helper_lock);
+                lock(&async_helper_lock);
                 goto update_list;
             }
         }
 
         struct async_event * tmp, * n;
 
-        lock(async_helper_lock);
+        lock(&async_helper_lock);
 
         listp_for_each_entry_safe(tmp, n, &async_list, list) {
             if (tmp->object == polled) {
                 debug("async event trigger at %lu\n",
                       latest_time);
-                unlock(async_helper_lock);
+                unlock(&async_helper_lock);
                 tmp->callback(tmp->caller, tmp->arg);
-                lock(async_helper_lock);
+                lock(&async_helper_lock);
                 break;
             }
         }
@@ -259,16 +259,16 @@ update_list:
                 debug("async event trigger at %lu (expire at %lu)\n",
                       latest_time, tmp->expire_time);
                 listp_del(tmp, &async_list, list);
-                unlock(async_helper_lock);
+                unlock(&async_helper_lock);
                 tmp->callback(tmp->caller, tmp->arg);
                 free(tmp);
-                lock(async_helper_lock);
+                lock(&async_helper_lock);
             }
 
             idle_cycles = 0;
         }
 
-        unlock(async_helper_lock);
+        unlock(&async_helper_lock);
 
         if (idle_cycles++ == MAX_IDLE_CYCLES) {
             debug("async helper thread reach helper cycle\n");
@@ -278,10 +278,10 @@ update_list:
         }
     }
 
-    lock(async_helper_lock);
+    lock(&async_helper_lock);
     async_helper_state = HELPER_NOTALIVE;
     async_helper_thread = NULL;
-    unlock(async_helper_lock);
+    unlock(&async_helper_lock);
     put_thread(self);
     debug("async helper thread terminated\n");
     free(local_objects);
@@ -337,12 +337,12 @@ struct shim_thread * terminate_async_helper (void)
     if (async_helper_state != HELPER_ALIVE)
         return NULL;
 
-    lock(async_helper_lock);
+    lock(&async_helper_lock);
     struct shim_thread * ret = async_helper_thread;
     if (ret)
         get_thread(ret);
     async_helper_state = HELPER_NOTALIVE;
-    unlock(async_helper_lock);
+    unlock(&async_helper_lock);
     set_event(&async_helper_event, 1);
     return ret;
 }

+ 1 - 1
LibOS/shim/src/shim_init.c

@@ -702,7 +702,7 @@ __attribute__((noreturn)) void* shim_init (int argc, void * args)
     allocshift = allocsize - 1;
     allocmask = ~allocshift;
 
-    create_lock(__master_lock);
+    create_lock(&__master_lock);
 
     int * argcp = &argc;
     const char ** argv, ** envp, ** argp = NULL;

+ 3 - 3
LibOS/shim/src/shim_malloc.c

@@ -40,8 +40,8 @@
 
 static struct shim_lock slab_mgr_lock;
 
-#define system_lock()       lock(slab_mgr_lock)
-#define system_unlock()     unlock(slab_mgr_lock)
+#define system_lock()       lock(&slab_mgr_lock)
+#define system_unlock()     unlock(&slab_mgr_lock)
 #define PAGE_SIZE           allocsize
 
 #ifdef SLAB_DEBUG_TRACE
@@ -108,7 +108,7 @@ void __system_free (void * addr, size_t size)
 
 int init_slab (void)
 {
-    create_lock(slab_mgr_lock);
+    create_lock(&slab_mgr_lock);
     slab_mgr = create_slab_mgr();
     return 0;
 }

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

@@ -352,10 +352,10 @@ int shim_do_clone (int flags, void * user_stack_addr, int * parent_tidptr,
         if (ret < 0)
             goto failed;
 
-        lock(thread->lock);
+        lock(&thread->lock);
         handle_map = thread->handle_map;
         thread->handle_map = NULL;
-        unlock(thread->lock);
+        unlock(&thread->lock);
 
         if (handle_map)
             put_handle_map(handle_map);

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

@@ -136,10 +136,10 @@ static void update_epoll (struct shim_epoll_handle * epoll)
 int delete_from_epoll_handles (struct shim_handle * handle)
 {
     while (1) {
-        lock(handle->lock);
+        lock(&handle->lock);
 
         if (listp_empty(&handle->epolls)) {
-            unlock(handle->lock);
+            unlock(&handle->lock);
             break;
         }
 
@@ -147,7 +147,7 @@ int delete_from_epoll_handles (struct shim_handle * handle)
                                  struct shim_epoll_fd, back);
 
         listp_del(epoll_fd, &handle->epolls, back);
-        unlock(handle->lock);
+        unlock(&handle->lock);
         put_handle(handle);
 
         struct shim_handle * epoll_hdl = epoll_fd->epoll;
@@ -156,14 +156,14 @@ int delete_from_epoll_handles (struct shim_handle * handle)
         debug("delete handle %p from epoll handle %p\n", handle,
               &epoll_hdl->info.epoll);
 
-        lock(epoll_hdl->lock);
+        lock(&epoll_hdl->lock);
 
         listp_del(epoll_fd, &epoll->fds, list);
         free(epoll_fd);
 
         epoll_hdl->info.epoll.nfds--;
         update_epoll(&epoll_hdl->info.epoll);
-        unlock(epoll_hdl->lock);
+        unlock(&epoll_hdl->lock);
         put_handle(epoll_hdl);
     }
 
@@ -187,7 +187,7 @@ int shim_do_epoll_ctl (int epfd, int op, int fd,
     struct shim_epoll_handle * epoll = &epoll_hdl->info.epoll;
     struct shim_epoll_fd * epoll_fd;
 
-    lock(epoll_hdl->lock);
+    lock(&epoll_hdl->lock);
 
     switch (op) {
         case EPOLL_CTL_ADD: {
@@ -227,10 +227,10 @@ int shim_do_epoll_ctl (int epfd, int op, int fd,
 
             /* Register the epoll handle */
             get_handle(epoll_hdl);
-            lock(hdl->lock);
+            lock(&hdl->lock);
             INIT_LIST_HEAD(epoll_fd, back);
             listp_add_tail(epoll_fd, &hdl->epolls, back);
-            unlock(hdl->lock);
+            unlock(&hdl->lock);
 
             INIT_LIST_HEAD(epoll_fd, list);
             listp_add_tail(epoll_fd, &epoll->fds, list);
@@ -256,9 +256,9 @@ int shim_do_epoll_ctl (int epfd, int op, int fd,
                     struct shim_handle * hdl = epoll_fd->handle;
 
                     /* Unregister the epoll handle */
-                    lock(hdl->lock);
+                    lock(&hdl->lock);
                     listp_del(epoll_fd, &hdl->epolls, back);
-                    unlock(hdl->lock);
+                    unlock(&hdl->lock);
                     put_handle(epoll_hdl);
 
                     debug("delete handle %p from epoll handle %p\n",
@@ -282,7 +282,7 @@ int shim_do_epoll_ctl (int epfd, int op, int fd,
 update:
     update_epoll(epoll);
 out:
-    unlock(epoll_hdl->lock);
+    unlock(&epoll_hdl->lock);
     put_handle(epoll_hdl);
     return ret;
 }
@@ -305,7 +305,7 @@ int shim_do_epoll_wait (int epfd, struct __kernel_epoll_event * events,
     int npals, nread;
     bool need_update = false;
 
-    lock(epoll_hdl->lock);
+    lock(&epoll_hdl->lock);
 retry:
     if (!(npals = epoll->npals))
         goto reply;
@@ -319,12 +319,12 @@ retry:
     if ((nread = epoll->nread))
         epoll->nwaiters++;
 
-    unlock(epoll_hdl->lock);
+    unlock(&epoll_hdl->lock);
 
     PAL_HANDLE polled = DkObjectsWaitAny(nread ? npals + 1 : npals, pal_handles,
                                          nread ? (timeout == -1 ? NO_TIMEOUT : (PAL_NUM) timeout) : 0);
 
-    lock(epoll_hdl->lock);
+    lock(&epoll_hdl->lock);
 
     if (nread)
         epoll->nwaiters--;
@@ -377,7 +377,7 @@ reply:
     if (need_update)
         update_epoll(epoll);
 
-    unlock(epoll_hdl->lock);
+    unlock(&epoll_hdl->lock);
     ret = nevents;
     put_handle(epoll_hdl);
     return ret;

+ 5 - 5
LibOS/shim/src/sys/shim_exec.c

@@ -454,7 +454,7 @@ err:
         argv = new_argv;
     }
 
-    lock(cur_thread->lock);
+    lock(&cur_thread->lock);
     put_handle(cur_thread->exec);
     cur_thread->exec = exec;
 
@@ -470,11 +470,11 @@ err:
     cur_thread->tcb       = NULL;
     cur_thread->user_tcb  = false;
     cur_thread->in_vm     = false;
-    unlock(cur_thread->lock);
+    unlock(&cur_thread->lock);
 
     ret = do_migrate_process(&migrate_execve, exec, argv, cur_thread, envp);
 
-    lock(cur_thread->lock);
+    lock(&cur_thread->lock);
     cur_thread->stack       = stack;
     cur_thread->stack_top   = stack_top;
     cur_thread->frameptr    = frameptr;
@@ -483,13 +483,13 @@ err:
 
     if (ret < 0) {
         cur_thread->in_vm = true;
-        unlock(cur_thread->lock);
+        unlock(&cur_thread->lock);
         return ret;
     }
 
     struct shim_handle_map * handle_map = cur_thread->handle_map;
     cur_thread->handle_map = NULL;
-    unlock(cur_thread->lock);
+    unlock(&cur_thread->lock);
     if (handle_map)
         put_handle_map(handle_map);
 

+ 5 - 5
LibOS/shim/src/sys/shim_exit.c

@@ -52,12 +52,12 @@ int thread_exit(struct shim_thread * self, bool send_ipc)
     if (self->in_vm && send_ipc)
         ipc_cld_exit_send(self->ppid, self->tid, self->exit_code, self->term_signal);
 
-    lock(self->lock);
+    lock(&self->lock);
 
     if (!self->is_alive) {
         debug("thread %d is dead\n", self->tid);
     out:
-        unlock(self->lock);
+        unlock(&self->lock);
         return 0;
     }
 
@@ -82,7 +82,7 @@ int thread_exit(struct shim_thread * self, bool send_ipc)
         assert(parent->child_exit_event);
         debug("thread exits, notifying thread %d\n", parent->tid);
 
-        lock(parent->lock);
+        lock(&parent->lock);
         listp_del_init(self, &parent->children, siblings);
         listp_add_tail(self, &parent->exited_children, siblings);
 
@@ -99,7 +99,7 @@ int thread_exit(struct shim_thread * self, bool send_ipc)
 
             append_signal(parent, SIGCHLD, &info, true);
         }
-        unlock(parent->lock);
+        unlock(&parent->lock);
 
         DkEventSet(parent->child_exit_event);
     } else {
@@ -110,7 +110,7 @@ int thread_exit(struct shim_thread * self, bool send_ipc)
     struct robust_list_head * robust_list = (void *) self->robust_list;
     self->robust_list = NULL;
 
-    unlock(self->lock);
+    unlock(&self->lock);
 
     if (handle_map)
         put_handle_map(handle_map);

+ 6 - 6
LibOS/shim/src/sys/shim_fcntl.c

@@ -106,10 +106,10 @@ int shim_do_fcntl (int fd, int cmd, unsigned long arg)
          *   Set the file descriptor flags to the value specified by arg.
          */
         case F_SETFD:
-            lock(handle_map->lock);
+            lock(&handle_map->lock);
             if (HANDLE_ALLOCATED(handle_map->map[fd]))
                 handle_map->map[fd]->flags = arg & FD_CLOEXEC;
-            unlock(handle_map->lock);
+            unlock(&handle_map->lock);
             ret = 0;
             break;
 
@@ -126,9 +126,9 @@ int shim_do_fcntl (int fd, int cmd, unsigned long arg)
          */
 
         case F_GETFL:
-            lock(hdl->lock);
+            lock(&hdl->lock);
             flags = hdl->flags;
-            unlock(hdl->lock);
+            unlock(&hdl->lock);
             ret = flags;
             break;
 
@@ -143,13 +143,13 @@ int shim_do_fcntl (int fd, int cmd, unsigned long arg)
 #define FCNTL_SETFL_MASK (O_APPEND|O_NONBLOCK)
 
         case F_SETFL:
-            lock(hdl->lock);
+            lock(&hdl->lock);
             if (hdl->fs && hdl->fs->fs_ops &&
                 hdl->fs->fs_ops->setflags)
                 hdl->fs->fs_ops->setflags(hdl, arg & FCNTL_SETFL_MASK);
             hdl->flags = (hdl->flags & ~FCNTL_SETFL_MASK) |
                          (arg & FCNTL_SETFL_MASK);
-            unlock(hdl->lock);
+            unlock(&hdl->lock);
             ret = 0;
             break;
 

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

@@ -100,10 +100,10 @@ int shim_do_fork (void)
         return ret;
     }
 
-    lock(new_thread->lock);
+    lock(&new_thread->lock);
     struct shim_handle_map * handle_map = new_thread->handle_map;
     new_thread->handle_map = NULL;
-    unlock(new_thread->lock);
+    unlock(&new_thread->lock);
     if (handle_map)
         put_handle_map(handle_map);
 

+ 4 - 4
LibOS/shim/src/sys/shim_fs.c

@@ -203,10 +203,10 @@ out:
 mode_t shim_do_umask (mode_t mask)
 {
     struct shim_thread * cur = get_cur_thread();
-    lock(cur->lock);
+    lock(&cur->lock);
     mode_t old = cur->umask;
     cur->umask = mask & 0777;
-    unlock(cur->lock);
+    unlock(&cur->lock);
     return old;
 }
 
@@ -818,10 +818,10 @@ int shim_do_chroot (const char * filename)
     }
 
     struct shim_thread * thread = get_cur_thread();
-    lock(thread->lock);
+    lock(&thread->lock);
     put_dentry(thread->root);
     thread->root = dent;
-    unlock(thread->lock);
+    unlock(&thread->lock);
 out:
     return ret;
 }

+ 20 - 20
LibOS/shim/src/sys/shim_futex.c

@@ -70,7 +70,7 @@ int shim_do_futex (int * uaddr, int op, int val, void * utime,
         return -EINVAL;
 
     create_lock_runtime(&futex_list_lock);
-    lock(futex_list_lock);
+    lock(&futex_list_lock);
 
     listp_for_each_entry(tmp, &futex_list, list)
         if (tmp->uaddr == uaddr) {
@@ -83,7 +83,7 @@ int shim_do_futex (int * uaddr, int op, int val, void * utime,
         get_handle(hdl);
     } else {
         if (!(hdl = get_new_handle())) {
-            unlock(futex_list_lock);
+            unlock(&futex_list_lock);
             return -ENOMEM;
         }
 
@@ -109,7 +109,7 @@ int shim_do_futex (int * uaddr, int op, int val, void * utime,
             get_handle(hdl2);
         } else {
             if (!(hdl2 = get_new_handle())) {
-                unlock(futex_list_lock);
+                unlock(&futex_list_lock);
                 return -ENOMEM;
             }
 
@@ -125,8 +125,8 @@ int shim_do_futex (int * uaddr, int op, int val, void * utime,
         val2 = (uint32_t)(uint64_t) utime;
     }
 
-    unlock(futex_list_lock);
-    lock(hdl->lock);
+    unlock(&futex_list_lock);
+    lock(&hdl->lock);
     uint64_t timeout_us = NO_TIMEOUT;
 
     switch (futex_op) {
@@ -182,14 +182,14 @@ int shim_do_futex (int * uaddr, int op, int val, void * utime,
             waiter.bitset = bitset;
             listp_add_tail(&waiter, &futex->waiters, list);
 
-            unlock(hdl->lock);
+            unlock(&hdl->lock);
             ret = thread_sleep(timeout_us);
             /* DEP 1/28/17: Should return ETIMEDOUT, not EAGAIN, on timeout. */
             if (ret == -EAGAIN)
                 ret = -ETIMEDOUT;
             if (ret == -ETIMEDOUT)
                 listp_del(&waiter, &futex->waiters, list);
-            lock(hdl->lock);
+            lock(&hdl->lock);
             /* Chia-Che 10/17/17: FUTEX_WAKE should remove the waiter
              * from the list; if not, we should remove it now. */
             if (!list_empty(&waiter, list))
@@ -261,10 +261,10 @@ int shim_do_futex (int * uaddr, int op, int val, void * utime,
             }
 
             if (cmpval) {
-                unlock(hdl->lock);
+                unlock(&hdl->lock);
                 put_handle(hdl);
                 hdl = hdl2;
-                lock(hdl->lock);
+                lock(&hdl->lock);
                 debug("FUTEX_WAKE: %p (val = %d) count = %d\n", uaddr2,
                       *uaddr2, val2);
                 listp_for_each_entry_safe(waiter, wtmp, &futex2->waiters, list) {
@@ -297,9 +297,9 @@ int shim_do_futex (int * uaddr, int op, int val, void * utime,
                     break;
             }
 
-            lock(hdl2->lock);
+            lock(&hdl2->lock);
             listp_splice_init(&futex->waiters, &futex2->waiters, list, futex_waiter);
-            unlock(hdl2->lock);
+            unlock(&hdl2->lock);
             put_handle(hdl2);
             ret = nwaken;
             break;
@@ -315,7 +315,7 @@ int shim_do_futex (int * uaddr, int op, int val, void * utime,
             break;
     }
 
-    unlock(hdl->lock);
+    unlock(&hdl->lock);
     put_handle(hdl);
     return ret;
 }
@@ -365,7 +365,7 @@ void release_robust_list (struct robust_list_head * head)
         void * futex_addr = (void *) robust + futex_offset;
         struct shim_futex_handle * tmp, * futex = NULL;
 
-        lock(futex_list_lock);
+        lock(&futex_list_lock);
 
         listp_for_each_entry(tmp, &futex_list, list)
             if (tmp->uaddr == futex_addr) {
@@ -373,7 +373,7 @@ void release_robust_list (struct robust_list_head * head)
                 break;
             }
 
-        unlock(futex_list_lock);
+        unlock(&futex_list_lock);
 
         if (!futex)
             continue;
@@ -382,7 +382,7 @@ void release_robust_list (struct robust_list_head * head)
         struct shim_handle * hdl =
             container_of(futex, struct shim_handle, info.futex);
         get_handle(hdl);
-        lock(hdl->lock);
+        lock(&hdl->lock);
 
         debug("release robust list: %p\n", futex_addr);
         *(int *) futex_addr = 0;
@@ -391,7 +391,7 @@ void release_robust_list (struct robust_list_head * head)
             thread_wakeup(waiter->thread);
         }
 
-        unlock(hdl->lock);
+        unlock(&hdl->lock);
         put_handle(hdl);
     }
 }
@@ -404,7 +404,7 @@ void release_clear_child_id (int * clear_child_tid)
     create_lock_runtime(&futex_list_lock);
 
     struct shim_futex_handle * tmp, * futex = NULL;
-    lock(futex_list_lock);
+    lock(&futex_list_lock);
 
     listp_for_each_entry(tmp, &futex_list, list)
         if (tmp->uaddr == (void *) clear_child_tid) {
@@ -412,7 +412,7 @@ void release_clear_child_id (int * clear_child_tid)
             break;
         }
 
-    unlock(futex_list_lock);
+    unlock(&futex_list_lock);
 
     if (!futex)
         return;
@@ -421,7 +421,7 @@ void release_clear_child_id (int * clear_child_tid)
     struct shim_handle * hdl =
             container_of(futex, struct shim_handle, info.futex);
     get_handle(hdl);
-    lock(hdl->lock);
+    lock(&hdl->lock);
 
     debug("release futex at %p\n", clear_child_tid);
     *clear_child_tid = 0;
@@ -430,6 +430,6 @@ void release_clear_child_id (int * clear_child_tid)
         thread_wakeup(waiter->thread);
     }
 
-    unlock(hdl->lock);
+    unlock(&hdl->lock);
     put_handle(hdl);
 }

+ 4 - 4
LibOS/shim/src/sys/shim_getcwd.c

@@ -95,10 +95,10 @@ int shim_do_chdir (const char * filename)
         return -ENOTDIR;
     }
 
-    lock(thread->lock);
+    lock(&thread->lock);
     put_dentry(thread->cwd);
     thread->cwd = dent;
-    unlock(thread->lock);
+    unlock(&thread->lock);
     return 0;
 }
 
@@ -117,11 +117,11 @@ int shim_do_fchdir (int fd)
         return -ENOTDIR;
     }
 
-    lock(thread->lock);
+    lock(&thread->lock);
     get_dentry(dent);
     put_dentry(thread->cwd);
     thread->cwd = dent;
-    unlock(thread->lock);
+    unlock(&thread->lock);
     put_handle(hdl);
     return 0;
 }

+ 31 - 31
LibOS/shim/src/sys/shim_msgget.c

@@ -139,9 +139,9 @@ static int __add_msg_handle (unsigned long key, IDTYPE msqid, bool owned,
 
 int add_msg_handle (unsigned long key, IDTYPE id, bool owned)
 {
-    lock(msgq_list_lock);
+    lock(&msgq_list_lock);
     int ret = __add_msg_handle(key, id, owned, NULL);
-    unlock(msgq_list_lock);
+    unlock(&msgq_list_lock);
     return ret;
 }
 
@@ -151,7 +151,7 @@ struct shim_msg_handle * get_msg_handle_by_key (unsigned long key)
     LISTP_TYPE(shim_msg_handle) * key_head = &msgq_key_hlist[MSGQ_HASH(key)];
     struct shim_msg_handle * tmp, * found = NULL;
 
-    lock(msgq_list_lock);
+    lock(&msgq_list_lock);
 
     listp_for_each_entry(tmp, key_head, key_hlist)
         if (tmp->msqkey == key) {
@@ -162,7 +162,7 @@ struct shim_msg_handle * get_msg_handle_by_key (unsigned long key)
     if (found)
         get_handle(MSG_TO_HANDLE(found));
 
-    unlock(msgq_list_lock);
+    unlock(&msgq_list_lock);
     return found;
 }
 
@@ -171,7 +171,7 @@ struct shim_msg_handle * get_msg_handle_by_id (IDTYPE msqid)
     LISTP_TYPE(shim_msg_handle) * qid_head = &msgq_qid_hlist[MSGQ_HASH(msqid)];
     struct shim_msg_handle * tmp, * found = NULL;
 
-    lock(msgq_list_lock);
+    lock(&msgq_list_lock);
 
     listp_for_each_entry(tmp, qid_head, qid_hlist)
         if (tmp->msqid == msqid) {
@@ -182,7 +182,7 @@ struct shim_msg_handle * get_msg_handle_by_id (IDTYPE msqid)
     if (found)
         get_handle(MSG_TO_HANDLE(found));
 
-    unlock(msgq_list_lock);
+    unlock(&msgq_list_lock);
     return found;
 }
 
@@ -242,7 +242,7 @@ static int __del_msg_handle (struct shim_msg_handle * msgq)
 
     struct shim_handle * hdl = MSG_TO_HANDLE(msgq);
 
-    lock(msgq_list_lock);
+    lock(&msgq_list_lock);
     listp_del_init(msgq, &msgq_list, list);
     put_handle(hdl);
     if (!list_empty(msgq, key_hlist)) {
@@ -257,16 +257,16 @@ static int __del_msg_handle (struct shim_msg_handle * msgq)
         listp_del_init(msgq, qid_head, qid_hlist);
         put_handle(hdl);
     }
-    unlock(msgq_list_lock);
+    unlock(&msgq_list_lock);
     return 0;
 }
 
 int del_msg_handle (struct shim_msg_handle * msgq)
 {
     struct shim_handle * hdl = MSG_TO_HANDLE(msgq);
-    lock(hdl->lock);
+    lock(&hdl->lock);
     int ret = __del_msg_handle(msgq);
-    unlock(hdl->lock);
+    unlock(&hdl->lock);
     return ret;
 }
 
@@ -337,9 +337,9 @@ static int connect_msg_handle (int msqid, struct shim_msg_handle ** msgqp)
             return ret;
 
         if (!msgq) {
-            lock(msgq_list_lock);
+            lock(&msgq_list_lock);
             ret = __add_msg_handle(IPC_PRIVATE, msqid, false, &msgq);
-            unlock(msgq_list_lock);
+            unlock(&msgq_list_lock);
             if (ret < 0)
                 return ret;
         }
@@ -355,7 +355,7 @@ static int connect_msg_handle (int msqid, struct shim_msg_handle ** msgqp)
 int recover_msg_ownership (struct shim_msg_handle * msgq)
 {
     struct shim_handle * hdl = MSG_TO_HANDLE(msgq);
-    lock(hdl->lock);
+    lock(&hdl->lock);
     assert(!msgq->owned);
     int ret = __load_msg_persist(msgq, true);
 
@@ -367,7 +367,7 @@ int recover_msg_ownership (struct shim_msg_handle * msgq)
     msgq->owned = true;
     DkEventSet(msgq->event);
 out:
-    unlock(hdl->lock);
+    unlock(&hdl->lock);
     return 0;
 }
 
@@ -592,7 +592,7 @@ int add_sysv_msg (struct shim_msg_handle * msgq,
 
     struct shim_handle * hdl = MSG_TO_HANDLE(msgq);
     int ret = 0;
-    lock(hdl->lock);
+    lock(&hdl->lock);
 
     if (msgq->deleted) {
         ret = -EIDRM;
@@ -600,7 +600,7 @@ int add_sysv_msg (struct shim_msg_handle * msgq,
     }
 
     if (!msgq->owned) {
-        unlock(hdl->lock);
+        unlock(&hdl->lock);
         ret = ipc_sysv_msgsnd_send(src->port, src->vmid, msgq->msqid,
                                    type, data, size, src->seq);
         goto out;
@@ -621,7 +621,7 @@ int add_sysv_msg (struct shim_msg_handle * msgq,
     DkEventSet(msgq->event);
     ret  = 0;
 out_locked:
-    unlock(hdl->lock);
+    unlock(&hdl->lock);
 out:
     SAVE_PROFILE_INTERVAL(add_sysv_msg);
     return ret;
@@ -677,7 +677,7 @@ int get_sysv_msg (struct shim_msg_handle * msgq,
     struct shim_handle * hdl = MSG_TO_HANDLE(msgq);
     struct msg_item * msg = NULL;
     struct msg_type * alltypes = NULL, * mtype = NULL;
-    lock(hdl->lock);
+    lock(&hdl->lock);
 
     if (msgq->deleted) {
         ret = -EIDRM;
@@ -714,13 +714,13 @@ int get_sysv_msg (struct shim_msg_handle * msgq,
         }
 
 unowned:
-        unlock(hdl->lock);
+        unlock(&hdl->lock);
         ret = ipc_sysv_msgrcv_send(msqid, type, flags, data, size);
         if (ret != -EAGAIN &&
             ret != -ECONNREFUSED)
             goto out;
 
-        lock(hdl->lock);
+        lock(&hdl->lock);
 
         if (!msgq->owned)
             goto out_locked;
@@ -744,9 +744,9 @@ unowned:
         if (flags & IPC_NOWAIT || src)
             break;
 
-        unlock(hdl->lock);
+        unlock(&hdl->lock);
         while (!DkObjectsWaitAny(1, &msgq->event, NO_TIMEOUT));
-        lock(hdl->lock);
+        lock(&hdl->lock);
 
         if (!msgq->owned)
             goto unowned;
@@ -763,7 +763,7 @@ unowned:
 
     ret = msg->size;
 out_locked:
-    unlock(hdl->lock);
+    unlock(&hdl->lock);
 out:
     SAVE_PROFILE_INTERVAL(get_sysv_msg);
     return ret;
@@ -931,18 +931,18 @@ int store_all_msg_persist (void)
 {
     struct shim_msg_handle * msgq, *n;
 
-    lock(msgq_list_lock);
+    lock(&msgq_list_lock);
 
     listp_for_each_entry_safe(msgq, n, &msgq_list, list)
         if (msgq->owned) {
             struct shim_handle * hdl = container_of(msgq, struct shim_handle,
                                                     info.msg);
-            lock(hdl->lock);
+            lock(&hdl->lock);
             __store_msg_persist(msgq);
-            unlock(hdl->lock);
+            unlock(&hdl->lock);
         }
 
-    unlock(msgq_list_lock);
+    unlock(&msgq_list_lock);
     return 0;
 }
 
@@ -959,18 +959,18 @@ int shim_do_msgpersist (int msqid, int cmd)
                 return -EINVAL;
 
             hdl = container_of(msgq, struct shim_handle, info.msg);
-            lock(hdl->lock);
+            lock(&hdl->lock);
             ret = __store_msg_persist(msgq);
-            unlock(hdl->lock);
+            unlock(&hdl->lock);
             put_msg_handle(msgq);
             break;
 
         case MSGPERSIST_LOAD:
-            lock(msgq_list_lock);
+            lock(&msgq_list_lock);
             ret = __add_msg_handle(0, msqid, false, &msgq);
             if (!ret)
                 ret = __load_msg_persist(msgq, true);
-            unlock(msgq_list_lock);
+            unlock(&msgq_list_lock);
             put_msg_handle(msgq);
             break;
     }

+ 4 - 4
LibOS/shim/src/sys/shim_open.c

@@ -354,7 +354,7 @@ size_t shim_do_getdents (int fd, struct linux_dirent * buf, size_t count)
 
     /* we are grabbing the lock because the handle content is actually
        updated */
-    lock(hdl->lock);
+    lock(&hdl->lock);
 
     struct shim_dir_handle * dirhdl = &hdl->info.dir;
     struct shim_dentry * dent = hdl->dentry;
@@ -432,7 +432,7 @@ done:
                        (dirhdl->ptr && *dirhdl->ptr)))
         ret = -EINVAL;
 out:
-    unlock(hdl->lock);
+    unlock(&hdl->lock);
 out_no_unlock:
     put_handle(hdl);
     return ret;
@@ -460,7 +460,7 @@ size_t shim_do_getdents64 (int fd, struct linux_dirent64 * buf, size_t count)
         goto out;
     }
 
-    lock(hdl->lock);
+    lock(&hdl->lock);
 
     struct shim_dir_handle * dirhdl = &hdl->info.dir;
     struct shim_dentry * dent = hdl->dentry;
@@ -528,7 +528,7 @@ done:
     if (bytes == 0 && (dirhdl->dot || dirhdl->dotdot ||
                        (dirhdl->ptr && *dirhdl->ptr)))
         ret = -EINVAL;
-    unlock(hdl->lock);
+    unlock(&hdl->lock);
 out:
     put_handle(hdl);
     return ret;

+ 3 - 3
LibOS/shim/src/sys/shim_poll.c

@@ -124,7 +124,7 @@ static int __do_poll (int npolls, struct poll_handle * polls,
     BEGIN_PROFILE_INTERVAL_SET(begin_time);
 #endif
 
-    lock(map->lock);
+    lock(&map->lock);
 
     for (p = polls ; p < polls + npolls ; p++) {
         bool do_r = p->flags & DO_R;
@@ -218,7 +218,7 @@ no_op:
 
                 if (polled < 0) {
                     if (polled != -EAGAIN) {
-                        unlock(map->lock);
+                        unlock(&map->lock);
                         ret = polled;
                         goto done_polling;
                     }
@@ -279,7 +279,7 @@ done_finding:
         SAVE_PROFILE_INTERVAL(do_poll_update_bookkeeping);
     }
 
-    unlock(map->lock);
+    unlock(&map->lock);
 
     SAVE_PROFILE_INTERVAL_SINCE(do_poll_first_loop, begin_time);
 

+ 22 - 22
LibOS/shim/src/sys/shim_semget.c

@@ -142,9 +142,9 @@ failed:
 
 int add_sem_handle (unsigned long key, IDTYPE id, int nsems, bool owned)
 {
-    lock(sem_list_lock);
+    lock(&sem_list_lock);
     int ret = __add_sem_handle(key, id, nsems, owned, NULL);
-    unlock(sem_list_lock);
+    unlock(&sem_list_lock);
     return ret;
 }
 
@@ -153,7 +153,7 @@ struct shim_sem_handle * get_sem_handle_by_key (unsigned long key)
     LISTP_TYPE(shim_sem_handle) * key_head = &sem_key_hlist[SEM_HASH(key)];
     struct shim_sem_handle * tmp, * found = NULL;
 
-    lock(sem_list_lock);
+    lock(&sem_list_lock);
 
     listp_for_each_entry(tmp, key_head, key_hlist)
         if (tmp->semkey == key) {
@@ -164,7 +164,7 @@ struct shim_sem_handle * get_sem_handle_by_key (unsigned long key)
     if (found)
         get_handle(SEM_TO_HANDLE(found));
 
-    unlock(sem_list_lock);
+    unlock(&sem_list_lock);
     return found;
 }
 
@@ -173,7 +173,7 @@ struct shim_sem_handle * get_sem_handle_by_id (IDTYPE semid)
     LISTP_TYPE(shim_sem_handle) * sid_head = &sem_sid_hlist[SEM_HASH(semid)];
     struct shim_sem_handle * tmp, * found = NULL;
 
-    lock(sem_list_lock);
+    lock(&sem_list_lock);
 
     listp_for_each_entry(tmp, sid_head, sid_hlist)
         if (tmp->semid == semid) {
@@ -184,7 +184,7 @@ struct shim_sem_handle * get_sem_handle_by_id (IDTYPE semid)
     if (found)
         get_handle(SEM_TO_HANDLE(found));
 
-    unlock(sem_list_lock);
+    unlock(&sem_list_lock);
     return found;
 }
 
@@ -202,7 +202,7 @@ static int __del_sem_handle (struct shim_sem_handle * sem)
 
     struct shim_handle * hdl = SEM_TO_HANDLE(sem);
 
-    lock(sem_list_lock);
+    lock(&sem_list_lock);
     listp_del_init(sem, &sem_list, list);
     put_handle(hdl);
     if (!list_empty(sem, key_hlist)) {
@@ -217,16 +217,16 @@ static int __del_sem_handle (struct shim_sem_handle * sem)
         listp_del_init(sem, sid_head, sid_hlist);
         put_handle(hdl);
     }
-    unlock(sem_list_lock);
+    unlock(&sem_list_lock);
     return 0;
 }
 
 int del_sem_handle (struct shim_sem_handle * sem)
 {
     struct shim_handle * hdl = SEM_TO_HANDLE(sem);
-    lock(hdl->lock);
+    lock(&hdl->lock);
     int ret = del_sem_handle(sem);
-    unlock(hdl->lock);
+    unlock(&hdl->lock);
     return ret;
 }
 
@@ -293,9 +293,9 @@ static int connect_sem_handle (int semid, int nsems,
             return ret;
 
         if (!sem) {
-            lock(sem_list_lock);
+            lock(&sem_list_lock);
             ret = __add_sem_handle(IPC_PRIVATE, semid, nsems, false, &sem);
-            unlock(sem_list_lock);
+            unlock(&sem_list_lock);
             if (ret < 0)
                 return ret;
         }
@@ -310,7 +310,7 @@ int recover_sem_ownership (struct shim_sem_handle * sem,
                            struct sem_client_backup * clients, int nclients)
 {
     struct shim_handle * hdl = SEM_TO_HANDLE(sem);
-    lock(hdl->lock);
+    lock(&hdl->lock);
     assert(!sem->owned);
     assert(!sem->nsems && !sem->sems);
 
@@ -348,7 +348,7 @@ int recover_sem_ownership (struct shim_sem_handle * sem,
     sem->owned = true;
     DkEventSet(sem->event);
 out:
-    unlock(hdl->lock);
+    unlock(&hdl->lock);
     return 0;
 }
 
@@ -398,7 +398,7 @@ int shim_do_semctl (int semid, int semnum, int cmd, unsigned long arg)
        return ret;
 
     struct shim_handle * hdl = SEM_TO_HANDLE(sem);
-    lock(hdl->lock);
+    lock(&hdl->lock);
 
     switch (cmd) {
         case IPC_RMID: {
@@ -489,7 +489,7 @@ int shim_do_semctl (int semid, int semnum, int cmd, unsigned long arg)
     }
 
 out:
-    unlock(hdl->lock);
+    unlock(&hdl->lock);
     put_sem_handle(sem);
     return ret;
 }
@@ -689,7 +689,7 @@ int submit_sysv_sem (struct shim_sem_handle * sem, struct sembuf * sops,
     stat.failed     = false;
     SAVE_PROFILE_INTERVAL(sem_prepare_stat);
 
-    lock(hdl->lock);
+    lock(&hdl->lock);
     SAVE_PROFILE_INTERVAL(sem_lock_handle);
 
     if (sem->deleted) {
@@ -758,13 +758,13 @@ int submit_sysv_sem (struct shim_sem_handle * sem, struct sembuf * sops,
         }
 
 unowned:
-        unlock(hdl->lock);
+        unlock(&hdl->lock);
         ret = ipc_sysv_semop_send(semid, sops, nsops, timeout, &seq);
         if (ret != -EAGAIN &&
             ret != -ECONNREFUSED)
             goto out;
 
-        lock(hdl->lock);
+        lock(&hdl->lock);
         SAVE_PROFILE_INTERVAL(sem_send_ipc_semop);
         if (!sem->owned)
             goto out_locked;
@@ -858,16 +858,16 @@ unowned:
             goto unowned;
         }
 
-        unlock(hdl->lock);
+        unlock(&hdl->lock);
         object_wait_with_retry(sem->event);
-        lock(hdl->lock);
+        lock(&hdl->lock);
         SAVE_PROFILE_INTERVAL(sem_wait_for_complete);
     }
 
     ret = sem_ops->stat.completed ? 0 : -EAGAIN;
 
 out_locked:
-    unlock(hdl->lock);
+    unlock(&hdl->lock);
 out:
     if (sem_ops && malloced)
         free(sem_ops);

+ 31 - 31
LibOS/shim/src/sys/shim_sigaction.c

@@ -60,7 +60,7 @@ int shim_do_sigaction (int signum, const struct __kernel_sigaction * act,
 
     struct shim_signal_handle * sighdl = &cur->signal_handles[signum - 1];
 
-    lock(cur->lock);
+    lock(&cur->lock);
 
     if (oldact) {
         if (sighdl->action) {
@@ -85,7 +85,7 @@ int shim_do_sigaction (int signum, const struct __kernel_sigaction * act,
 
     err = 0;
 out:
-    unlock(cur->lock);
+    unlock(&cur->lock);
     return err;
 }
 
@@ -112,7 +112,7 @@ int shim_do_sigprocmask (int how, const __sigset_t * set, __sigset_t * oldset)
     struct shim_thread * cur = get_cur_thread();
     int err = 0;
 
-    lock(cur->lock);
+    lock(&cur->lock);
 
     old = get_sig_mask(cur);
     if (oldset) {
@@ -144,7 +144,7 @@ int shim_do_sigprocmask (int how, const __sigset_t * set, __sigset_t * oldset)
     set_sig_mask(cur, &set_tmp);
 
 out:
-    unlock(cur->lock);
+    unlock(&cur->lock);
 
     if (!err && oldset)
         memcpy(oldset, old, sizeof(__sigset_t));
@@ -158,21 +158,21 @@ int shim_do_sigaltstack (const stack_t * ss, stack_t * oss)
         return -EINVAL;
 
     struct shim_thread * cur = get_cur_thread();
-    lock(cur->lock);
+    lock(&cur->lock);
 
     if (oss)
         *oss = cur->signal_altstack;
 
     if (ss) {
         if (ss->ss_size < MINSIGSTKSZ) {
-            unlock(cur->lock);
+            unlock(&cur->lock);
             return -ENOMEM;
         }
 
         cur->signal_altstack = *ss;
     }
 
-    unlock(cur->lock);
+    unlock(&cur->lock);
     return 0;
 }
 
@@ -184,7 +184,7 @@ int shim_do_sigsuspend (const __sigset_t * mask)
     __sigset_t * old, tmp;
     struct shim_thread * cur = get_cur_thread();
 
-    lock(cur->lock);
+    lock(&cur->lock);
 
     old = get_sig_mask(cur);
     memcpy(&tmp, old, sizeof(__sigset_t));
@@ -195,7 +195,7 @@ int shim_do_sigsuspend (const __sigset_t * mask)
     thread_setwait(NULL, NULL);
     thread_sleep(NO_TIMEOUT);
 
-    unlock(cur->lock);
+    unlock(&cur->lock);
     set_sig_mask(cur, old);
     return -EINTR;
 }
@@ -263,12 +263,12 @@ static int __kill_proc (struct shim_thread * thread, void * arg,
         goto out;
 
     if (!thread->in_vm) {
-        unlock(thread_list_lock);
+        unlock(&thread_list_lock);
         *unlocked = true;
         return (!ipc_pid_kill_send(warg->sender, warg->id, KILL_PROCESS,
                                    warg->sig)) ? 1 : 0;
     } else {
-        lock(thread->lock);
+        lock(&thread->lock);
 
         if (!thread->is_alive)
             goto out_locked;
@@ -279,15 +279,15 @@ static int __kill_proc (struct shim_thread * thread, void * arg,
             srched = 1;
         } else {
             /* This double-check case is probably unnecessary, but keep it for now */
-            unlock(thread->lock);
-            unlock(thread_list_lock);
+            unlock(&thread->lock);
+            unlock(&thread_list_lock);
             *unlocked = true;
             return (!ipc_pid_kill_send(warg->sender, warg->id, KILL_PROCESS,
                                    warg->sig)) ? 1 : 0;
         }
     }
 out_locked:
-    unlock(thread->lock);
+    unlock(&thread->lock);
 out:
     return srched;
 }
@@ -301,17 +301,17 @@ static int __kill_proc_simple (struct shim_simple_thread * sthread,
     if (sthread->tgid != warg->id)
         return 0;
 
-    lock(sthread->lock);
+    lock(&sthread->lock);
 
     if (sthread->is_alive) {
-        unlock(sthread->lock);
-        unlock(thread_list_lock);
+        unlock(&sthread->lock);
+        unlock(&thread_list_lock);
         *unlocked = true;
         return (!ipc_pid_kill_send(warg->sender, warg->id, KILL_PROCESS,
                                    warg->sig)) ? 1 : 0;
     }
 
-    unlock(sthread->lock);
+    unlock(&sthread->lock);
     return srched;
 }
 
@@ -364,7 +364,7 @@ static int __kill_pgroup (struct shim_thread * thread, void * arg,
     if (warg->current == thread)
         return 1;
 
-    lock(thread->lock);
+    lock(&thread->lock);
 
     if (!thread->is_alive)
         goto out;
@@ -375,15 +375,15 @@ static int __kill_pgroup (struct shim_thread * thread, void * arg,
 
         srched = 1;
     } else {
-        unlock(thread->lock);
-        unlock(thread_list_lock);
+        unlock(&thread->lock);
+        unlock(&thread_list_lock);
         *unlocked = true;
         return (!ipc_pid_kill_send(warg->sender, warg->id, KILL_PGROUP,
                                    warg->sig)) ? 1 : 0;
     }
 
 out:
-    unlock(thread->lock);
+    unlock(&thread->lock);
     return srched;
 }
 
@@ -396,17 +396,17 @@ static int __kill_pgroup_simple (struct shim_simple_thread * sthread,
     if (sthread->pgid != warg->id)
         return 0;
 
-    lock(sthread->lock);
+    lock(&sthread->lock);
 
     if (sthread->is_alive) {
-        unlock(sthread->lock);
-        unlock(thread_list_lock);
+        unlock(&sthread->lock);
+        unlock(&thread_list_lock);
         *unlocked = true;
         return (!ipc_pid_kill_send(warg->sender, warg->id, KILL_PGROUP,
                                    warg->sig)) ? 1 : 0;
     }
 
-    unlock(sthread->lock);
+    unlock(&sthread->lock);
     return srched;
 }
 
@@ -455,14 +455,14 @@ static int __kill_all_threads (struct shim_thread * thread, void * arg,
     if (warg->current == thread)
         return 1;
 
-    lock(thread->lock);
+    lock(&thread->lock);
 
     if (thread->in_vm) {
         __append_signal(thread, warg->sig, warg->sender);
         srched = 1;
     }
 
-    unlock(thread->lock);
+    unlock(&thread->lock);
     return srched;
 }
 
@@ -545,7 +545,7 @@ int do_kill_thread (IDTYPE sender, IDTYPE tgid, IDTYPE tid, int sig,
     int ret = 0;
 
     if (thread) {
-        lock(thread->lock);
+        lock(&thread->lock);
 
         if (thread->in_vm) {
             if (!tgid || thread->tgid == tgid)
@@ -553,11 +553,11 @@ int do_kill_thread (IDTYPE sender, IDTYPE tgid, IDTYPE tid, int sig,
             else
                 ret = -ESRCH;
         } else {
-            unlock(thread->lock);
+            unlock(&thread->lock);
             return ipc_pid_kill_send(sender, tid, KILL_THREAD, sig);
         }
 
-        unlock(thread->lock);
+        unlock(&thread->lock);
         return ret;
     }
 

+ 30 - 30
LibOS/shim/src/sys/shim_socket.c

@@ -472,7 +472,7 @@ int shim_do_bind (int sockfd, struct sockaddr * addr, socklen_t addrlen)
     }
 
     struct shim_sock_handle * sock = &hdl->info.sock;
-    lock(hdl->lock);
+    lock(&hdl->lock);
     enum shim_sock_state state = sock->sock_state;
 
     if (state != SOCK_CREATED) {
@@ -576,7 +576,7 @@ out:
         }
     }
 
-    unlock(hdl->lock);
+    unlock(&hdl->lock);
     put_handle(hdl);
     return ret;
 }
@@ -673,7 +673,7 @@ int shim_do_listen (int sockfd, int backlog)
         return -EINVAL;
     }
 
-    lock(hdl->lock);
+    lock(&hdl->lock);
 
     enum shim_sock_state state = sock->sock_state;
     int ret = -EINVAL;
@@ -692,7 +692,7 @@ out:
     if (ret < 0)
         sock->sock_state = state;
 
-    unlock(hdl->lock);
+    unlock(&hdl->lock);
     put_handle(hdl);
     return ret;
 }
@@ -720,7 +720,7 @@ int shim_do_connect (int sockfd, struct sockaddr * addr, int addrlen)
     }
 
     struct shim_sock_handle * sock = &hdl->info.sock;
-    lock(hdl->lock);
+    lock(&hdl->lock);
     enum shim_sock_state state = sock->sock_state;
     int ret = -EINVAL;
 
@@ -809,12 +809,12 @@ int shim_do_connect (int sockfd, struct sockaddr * addr, int addrlen)
 
     if (sock->domain == AF_UNIX) {
         struct shim_dentry * dent = sock->addr.un.dentry;
-        lock(dent->lock);
+        lock(&dent->lock);
         dent->state ^= DENTRY_NEGATIVE;
         dent->state |= DENTRY_VALID|DENTRY_RECENTLY;
         dent->fs = &socket_builtin_fs;
         dent->data = sock->addr.un.data;
-        unlock(dent->lock);
+        unlock(&dent->lock);
     }
 
     if (sock->domain == AF_INET || sock->domain == AF_INET6) {
@@ -854,7 +854,7 @@ out:
         }
     }
 
-    unlock(hdl->lock);
+    unlock(&hdl->lock);
     put_handle(hdl);
     return ret;
 }
@@ -885,7 +885,7 @@ int __do_accept (struct shim_handle * hdl, int flags, struct sockaddr * addr,
             return -EINVAL;
     }
 
-    lock(hdl->lock);
+    lock(&hdl->lock);
 
     if (sock->sock_state != SOCK_LISTENED) {
         debug("shim_accpet: invalid socket\n");
@@ -988,7 +988,7 @@ out:
         sock->error = -ret;
     if (accepted)
         DkObjectClose(accepted);
-    unlock(hdl->lock);
+    unlock(&hdl->lock);
     return ret;
 }
 
@@ -1046,7 +1046,7 @@ static ssize_t do_sendmsg (int fd, struct iovec * bufs, int nbufs, int flags,
             goto out;
     }
 
-    lock(hdl->lock);
+    lock(&hdl->lock);
 
     PAL_HANDLE pal_hdl = hdl->pal_handle;
     char * uri = NULL;
@@ -1098,7 +1098,7 @@ static ssize_t do_sendmsg (int fd, struct iovec * bufs, int nbufs, int flags,
         uri = __alloca(SOCK_URI_SIZE);
     }
 
-    unlock(hdl->lock);
+    unlock(&hdl->lock);
 
     if (uri) {
         struct addr_inet addr_buf;
@@ -1107,7 +1107,7 @@ static ssize_t do_sendmsg (int fd, struct iovec * bufs, int nbufs, int flags,
         memcpy(uri, "udp:", 5);
         if ((ret = inet_translate_addr(sock->domain, uri + 4, SOCK_URI_SIZE - 4,
                                        &addr_buf)) < 0) {
-            lock(hdl->lock);
+            lock(&hdl->lock);
             goto out_locked;
         }
 
@@ -1133,7 +1133,7 @@ static ssize_t do_sendmsg (int fd, struct iovec * bufs, int nbufs, int flags,
     if (bytes)
         ret = bytes;
     if (ret < 0) {
-        lock(hdl->lock);
+        lock(&hdl->lock);
         goto out_locked;
     }
     goto out;
@@ -1142,7 +1142,7 @@ out_locked:
     if (ret < 0)
         sock->error = -ret;
 
-    unlock(hdl->lock);
+    unlock(&hdl->lock);
 out:
     put_handle(hdl);
     return ret;
@@ -1224,7 +1224,7 @@ static ssize_t do_recvmsg (int fd, struct iovec * bufs, int nbufs, int flags,
             goto out;
     }
 
-    lock(hdl->lock);
+    lock(&hdl->lock);
 
     PAL_HANDLE pal_hdl = hdl->pal_handle;
     char * uri = NULL;
@@ -1253,7 +1253,7 @@ static ssize_t do_recvmsg (int fd, struct iovec * bufs, int nbufs, int flags,
         uri = __alloca(SOCK_URI_SIZE);
     }
 
-    unlock(hdl->lock);
+    unlock(&hdl->lock);
 
     bool address_received = false;
     int bytes = 0;
@@ -1285,7 +1285,7 @@ static ssize_t do_recvmsg (int fd, struct iovec * bufs, int nbufs, int flags,
 
                 if ((ret = inet_parse_addr(sock->domain, sock->sock_type, uri,
                                            &conn, NULL)) < 0) {
-                    lock(hdl->lock);
+                    lock(&hdl->lock);
                     goto out_locked;
                 }
 
@@ -1307,7 +1307,7 @@ static ssize_t do_recvmsg (int fd, struct iovec * bufs, int nbufs, int flags,
     if (bytes)
         ret = bytes;
     if (ret < 0) {
-        lock(hdl->lock);
+        lock(&hdl->lock);
         goto out_locked;
     }
     goto out;
@@ -1316,7 +1316,7 @@ out_locked:
     if (ret < 0)
         sock->error = -ret;
 
-    unlock(hdl->lock);
+    unlock(&hdl->lock);
 out:
     put_handle(hdl);
     return ret;
@@ -1376,7 +1376,7 @@ int shim_do_shutdown (int sockfd, int how)
         goto out;
     }
 
-    lock(hdl->lock);
+    lock(&hdl->lock);
 
     if (sock->sock_state != SOCK_LISTENED &&
         sock->sock_state != SOCK_ACCEPTED &&
@@ -1407,7 +1407,7 @@ out_locked:
     if (ret < 0)
         sock->error = -ret;
 
-    unlock(hdl->lock);
+    unlock(&hdl->lock);
 out:
     put_handle(hdl);
     return ret;
@@ -1436,7 +1436,7 @@ int shim_do_getsockname (int sockfd, struct sockaddr * addr, int * addrlen)
     }
 
     struct shim_sock_handle * sock = &hdl->info.sock;
-    lock(hdl->lock);
+    lock(&hdl->lock);
 
     struct sockaddr saddr;
     int len = inet_copy_addr(sock->domain, &saddr, &sock->addr.in.bind);
@@ -1447,7 +1447,7 @@ int shim_do_getsockname (int sockfd, struct sockaddr * addr, int * addrlen)
     memcpy(addr, &saddr, len);
     *addrlen = len;
     ret = 0;
-    unlock(hdl->lock);
+    unlock(&hdl->lock);
 out:
     put_handle(hdl);
     return ret;
@@ -1476,7 +1476,7 @@ int shim_do_getpeername (int sockfd, struct sockaddr * addr, int * addrlen)
     }
 
     struct shim_sock_handle * sock = &hdl->info.sock;
-    lock(hdl->lock);
+    lock(&hdl->lock);
 
     /* Data gram sock need not be conneted or bound at all */
     if (sock->sock_type == SOCK_STREAM &&
@@ -1504,7 +1504,7 @@ int shim_do_getpeername (int sockfd, struct sockaddr * addr, int * addrlen)
     *addrlen = len;
     ret = 0;
 out_locked:
-    unlock(hdl->lock);
+    unlock(&hdl->lock);
 out:
     put_handle(hdl);
     return ret;
@@ -1684,7 +1684,7 @@ int shim_do_setsockopt (int fd, int level, int optname, char * optval,
     }
 
     struct shim_sock_handle * sock = &hdl->info.sock;
-    lock(hdl->lock);
+    lock(&hdl->lock);
 
     if (!hdl->pal_handle) {
         struct shim_sock_option * o = malloc(sizeof(struct shim_sock_option) +
@@ -1710,7 +1710,7 @@ int shim_do_setsockopt (int fd, int level, int optname, char * optval,
     ret = __do_setsockopt(hdl, level, optname, optval, optlen, NULL);
 
 out_locked:
-    unlock(hdl->lock);
+    unlock(&hdl->lock);
 out:
     put_handle(hdl);
     return ret;
@@ -1734,7 +1734,7 @@ int shim_do_getsockopt (int fd, int level, int optname, char * optval,
     }
 
     struct shim_sock_handle * sock = &hdl->info.sock;
-    lock(hdl->lock);
+    lock(&hdl->lock);
 
     int * intval = (int *) optval;
 
@@ -1843,7 +1843,7 @@ query:
     }
 
 out:
-    unlock(hdl->lock);
+    unlock(&hdl->lock);
     put_handle(hdl);
     return ret;
 }

+ 2 - 2
LibOS/shim/src/sys/shim_vfork.c

@@ -78,7 +78,7 @@ int shim_do_vfork (void)
     memcpy(dummy_stack, new_thread->frameptr, stack_size);
 
     /* assigned the stack of the thread */
-    lock(cur_thread->lock);
+    lock(&cur_thread->lock);
     new_thread->tgid      = new_thread->tid;
     new_thread->in_vm     = true;
     new_thread->is_alive  = true;
@@ -89,7 +89,7 @@ int shim_do_vfork (void)
     cur_thread->stack     = dummy_stack;
     cur_thread->stack_top = dummy_stack + stack_size;
     cur_thread->frameptr  = NULL;
-    unlock(cur_thread->lock);
+    unlock(&cur_thread->lock);
 
     /* Now we are good, set this child as ours */
     set_as_child(NULL, new_thread);

+ 11 - 11
LibOS/shim/src/sys/shim_wait.c

@@ -59,10 +59,10 @@ block_pid:
             object_wait_with_retry(thread->exit_event);
         }
 
-        lock(thread->lock);
+        lock(&thread->lock);
 
         if (thread->is_alive) {
-            unlock(thread->lock);
+            unlock(&thread->lock);
             if (!(option & WNOHANG))
                 goto block_pid;
             put_thread(thread);
@@ -74,26 +74,26 @@ block_pid:
             struct shim_thread * parent = thread->parent;
             assert(parent);
 
-            lock(parent->lock);
+            lock(&parent->lock);
             /* DEP 5/15/17: These threads are exited */
             assert(!thread->is_alive);
             listp_del_init(thread, &thread->parent->exited_children, siblings);
-            unlock(parent->lock);
+            unlock(&parent->lock);
 
             put_thread(parent);
             put_thread(thread);
             thread->parent = NULL;
         }
 
-        unlock(thread->lock);
+        unlock(&thread->lock);
         goto found;
     }
 
-    lock(cur->lock);
+    lock(&cur->lock);
 
     if (listp_empty(&cur->children) &&
         listp_empty(&cur->exited_children)) {
-        unlock(cur->lock);
+        unlock(&cur->lock);
         return -ECHILD;
     }
 
@@ -101,9 +101,9 @@ block_pid:
 block:
         if (cur->child_exit_event)
             while (listp_empty(&cur->exited_children)) {
-                unlock(cur->lock);
+                unlock(&cur->lock);
                 object_wait_with_retry(cur->child_exit_event);
-                lock(cur->lock);
+                lock(&cur->lock);
             }
     }
 
@@ -125,7 +125,7 @@ block:
         }
     }
 
-    unlock(cur->lock);
+    unlock(&cur->lock);
     return 0;
 
 found_child:
@@ -136,7 +136,7 @@ found_child:
     if (listp_empty(&cur->exited_children))
         DkEventClear(cur->child_exit_event);
 
-    unlock(cur->lock);
+    unlock(&cur->lock);
 
 found:
     if (status) {

+ 3 - 3
LibOS/shim/src/utils/strobjs.c

@@ -28,8 +28,8 @@
 
 static struct shim_lock str_mgr_lock;
 
-#define system_lock()       lock(str_mgr_lock)
-#define system_unlock()     unlock(str_mgr_lock)
+#define system_lock()       lock(&str_mgr_lock)
+#define system_unlock()     unlock(&str_mgr_lock)
 
 #define STR_MGR_ALLOC  32
 #define PAGE_SIZE      allocsize
@@ -41,7 +41,7 @@ static MEM_MGR str_mgr = NULL;
 
 int init_str_mgr (void)
 {
-    create_lock(str_mgr_lock);
+    create_lock(&str_mgr_lock);
     str_mgr = create_mem_mgr(init_align_up(STR_MGR_ALLOC));
     return 0;
 }