From 79436f0c744a65ed2757f0119f5bd13e2fbef995 Mon Sep 17 00:00:00 2001 From: Andrea Corallo Date: Fri, 20 Dec 2019 22:32:19 +0100 Subject: [PATCH] use memory mapped file for loading elns --- src/comp.c | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/src/comp.c b/src/comp.c index 79ece461a54..ea5d3238d2c 100644 --- a/src/comp.c +++ b/src/comp.c @@ -27,6 +27,13 @@ along with GNU Emacs. If not, see . */ #include #include +#include /* For getpid. */ +#include +#include /* For O_RDONLY. */ +#include +/* FIXME non portable. */ +#include /* For memfd_create. */ + #include "lisp.h" #include "puresize.h" #include "window.h" @@ -3301,7 +3308,22 @@ DEFUN ("native-elisp-load", Fnative_elisp_load, Snative_elisp_load, 1, 1, 0, xsignal2 (Qnative_lisp_load_failed, file, build_string ("Empty relocation table")); - dynlib_handle_ptr handle = dynlib_open (SSDATA (file)); + /* FIXME non portable. */ + /* We copy the content of the file to be loaded in a memory mapped + file. We then keep track of this in the struct + Lisp_Native_Compilation_Unit. In case this will be overwritten + or delete we'll dump the right data. */ + int fd_in = emacs_open (SSDATA (file), O_RDONLY, 0); + int fd_out = memfd_create (SSDATA (file), 0); + if (fd_in < 0 || fd_out < 0) + xsignal2 (Qnative_lisp_load_failed, file, + build_string ("Failing to get file descriptor")); + struct stat st; + if (fstat (fd_in, &st) != 0) + report_file_error ("Input file status", file); + copy_file_fd (fd_out, fd_in, &st, Qnil, file); + dynlib_handle_ptr handle = + dynlib_open (format_string ("/proc/%d/fd/%d", getpid (), fd_out)); load_handle_stack = Fcons (make_mint_ptr (handle), load_handle_stack); if (!handle) xsignal2 (Qnative_lisp_load_failed, file, build_string (dynlib_error ())); -- 2.39.5