Track the FD assigned to a user FD (XCC)
authorBarret Rhoden <brho@cs.berkeley.edu>
Fri, 18 Dec 2015 22:52:22 +0000 (17:52 -0500)
committerBarret Rhoden <brho@cs.berkeley.edu>
Thu, 14 Jan 2016 21:04:46 +0000 (16:04 -0500)
Rebuild glibc.

Signed-off-by: Barret Rhoden <brho@cs.berkeley.edu>
tools/compilers/gcc-glibc/glibc-2.19-akaros/sysdeps/akaros/sys/user_fd.h
tools/compilers/gcc-glibc/glibc-2.19-akaros/sysdeps/akaros/user_fd.c

index dc0a802..e0c3e25 100644 (file)
@@ -29,6 +29,7 @@
  * you have the right type of FD. */
 struct user_fd {
        int                                                     magic;
+       int                                                     fd;
        void (*close)(struct user_fd *);
 };
 
index 4e16c98..10afc59 100644 (file)
@@ -27,6 +27,8 @@ static size_t nr_ufds = 0;
 int ufd_get_fd(struct user_fd *ufd)
 {
        struct user_fd **new_ufds;
+       int fd;
+
        if (!ufds) {
                nr_ufds = 1 << (sizeof(int) * 8 - LOG2_UP(NR_FILE_DESC_MAX) - 1);
                /* Two things: instead of worrying about growing and reallocing (which
@@ -45,8 +47,11 @@ int ufd_get_fd(struct user_fd *ufd)
         * start in different areas, or maintain a 'last used' hint FD. */
        for (int i = 0; i < nr_ufds; i++) {
                if (!ufds[i]) {
-                       if (atomic_cas_ptr((void**)&ufds[i], 0, ufd))
-                               return i + USER_FD_BASE;
+                       if (atomic_cas_ptr((void**)&ufds[i], 0, ufd)) {
+                               fd = i + USER_FD_BASE;
+                               ufds[i]->fd = fd;
+                               return fd;
+                       }
                }
        }
        __set_errno(ENFILE);