[前][次][番号順一覧][スレッド一覧]

ruby-changes:51696

From: normal <ko1@a...>
Date: Mon, 9 Jul 2018 08:43:18 +0900 (JST)
Subject: [ruby-changes:51696] normal:r63908 (trunk): addr2line.c: no need to keep fd around after mmap

normal	2018-07-09 08:43:14 +0900 (Mon, 09 Jul 2018)

  New Revision: 63908

  https://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=63908

  Log:
    addr2line.c: no need to keep fd around after mmap
    
    POSIX mmap(3) manpage stipulates mmap bumps the reference
    count of the file description.  Thus keeping a file descriptor
    to maintain the reference is not necessary.
    
    If this didn't work, every extension .so would require a
    permanent FD, which is obviously not the case.

  Modified files:
    trunk/addr2line.c
Index: addr2line.c
===================================================================
--- addr2line.c	(revision 63907)
+++ addr2line.c	(revision 63908)
@@ -119,7 +119,6 @@ typedef struct { https://github.com/ruby/ruby/blob/trunk/addr2line.c#L119
 typedef struct obj_info obj_info_t;
 struct obj_info {
     const char *path; /* object path */
-    int fd;
     void *mapped;
     size_t mapped_size;
     uintptr_t base_addr;
@@ -525,6 +524,7 @@ fill_lines(int num_traces, void **traces https://github.com/ruby/ruby/blob/trunk/addr2line.c#L524
 	kprintf("mmap: %s\n", strerror(e));
 	goto fail;
     }
+    close(fd);
 
     ehdr = (ElfW(Ehdr) *)file;
     if (memcmp(ehdr->e_ident, "\177ELF", 4) != 0) {
@@ -532,11 +532,8 @@ fill_lines(int num_traces, void **traces https://github.com/ruby/ruby/blob/trunk/addr2line.c#L532
 	 * Huh? Maybe filename was overridden by setproctitle() and
 	 * it match non-elf file.
 	 */
-	close(fd);
 	goto fail;
     }
-
-    obj->fd = fd;
     obj->mapped = file;
     obj->mapped_size = (size_t)filesize;
 
@@ -790,9 +787,8 @@ next_line: https://github.com/ruby/ruby/blob/trunk/addr2line.c#L787
     while (obj) {
 	obj_info_t *o = obj;
 	obj = o->next;
-	if (o->fd) {
+	if (o->mapped_size) {
 	    munmap(o->mapped, o->mapped_size);
-	    close(o->fd);
 	}
 	free(o);
     }

--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]