Skip to content
This repository was archived by the owner on Jun 1, 2023. It is now read-only.

Commit cc207e2

Browse files
Reini Urbanrurban
Reini Urban
authored andcommitted
unexec: enable unexmacosx
dumps and starts fine, even if we don't record the regions yet. fails in starting at Perl_set_caret_X(), empty gv_fetchpvs() $^X symbol. we need to change the init order, as $^X and some others need to be initialized dynamically, similar to dynaloaded modules. prepared the other sources also, but untested. esp. win32 and solaris. macosx and win32 seem to be the most trickiest. harmonize error message, esp. when failing to create the file, most likely due to a BEGIN { chdir .. }, changed pwd. See #176
1 parent 8441b6e commit cc207e2

13 files changed

+204
-116
lines changed

MANIFEST

+1
Original file line numberDiff line numberDiff line change
@@ -5640,6 +5640,7 @@ iperlsys.h Perl's interface to the system
56405640
keywords.c Perl_keyword(), generated by regen/keywords.pl
56415641
keywords.h The keyword numbers
56425642
l1_char_class_tab.h 256 word bit table of character classes (for handy.h)
5643+
lastfile.c For unexec from GNU emacs
56435644
lib/_charnames.pm Character names
56445645
lib/AnyDBM_File.pm Perl module to emulate dbmopen
56455646
lib/AnyDBM_File.t See if AnyDBM_File works

Makefile.SH

+5-6
Original file line numberDiff line numberDiff line change
@@ -429,8 +429,7 @@ $make_set_make
429429

430430
# disabled for now until properly integrated
431431
case "${unexec}" in
432-
#unex*) archobjs="$archobjs ${unexec}${_o}" ;;
433-
*) ;;
432+
unex*) archobjs="$archobjs ${unexec}${_o}" ;;
434433
esac
435434

436435
case "${osname}" in
@@ -625,9 +624,9 @@ miniperl_dtrace_objs = $(miniperl_objs_nodt:%=mpdtrace/%)
625624
perllib_dtrace_objs = $(perllib_objs_nodt:%=libpdtrace/%)
626625
perlmain_dtrace_objs = maindtrace/perlmain$(OBJ_EXT)
627626
628-
miniperl_objs = $(miniperl_dtrace_objs) $(DTRACE_MINI_O)
627+
miniperl_objs = $(miniperl_dtrace_objs) $(DTRACE_MINI_O) lastfile$(OBJ_EXT)
629628
perllib_objs = $(perllib_dtrace_objs) $(DTRACE_PERLLIB_O)
630-
perlmain_objs = $(perlmain_dtrace_objs) $(DTRACE_MAIN_O)
629+
perlmain_objs = $(perlmain_dtrace_objs) $(DTRACE_MAIN_O) lastfile$(OBJ_EXT)
631630
632631
miniperl_dep = $(DTRACE_MINI_O)
633632
perllib_dep = $(DTRACE_PERLLIB_O)
@@ -638,9 +637,9 @@ perlmain_dep = $(DTRACE_MAIN_O)
638637
*)
639638
$spitshell >>$Makefile <<'!NO!SUBS!'
640639
641-
miniperl_objs = $(miniperl_objs_nodt) $(DTRACE_MINI_O)
640+
miniperl_objs = $(miniperl_objs_nodt) $(DTRACE_MINI_O) lastfile$(OBJ_EXT)
642641
perllib_objs = $(perllib_objs_nodt) $(DTRACE_PERLLIB_O)
643-
perlmain_objs = perlmain$(OBJ_EXT) $(DTRACE_MAIN_O)
642+
perlmain_objs = perlmain$(OBJ_EXT) $(DTRACE_MAIN_O) lastfile$(OBJ_EXT)
644643
645644
miniperl_dep = $(miniperl_objs)
646645
perllib_dep = $(perllib_objs)

lastfile.c

+49
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
/* Mark end of data space to dump as pure, for GNU Emacs.
2+
Copyright (C) 1985, 2001-2015 Free Software Foundation, Inc.
3+
4+
This file is part of GNU Emacs.
5+
6+
GNU Emacs is free software: you can redistribute it and/or modify
7+
it under the terms of the GNU General Public License as published by
8+
the Free Software Foundation, either version 3 of the License, or
9+
(at your option) any later version.
10+
11+
GNU Emacs is distributed in the hope that it will be useful,
12+
but WITHOUT ANY WARRANTY; without even the implied warranty of
13+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14+
GNU General Public License for more details.
15+
16+
You should have received a copy of the GNU General Public License
17+
along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */
18+
19+
20+
/* How this works:
21+
22+
Fdump_emacs dumps everything up to my_edata as text space (pure).
23+
24+
The files of Emacs are written so as to have no initialized
25+
data that can ever need to be altered except at the first startup.
26+
This is so that those words can be dumped as shareable text.
27+
28+
It is not possible to exercise such control over library files.
29+
So it is necessary to refrain from making their data areas shared.
30+
Therefore, this file is loaded following all the files of Emacs
31+
but before library files.
32+
As a result, the symbol my_edata indicates the point
33+
in data space between data coming from Emacs and data
34+
coming from libraries.
35+
*/
36+
37+
/*#include <config.h>*/
38+
39+
char my_edata[] = "End of Emacs initialized data";
40+
41+
/* Help unexec locate the end of the .bss area used by Emacs (which
42+
isn't always a separate section in NT executables). */
43+
char my_endbss[1];
44+
45+
/* The Alpha MSVC linker globally segregates all static and public bss
46+
data, so we must take both into account to determine the true extent
47+
of the bss area used by Emacs. */
48+
static char _my_endbss[1];
49+
char * my_endbss_static = _my_endbss;

perl.c

+11-9
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,10 @@
4646
# include "nwutil.h"
4747
#endif
4848

49+
#ifdef UNEXEC
50+
#include "unexec.h"
51+
#endif
52+
4953
#ifdef DEBUG_LEAKING_SCALARS_FORK_DUMP
5054
# ifdef I_SYSUIO
5155
# include <sys/uio.h>
@@ -4065,18 +4069,16 @@ void
40654069
Perl_my_unexec(pTHX)
40664070
{
40674071
#ifdef UNEXEC
4068-
SV * prog = newSVpv(BIN_EXP, 0);
4069-
SV * file = newSVpv(PL_origfilename, 0);
4070-
int status = 1;
4071-
extern int etext;
4072-
4073-
sv_catpvs(prog, "/perl");
4072+
SV * const caret_X = get_sv("\030", 0);
4073+
SV * const prog = newSVpvn_flags(SvPVX(caret_X), SvCUR(caret_X),
4074+
SvUTF8(caret_X));
4075+
/* what to do with "-e" ? */
4076+
SV * file = newSVpv(strEQc(PL_origfilename, "-e") ? "script" : PL_origfilename, 0);
40744077
sv_catpvs(file, ".perldump");
40754078

4076-
/* unexec, etext defined in unexec.c */
4077-
unexec(SvPVX(file), SvPVX(prog), &etext, sbrk(0), 0);
4079+
unexec(SvPVX(file), SvPVX(prog));
40784080
/* unexec prints msg to stderr in case of failure */
4079-
PerlProc_exit(status);
4081+
PerlProc_exit(1);
40804082
#else
40814083
/* dump to core */
40824084
PERL_UNUSED_CONTEXT;

uconfig.h

+6-1
Original file line numberDiff line numberDiff line change
@@ -5480,9 +5480,14 @@
54805480
*/
54815481
/*#define USE_FFI / **/
54825482

5483+
/* UNEXEC:
5484+
* This symbol defines the used unexec source.
5485+
* Defined via ccflags.
5486+
*/
5487+
54835488
#endif
54845489

54855490
/* Generated from:
5486-
* d295cb5b21070ab7c5076d71ceaa6fe08b12b02a619a95aba11c443ef7f8600a config_h.SH
5491+
* 7c910e3df6f8dfb8c2976b0c7b72ec560d55a386fd49b20054b0c3ddb716eae0 config_h.SH
54875492
* 1ad21ed3ecb2fac07b7c4aabef76b2fc7354cc6dee0b561e852a1651f8dd6025 uconfig.sh
54885493
* ex: set ro: */

unexaix.c

+13-11
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,11 @@ what you give them. Help stamp out software-hoarding! */
4040
*
4141
*/
4242

43-
#include <config.h>
4443
#include "unexec.h"
45-
#include "lisp.h"
44+
#define PERLIO_NOT_STDIO 0
45+
#include "EXTERN.h"
46+
#define PERL_IN_UNEXEC_C
47+
#include "perl.h"
4648

4749
#define PERROR(file) report_error (file, new)
4850
#include <a.out.h>
@@ -96,7 +98,7 @@ report_error (const char *file, int fd)
9698
{
9799
int err = errno;
98100
if (fd)
99-
emacs_close (fd);
101+
close (fd);
100102
report_file_errno ("Cannot unexec", build_string (file), err);
101103
}
102104

@@ -108,7 +110,7 @@ static _Noreturn void ATTRIBUTE_FORMAT_PRINTF (2, 3)
108110
report_error_1 (int fd, const char *msg, ...)
109111
{
110112
va_list ap;
111-
emacs_close (fd);
113+
close (fd);
112114
va_start (ap, msg);
113115
verror (msg, ap);
114116
va_end (ap);
@@ -130,11 +132,11 @@ unexec (const char *new_name, const char *a_name)
130132
{
131133
int new = -1, a_out = -1;
132134

133-
if (a_name && (a_out = emacs_open (a_name, O_RDONLY, 0)) < 0)
135+
if (a_name && (a_out = open (a_name, O_RDONLY, 0)) < 0)
134136
{
135137
PERROR (a_name);
136138
}
137-
if ((new = emacs_open (new_name, O_WRONLY | O_CREAT | O_TRUNC, 0666)) < 0)
139+
if ((new = open (new_name, O_WRONLY | O_CREAT | O_TRUNC, 0666)) < 0)
138140
{
139141
PERROR (new_name);
140142
}
@@ -145,13 +147,13 @@ unexec (const char *new_name, const char *a_name)
145147
|| adjust_lnnoptrs (new, a_out, new_name) < 0
146148
|| unrelocate_symbols (new, a_out, a_name, new_name) < 0)
147149
{
148-
emacs_close (new);
150+
close (new);
149151
return;
150152
}
151153

152-
emacs_close (new);
154+
close (new);
153155
if (a_out >= 0)
154-
emacs_close (a_out);
156+
close (a_out);
155157
mark_x (new_name);
156158
}
157159

@@ -501,7 +503,7 @@ adjust_lnnoptrs (int writedesc, int readdesc, const char *new_name)
501503
if (!lnnoptr || !f_hdr.f_symptr)
502504
return 0;
503505

504-
if ((new = emacs_open (new_name, O_RDWR, 0)) < 0)
506+
if ((new = open (new_name, O_RDWR, 0)) < 0)
505507
{
506508
PERROR (new_name);
507509
return -1;
@@ -531,7 +533,7 @@ adjust_lnnoptrs (int writedesc, int readdesc, const char *new_name)
531533
}
532534
}
533535
}
534-
emacs_close (new);
536+
close (new);
535537

536538
return 0;
537539
}

unexcoff.c

+13-11
Original file line numberDiff line numberDiff line change
@@ -50,9 +50,11 @@ along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */
5050
* of Dell Computer Corporation. [email protected].
5151
*/
5252

53-
#include <config.h>
5453
#include "unexec.h"
55-
#include "lisp.h"
54+
#define PERLIO_NOT_STDIO 0
55+
#include "EXTERN.h"
56+
#define PERL_IN_UNEXEC_C
57+
#include "perl.h"
5658

5759
#define PERROR(file) report_error (file, new)
5860

@@ -131,7 +133,7 @@ report_error (const char *file, int fd)
131133
{
132134
int err = errno;
133135
if (fd)
134-
emacs_close (fd);
136+
close (fd);
135137
report_file_errno ("Cannot unexec", build_string (file), err);
136138
}
137139

@@ -142,7 +144,7 @@ report_error (const char *file, int fd)
142144
static void
143145
report_error_1 (int fd, const char *msg, int a1, int a2)
144146
{
145-
emacs_close (fd);
147+
close (fd);
146148
error (msg, a1, a2);
147149
}
148150

@@ -499,7 +501,7 @@ adjust_lnnoptrs (int writedesc, int readdesc, const char *new_name)
499501
#ifdef MSDOS
500502
if ((new = writedesc) < 0)
501503
#else
502-
if ((new = emacs_open (new_name, O_RDWR, 0)) < 0)
504+
if ((new = open (new_name, O_RDWR, 0)) < 0)
503505
#endif
504506
{
505507
PERROR (new_name);
@@ -523,7 +525,7 @@ adjust_lnnoptrs (int writedesc, int readdesc, const char *new_name)
523525
}
524526
}
525527
#ifndef MSDOS
526-
emacs_close (new);
528+
close (new);
527529
#endif
528530
return 0;
529531
}
@@ -538,11 +540,11 @@ unexec (const char *new_name, const char *a_name)
538540
{
539541
int new = -1, a_out = -1;
540542

541-
if (a_name && (a_out = emacs_open (a_name, O_RDONLY, 0)) < 0)
543+
if (a_name && (a_out = open (a_name, O_RDONLY, 0)) < 0)
542544
{
543545
PERROR (a_name);
544546
}
545-
if ((new = emacs_open (new_name, O_WRONLY | O_CREAT | O_TRUNC, 0666)) < 0)
547+
if ((new = open (new_name, O_WRONLY | O_CREAT | O_TRUNC, 0666)) < 0)
546548
{
547549
PERROR (new_name);
548550
}
@@ -553,13 +555,13 @@ unexec (const char *new_name, const char *a_name)
553555
|| adjust_lnnoptrs (new, a_out, new_name) < 0
554556
)
555557
{
556-
emacs_close (new);
558+
close (new);
557559
return;
558560
}
559561

560-
emacs_close (new);
562+
close (new);
561563
if (a_out >= 0)
562-
emacs_close (a_out);
564+
close (a_out);
563565
mark_x (new_name);
564566
}
565567

unexcw.c

+8-6
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,11 @@ GNU General Public License for more details.
1818
You should have received a copy of the GNU General Public License
1919
along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */
2020

21-
#include <config.h>
2221
#include "unexec.h"
23-
#include "lisp.h"
22+
#define PERLIO_NOT_STDIO 0
23+
#include "EXTERN.h"
24+
#define PERL_IN_UNEXEC_C
25+
#include "perl.h"
2426

2527
#include <stdio.h>
2628
#include <fcntl.h>
@@ -298,9 +300,9 @@ unexec (const char *outfile, const char *infile)
298300
infile = add_exe_suffix_if_necessary (infile, infile_buffer);
299301
outfile = add_exe_suffix_if_necessary (outfile, outfile_buffer);
300302

301-
fd_in = emacs_open (infile, O_RDONLY | O_BINARY, 0);
303+
fd_in = open (infile, O_RDONLY | O_BINARY, 0);
302304
assert (fd_in >= 0);
303-
fd_out = emacs_open (outfile, O_RDWR | O_TRUNC | O_CREAT | O_BINARY, 0755);
305+
fd_out = open (outfile, O_RDWR | O_TRUNC | O_CREAT | O_BINARY, 0755);
304306
assert (fd_out >= 0);
305307
for (;;)
306308
{
@@ -316,13 +318,13 @@ unexec (const char *outfile, const char *infile)
316318
ret2 = write (fd_out, buffer, ret);
317319
assert (ret2 == ret);
318320
}
319-
ret = emacs_close (fd_in);
321+
ret = close (fd_in);
320322
assert (ret == 0);
321323

322324
bss_sbrk_did_unexec = 1;
323325
fixup_executable (fd_out);
324326
bss_sbrk_did_unexec = 0;
325327

326-
ret = emacs_close (fd_out);
328+
ret = close (fd_out);
327329
assert (ret == 0);
328330
}

0 commit comments

Comments
 (0)