aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEli Zaretskii2019-01-16 17:55:53 +0200
committerEli Zaretskii2019-01-16 17:55:53 +0200
commitebd174e218f46e2d3e30646a8426f6ec1ae9e8d1 (patch)
treed0b88ce3b9538920d5f495e3c86503b259baaf71
parente96a54eb3bdfd75bafbe795ec6dd7b94ff65b8ac (diff)
downloademacs-ebd174e218f46e2d3e30646a8426f6ec1ae9e8d1.tar.gz
emacs-ebd174e218f46e2d3e30646a8426f6ec1ae9e8d1.zip
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.
-rw-r--r--doc/emacs/cmdargs.texi11
-rw-r--r--etc/NEWS22
-rw-r--r--src/emacs.c82
3 files changed, 61 insertions, 54 deletions
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
383option makes Emacs abort if a module-related assertion triggers. 383option makes Emacs abort if a module-related assertion triggers.
384@xref{Writing Dynamic Modules,, Writing Dynamically-Loaded Modules, 384@xref{Writing Dynamic Modules,, Writing Dynamically-Loaded Modules,
385elisp, The GNU Emacs Lisp Reference Manual}. 385elisp, The GNU Emacs Lisp Reference Manual}.
386
387@item --dump-file=@var{file}
388@opindex --dump-file
389@cindex specify dump file
390Load the dumped Emacs state from the named @var{file}. By default,
391Emacs will look for its dump state in a file named
392@file{@var{emacs}.pdmp} in the directory of the executable, where
393@var{emacs} is the name of the Emacs executable file, normally just
394@file{emacs}. However, if you rename or move the dump file to a
395different place, you can use this option to tell Emacs where to find
396that file.
386@end table 397@end table
387 398
388@node Command Example 399@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
59useful and so is no longer enabled by default in developer builds, 59useful and so is no longer enabled by default in developer builds,
60to reduce differences between developer and production builds. 60to reduce differences between developer and production builds.
61 61
62** Emacs by default uses a "portable dumper" instead of unexec, 62+++
63improving compatibility with modern systems and supporting ASLR. 63** Emacs now uses a "portable dumper" instead of unexec.
64Emacs now needs an "emacs.pdmp" file, generated during the built, in 64This improves compatibility with memory allocation on modern systems,
65its data directory at runtime. 65and in particular better supports the Address Space Layout
66Randomization (ASLR) feature, a security technique used by most modern
67operating systems.
68
69Portable dumping can be disabled at configure time via the configure
70option '--with-pdumper=no' (but we don't recommend that, unless the
71portable dumping doesn't work on your system for some reason---please
72report such systems to the Emacs developers as bugs).
73
74When built with the portable dumping support (which is the default),
75Emacs looks for the 'emacs.pdmp' file, generated during the build, in
76its data directory at startup, and loads the dumped state from there.
77The new command-line argument '--dump-file=FILE' allows to specify a
78non-default '.pdmp' file to load the state from; see the node "Initial
79Options" in the Emacs manual for more information.
66 80
67** Ibuffer 81** Ibuffer
68 82
diff --git a/src/emacs.c b/src/emacs.c
index 9c88b6e3f17..c1133f2460a 100644
--- a/src/emacs.c
+++ b/src/emacs.c
@@ -231,6 +231,11 @@ Initialization options:\n\
231--module-assertions assert behavior of dynamic modules\n\ 231--module-assertions assert behavior of dynamic modules\n\
232", 232",
233#endif 233#endif
234#ifdef HAVE_PDUMPER
235 "\
236--dump-file FILE read dumped state from FILE\n\
237",
238#endif
234 "\ 239 "\
235--no-build-details do not add build details such as time stamps\n\ 240--no-build-details do not add build details such as time stamps\n\
236--no-desktop do not load a saved desktop\n\ 241--no-desktop do not load a saved desktop\n\
@@ -650,43 +655,6 @@ argmatch (char **argv, int argc, const char *sstr, const char *lstr,
650 } 655 }
651} 656}
652 657
653static bool
654string_starts_with_p (const char* string, const char* prefix)
655{
656 return strncmp (string, prefix, strlen (prefix)) == 0;
657}
658
659/* Return the value of GNU-style long argument ARGUMENT if given on
660 command line. ARGUMENT must begin with "-". If ARGUMENT is not
661 given, return NULL. */
662static char *
663find_argument (const char *argument, int argc, char **argv)
664{
665 char *found = NULL;
666 int i;
667
668 eassert (argument[0] == '-');
669
670 for (i = 1; i < argc; ++i)
671 if (string_starts_with_p (argv[i], argument) &&
672 ((argv[i] + strlen (argument))[0] == '=' ||
673 (argv[i] + strlen (argument))[0] == '\0'))
674 {
675 int j = i;
676 found = argv[j++] + strlen (argument);
677 if (*found == '=')
678 ++found;
679 else if (i < argc)
680 found = argv[j++];
681 else
682 fatal ("no argument given for %s", argument);
683 break;
684 }
685 else if (strcmp (argv[i], "--") == 0)
686 break;
687 return found;
688}
689
690/* Close standard output and standard error, reporting any write 658/* Close standard output and standard error, reporting any write
691 errors as best we can. This is intended for use with atexit. */ 659 errors as best we can. This is intended for use with atexit. */
692static void 660static void
@@ -731,8 +699,6 @@ dump_error_to_string (enum pdumper_load_result result)
731 } 699 }
732} 700}
733 701
734#define PDUMP_FILE_ARG "--dump-file"
735
736static enum pdumper_load_result 702static enum pdumper_load_result
737load_pdump (int argc, char **argv) 703load_pdump (int argc, char **argv)
738{ 704{
@@ -753,7 +719,16 @@ load_pdump (int argc, char **argv)
753 719
754 /* Look for an explicitly-specified dump file. */ 720 /* Look for an explicitly-specified dump file. */
755 const char *path_exec = PATH_EXEC; 721 const char *path_exec = PATH_EXEC;
756 char *dump_file = find_argument (PDUMP_FILE_ARG, argc, argv); 722 char *dump_file = NULL;
723 int skip_args = 0;
724 while (skip_args < argc - 1)
725 {
726 if (argmatch (argv, argc, "-dump-file", "--dump-file", 6,
727 &dump_file, &skip_args)
728 || argmatch (argv, argc, "--", NULL, 2, NULL, &skip_args))
729 break;
730 skip_args++;
731 }
757 732
758 result = PDUMPER_NOT_LOADED; 733 result = PDUMPER_NOT_LOADED;
759 if (dump_file) 734 if (dump_file)
@@ -822,7 +797,6 @@ main (int argc, char **argv)
822 void *stack_bottom_variable; 797 void *stack_bottom_variable;
823 798
824 bool do_initial_setlocale; 799 bool do_initial_setlocale;
825 int skip_args = 0;
826 bool no_loadup = false; 800 bool no_loadup = false;
827 char *junk = 0; 801 char *junk = 0;
828 char *dname_arg = 0; 802 char *dname_arg = 0;
@@ -838,7 +812,15 @@ main (int argc, char **argv)
838 stack_bottom = (char *) &stack_bottom_variable; 812 stack_bottom = (char *) &stack_bottom_variable;
839 813
840 const char *dump_mode = NULL; 814 const char *dump_mode = NULL;
841 const char *temacs = find_argument ("--temacs", argc, argv); 815 int skip_args = 0;
816 char *temacs = NULL;
817 while (skip_args < argc - 1)
818 {
819 if (argmatch (argv, argc, "-temacs", "--temacs", 8, &temacs, &skip_args)
820 || argmatch (argv, argc, "--", NULL, 2, NULL, &skip_args))
821 break;
822 skip_args++;
823 }
842#ifdef HAVE_PDUMPER 824#ifdef HAVE_PDUMPER
843 bool attempt_load_pdump = false; 825 bool attempt_load_pdump = false;
844#endif 826#endif
@@ -874,18 +856,11 @@ main (int argc, char **argv)
874 { 856 {
875 fatal ("--temacs not supported for unexeced emacs"); 857 fatal ("--temacs not supported for unexeced emacs");
876 } 858 }
877 else if (initialized)
878 {
879#ifdef HAVE_PDUMPER
880 if (find_argument (PDUMP_FILE_ARG, argc, argv))
881 fatal ("%s not supported in unexeced emacs", PDUMP_FILE_ARG);
882#endif
883 }
884 else 859 else
885 { 860 {
886 eassert (!initialized); 861 eassert (!initialized);
887 eassert (!temacs); 862 eassert (!temacs);
888#ifdef PDUMP_FILE_ARG 863#ifdef HAVE_PDUMPER
889 attempt_load_pdump = true; 864 attempt_load_pdump = true;
890#endif 865#endif
891 } 866 }
@@ -948,6 +923,7 @@ main (int argc, char **argv)
948 argc = 0; 923 argc = 0;
949 while (argv[argc]) argc++; 924 while (argv[argc]) argc++;
950 925
926 skip_args = 0;
951 if (argmatch (argv, argc, "-version", "--version", 3, NULL, &skip_args)) 927 if (argmatch (argv, argc, "-version", "--version", 3, NULL, &skip_args))
952 { 928 {
953 const char *version, *copyright; 929 const char *version, *copyright;
@@ -1992,6 +1968,12 @@ static const struct standard_args standard_args[] =
1992 { "-color", "--color", 5, 0}, 1968 { "-color", "--color", 5, 0},
1993 { "-no-splash", "--no-splash", 3, 0 }, 1969 { "-no-splash", "--no-splash", 3, 0 },
1994 { "-no-desktop", "--no-desktop", 3, 0 }, 1970 { "-no-desktop", "--no-desktop", 3, 0 },
1971 /* The following two must be just above the file-name args, to get
1972 them out of our way, but without mixing them with file names. */
1973 { "-temacs", "--temacs", 1, 1 },
1974#ifdef HAVE_PDUMPER
1975 { "-dump-file", "--dump-file", 1, 1 },
1976#endif
1995#ifdef HAVE_NS 1977#ifdef HAVE_NS
1996 { "-NSAutoLaunch", 0, 5, 1 }, 1978 { "-NSAutoLaunch", 0, 5, 1 },
1997 { "-NXAutoLaunch", 0, 5, 1 }, 1979 { "-NXAutoLaunch", 0, 5, 1 },