Browse Source

Bugfixes
'make install' to create a Runtime directory

Chia-Che Tsai 8 years ago
parent
commit
1708e4af96

+ 3 - 1
LibOS/Makefile

@@ -13,8 +13,10 @@ debug: DEBUG=debug
 debug: $(GLIBC_TARGET)
 	$(MAKE) -C $(SHIM_DIR) debug
 
-# nothing to install
 install:
+	[ -d ../Runtime ] || mkdir -p ../Runtime
+	[ -f ../Runtime/libsysdb.so ] || ln -sf ../LibOS/shim/src/libsysdb.so ../Runtime/libsysdb.so
+	./buildglibc.py install --quiet
 
 ifeq ($(SYS),x86_64-linux-gnu)
 $(GLIBC_TARGET): $(BUILD_DIR)/Makefile

+ 40 - 26
LibOS/buildglibc.py

@@ -23,29 +23,32 @@ def appendText(filename, text) :
         myfile.write(text)
 
 
-
-try:
-    home = os.getcwd()
-    glibc = "glibc-2.19"
-    glibcParent = "" # glibc parent directory
-    glibcDir = ""    # glibc dir (ex. glibc-2.19)
-    buildDir = "build"
-    installDir = "/usr/local/graphene"
-    commandStr = ""
-    commandOutput = ""
-    quiet = False
-    debug_flags = ""
-
-    for arg in sys.argv[1:]:
-        if arg == '--quiet' or arg == '-q':
-            quiet = True
-        if arg == 'debug':
-            debug_flags = "-g"
+home = os.getcwd()
+glibc = "glibc-2.19"
+glibcParent = "" # glibc parent directory
+glibcDir = ""    # glibc dir (ex. glibc-2.19)
+buildDir = "build"
+installDir = os.path.dirname(home) + '/Runtime/'
+do_install = False
+commandStr = ""
+commandOutput = ""
+quiet = False
+debug_flags = ""
+
+for arg in sys.argv[1:]:
+    if arg == '--quiet' or arg == '-q':
+        quiet = True
+    if arg == 'debug':
+        debug_flags = "-g"
+    if arg == 'install':
+        do_install = True
 
     #########################################
     #### get the locations of directories ###
     #########################################
 
+if not do_install:
+
     if not quiet:
         iput = raw_input('use {0} as the source of GNU libc? ([y]/n):'.format(glibc)).lower()
         if not iput == 'y' and not iput == '' :
@@ -83,10 +86,11 @@ try:
     else :
         os.makedirs(buildDir)
 
-    if not quiet:
-        iput = raw_input('use {0} as the directory to install glibc in? ([y]/n): '.format(installDir)).lower()
-        if not iput == 'y' and not iput == '':
-            installDir = raw_input('the directory to install glibc in:  ')
+if do_install and not quiet:
+
+    iput = raw_input('use {0} as the directory to install glibc in? ([y]/n): '.format(installDir)).lower()
+    if not iput == 'y' and not iput == '':
+        installDir = raw_input('the directory to install glibc in:  ')
 
     installDir = os.path.abspath(installDir)
     print 'using install dir: {0}'.format(installDir)
@@ -97,6 +101,8 @@ try:
     #### doctor glibc's Makefile ###
     ################################
 
+if not do_install:
+
     os.chdir(buildDir)
 
     cflags = '{0} -O2 -U_FORTIFY_SOURCE -fno-stack-protector'.format(debug_flags)
@@ -118,7 +124,7 @@ try:
     replaceAll('Makefile', r'# PARALLELMFLAGS = -j4', r'PARALLELMFLAGS = -j{0}'.format(numCPUs))
 
 
-    link_binaries = [ ( 'elf',    'ld-linux-x86-64.so.2' ),
+link_binaries     = [ ( 'elf',    'ld-linux-x86-64.so.2' ),
                       ( 'nptl',   'libpthread.so.0' ),
                       ( 'nptl_db','libthread_db.so.1' ),
                       ( 'math',   'libm.so.6' ),
@@ -129,12 +135,20 @@ try:
                       ( 'csu',    'crtn.o' ),
                       ( 'libos',  'liblibos.so.1' ) ]
 
+
+if not do_install:
+
     for (dir, bin) in link_binaries:
         print bin + ' -> ' + dir + '/' + bin
         os.symlink(dir + '/' + bin, bin)
 
-
     print '\n\n\nNow type \'make\' in \'{0}\'\n\n'.format(buildDir)
 
-except:
-    print 'uh-oh: {0}'.format(sys.exc_info()[0])
+
+
+if do_install:
+
+    for (dir, bin) in link_binaries:
+        print installDir + '/' + bin + ' -> ' + buildDir + '/' + dir + '/' + bin
+        if not os.path.lexists(installDir + '/' + bin):
+            os.symlink(os.path.relpath(buildDir + '/' + dir + '/' + bin, installDir), installDir + '/' + bin)

+ 12 - 30
LibOS/glibc-2.19.patch

@@ -700,7 +700,7 @@ index eef2bfd..a21d2ac 100644
  #define OUT \
    for (map = MAPS; map != NULL; map = map->l_next)			      \
 diff --git a/malloc/arena.c b/malloc/arena.c
-index 5088a25..b3b0e1c 100644
+index 5088a25..33a3879 100644
 --- a/malloc/arena.c
 +++ b/malloc/arena.c
 @@ -21,6 +21,27 @@
@@ -731,7 +731,7 @@ index 5088a25..b3b0e1c 100644
  #define HEAP_MIN_SIZE (32 * 1024)
  #ifndef HEAP_MAX_SIZE
  # ifdef DEFAULT_MMAP_THRESHOLD_MAX
-@@ -545,33 +566,7 @@ new_heap (size_t size, size_t top_pad)
+@@ -545,17 +566,6 @@ new_heap (size_t size, size_t top_pad)
       mapping (on Linux, this is the case for all non-writable mappings
       anyway). */
    p2 = MAP_FAILED;
@@ -746,36 +746,18 @@ index 5088a25..b3b0e1c 100644
 -          p2 = MAP_FAILED;
 -        }
 -    }
--  if (p2 == MAP_FAILED)
--    {
--      p1 = (char *) MMAP (0, HEAP_MAX_SIZE << 1, PROT_NONE, MAP_NORESERVE);
--      if (p1 != MAP_FAILED)
--        {
--          p2 = (char *) (((unsigned long) p1 + (HEAP_MAX_SIZE - 1))
--                         & ~(HEAP_MAX_SIZE - 1));
--          ul = p2 - p1;
--          if (ul)
--            __munmap (p1, ul);
+   if (p2 == MAP_FAILED)
+     {
+       p1 = (char *) MMAP (0, HEAP_MAX_SIZE << 1, PROT_NONE, MAP_NORESERVE);
+@@ -566,8 +576,6 @@ new_heap (size_t size, size_t top_pad)
+           ul = p2 - p1;
+           if (ul)
+             __munmap (p1, ul);
 -          else
 -            aligned_heap_area = p2 + HEAP_MAX_SIZE;
--          __munmap (p2 + HEAP_MAX_SIZE, HEAP_MAX_SIZE - ul);
--        }
--      else
--        {
-+
-           /* Try to take the chance that an allocation of only HEAP_MAX_SIZE
-              is already aligned. */
-           p2 = (char *) MMAP (0, HEAP_MAX_SIZE, PROT_NONE, MAP_NORESERVE);
-@@ -583,8 +578,7 @@ new_heap (size_t size, size_t top_pad)
-               __munmap (p2, HEAP_MAX_SIZE);
-               return 0;
-             }
--        }
--    }
-+
-   if (__mprotect (p2, size, PROT_READ | PROT_WRITE) != 0)
-     {
-       __munmap (p2, HEAP_MAX_SIZE);
+           __munmap (p2 + HEAP_MAX_SIZE, HEAP_MAX_SIZE - ul);
+         }
+       else
 diff --git a/nptl/Makefile b/nptl/Makefile
 index 57cc8c6..81f1bf4 100644
 --- a/nptl/Makefile

+ 2 - 0
LibOS/shim/include/shim_fs.h

@@ -290,6 +290,8 @@ int search_builtin_fs (const char * type, struct shim_mount ** fs);
 void get_mount (struct shim_mount * mount);
 void put_mount (struct shim_mount * mount);
 
+struct shim_mount * find_mount_from_uri (const char * uri);
+
 #include <shim_utils.h>
 
 static inline void set_handle_fs (struct shim_handle * hdl,

+ 15 - 1
LibOS/shim/src/bookkeep/shim_handle.c

@@ -86,12 +86,26 @@ static inline int init_exec_handle (struct shim_thread * thread)
     if (!exec)
         return -ENOMEM;
 
-    set_handle_fs(exec, &chroot_builtin_fs);
     qstrsetstr(&exec->uri, PAL_CB(executable), strlen(PAL_CB(executable)));
     exec->type     = TYPE_FILE;
     exec->flags    = O_RDONLY;
     exec->acc_mode = MAY_READ;
 
+    struct shim_mount * fs = find_mount_from_uri(PAL_CB(executable));
+    if (fs) {
+        path_lookupat(fs->root, PAL_CB(executable) + fs->uri.len, 0,
+                      &exec->dentry);
+        set_handle_fs(exec, fs);
+        if (exec->dentry) {
+            int len;
+            const char * path = dentry_get_path(exec->dentry, true, &len);
+            qstrsetstr(&exec->path, path, len);
+        }
+        put_mount(fs);
+    } else {
+        set_handle_fs(exec, &chroot_builtin_fs);
+    }
+
     lock(thread->lock);
     thread->exec = exec;
     unlock(thread->lock);

+ 11 - 16
LibOS/shim/src/bookkeep/shim_signal.c

@@ -245,26 +245,21 @@ internal:
         goto ret_exception;
     }
 
-    struct shim_vma * vma = NULL;
-
-    if (!(lookup_supervma((void *) arg, 0, &vma)) &&
-        !(vma->flags & VMA_INTERNAL)) {
-        int signo = SIGSEGV;
-
-        if (context)
-            debug("memory fault at %p (IP = %p)\n", arg, context->IP);
-
-        if (vma)
-            put_vma(vma);
+    if (context)
+        debug("memory fault at %p (IP = %p)\n", arg, context->IP);
 
-        deliver_signal(ALLOC_SIGINFO(signo, si_addr, (void *) arg), context);
-    } else {
-        if (vma)
+    struct shim_vma * vma = NULL;
+    if (!lookup_supervma((void *) arg, 0, &vma)) {
+        if (vma->flags & VMA_INTERNAL) {
             put_vma(vma);
-
-        goto internal;
+            goto internal;
+        }
+        put_vma(vma);
     }
 
+    int signo = SIGSEGV;
+    deliver_signal(ALLOC_SIGINFO(signo, si_addr, (void *) arg), context);
+
 ret_exception:
     DkExceptionReturn(event);
 }

+ 3 - 0
LibOS/shim/src/fs/proc/fs.c

@@ -183,6 +183,9 @@ static int proc_lookup (struct shim_dentry * dent, bool force)
     if (!ret && ent->dir)
         dent->state |= DENTRY_ISDIRECTORY;
 
+    if (ent->fs_ops && ent->fs_ops->follow_link)
+        dent->state |= DENTRY_ISLINK;
+
      return ret;
 }
 

+ 1 - 2
LibOS/shim/src/fs/proc/thread.c

@@ -103,10 +103,9 @@ static int find_thread_link (const char * name, struct shim_qstr * link,
         struct shim_handle * exec = thread->exec;
         if (!exec->dentry) {
             unlock(thread->lock);
-            ret = -ENOENT;
+            ret = -EINVAL;
             goto out;
         }
-
         dent = exec->dentry;
         get_dentry(dent);
     }

+ 26 - 0
LibOS/shim/src/fs/shim_fs.c

@@ -390,6 +390,32 @@ int walk_mounts (int (*walk) (struct shim_mount * mount, void * arg),
     return ret < 0 ? ret : (nsrched ? 0 : -ESRCH);
 }
 
+struct shim_mount * find_mount_from_uri (const char * uri)
+{
+    struct shim_mount * mount, * found = NULL;
+    int longest_path = 0;
+
+    lock(mount_list_lock);
+    list_for_each_entry(mount, &mount_list, list) {
+        if (qstrempty(&mount->uri))
+            continue;
+
+        if (!memcmp(qstrgetstr(&mount->uri), uri, mount->uri.len) &&
+            (uri[mount->uri.len] == '/' || uri[mount->uri.len] == '/')) {
+            if (mount->path.len > longest_path) {
+                longest_path = mount->path.len;
+                found = mount;
+            }
+        }
+    }
+
+    if (found)
+        get_mount(found);
+
+    unlock(mount_list_lock);
+    return found;
+}
+
 BEGIN_CP_FUNC(mount)
 {
     assert(size == sizeof(struct shim_mount));

+ 3 - 6
LibOS/shim/src/fs/shim_namei.c

@@ -324,10 +324,6 @@ static int link_path_walk (const char * name, struct lookup * look)
     }
 
     dent = look->dentry;
-
-    if (look->depth)
-        lookup_flags |= LOOKUP_FOLLOW;
-
     lookup_flags |= LOOKUP_CONTINUE;
 
     while (*name) {
@@ -348,7 +344,7 @@ static int link_path_walk (const char * name, struct lookup * look)
             while (*(++name) == '/');
 
             if (!*name) {
-                lookup_flags |= LOOKUP_FOLLOW | LOOKUP_DIRECTORY;
+                lookup_flags |= LOOKUP_DIRECTORY;
                 lookup_flags &= ~LOOKUP_CONTINUE;
             }
         }
@@ -392,7 +388,8 @@ static int link_path_walk (const char * name, struct lookup * look)
                 goto out;
         }
 
-        if (look->dentry->state & DENTRY_ISLINK) {
+        if ((look->dentry->state & DENTRY_ISLINK) &&
+            (look->last_type != LAST_NORM || look->flags & LOOKUP_FOLLOW)) {
             err = follow_link(look);
             if (err < 0)
                 goto out;

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

@@ -744,8 +744,8 @@ restore:
     RUN_INIT(init_mount_root);
     RUN_INIT(init_ipc);
     RUN_INIT(init_thread);
-    RUN_INIT(init_important_handles);
     RUN_INIT(init_mount);
+    RUN_INIT(init_important_handles);
     RUN_INIT(init_async);
     RUN_INIT(init_stack, argv, envp, &argp, nauxv, &auxp);
     RUN_INIT(init_loader);

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

@@ -43,7 +43,7 @@ int shim_do_access (const char * file, mode_t mode)
     struct shim_dentry * dent = NULL;
     int ret = 0;
 
-    ret = path_lookupat(NULL, file, LOOKUP_ACCESS, &dent);
+    ret = path_lookupat(NULL, file, LOOKUP_ACCESS|LOOKUP_FOLLOW, &dent);
     if (!ret)
         ret = permission(dent, mode, 1);
 
@@ -64,7 +64,7 @@ int shim_do_faccessat (int dfd, const char * filename, mode_t mode)
     if ((ret = path_startat(dfd, &dir)) < 0)
         return ret;
 
-    ret = path_lookupat(dir, filename, LOOKUP_ACCESS, &dent);
+    ret = path_lookupat(dir, filename, LOOKUP_ACCESS|LOOKUP_FOLLOW, &dent);
     if (ret < 0)
         goto out;
 

+ 22 - 14
LibOS/shim/src/sys/shim_stat.c

@@ -42,7 +42,7 @@ int shim_do_stat (const char * file, struct stat * stat)
     int ret;
     struct shim_dentry * dent = NULL;
 
-    if ((ret = path_lookupat(NULL, file, LOOKUP_ACCESS, &dent)) < 0)
+    if ((ret = path_lookupat(NULL, file, LOOKUP_ACCESS|LOOKUP_FOLLOW, &dent)) < 0)
         goto out;
 
     struct shim_mount * fs = dent->fs;
@@ -113,25 +113,33 @@ int shim_do_readlink (const char * file, char * buf, int bufsize)
     if (bufsize <= 0)
         return -EINVAL;
 
-    /* The correct behavior is to return -EINVAL if file is not a
-       symbolic link */
-    return -EINVAL;
-
-#if 0
     int ret;
     struct shim_dentry * dent = NULL;
+    struct shim_qstr qstr;
 
     if ((ret = path_lookupat(NULL, file, LOOKUP_ACCESS, &dent)) < 0)
         return ret;
 
-    char * relpath;
-    int len;
+    ret = -EINVAL;
+    /* The correct behavior is to return -EINVAL if file is not a
+       symbolic link */
+    if (!(dent->state & DENTRY_ISLINK))
+        goto out;
 
-    relpath = dentry_get_path(dent, true, &len);
-    if (len > bufsize)
-        len = bufsize;
-    memcpy(buf, relpath, len);
+    if (!dent->fs || !dent->fs->d_ops || !dent->fs->d_ops->follow_link)
+        goto out;
+
+    ret = dent->fs->d_ops->follow_link(dent, &qstr);
+    if (ret < 0)
+        goto out;
+
+    ret = -ENAMETOOLONG;
+    if (qstr.len >= bufsize)
+        goto out;
+
+    memcpy(buf, qstrgetstr(&qstr), qstr.len);
+    ret = qstr.len;
+out:
     put_dentry(dent);
-    return len;
-#endif
+    return ret;
 }

+ 7 - 1
Pal/Makefile

@@ -38,9 +38,15 @@ $(LINUX_SRC)/graphene: linux-kernel/graphene
 $(LINUX_SRC)/.config: $(LINUX_SRC)/Makefile
 	cd $(LINUX_SRC) && make menuconfig
 
-install: $(LINUX_KERNEL)
+kernel_install: $(LINUX_KERNEL)
 	$(MAKE) -C $(LINUX_SRC) install modules_install headers_install
 
+install:
+	[ -d ../Runtime ] || mkdir -p ../Runtime
+	[ -f ../Runtime/libpal.so ] || ln -sf ../Pal/src/libpal.so ../Runtime/libpal.so
+	[ -f ../Runtime/pal ] || ln -sf ../Pal/src/pal ../Runtime/pal
+	[ -f ../Runtime/pal_sec ] || ln -sf ../Pal/src/pal_sec ../Runtime/pal_sec
+
 linux-deb:
 	if [ ! -f $(LINUX_SRC)/.config ]; then \
 		cp /boot/config-$(shell uname -r) $(LINUX_SRC)/.config && \