Browse Source

[LibOS] Introduce hashtype_to_idtype() for correct casting

HASHTYPE is currently 8B int while IDTYPE is 4B int. This commit
introduces a folding helper function for correct casting.
Dmitrii Kuvaiskii 6 years ago
parent
commit
97d2a195a7
2 changed files with 7 additions and 2 deletions
  1. 5 0
      LibOS/shim/include/shim_internal.h
  2. 2 2
      LibOS/shim/src/sys/shim_socket.c

+ 5 - 0
LibOS/shim/include/shim_internal.h

@@ -800,4 +800,9 @@ static inline bool access_ok(const volatile void* addr, size_t size) {
 # error "Unsupported architecture"
 #endif /* __x86_64__ */
 
+static inline IDTYPE hashtype_to_idtype(HASHTYPE hash) {
+    assert(sizeof(HASHTYPE) == 8 && sizeof(IDTYPE) == 4);
+    return ((IDTYPE)hash) ^ ((IDTYPE)(hash >> 32));
+}
+
 #endif /* _PAL_INTERNAL_H_ */

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

@@ -504,7 +504,7 @@ int shim_do_bind (int sockfd, struct sockaddr * addr, socklen_t addrlen)
 
         struct shim_unix_data * data = malloc(sizeof(struct shim_unix_data));
 
-        data->pipeid = dent->rel_path.hash >> 32;
+        data->pipeid = hashtype_to_idtype(dent->rel_path.hash);
         sock->addr.un.pipeid = data->pipeid;
         sock->addr.un.data = data;
         sock->addr.un.dentry = dent;
@@ -763,7 +763,7 @@ int shim_do_connect (int sockfd, struct sockaddr * addr, int addrlen)
 
         if (!(dent->state & DENTRY_VALID) || dent->state & DENTRY_NEGATIVE) {
             data = malloc(sizeof(struct shim_unix_data));
-            data->pipeid = dent->rel_path.hash >> 32;
+            data->pipeid = hashtype_to_idtype(dent->rel_path.hash);
         } else if (dent->fs != &socket_builtin_fs) {
             ret = -ECONNREFUSED;
             goto out;