From: Eli Zaretskii Date: Wed, 16 Jan 2019 15:55:53 +0000 (+0200) Subject: Improve documentation of pdumper; minor code cleanup X-Git-Tag: emacs-27.0.90~3814 X-Git-Url: http://git.eshelyaron.com/gitweb/?a=commitdiff_plain;h=ebd174e218f46e2d3e30646a8426f6ec1ae9e8d1;p=emacs.git Improve documentation of pdumper; minor code cleanup * src/emacs.c (usage_message): Add the --dump-file option. (string_starts_with_p, find_argument): Functions removed; use 'argmatch' instead. (PDUMP_FILE_ARG): Macro removed; use literal strings instead, as with other command-line options. Use HAVE_PDUMPER for cpp conditionals which used PDUMP_FILE_ARG. (load_pdump, main): Use 'argmatch' for "--dump-file" and "--temacs" arguments, thus supporting the "-dump-file" and "-temacs" variants, for consistency with other options. (main): Remove the extra fatal error for using --dump-file in unexec'ed Emacs: load_pdump does that anyway. (standard_args): Add --dump-file and --temacs, with appropriate priorities. * etc/NEWS: Expand on the pdumper support. * doc/emacs/cmdargs.texi (Initial Options): Document the '--dump-file' command-line option. --- diff --git a/doc/emacs/cmdargs.texi b/doc/emacs/cmdargs.texi index d51d97b48a2..b49126764a6 100644 --- a/doc/emacs/cmdargs.texi +++ b/doc/emacs/cmdargs.texi @@ -383,6 +383,17 @@ verify that their module conforms to the module API requirements. The option makes Emacs abort if a module-related assertion triggers. @xref{Writing Dynamic Modules,, Writing Dynamically-Loaded Modules, elisp, The GNU Emacs Lisp Reference Manual}. + +@item --dump-file=@var{file} +@opindex --dump-file +@cindex specify dump file +Load the dumped Emacs state from the named @var{file}. By default, +Emacs will look for its dump state in a file named +@file{@var{emacs}.pdmp} in the directory of the executable, where +@var{emacs} is the name of the Emacs executable file, normally just +@file{emacs}. However, if you rename or move the dump file to a +different place, you can use this option to tell Emacs where to find +that file. @end table @node Command Example diff --git a/etc/NEWS b/etc/NEWS index 5af0c1fab03..02503073c1c 100644 --- a/etc/NEWS +++ b/etc/NEWS @@ -59,10 +59,24 @@ option '--enable-check-lisp-object-type' is therefore no longer as useful and so is no longer enabled by default in developer builds, to reduce differences between developer and production builds. -** Emacs by default uses a "portable dumper" instead of unexec, -improving compatibility with modern systems and supporting ASLR. -Emacs now needs an "emacs.pdmp" file, generated during the built, in -its data directory at runtime. ++++ +** Emacs now uses a "portable dumper" instead of unexec. +This improves compatibility with memory allocation on modern systems, +and in particular better supports the Address Space Layout +Randomization (ASLR) feature, a security technique used by most modern +operating systems. + +Portable dumping can be disabled at configure time via the configure +option '--with-pdumper=no' (but we don't recommend that, unless the +portable dumping doesn't work on your system for some reason---please +report such systems to the Emacs developers as bugs). + +When built with the portable dumping support (which is the default), +Emacs looks for the 'emacs.pdmp' file, generated during the build, in +its data directory at startup, and loads the dumped state from there. +The new command-line argument '--dump-file=FILE' allows to specify a +non-default '.pdmp' file to load the state from; see the node "Initial +Options" in the Emacs manual for more information. ** Ibuffer diff --git a/src/emacs.c b/src/emacs.c index 9c88b6e3f17..c1133f2460a 100644 --- a/src/emacs.c +++ b/src/emacs.c @@ -230,6 +230,11 @@ Initialization options:\n\ "\ --module-assertions assert behavior of dynamic modules\n\ ", +#endif +#ifdef HAVE_PDUMPER + "\ +--dump-file FILE read dumped state from FILE\n\ +", #endif "\ --no-build-details do not add build details such as time stamps\n\ @@ -650,43 +655,6 @@ argmatch (char **argv, int argc, const char *sstr, const char *lstr, } } -static bool -string_starts_with_p (const char* string, const char* prefix) -{ - return strncmp (string, prefix, strlen (prefix)) == 0; -} - -/* Return the value of GNU-style long argument ARGUMENT if given on - command line. ARGUMENT must begin with "-". If ARGUMENT is not - given, return NULL. */ -static char * -find_argument (const char *argument, int argc, char **argv) -{ - char *found = NULL; - int i; - - eassert (argument[0] == '-'); - - for (i = 1; i < argc; ++i) - if (string_starts_with_p (argv[i], argument) && - ((argv[i] + strlen (argument))[0] == '=' || - (argv[i] + strlen (argument))[0] == '\0')) - { - int j = i; - found = argv[j++] + strlen (argument); - if (*found == '=') - ++found; - else if (i < argc) - found = argv[j++]; - else - fatal ("no argument given for %s", argument); - break; - } - else if (strcmp (argv[i], "--") == 0) - break; - return found; -} - /* Close standard output and standard error, reporting any write errors as best we can. This is intended for use with atexit. */ static void @@ -731,8 +699,6 @@ dump_error_to_string (enum pdumper_load_result result) } } -#define PDUMP_FILE_ARG "--dump-file" - static enum pdumper_load_result load_pdump (int argc, char **argv) { @@ -753,7 +719,16 @@ load_pdump (int argc, char **argv) /* Look for an explicitly-specified dump file. */ const char *path_exec = PATH_EXEC; - char *dump_file = find_argument (PDUMP_FILE_ARG, argc, argv); + char *dump_file = NULL; + int skip_args = 0; + while (skip_args < argc - 1) + { + if (argmatch (argv, argc, "-dump-file", "--dump-file", 6, + &dump_file, &skip_args) + || argmatch (argv, argc, "--", NULL, 2, NULL, &skip_args)) + break; + skip_args++; + } result = PDUMPER_NOT_LOADED; if (dump_file) @@ -822,7 +797,6 @@ main (int argc, char **argv) void *stack_bottom_variable; bool do_initial_setlocale; - int skip_args = 0; bool no_loadup = false; char *junk = 0; char *dname_arg = 0; @@ -838,7 +812,15 @@ main (int argc, char **argv) stack_bottom = (char *) &stack_bottom_variable; const char *dump_mode = NULL; - const char *temacs = find_argument ("--temacs", argc, argv); + int skip_args = 0; + char *temacs = NULL; + while (skip_args < argc - 1) + { + if (argmatch (argv, argc, "-temacs", "--temacs", 8, &temacs, &skip_args) + || argmatch (argv, argc, "--", NULL, 2, NULL, &skip_args)) + break; + skip_args++; + } #ifdef HAVE_PDUMPER bool attempt_load_pdump = false; #endif @@ -874,18 +856,11 @@ main (int argc, char **argv) { fatal ("--temacs not supported for unexeced emacs"); } - else if (initialized) - { -#ifdef HAVE_PDUMPER - if (find_argument (PDUMP_FILE_ARG, argc, argv)) - fatal ("%s not supported in unexeced emacs", PDUMP_FILE_ARG); -#endif - } else { eassert (!initialized); eassert (!temacs); -#ifdef PDUMP_FILE_ARG +#ifdef HAVE_PDUMPER attempt_load_pdump = true; #endif } @@ -948,6 +923,7 @@ main (int argc, char **argv) argc = 0; while (argv[argc]) argc++; + skip_args = 0; if (argmatch (argv, argc, "-version", "--version", 3, NULL, &skip_args)) { const char *version, *copyright; @@ -1992,6 +1968,12 @@ static const struct standard_args standard_args[] = { "-color", "--color", 5, 0}, { "-no-splash", "--no-splash", 3, 0 }, { "-no-desktop", "--no-desktop", 3, 0 }, + /* The following two must be just above the file-name args, to get + them out of our way, but without mixing them with file names. */ + { "-temacs", "--temacs", 1, 1 }, +#ifdef HAVE_PDUMPER + { "-dump-file", "--dump-file", 1, 1 }, +#endif #ifdef HAVE_NS { "-NSAutoLaunch", 0, 5, 1 }, { "-NXAutoLaunch", 0, 5, 1 },