Browse Source

Misc bugfixes, mostly in sockets and memory mapping

Don Porter 7 years ago
parent
commit
62d2cfc6c5

+ 4 - 0
LibOS/shim/src/bookkeep/shim_vma.c

@@ -589,6 +589,10 @@ static int __bkeep_mprotect (void * addr, uint64_t length, int prot,
 
                 candidate = __lookup_vma((void *) addr, length);
                 assert(candidate);
+
+                /* DEP 10/19/16: If we make a vma that perfectly matches this
+                 * region, we want to break the loop and stop. */
+                length = 0;
             }
 
             length -= candidate->addr - addr;

+ 5 - 7
LibOS/shim/src/fs/socket/fs.c

@@ -183,11 +183,6 @@ static int socket_poll (struct shim_handle * hdl, int poll_type)
                 ret = -ENOTCONN;
                 goto out;
             }
-
-            if (sock->sock_state == SOCK_LISTENED) {
-                ret = -EAGAIN;
-                goto out;
-            }
         }
 
         if (sock->sock_type == SOCK_DGRAM &&
@@ -223,6 +218,7 @@ static int socket_poll (struct shim_handle * hdl, int poll_type)
 
     PAL_STREAM_ATTR attr;
     if (!DkStreamAttributesQuerybyHandle(hdl->pal_handle, &attr)) {
+        debug("socket_poll: Setting -PAL_ERRNO %d\n", PAL_ERRNO);
         ret = -PAL_ERRNO;
         goto out;
     }
@@ -233,7 +229,7 @@ static int socket_poll (struct shim_handle * hdl, int poll_type)
     }
 
     ret = 0;
-    if (attr.disconnected)
+    if (attr.disconnected) 
         ret |= FS_POLL_ER;
     if ((poll_type & FS_POLL_RD) && attr.readable)
         ret |= FS_POLL_RD;
@@ -241,8 +237,10 @@ static int socket_poll (struct shim_handle * hdl, int poll_type)
         ret |= FS_POLL_WR;
 
 out:
-    if (ret < 0)
+    if (ret < 0) {
+        debug("Setting sock error %d\n", ret);
         sock->error = -ret;
+    }
 
     unlock(hdl->lock);
     return ret;

+ 9 - 0
LibOS/shim/src/sys/shim_open.c

@@ -488,6 +488,15 @@ int shim_do_fdatasync (int fd)
     return shim_do_fsync(fd);
 }
 
+
+// DEP 10/20/16: Assuming fsync >> fdatasync for now
+//  and no app depends on only syncing data for correctness.
+int shim_do_fdatasync (int fd)
+{
+    return shim_do_fsync(fd);
+}
+
+
 int shim_do_truncate (const char * path, loff_t length)
 {
     struct shim_dentry * dent = NULL;

+ 15 - 12
LibOS/shim/src/sys/shim_socket.c

@@ -407,11 +407,10 @@ static int create_socket_uri (struct shim_handle * hdl)
 int shim_do_bind (int sockfd, struct sockaddr * addr, socklen_t addrlen)
 {
     struct shim_handle * hdl = get_fd_handle(sockfd, NULL, NULL);
+    int ret = -EINVAL;
     if (!hdl)
         return -EBADF;
 
-    int ret = -EINVAL;
-
     if (hdl->type != TYPE_SOCK) {
         put_handle(hdl);
         return -ENOTSOCK;
@@ -427,16 +426,17 @@ int shim_do_bind (int sockfd, struct sockaddr * addr, socklen_t addrlen)
     }
 
     if (sock->domain == AF_UNIX) {
-        if (addrlen != sizeof(struct sockaddr_un))
+        if (addrlen != sizeof(struct sockaddr_un)) 
             goto out;
 
         struct sockaddr_un * saddr = (struct sockaddr_un *) addr;
         char * spath = saddr->sun_path;
         struct shim_dentry * dent = NULL;
 
-        if ((ret = path_lookupat(NULL, spath, LOOKUP_CREATE, &dent)) < 0)
+        if ((ret = path_lookupat(NULL, spath, LOOKUP_CREATE, &dent)) < 0) 
             goto out;
 
+
         if (dent->state & DENTRY_VALID &&
             !(dent->state & DENTRY_NEGATIVE)) {
             ret = -EADDRINUSE;
@@ -449,18 +449,21 @@ int shim_do_bind (int sockfd, struct sockaddr * addr, socklen_t addrlen)
         sock->addr.un.pipeid = data->pipeid;
         sock->addr.un.data = data;
         sock->addr.un.dentry = dent;
+
     } else if (sock->domain == AF_INET || sock->domain == AF_INET6) {
-		if (addrlen != ((sock->domain == AF_INET) ? sizeof(struct sockaddr_in) :
-					sizeof(struct sockaddr_in6)))
-			goto out;
 
-		inet_save_addr(sock->domain, &sock->addr.in.bind, addr);
-		inet_rebase_port(false, sock->domain, &sock->addr.in.bind, true);
-	}
+        if (addrlen != ((sock->domain == AF_INET) ? sizeof(struct sockaddr_in) :
+                        sizeof(struct sockaddr_in6))) {
+            goto out;
+        }
+        
+        inet_save_addr(sock->domain, &sock->addr.in.bind, addr);
+        inet_rebase_port(false, sock->domain, &sock->addr.in.bind, true);
+    }
 
     sock->sock_state = SOCK_BOUND;
 
-    if ((ret = create_socket_uri(hdl)) < 0)
+    if ((ret = create_socket_uri(hdl)) < 0) 
         goto out;
 
     PAL_HANDLE pal_hdl = DkStreamOpen(qstrgetstr(&hdl->uri),
@@ -468,8 +471,8 @@ int shim_do_bind (int sockfd, struct sockaddr * addr, socklen_t addrlen)
                                       hdl->flags & O_NONBLOCK);
 
     if (!pal_hdl) {
-        debug("bind: invalid handle returned\n");
         ret = (PAL_NATIVE_ERRNO == PAL_ERROR_STREAMEXIST) ? -EADDRINUSE : -PAL_ERRNO;
+        debug("bind: invalid handle returned\n");
         goto out;
     }
 

+ 3 - 0
Pal/regression/02_Pipe.py

@@ -10,6 +10,9 @@ regression = Regression(loader, "Pipe")
 regression.add_check(name="Pipe Creation",
     check=lambda res: "Pipe Creation 1 OK" in res[0].log)
 
+regression.add_check(name="Pipe Attributes",
+    check=lambda res: "Pipe Attribute Query 1 on pipesrv returned OK" in res[0].log)
+
 regression.add_check(name="Pipe Connection",
     check=lambda res: "Pipe Connection 1 OK" in res[0].log)
 

+ 14 - 0
Pal/regression/Pipe.c

@@ -16,9 +16,23 @@ int main (int argc, char ** argv, char ** envp)
     if (pipe1) {
         pal_printf("Pipe Creation 1 OK\n");
 
+        // DEP 10/24/16: Try to read some attributes of the pipe
+        PAL_STREAM_ATTR attr;
+        if (!DkStreamAttributesQuerybyHandle(pipe1, &attr)) {
+            pal_printf("Failed to get any attributes from the pipesrv\n");
+            return -1;
+        } else 
+            pal_printf("Pipe Attribute Query 1 on pipesrv returned OK\n");
+        // DEP: would be nice to sanity check the attributes.
+        // Job for another day...
+
         PAL_HANDLE pipe2 = DkStreamOpen("pipe:1", PAL_ACCESS_RDWR, 0, 0, 0);
 
         if (pipe2) {
+            // DEP 10/24/16: We should also be able to wait for a connection
+            //  on this handle
+            //PAL_HANDLE pipe3 = DkObjectsWaitAny(1, &pipe1, 0);
+
             PAL_HANDLE pipe3 = DkStreamWaitForClient(pipe1);
 
             if (pipe3) {

+ 8 - 4
Pal/src/host/Linux/db_pipes.c

@@ -527,11 +527,15 @@ static int pipe_attrquerybyhdl (PAL_HANDLE handle, PAL_STREAM_ATTR * attr)
     if (HANDLE_HDR(handle)->fds[0] == PAL_IDX_POISON)
         return -PAL_ERROR_BADHANDLE;
 
-    ret = INLINE_SYSCALL(ioctl, 3, HANDLE_HDR(handle)->fds[0], FIONREAD, &val);
-    if (IS_ERR(ret))
-        return unix_to_pal_error(ERRNO(ret));
+    attr->handle_type  = PAL_GET_TYPE(handle);
+
+    if (attr->handle_type == pal_type_pipe) {
+        ret = INLINE_SYSCALL(ioctl, 3, HANDLE_HDR(handle)->fds[0], FIONREAD, &val);
+        if (IS_ERR(ret)) {
+            return unix_to_pal_error(ERRNO(ret));
+        }
+    }
 
-    attr->handle_type  = pal_type_pipe;
     attr->disconnected = HANDLE_HDR(handle)->flags & ERROR(0);
     attr->nonblocking  = (HANDLE_HDR(handle)->type == pal_type_pipeprv) ?
                          handle->pipeprv.nonblocking : handle->pipe.nonblocking;